var undefined;	// to use in expression to determ the variable's existence.
popUp="resizable=no, scrollbar=yes, menubar=no, toolbar=no,top=400,left=400";// std popup window attributes
var browserType;
browser = (		// browser type - 1 microsoft specific, 2 - netscape specific
	((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >=6 ))
	||
	((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ))
	||
	((navigator.appName == "Opera") && (parseInt(navigator.appVersion) >= 7 ))
);

if ( browser  )  
{
	// microsoft specific
	browserType = 1;
}
else 
{
	// netscape
	browserType = 2

}
	/**********************************************************************************************
		Pavel Treinis 4.13.2006
		checkData() used to transform FORMs data diring form submition time.		
		To make an INPUT tag to work with this function put into it an attribut "action" like:
			<INPUT ... action="UTQ" .. value=" my ' example " >
		If during submition time to call checkData() function, then it trunsforms the value  
		" my ' example " 
			to 
		"MY '' EXAMPLE "
		
		Function allows to transform values of input tags as:
		  Char  Function
			 U to upper case
			 L to lower case
			 T to trim text
			 Q to replace a every single quotes in the text to two single quotes. To use in SQL statements.
			   
		Function tested with MS explorer, Mozila and Firefox.
				
		last updated:	PGT 4.13.06 Initial revision.		
	******************************************************************************************/
	function checkData( oFrm )
	{
		try{
		var all = oFrm.getElementsByTagName("input");				
		for (var i=0; i< all.length; i++)
		{
			var sVal = all[i].getAttribute("action");
			if ( sVal != null )
			{
				if ( sVal.indexOf("U") >=0)
					all[i].value = all[i].value.toUpperCase();
				if ( sVal.indexOf("L") >=0)
					all[i].value = all[i].value.toLowerCase();					
				if ( sVal.indexOf("Q") >=0)
				{
					all[i].value = all[i].value.replace(/'/g,"''");
					all[i].value = all[i].value.replace(/''''/g,"''");					
				}
				if ( sVal.indexOf("T") >=0)
					all[i].value = trim(all[i].value);							
			}
		}
		return true;
		}catch(e){alert(e.description)}
		return false;
	}	
	// pgt 11.14.08
	function checkEmail(emailaddress) {
		var email = document.getElementsByName(emailaddress);
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
		if ( email.length > 0 ){
			if (!filter.test(email[0].value)) {
				alert("Please provide a valid email address");
				email[0].focus();
				return false;
			}
		}
		return true;
	}//checkEmail
	// pgt 11.14.08
	function checkPhone(phoneNumber) 
   {
		var phone = document.getElementsByName(phoneNumber);
	   	var phoneRE = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/; 			
		if ( phone.length > 0 ){
			if (!phoneRE.test(phone[0].value)) {
				alert("Please provide a valid phone number. Like: (nnn)nnn-nnnn");
				phone[0].focus();
				return false;
			}
		}
		return true;
  }//checkPhone
	
/********************************************************** 
	Radio button related function 
	PGT 1.27.06
***********************************************************/
/*
	rb_getValue( sRB_Name ) returns selected radio button value or null.	 
	Parametrs
			sRB_Name - radio button grop's name.( value of "name" property 
*/
function rb_getValue( sRB_Name ) 
{	
	var oRB = docAll( sRB_Name );
	return ( oRB == null?  null : rb_getValue2( oRB, null ) );
}

/*
	rb_getValue( oRB ) returns selected radio button value or null.	 
	Parametrs
			oRB			- result of call to docAll( RB_Name ). RB_Name - radio button grop's name.( value of "name" property 
			uDefReturn	- return value when no one radio button selected.
*/
function rb_getValue2( oRB, uDefReturn )
{
	try{
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < oRB.length; counter++)	
		if ( oRB[counter] != undefined && oRB[counter].checked )
			return oRB[counter].value;
	}catch(e){alert( "rb_getValue2." + e.description);}			
	return uDefReturn;
} 

function rb_CheckedIndex( sRB_Name ) 
{	
	var oRB = docAll( sRB_Name );
	return ( oRB == null?  -1 : rb_CheckedIndex2( oRB ) );
}
function rb_CheckedIndex2( oRB  )
{
	try{
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < oRB.length; counter++)	
		if ( oRB[counter] != undefined && oRB[counter].checked )
			return counter;
			
	}catch(e){alert( "rb_getValue2." + e.description);}			
	return -1;
} 
/**********************************************************************************************
		PGT TimeTracker.
		OnKeyPressed() use to allow enter only numeric values in textboxes
		Paramatrs:
				o 		- text box object
				event	- last event
		last updated:	PGT 12.1.04 Initial revision.		
		Example of usage:
			<INPUT type="textbox" id="HrPerDay" type_="D" disabled  onKeyUp="OnKeyPressed(this)"  name="HrPerDay" value="10" maxsize=5 size=3> hours per day
	******************************************************************************************/
/*	<script type="text/javascript">
document.onkeyup = KeyCheck;       

function KeyCheck(e)
{
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   switch(KeyID)
   {
      case 16:
      document.Form1.KeyName.value = "Shift";
      break;       case 17:
      document.Form1.KeyName.value = "Ctrl";
      break;      case 18:
      document.Form1.KeyName.value = "Alt";
      break;      case 19:
      document.Form1.KeyName.value = "Pause";
      break;      case 37:
      document.Form1.KeyName.value = "Arrow Left";
      break;      case 38:
      document.Form1.KeyName.value = "Arrow Up";
      break;      case 39:
      document.Form1.KeyName.value = "Arrow Right";
      break;      case 40:
      document.Form1.KeyName.value = "Arrow Down";
      break;   }
}</script> 
*/

function OnKeyPressed( o ){
try{
	if ( browserType != 1)	event=Event;
	if ( browserType != 1 || arguments.length >1)
	{

		if ( arguments.length > 1) o.type_ 		=  arguments[1];		
		if ( arguments.length > 2) o.minvalue 	=  arguments[2];
		if ( arguments.length > 3) o.maxvalue 	=  arguments[3];
	//	alert(window.event)

	}

	if( event.keyCode == 9 || (event.keyCode >= 36 && event.keyCode <= 40) )
			return;
		//function autoTab(input,len, e)

		if ( o.type_ != undefined)
		{
			switch (o.type_)			
			{
			 case 'GPA':

				o.value = trim(o.value);
				if ( o.value.length == 1 && "ABCDF".indexOf(o.value.toUpperCase()) >= 0 )
				{	o.value = o.value.toUpperCase()
					break;				
				}
			 case 'D':	// decimal			
				o.value =o.value.replace(/[^0-9,^.]/g,'');	

				for (var i=1; i<o.value.length && o.value.substr(i-1,1)=='0';i++);
				if (i>1)
					o.value = o.value.substr(i-1);
				
				if ( o.maxvalue != undefined && parseFloat(o.maxvalue) < parseFloat(o.value) ){
					o.value = o.maxvalue;				
				}
				if ( o.minvalue != undefined && parseFloat(o.minvalue) < parseFloat(o.value) )
					o.value = o.minvalue;									
/*				try{ 
			
					eval(funcName+"()")

				if ( typeof funcName == "function" )
					funcName;
				}catch(e){ alert(e.description)}					
*/					
				 break;
			 case 'N':
				o.value =o.value.replace(/[^0-9]/g,'');	

//				for (var i=1; i<o.value.length && o.value.substr(i-1,1)=='0';i++);
	//			if (i>1)
		//			o.value = o.value.substr(i-1);
				if ( o.size !=undefined && o.size>0){
					if (o.value.length > o.size)
						o.value = o.value.substr(o.value.length - o.size);
				}

				if ( o.maxvalue != undefined && parseInt(o.maxvalue) < parseInt(o.value) ){
					alert("Max value for this field is "+o.maxvalue);
					o.value = o.maxvalue;
					o.focus();
				}
				if ( o.minvalue != undefined && (parseInt(o.minvalue) > parseInt(o.value)) ){
					alert("Min value for this field is "+o.minvalue);					
					o.value = o.minvalue;
					o.focus();
				}
/*							pgt 1.6.10
				else
					if ( browserType == 1){
						if ( o.minvalue != undefined && parseInt(o.minvalue) < parseInt(o.value) ){
							alert("Minvalue for this field is "+o.minvalue);
						o.value = o.maxvalue;
						o.focus();
					}
					if (o.value.length == o.size && o.nextField != undefined ){
						if ( o.minvalue != undefined && (parseInt(o.minvalue) < parseInt(o.value)) )
							o.value = o.minvalue;
						document.getElementById(o.nextField).focus();
					}
				}
*/
		//commented because do not allows to enter any values - repl it with min value	
		//	if ( o.minvalue != undefined && parseInt(o.minvalue) > parseFloat(o.value) )
			//		o.value = o.minvalue;									
				 break;
				 
			}
		}
		if ( o.default_ != undefined && Trim(o.value).length == 0)
				o.value = o.default_;		
		}catch(e){;}									

	}
	/**********************************************************************************************
		Pavel Treinis 5.5.2005
		showObj() shows object's property names and values in the alphabeticle order.
		Paramatrs:
				object
		last updated:	PGT 4.1.05 Initial revision.		
	******************************************************************************************/
	function showObj(obj)
	{	try{
		var names = "", aNames= new Array();

//		alert(eval("obj.offsetX"));
//		return;
		for(var Name in  obj )
		{	try{
			if ( Name.indexOf("HTML")>=0 ||
				 Name.indexOf("outerText")>=0 ||
				 Name.indexOf("innerText")>=0  )
				 aNames.push( Name);
			else
			{
			 s=eval("obj."+Name); 
			if ( s.indexOf("function") == 0 )
			 aNames.push( Name +"=..;");
			else
			 aNames.push( Name +"="+s);
			 }
			}catch(e){aNames.push( Name);}					 
		}
		aNames.sort();
		
		alert(aNames.join("\t") ) ;
		
		}catch(e){alert( "dispObj." + e.description);}		
		
	}
	/* PGT */
	function docAll( sName )
	{
		try{
		var o = document.getElementsByName(sName);
	
		if ( o.length == 0 && ! browser )
		     o = document.getElementById(sName);
		if ( o.length == 0 )
			return null;
		else if ( o.length == 1 )
			return o[0];
	
		return o; 	
		}catch(e){ ;}
		return null;
	}	

	function NotLess(name,param){
		if (name.length < param){
			return(false);
		} else 
			return(true);
	}

	function NotMore(name,param){
		if (name.length > param){
			return(false);
		} else 
			return(true);
	}
	
	function IsEmpty(nameIn){
		if (nameIn.length == 0) {
			return false;
		} else 
		return true;
	}
		
	// function checked for at least one numeric and one alpha character
	function IsAlphaNimeric(name)
	{
		var strTempl="[0-9]{1,10}[A-z]{1,10}|[A-z]{1,10}[0-9]{1,10}";
		if ( name.match(strTempl)== null){
			return(false);
		}else
			return(true);
	}	
	// PGT 12/11/09 FUNCTION TO TEST NAMES
	var rgName = /^[a-zA-z'-., ]+$/;
	function IsRightName(name){
		return rgName.test(name);
	}
	
	function IsName(name)
	{
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,' '-";
	  var allValid = true;
	  for (i = 0;  i < name.length;  i++)
	  {
	   	ch = name.charAt(i);
	    	for (j = 0;  j < checkOK.length;  j++)
			{
	      	if (ch == checkOK.charAt(j))
	        	break;
	    		if (j == checkOK.length)
	    		{
	      		allValid = false;
	      		break;
	    		}
			}
	  }
	  
	  if (!allValid)
	  {
	    return (false);
	  }
	}			
	/*function IsAlpha(name)
	{
		return /^[a-zA-z-]+$/.test(name)
	}*/
	
	function IsAlpha(name)
	{
	  flg=0;
	  str="";
	  spc=""
	  arw="";
	  for (var i=0;i<name.length;i++)
	  {
	   cmp="0123456789"
	   tst=name.substring(i,i+1)
	   if (cmp.indexOf(tst)>0)
		{
	    flg++;
	    str+=" "+tst;
	    spc+=tst;
	    arw+="^";
	   }
	   else{arw+="_";}
	  }
	  if (flg!=0){
	   if (spc.indexOf(" ")>-1) {
	    str+=" and a space";
	    }
	   return(false)
	  }
	}

	function IsAlpha_(name)
	{
	  flg=0;
	  str="";
	  spc=""
	  arw="";
	  for (var i=0;i<name.length;i++)
	  {
	   cmp="0123456789"
	   tst=name.substring(i,i+1)
	   if (cmp.indexOf(tst)>0)
		{
	    flg++;
	    str+=" "+tst;
	    spc+=tst;
	    arw+="^";
	   }
	   else{arw+="_";}
	  }
	  if (flg!=0){
	   if (spc.indexOf(" ")>-1) {
	    str+=" and a space";
	    }
	   return(false)
	  }
	}
	
	 function IsAllZero(name){
	  flg=0;
	  str="";
	  spc=""
	  arw="";
	  for (var i=0;i<name.length;i++){
	   cmp="123456789"
	   tst=name.substring(i,i+1)
	   if (cmp.indexOf(tst)<0){
	    flg++;
	    str+=" "+tst;
	    spc+=tst;
	    arw+="^";
	   }
	   else{arw+="_";}
	  }
	  if (flg!=0){
	   if (spc.indexOf(" ")>-1) {
	    str+=" and a space";
	    }
	   return(false)
	  }
	}
	
	function trim(str) {
  	var re=/^\s*|\s*$/g;
		 return str.replace(re, "");
	 }//trim()
	 
	 function IsInteger( p ){ 
	 try{ 
	  var s = trim(p).match(/[^0-9]/g );
	  return ( s==null );
	  }catch(e){}
	  return false;
	 }//IsInteger()
	 
	function IsListOfIntegers( p ){ 
	 try{ 
	  var s = trim(p).match(/[^0-9,^,]/g );
	  return ( s==null );
	  }catch(e){}
	  return false;
	 }//IsInteger()
	 
	function IsNumeric(name){
	  flg=0;
	  str="";
	  spc=""
	  arw="";
	  for (var i=0;i<name.length;i++){
	   cmp="0123456789"
	   tst=name.substring(i,i+1)
	   if (cmp.indexOf(tst)<0){
	    flg++;
	    str+=" "+tst;
	    spc+=tst;
	    arw+="^";
	   }
	   else{arw+="_";}
	  }
	  if (flg!=0){
	   if (spc.indexOf(" ")>-1) {
	    str+=" and a space";
	    }
	   return(false)
	  }
	}
		
	function IsSpace(name) {
		if ((name.indexOf(" ")!=-1)) {
	   		return(false);
			}
 	}

	function IsAdSign(name) {
		 if ((name.indexOf("@")==-1)) {
	   		return(false);
			}
 	}
	
	function IsDash(name) {
		 if ((name.indexOf("-")==-1)) {
	   		return(false);
			}
 	}
	
	
	function IsWWW(name) {
		 if ((name.indexOf("www")==-1)||(name.indexOf("WWW")==-1) ) {
	   		return(false);
			}
 	}
		 
	function CheckPrefix(name){ 
			var name=name.toLowerCase();
			if ((name.indexOf(".com")<5)&&(name.indexOf(".org")<5)&&(name.indexOf(".gov")<5)&&(name.indexOf(".net")<5)&&(name.indexOf(".mil")<5)&&(name.indexOf(".edu")<5)&&(name.indexOf(".pl")<5)&&(name.indexOf(".us")<5)&&(name.indexOf(".state")<5)){
		    return(false);
		 }
	 }
	 
	 function isInt(myNum) {
        // get the modulus: if it's 0, then it's an integer
        var myMod = myNum % 1;

        if (myMod == 0) {
             return true;
        } else {
             return false;
        }
	}

		
		
	function IsSymbols(name){
		  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		  var allValid = true;
		  for (i = 0;  i < name.length;  i++)
		  {
		    ch = name.charAt(i);
		    for (j = 0;  j < checkOK.length;  j++)
		      if (ch == checkOK.charAt(j))
		        break;
		    if (j == checkOK.length)
		    {
		      allValid = false;
		      break;
		    }
		  }
		  if (!allValid)
		  {
		    return (false);
		  }
	}		
		
	function redirect(myurl){
		document.location.href=myurl
	}
		
	/*function IsDate(name) {
		 if (chkDate(name) == false) {
		 return false;
		}
	}

	function chkDate(name) {
			var strDatestyle = "US"; //United States date style    mm/dd/yyyy
			var strDate;
			var strDateArray;
			var strDay;
			var strMonth;
			var strYear;
			var intday;
			var intMonth;
			var intYear;
			var err = 0;
			var errFound = false;
			//var datefield = name;
			var strSeparatorArray = new Array("/");
			var intElementNr;
			//strDate = name;
		
		if (name.length != 10) {
		 return false;
		}
		
		for (intElementNr = 0; intElementNr < strSeparatorArray.length;
		intElementNr++) {
		
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
		 strDateArray = strDate.split(strSeparatorArray[intElementNr]);
		 if (strDateArray.length != 3) {
		  err = 1;
		  return false;
		 }
		 else {
		  strDay = strDateArray[0];
		  strMonth = strDateArray[1];
		  strYear = strDateArray[2];
		 }
		errFound = true;
		}
		}
		
		if (errFound == false) {
		if (strDate.length>5) {
		 strDay = strDate.substr(0, 2);
		 strMonth = strDate.substr(2, 2);
		 strYear = strDate.substr(4);
		}
		}
		
		if (strYear.length != 4) {
		return false;
		}
		// US style
		if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
		}
		
		intday = parseInt(strDay, 10);
		if (isNaN(intday)) {
		 return false;
		}
		
		intMonth = parseInt(strMonth, 10);
		if (isNaN(intMonth)) {
		 err = 3;
		return false;
		}
		
		intYear = parseInt(strYear, 10);
		if (isNaN(intYear)) {
		 return false;
		}
		
		if (intMonth>12 || intMonth<1) {
		 return false;
		}
		
		if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 ||
		intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 ||
		intday < 1)) {
		 return false;
		 }
		if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11)
		&& (intday > 30 || intday < 1)) {
		 return false;
		 }
		
		if (intMonth == 2) {
		 if (intday < 1) {
		 return false;
		 }
		 if (LeapYear(intYear) == true) {
		  if (intday > 29) {
		  return false;
		  }
		 }
		 else {
		  if (intday > 28) {
		  return false;
		  }
		 }
		}
		}
		
	function LeapYear(intYear) {
		if (intYear % 100 == 0) {
		 if (intYear % 400 == 0) {return true;}
		 }
		else {
		 if ((intYear % 4) == 0) {return true;}
		 }
		return false;
	}*/
		
	function Capitalize_FirstLetter(fieldReference){

     var field = fieldReference
     var tempString = new String("")
     var tempChar = new String("")
     var newString= new String("")

     tempString = field.value.toLowerCase()
     var tempStringLength = tempString.length

     for (i = 0; i <= tempStringLength; i++){

          if (i == 0){
               tempChar = tempString.charAt(i)
               newString += tempChar.toUpperCase()
          }else {
               if (tempString.charAt(i - 1) == " "){
                    tempChar = tempString.charAt(i)
                    newString += tempChar.toUpperCase()
               }else if (tempString.charAt(i - 1) == "-"){
                    tempChar = tempString.charAt(i)
                    newString += tempChar.toUpperCase()
               }
               else {
                    tempChar = tempString.charAt(i)
                    newString += tempChar
               }
          }
     }
     field.value = newString
}	
	
	
function autoTab(input,len, e) {
		var isNN = (navigator.appName.indexOf("Netscape")!=-1);
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
		
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
		return found;
	}
	
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
			return index;
		}
	return true;
	}

	function verify() {
		if 
			(confirm('Once you click on the submit button, your order will\nbe placed. If you would like to modify your\norder now, click `Cancel`.'))
			return true;
		else
			return false;
	} 
	
	   //chage url
     function changeUrl()
		 {
		 	//variable to store Form Elements
       var sField;          
			 //variable for making URL       
       sUrl = new String("");  
        for(i=0;i<document.forms[0].length;i++) {
          //take form's element in the variable
          sField = document.forms[0].elements[i];
          //construct the URL
			if((sField.name!='Reset')&& (sField.name!='Submit')&& (sField.name!='Cancel')&& (sField.name!='Preview')) {
         	//sUrl = sUrl + "|" + sField.value;
				sUrl = sUrl + "|" + sField.name + "=" + sField.value;
			}
						//trim the last "|"
           //sUrl = sUrl.substring(1,sUrl.length);
      	}		
				return sUrl
      }

		//open popup window located in the middle of the screen
		function centerPopUp(myurl,w,h)
		{
	    	if (document.all)
	        	var xMax = screen.width, yMax = screen.height;
	   		else  	if (document.layers)
	           	var xMax = window.outerWidth, yMax =
				 			window.outerHeight;
	        	else
	            var xMax = 640, yMax=480;
	    		var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
					
					strUrl=changeUrl()
					result=(window.open(myurl+"&lst="+strUrl,"Pop_Up","width="+w+",resizable=no, scrollbar=yes, menubar=no, toolbar=no, height="+h+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+", left="+xOffset+""));
		}
		
		//open popup window located in the middle of the screen
		function showPopUp(myurl,w,h)
		{
	    	if (document.all)
	        	var xMax = screen.width, yMax = screen.height;
	   		else  	if (document.layers)
	           	var xMax = window.outerWidth, yMax =
				 			window.outerHeight;
	        	else
	            var xMax = 640, yMax=480;
	    		var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
				result=(window.open(myurl,"Pop_Up","width="+w+",resizable=no, scrollbar=yes, menubar=no, toolbar=no, height="+h+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+", left="+xOffset+""));
		}
	/*****************************************************************************************
		 Pavel Treinis	02.12.07 
		 Show Web Page Printer friendly. 
		 Will open web page in the new window.
		 The portion on the Web Page wich needs to shown must be mark using <div name="Output">  tag.
		 Parts inside of the "Output" div which needs to be hided, must have id="Hide". 
	*****************************************************************************************/	
	function ShowPrinterFriendly2() {
			var height = window.screen.availHeight / 2;
			var width = 840;
			var top = (window.screen.availHeight / 2) - (height / 2);
			var left = window.screen.availWidth / 2 - (width / 2);
			var features = "width=" + width + ",height=" + height + ",scrollbars=yes,directories=no";
			features += ",location=no,menubar=yes,status=no,titlebar=no,toolbar=no,top=" + top;
			features += ",left=" + left;
			window.open("/includes/PrinterOutputN.cfm", "print", features);
	}//end function             


					
		function copyToParentFields(Value1) 
		{
       // read info from popup window and submit to email and flat file
			 result=document.location.href="qry_additem.cfm?action="+Value1
     }
		 
		 //colect info for school cost data
			function CostData(myurl)
			{
				strUrl=changeUrl()
				//alert(strUrl)
				location.href= myurl+"&lst="+strUrl
			}
			
			// for ascii codes see http://www.asciitable.com/

//
// **** screening functions **** //
//

//does not allow any characters to be entered into a text field except
//lowercase and uppercase letters
function screenNum(){
	if (event.keyCode < 65 || event.keyCode > 122 || event.keyCode == 91
			|| event.keyCode == 92 || event.keyCode == 93
			|| event.keyCode == 94 || event.keyCode == 95
			|| event.keyCode == 96)
				event.returnValue = false;}

//does not allow any characters to be entered into a text field except
//lowercase and uppercase letters - but WILL allow the single quote (39)
function screenNumSQuote(){
	if (event.keyCode < 65 || event.keyCode > 122 || event.keyCode == 91
			|| event.keyCode == 92 || event.keyCode == 93
			|| event.keyCode == 94 || event.keyCode == 95
			|| event.keyCode == 96)
	if (event.keyCode != 39)
				event.returnValue = false;}

//does not allow any characters to be entered into a text field except
//lowercase and uppercase letters - but WILL allow the space (32)
function screenNumSpace(){
	if (event.keyCode < 65 || event.keyCode > 122 || event.keyCode == 91
			|| event.keyCode == 92 || event.keyCode == 93
			|| event.keyCode == 94 || event.keyCode == 95
			|| event.keyCode == 96)
	if (event.keyCode != 32)
				event.returnValue = false;}


//does not allow any characters to be entered into a text field except
//lowercase and uppercase letters - but WILL certain special chars 
// 32 - space
// 39 - '
// 40 - (
// 41 - )
// 43 - +
// 45 - -
// 46 - .
// 47 - /
// 58 - :

function screenNumSpecial(){
	if (event.keyCode < 65 || event.keyCode > 122 || event.keyCode == 91
			|| event.keyCode == 92 || event.keyCode == 93
			|| event.keyCode == 94 || event.keyCode == 95
			|| event.keyCode == 96)
	if (event.keyCode != 32 || event.keyCode != 39 || event.keyCode != 40
			|| event.keyCode != 41 || event.keyCode != 43
			|| event.keyCode != 45 || event.keyCode != 46
			|| event.keyCode != 47 || event.keyCode != 58)
				event.returnValue = false;}



//does not allow any characters to be entered into a text field except
//lowercase letters - LOWERCASE ONLY
function screenNumLCase(){
	if (event.keyCode < 97 || event.keyCode > 122)
				event.returnValue = false;}		


//does not allow any characters to be entered into a text field except
//numbers and a decimal point
function screenAlpha(){
	if (event.keyCode < 46 || event.keyCode > 57 || event.keyCode == 47)
		event.returnValue = false;}

//screens to allow ONLY numerals, no special characters
function screenAlphaSpec(){
	if (event.keyCode < 48 || event.keyCode > 57)
		event.returnValue = false;}

//
// **** formatting functions **** //
//

//capitalizes initial character of alpha text field
function initCap(field){
	field.value = (field.value.charAt(0)).toUpperCase() + (field.value.toLowerCase()).substring(1);}

//capitalizes the initial letter of multiple words
function initCapWord(field){
	strFin = "";
	strNew = field.value;
	strSplit = strNew.split(" ");
	for (i=0; i<strSplit.length; i++){
		strNew = (strSplit[i].charAt(0)).toUpperCase() + (strSplit[i].toLowerCase()).substring(1);
		if(i == strSplit.length - 1)
			strFin = strFin + strNew;
		else
			strFin = strFin + strNew + " ";}
	field.value = strFin;}

//capitalizes the initial letter of multiple words
function initCapWordSQuote(field){
	strFin = "";
	strNew = field.value;
	strSplit = strNew.split("'");
	for (i=0; i<strSplit.length; i++){
		strNew = (strSplit[i].charAt(0)).toUpperCase() + (strSplit[i].toLowerCase()).substring(1);
		if(i == strSplit.length - 1)
			strFin = strFin + strNew;
		else
			strFin = strFin + strNew + "'";}
	field.value = strFin;}

//auto formats ssn's with dashes
function ssnFormat(field){
	if(event.keyCode == 8)
		field.value = field.value.substring(0, field.value.length);
	else{
		str = field.value;
		if(str.length == 3)
			str = str + '-';
		if(str.length == 6)
			str = str + '-';
		field.value = str;}}
		
//appends .00 to dollar amounts entered without decimals
function currFormat(field){
	if(field.value.indexOf(".") == -1)
		if(field.value == "")
			field.value;
		else
			field.value = field.value + ".00";}


// strips leading spaces for validation
function stripspaces(x) 
{
    while (x.substring(0,1) == ' ') x = x.substring(1);
    return x;
}

//  form field validation for empty text
function empty(x) { if (x.length > 0) return false; else return true; }


// form field validation for date field in format mm/dd/yyyy
function isvaliddate (mydate) 
{
	// setting seperator value
	var sep = "/";
	// checking for correct length
    if (mydate.length == 10) 
	{
		// checking if seperators are in place
        if (mydate.substring(2,3) == sep && mydate.substring(5,6) == sep) 
		{
			// checking valid months
			var month = 0;
			if(mydate.substring(0,2) > 0 && mydate.substring(0,2) < 13) month  = mydate.substring(0,2);
			// checking valid days
			var date = 0;
			if(month == 4 || month == 6 || month == 9 || month == 11)
			{
				if(mydate.substring(3,5) > 0 && mydate.substring(3,5) < 31) date  = mydate.substring(3,5);
			}
			else
			{
				if(mydate.substring(3,5) > 0 && mydate.substring(3,5) <= 31) date  = mydate.substring(3,5);
			}
			if(month == 2 && mydate.substring(3,5) > 29) date = 0;
			// checking valid year range
          	var year = 0;
			if(mydate.substring(6,10) > 0 && mydate.substring(6,10) < 2100) year  = mydate.substring(6,10);
			if (year != 0 && month != 0 && date != 0) 
			{
            	return true;
           	}
            else 
			{
                return false;
            }
        }
        else 
		{
            return false;
        }
    }
    else 
	{
        return false;
    }
}
		
// moving data in or out
function selectsome(list1,list2)
{
	for(x = 0; x < list1.options.length; x++)
	{
		if(list1.options[x].selected)
		{
			var tempopt = new Option(list1.options[x].text, list1.options[x].value,false,false);
			list2.options[list2.options.length] = tempopt;
			list2.options[list2.options.length-1].selected = false;
			list1.options[x] = null;
			x = x - 1;
		}
	}
	sortSelect(list2);
}

// moving all data in or out
function selectall(list1,list2)
{
	for(x=0; x<list1.options.length; x++)
	{
		var tempopt = new Option(list1.options[x].text, list1.options[x].value,false,false);
		list2.options[list2.options.length] = tempopt;
		list2.options[list2.options.length-1].selected = false;
		list1.options[x] = null;
		x = x - 1;
	}
	sortSelect(list2);
}

function sortSelect(obj) 
{
	var o = new Array();
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value);
		}
	}
	
// storing cursor location
function storecursor(txtarea)
{
	if (txtarea.createTextRange) 
	{
		txtarea.caretPos = document.selection.createRange().duplicate();
	}
}

// adding text to text area
function inserttext(txtarea, text)
{
	if (txtarea.createTextRange && txtarea.caretPos)
  	{
    	var caretPos = txtarea.caretPos;
    	caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
   	}
 	else
	{
   		//txtarea.value  = text;
	}
	
	txtarea.focus();
}

//--------ZIP CODE VALIDATION-----------------------------//
function isZipCode(field) {
	var valid = "0123456789-";
	var hyphencount = 0;

	if (field.length!=5 && field.length!=10) {
		alert("Warning! Please enter your 5 digit or 5 digit+4 zip code.");
		return false;
	}
	for (var i=0; i < field.length; i++) {
	temp = "" + field.substring(i, i+1);
	if (temp == "-") hyphencount++;
		if (valid.indexOf(temp) == "-1") {
			alert("Warning! Invalid characters in your zip code. Please try again.");
			return false;
		}
		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
			alert("Warning! The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'. Please try again.");
			return false;
	   }
	}
	return true;
}
//--------Phone VALIDATION-----------------------------//
function CheckPhoneNumber(TheNumber) {
	
	var valid = true
	var GoodChars = "0123456789()-+ "
	var i = 0
	if (TheNumber=="") {
		// Return false if number is empty
		valid = false
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
		// Note: Remove the comments from the following line to see this
		// for loop in action.
		// alert(TheNumber.charAt(i) + " is no good.")
		valid = false
		} // End if statement
	} // End for loop
	return valid
}


//..................fallowing three function - for phone number validation ........//
	// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


//display Popup window in the middle of the screen
function cPopUp(myurl,w,h)
	{
		if (document.all)
     		var xMax = screen.width, yMax = screen.height;
  		else
     		if (document.layers)
        		var xMax = window.outerWidth, yMax =window.outerHeight;
     		else{
            		var xMax = 640, yMax=480;
    				var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;
			}
			
		popup = window.open(myurl,"","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width="+w+",height="+h+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+", left="+xOffset+"")
		
		//popup = window.open("dsp_msg.cfm","","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=360,height=300")
	}

	
	function PopUp(myurl,w,h){
		popup = window.open(myurl,"","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width="+w+",height="+h+"")
	}
	
	
	//---------------------Date Validation-----------------------------------------------------------------//

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function isDateOK(dtStr){
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}

	if ((strYear.length != 4 && year==0 )||( year<minYear || year>maxYear)){
		alert("Please enter a valid 4 digit year")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// validte SSN number.
function SSNValidation(ssn) {
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	var numDashes = ssn.split('-').length - 1;
	if (matchArr == null || numDashes != 2) { // forse to put dashes
		//if (matchArr == null || numDashes == 1) { do not forse to put dashes
		//alert('Invalid SSN. Must be 9 digits or in the form NNN-NN-NNNN.');
		alert('Invalid SSN. Must be  in the form NNN-NN-NNNN.');
		return false
		//msg = "does not appear to be valid";
	}
	else 
		if (parseInt(matchArr[1],10)==0) {
		alert("Invalid SSN: SSN's can't start with 000.");
		return false;
		//msg = "does not appear to be valid";
	}
	else {
		//msg = "appears to be valid";
		//alert(ssn + "\r\n\r\n" + msg + " Social Security Number.");
		return true
	}
}

function checkdate(object_value)
    {
	    //Returns true if value is a date format or is NULL
	    //otherwise returns false	
	
	    if (object_value.length == 0){
	       return true;
		}
	    //Returns true if value is a date in the mm/dd/yyyy format
		var isplit = object_value.indexOf('/');
	
		if (isplit == -1 || isplit == object_value.length){
			alert("Warning! " + object_value + " is not in a valid date format.");
			return false;
		}
		
	    sMonth = object_value.substring(0, isplit);
	
		if (sMonth.length == 0){
	        return false;
		}
		
		var isplit = object_value.indexOf('/', isplit + 1);
	
		if (isplit == -1 || (isplit + 1 ) == object_value.length){
			alert("Warning! " + object_value + " is not in a valid date format.");
			return false;
		}
		
	    var sDay = object_value.substring((sMonth.length + 1), isplit);
	
		if (sDay.length == 0){
	        return false;
		}
		var sYear = trim(object_value.substring(isplit + 1));
		var minYear=1930;
		var time=new Date();
		var maxYear=time.getYear()+1;
		if (sYear.length != 0 && (  sYear<minYear || sYear>maxYear)) {		
<!--- 		if (sYear.length != 4 || sYear==0 || sYear<minYear || sYear>maxYear){ --->
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
			return false
		}
		
		if (!checkinteger(sMonth)){ //check month
			alert("Warning! Please specify valid month.");
			return false;
		}else{
			if (!checkrange(sMonth, 1, 12)){ //check month
				alert("Warning! Month must be between 1 and 12.");
				return false;
			}else{
				if (!checkinteger(sYear)){ //check year
					alert("Warning! Please specify valid year.");
					return false;
				}else{
					if (!checkinteger(sDay)){ //check day
						alert("Warning! Please specify valid day.");
						return false;
					}else{
						if (!checkday(sYear, sMonth, sDay)){ // check day
							alert("Warning! " + object_value + " is not in a valid date format.");
							return false;
						}else{
							return true;
						}
					}
				}
			}
		}
	}
	
function checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return checkrange(checkDay, 1, maxDay); //check day
    }



function checkinteger(object_value)
    {
	    //Returns true if value is a number or is NULL
	    //otherwise returns false	
	
	    if (object_value.length == 0)
	        return true;
	
	    //Returns true if value is an integer defined as
	    //   having an optional leading + or -.
	    //   otherwise containing only the characters 0-9.
		var decimal_format = ".";
		var check_char;
	
	    //The first character can be + -  blank or a digit.
		check_char = object_value.indexOf(decimal_format)
	    //Was it a decimal?
	    if (check_char < 1)
			return checknumber(object_value);
	    else
			
			return false;
    }

function numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }

function checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }

function checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }
	
//---------TRIM STRING Function------------//

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also
   // removes consecutive spaces and replaces it with one space.
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//---------Age Calculation Function------------//
	function getAge(year, month, day) 
	{
		var today=new Date();
		var curyear=today.getYear()
		if (curyear < 1000)
			curyear+=1900
		var display_value =" Time:  " + curyear
			
		display_value += " Date:  " + (today.getMonth()+1) + "/" + today.getDate() + "/" + curyear; 
		window.status=display_value; 
		TheDate = new Date();                     
		Month = TheDate.getMonth();              
		Day = TheDate.getDate();                 
		Year = TheDate.getYear();
		
		if (Year< 1000)
		Year+=1900
					
		BDate = Date.UTC(year,month,day);
		if (Year<2000) {              
			CDate = Date.UTC(Year,Month,Day);
		} else {
			CDate = Date.UTC(Year,Month,Day);
		}
		Age = CDate-BDate + (1000*60*60*24*30); 
		var calc_age=(parseInt(((((Age/1000)/60)/60)/24)/365.25,10));
		var calc_days=(parseInt((((Age/1000)/60)/60)/24,10));
		return calc_age
		
	}
	
	//---------URL address validation------------//
function check_url(address) {
  if ((address == "") || (address.indexOf ('http://') == -1) || (address.indexOf ('.') == -1))
      return false;
  return true;
}

//---------currency/money validation------------//
function validateDollar(val, fld ) 
{ 
  var temp_value = val; 
   if (temp_value == "") 
   { 
     fld.value = "$0.00"; 
     return true; 
   } 
   
   var Chars = "0123456789.,$"; 
   for (var i = 0; i < temp_value.length; i++){
       var a = temp_value.charAt(i);
       if (Chars.indexOf(a) == -1) 
       { 
           alert("Invalid Character(s)\n\nOnly numbers (0-9), a dollar sign, a comma, and a period are allowed in " + fld+ " field."); 
           return false;
       }  
   } 
} 	


//------------------- format date output  with mask "mm/dd/yyyy" ------------//
 function DateMask(dateString){
    var myDate = dateString;
	var month   = myDate.substring(0, myDate.indexOf("/"));
	var myDate = myDate.substring(myDate.indexOf("/")+1, myDate.length);
	var day       = myDate.substring(0, myDate.indexOf("/"));
	var year      = myDate.substring(myDate.indexOf("/")+1, myDate.length);
	
	var myDate = "";
	if(month.length<2) 
	  month = "0" + month;
	if(day.length<2) 
	  day = "0" + day;

	var myDate = month + "/" + day + "/" + year;
	
	return myDate
 }
 
 //---------this function compere today day with the date passing from form------------//
 
 function DatePosition(dateString,dateType) {
/*
   function DatePosition 
   parameters: dateString dateType
   returns: integer (-1, 0, 1)
   
   dateString is a date passed as a string in the following
   formats:

   type 1 : 19970529
   type 2 : 970529
   type 3 : 29/05/1997
   type 4 : 29/05/97
   type 5 : 05/29/1997
   type 6 : 05291997
   type 7 : 052997
   
   dateType is a numeric integer from 1 to 7, representing
   the type of dateString passed, as defined above.

   Returns -1 if the date passed is behind todays date
   Returns 0 if the date passed is equal to todays date
   or if dateType is not 1 to 7
   Returns 1 if the date passed is ahead of todays date
   
   Added Y2K checking.  (Works for any century cross over)
*/


    var now = new Date();
    var today = new Date(now.getYear(),now.getMonth(),now.getDate());
    var century = parseInt(now.getYear()/100)*100;
        
    if (dateType == 1)
        var date = new Date(dateString.substring(0,4),
                            dateString.substring(4,6)-1,
                            dateString.substring(6,8));
    else if (dateType == 2)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(0,2)))
        {
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(2,4)-1),
                            dateString.substring(4,6));
        }
        else
        {
            var date = new Date(century-100+parseInt(dateString.substring(0,2)),
                            parseInt(dateString.substring(2,4)-1),
                            dateString.substring(4,6));
        }
        
    }
    else if (dateType == 3)
        var date = new Date(dateString.substring(6,10),
                            dateString.substring(3,5)-1,
                            dateString.substring(0,2));
    else if (dateType == 4)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(6,8)))
        {
            document.write(century+parseInt(dateString.substring(6,8)),'<P>');
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(3,5)-1),
                            dateString.substring(0,2));
        }
        else
        {
            document.write(century-100+parseInt(dateString.substring(6,8)),'<P>');
            var date = new Date(century-100+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(3,5)-1),
                            dateString.substring(0,2));
        }
        
    }
    else if (dateType == 5)
        var date = new Date(dateString.substring(6,10),
                            dateString.substring(0,2)-1,
                            dateString.substring(3,5));
    else if (dateType == 6)
        var date = new Date(dateString.substring(4,8),
                            dateString.substring(0,2)-1,
                            dateString.substring(2,4));
    else if (dateType == 7)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(4,6)))
        {
            document.write('datestring Century:',century+parseInt(dateString.substring(4,6)),'<P>');
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(0,2)-1),
                            dateString.substring(2,4));
        }
        else
        {
            document.write('datestring Century:',century-100+parseInt(dateString.substring(4,6)),'<P>');
            var date = new Date(century-100+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(0,2)-1),
                            dateString.substring(2,4));
        }
        
    }
    else
        return false;

    if (date < today)
    {
        //document.write(date.toString(),' is behind ',today.toString(),'<P>');
        return -1;
    }
    else if (date > today)
    {
       //document.write(date.toString(),' is ahead of ',today.toString(),'<P>');
        return 1;
        
    }
    else
    {
       // document.write(date.toString(),' is the same as ',today.toString(),'<P>');
        return 0;
    }
}   


//Hide status bar msg II script- by javascriptkit.com
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use

function hidestatus(){
window.status='GSFC Intranet'
return true
}

if (document.layers){
	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
	
	document.onmouseover=hidestatus
	document.onmouseout=hidestatus
}
 
 function doUpperCase(fieldObj)
{ 
	var vl = fieldObj.value;
fieldObj.value=vl.toUpperCase();
return fieldObj; }

function WinStat(state) {
	
	if ((state)=='ON'){
		window.status='GSFC';
		return true
	}else {
		window.status='Done';
		return true
	}
}

//---------submiting form on 'Enter' key press------------//

function checkEnter(e)   //e is event object passed from function invocation
{	try{
	if(getKey(e) == 13)     //if generated character code is equal to ascii 13 (if enter key)
	{
		if (Validate_Form()==true){			
			document.forms[0].submit() //submit the form
			return true; 
		}
		else
			return false;		
	}
			return true 
	}catch(e){;}
	return false;
}

function getKey(e)
{ 
	var characterCode //literal character code will be stored in this variable
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}else{							
		e = event						
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	return characterCode;
} 
	
	
	//---------validate SSN number with the regular expression--------------//
	/*function CheckSSN(ssn){
		var matchArr = ssn.match(^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -])?(?!00)\d\d\3(?!0000)\d{4}$));
 		if (matchArr == null){
			return false 
		} 
	}*/
	
	
//---------Select Element Keyboard Selection for IE/Windows--------------//
	// global storage object for type-ahead info, including reset() method
var typeAheadInfo = {last:0, 
                     accumString:"", 
                     delay:500,
                     timeout:null, 
                     reset:function() {this.last=0; this.accumString=""}
                    };

// function invoked by select element's onkeydown event handler
function typeAhead() {
   // limit processing to IE event model supporter; don't trap Ctrl+keys
   if (window.event && !window.event.ctrlKey) {
      // timer for current event
      var now = new Date();
      // process for an empty accumString or an event within [delay] ms of last
      if (typeAheadInfo.accumString == "" || now - typeAheadInfo.last < typeAheadInfo.delay) {
         // make shortcut event object reference
         var evt = window.event;
         // get reference to the select element
         var selectElem = evt.srcElement;
         // get typed character ASCII value
         var charCode = evt.keyCode;
         // get the actual character, converted to uppercase
         var newChar =  String.fromCharCode(charCode).toUpperCase();
         // append new character to accumString storage
         typeAheadInfo.accumString += newChar;
         // grab all select element option objects as an array
         var selectOptions = selectElem.options;
         // prepare local variables for use inside loop
         var txt, nearest;
         // look through all options for a match starting with accumString
         for (var i = 0; i < selectOptions.length; i++) {
            // convert each item's text to uppercase to facilitate comparison
            // (use value property if you want match to be for hidden option value)
            txt = selectOptions[i].text.toUpperCase();
            // record nearest lowest index, if applicable
            nearest = (typeAheadInfo.accumString > 
                       txt.substr(0, typeAheadInfo.accumString.length)) ? i : nearest;
            // process if accumString is at start of option text
            if (txt.indexOf(typeAheadInfo.accumString) == 0) {
               // stop any previous timeout timer
               clearTimeout(typeAheadInfo.timeout);
               // store current event's time in object 
               typeAheadInfo.last = now;
               // reset typeAhead properties in [delay] ms unless cleared beforehand
               typeAheadInfo.timeout = setTimeout("typeAheadInfo.reset()", typeAheadInfo.delay);
               // visibly select the matching item
               selectElem.selectedIndex = i;
               // prevent default event actions and propagation
               evt.cancelBubble = true;
               evt.returnValue = false;
               // exit function
               return false;   
            }            
         }
         // if a next lowest match exists, select it
         if (nearest != null) {
            selectElem.selectedIndex = nearest;
         }
      } else {
         // not a desired event, so clear timeout
         clearTimeout(typeAheadInfo.timeout);
      }
      // reset global object
      typeAheadInfo.reset();
   }
   return true;
}

//generic number format function
function numFormat(expr, decplaces){
	// raise incoming value by power of 10 times the number of dicimal places;round to integer; convert to string;
	var str = "" + Math.round(eval(expr)* Math.pow(10,decplaces))
	// pad small value strings with zeros to the left of rounded number
	while (str.length<=decplaces){
		str="0"+str
	}
	// establish location of the decimal point
	var decpoint=str.length - decplaces
	// assemble final result from: (a) the string up to the position of the dicemal point;
	// (b) the decimal point; (c) the balance of the string. Return finished product.
	return str.substring(0,decpoint)+ "."+ str.substring(decpoint,str.length);
}

// get parametr from url
function getURLparam(myurl){
	var a=myurl.indexOf("=", 1);
	var id=myurl.substring(a+1);
	return id
}

function isValidDate(dateStr) 
{
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert(dateStr + " Date is not in a valid format.")
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
	   }
	}
	return true;
}

//--------Disables a Submit Button after the submit.--------------//
function DisableSubmitButton(el) { //v1.0
	el.disabled=true;
}

function flvFPW1(){// v1.3
// Copyright 2002, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18;if (v4>1){v10=screen.width;for (v6=0;v6<v2.length;v6++){v18=v2[v6].split("=");if (v18[0]=="width"){v8=parseInt(v18[1]);}if (v18[0]=="left"){v9=parseInt(v18[1]);v11=v6;}}if (v4==2){v7=(v10-v8)/2;v11=v2.length;}else if (v4==3){v7=v10-v8-v9;}v2[v11]="left="+v7;}if (v5>1){v14=screen.height;for (v6=0;v6<v2.length;v6++){v18=v2[v6].split("=");if (v18[0]=="height"){v12=parseInt(v18[1]);}if (v18[0]=="top"){v13=parseInt(v18[1]);v15=v6;}}if (v5==2){v7=(v14-v12)/2;v15=v2.length;}else if (v5==3){v7=v14-v12-v13;}v2[v15]="top="+v7;}v16=v2.join(",");v17=window.open(v1[0],v1[1],v16);if (v3){v17.focus();}document.MM_returnValue=false;}
//-->

function ClearError() {
	window.status = "There is a javascript error on this page.  Please e-mail the website owner of this page and inform him of this.";
	return true;
}

