//companyDataV.js
function checkCompLoc(compLocArr){
var ArrcompLoc= compLocArr;
var compLocValue;

var returnStr=false;
for (var i=0; i<ArrcompLoc.length; i++){
	if (ArrcompLoc[i].checked ){
		compLocValue = ArrcompLoc[i].value;
       returnStr=true;
	   break;
	}	
}

if (returnStr){
	document.getElementById("compLocValID").value = compLocValue;
   return true;
}
else 
	return false;
}

function verifyCompanyInput() { 
	var passwdPat=/^\w{4,8}$/;
	var zipcodePat =/^\d{5}$/;
	var telePat=/^\d{3}\-\d{3}\-\d{4}$/;
	var teleExtPat = /^[0-9]+$/;
	var this_field;
	
     /*Company account validation*/
	if (document.getElementById("userNameID").value =="" ||
		document.getElementById("userNameID").value ==null){
		alert("Please choose a user name.");
       document.getElementById("userNameID").focus();
		return false;
   }

	
	
	else if (document.getElementById("accFirstNameID").value =="" ||
		document.getElementById("accFirstNameID").value ==null){
		alert("Please input your First Name.");
       document.getElementById("accFirstNameID").focus();
		return false;
   }

	else if (document.getElementById("accLastNameID").value =="" ||
		document.getElementById("accLastNameID").value ==null){
		alert("Please input your Last Name.");
		document.getElementById("accLastNameID").focus();
		return false;
   }

else  if (document.getElementById("accemailID").value =="" ||
		document.getElementById("accemailID").value ==null){
		alert("Please enter your E-mail address.");
		document.getElementById("accemailID").focus();
		return false;
   }

else if (document.getElementById("accemailID").value.length != 0 &&
	   document.getElementById("accemailID").value.indexOf(' ') >= 0 ){
        alert("E-mail address cannot have spaces in it.");
        document.getElementById("accemailID").focus();
        return false;
      }

else if (document.getElementById("accemailID").value.length != 0 &&
	   document.getElementById("accemailID").value.indexOf('@') == -1){
       alert("A valid E-mail address must have an @ in it.");
        document.getElementById("accemailID").focus();
        return false;
   
}

else if (document.getElementById("accPasswrdID").value =="" ||
	 document.getElementById("accemailID").value ==null){
		alert("Please enter your Password.");
		document.getElementById("accPasswrdID").focus();
		return false;
   }

 else  if (document.getElementById("accPasswrdID").value.length  !=0 && 
	 !passwdPat.test(document.getElementById("accPasswrdID").value ) ){
	 alert("Incorrect password format. \nValid Characters: a-z A-Z 0-9, length: 4-8.");
		document.getElementById("accPasswrdID").focus();
		return false;
			
   }

 else  if (document.getElementById("reTpasswrdID").value =="" ||
	 document.getElementById("reTpasswrdID").value ==null){
		alert("Please re-type your Password");
		document.getElementById("reTpasswrdID").focus();
		return false;
   }

else if (document.getElementById("accPasswrdID").value !=	document.getElementById("reTpasswrdID").value ){
		alert(" The input password does not match with re-typed password.");
      document.getElementById("accPasswrdID").value  ="";
      document.getElementById("reTpasswrdID").value ="";
		return false;
   }

/*Company Information validation*/
else if (document.getElementById("companyNameID").value =="" ||
		document.getElementById("companyNameID").value ==null){
		alert("Please input your Company Name.");
		document.getElementById("companyNameID").focus();
		return false;
   }

/*
else if (document.getElementById("companyAddressID").value =="" ||
		document.getElementById("companyAddressID").value ==null){
		alert("Please input your Company Address.");
		document.getElementById("companyAddressID").focus();
		return false;
   }

else  if (document.getElementById("companyCityID").value =="" ||
		document.getElementById("companyCityID").value ==null){
		alert("Please input the City name of your company.");
		document.getElementById("companyCityID").focus();
		return false;
   }

  else  if (document.getElementById("companyStateID").value =="" ||
		document.getElementById("companyStateID").value ==null){
		alert("Please input the State name of your company.");
		document.getElementById("companyStateID").focus();
		return false;
   }

else  if (document.getElementById("companyZipcodeID").value =="" ||
		document.getElementById("companyZipcodeID").value ==null){
		alert("Please input the Zip Code of your company.");
		document.getElementById("companyZipcodeID").focus();
		return false;
   }

else  if (!checkCompLoc(document.getElementsByName("compLocType") )){
		alert("Please choose the Location Type of your company.");
		return false;
}


else if (document.getElementById("companyZipcodeID").value.length  !=0&&
	       !zipcodePat.test(document.getElementById("companyZipcodeID").value )){
		   alert("Incorrect zip code format. \nValid format: a five-digit number.");
		  document.getElementById("companyZipcodeID").focus();
		  return false;
}

else  if (document.getElementById("companyPhoneID").value =="" ||
		document.getElementById("companyPhoneID").value ==null ||
	 document.getElementById("companyPhoneID").value =="000-000-0000"	){
		alert("Please input a company contact phone number.");
		document.getElementById("companyPhoneID").focus();
		return false;
   }

else   if (document.getElementById("companyPhoneID").value.length  !=0&& 
            document.getElementById("companyPhoneID").value !="000-000-0000"&&
	       !telePat.test(document.getElementById("companyPhoneID").value ))  {
		alert("Please use this format to input the Tel. No.: 123-123-1234.");
		document.getElementById("companyPhoneID").focus();
		return false;
}

else if (document.getElementById("companyExtensionID").value.length !=0&&
	    !teleExtPat.test(document.getElementById("companyExtensionID").value ))  {
		alert("Please use valid digit numbers (0-9) for the tele. No. extension.");
		document.getElementById("companyExtensionID").focus();
		return false;
	 
}

else  if (document.getElementById("companyFaxID").value =="" ||
		document.getElementById("companyFaxID").value ==null ||
		document.getElementById("companyFaxID").value =="000-000-0000"	){
		alert("Please input a company contact FAX number.");
		document.getElementById("companyFaxID").focus();
		return false;
   }

else if (document.getElementById("companyFaxID").value.length  !=0 && 
            document.getElementById("companyFaxID").value !="000-000-0000"	&& 
	        !telePat.test(document.getElementById("companyFaxID").value )){
	    	alert("Please use this format to input the FAX No.: 123-123-1234.");
		   document.getElementById("companyFaxID").focus();
		  return false;
}
else  if (document.getElementById("companyEmailID").value =="" ||
		document.getElementById("companyEmailID").value ==null){
		alert("Please input a company contact E-mail address.");
		document.getElementById("companyEmailID").focus();
		return false;
   }

else   if (document.getElementById("companyEmailID").value.length  !=0 && 
	        document.getElementById("companyEmailID").value.indexOf(' ') >= 0)  {
		    alert("E-mail address cannot have spaces in it.");
		   document.getElementById("companyEmailID").focus();
		   return false;
}

else  if (document.getElementById("companyEmailID").value.length  !=0 &&
     	         document.getElementById("companyEmailID").value.indexOf('@') == -1)  {
		alert("A valid E-mail address must have an @ in it");
		document.getElementById("companyEmailID").focus();
		return false;
	  
   }

/*if (document.getElementById("companyWebAddressID").value  !="" ||
		document.getElementById("companyWebAddressID").value !=null){
	   if (  !telePat.test(document.getElementById("companyWebAddressID").value ))  {
		alert("Please use this format to input the FAX No.: 123-123-1234");
		document.getElementById("companyWebAddressID").focus();
		return false;
	   }

else if (document.getElementById("marketingStID").value=="" ||
		document.getElementById("marketingStID").value ==null )  {
		alert("Please input your company's Marketing Statement");
		document.getElementById("marketingStID").focus();
		return false;
	  
   }

else if (!CountWords () )
{alert("You have reached the maximum number of words(200) that you can send!\nPlease re-arrange your statement.");
return false;
}
*/
else	  
	 return true;
} // end of verifyCompanyInput


function CountWords () {
   var char_count = document.getElementById('marketingStID').value.length;
      var fullStr = document.getElementById('marketingStID').value + " ";
     var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
     var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
    var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
    var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
    var splitString = cleanedStr.split(" ");
      var word_count = splitString.length -1;

      if (fullStr.length <2) {
            word_count = 0;
      }
      if (word_count == 1) {
            wordOrWords = " word";
      } else {
            wordOrWords = " words";
      }

      var retstring = word_count + " " + wordOrWords
      document.getElementById('wrdcnt').innerHTML=retstring;

      if (word_count>200) {
            if(document.layers){ document.layers["q"].bgColor = '#ff0000'; }
            else { document.getElementById('wrdcnt').style.backgroundColor = '#ff0000'; 
			return false;
			
	}
      } else {
            if(document.layers){ document.layers["q"].bgColor = '#ffffff'; }
            else { document.getElementById('wrdcnt').style.backgroundColor = '#ffffff'; 
			return true;}
      }
}
