/* $Id: registration1.js 4903 2010-05-19 18:52:16Z vivek.awana@nbcuni.com $
 * Custom JavaScript Library for Registration Module
 * Not to be confused with registration.js which was supplied
 * by IndustryNext WebDesigning team.
*/
var sites ="";
var email="";

function matchConfirmEmail(textBox) {
	var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkMatch(theForm['email_input'],textBox,icuesnasregistration.Validator.emailconfirmation) == false) return false;
	
}

function checkZip(textBox) {
	if ($("#country").val() == 'USA') {
		if (icuesnasregistration.Validator.checkString(textBox,"Zip/Postal Code") == false) {
			return false ;
		} else	if (icuesnasregistration.Validator.checkZIPCode(textBox)== false) {
			return false ;
		}
	}
	return true;
}

function checkHowDidHear(textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Source")== false) { 
		return false;
	} else 	if ($("#howhear").val() != "-1" && $("#howhear").val() != "Friend/Family") {
		$('#pleasespecify_div').show();
	}
	return true;
}


function checkFirstName(textBox) {
	var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkFirstName(textBox, "First Name") == false) return false ;
		if(textBox.value.replace(/^\s+|\s+$/g, "") == ""){
			/*alert("in checkUserName()"); */
			icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emptyfirstname,textBox);
			return;
		}

	}
function checkHowDid(textBox) {

	if (icuesnasregistration.Validator.checkHowDid(textBox, "How did") == false) return false ;
		if(textBox.value.replace(/^\s+|\s+$/g, "") == ""){
			/*alert("in checkUserName()"); */
			icuesnasregistration.Validator.displayError("This field is required.",textBox);
			return;
		}

	}

function checkPhone(textBox) {
	
	//var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkGeneralPhoneRules(textBox) == false) return false ;
		

	}

function checkPhoneFormatOnly(textBox) {
	
	//var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkPhoneFormatRules(textBox,true) == false) return false ;
		

	}



function checkSchool(textBox) {
	
	//var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkString(textBox,"Institution Name") == false) return false ;
		

	}

function checkState( textBox){

	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"State")== false) return false;
	
}
function checkStateName(textBox) {
	
	//var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkString(textBox,"State") == false) return false ;
		

}

function checkAddress1(textBox) {
	
	//var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkString(textBox,"Address ") == false) return false ;
		

	}

function checkCity(textBox) {
	
	//var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkString(textBox,"City") == false) return false ;
		

	}

function checkCountry( textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Country")== false) return false;
}

function checkRole(textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Role")== false) return false;
}


function checkReason(textBox){
        if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Reason")== false) return false;
}
function checkInterest(textBox){
	if (icuesnasregistration.Validator.checkInvalidInterestListSelection(textBox,"Interest")== false) return false;
}

function checkBbSystem(textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Blackboard System")== false) return false;
}

function agePopUp(){
	var result="";

	age_popup("Under 13 Error",icuesnasregistration.Validator.agebelow13alert,'popup_small');
}


function checkLastName(textBox) {
	var theForm = document.getElementById("registration_form");
	if(icuesnasregistration.Validator.checkLastName(textBox, "Last Name") == false) return false ;
		if(textBox.value.replace(/^\s+|\s+$/g, "") == ""){
			/*alert("in checkUserName()"); */
			icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emptylastname,textBox);
			return;
		}

	}

function checkPassword(textBox) {
	var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkMinChar(textBox,icuesnasregistration.Validator.passwordlength , 6, true) == false) return false ;
	if (icuesnasregistration.Validator.checkMaxChar(textBox, "Password", 32, true) == false) return false ;

	

	}

function matchConfirmPassword(textBox) {
	var theForm = document.getElementById("registration_form");
      if (icuesnasregistration.Validator.checkString(textBox, "Confirm Password", true) == false) return false ;
	
	  if (icuesnasregistration.Validator.checkMatch(theForm['password_input'], textBox, icuesnasregistration.Validator.passwordconfirmation) == false) return false ;
}
	function checkUserName(textBox) {
		
		try{
			
			if(textBox.value.replace(/^\s+|\s+$/g, "") == ""){
				/*alert("in checkUserName()"); */
				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emptydiaplyname,textBox);
				return;
			}

			if(icuesnasregistration.Validator.checkMinChar(textBox, icuesnasregistration.Validator.displaynamelength, 6, true) == false) return false;

			var val = textBox.value.split(" ");

			if (val.length > 1) {
				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.singleworddisplayname,textBox);
				return false;
			}

			if(icuesnasregistration.Validator.checkUserName(textBox, "Display Name") == false) return false;;

			var snasUrl = window.location.protocol + "//" + document.domain + ":" + 
						  (window.location.port ? parseInt(window.location.port):'') + 
						  "/nbcarchive/snas/api/isUsernameAvailable?userName=" + textBox.value + "&siteName=aod.icue.nbcuni.com";
			
			/*alert("snasUrl: "+snasUrl); */
			
			$.ajax({
			  
			    url: snasUrl,
			    type: 'GET',
			    dataType: 'text',
			    timeout: 25000,
			    error: function(){
			        alert('AjaX Error!');
			    },
			    success: function(xml){
			       	if(xml.indexOf("false") != -1){
		
				    
			       		//registration_popup("checkname","Display name already taken - please try again.",'popup_small');
			       		icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.displaynameexistonsite,textBox);
						//textBox.focus();
						//textBox.value = "";

					}
			    }
			});
		} catch (ex) {
			alert("Error: " + ex.description);
		}
	}

	$(document).ajaxError(function(){

	    if (window.console && window.console.error) {
	
	        console.error(arguments);

	    }
	});
	
	function checkEmailformatOnly(emailField){
		if (icuesnasregistration.Validator.checkEmail(emailField, false) == false) return ;
	}

	function checkEmail(emailField) {
		try{
            sites="";
			email = emailField.value;
			
			var verifiedEmail = document.getElementById('verifiedEmail').value;

			//if(email == verifiedEmail && ! document.getElementById('uniqueIdentifier').value == ""){
				
				/* Email Already verified. Hide fields.*/
				//hideLogin(true, 'registrationForm');
				//return false;
			
			//} else {
				/* New Email. Unhide fields.*/
			//	hideLogin(false, 'registrationForm');
				
			//}
			
			if(email.replace(/^\s+|\s+$/g, "") == ""){

				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emptyemail,emailField);
				
				return false;
				
			}
			if (icuesnasregistration.Validator.checkEmail(emailField, false) == false) return ;
			//var parentsEmail=document.getElementById('parentGuardianEmail').value.replace(/^\s+|\s+$/g, "");
		
			/*if(email == parentsEmail) {
				document.getElementById('parentGuardianEmail').value = "";
				document.getElementById('alertText').innerHTML = "The email address used to register cannot also be used for parent/guardian approval. Please use the address of your parent or guardian.";
				$('#alertDialog').jqmShow();
				document.getElementById('parentGuardianEmail').focus();
			}
			*/
			var snasUrl = window.location.protocol + "//" + document.domain + ":" + 
						  (window.location.port ? parseInt(window.location.port):'') + 
						  "/nbcarchive/snas/api/checkEmailExists?email=" + emailField.value;
			
			$.ajax({
			    url: snasUrl,
			    type: 'GET',
			    dataType: 'xml',
			    timeout: 25000,
			    error: function(){
			        alert('AjaX Error!');
			    },
			    success: function(xml){
			    	
			    	var bool = $(xml).find('status').text();
			    	
			    	
			    	if(bool) {
			    		
			    		var isinnbcarchive = false;
			    		
			    		//var sites = "";
	                    
	                    $(xml).find('site').each(function(){
	                         
	                         var siteName = $(this).text();
	                         
	                         sites += siteName + ","; 
	                         
	                         if(siteName == "aod.icue.nbcuni.com"){
	                         
	                         	isinnbcarchive = true;
	                         
	                         }
	                    });
	                    
	                    //document.getElementById('userSites').value = sites;
	                    
	                    if(isinnbcarchive) {
	                    	
	                    	//emailField.focus();
	                    	
	                    	//document.getElementById('alertText').innerHTML = "Email already registered in Archives on Demand! <br>please enter a different email address";
	                    	
							///$('#alertDialog').jqmShow();
	                    	//registration_popup("checkmail","Email already registered in Archives on Demand! <br>please enter a different email address",'popup_small');
	                    	icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emailexistonsite,emailField);
	                    	//emailField.value = "";
	                    	//emailField.focus();
	                    	
	                    } else if(sites.length > 1) {
	                    	
	                    	sites = sites.substring(0, sites.length - 1);
				    		
	                    	//document.getElementById('userEmail').innerHTML = emailField.value;
				//document.getElementById('userEmail').innerHTML = "You already have an account on " + sites + " with this email address: " + emailField.value;
	                    	var result ='<p>You already have an account on ' + sites + 'with this email address: ' + emailField.value +'</p><p>Please enter a password for this account:<br><input type="password" id="anotherPassword" class="small_input" /></p>';
	                    	registration_popup("Check Email",result,'popup_small');
	                    	//document.getElementById('existingEmail').value = emailField.value;
	                    	//document.getElementById('existingSites').value = sites;
	                    	
	                    	//$('#mediumDialog').jqmShow();
	                    }
	                    
			    	}
			    }
			});
		} catch (ex) {
			alert("Error: " + ex);
		}
	}

	function verifyEmail() {
		var password = document.getElementById('anotherPassword').value;
		if(password.replace(/^\s+|\s+$/g, "") == ""){
			
			alert("Please enter your password...!");
			
			document.getElementById('anotherPassword').value = "";
			
			return false;
		}
		
		var sitesArray = sites.split(",");
			
		var snasURL = window.location.protocol + "//" + document.domain + ":" + 
						  (window.location.port ? parseInt(window.location.port):'') + 
						  "/nbcarchive/snas/api/authenticatePersonWithEmail?email=" + email + 
						  "&password=" + password + "&siteName=" + sitesArray[0];
		authenticatePass(snasURL, password) ;
	
	
	}

	function authenticatePass(snasURL, password) {
		
		try{
			$.ajax({
			    url: snasURL,
			    type: 'GET',
			    dataType: 'text/xml',
			    timeout: 25000,
			    error: function(){
			        alert('AjaX Error!');
			       
			    },
			    success: function(xml){
				    
				    if(xml.indexOf("<uniqueIdentifier>") > -1)
				    {
				    	uniqueIdentifier = xml.substring(xml.indexOf("<uniqueIdentifier>") + 18, xml.indexOf("</uniqueIdentifier>"));

				    	document.getElementById("uniqueIdentifier").value = uniqueIdentifier;

						//hideLogin(true, 'registrationForm');
						//hideConfirmations('registrationForm');

						document.getElementById('confirm_email_input').value = email;
						
						document.getElementById("registration_form")["password_input"].value = password;

						document.getElementById("confirm_password_input").value = password;
						
						//document.getElementById("confirmEmail").disabled = true;
				    	document.getElementById('verifiedEmail').value = email;
				    	
				    	//document.getElementById("tempassword").value = password;
				    	
				    	document.getElementById("password_input").value = password;
				    	
				    	$('.dialog_popup').dialog("close");


				    } else {
						alert("wrong password!, please reenter the password");
						document.getElementById('anotherPassword').value = "";
						document.getElementById('anotherPassword').focus();
					}
			    }
			});
			
		} catch (ex) {
			alert("Error: " + ex);
		}
	}

	function opt_disabled(select_object){
		try {
			
			var selIndex = select_object.selectedIndex;
			
			if(select_object.options[selIndex].disabled){
				
				while (select_object.options[selIndex].disabled) selIndex += 1;
				
				select_object.selectedIndex = selIndex;
			}
			
			return true;
			
		} catch(e){
		}
	}

	function cancelEmailVerification(){
		
		document.getElementById('anotherPassword').value = "";
		document.getElementById("email").focus();
	}

	function isValidDate(day, month, year) {

		if (month < 1 || month > 12) {
			return false;
		}
		
		if (day < 1 || day > 31) {
			return false;
		}
		
		if ((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31)) {
			return false;
		}
		
		if (month == 2) {
			
			var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			
			if (day > 29 || (day == 29 && !leap)) {
			
				return false;
			
			}
		}
		
		return true;
	}

	function enableRequiredFields(bool) {
		
		document.getElementById('day').disabled = !bool;
		
		document.getElementById('month').disabled = !bool;
		
		document.getElementById('year').disabled = !bool;
		document.getElementById('password').disabled = !bool;

		return true;
	}



var registration ={} ;

registration.Validator = {
	
	validate_registrationForm : function() 
	{
	    var formsubmit=true;
	    
		var theForm = document.getElementById("registration_form");
		
		if (theForm['formtype'].value=="register"){

		theForm['email_input'].value = icuesnasregistration.Validator.trimString(theForm['email_input'].value); 
		if (icuesnasregistration.Validator.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
		
		if (icuesnasregistration.Validator.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

		if (icuesnasregistration.Validator.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
		
		if (icuesnasregistration.Validator.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

		if (icuesnasregistration.Validator.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
	
		if (icuesnasregistration.Validator.checkMatch(theForm['email_input'], theForm['confirm_email_input'], icuesnasregistration.Validator.emailconfirmation) == false) formsubmit= false;

		if (icuesnasregistration.Validator.checkString(theForm['password_input'], "Password", false) == false) formsubmit= false ;

		if (icuesnasregistration.Validator.checkMinChar(theForm['password_input'], icuesnasregistration.Validator.passwordlength, 6, true) == false) formsubmit= false ;
		
		if (icuesnasregistration.Validator.checkMaxChar(theForm['password_input'], "Password", 32, true) == false) formsubmit= false ;

		if (icuesnasregistration.Validator.checkString(theForm['confirm_password_input'], "Confirm Password", true) == false) formsubmit= false ;
		
		if (icuesnasregistration.Validator.checkMatch(theForm['password_input'], theForm['confirm_password_input'], icuesnasregistration.Validator.passwordconfirmation) == false) formsubmit= false ;

		theForm['displayName'].value = icuesnasregistration.Validator.trimString(theForm['displayName'].value); 
		
		if (icuesnasregistration.Validator.checkUserName(theForm['displayName'], "Display Name") == false) formsubmit= false ;
		if (icuesnasregistration.Validator.checkString(theForm['communitynamereg'],"School/Business Name") == false) formsubmit= false ;
		
		if (icuesnasregistration.Validator.checkMinChar(theForm['displayName'], icuesnasregistration.Validator.displaynamelength, 6, true) == false) formsubmit= false ;
		if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
		//if (icuesnasregistration.Validator.checkString(theForm['city'],"City ") == false) formsubmit= false ;
		option = $("#my_role").val();  
		if ( option=='Student'|| option=='student'){
		if (icuesnasregistration.Validator.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
		}

		if (!theForm['tos'].checked)
		{
			icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.iagreetos,theForm['tos']);
			formsubmit= false ;
		}
		
		if (icuesnasregistration.Validator.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
		}
		if (theForm['formtype'].value=="freetrial"){
			theForm['email_input'].value = icuesnasregistration.Validator.trimString(theForm['email_input'].value); 
			if (icuesnasregistration.Validator.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if (icuesnasregistration.Validator.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
		
			if (icuesnasregistration.Validator.checkMatch(theForm['email_input'], theForm['confirm_email_input'], icuesnasregistration.Validator.emailconfirmation) == false) formsubmit= false;

			if (icuesnasregistration.Validator.checkString(theForm['password_input'], "Password", false) == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkMinChar(theForm['password_input'], icuesnasregistration.Validator.passwordlength, 6, true) == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkMaxChar(theForm['password_input'], "Password", 32, true) == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['confirm_password_input'], "Confirm Password", true) == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkMatch(theForm['password_input'], theForm['confirm_password_input'], icuesnasregistration.Validator.passwordconfirmation) == false) formsubmit= false ;

			theForm['displayName'].value = icuesnasregistration.Validator.trimString(theForm['displayName'].value); 
			
			if (icuesnasregistration.Validator.checkUserName(theForm['displayName'], "Display Name") == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkMinChar(theForm['displayName'], icuesnasregistration.Validator.displaynamelength, 6, true) == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkGeneralPhoneRules(theForm['phone1'])==false)formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['address1'],"Address ") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['communityname'],"School/Business Name") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkHowDid(theForm['howhear'], "How did") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['country'],"Country")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['city'],"City ") == false) formsubmit= false ;
			option = $("#my_role").val();  
			if ( option=='Student'|| option=='student'){
			if (icuesnasregistration.Validator.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			}

			if (!theForm['tos'].checked)
			{
				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.iagreetos,theForm['tos']);
				formsubmit= false ;
			}
			
			if (icuesnasregistration.Validator.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;	
			
		}
		if (theForm['formtype'].value=="contactsales"){
			theForm['email_input'].value = icuesnasregistration.Validator.trimString(theForm['email_input'].value); 
			if (icuesnasregistration.Validator.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if (icuesnasregistration.Validator.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
		
			if (icuesnasregistration.Validator.checkMatch(theForm['email_input'], theForm['confirm_email_input'], icuesnasregistration.Validator.emailconfirmation) == false) formsubmit= false;

			if (icuesnasregistration.Validator.checkGeneralPhoneRules(theForm['phone1'])==false)formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['address1'],"Address ") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['communityname'],"Institution Name") == false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkHowDid(theForm['howhear'], "How did") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['howhear'], "Source") == false) formsubmit= false ;

		//	if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['country'],"Country")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['bbsystem'],"Blackboard System")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['city'], "City") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['zip'], "Zip") == false) formsubmit= false ;
			
			
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['country'],"Country")== false) {
				formsubmit= false ;
			} else {
				$('#countryName').val($('#country option:selected').text()); 
				if ($("#country").val() == 'USA') {
					$('#state_div').show();
					$('#stateName').val('');
					$('#state_name_div').hide();
					if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['state'],"State")== false) formsubmit= false ;
					
					if (icuesnasregistration.Validator.checkString(theForm['zip'],"Zip/Postal Code ") == false) formsubmit= false ;
					
					if (!icuesnasregistration.Validator.isEmpty(theForm['zip'].value)) {
						if (icuesnasregistration.Validator.checkZIPCode(theForm['zip'])== false) formsubmit= false ;
					}
				} else {
					$("#state option[value='-1']").attr('selected', 'selected');
					$('#state_div').hide();
					$('#state_name_div').show();
					if (icuesnasregistration.Validator.checkString(theForm['stateName'], "State/Province") == false) formsubmit= false ;
				}
			}

			//if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['state'], "State") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidInterestListSelection(theForm['interested_in'],"Interest")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkString(theForm['city'],"City ") == false) formsubmit= false ;
			//option = $("#my_role").val();  
			//if ( option=='Student'|| option=='student'){
			//if (icuesnasregistration.Validator.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			//}

			if (!theForm['tos'].checked)
			{
				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.iagreetos,theForm['tos']);
				formsubmit= false ;
			}
			
			if (icuesnasregistration.Validator.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
			
		}
		
		if (theForm['formtype'].value=="contactus"){
			theForm['email_input'].value = icuesnasregistration.Validator.trimString(theForm['email_input'].value); 
			if (icuesnasregistration.Validator.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if (icuesnasregistration.Validator.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
		
			if (icuesnasregistration.Validator.checkMatch(theForm['email_input'], theForm['confirm_email_input'], icuesnasregistration.Validator.emailconfirmation) == false) formsubmit= false;

			if (icuesnasregistration.Validator.checkGeneralPhoneRules(theForm['phone1'])==false)formsubmit= false ;
			//if (icuesnasregistration.Validator.checkString(theForm['address1'],"Address ") == false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkString(theForm['communityname'],"School/Business Name") == false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkHowDid(theForm['reason'], "How did") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkHowDid(theForm['comments'], "How did") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['reason'],"Reason")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkString(theForm['city'],"City ") == false) formsubmit= false ;
			//option = $("#my_role").val();  
			//if ( option=='Student'|| option=='student'){
			//if (icuesnasregistration.Validator.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			//}

			/*if (!theForm['tos'].checked)
			{
				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.iagreetos,theForm['tos']);
				formsubmit= false ;
			}
			
			if (icuesnasregistration.Validator.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;	*/
			
		}

		return formsubmit;
	},
	
	validate_contactUsForm : function() 
	{
		var formsubmit=true;
	    
		var theForm = document.getElementById("contactusform");
		//if (theForm['formtype'].value=="contactus"){
			theForm['email_input'].value = icuesnasregistration.Validator.trimString(theForm['email_input'].value); 
			if (icuesnasregistration.Validator.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if (icuesnasregistration.Validator.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if (icuesnasregistration.Validator.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if (icuesnasregistration.Validator.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			//if (icuesnasregistration.Validator.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
		
			//if (icuesnasregistration.Validator.checkMatch(theForm['email_input'], theForm['confirm_email_input'], icuesnasregistration.Validator.emailconfirmation) == false) formsubmit= false;

			if (icuesnasregistration.Validator.checkGeneralPhoneRules(theForm['phone1'])==false)formsubmit= false ;
			if (icuesnasregistration.Validator.checkPhoneFormatRules(theForm['phone2'],true)==false)formsubmit= false ;
			//if (icuesnasregistration.Validator.checkString(theForm['address1'],"Address ") == false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkString(theForm['communityname'],"School/Business Name") == false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkHowDid(theForm['reason'], "How did") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkHowDid(theForm['writeusanote'], "How did") == false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['reason'],"Reason")== false) formsubmit= false ;
			if (icuesnasregistration.Validator.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			//if (icuesnasregistration.Validator.checkString(theForm['city'],"City ") == false) formsubmit= false ;
			option = $("#my_role").val();  
			if ( option=='Student'|| option=='student'){
			if (icuesnasregistration.Validator.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			}

			/*if (!theForm['tos'].checked)
			{
				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.iagreetos,theForm['tos']);
				formsubmit= false ;
			}*/
			
			if (icuesnasregistration.Validator.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
			
		//}

		return formsubmit;
		
		
	}

}


var icuesnasregistration ={} ;

icuesnasregistration.Validator= {

		whitespace : " \t\n\r",
		digits : "0123456789",
		emailconfirmation: "Email and Confirm Email do not match.  Please verify they are the same",
		passwordconfirmation: "Password and Confirm Password do not match. Please verify they are the same",
		passwordlength: "Please enter a password at least 6 characters long (letters and/or numbers)",
		displaynamelength: "Your Display Name must be at least 6 characters long",
		iagreetos: "You must agree to the Terms of Service & Privacy Policy to use Archives on Demand",
		emailexistonsite: "Email already registered in Archives on Demand!please enter a different email address",
		displaynameexistonsite: "Display name already taken - please try again",
		emptyfirstname: "Please enter your First Name",
		emptylastname: "Please enter your Last Name",
		emptyemail: "Please enter your Email Address",
		emptyphone: "Please enter your Phone Number",
		emptydiaplyname: "Please enter your Display Name",
		agebelow13alert: "<p>At this time we are not able to allow users under 13 to create accounts in NBC News Archives on Demand. <br>Please talk with your parents or teacher about accessing the website.</p>",
		iPhone : "Only numbers,spaces, dashes, and parentheses are allowed in Phone",
		singleworddisplayname: "Display name has to be a single word",
		mPrefix : "Please enter your ",
		mSuffix : "",
		defaultEmptyOK : false,
		maxCharPrefix : "Maximum character limit reached for ",
		maxCharSuffix : " ",
		minCharPrefix : "The ",
		minCharSuffix1 : " must have a minimum of ",
		minCharSuffix2 : " characters. Please re-enter it now",
		iEmail : "Please enter a valid email address (i.e foo@bar.com)" ,
		iCity : "Please enter your city name" ,
		iUSPhone : "This field must be a 10 digit U.S. phone number (i.e 415 555 1212),Please reenter it now",
		iUSFax : "This field must be a 10 digit U.S. fax number (i.e 415 555 1212), Please reenter it now",
		iWorldPhone : "Please enter a valid international phone number",
		iWorldFax : "Please enter a valid international fax number",
		iZIPCode : "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now",
		pSelectPrompt : "Please select a ",
		pSelectInterest: "Please select your ",
		iFirstName: "Only letters, numbers, white space between words and single quote (\') are allowed in First Name",
		iLastName: "Only letters, numbers, white space between words and single quote (\') are allowed in Last Name",
		iUserName: "Only letters, numbers, underscore (_) and dash (-) are allowed in Archives on Demand Display Name",
		digitsInZIPCode1 : 5,
		digitsInZIPCode2 : 9,
		ZIPCodeDelimiters : "-",
		ZIPCodeDelimeter : "-",
		validZIPCodeChars : this.digits + this.ZIPCodeDelimiters,
		phoneNumberDelimiters : "()- ",
		digitsInUSPhoneNumber : 10,
		
		// *********************** IS FUNCTIONS *******************************
		isEmpty : function (s)
		
		{  
			return ((s == null) || (s.length == 0));
		},
		
		isWhitespace : function (s)
		
		{   var i;
		
		    if (this.isEmpty(s)) return true;
		
		    for (i = 0; i < s.length; i++)
		    {
		        var c = s.charAt(i);
		
		        if (this.whitespace.indexOf(c) == -1) return false;
		    }
		
		    return true;
		},
		
		charInString : function (c, s)
		
		{   for (i = 0; i < s.length; i++)
		    {   if (s.charAt(i) == c) return true;
		    }
		    return false;
		},
		
		isLetter : function (c)
		
		{   
			return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
		},
		
		isDigit : function  (c)
		
		{   
			return ((c >= "0") && (c <= "9"));
		},
		
		isLetterOrDigit : function  (c)
		
		{   
			return (this.isLetter(c) || this.isDigit(c));
		},
		
		isAlpha : function (s)
		
		{   var i;
		
		    for (i = 0; i < s.length; i++)
		    {
		        /*Check that current character is letter.*/
		        var c = s.charAt(i);
		
		        if (!this.isLetter(c)) {
		        	return false;
				}
		    }
		    /*All characters are letters.*/
		    return true;
		},
		
		isAlpha1 : function (s)
		
		{   var i;
		
		    for (i = 0; i < s.length; i++)
		    {
		        // Check that current character is letter.
		        var c = s.charAt(i);
		
		        if (!this.isLetter(c)) {
				if (c != ' ') {
					if (c != ".") {
		        			return false;
					}
				}
			}
		    }
		    // All characters are letters.
		    return true;
		},
		
		isAlphaNumeric : function (s)
		
		{   var i;
		
		    for (i = 0; i < s.length; i++)
		    {
		        // Check that current character is letter or a digit
		        var c = s.charAt(i);
		
		        if (!this.isLetterOrDigit(c)) {
					return false;
				}
			}
		 
		    // All characters are alpha numeric.
		    return true;
		},
		
		isInteger : function  (s)
		
		{   var i;
		
		    if (this.isEmpty(s))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		
		
		    for (i = 0; i < s.length; i++)
		    {
		        var c = s.charAt(i);
		
		        if (!this.isDigit(c)) return false;
		    }
		
		    return true;
		},
		
		isSignedInteger : function  (s)
		
		{   
		
			if (this.isEmpty(s))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		
		    else {
		        var startPos = 0;
		        var secondArg = this.defaultEmptyOK;
		
		        if (arguments.length > 1)
		            secondArg = arguments[1];
		
		        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
		           startPos = 1;
		        return (this.isInteger(s.substring(startPos, s.length), secondArg));
		    }
		},
		
		
		isPositiveInteger : function  (s)
		
		{   var secondArg = this.defaultEmptyOK;
		
		    if (arguments.length > 1)
		        secondArg = arguments[1];
		
		    return (this.isSignedInteger(s, secondArg)
		         && ( (this.isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
		},
		
		isvalidEmailChar : function  (s)
		
		{   
			var invalidChars = " /:,;#$%^()+{}[]|\\`~<>\"?" ;
		    
		    if (s == ""){
				return false;
		    }
		    
		    for (e2=0; e2< invalidChars.length; e2++)
		    {
				badChar = invalidChars.charAt(e2)
				if (s.indexOf(badChar,0) != -1)
				{
			    	return false;
				}
		    }
		
		    return true;
		},
		
		isEmail : function  (str)
		
		{   if (this.isEmpty(str))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		
		    if (this.isWhitespace(str)) return false;
		    if (!this.isvalidEmailChar(str)) return false;
		
				var at="@";
				var dot=".";
				var lat=str.indexOf(at);
				var lstr=str.length;
				var ldot=str.indexOf(dot);
				
				/* CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING */
				if (str.indexOf(at)==-1){
				   return false;
				}
				
				/* CHECK THERE IS AT LEAST ONE CHARACTER BEFORE AND AFTER THE '@' CHARACTER */
				if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
				   return false;
				}
		
				 /* CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING */
				 /* CHECK THERE IS AT LEAST ONE CHARACTER BEFORE AND AFTER THE PERIOD CHARACTER */
				if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				    return false;
				}
		
				 if (str.indexOf(at,(lat+1))!=-1){
				    return false;
				 }
		
				 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				    return false;
				 }
		
				 if (str.indexOf(dot,(lat+2))==-1){
				    return false;
				 }
				
				 if (str.indexOf(" ")!=-1){
				    return false;
				 }
				
				 /* CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD */
				  var pos = str.lastIndexOf (dot) + 1;
				  
				  if ((lstr - pos ) < 2 || (lstr - pos) > 3) {
				  	return false ;
				  }
				  
				  /* CHECK THAT THERE ARE ONLY ALPHA CHARACTERS AFTER THE LAST PERIOD */
				  if (!this.isAlpha(str.substring(pos))) {
				  	return false ;
				  }
				  				 	
		 		 return true	;				
		},
		
		isUSorCanada : function (s) 
		
		{
			if (this.isEmpty(s))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		       
		    if((s=="USA") || (s=="Canada")) return true;
		    
		    return false ;   
		       
		},
		
		isZIPCode : function  (s)
		
		{  if (this.isEmpty(s))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		   return (this.isInteger(s) &&
		            ((s.length == this.digitsInZIPCode1) ||
		             (s.length == this.digitsInZIPCode2)));
		},
		
		isUSPhoneNumber : function  (s)
		
		{  
			if (this.isEmpty(s))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		    return (this.isInteger(s) && s.length == this.digitsInUSPhoneNumber);
		},
		
		isInternationalPhoneNumber : function  (s)
		
		{   if (this.isEmpty(s))
		       if (arguments.length == 1) return this.defaultEmptyOK;
		       else return (arguments[1] == true);
		    return (this.isPositiveInteger(s));
		},
		
		isValidCity : function (name) 
		
		{
			var inName = this.stripInitialWhitespace(name);
			if (this.isAlpha1(inName)) {
				return true;
			}
			
			return false;
		},
		
		isSame : function (s1, s2)
		
		{
			if (s1 == s2) {
				return true ;
			}
			return false ;
		},
		//********************** MODAL ERROR DISPLAY *************************
		hideError : function (field) 
		{
			errdivid=field.id+"Error"; 
			document.getElementById(errdivid).innerHTML = "";
			document.getElementById(errdivid).style.display = 'none'; 
		},
		
		displayError : function (message,field) 
		
		{
			
			errdivid=field.id+"Error"; 
		
			document.getElementById(errdivid).innerHTML = "<p>"+message+"</p>";
			document.getElementById(errdivid).style.display = 'block'; 
			
        
        },
        
		// ********************* FORMAT FUNCTIONS *****************************
		trimString : function (str) 
		
		{
		  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
		},
		
		stripCharsInBag : function  (s, bag)
		
		{   var i;
		    var returnString = "";
		
		    for (i = 0; i < s.length; i++)
		    {
		        var c = s.charAt(i);
		        if (bag.indexOf(c) == -1) returnString += c;
		    }
		
		    return returnString;
		},
		
		stripCharsNotInBag : function  (s, bag)
		
		{   var i;
		    var returnString = "";
		
		    for (i = 0; i < s.length; i++)
		    {
		        var c = s.charAt(i);
		        if (bag.indexOf(c) != -1) returnString += c;
		    }
		
		    return returnString;
		},
		
		stripWhitespace : function  (s)
		
		{   
			return this.stripCharsInBag (s, this.whitespace);
		
		},
		
		stripInitialWhitespace : function  (s)
		
		{   var i = 0;
		
		    while ((i < s.length) && this.charInString (s.charAt(i), this.whitespace))
		       i++;
		
		    return s.substring (i, s.length);
		},
		
		reformat : function  (s)
		
		{   var arg;
		    var sPos = 0;
		    var resultString = "";
		
		    for (var i = 1; i < arguments.length; i++) {
		       arg = arguments[i];
		       if (i % 2 == 1) resultString += arg;
		       else {
		           resultString += s.substring(sPos, sPos + arg);
		           sPos += arg;
		       }
		    }
		    return resultString;
		},
		
		reformatZIPCode : function  (ZIPString)
		
		{   
			if (ZIPString.length == 5) return ZIPString;
		    else return (this.reformat (ZIPString, "", 5, "-", 4));
		},
		
		reformatUSPhone : function  (USPhone)
		
		{   
			return (this.reformat (USPhone, "(", 3, ") ", 3, "-", 4));
		},
		
		// *********************** WARN FUNCTIONS ********************************
		warnEmpty : function  (theField, s)
		
		{   //theField.focus();
		    this.displayError(this.mPrefix + s + this.mSuffix,theField);
		    return false;
		},
		
		warnInvalid : function  (theField, s)
		
		{   //theField.focus();
		    //theField.select();
		    this.displayError(s,theField);
		    return false;
		},
		
		warnSelection : function  (theField, s)
		
		{   
			
			return  this.displayError(this.pSelectPrompt + s,theField) ;
		
			
		},
		warnInterestSelection : function  (theField, s)
		
		{   
			
			return  this.displayError(this.pSelectInterest + s,theField) ;
		
			
		},
		
		warnMaxChar : function (theField, s) 
		
		{
			//theField.focus();
			this.displayError(this.maxCharPrefix + s + this.maxCharSuffix,theField);
			return false;
			
		},
		
		warnMatch : function (field1, label1, label2) 
		
		{
			//field1.focus();
			this.displayError("Values of fields " + label1 + " and " + label2 + " should match.");
			return false;
			
		},
		
		warnMinChar : function (theField, theMessage, minCharLength) 
		
		{
			//theField.focus();
		    //theField.select();
			this.displayError(theMessage,theField);
			return false;
			
		},
		
		// *********************** CHECK FUNCTIONS *******************************
		// Only these functions should be called from outside.
		checkString : function  (theField, s, emptyOK)
		
		{
		    if (arguments.length == 2) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    if (this.isWhitespace(theField.value))
		       return this.warnEmpty (theField, s);
		    else return true;
		},
		
		checkEmail : function  (theField, emptyOK)
		
		{   if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else if (!this.isEmail(theField.value, false))
		       return this.warnInvalid (theField, this.iEmail);
		    else return true;
		},
		
		checkAge : function  (theField, s)
		
		{   if(theField[0].checked || theField[1].checked) return true;
			else {
				this.displayError("Please select your " + s,theField[0]);
				return false;
			}
		},


		checkEducation : function  (theField, s)
		
		{   if(theField.selectedIndex != 0) return true;
			else {
				this.displayError("Please select your " + s,theField);
				return false;
			}
		},
		
		checkZIPCode: function  (theField, emptyOK)
		
		{   if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    { var normalizedZIP = this.stripCharsInBag(theField.value, this.ZIPCodeDelimiters)
		      if (!this.isZIPCode(normalizedZIP, false))
		         return this.warnInvalid (theField, this.iZIPCode);
		      else
		      {
		         theField.value = this.reformatZIPCode(normalizedZIP);
		         return true;
		      }
		    }
		},
		
		checkUSPhone : function  (theField, emptyOK)
		
		{ 
			if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  var normalizedPhone = this.stripCharsInBag(theField.value, this.phoneNumberDelimiters)
		       if (!this.isUSPhoneNumber(normalizedPhone, false))
		          return this.warnInvalid (theField, this.iUSPhone);
		       else
		       {
		          theField.value = this.reformatUSPhone(normalizedPhone);
		          return true;
		       }
		    }
		},
		
		

		    
		
		checkGeneralPhoneRules : function  (theField, emptyOK)
		
		{ 
			if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  var normalizedPhone = this.stripCharsInBag(theField.value, this.phoneNumberDelimiters)
		    	if (this.isEmpty(normalizedPhone)){
		    		this.warnEmpty(theField, "Phone");
		    		return false;
		    	}
		    	else{
		    	var i;			
			    for (i = 0; i < normalizedPhone.length; i++)
			    {
			        var c = normalizedPhone.charAt(i);
			      
			
			        if (!this.isDigit(c) && c != '-' && c!='(' && c!=')' && c!=' ') {
						
							this.warnInvalid(theField, this.iPhone);
							return false;
		
					}
					
				}
			    theField.value = normalizedPhone;
			    return true;
		    	}
		    }
		},
		
checkPhoneFormatRules : function  (theField, emptyOK)
		
		{ 
			if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  var normalizedPhone = this.stripCharsInBag(theField.value, this.phoneNumberDelimiters)
		    
		    	var i;			
			    for (i = 0; i < normalizedPhone.length; i++)
			    {
			        var c = normalizedPhone.charAt(i);
			      
			
			        if (!this.isDigit(c) && c != '-' && c!='(' && c!=')' && c!=' ') {
						
							this.warnInvalid(theField, this.iPhone);
							return false;
		
					}
					
				}
			    theField.value = normalizedPhone;
			    return true;
		    	}
		},
		
		checkUSFax : function  (theField, emptyOK)
		
		{   if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  var normalizedPhone = this.stripCharsInBag(theField.value, this.phoneNumberDelimiters)
		       if (!this.isUSPhoneNumber(normalizedPhone, false))
		          return this.warnInvalid (theField, this.iUSFax);
		       else
		       {
		          theField.value = this.reformatUSPhone(normalizedPhone);
		          return true;
		       }
		    }
		},
		
		checkInternationalPhone : function  (theField, emptyOK)
		
		{   if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  if (!this.isInternationalPhoneNumber(theField.value, false))
		          return this.warnInvalid (theField, this.iWorldPhone);
		       else 
		       		return true;
		    }
		},
		
		checkInternationalFax : function  (theField, emptyOK)
		
		{   if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  if (!this.isInternationalPhoneNumber(theField.value, false))
		          return this.warnInvalid (theField, this.iWorldFax);
		       else return true;
		    }
		},
		
		checkCity : function (theField, emptyOK)
		
		{   if (arguments.length == 1) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    else
		    {  if (!this.isValidCity(theField.value, false))
		          return this.warnInvalid (theField, this.iCity);
		       else return true;
		    }
		},
		
		checkMaxChar : function (theField, fieldLabel, charLimit, emptyOK) 
		
		{
			
			if (arguments.length == 3) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    
		    if(theField.value.length > charLimit)
			{
				theField.value = theField.value.substring(0,charLimit);
				return this.warnMaxChar(theField, fieldLabel);
			}
		    
		    return true ;
		},
		
		checkMinChar : function (theField, theMessage, minCharLimit, emptyOK) 
		
		{
			
			if (arguments.length == 3) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    
		    if(theField.value.length < minCharLimit)
			{
				return this.warnMinChar(theField, theMessage, minCharLimit);
			}
		    
		    return true ;
		},
		
		checkMatch : function (theField1, theField2, theMessage) 
		
		{
		    
		    if (!this.isSame(theField1.value, theField2.value))
			{
				//return this.warnMatch(theField1, field1Label, field2Label);
				this.displayError(theMessage,theField2);
				return false;
			}
		    
		    return true ;
		},
		
		checkFirstName : function  (theField, s, emptyOK)
		
		{
		    if (arguments.length == 2) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    if (this.isWhitespace(theField.value)) 
		    {
		       return this.warnEmpty (theField, s);
		    } else {
		    	
		    	
		    	var i;
				var value = theField.value ;
				
				    for (i = 0; i < value.length; i++)
				    {
				        var c = value.charAt(i);
				
				        if (!this.isLetterOrDigit(c) && c != '\'') {
							if (!this.isWhitespace(c)) {
								return this.warnInvalid(theField, this.iFirstName);
							}
						}
						
					}
				 
				    return true;
				    
			}// end-else
		    
		    
		},
		
		checkHowDid : function  (theField, s, emptyOK)
		
		{
		    if (arguments.length == 2) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    if (this.isWhitespace(theField.value)) 
		    {
		    	this.displayError("This field is required",theField);
			    return false;
		    } 
		    
		    
		},
		
		checkLastName : function  (theField, s, emptyOK)
		
		{
		    if (arguments.length == 2) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;
		    if (this.isWhitespace(theField.value)) 
		    {
		       return this.warnEmpty (theField, s);
		    } else {
		    	
		    	
		    	var i;
				var value = theField.value ;
				
				    for (i = 0; i < value.length; i++)
				    {
				        var c = value.charAt(i);
				
				       if (!this.isLetterOrDigit(c) && c != '\'') {
							if (!this.isWhitespace(c)) {
								return this.warnInvalid(theField, this.iLastName);
							}
						}
						
					}
				 
				    return true;
				    
			}// end-else
		    
		    
		},
		checkUserName : function  (theField, s, emptyOK)
		
		{
			
		    if (arguments.length == 2) emptyOK = this.defaultEmptyOK;
		    if ((emptyOK == true) && (this.isEmpty(theField.value))) return true;

		    if (this.isWhitespace(theField.value)) 
		    {
		       return this.warnEmpty (theField, s);
		    } else {
		    	
		    	var i;
				var value = theField.value ;
				
				    for (i = 0; i < value.length; i++)
				    {

				        var c = value.charAt(i);
				
				        if (!this.isLetterOrDigit(c) && c != '_' && c != '-') {
							return this.warnInvalid(theField, this.iUserName);
						}
						
					}
				 
				    return true;
				    
			}// end-else
		},
		
		checkInvalidListSelection :function(theField, s){
			
			var theSelectedIndex = theField.selectedIndex ;	 
			var theValue = theField.options[theSelectedIndex].value;
			
			if (theValue == "-1") {
					 this.warnSelection(theField,s) ;
					 return false;
			}
		},
		
		checkInvalidInterestListSelection :function(theField, s){
			
			var theSelectedIndex = theField.selectedIndex ;	 
			var theValue = theField.options[theSelectedIndex].value;
			
			if (theValue == "-1") {
					return this.warnInterestSelection(theField,s) ;
			}
		},

		confirmPass : function (pass, confPass) 
		
		{
		    //if (pass.value.length > 5)
			//{
			return this.checkMatch(pass, confPass, '"The "Password" and "Confirm Password" do not match.  Please verify that they are the same.');
			//}
		    
		   
		},

		confirmEmail : function (email, confemail) 
		{
			return this.checkMatch(email,confemail,'"The "Email Address" and "Confirm Email Address" do not match.  Please verify that they are the same.');

		}

}
