/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
special_chars = new Array("~","`","!","@","#","$","%","^","&","*","(",")","-","_","+","=","[","{","]","}","\\","|","\"",">","<",";",":",".",",","/","'");

   function checkForSpecialChars(str, isEmail){

	   for(spc=0; spc<special_chars.length; spc++){
			if(str.indexOf(special_chars[spc]) != -1){

				if(isEmail && special_chars[spc] == "@" || special_chars[spc] == "." || special_chars[spc] == "_"){
					// do nothing.  allow for these special chars in email address
				} else {
				return false;
				}
			}
	   }
		return true;
   }

  function disagree(){
		alert("You cannot download AIi software if you do not agree to the license.");
		//elm = document.getElementById("downloadsLayer");
	    //elm.style.visibility = "hidden";
		ACCEPT_STATE = "no";
		elm = document.getElementById("acceptState").value = ACCEPT_STATE;
		document.forms[0].submit();
  }

  function agree(){

     //elm = document.getElementById("downloadsLayer");
	// elm.style.visibility = "visible";
	ACCEPT_STATE = "yes";
	elm = document.getElementById("acceptState").value = ACCEPT_STATE;
	if(getAcceptState(document.forms[0])){
	   document.forms[0].submit();
	}

  }

  function getAcceptState(theForm){
	  elm = document.getElementById("acceptState");
	  emailEle = document.getElementById("email");
      var formIsValidated = true;
	//  alert("form length: "+theForm.elements.length);

      for(i=0; i<theForm.elements.length; i++){
		 // alert("validating: "+theForm.elements[i].name+" with value: "+theForm.elements[i].value);
		if(theForm.elements[i].type == "text" && theForm.elements[i].value == "" ){
			alert("The Field: "+theForm.elements[i].name+" is required");
			break;
			formIsValidated = false;
		}

        if(theForm.elements[i].name == "firstName" || theForm.elements[i].name == "lastName"){
           if(!checkForSpecialChars(theForm.elements[i].value, false)){
				alert("Special Characters are not allowed in this field.");
				theForm.elements[i].value = "";
			    theForm.elements[i].focus();
			    return false;
		   }
		}

		if(theForm.elements[i].name == "email"){
           if(!checkForSpecialChars(theForm.elements[i].value, true)){
				alert("Special Characters are not allowed in this field.");
				theForm.elements[i].value = "";
			    theForm.elements[i].focus();
			    return false;
		   }
		}


		 if(theForm.elements[i].name == "firstName" && theForm.elements[i].value.indexOf(" ") != -1){
            alert("The Field: "+theForm.elements[i].name+" is required, and may not contain empty spaces.");
			formIsValidated = false;
			theForm.elements[i].value = "";
			theForm.elements[i].focus();
			return false;
		}

		if(theForm.elements[i].name == "lastName" && theForm.elements[i].value.indexOf(" ") != -1){
            alert("The Field: "+theForm.elements[i].name+" is required, and may not contain empty spaces.");
			formIsValidated = false;
			theForm.elements[i].value = "";
			theForm.elements[i].focus();
			return false;
		}

		if(theForm.elements[i].name == "email" && theForm.elements[i].value.indexOf(" ")!= -1){
            alert("The Field: "+theForm.elements[i].name+" is required, and may not contain empty spaces.");
			formIsValidated = false;
			theForm.elements[i].value = "";
			theForm.elements[i].focus();
			return false;
		}
	  }

	 formIsValidated = validateEmail(emailEle);
	  if(elm.value == "yes" && formIsValidated){
		  return true;
	  } else {
		 // alert("validation failed!");
		  return false;
	  }

  }// end fnc

  function validateEmail(emailEle){
	  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|cc|us|tv|ru|ca|li|jp)$/;

	  var emailPat=/^(.+)@(.+)$/;

	emailStr = emailEle.value;

	return true;

  }

