// JavaScript Document

<!--
function changeval(what,str,k)
	{
		var strmain = '';
		var strdd = '';
		var strmm = '';
		var stryy= '';
		if (k==0)
		{
			strmain='F'+str;
			strdd = 'dd'+str;
			strmm = 'mm'+str;
			stryy = 'yy'+str;			
		}
		else
		{
			strmain='*F'+str;
			strdd = '*dd'+str;
			strmm = '*mm'+str;
			stryy = '*yy'+str;
		}
    selected1 = what.elements[''+strmm].selectedIndex;
    if(selected1==-1)
	value1='';
	else
	value1 = what.elements[''+strmm].options[selected1].value;

    selected2 = what.elements[''+strdd].selectedIndex;
	if(selected2==-1)
		value2='';
	else
    value2 = what.elements[''+strdd].options[selected2].value;

    selected3 = what.elements[''+stryy].selectedIndex;
	if(selected3==-1)
		value3='';
	else
    value3 = what.elements[''+stryy].options[selected3].value;
	what.elements[''+strmain].value = value1 + '/' +value2 + '/' +value3+'';
}
		var radioarray = new Array();
	//Make sure all required fields are entered
	function CheckRequiredFields() {
		var elementname;
		var elementvalue;
		var elementtype;
		var emailvalue;
		var emailagainvalue;
		var nochecked=0;

		//Loop through all elements on the page
		for (var i=0; i < document.forms[0].elements.length; i++) {

			elementtype = document.forms[0].elements[i].type;
			
			//If the first position of the element name equals "*"
			elementname = document.forms[0].elements[i].name;
	

			//Save the value of the email field
			if (elementname == '*email') {
				emailvalue = document.forms[0].elements[i].value;
			}

			//Save the value of the email again field
			if (elementname == '*emailagain') {
				emailagainvalue = document.forms[0].elements[i].value;
			}
			//If this is a required field
			if (elementname.substr(0,1) == '*') {
			elementvalue = document.forms[0].elements[i].value;
					if (elementtype.indexOf('radio') > -1) 
					{
						addarray(elementname);
            			if (document.forms[0].elements[i].checked) 
						{
						nochecked++;
						}
        			}
					
        			if (elementtype.indexOf('select') > -1)
            		if (document.forms[0].elements[i].selectedIndex == 0) 
					{
						if((elementname.indexOf('*dd')>-1)||(elementname.indexOf('*mm')>-1)||(elementname.indexOf('*yy')>-1))
						{
							if(trim(elementvalue)=="0"||trim(elementvalue)=="00")
							{	
									alert('Invalid Date. Please try again');
									return false;
							}
						}
						if((trim(elementvalue)==" ") || (elementvalue.indexOf('Select') > -1))
						{
						alert('All required fields have not been entered.');
						return false;
						}
					}
    
        
								
				//If the value is empty
				if (elementvalue.length == 0 || trim(elementvalue) == " ") {
					alert('All required fields have not been entered.');
					return false;
				}
			}
		}
		
//    if (radioButtons && !radioChecked)
	if(radioarray.length!=nochecked)
	{
					alert('All required fields have not been entered.');
					return false;
	
	}


		if (emailvalue != emailagainvalue) {
			alert('Your email address must be entered the same way twice.');
			return false;
		}

		return true;
	}

function addarray(elementname){
var flag=0;
for (var i=0;i<radioarray.length;i++)
{
	if(radioarray[i]==elementname)
	flag = 1;
}
if(flag==0)
radioarray[radioarray.length] = elementname;
}
	/// This checks the string passed in as a domain name and requires that it
	///   either end in one of the '.com' style endings or ends with '.cc' where the
	///   'cc' represents two alphabetic characters of a country code domain.
	///   I don't actually check for a valid country code, only for the proper form.
	/// This function needs JS1.2 and does not work in Opera3.5
	function isStandardDomain(domainIn) {

		/// The value to return, start out assuming invalid domain.
		var isStandardReturn = false;

		/// Holds the last 4 characters of domain name.
		var last4chars  =  domainIn.substring( domainIn.length-4, domainIn.length );
		var last5chars  =  domainIn.substring( domainIn.length-5, domainIn.length );
		

		/// Holds the last 3 characters of domain name.
		var last4chars  =  domainIn.substring( domainIn.length-4, domainIn.length );
		var last5chars  =  domainIn.substring( domainIn.length-5, domainIn.length );

		/// Uppercase it for comparison purposes.
		last4chars = last4chars.toUpperCase();
		last5chars = last5chars.toUpperCase();

		/// A regular expression pattern to match country code domains.
		///  In otherwords a Dot character followed by two alphabetic characters.
		/// NOTE:  This line doesn't work at all in Opera3.5 and prevents the
		///  entire script from running!!!  BUMMER!!!
		///  It also seems to not work in Opera4.02 but only prevents
		///  the 2 letter codes from working but doesn't crash the script.
		var countryCodePattern = /\.[a-zA-Z][a-zA-Z]/;

		if      ( last4chars == ".COM" )  isStandardReturn = true;
		else if ( last4chars == ".EDU" )  isStandardReturn = true;
		else if ( last4chars == ".GOV" )  isStandardReturn = true;
		else if ( last4chars == ".NET" )  isStandardReturn = true;
		else if ( last4chars == ".MIL" )  isStandardReturn = true;
		else if ( last4chars == ".ORG" )  isStandardReturn = true;
		else if ( last4chars == ".BIZ" )  isStandardReturn = true;
	  else if ( last5chars == ".INFO" ) isStandardReturn = true;
	  else if ( last5chars == ".MOBI" ) isStandardReturn = true;
	  else if ( last5chars == ".NAME" ) isStandardReturn = true;
	  else if ( last5chars == ".ASIA" ) isStandardReturn = true;
		else if ( last4chars.search( countryCodePattern )   !=  -1 )

		isStandardReturn = true;

		return  isStandardReturn;

	} // Ends isStandardDomain(domainIn)


	/// Checks basic validity of an email address that's passed in.
	///  Requires proper configuration of the '@' character lack of Spaces
	///  and calls function "isStandardDomain()" to check on the form of the
	///  domain name part.
	/// Used an alert box to display it's answer.
	/// This function needs JS1.2 [because isStandardDomain() does] and does not work in Opera3.5.
	function  validateEmailAddress(objName) {

		var emailIn;
		emailIn = objName.value;

		/// Number of '@' chars present in input string.
		var numAtChars;

		/// The part of input address before the '@' character.
		var userNameIn;

		/// The part of input address after the '@' character.
		var domainNameIn;

		/// Holds the fields of the entered address, delimitted by '@' chars.
		var addressFields = new Array();

		// Concatenate all alert output to here.
		var alertString = "";

		/// Divide the input email address into fields.
		///  Note that the array "addressFields" will have one more element
		///  than the number of '@' signs in the input string.
		/// IE4 handles this OK with '@' as last character but NS4,4.5 and Opera 3.5 don't.
		addressFields = emailIn.split('@');

		numAtChars = addressFields.length - 1;

		alertString += "Email Address ";

		if ( emailIn == "" )
			alertString += "must be entered.";

		else if ( numAtChars  ==  0 )
			alertString += "contains no '@' character and is therefore Not a valid Email Address.";

		else if ( numAtChars  >  1 )
			alertString += "contains " + numAtChars + " '@' characters and is therefore Not a valid Email Address.";

		else if ( addressFields[0] == "" )
			alertString += "has no Username before the '@' character and is therefore Not a valid Email Address.";

		else if ( addressFields[1] == "" )
			alertString += "has no Domain Name after the '@' character and is therefore Not a valid Email Address.";

		else {
			userNameIn   = addressFields[0];
			domainNameIn = addressFields[1];

			if ( userNameIn.indexOf( " " ) != -1 )
				alertString += "has one or more Spaces in the Username before the '@' character and is therefore Not a valid Email Address.";
			else if ( domainNameIn.indexOf( " " ) != -1 )
				alertString += "has one or more Spaces in the Domain Name after the '@' character and is therefore Not a valid Email Address.";
			else if ( isStandardDomain( domainNameIn ) == false )
				alertString += "does not end with a '.com' style domain or two letter country code domain and is therefore Not a valid Email Address.";
			else
				alertString = "";

		} // Ends else from outer string of if-then-else's.

		// Post the alert box.
		if (alertString.length > 0) {
			alert(alertString);
			objName.focus();
			return false;
		}

		return true;

	} // Ends validateEmailAddress(objName)

	function isEmpty(objName) {
		var field;
		var fieldvalue;
		field = objName;
		fieldvalue = field.value;
		if (fieldvalue.length == 0) {
			alert("This is a required field.");
			objName.focus();
		}
	}

	function checkdate(objName) {
		var datefield = objName;
		if (chkdate(objName) == false) {
			datefield.select();
			alert("The date is invalid.  Please try again.");
			datefield.focus();
			return false;
		}
		else {
			return true;
		}
	}

	//Validate a date field
	function chkdate(objName) {
		var strDatestyle = "US"; //United States date style
		//var strDatestyle = "EU";  //European date style
		var strDate;
		var strDateArray;
		var strDay;
		var strMonth;
		var strYear;
		var intday;
		var intMonth;
		var intYear;
		var booFound = false;
		var datefield = objName;
		var strSeparatorArray = new Array("-"," ","/",".");
		var intElementNr;
		var err = 0;
		var strMonthArray = new Array(12);
		strMonthArray[0] = "Jan";
		strMonthArray[1] = "Feb";
		strMonthArray[2] = "Mar";
		strMonthArray[3] = "Apr";
		strMonthArray[4] = "May";
		strMonthArray[5] = "Jun";
		strMonthArray[6] = "Jul";
		strMonthArray[7] = "Aug";
		strMonthArray[8] = "Sep";
		strMonthArray[9] = "Oct";
		strMonthArray[10] = "Nov";
		strMonthArray[11] = "Dec";
		strDate = datefield.value;

		//If the date field is empty, return without validating
		if (strDate.length < 1) {
			return true;
		}

		//Retrieve the month, day and year portions of the date
		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];
				}
				booFound = true;
			}
		}

		if (booFound == false) {
			if (strDate.length > 5) {
				strDay = strDate.substr(0, 2);
				strMonth = strDate.substr(2, 2);
				strYear = strDate.substr(4);
			}
			else
				return false;
		}

		//If year is only 2 positions long, then prefix with "20"
		if (strYear.length == 2) {
			strYear = '20' + strYear;
		}

		// US style
		if (strDatestyle == "US") {
			strTemp = strDay;
			strDay = strMonth;
			strMonth = strTemp;
		}

		intday = parseInt(strDay, 10);

		if (isNaN(intday)) {
			err = 2;
			return false;
		}

		intMonth = parseInt(strMonth, 10);

		if (isNaN(intMonth)) {
			for (i = 0;i<12;i++) {
				if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
					intMonth = i+1;
					strMonth = strMonthArray[i];
					i = 12;
				}
			}
			if (isNaN(intMonth)) {
				err = 3;
				return false;
			}
		}

		intYear = parseInt(strYear, 10);

		if (isNaN(intYear)) {
			err = 4;
			return false;
		}

		if (intMonth>12 || intMonth<1) {
			err = 5;
			return false;
		}

		if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
			err = 6;
			return false;
		}

		if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
			err = 7;
			return false;
		}

		if (intMonth == 2) {
			if (intday < 1) {
				err = 8;
				return false;
			}
			if (LeapYear(intYear) == true) {
				if (intday > 29) {
					err = 9;
					return false;
				}
			}
			else {
				if (intday > 28) {
					err = 10;
					return false;
				}
			}
		}

		return true;
	}

	//Determine if year is a leap year
	function LeapYear(intYear) {
		if (intYear % 100 == 0) {
			if (intYear % 400 == 0) { return true; }
		}
		else {
			if ((intYear % 4) == 0) { return true; }
		}
		return false;
	}

	function trim(stringToTest)
	{
    	var kk
    	var subStart
    	var subEnd

			if (stringToTest == null)
				 return (" ")
			if (stringToTest.length == 0)
       	return (" ")


    	subStart = (-1)
    	for (kk=0;kk<stringToTest.length;kk++)
    	{
        	if (stringToTest.charAt(kk) > " ")
        	{
          	subStart = kk
          	break;
        	}
    	}

    	for (kk=stringToTest.length;kk>=0;kk--)
    	{
        	if (stringToTest.charAt(kk) > " ")
        	{
           	subEnd = kk
           	break;
        	}
    	}

    	if (subStart < 0)
       	return (" ")
    	return (stringToTest.substr(subStart,subEnd+1))
	}

// -->
