/* Trial Form Vaidation */

/*-----------------------------------------------------------------------------------------*/
function IsNumeric(sText){
   	var ValidChars = "0123456789.";
   	var IsNumber=true;
   	var Char;
		
   	for (i = 0; i < sText.length && IsNumber == true; i++){ 
      	Char = sText.charAt(i); 
      	if (ValidChars.indexOf(Char) == -1){
         	IsNumber = false;
         	}
      	}
      	
   	return IsNumber;
}

/*-----------------------------------------------------------------------------------------*/
function chkZipLen() {
	var theZip = document.getElementById("zipCode");
	if (theZip.value.length==0 || theZip.value.length!=5) {
		window.status = "Zip Code cannot be empty and must be a valid 5 digit zip code.";
		return false;
	} else if(!IsNumeric(theZip.value)){
		window.status = "Zip Code must not contain letters";
		return false;
	} else {
		return true;
	}
}

/*-----------------------------------------------------------------------------------------*/
function chkOrganizationType() {
	if (document.getElementById("strOrganizationType").selectedIndex !=0){
		return true;
	}else {
		window.status = "You must select an Organization Type";
		return false;
	}
}

/*-----------------------------------------------------------------------------------------*/
function chkState() {
	if (document.forms["form"].elements["state"].options[document.forms["form"].elements["state"].selectedIndex].text.substr(0,3) == "Can")
		document.forms["form"].elements["country"].value = "Canada";
	else if (document.forms["form"].elements["state"].selectedIndex !=1)
		document.forms["form"].elements["country"].selectedIndex = 0;
	return chkLen("state","State/Province") &&
		(document.forms["form"].elements["state"].value != "--" || chkLen("state1","State/Province"));
}

/*-----------------------------------------------------------------------------------------*/
function chkEmail() {
	
	//Regular expression for typical email format
	var objRegExp  = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
	theEmail = document.getElementById("email");
		
	if ( !chkLen("email","Email") || !chkLen("confirmemail","Confirm Email") ){
			return false;
	}else{
		if(document.getElementById("email").value.search(/@/) != -1 && document.getElementById("email").value.search(/./) != -1){ //objRegExp.test(theEmail)
			if (document.getElementById("email").value == document.getElementById("confirmemail").value){
				return true;
			}else{
				window.status = "Email is different from Confirm Email";
				return false;
			}
		}else{
			window.status = "Email is not formatted correctly";
			return false;
		}
	}
}

/*-----------------------------------------------------------------------------------------*/
var i,objElement;
function chkLen(s,s2) {
	//objElement = document.forms["form"].elements[s];
	objElement = document.getElementById(s);
	if (objElement.value=="" ) {
		window.status = s2 + " cannot be empty.";
		return 0;
	} else {
		window.status = "" ;
		return -1;
	}
}
/*-----------------------------------------------------------------------------------------*/
function chkZipLen(s,s2) {
	var objElement = document.forms["form"].elements[s];
	if (objElement.value.length==0 || objElement.value.length!=5) {
		window.status = s2 + " cannot be empty and must be a valid 5 digit zip code.";
		return 0;
	} else if(!IsNumeric(objElement.value)){
		window.status = s2 + " must not contain letters";
		return 0;
	} else {
		return -1;
	}
}

/*-----------------------------------------------------------------------------------------*/
function chkData() {
	if (
			//(chkLen("strActivationCode","Activation Password"))			&&
			(chkLen("firstName","First Name"))			&&
			(chkLen("lastName","Last Name"))			&&
			(chkLen("firmName","Firm Name"))		 	&&
			//(chkLen("infoNeed","Pressing Info Need"))	&&
			(chkLen("jobTitle","Job Title"))			&&
			(chkLen("address","Address"))				&&
			(chkLen("city","City"))						&&
			(chkState())								&&
			(chkZipLen("zip","Zip Code"))				&&
			(chkLen("country","Country"))				&&
			(chkLen("phone","Business Phone"))			&&
			(chkEmail())		
		)
	{
		document.forms["form"].elements["btnSubmit"].disabled = false;
		window.status = "";
	} else {
		document.forms["form"].elements["btnSubmit"].disabled = true;
	}
}


