var reEmail=/^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\.-]+\.[0-9a-zA-Z_\.-]+$/
var reFloat	=	/^[0-9\.,]+$/
var reNumaric	=	/^[0-9]+$/

function printPage(){
	var strTemp;
	strTemp = navigator.appVersion.toLowerCase();
	if (strTemp.indexOf("mac") > 0){
       alert("Press Command-P for Macintosh to Print this page."); 
	}else{
		window.print();
	}
}

function trimchar(pastr){
	var lenstr = pastr.length;
	for(var i = 0 ; pastr.charAt(i) == " "; i++);
	for(var j = pastr.length - 1; pastr.charAt(j)== " "; j--);
	j++;
	if (i > j)
		pastr = "";
	else
		pastr = pastr.substring(i,j);
	return pastr;
}
 
function checkEmail(obj){
 	if(!reEmail.test(obj.value))
	{
		alert("Please enter a valid email address.");
		obj.focus();
		return false;
	}
	return true;
}
 
function formatNumber(value, precision){

	value = "" + value;
	precision = parseInt(precision);

	var whole = "" + Math.round(value * Math.pow(10, precision));

	var decPoint = whole.length - precision;

	if(decPoint != 0) {
		result = whole.substring(0, decPoint);
		result += ".";
		result += whole.substring(decPoint, whole.length);
	} else {
		result = whole;
	}
	return result;
}

function isFloat(s){
	if(reFloat.test(s) == false)
		return false;
	return true;
}

function isNumaric(s){
	if(reNumaric.test(s) == false)
		return false;
	return true;
}

function protectrightclick()
{	
	var cnt=0;
	if(!document.all)
		window.captureEvents(Event.MOUSEDOWN|Event.KEYDOWN);
	function keyhan(evnt){
		if(!document.all){
			if (evnt.which == 8){
				return !confirm("Would you like to save this information?");
			}
		}else{
			if (event.keyCode == 8){
				return !confirm("Would you like to save this information?");
			}
		}
	}
	document.onkeydown=keyhan;
	window.onkeydown=keyhan;
}	 


function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


function comparedate(objDate1, objDate2, paMsg){
	if (objDate1 >= objDate2)  {
		alert(paMsg);
		return false;
	}
	return true;
}

function checkDateFormat(paDate){
	
	var arrDate = new Array();
	var strDate;
	var isLeap;
	var sMsg = "Format of date should be mm/dd/yyyy";
	
	strDate = trimchar (paDate.value);
	
	if (strDate.length > 0){
	
		arrDate = strDate.split("/");
		
		if (arrDate.length == 3 && strDate.length >= 7){
			if ((isNumaric(arrDate[0])) ||  (isNumaric (arrDate[1])) || (isNumaric (arrDate[2])) ){
				if ( (arrDate[0] < 1) || (arrDate[0] > 12) ){
					alert (sMsg);
					return false;	
				}
				
				if ( arrDate[2].length <= 3 ){
					alert (sMsg);
					return false;	
				}
				
				if ( arrDate[1] > 31 ){
					alert (sMsg);
					return false;	
				}else{
					if (arrDate[0] == "02"  || arrDate[0] == "2"){
						isLeap = arrDate[2]%4;
						
						if (isLeap == 0){
							if (arrDate[1] > 29){alert (sMsg); return false;}
						}else{
							if (arrDate[1] > 28){alert (sMsg); return false;}
						}
					}
					
					if (arrDate[0] == "04"  || arrDate[0] == "4"){
						if (arrDate[1] > 30){alert (sMsg); return false;}
					}
					
					if (arrDate[0] == "06"  || arrDate[0] == "6"){
						if (arrDate[1] > 30){alert (sMsg); return false;}
					}
					
					if (arrDate[0] == "09"  || arrDate[0] == "9"){
						if (arrDate[1] > 30){alert (sMsg); return false;}
					}
					
					if (arrDate[0] == "11"  || arrDate[0] == "11"){
						if (arrDate[1] > 30){alert (sMsg); return false;}
					}
				}
				
				return true;
						
			}else{
				alert (sMsg);	
				return false;	
			}
		}else{
			alert (sMsg);	
			return false;	
		}
		return true;
	}
	return true;
}

function formatCurrency(num){
	var iDivisor, iLastThree, iRestOther;
	var strNum, strNewNum;
	strNum = "";
	strNewNum = "";
	
	iDivisor = 3;
	
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();

	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/iDivisor); i++){
		num = num.substring(0,num.length-(4*i+iDivisor))+','+
	num.substring(num.length-(4*i+iDivisor));
	//iDivisor = 2;
	}
	
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}


function checkTimeFormat (paTime, paMsg){
	var arrTimeMarker = new Array();
	var arrTime = new Array();
	var strTime;
	
	
	paTime = trimchar(paTime);
	paTime = replaceSubstring(paTime, "  ", " ");
	
	if (paTime.length > 0){// to check the format
		paTime = trimchar(paTime);
		sChar = paTime;
		
		arrTimeMarker = sChar.split(" ");
		sChar = arrTimeMarker[0];
		
		arrTime = sChar.split(":");
		
		if (arrTime.length == 2){
			if (  (!isNumaric(arrTime[0])) && (!isNumaric(arrTime[1])) ){
				alert (paMsg);
				return 0;
			}
		}else{
			alert (paMsg);
			return 0;
		}
		if (arrTimeMarker.length == 2){
			if ((arrTimeMarker[1].toUpperCase() == "AM") || (arrTimeMarker[1].toUpperCase() == "PM")){
			}else{
				alert (paMsg);
				return 0;
			}
		}else{
			alert (paMsg);
			return 0;
		}
		
		strTime = "";
		
		if (arrTime[0].length == 1) strTime = "0" + arrTime[0];
		else strTime = arrTime[0];
		
		strTime = strTime + ":";
		
		if (arrTime[1].length == 1) strTime = strTime + "0" + arrTime[1];
		else strTime = strTime + arrTime[1];
		
		strTime = strTime + " " + arrTimeMarker[1];
		
		
		return strTime;
		
	}else{
		alert (paMsg);
		return 0;
	}
	return 0;
} 

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// Verisign Logo
function popUp() {
var url = 'https://digitalid.verisign.com/as2/6b1f0aeac600525034d3206d2dcf579d';
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
self.name = "mainWin";
}


