/* $Id: registration1.js 4537 2010-04-14 21:09:00Z 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="";

var checkFreeTrial = false;
var personXmlBuffer = "";
var uniqueIdent = "";
var enteredEmail = "";
var enteredPassword = "";
var communityID = "";

$("#anotherPassword").keypress(function (e) {
	alert("keypress");
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
    	verifyEmail();
   	 return false;
    }  
    return true;  
});

function verifyEmailCallerFunction(){
//	e=window.event;
	alert(event);
	 if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {  
	    	verifyEmail();
	   	 return false;
	    }  
	    return true;  
}
function matchConfirmEmail(textBox) {
	var theForm = document.getElementById("registration_form");
	if (icuesnasregistration.Validator.checkMatch(theForm['email_input'],textBox,icuesnasregistration.Validator.emailconfirmation) == false) return false;
	
}
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, "") == ""){
			icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emptyfirstname,textBox);
			return false;
		}
}
function checkRequired(textBox) {
	if (icuesnasregistration.Validator.checkRequired(textBox) == false) return false ;
}
function checkPhone(textBox) {
	
		if (icuesnasregistration.Validator.checkString(textBox,"Phone Number")== false ? false : true ) {
			
			return icuesnasregistration.Validator.checkPhoneFormatRules(textBox) ==false ? false : true ;
		}
	
	return true;
}
function checkPhoneFormatOnly(textBox) {
	if (icuesnasregistration.Validator.checkPhoneFormatRules(textBox,true) == false) return false ;
}
function checkSchool(textBox) {
	if (icuesnasregistration.Validator.checkString(textBox,"Institution Name") == false) return false ;
}
function checkAddress1(textBox) {
	if (icuesnasregistration.Validator.checkString(textBox,"Address ") == false) return false ;
}
function checkCity(textBox) {
	if (icuesnasregistration.Validator.checkString(textBox,"City") == false) return false ;
}
function checkZip(textBox) {
	if ($("#country").val() == 'US') {
		if (icuesnasregistration.Validator.checkString(textBox,"Zip/Postal Code") == false) {
			return false ;
		} else	if (icuesnasregistration.Validator.checkZIPCode(textBox)== false) {
			return false ;
		}
	}
	return true;
}
function checkState( textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"State")== false) return false;
}
function checkStateName(textBox) {
	if (icuesnasregistration.Validator.checkString(textBox,"State/Province") == false) return false ;
}
function checkCountry( textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Country")== false)  {
		return false;
	} else {
		$("#country").trigger('change');
	}
	return true;
}
function checkHowDidHear(textBox){
	if (icuesnasregistration.Validator.checkInvalidListSelection(textBox,"Source")== false) { 
		return false;
	} else 	if ($("#howhear").val() != "-1" && $("#howhear").val() != "Friend/Family") {
		$('#howhear_specify_div').show();
	}
	return true;
}
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 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, "") == ""){
			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 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.replace(/^\s+|\s+$/g, "") == ""){

				icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emptyemail,emailField);
				
				return false;
				
			}
			if (icuesnasregistration.Validator.checkEmail(emailField, false) == false) return ;
			var snasUrl = "/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;
	                    $(xml).find('site').each(function(){
	                         var siteName = $(this).text();
	                         sites += siteName + ", "; 
	                         if(siteName == "aod.icue.nbcuni.com"){
	                         	isinnbcarchive = true;
	                         }
	                    });
	                    
	                    if(isinnbcarchive) {
	                    	
	                    	$formtype = $('#formtype').val();
	                    	
	                    	if ($formtype == 'register') {
	                    	   	checkFreeTrial = true; 
	                    	   	var result ='<p>Your email address is already used on this NBC site: Archives on Demand K-12. Please enter your existing password to login:</p><p><br><input type="password" id="anotherPassword" class="small_input" onkeypress="if (event.keyCode == 13) verifyEmail();" /></p>';
	                    	   	registration_popup("Verify NBC Password",result,'popup_small');
	                    	} else {
	                    		checkFreeTrial = false;
	                    		icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emailexistonsite,emailField);
	                    	}
	                    } else if(sites.length > 1) {
	                    	
	                    	sites = sites.substring(0, sites.length - 1);
	                    	
	                    	displaysites= sites;
	                    	displaysites=displaysites.replace("aod.icue.nbcuni.com", "Archives on Demand K-12");
	                    	displaysites=displaysites.replace("higheredsa.icue.nbcuni.com", "Archives on Demand HE");
	                    	
	                    	var result ='<p>Your email address is already used on this NBC site: ' + displaysites + '. Please enter your existing password to automatically link your account to Archives on Demand K-12.</p><p><br><input type="password" id="anotherPassword" class="small_input" onkeypress="if (event.keyCode == 13) verifyEmail();" /></p>';
	                    	registration_popup("Verify NBC Password",result,'popup_small');
	                    }
	                    
			    	}
			    }
			});
		} 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 = "/nbcarchive/snas/api/authenticatePersonWithEmail?email=" + email + 
						  "&password=" + password + "&siteName=" + sitesArray[0];
		authenticatePass(snasURL, password) ;
	
	
}
function checkMyCommunity(uniqueIdentifier, email, password, personXml) {
		personXmlBuffer = $(parseXML(personXml));
		uniqueIdent = uniqueIdentifier;
		enteredEmail = email;
		enteredPassword = password;
		try{
			var snasURL = "/nbcarchive/snas/api/listMyCommunity?siteName=aod.icue.nbcuni.com&siteDomainName=aod.icue.nbcuni.com&memberPersonUUID=" + uniqueIdentifier;
			$.ajax({
			    url: snasURL,
			    type: 'GET',
			    dataType: 'text/xml',
			    timeout: 25000,
			    error: function(){
			        alert('AjaX Error!');
			    },
			    success: function(xml){
			    	if (xml.indexOf("<listMyCommunity") > -1) {
			    		/*community present, user already is part of the community in AOD, stop the flow here by alerting the user. */ 
			    		var community = $(parseXML(xml)).find("listMyCommunity > community:first");
			    	     communityID = community.attr("ID");
			    		var communityName = community.find("name").text();
			    		var $communitynamereg = $('#communitynamereg').val();
			    		/*check if the community that the user is trying to get in is the same that he has registered with */
			    		if ($communitynamereg == communityName) {
			    			icuesnasregistration.Validator.displayError(icuesnasregistration.Validator.emailexistonsite,document.getElementById("email_input"));
			    		}else {
			    			$('.dialog_popup').dialog("close");
			    			var result = 'Are you sure you want to leave '+communityName+' and join '+$communitynamereg+'?' ;
			    			confirmCommunityChange_popup("Switch Institution?",result,'popup_small');
			    		}
			    	} else if (xml.indexOf("<error>") > -1) {
			    		/*no community present, this must be a free trial user, trying to register as a regular user, allow the user to proceed.*/
			    		$('#subformtype').val('freetrialconversion');
			    		populateFormAndDisable();
			    		removeErrorMsg();
			    		$('.dialog_popup').dialog("close");
			    		continueFreeTrialConversion_popup("Thank You","Your existing password was successfully entered and we were able to retrieve your account information.  Please proceed to submit the form to complete the registration process.",'popup_small');
			    	}
			    }
			});
		} catch(ex) {
			alert("Ex:"+ex);
		}
}
function proceedWithNewCommunity() {
		$("#communityID").val(communityID);
		$('#subformtype').val('changecommunity');
		populateFormAndDisable();
		removeErrorMsg();
}
function populateFormAndDisable() {
		$('#uniqueIdentifier').val(uniqueIdentifier);
		$('#confirm_email_input').val(enteredEmail);
		document.getElementById("registration_form")["password_input"].value = enteredPassword;
		$('#confirm_password_input').val(enteredPassword);
		$('#verifiedEmail').val(enteredEmail);
    	$('#password_input').value = enteredPassword;

    	$('#displayName').val(getAttributeFromXML("userName"));
    	$('#firstname').val(getAttributeFromXML("firstName"));
    	$('#lastname').val(getAttributeFromXML("lastName"));
    	var myroletemp = getAttributeFromXML("myrole");
    	try {
    		$("#my_role option:contains("+myroletemp+")").attr("selected", true);
    	} catch (e) {
    		$("#my_role option:last").attr("selected", true);
    		myroletemp="";
    	}
    	
    	if (myroletemp == 'Student' || myroletemp == 'student') {
	    	$('#age_check').show();
	    	
	    	var agetemp = getAttributeFromXML("age13orover");
	    	$("input[id='age']").val(agetemp);
	    	if (agetemp == 'Y' || agetemp == 'y') {
	    		
	    		$("input[id='age']")[0].checked = true;
	    		
	    	}else{
	    		$("input[id='age']")[1].checked = true;
	    	
	    	}
	    	$('#age_check').find(':radio').each(function() {
	    		/* transfer values to hidden field and disable radio button */
	    		$('#age13orover_dis').val($('#age_check').find(':radio:checked').val());
	    		$(this).attr("disabled", true); 
	
	    	});
    	} else {
    		$('#age_check').hide();
    	}
    	var newsletterOptinState = getAttributeFromXML("newsletterOptin");
    	var newesletteroptin = $('#sign_me_div').find(':checkbox:first');
    	newesletteroptin.attr('checked', (newsletterOptinState = 'Yes' || newsletterOptinState == 'yes')?true:false);
    	
    	
    	disableLogin();
    	/* transfer values to hidden fields and disable fields */
    	$('#newsletteroptin_dis').val(newsletterOptinState);
    	newesletteroptin.attr("disabled", true);
    	
    	$('#firstname_dis').val($('#firstname').val());
    	
    	$('#lastname_dis').val($('#lastname').val());
    	
    	$('#my_role_dis').val($('#my_role').val());
    	$('#firstname,#lastname,#my_role').attr("disabled", true);
    	
    	uniqueIdent = "";
    	enteredPassword = "";
    	enteredEmail = "";
    	
}
function getAttributeFromXML(attributeName) {
		var $att = personXmlBuffer.find(attributeName);
		if ($att.size() > 0 ) {
			return $att.filter(":first").text();
		}
		return "";
}
function parseXML( xml ) {
		if( window.ActiveXObject && window.GetObject ) {
			var dom = new ActiveXObject( 'Microsoft.XMLDOM' );
			dom.loadXML( xml );
			return dom;
		}
		if( window.DOMParser )
		return new DOMParser().parseFromString( xml, 'text/xml' );
		throw new Error( 'No XML parser available' );
}
function authenticatePass(snasURL, password) {
		
		try{
			$.ajax({
			    url: snasURL,
			    type: 'GET',
			    dataType: 'text/xml',
			    timeout: 25000,
			    error: function(){
			        alert('AjaX Error!');
			       
			    },
			    success: function(xml){
			    	personXmlBuffer = $(parseXML(xml));
				    if(xml.indexOf("<uniqueIdentifier>") > -1)
				    {
				    	$('.dialog_popup').dialog("close");
				    	uniqueIdentifier = xml.substring(xml.indexOf("<uniqueIdentifier>") + 18, xml.indexOf("</uniqueIdentifier>"));
				    	
				    	if (checkFreeTrial) {
				    		/*as the user already belongs to AOD site, we need to check 
				    		 * whether he is a existing free trial user trying to
				    		 * convert or does it already have a community to this site */
				    		checkMyCommunity(uniqueIdentifier, email, password, xml);
				    	} else {
					    	document.getElementById("uniqueIdentifier").value = uniqueIdentifier;
							document.getElementById('confirm_email_input').value = email;
							document.getElementById("registration_form")["password_input"].value = password;
							enteredPassword=password;
							document.getElementById("password_input").value = password;
							document.getElementById("confirm_password_input").value = password;
					    	document.getElementById('verifiedEmail').value = email;
					    	enteredEmail = email;
					    	populateFormAndDisable();
					    	removeErrorMsg();
					    	//disableLogin();
					    	$('.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 disableLogin() {
		/* transfer values to hidden fields and disable fields */ 
		$('#email_dis').val($('#email_input').val());
		
		$('#password_dis').val($('#password_input').val());
		
		$('#confirmemail_dis').val($('#confirm_email_input').val());
		
		$('#confirmpassword_dis').val($('#confirm_password_input').val());
		
		$('#email_input,#password_input,#confirm_email_input,#confirm_password_input').attr("disabled", true); 
}
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 ={} ;
var icuesnasregistration ={} ;

registration.Validator = {
	
	validate_registrationForm : function() 
	{
	    var formsubmit=true;
		var theForm = document.getElementById("registration_form");
		/* core validator */
		var $CVal = icuesnasregistration.Validator ;
//		alert($('#formtype').val());
		
		/* REGISTRATION FORM */
		if ($('#formtype').val() =="register"){
			try {
			theForm['email_input'].value = $CVal.trimString(theForm['email_input'].value); 
			if ($CVal.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			if ($CVal.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;
			if ($CVal.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			if ($CVal.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;
			if ($CVal.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
			if ($CVal.checkMatch(theForm['email_input'], theForm['confirm_email_input'], $CVal.emailconfirmation) == false) formsubmit= false;
			if ($CVal.checkString(theForm['password_input'], "Password", false) == false) formsubmit= false ;
			if ($CVal.checkMinChar(theForm['password_input'], $CVal.passwordlength, 6, true) == false) formsubmit= false ;
			if ($CVal.checkMaxChar(theForm['password_input'], "Password", 32, true) == false) formsubmit= false ;
			if ($CVal.checkString(theForm['confirm_password_input'], "Confirm Password", true) == false) formsubmit= false ;
			if ($CVal.checkMatch(theForm['password_input'], theForm['confirm_password_input'], $CVal.passwordconfirmation) == false) formsubmit= false ;
			if ($CVal.checkString(theForm['communitynamereg'],"Institution Name") == false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			var $role = $("#my_role").val();  
			if ( $role=='Student'|| $role=='student'){
				if ($CVal.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			}
			if (!theForm['tos'].checked)
			{
				$CVal.displayError($CVal.iagreetos,theForm['tos']);
				formsubmit= false ;
			}
			
			if ($CVal.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
			
			
			} catch (e) {
				alert(e);
			}
//			alert(formsubmit);
			return formsubmit;
			
		}
		/* FREE TRIAL FORM */
		if ($('#formtype').val() =="freetrial"){
			/* Validate Login Info */
			theForm['email_input'].value = $CVal.trimString(theForm['email_input'].value); 
			if ($CVal.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			if ($CVal.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;
			if ($CVal.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
			if ($CVal.checkMatch(theForm['email_input'], theForm['confirm_email_input'], $CVal.emailconfirmation) == false) formsubmit= false;
			if ($CVal.checkString(theForm['password_input'], "Password", false) == false) formsubmit= false ;
			if ($CVal.checkMinChar(theForm['password_input'], $CVal.passwordlength, 6, true) == false) formsubmit= false ;
			if ($CVal.checkMaxChar(theForm['password_input'], "Password", 32, true) == false) formsubmit= false ;
			if ($CVal.checkString(theForm['confirm_password_input'], "Confirm Password", true) == false) formsubmit= false ;
			if ($CVal.checkMatch(theForm['password_input'], theForm['confirm_password_input'], $CVal.passwordconfirmation) == false) formsubmit= false ;

			/* Validate My Info */
			if ($CVal.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			var $role = $("#my_role").val();  
			if ( $role=='Student'|| $role=='student'){
			if ($CVal.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			}
			if ($CVal.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			if ($CVal.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;
			if ($CVal.checkString(theForm['phone1'],"Phone Number") == false) formsubmit= false ;		
			if ($CVal.checkPhoneFormatRules(theForm['phone1'])==false)formsubmit= false ;
			if ($CVal.checkPhoneFormatRules(theForm['phone2'],true)==false)formsubmit= false ;
			
			/* Validate My Institution Info */
			if ($CVal.checkString(theForm['communityname'],"Institution Name") == false) formsubmit= false ;
			if ($CVal.checkString(theForm['address1'],"Address ") == false) formsubmit= false ;
			if ($CVal.checkString(theForm['city'],"City ") == false) formsubmit= false ;
			
			if ($CVal.checkInvalidListSelection(theForm['country'],"Country")== false) {
				formsubmit= false ;
			} else {
				$('#countryName').val($('#country option:selected').text()); 
				if ($("#country").val() == 'US') {
					$('#state_div').show();
					$('#statename').val('');
					$('#state_name_div').hide();
					if ($CVal.checkInvalidListSelection(theForm['state'],"State")== false) formsubmit= false ;
					
					if ($CVal.checkString(theForm['zip'],"Zip/Postal Code ") == false) formsubmit= false ;
					
					if (!$CVal.isEmpty(theForm['zip'].value)) {
						if ($CVal.checkZIPCode(theForm['zip'])== false) formsubmit= false ;
					}
				} else {
					$("#state option[value='-1']").attr('selected', 'selected');
					$('#state_div').hide();
					$('#state_name_div').show();
					if ($CVal.checkString(theForm['statename'], "State/Province") == false) formsubmit= false ;
				}
			}
			
			if ($CVal.checkInvalidListSelection(theForm['howhear'], "Source") == false) formsubmit= false ;
			
			if (!theForm['tos'].checked)
			{
				$CVal.displayError($CVal.iagreetos,theForm['tos']);
				formsubmit= false ;
			}
			/* Validate Security Info */
			if ($CVal.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
			return formsubmit;
		}
		/* CONTACT SALES FORM */
		if ($('#formtype').val() =="contactsales"){
			theForm['email_input'].value = $CVal.trimString(theForm['email_input'].value); 
			if ($CVal.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if ($CVal.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if ($CVal.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if ($CVal.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			if ($CVal.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
		
			if ($CVal.checkMatch(theForm['email_input'], theForm['confirm_email_input'], $CVal.emailconfirmation) == false) formsubmit= false;

			if ($CVal.checkGeneralPhoneRules(theForm['phone1'])==false)formsubmit= false ;
			if ($CVal.checkString(theForm['address1'],"Address ") == false) formsubmit= false ;
			if ($CVal.checkString(theForm['communityname'],"School/Business Name") == false) formsubmit= false ;
			if ($CVal.checkRequired(theForm['howhear']) == false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['country'],"Country")== false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			if ($CVal.checkString(theForm['city'],"City ") == false) formsubmit= false ;
			if ($CVal.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
			return formsubmit;
		}
		/* CONTACT US FORM */
		if ($('#formtype').val() =="contactus"){
			theForm['email_input'].value = $CVal.trimString(theForm['email_input'].value); 
			if ($CVal.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if ($CVal.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if ($CVal.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if ($CVal.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			if ($CVal.checkString(theForm['confirm_email_input'], "Confirm Email Address") == false) formsubmit= false ;
		
			if ($CVal.checkMatch(theForm['email_input'], theForm['confirm_email_input'], $CVal.emailconfirmation) == false) formsubmit= false;

			if ($CVal.checkGeneralPhoneRules(theForm['phone1'])==false)formsubmit= false ;
			if ($CVal.checkRequired(theForm['comments']) == false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['reason'],"Reason")== false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			return formsubmit;
		}

		return formsubmit;
	},
	
	validate_contactUsForm : function() 
	{
		var formsubmit=true;
		/* core validator */
		var $CVal = icuesnasregistration.Validator ;
		var theForm = document.getElementById("contactusform");
		//if (theForm['formtype'].value=="contactus"){
			theForm['email_input'].value = icuesnasregistration.Validator.trimString(theForm['email_input'].value); 
			if ($CVal.checkFirstName(theForm['firstname'], "First Name") == false) formsubmit=false ;	
			
			if ($CVal.checkLastName(theForm['lastname'], "Last Name") == false) formsubmit= false ;

			if ($CVal.checkString(theForm['email_input'], "Email Address") == false) formsubmit= false ;
			
			if ($CVal.checkEmail(theForm['email_input'], false) == false) formsubmit= false ;

			if ($CVal.checkPhoneFormatRules(theForm['phone1'])==false)formsubmit= false ;
			if ($CVal.checkPhoneFormatRules(theForm['phone2'],true)==false)formsubmit= false ;
			if ($CVal.checkRequired(theForm['writeusanote']) == false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['reason'],"Reason")== false) formsubmit= false ;
			if ($CVal.checkInvalidListSelection(theForm['my_role'],"Role")== false) formsubmit= false ;
			option = $("#my_role").val();  
			if ( option=='Student'|| option=='student'){
			if ($CVal.checkAge(theForm['age'], "Age") == false) formsubmit= false ;
			}
			if ($CVal.checkString(theForm['recaptcha_response_field'], "Captcha Text") == false) formsubmit= false ;
			
		return formsubmit;
	}
}; /* End registration.Validator */

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 K-12! 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 ",
		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 ********************************
		/* All Warn functions must return false */
		warnEmpty : function  (theField, s)
		
		{   
		    this.displayError(this.mPrefix + s + this.mSuffix,theField);
		    return false;
		},
		
		warnInvalid : function  (theField, s)
		
		{   
		    this.displayError(s,theField);
		    return false;
		},
		
		warnSelection : function  (theField, s)
		
		{   
			
			this.displayError(this.pSelectPrompt + s,theField) ;
			return false;
			
		},
		
		warnMaxChar : function (theField, s) 
		
		{
			this.displayError(this.maxCharPrefix + s + this.maxCharSuffix,theField);
			return false;
			
		},
		
		warnMatch : function (field1, label1, label2) 
		
		{
			this.displayError("Values of fields " + label1 + " and " + label2 + " should match.");
			return false;
			
		},
		
		warnMinChar : function (theField, theMessage, minCharLength) 
		
		{
			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))
			{
				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
		    
		    
		},
		
		checkRequired : function  (theField, emptyOK)
		
		{
		    if (arguments.length == 1) 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") {
					return this.warnSelection(theField,s) ;
			}
		},

		confirmPass : function (pass, confPass) 
		
		{
			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.');

		}

}; /* End icuesnasregistration.Validator */
