/* 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 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  chkRadioButtons()
     {var radios = document.getElementsByTagName('input');
    var value;
    for (var i = 0; i < radios.length; i++) {
        if (radios[i].type === 'radio' && radios[i].checked) {
            // return true if any of our radio buttons is checked
            return true;
        }
    }

    // if we made it this far, none of our radio buttons are checked
    return false;
}

/*-----------------------------------------------------------------------------------------*/
function chkData() {
	if (
			//(chkLen("strActivationCode","Activation Password"))			&&
			//(chkLen("trial","Must select a trial -"))			&&
			(chkLen("firstName","First Name"))			&&
			(chkLen("lastName","Last Name"))			&&
			(chkLen("firmName","Firm Name"))		 	&&
			(chkZipLen("zip","Zip Code"))				&&
			(chkLen("phone","Business Phone"))			&&
			(chkEmail())		                        &&
            (chkRadioButtons())
		)
	{
		document.forms["form"].elements["btnSubmit"].disabled = false;
		window.status = "";
	} else {
		document.forms["form"].elements["btnSubmit"].disabled = true;

	}
}




