// JavaScript Document
function cPhone(e) {
		var strCheck = '0123456789-+ ()[]/\b';
		//var strCheck = '0123456789'; 
		var whichCode = (window.Event) ? e.which : e.keyCode;
		key = String.fromCharCode(whichCode);  // Get key value from key code
		if (whichCode == 0) return true ;
		if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	}
	
   	
function isEmail(Email) {
		var result = true ;
		var Regex = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/ ;
		return Regex.test(Email) ;
	}
	
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function



function check_form()
				{
				 var FN = eval("document.frm");
				   
				   var AlertMsg = "" ;
				   var IsValid = true ;
				
				   if (document.frm.firstname.value == "") {
					AlertMsg += "- Please enter your First Name!\n" ;
					IsValid=false;
				   }  



if (document.frm.address.value == "") {
					AlertMsg += "- Please enter your Address!\n" ;
					IsValid=false;
				   }  

if (document.frm.city.value == "") {
					AlertMsg += "- Please enter your City!\n" ;
					IsValid=false;
				   } 

if (document.frm.phone.value == "") {
					AlertMsg += "- Please enter your Phone number!\n" ;
					IsValid=false;
				   } 
	   
			if (!IsValid) {
						alert(AlertMsg) ;
		 			} else {
						document.frm.submit() ;
					}// JavaScript Document
}
	
function check_formask()
				{
				 var FN = eval("document.frm");
				   var xEmail= FN.email.value;
				   var AlertMsg = "" ;
				   var IsValid = true ;
				
				   if (document.frm.firstname.value == "") {
					AlertMsg += "- Please enter your First Name!\n" ;
					IsValid=false;
				   }  



if (document.frm.address.value == "") {
					AlertMsg += "- Please enter your Address!\n" ;
					IsValid=false;
				   }  

if (document.frm.city.value == "") {
					AlertMsg += "- Please enter your City!\n" ;
					IsValid=false;
				   } 
				   


var radioobj = document.forms['frm'].elements['contact'];

if (getCheckedValue(radioobj)==""){
	AlertMsg +="- Please select Preferred Method Of Contact \n";
	IsValid=false;
}

if (getCheckedValue(radioobj)=="Phone"){
	if (document.frm.phone.value == "") {
					AlertMsg += "- Please enter your Phone number!\n" ;
					IsValid=false;
				   } 

}

if (getCheckedValue(radioobj)=="Email"){
	if (document.frm.email.value == "") {
		AlertMsg += "- Please enter your Email address!\n" ;
		IsValid=false;
	} else {
		if (isEmail(document.frm.email.value) == false) {
			IsValid = false ;
			AlertMsg += "- Fill in with the correct Email format\n" ;
		}
}
}

/*var total=""
for(var i=0; i < document.frm.service[].length; i++){
	if(document.frm.service[i].checked)
		total +=document.frm.service[i].value + "\n"
}

if(total==""){
	AlertMsg += "- Please select Your Terminix Service!\n" ;
	IsValid=false;
}
*/



var elms=document.frm.elements;
var check=false;
for(var i=0;i<elms.length;i++)
if(elms[i].name=='service[]'){
myElement=elms[i];
if (myElement.checked==false) {
checked = false;
}else {
checked = true;
check = true;
} 

//code for myElement
}

if (check==false) {
AlertMsg += "- Please select Your Terminix Service!\n" ;
	IsValid=false;
}

if (document.frm.question.value == "") {
					AlertMsg += "- Please enter your Question or Suggestion!\n" ;
					IsValid=false;
				   } 
				   
			if (!IsValid) {
						alert(AlertMsg) ;
		 			} else {
						document.frm.submit() ;
					}// JavaScript Document
						
		 		
				}
	
