var required=false;
var notRequired=true;
var whitespace=" \t\n\r";
var decimalPointDelimiter=".";
var daysInMonth=new Array(12);
daysInMonth[1]=31;
daysInMonth[2]=29;
daysInMonth[3]=31;
daysInMonth[4]=30;
daysInMonth[5]=31;
daysInMonth[6]=30;
daysInMonth[7]=31;
daysInMonth[8]=31;
daysInMonth[9]=30;
daysInMonth[10]=31;
daysInMonth[11]=30;
daysInMonth[12]=31;
var iDayPrefix="The second field in ";
var iDaySuffix=" must be a day number between 1 and 31.";
var iMonthPrefix="The first field in ";
var iMonthSuffix=" must be a month number between 1 and 12.";
var iYearPrefix="The third field in ";
var iYearSuffix=" must be a 4 digit year number.";
function isEmpty(s){
 return ((s==null)||(s.length==0));
}
function isWhitespace(s){
 var i;
 if(isEmpty(s)){
  return true;
 }
 for (i=0;i<s.length;i++){
  var c=s.charAt(i);
  if(whitespace.indexOf(c)==-1){
   return false;
  }
 }
 return true;
}
function isInteger(s){
 var i;
 if(isEmpty(s)){
  if(isInteger.arguments.length==1){
   return required;
  }
  else{
   return notRequired;
  }
 }
 for(i=0;i<s.length;i++){
  var c=s.charAt(i);
  if(!isDigit(c)){
   return false;
  }
 }
 return true;
}
function isFloat(s){
 var i;
 var seenDecimalPoint=false;
 if(isEmpty(s)){
  if(isFloat.arguments.length==1){
   return required;
  }
  else{
   return(isFloat.arguments[1]==true);
  }
 }
 if(s==decimalPointDelimiter){
  return false;
 }
 for(i=0;i<s.length;i++){
  var c=s.charAt(i);
  if((c==decimalPointDelimiter)&&!seenDecimalPoint){
   seenDecimalPoint=true;
  }
  else if(!isDigit(c)){
   return false;
  }
 }
 return true;
}
function isDigit(c){
 return((c>="0")&&(c<="9"));
}
function stripWhitespace(s){
 return stripCharsInBag(s,whitespace);
}
function stripCharsInBag(s,bag){
 var i;
 var returnString="";
 for(i=0;i<s.length;i++){
  var c=s.charAt(i);
  if(bag.indexOf(c)==-1){
   returnString+=c;
  }
 }
 return returnString;
}
function isYear(s){
 if(isEmpty(s)){
  return false;
 }
 if(!isInteger(s)){
  return false;
 }
 return(s.length==4);
}
function isIntegerInRange(s,a,b){
 if(isEmpty(s)){
  return false;
 }
 if(!isInteger(s)){
  return false;
 }
 var num=parseInt(s,10);
 return ((num>=a)&&(num<=b));
}
function isMonth(s){
 if(isEmpty(s)){
  return false;
 }
 else{
  return isIntegerInRange(s,1,12);
 }
}
function isDay(s){
 if(isEmpty(s)){
  return false;
 }
 else{
  return isIntegerInRange(s,1,31);
 }
}
function daysInFebruary(year){
 return(((year%4==0)&&((!(year%100==0))||(year%400==0)))?29:28);
}
function isDate(month,day,year){
 if(!(isYear(year,false)&&isMonth(month,false)&&isDay(day,false))){
  return false;
 }
 var intYear=parseInt(year,10);
 var intMonth=parseInt(month,10);
 var intDay=parseInt(day,10);
 if(intDay>daysInMonth[intMonth]){
  return false;
 }
 if((intMonth==2)&&(intDay>daysInFebruary(intYear))){
  return false;
 }
 return true;
}
function selectField(theField){
 theField.select();
}
function stripBegEndSpaces(field){
 var pos=0;
 var interString="";
 var finalString="";
 while(pos<field.value.length&&field.value.charAt(pos)==" "){
  pos++;
 }
 while(pos<field.value.length){
  interString+=field.value.charAt(pos);
  pos++;
 }
 var cnt=interString.length-1;
 while(cnt>0&&interString.charAt(cnt)==" "){
  cnt--;
 }
 var index=0;
 while(index<=cnt){
  finalString+=interString.charAt(index);
  index++;
 }
 field.value=finalString;
}
function focusField(field,radio,values){
 var value=getRadioButtonValue(radio);
 var a=values.split(';');
 for(i=0;i<a.length;i++){
  if(a[i]==value){
   return false;
  }
 }
 field.blur();
 return true;
}
function checkBadCharsField(field,fieldName){
 for(var i=0;i<field.value.length;i++){
  if(field.value.charAt(i)=="="){
   addError(fieldName+" cannot have a '=' character.");
   break;
  }
  if(field.value.charAt(i)=="|"){
   addError(fieldName+" cannot have a '|' character.");
   break;
  }
 }
 return;
}
function checkBadCharsForm(form){
 for(var i=0;i<form.elements.length;i++){
  if((form.elements[i].type=="text")||(form.elements[i].type=="password")){
   checkBadCharsField(form.elements[i],form.elements[i].name);
  }
 }
}
function validPassword(pwd){
 var letters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 var letterCount=0;
 var digits="0123456789";
 var digitCount=0;
 for(i=0;i<pwd.length;i++){
  var c=pwd.charAt(i);
  if(letters.indexOf(c)>=0){
   letterCount++;
  }
  if(digits.indexOf(c)>=0){
   digitCount++;
  }
  if((letterCount>=1)&&(digitCount>=1)){
   return true;
  }
 }
 return false;
}
function checkRadioButtonChecked(radio){
 for(var i=0;i<radio.length;i++){
  if(radio[i].checked==true){
   return true;
  }
 }
 return false;
}
function getRadioButtonValue(radio){
 var found=false;
 for(var i=0;i<radio.length;i++){
  if(radio[i].checked==true){
   found=true;
   break;
  }
 }
 if(found){
  return radio[i].value;
 }
 else{
  return "";
 }
}
function isRadioButtonOption(radio,value)
{
 for(var i=0;i<radio.length;i++){
  if(radio[i].value==value){
   return true;
  }
 }
 return false;
}
function setRadioButtonChecked(radio,value){
 for(vari=0;i<radio.length;i++){
  if(radio[i].value==value){
   radio[i].checked=true;
   return true;
  }
 }
 return false;
}
function clearRadioButton(radio){
 for(var i=0;i<radio.length;i++){
  radio[i].checked=false;
 }
 return;
}
function setRadioButtonState(radio,value,enabled){
 for(var i=0;i<radio.length;i++){
  if(radio[i].value==value){
   radio[i].disabled=!enabled;
   return true;
  }
 }
 return false;
}
function getSelectValue(select){
 return select.options[select.selectedIndex].value;
}

/* This is the global Pop-Up window function
function openWindow(theURL,winName,features)
	{
  		window.open(theURL,winName,features);
	}*/

/* Disable Stus Bar message on ALL links */
function hidestatus(){
	window.status=''
	return true
}

/* Pick School */
function jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function jumpMenuGo(selName,targ,restore){
  var selObj = MM_findObj(selName); if (selObj) jumpMenu(targ,selObj,restore);
}

function openWindow(HREF, Name) {
	var pixelHeight=600;
	var pixelWidth=717;
	var CenteredX = (screen.width - pixelWidth) / 2;
	var CenteredY = (screen.height - pixelHeight) / 3;
	window.open(HREF,Name,'top='+CenteredY+',left='+CenteredX+',height='+pixelHeight+',width='+pixelWidth+',scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=no');
}

function openResizableWindow(HREF, Name) {
	var pixelHeight=600;
	var pixelWidth=717;
	var CenteredX = (screen.width - pixelWidth) / 2;
	var CenteredY = (screen.height - pixelHeight) / 3;
	window.open(HREF,Name,'top='+CenteredY+',left='+CenteredX+',height='+pixelHeight+',width='+pixelWidth+',scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=yes');
}

function openWindowSize(HREF, Name, w, h) {
	var pixelHeight=h;
	var pixelWidth=w;
	var CenteredX = (screen.width - pixelWidth) / 2;
	var CenteredY = (screen.height - pixelHeight) / 3;
	window.open(HREF,Name,'top='+CenteredY+',left='+CenteredX+',height='+pixelHeight+',width='+pixelWidth+',scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=no');
}

function formatMoney(fieldObj){
	var i;
	var s='0'+fieldObj.value;
	var s2='';
	var stripChars="~`!@#$%^&*()_-+={[}]|'\":;?/><,abcdefghijklmnopqrstuvwxyz";
	for(i=0;i<s.length;i++){ var c=s.charAt(i); if(stripChars.indexOf(c)==-1){ s2+=c; } }
	s2=s2*100/100;
	if(parseFloat(s2)){
    	if(s2==Math.round(s2)){ s2+=".00"; }
   		else{ s2=s2+"0"; s2=(s2.substring(0,(s2.indexOf(".")+3))) }
  	}else{ s2="0.00" }
	fieldObj.value=s2;
}

function formatPIN(fieldObj){
	var i;
	var s='0'+fieldObj.value;
	var s2='';
	var stripChars="~`!@#$%^&*()_-+={[}]|'\":;?/><,abcdefghijklmnopqrstuvwxyz";
	for(i=0;i<s.length;i++){ var c=s.charAt(i); if(stripChars.indexOf(c)==-1){ s2+=c; } }
	s2=parseInt(s2*100/100);
	if(s2==0) s2='';
	fieldObj.value=s2;
}

function formatFloat(fieldObj){
	var i;
	var s='0'+fieldObj.value;
	var s2='';
	var stripChars="~`!@#$%^&*()_-+={[}]|'\":;?/><,abcdefghijklmnopqrstuvwxyz";
	var precision=(formatFloat.arguments.length==1)?2:formatFloat.arguments[1];
	var precisionMask='';
	for(i=0;i<precision;i++){ precisionMask+="0"; }
	for(i=0;i<s.length;i++){ var c=s.charAt(i); if(stripChars.indexOf(c)==-1){ s2+=c; } }
	var roundingValue=parseInt("1"+precisionMask+"0");
	s2=(s2*roundingValue)/roundingValue;
	if(parseFloat(s2)){
    	if(s2==Math.round(s2)){ s2+="."+precisionMask; }
   		else{ s2=s2+precisionMask; s2=(s2.substring(0,(s2.indexOf(".")+(precision+1)))) }
  	}else{ s2="0."+precisionMask; }
	fieldObj.value=s2;
}

function getLayer(name){
	 if (document.all){
	    return document.all[name].style;
	  }else if (document.layers){
	    return document.layers[name];
	  }else return false;
}

function setLayerVisibility(layerID,desiredStatus){
	i=getLayer(layerID);
	i.visibility=desiredStatus;
	return true;
}

//------------------------------------------------------------------------------
// toggleMenu
//
// 	Hides/shows the menu div
//------------------------------------------------------------------------------
function toggleMenu(menuID,status){
	//alert(menuID);
	var theElement=document.getElementById(menuID);

	// clear the time out variable
	timeOutMenu=null;

	if (status == "inline"){
		theElement.style.display=status;

		// position the element
		var source=event.srcElement;
		var xCoord=source.offsetX;
		var yCoord=source.offsetY;
		placeMenuDiv(theElement, xCoord, yCoord);
	} else {
		timeOutMenu=window.setTimeout("turnMenuOff('"+menuID+"')", 100);
	}
}

//------------------------------------------------------------------------------
// turnMenuOff
//
// 	Hides/shows the menu div
//------------------------------------------------------------------------------
function turnMenuOff(menuID){
	var theElement=document.getElementById(menuID);
	theElement.style.display="none";
}

//------------------------------------------------------------------------------
// clearWinTimeout
//
// 	this clears the timeout of the currently visible menu div, using the global
//	var 'timeOutMenu'
//------------------------------------------------------------------------------
function clearWinTimeout(){
	window.clearTimeout(timeOutMenu);
}

//------------------------------------------------------------------------------
// placeMenuDiv
//
// 	Position an object at a specific pixel coordinate
//------------------------------------------------------------------------------
function placeMenuDiv(obj, x, y) {
	var theObj = document.getElementById(obj.id);

	if (theObj) {
		if (isW3C) {
			// equalize incorrect numeric value type
			var units = typeof(theObj.left == "string") ? "px" : 0;
			theObj.left = x+units;
			theObj.top = y+units;
		} else if (isNN4) {
			theObj.moveTo(x,y);
		}
	}
}

function openAccount(url){
	var w=766;
	var h=screen.height*0.75;
	var winl=(screen.width-w)/2;
	var wint=((screen.height-h)/2)*0.75;
	window.open(url,'openAccount','height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,menubar=no,status=yes,toolbar=no,resizable=no,location=yes'); //rramaiah: added 'location'
}

//------------------------------------------------------------------------------
// safePrint
//
// 	Prints the current window only if the print() function is supported. If not,
//  an alert instructs the user how to print the page.
//------------------------------------------------------------------------------
function safePrint() {
	if (window.print) {
		window.print();
	}
	else {
		alert("To print this page, choose 'Print' from the 'File' menu.");
	}
}

//------------------------------------------------------------------------------
// capFirstLetter
//
// 	This takes a string of words and converts the first letter to uppercase.
//  This function is used for input fields for Name, city, etc.
//------------------------------------------------------------------------------
function capFirstLetter(element){
	var theValue=element.value;
	// without the callback function the replace does not work (???)
	var newString=theValue.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});

	// write the new value to the form field
	element.value=newString;
}

function selectFieldValue(formName,fieldName,val){
	var i,frmObj,fieldObj,fieldLength;
	frmObj=document.all[formName];
	fieldObj=frmObj[fieldName];
	fieldLength=fieldObj.options.length;
	for(i=0;i<fieldLength;i++){
		if(fieldObj.options[i].value==val)
			fieldObj.options[i].selected=true;
	}
}

function goToStep(href,queryString){
	// if there is a query string specified, then run it
	if (arguments.length == 2){
		document.location.href=href+'.asp'+'?'+queryString;
	} else {
		document.location.href=href+'.asp';
	}
}


function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function printYesterday(mask,numberofDays){
	var date=new Date();
	if (arguments.length < 2){
		var numberofDays=1;
	}
	var numHours=numberofDays*24;
	var date=new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) - numHours*60*60*1000);
	var string=date.toString();
	var theMonth=string.substring(4,7);
	var theDate=string.substring(8,10);
	var theYear="";

	if (mask == "mm dd, yyyy"){
		theYear=string.substring(23,28);
		document.write(theMonth+" "+theDate+", "+theYear);
	} else if (mask == "mm/dd/yy"){
		theYear=string.substring(26,28);
		switch (theMonth){
			case 'Jan': thisMonth=01; break
			case 'Feb': thisMonth=02; break
			case 'Mar': thisMonth=03; break
			case 'Apr': thisMonth=04; break
			case 'May': thisMonth=05; break
			case 'Jun': thisMonth=06; break
			case 'Jul': thisMonth=07; break
			case 'Aug': thisMonth=08; break
			case 'Sep': thisMonth=09; break
			case 'Oct': thisMonth=10; break
			case 'Nov': thisMonth=11; break
			case 'Dec': thisMonth=12; break
		}
		document.write(thisMonth+"/"+theDate+"/"+theYear);
	} else {
		document.write("Spec. mask");
	}
}

function printTomorrow(mask,numberofDays){
	var date=new Date();
	if (arguments.length < 2){
		var numberofDays=1;
	}
	var numHours=numberofDays*24;
	var date=new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) + numHours*60*60*1000);
	var string=date.toString();
	var theMonth=string.substring(4,7);
	var theDate=string.substring(8,10);
	var theYear="";

	if (mask == "mm dd, yyyy"){
		theYear=string.substring(23,28);
		document.write(theMonth+" "+theDate+", "+theYear);
	} else if (mask == "mm/dd/yy"){
		theYear=string.substring(26,28);
		switch (theMonth){
			case 'Jan': thisMonth=01; break
			case 'Feb': thisMonth=02; break
			case 'Mar': thisMonth=03; break
			case 'Apr': thisMonth=04; break
			case 'May': thisMonth=05; break
			case 'Jun': thisMonth=06; break
			case 'Jul': thisMonth=07; break
			case 'Aug': thisMonth=08; break
			case 'Sep': thisMonth=09; break
			case 'Oct': thisMonth=10; break
			case 'Nov': thisMonth=11; break
			case 'Dec': thisMonth=12; break
		}
		document.write(thisMonth+"/"+theDate+"/"+theYear);
	} else {
		document.write("Spec. mask");
	}
}

function printToday(){
	var today=new Date();
	theDate = today.getDate();
	theMonth = today.getMonth();
	theMonth = theMonth+1;
	theYear = today.getYear();
	var theYearString=theYear.toString();
	theYear=theYearString.substring(2,4);

	document.write(theMonth+"/"+theDate+"/"+theYear);
}