

  /* ------------------------------------ */
  /* --- Validation & Masking Scripts --- */
  /* ------------------------------------ */



    /*Unsubscribe page Validation*/
    function Validation_UnsubscribeEmail()
{
            var Valid = true;
			var Message = "Please insert :\n";
			
			var elementObj= null;
			//Frist Name Validation
			elementObj = document.getElementById("First_Name");
			if(elementObj != null)
			{
			   if(elementObj.value.trim() == "")
			   {
			        Valid &= false;
			        Message += "- First Name\n";
			   }
			}			
			//Last Name Validation
			elementObj = document.getElementById("Last_Name");
			if(elementObj != null)
			{
			   if(elementObj.value.trim() == "")
			   {
			        Valid &= false;
			        Message += "- Last Name\n";
			   }
			}
			//Email Validation
			elementObj = document.getElementById("Email");
			if(elementObj != null)
			{
               if(elementObj.value.trim() == "")
			   {
			        Valid &= false;
			        Message += "- Email address\n";
			   }
			   else
			   {
			      if(!(elementObj.value.match(/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/)))
			      {
			        Valid &= false;
			        Message += "- Valid Email address\n";
			      }
			   }
			}

            if(!Valid)
            {
                alert(Message);
                return false;
            }
            return true;
}
//End Unsubscribe page validation;
	function trim() {
	// Remove leading spaces
	var s = this.replace(/^\s+/g, "")
	// Remove trailing spaces
	s = s.replace(/\s+$/g, "")
	return s
	}

	// Assign this trim function to all strings
	String.prototype.trim = trim

	/* --- Change the Value of an Element to Proper Case --- */
	function makeProper(vElement) {
		var sText = vElement.value;
	  var c = sText.substring(0,1).toUpperCase();
	  var sRight = sText.substring(1, sText.length)
	  vElement.value = c + sRight;
	}

 /* remove spaces (trim) the fields value*/
  function trimTextFields() 
  {
    for (i = 0; i < window.document.forms[0].elements.length; i++)
    {
        if(window.document.forms[0].elements[i].type == 'text' || window.document.forms[0].elements[i].type == 'textarea' || window.document.forms[0].elements[i].type == 'password')
        {
            fieldValue = window.document.forms[0].elements[i].value;                 

			while(''+fieldValue.charAt(0)==' ')
			fieldValue=fieldValue.substring(1,fieldValue.length);

			while(''+fieldValue.charAt(fieldValue.length-1)==' ')
			fieldValue=fieldValue.substring(0,fieldValue.length-1);
          
           window.document.forms[0].elements[i].value =fieldValue;
        }
    }  
    return false;
  }

  function clearInfoBlockCont() 
  {
    if( window.document.forms[0].elements['//Exam_Page_Options_Detail/BlockCont'] != null )
    {
		window.document.forms[0].elements['//Exam_Page_Options_Detail/BlockCont'].value = '';
    }       
    return false;
  }


  function clearInputFields() 
  {
    for (i = 0; i < window.document.forms[0].elements.length; i++)
    {
        if( window.document.forms[0].elements[i].type == 'text' || window.document.forms[0].elements[i].type == 'textarea' )
        {       
			if( window.document.forms[0].elements[i].name != "//Exam_Page_Options_Detail/BlockLabel")
			{
				//document.forms[0].elements['//Exam_Page_Options_Detail/BlockLabel'].value != '' )
				window.document.forms[0].elements[i].value ='';
			}			
		}	
		else
		if(window.document.forms[0].elements[i].type == 'select')
		{
		  window.document.forms[0].elements[i].value ='';
		}
		else 
		if( window.document.forms[0].elements[i].type == 'file' )
		{
			window.document.forms[0].elements['//Exam_Page_Options_Detail/LoadFrom'].filepath = "";					
		}	
    }      
    return false;
  }

	/* --- Filter Input for Hours and Cursor Control --- */
  function public_hoursMask(evt) {
   var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
  }
  
  

	/* --- Filter Input for DateTime-valid Characters (and Cursor Control) --- */
  function public_datetimeMask(evt) {
    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		
		if (!(charCode > 32 && (charCode < 47 || charCode > 58) && charCode !=191 && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
		return bOK;			
  }
  
  /* --- Filter Input for Time-valid Characters (and Cursor Control) --- */
  function public_timeMask(evt) {
    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		
		if (!(charCode > 31 && (charCode < 48 || charCode > 58) && charCode !=191 && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
		return bOK;			
  }


	/* --- Filter Input for Date-valid Characters (and Cursor Control) --- */
  function public_dateMask(evt) {
    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		
		if (!(charCode > 31 && (charCode < 47 || charCode > 57) && charCode !=191 && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
	
	
	
  }
 /* clear the field value*/
  function clearCreditorFields() 
  {
    for (i = 0; i < window.document.forms[0].elements.length; i++)
    {
        if(window.document.forms[0].elements[i].type == 'text')
        {
           window.document.forms[0].elements[i].value ='';
        }
    }  
    return false;
  }


/* --- Validate an Element Value as a Zip Code --- not used */
	
	function zipMask(vElement) {
    var sValue = vElement.value;
    var nLen = sValue.length;
     
    //TEMPORARY: DISABLED
    return true;

    /* --- Empty is OK --- */
    if (nLen == 0) {
      return true;
    }
     
    /* --- Validate Characters --- */
    if (nLen == 5 || nLen == 10) {      // Valid ZIPs are 5 or 10 digits
      switch (nLen) {
        case 5 :                        // If a 5-digit ZIP code
          for (i = 0; i <= 4; i++) {    // All Numeric
            if (sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) {
              vElement.focus();
              return false;
            }
          }
          break;          
        case 10 :                       // If a 10-digit ZIP+4 code
          for (i = 0; i <= 9; i++) {
            if (i != 5) {               // All Numeric, except
              if (sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) {
                vElement.focus();
                return false;
              }
            }
            else {                      // 6th Position must be '-'
              if (sValue.charCodeAt(i) != 45) {
                vElement.focus();
                return false;
              }
            }
          }
          break;
        default :                       // Fall-through, shouldn't happen
          vElement.focus();
          return false;
      }
    }
    else {                              // Valid ZIPs are 5 or 10 digits
      vElement.focus();
      return false;
    }
  }

/* --- Filter Input for Numeric and Cursor Control --- */
  function public_numMask(evt,oControl) {
    var i = 0;
    var bOK = false;
    var sValue = oControl.value;	    
    var nCounterArray = new Array(256);
	
	for (idx = 0; idx<256; idx++)
		nCounterArray[idx]=0;
	
    evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
		((evt.which) ? evt.which : 0));
	 
	if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
		bOK=true;
	}
	else if(charCode > 95 && charCode < 106)//NumPad
	{
		bOK=true;
	}		    
    else
    {
		
		if (charCode == 46 || charCode == 44)
		{   			
			for (idx = 0; idx < sValue.length; idx++)
			{							
				nCounterArray[sValue.charCodeAt(idx)]++;
			}
			if (charCode == 46 && nCounterArray[46] == 0)
				bOK = true;
			else
			if (charCode == 44)
				bOK = true;
			
		 }
    }
    
     
    if (!bOK) {
        return bOK;      // Cancel keystroke
    }
  }

function public_numonlyMask(evt) {
    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
}


 /* --- Filter Input for ZIp code and Cursor Control --- */
  function public_ZipcodeMask(evt) {
    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
}
  
  
 // SSN Mask to allow only numbers, '-' and space
	/* --- Filter Input for SSN Numeric and Cursor Control --- */
  function public_ssnNumMask(evt) {
    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0) || charCode == 45) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
}


var runnext;
function FieldNo(curField,len)
{
	
	if (document.getElementById(curField).value.length >= len)
		runnext=0;
	else
		runnext=1;
}

//ssn Mask to allow only numbers
function public_ssnNumOnlyMask(evt,curField,nxtField,len) {
    var bOK = false;
    var i=0;
    
    if 	(document.getElementById(curField).value.length >= len && runnext==1)
  	{
  		document.getElementById(nxtField).focus();
  		document.getElementById(nxtField).select();
  		if (navigator.appName == "Netscape")
  		return false;
  	}
  	if (document.getElementById(curField).value.length == len)
		runnext=0;
		else
		runnext=1;
	
  	
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
}

 // phone Mask to allow only numbers
 function public_PhoneNumOnlyMask(evt,curField,nxtField,len) {
    var bOK = false;
    var i=0;
  	
  	 if 	(document.getElementById(curField).value.length >= len && runnext==1)
  	{
  		document.getElementById(nxtField).focus();
  		document.getElementById(nxtField).select();
  		if (navigator.appName == "Netscape")
  		return false;
  	}
  	if (document.getElementById(curField).value.length == len)
		runnext=0;
		else
		runnext=1;

		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
}

  
  /* --- Filter Input for Percentage and Cursor Control --- */
  function public_percentageMask(evt,oControl) {
   var i = 0;
    var bOK = false;
    var sValue = oControl.value;	    
    var nCounterArray = new Array(256);
	
	for (idx = 0; idx<256; idx++)
		nCounterArray[idx]=0;
	
    evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
		((evt.which) ? evt.which : 0));
	 
	if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
		bOK=true;
	}		    
    else
    {		
		
		if (charCode == 46 || charCode == 44)
		{   			
			for (idx = 0; idx < sValue.length; idx++)
			{	//alert(sValue.charCodeAt(idx));
				//alert(sValue.charCodeAt(idx));								
				nCounterArray[sValue.charCodeAt(idx)]++;
			}
			if (charCode == 46 && nCounterArray[46] == 0)
				bOK = true;
			
			
		 }
    }
    
     
    if (!bOK) {
        return bOK;      // Cancel keystroke
    }
  }
  
 
  

	/* --- Validate an Element Value as a Phone Number --- */
  function phoneMask(vElement) {
   var sValue = vElement.value;
   var nLen = sValue.length;
   
    // TEMPORARY: DISABLED
    return true;

   /* --- Empty is OK --- */
   if (nLen == 0) {
     return true;
   }
   
   /* --- Validate Length --- */
   switch (nLen) {
     case 8 :      // Form: ###-####
       for (i = 0; i <= 7; i++) {
         switch (i) {
           case (3) :                // 4th Position must be '-'
             if (sValue.charCodeAt(i) != 45) {
               vElement.focus();
               return false;
             }
             break;
           default :                 // All others numeric
             if (sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) {
               vElement.focus();
               return false;
             }
         }
       } 
       break;
     case 12 :     // Form: ###-###-####
       for (i = 0; i <= 11; i++) {
         switch (i) {
           case (3) :                // 4th Position must be '-'
             if (sValue.charCodeAt(i) != 45) {
               vElement.focus();
               return false;
             }
             break;
           case (7) :                // 8th Position must be '-'
             if (sValue.charCodeAt(i) != 45) {
               vElement.focus();
               return false;
             }
             break;
           default :                 // All others numeric
             if (sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) {
               vElement.focus();
               return false;
             }
         }
       }
       break;      
     case 13 :     // Form: (###)###-####
       for (i = 0; i <= 12; i++) {
         switch (i) {
           case (0) :                  // 1st position must be '('
             if (sValue.charAt(i) != '(') {
               vElement.focus();
               return false;
             }
             break;
           case (4) :                  // 5th position must be ')'
             if (sValue.charAt(i) != ')') {
               vElement.focus();
               return false;
             }
             break;
           case (8) :                  // 9th position must be '-'
             if (sValue.charAt(i) != '-') {
               vElement.focus();
               return false;
             }
             break;
           default :                 // All others numeric
             if (sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) {
               vElement.focus();
               return false;
             }
         }
       }
       break;
     default :     // Valid phone numbers are 8, 12 or 13 chars
       vElement.focus();
       return false;
   }
   return true;
  }
 
 // To validate the number of character of a ZipCode to be 5
 // 31/12/2003 Fadi Zaghmout
  function zipcodeValid(vElement, bShowErrorMsg) {
   var sValue = vElement.value;
   var nLen = sValue.length;
   var sNewValue="";
   vElementID = vElement.id;
      

   /* --- Empty is OK --- */
   if (nLen == 0) {
     return true;
   }
   else 
   {
    
      if (nLen != 5) {     // Must be 9 chars in length
	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
        	{
        	if (bShowErrorMsg == null)
        		alert("Invalid Zip Code. You must provide a five digit Zip Code");
        	 vElement.focus();
        	 }
        	
       return false;
     }           
     } 
     
     return true;  
  } 

 // To validate the number of character of a SSN to be 9, removing the '-' and space before validation
 // 31/12/2003 Fadi Zaghmout
  function ssnValid(vElement, bShowErrorMsg) {
   var sValue = vElement.value;
   var nLen = sValue.length;
   var sNewValue="";
   vElementID = vElement.id;

   /* --- Empty is OK --- */
   if (nLen == 0) {
     return true;
   }
   else 
   {
     for (i=0;i<=10;i++) 
     {
           if (sValue.charAt(i) != '-' && sValue.charAt(i) != ' ') 
           {
				sNewValue = sNewValue + sValue.charAt(i)
			}
       }
	  var nLen = sNewValue.length;
      if (nLen != 9) {     // Must be 9 chars in length
       	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
        	{
        		if (bShowErrorMsg == null)
        		{
        			alert("Invalid SSN. You must provide a nine digit SSN number");
	        		vElement.focus();
				}
        	 }
      
       return false;
     }
     vElement.value = sNewValue;
       
     } 
     return true;  
  }
  
 
  
  function addtoHiddenSSN(vSSN,vSSN1,vSSN2,vSSN3)
  {
	value1 = window.document.getElementById(vSSN1).value;
	value2 = window.document.getElementById(vSSN2).value;
	value3 = window.document.getElementById(vSSN3).value;
	window.document.getElementById(vSSN).value = value1 + value2 + value3;
	//alert(window.document.getElementById(vSSN).value);
  }
  
   function addtoHiddenphone(vphone,vphone1,vphone2,vphone3)
  {
	value1 = window.document.getElementById(vphone1).value;
	value2 = window.document.getElementById(vphone2).value;
	value3 = window.document.getElementById(vphone3).value;
	window.document.getElementById(vphone).value = value1 + value2 + value3;
	
  }
  
	/* --- Validate an Element Value as a Social Security Number --- */
  function ssnMask(vElement) {
     
   var sValue = vElement.value;
   var nLen = sValue.length;

    // TEMPORARY: DISABLED
    return true;

   /* --- Empty is OK --- */
   if (nLen == 0) {
     return true;
   }
   else {
     if (nLen != 11) {     // Must be 11 chars in length
       vElement.focus();
       return false;
     }
     for (i=0;i<=10;i++) {
       switch (i) {
         case 3 :
         case 6 :
           if (sValue.charAt(i) != '-') {
             vElement.focus();
             return false;
           }
           break;
         default :
         if (sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) {
           vElement.focus();
           return false;
         }
       }
     }   
   }
  }

/* --- Validate an Element Value as Currency --- */
function validateCurrency(vElement, nDigits) {
		if (trimCurrency(vElement)) {
		vElement.value = vbFormatCurrency(vElement.value, nDigits);		// A script generated by																																	// FPIWebForms.CFormHTML
	}
	else {
		//vElement.focus();
		return false;
	}
	//	<script Language="VBScript">
  //		function vbFormatCurrency(vValue, nDigits)
  //			vbFormatCurrency = FormatCurrency(vValue, nDigits, -2, 0, -1)
  //		end function
  //	</script>
}

function trimCurrency(vElement) {
	var vValue = vElement.value;
	var vTemp = vValue;
	var a = new Array;
	var nLen = vValue.length;
	var i;

	/* --- Strip Leading Symbol --- */
	if (vTemp.charCodeAt(0) < 48 || vTemp.charCodeAt(0) > 57) {
		vTemp = vTemp.substring(1,nLen);		
		nLen = vTemp.length;
	}
					
	/* --- Strip Commas --- */
	a = vTemp.split(",");
	vTemp = '';
	for (i=0;i<a.length;i++) {
		vTemp = vTemp + a[i];
	}

	/* --- Verify Numeric --- */
	if (isNaN(vTemp)) 
	{
		if (vValue == 'NaN')
		{
			vElement.value = 0;
		}
		else
		{
			vElement.value = vValue;
		}
		return false;
	}
	else if (vTemp == '')
	{
		return false;
	}	
	else {
		vElement.value = vTemp;
		return true;
	}
}

/* --- Validate an Element Value as an Integer in Range --- */
function validateInt(vElement, sType) {
	var vValue = vElement.value;
	var nLen = vValue.length;
	var nMin;
	var nMax;	
	
	if (nLen == 0) {
		return true;
	}
	
	if (isNaN(vValue)) {
		if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
			{alert("Please enter a valid integer");
			vElement.focus();}
		return false;
	}

	/* FIX - there seems to be an bug in the code below: when the line following this
	         comment is removed, and the rest of the code allowed to execute, and the user
	         tries to enter values on the Concerns screen, he gets in some kind of infinite
		 loop with focus switching rapidly between the two controls.  Until this is fixed,
		 just return True as long as the value is a number */
	
	/*  ------------------------------------------------------ */


	switch (sType) {
		case "byte" :						// 1-byte unsigned integer range
			nMin = 0;
			nMax = 255;
		case "int" :						// 2-byte integer range
			nMin = -32768;
			nMax = 32767;
		case "unsigned_int" :		// 2-byte unsigned integer range
			nMin = 0;
			nMax = 65536;
		case "long" :						// 4-byte long integer range
			nMin = -2147483648;
			nMax = 2147483647;
		default :
			vElement.focus();
			return false;
	}
	
	if (Math.round(vValue) >= nMin && Math.round(vValue) <= nMax) {
		vElement.value = Math.round(vValue);
		return true;
	}
	else {
		if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
			{alert("Please enter a valid integer");
			vElement.focus();}
		return false;
	}
}

/* --- Return "significant" (non-zero) digits from fractional part of float --- */
function SigDigits(nValue) {
	var nSig = 0;
	var nStart;
	var nEnd;
	var i;
	
	if (nValue % 1 > 0) {				// "x.x"
		nStart = nValue.indexOf(".", 0) + 1;
		nEnd = nValue.length;
		nSig = nEnd - nStart;

		for (i = nEnd; i--; i >= nStart) {
			if (nValue.charAt(i) != "0") {
				break;
			}
			nSig--;
		}	
		return nSig;
	}
	else {											// "x", "x.", "x.0"
		return 0;
	}
}

/* --- Validate and Mask an Element Value as a Percent Rate --- */
function validateRate(vElement, nMin, nMax) {
	var vValue = vElement.value;
	var nLen = vValue.length;	
	var nDigits;
	
	if (nLen == 0) {
		return true;
	}
	
	if (isNaN(vValue)) {
		vElement.focus();
		return false;
	}
	
	if (vValue < nMin || vValue > nMax) {
		vElement.focus();
		return false;
	}
	else {
		nDigits = SigDigits(vValue);
		vElement.value = vbFormatNumber(vValue, Math.min(nDigits, 2), -1, 0, -1)
		return true;
	}
			// <script Language="VBScript">
			// Function vbFormatNumber(nValue, nDigits, tsLead, tsParen, tsGroup)
			//   If IsNumeric(nValue) Then
			//     vbFormatNumber = FormatNumber(nValue, nDigits, tsLead, tsParen, tsGroup)
			//   Else
			//     vbFormatNumber = 0
			//   End If
			// End Function
			// </script>
}


//prevent the input characters to be only any digit and a slash character.
function valid_dateMask() {
    var i = window.event.keyCode;
    var bOK = false;
    if ( (i >= 47 && i <= 57) )                 // Top row 0 to 9 in addition to /(Back slash).
         {                // Number pad 0 to 9
             bOK = true;
         }
    if (!bOK) {
      window.event.returnValue = false;         // Cancel keystroke
    }
  }


//checking for leap year
function isLeap(year){

if(year % 400 == 0){
return true;
} else if((year % 4 == 0) && (year % 100 != 0)){
return true
} else return false;
}


// get the number of days for each the month in the year
function days_in(month, year){

if(month == 4 || month == 6 || month == 9 || month == 11){
return 30;
} else if(!isLeap(year) && month == 2){
return 28;
} else if(isLeap(year) && month == 2){
return 29;
} else return 31;
}


function checkDatetime(myItem)
{
	var myArrayDateTime,myString, sTemp;
	
	myItemID = myItem.id
	myString = myItem.value + "";

	if (myString == "" || myString == null){
		return true;	
	}
	
	myString = myString.trim();
	if (myString.indexOf(" ") == -1) //Time not enetered (date only).
	{
		sTemp = myItem.value;
		myItem.value = myString;
		if (!checkDate(myItem,"Please check your Date Time format. (mm/dd/yyyy hh:mm:ss)"))
		{
			myItem.value = sTemp;
			myItem.focus();				
			return false;
		}
		else
		{
			sTemp = myItem.value + " 12:00:00";
			myItem.value = sTemp;
		}
	}
	else
	{	
		myArrayDateTime = myString.split(" ");	
		if (myArrayDateTime.length != 2)
		{
			if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
				{alert("Please check your Date Time format. (mm/dd/yyyy hh:mm:ss)");
				myItem.focus();
				}
			return false;
		}		
		
		
		// If the entered value follows the format:
		// 1. validate the date portion
		sTemp = myItem.value;
		myItem.value = myArrayDateTime[0];
		if (checkDate(myItem, "Please check your Date Time format. (mm/dd/yyyy hh:mm:ss)",sTemp))
		{
			myItem.value = sTemp; //restore the field value.			
			if (!checkTime(myArrayDateTime[1]))
			{
				if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
					{alert("Please check your Date Time format. (mm/dd/yyyy hh:mm:ss)");
					myItem.value = sTemp;
					myItem.focus();
					}
				return false;
			}
			else
			{
				myArrayDateTime[1] = GetCompleteTimeValue(myArrayDateTime[1]);
				sTemp = myArrayDateTime[0] + " " + myArrayDateTime[1];
				if (myArrayDateTime[1].length == 0)
					sTemp = sTemp + "12:00:00";
				else if (myArrayDateTime[1].indexOf(":") == -1)
					sTemp = sTemp + ":00:00";
				else if (myArrayDateTime[1].indexOf(":") == myArrayDateTime[1].lastIndexOf(":"))
					sTemp = sTemp + ":00";
			}
		}		
		myItem.value = sTemp;
	}
}


//This is the function that is called when the field looses the focus.
function checktime(myItem)
{			
	if (myItem.value == "" || myItem.value == null){
		
		return true;	
	}			
	
	myItemID = myItem.id
	if (!checkTime(myItem.value))
	{
		if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
			{alert("Please check your Time format. (hh:mm:ss)");
			myItem.focus();
			}
			
		return false;
	}
	else
	{
		myItem.value = GetCompleteTimeValue(myItem.value);
		if (myItem.value.indexOf(":") == -1)
			myItem.value = myItem.value + ":00:00";
		else if (myItem.value.indexOf(":") == myItem.value.lastIndexOf(":"))
			myItem.value = myItem.value + ":00";
	}
}


// Returns a hh:mm:ss value.
function GetCompleteTimeValue(sTimeString)
{
	var myArrayTime, sTimeStringTemp = "";
		
	myArrayTime = sTimeString.split(":");		
	
	for (i = 0; i < myArrayTime.length; i++)
	{
		if (i > 0 && myArrayTime[i].length == 1)
			myArrayTime[i] = "0" + myArrayTime[i];
			
		sTimeStringTemp += myArrayTime[i];
		if ( i < myArrayTime.length - 1)
			sTimeStringTemp += ":";
	}			
		
	if (sTimeStringTemp.length > 0)
		return sTimeStringTemp;
	else
		return sTimeString;
}

	
// Format is hh:mm. 24 hrs system.
function checkTime(sTimeString) 
{
	sTimeString = GetCompleteTimeValue(sTimeString);
	
	//return /^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$/.test(sTimeString) 
	return /^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?(:[0-5][0-9])?$/.test(sTimeString) 
}


//check if the date is valid.
//then it will call the getAge method.
// the input for this method is the birth date input field reference (ex: document.frmMain.birthdate).
// the result will either be an alert to fix the date format, or the correct age in another field.

function checkDate(myItem, sErrorMessage, myString){

var myArrayDate, myDay, myMonth, myYear, /*myString,*/ myYearDigit,
	myDayString, myMonthString,myYearString, sSplitter, sTempString;

if (myString == null)
{	
	myString = myItem.value + "";	
}
else
{
	sTempString = myString;
	myString = myItem.value + "";
	myItem.value = sTempString;
}

myItemID = myItem.id

if (sErrorMessage == null)
	sErrorMessage = "Please check your Date format. (mm/dd/yyyy)";

if (myString == "" || myString == null){
	
	return true;

}

if (myString.indexOf("/") != -1)
{
	myArrayDate = myString.split("/");
	sSplitter = "/";
}
else
{
	if (myString.indexOf("-") != -1)
	{
		myArrayDate = myString.split("-");
		sSplitter = "-";
	}
	else
	{
		if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
			{alert(sErrorMessage);
			//myArrayDate = myString.split("-");
			myItem.focus();}
		
		return false;
	}
}

myDay = myArrayDate[1];

myMonth = myArrayDate[0];

myYear = myArrayDate[2];

myString = myYear + "";

myYearDigit = myString.length;

if (isNaN(myDay) || isNaN(myMonth) || isNaN(myYear) || (myYear < 1) || (myDay < 1) || (myMonth < 1) || (myMonth > 12) || (myYearDigit != 4) || (myDay > days_in(myMonth, myYear))){
	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert(sErrorMessage);
		myItem.focus();}
	
	return false;
} 

if (parseInt(myYear)<1753 || parseInt(myYear)>9999)
{
	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Year cannot be less than 1753 or greater than 9999");
		myItem.focus();}
	
	return false;
}
myMonthString = myMonth + "";
myDayString = myDay + "";
myYearString = myYear + "";
myItem.value =  myMonthString;
myItem.value =  myItem.value + sSplitter;
myItem.value =  myItem.value + myDayString;
myItem.value =  myItem.value + sSplitter;
myItem.value =  myItem.value + myYearString;

return true;
}


//check if the date is valid.
//then it will call the getAge method.
// the input for this method is the birth date input field reference (ex: document.frmMain.birthdate).
// the result will either be an alert to fix the date format, or the correct age in another field.

function checkAgeDate(myItem){


var myArrayDate, myDay, myMonth, myYear, myString, myYearDigit,
		myDayString, myMonthString,myYearString;;

myString = myItem.value + "";
myItemID = myItem.id

if (myString == "" || myString == null){
	
	return true;
}

myArrayDate = myString.split("/");

myDay = myArrayDate[1];

myMonth = myArrayDate[0];

myYear = myArrayDate[2];

myString = myYear + "";

myYearDigit = myString.length;

//if (myYearDigit == 1 || myYearDigit == 2)
//{
//	myYear = myYear +2000;
//	myString = myYear + "";
//	myYearDigit = myString.length;
//}

if (isNaN(myDay) || isNaN(myMonth) || isNaN(myYear) || (myYear < 1) || (myDay < 1) || (myMonth < 1) || (myMonth > 12) || (myYearDigit != 4) || (myDay > days_in(myMonth, myYear))){
	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Please check your Date format. (mm/dd/yyyy)" );
		//myItem.value = "";
		myItem.focus();}
	
	return false;
} else{
	result = getAge(myItemID,myString,myMonth,myDay);
		if( result == -1)
			{
			myItem.focus();
			
			return false;
			//   alert("the result age is "+result);
			}
	
	myMonthString = myMonth + "";
	myDayString = myDay + "";
	myYearString = myYear + "";
	myItem.value =  myMonthString;
	myItem.value =  myItem.value + "/";
	myItem.value =  myItem.value + myDayString;
	myItem.value =  myItem.value + "/";
	myItem.value =  myItem.value + myYearString;

return true;
}
}



//this method will be used from withen the checkDate method, so dont use it directly.
// or you can use it by entering the following parameter (year,month,day).

function getAge(myItemID,dateString,strmonth,strDay) {
if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
{
var now = new Date();

var nowyear = now.getFullYear();

var age = window.document.getElementById('//DOB_Range').value;

if (parseInt(dateString)<1753 || parseInt(dateString)>9999)
{
	alert("Year cannot be less than 1753 or greater than 9999");
		//myItem.value = "";
		document.getElementById(myItemID).focus()
	
	return false;
}

  nAgeDiff = nowyear - dateString;
  //per salah feedback: no check is required on max/min ages 
/*
  if( (nAgeDiff > 99) || (nAgeDiff < 0))
  { 
     	if (navigator.userAgent.indexOf("Mac") == -1)
	alert("The age should be between 0 - 99 years");
      	return -1;    
  }
*/
if ((age == 1) && (nAgeDiff < age))
{
      alert("Invalid Date of Birth. You have to be at least "+ age +" year old");
      return -1;  
}
else
{
  if( nAgeDiff < age )
  {
     alert("Invalid Date of Birth. You have to be at least "+ age +" years old");
     return -1;   
  }
}
return nowyear - dateString;
}
return true;
}




/*
   this function will check the input email address.

   ex: of using this function:      
<form name=emailform onSubmit="return emailCheck(this.email.value);">
Your Email Address:  <input type=text name="email"><br>
<input type=submit value="Submit">
</form>
*/
function ampmhours (objfield) 
{
   if(objfield == null) return true;
   HoursStr = objfield.value;   
while(''+HoursStr.charAt(0)==' ')
HoursStr=HoursStr.substring(1,HoursStr.length);

while(''+HoursStr.charAt(HoursStr.length-1)==' ')
HoursStr=HoursStr.substring(0,HoursStr.length-1);
objfield.value = HoursStr;
if(HoursStr == '')
{
  HoursStr.value = '';
  return true;
}
else
if( HoursStr > 12 || HoursStr==0)
{
   	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Hours should be between 1 - 12 ");
   		objfield.focus();}
   	return false;
}
   
}


function emailCheck (objfield, bShowErrorMsg) {

objfieldID = objfield.id;
if(objfield == null) return true;
emailStr = objfield.value;
while(''+emailStr.charAt(0)==' ')
emailStr=emailStr.substring(1,emailStr.length);

while(''+emailStr.charAt(emailStr.length-1)==' ')
emailStr=emailStr.substring(0,emailStr.length-1);
objfield.value = emailStr;
if(emailStr == '')
{
  objfield.value = '';
  return true;
}
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. 
*/

var emailPat=/^(.+)@(.+)$/

/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */

var validChars="\[^\\s" + specialChars + "\]"

/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")"

/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

/* The following string represents an atom (basically a series of
   non-special characters.) */

var atom=validChars + '+'

/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")"

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat)

if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */

	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{
		if (bShowErrorMsg == null)
			alert("Invalid Email address.")
		objfield.focus();}
		
	return false;
}

var user=matchArray[1]

var domain=matchArray[2]

// See if "user" is valid 

if (user.match(userPat)==null) {
    // user is not valid
    if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
	{
	if (bShowErrorMsg == null)
		alert("The username doesn't seem to be valid.")
   	 objfield.focus();}
   
    return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat)

if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
			{
				if (bShowErrorMsg == null)
					alert("Invalid Destination IP address!")
				objfield.focus();}
		
		return false;
	    }
    }
    return true;
}


// Domain is symbolic name

var domainArray=domain.match(domainPat)

if (domainArray==null) {
	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{
		if (bShowErrorMsg == null)
			alert("Invalid domain name.")
		objfield.focus();}
	
    return false;
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */

var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{
		if (bShowErrorMsg == null)
			alert("The address must end in a three-letter domain, or two letter country.");
  		objfield.focus();}
  	
   return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
   var errStr="This address is missing a hostname!"
   	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{
		if (bShowErrorMsg == null)
			alert(errStr);
  		objfield.focus();}
   
   return false;
}

// If we've gotten this far, everything's valid!

return true;
}


// prevent any characters to be entered except the digits,coz the input field is for Age data.

  function public_AgeMask(evt) {

    var bOK = false;
    var i=0;
  		
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
  }


// forbid any characters to be entered to Currency input field except : $,0--9,comma,dot
//// ex: <input type="text" onkeypress="CurrencyMask();" onChange="this.value = formatCurrency(this.value);">

 function public_CurrencyMask(evt) {

    var bOK = false;
    var i=0;
  	
		evt = (evt) ? evt : event;
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
			((evt.which) ? evt.which : 0));
		if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0) || charCode==46 || charCode==44 || charCode==36) {
			bOK=true;
		}				
	

    if (!bOK)
	return bOK;
	
  }





// used when using onChange on the input field.
// ex: <input type="text" onkeypress="CurrencyMask();" onChange="this.value = formatCurrency(this.value);">


function formatCurrency(num) {
if (num == null || num.length == 0)
{
	return num;
}
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;
if (cents.length == 2) cents += "0";


num = Math.floor(num/100).toString();

if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)

num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function formatPercent(percent,num) {

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;
if(num > 100 || ((num == 100) && (cents != "00"))) 
{
       	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
	alert("The value should be less or equal 100 ");
       return 0.00; 
}
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}

// check currency fields format for valid currency format (at most 1 (dot))

function formatCurr(num) {
	var currField = num.value;

        if( (currField != null) && (currField != ''))
        {

		currField = currField.toString();

		nDotCounter=0;

		while(currField.indexOf('.') != -1)
		{

                   nDotCounter= parseInt(nDotCounter) + 1;

                   currField = currField.replace('.','');
		}

		if( nDotCounter > 1 )
		{
			if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")	
		   		{alert("Invalid amount.");
                  	 	num.focus(); }

		   return false;
		}
        } 
	return true;
}




function validAge(age)
{
    var ageValue = age.value;
    if( ( ageValue == null )  || (ageValue == ''))
    {
        if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Age field is required.");
	  	age.focus();}	
        return false;
    }
    if( (ageValue > 99) || (ageValue < 0))
    { 
      	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("The age should be between 0 - 99 years");
     		age.focus();}	
      return false; 
    }
    return true;
   
}

function validPercent(percent)
{
    var perValue = percent.value;
    if( ( perValue == null )  || (perValue == ''))
    {
        if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Percentage field is required.");
	  	percent.focus();}
        return false;
    }
    else if( isNaN(perValue))
    {
       	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Percentage field should be Number.");
	  	percent.focus();}
        return false;
 
    }
    else if( (perValue > 100) || (perValue < 0))
    { 
       	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("The percentage should be between 0 - 100 ");
      	 	percent.focus();}
       return false; 
    }
    else
    {
       return checkDecimals(percent, perValue);
    }
    return true;   
}


function public_PercentMask(evt,oControl) {

    var i = 0;
    var bOK = false;
    var sValue = oControl.value;	    
    var nCounterArray = new Array(256);
	
	for (idx = 0; idx<256; idx++)
		nCounterArray[idx]=0;
	
    evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
		((evt.which) ? evt.which : 0));
	 
	if (!(charCode > 31 && (charCode < 48 || charCode > 57) && evt.which != 0)) {
		bOK=true;
	}		    
    else
    {		
		
		if (charCode == 46 || charCode == 44)
		{   			
			for (idx = 0; idx < sValue.length; idx++)
			{	//alert(sValue.charCodeAt(idx));
				//alert(sValue.charCodeAt(idx));								
				nCounterArray[sValue.charCodeAt(idx)]++;
			}
			if (charCode == 46 && nCounterArray[46] == 0)
				bOK = true;
			
			
		 }
    }
    
     
    if (!bOK) {
        return bOK;      // Cancel keystroke
    }
  }


function checkDecimals(fieldName, fieldValue) {

  decallowed = 2;  // how many decimals are allowed?

  if (isNaN(fieldValue) || fieldValue == "") {
  	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert("Invalid percentage.");
  		fieldName.select();
  		fieldName.focus();}
  return false;
  }
  else {
  if (fieldValue.indexOf('.') == -1) fieldValue += ".";
  dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

  if (dectext.length > decallowed)
  {
   	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
		{alert ("Please enter a percentage with up to " + decallowed + " decimal places. ");
		fieldName.select();
		fieldName.focus();}
	return false;
  }
  else {
          //alert ("That number validated successfully.");
          return true;
       }
  }
}

// copy the checked boxes values into the textarea field, and remove its value when unchecked.
// used in onefinalquestion tab page

function finalnotes(checkList)
{
   window.document.forms[0].elements['/*/*/dat_MainA/dat_MainA_Item[1]/FPNotes'].value = "";
   for(i =0; i < 11; i++)
   {
     if (checkList[i].checked)
     {
        window.document.forms[0].elements['/*/*/dat_MainA/dat_MainA_Item[1]/FPNotes'].value = window.document.forms[0].elements['/*/*/dat_MainA/dat_MainA_Item[1]/FPNotes'].value + checkList[i].value + "\n";
     }
   }       

   return true;
}



function recal() {

	var total = 0;

	//calculate total cost on client side

	if (window.document.forms[0].elements['TuitionCost'][0].checked) { 

                if( (window.document.forms[0].elements['Tuition'].value == null) || (window.document.forms[0].elements['Tuition'].value == ""))
                {
                   total = 0;
                }
                else
                { 
   		   total = parseInt(window.document.forms[0].elements['Tuition'].value);
                }
                 
	}
	else if (window.document.forms[0].elements['TuitionCost'][1].checked) { 

                if( (window.document.forms[0].elements['OutOfState'].value == null) || (window.document.forms[0].elements['OutOfState'].value == ""))
                {
                   total = 0;                      
                } 
                else
                {
                   total = parseInt(window.document.forms[0].elements['OutOfState'].value);
                } 
	}
	else 
        {
		total = 0;
	}

	if (window.document.forms[0].elements['ckRoom'].checked) { 
                 if((window.document.forms[0].elements['RoomOnly'].value == null ) || (window.document.forms[0].elements['RoomOnly'].value == ""))
                 {
                    total +=0;
                 }
                 else
 		 {
  		    total += parseInt(window.document.forms[0].elements['RoomOnly'].value);
	 	 }
                

	}
	if (window.document.forms[0].elements['ckBoard'].checked) { 

                 if((window.document.forms[0].elements['RoomBoard'].value == null ) || (window.document.forms[0].elements['RoomBoard'].value == ""))
                 {
                    total +=0;
                 }
                 else
  		 {
 		    total += parseInt(window.document.forms[0].elements['RoomBoard'].value);
 		 }
	}
	if (window.document.forms[0].elements['ckBook'].checked) {

                 if((window.document.forms[0].elements['BooksSupplies'].value == null ) || (window.document.forms[0].elements['BooksSupplies'].value == ""))
                 {
                    total +=0;
                 }
                 else
	         {
 	            total += parseInt(window.document.forms[0].elements['BooksSupplies'].value);
         	 }
         
	}

	
//	var newName = "F_FPEdAmt" + index
//	document.forms[0].elements[newName].value = total;

        window.document.forms[0].elements['TotalCost'].value = total;

	return true;
}


function depthUp()
{
    
    var depthValue = window.document.forms[0].elements['depth'].value;
    var sum = 0;
    if((depthValue == null ) || (depthValue == ""))
    {
       sum = 0;
    }
    else
    {
        sum = parseInt(depthValue) + 1;     
    }    
    window.document.forms[0].elements['depth'].value  = sum;
    popupAction('frmother');
}


function depthDown()
{
    
    var depthValue = window.document.forms[0].elements['depth'].value;
    var sum = 0;
    if((depthValue == null ) || (depthValue == "") || ( depthValue == "1") || (depthValue < 1))
    {
       sum = 1;
    }
    else
    {
        sum = parseInt(depthValue) - 1;     
    }    
    window.document.forms[0].elements['depth'].value  = sum;
    popupAction('frmother');
}


// check all selected checkboxes in One Final Question tab page.

function checkSelectedBoxes()
{
   var strTextArea = window.document.forms[0].elements['/*/*/dat_MainA/dat_MainA_Item[1]/FPNotes'].value;
     
   if( ( strTextArea != null ) && (strTextArea != '') && ( strTextArea.length != 0 )) // check if textarea is filled with data or not
   {
           while(strTextArea.indexOf('(') != -1 )
           strTextArea = strTextArea.replace('(','');

           while(strTextArea.indexOf(')') != -1 )
           strTextArea = strTextArea.replace(')','');
           
	   
           for (i = 0; i < window.document.forms[0].elements.length; i++)
	   {	 
          
              if ((window.document.forms[0].elements[i].type == 'checkbox') && (window.document.forms[0].elements[i].value != ''))
              {
	           var strValueSelected = window.document.forms[0].elements[i].value;

	           while(strValueSelected.indexOf('(') != -1 )
        	   strValueSelected = strValueSelected.replace('(','');

	           while(strValueSelected.indexOf(')') != -1 )
        	   strValueSelected = strValueSelected.replace(')','');


	           if (strTextArea.toLowerCase().match(strValueSelected.toLowerCase()) != null )
                   {
                       window.document.forms[0].elements[i].checked = true;
                   }
             }
	}
   }
   return true;
}

function validEntry(action,id)
{
if (action == 'frmPersonal')
{
		Fld = "/*/*/dat_MainA/dat_MainA_Item[1]/FPClFirst";
	      if (getLength(window.document.forms[0].elements[Fld].value) == 0)
		{
			if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
				{alert("Client A first name can not be empty");
				window.document.forms[0].elements[Fld ].focus();}
			return false;
		}
		if (id == 'AddChild')
		{	
			for (i=1; i <= window.document.forms[0].elements['RecsCount'].value;i++)
			{
				s = i.toString();          
				Fld = "/*/*/dat_Dependents/dat_Dependents_Item[" + s + "]/FPDName";
			      if (window.document.forms[0].elements[Fld ].value.length == 0)
				{
					if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
						{alert("You can not add child while there is an other empty child record");
						window.document.forms[0].elements[Fld ].focus();}
					return false;
				}
			}

		}
}
else
 if (action == 'frmrf' || action == 'frmta' || action == 'frmlb')
 {
	for (i=1; i <= window.document.forms[0].elements['RecsCount'].value;i++)
	{
		s = i.toString();          
		Fld = "/*/*/dat_Assets/dat_Assets_Item[" + s + "]/FPAsName";
	      if (getLength(window.document.forms[0].elements[Fld ].value) == 0)
		{
			if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
				{alert("Account name can not be empty");
				window.document.forms[0].elements[Fld ].focus();}
			return false;
		}
	}
 }
else
 if (action == 'frmdis')
 {
	for (i=1; i <= window.document.forms[0].elements['RecsCount'].value;i++)
	{
		s = i.toString();          
		Fld = "/*/*/dat_Disability/dat_Disability_Item[" + s + "]/FPDInsPol";
	      if (getLength(window.document.forms[0].elements[Fld ].value) == 0)
		{
			if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
				{alert("Company name can not be empty");
				window.document.forms[0].elements[Fld ].focus();}
			return false;
		}
	}
 }
return true;
}

function getLength(vVariable)
{
var s = new String(vVariable);
var len = s.length;
for (k=s.length -1 ; k>=0;k--)
{
	if (s.charAt(k) == ' ')
	   len--;
	else	
	   break;
}
return len;
}


// check age number , Age should be not lessthan 0, not greater than 99

function checkAge(nAgeValue) {

  if( (nAgeValue.value != null) && (nAgeValue.value != '') )
  {

	  if( (parseInt(nAgeValue.value) > 99) || (parseInt(nAgeValue.value) < 0) )
	  { 
	      	if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape")
			{alert("The age should be between 0 - 99 years");
             	 	nAgeValue.focus(); } 
	      return false;    
	  }
  }

  return true;
}


// this function to validate Password input value.
// Pwd length is implemented as variable so as to change it later (if needed).

function checkPassword(pwd)
{
    var nPwdLength = 8;

    var strPwdValue = pwd.value;

    if( ( strPwdValue == null ) || ( strPwdValue == '') )
    {
        if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape") 
		{alert('Password field should not be empty');
         	pwd.focus();}
         return false;
    }
    else if( strPwdValue.indexOf(' ') != -1 ) 
    {
        if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape") 
		{alert('Password should not contain spaces');
         	pwd.focus();}
         return false;                       
    }
    else if( (strPwdValue.length) < (parseInt(nPwdLength)) )
    {
        if (navigator.userAgent.indexOf("Mac") == -1 && navigator.appName != "Netscape") 
		{alert('Password length should not be less than '+nPwdLength);
         	pwd.focus();}
         return false;          
    }
    return true;    
}


function year_entered()
{   

         if( (window.document.forms[0].elements['/*/*/dat_MainC/dat_MainC_Item[1]/FPSurvivorDurationYears'].value != 0) )
         {
            window.document.forms[0].elements['/*/*/dat_MainC/dat_MainC_Item[1]/FPSurvivorDurationLifetime'].checked = false;
         }

      return true; 
}


function year_checked()
{

       if( window.document.forms[0].elements['/*/*/dat_MainC/dat_MainC_Item[1]/FPSurvivorDurationLifetime'].checked == true)
       { 
	       window.document.forms[0].elements['/*/*/dat_MainC/dat_MainC_Item[1]/FPSurvivorDurationYears'].value = 0;
       }
       return true;
    
}
function getNextElement(field) {
  var fieldFound = false;
  var form = field.form;
  for (var e = 0; e < form.elements.length; e++) {
    if (fieldFound && form.elements[e].type != 'hidden')
      break;
    if (field == form.elements[e])
      fieldFound = true;
  }
  return form.elements[e % form.elements.length];
}
	// validate Other school name text box value in case "Any <state> school" school name is choosen,
	// this field is required while user select "Any <state> school" option, so alert will be displayed.
	function checkOtherSchoolFilledFromBorrowerInitiatedPublic()
	{
		// get School Name so as to decide if we need o display Other text box or not.
		if( document.getElementById( '//StartLoanQWizard/School_ID') != null )
		{
			//get items count for School codes
			var c = document.forms[0].elements['//StartLoanQWizard/School_ID'].length ;
			oOption = new Option();			
			for(i=0; i<c; i++)
			{// loop through the combo items till we find the selected one
				if (document.forms[0].elements['//StartLoanQWizard/School_ID'][i].selected)
				{ // keep value(ID)  and text (displayed string)
					oOption.value= document.forms[0].elements['//StartLoanQWizard/School_ID'].options[i].value;
					oOption.text= document.forms[0].elements['//StartLoanQWizard/School_ID'].options[i].text;
					break;
				}
			}
			if(oOption != null )			
			{
					if( document.getElementById('//StartLoanQWizard/Selected_School_Name') != null )
					{
						document.getElementById('//StartLoanQWizard/Selected_School_Name').value = 	oOption.text;									
					}
			}
		}	
		return true;
	}	


/* this funtion is used to limit data entered into text box to certain lenght
	when textBox has multiLine value for textMode
*/
function checkMaxTextLength(objName , Maxlength)
{
	//alert(objName);
	
	var obj = document.getElementById(objName);
	var str = obj.value;
	if( str.length >= Maxlength )  // delete extra characters
	{
		var i = window.event.keyCode;
		if ( (i == 8) || (i == 46) )
		{ 
			return true ;
		}
		else
		{
			return false ;
		}
	}
	else
		return (true);
}
function uppercase()
{
	key = window.event.keyCode;
	if( key >= 97 && key <= 122 )
	window.event.keyCode = key - 32;
	
}
			function onPasteActivation(field1)
			{
				field = document.getElementById(field1);
				event.returnValue = false;
				if(field != null )
				{
					if( field.value != null )
					{
						field.value = field.value + window.clipboardData.getData('Text').toUpperCase();
					}
					else
					{
						field.value = window.clipboardData.getData('Text').toUpperCase();					
					}
				}
			}

// it is a generic JS function that will switch the disable property
//-- for target field according to change of triggering field(usually Combo list).
function flipFieldOneDependsOnFieldTwoStatus(FieldOne,FieldTwo,triggerValue,hiddenFieldName)
{
	if( FieldTwo != null )
	{
		if( FieldTwo.substr(0,2) == '//')
		{
			FieldTwo = FieldTwo.substring(2);
		}
		for (i = 0; i < document.forms[0].elements.length; i++)
		{
			var stname_ = new String(document.forms[0].elements[i].name);
			if (stname_.indexOf(FieldTwo) != -1 && (stname_.indexOf('_HIDDEN_PARAM') == -1))
			{
				FieldTwo = stname_;
				break;
			}
		}
	}
	if( document.getElementById(FieldOne) != null && 
		document.getElementById(FieldTwo) != null && triggerValue != null
	   )
	   {
			typeOfFieldOne = '';
			bValueMatched = false;
			for (i = 0; i < document.forms[0].elements.length; i++)
			{
				var stname = new String(document.forms[0].elements[i].name);
				Final = document.forms[0].elements[i].type;
				if (stname == FieldOne)
				{
					if(document.forms[0].elements[i].type == 'select-one')
					{						
						typeOfFieldOne = document.forms[0].elements[i].type;
						var c = document.forms[0].elements[stname].length ;
						oOption = new Option();
						for(i=0; i<c; i++)
						{// loop through the combo items till we find the selected one
							if (document.forms[0].elements[stname][i].selected)
							{ // keep value(ID)  and text (displayed string)
								if( document.forms[0].elements[stname].options[i].value == triggerValue )
								{
									bValueMatched = true;
									break;
								}
							}
						}
					}
					break; 
				}
			}
			if( typeOfFieldOne == 'select-one' )
			{			
				if( bValueMatched )
				{
					document.forms[0].elements[FieldTwo].value = '';					
					document.forms[0].elements[FieldTwo].disabled = true;
					if( document.forms[0].elements[hiddenFieldName] != null )
					{
						document.forms[0].elements[hiddenFieldName].value = '1';
					}
				}
				else
				{
					document.forms[0].elements[FieldTwo].disabled = false;
					if( document.forms[0].elements[hiddenFieldName] != null )
					{
						document.forms[0].elements[hiddenFieldName].value = '0';
					}
				}			
 		   }
	   }
}