// JavaScript Document

function trimString (str){
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function check_phonenumber(phoneBox){
	var phoneVal = trimString(phoneBox.value.toString()); 
	phoneBox.value=trimString(phoneBox.value.toString());
	
	var valid;
	valid=true;
	var mstr=phoneVal.toString();
	var count=0;
	for (var i = 0;i < mstr.length;i++){
		var oc = mstr.charAt(i);
		if ((oc < "0" ||oc > "9")){
			count++;
		}
		
	}
	
	if(mstr.length>0){
		var oc = mstr.charAt(0);
		if ((oc < "0" ||oc > "9")&& oc!="+"){
			valid=false;
		}
	}
	for (var i = 1;i < mstr.length;i++){
		var oc = mstr.charAt(i);
		if ((oc < "0" ||oc > "9")&& oc!=" "&& oc!=","&& oc!="-"&& oc!="+"){
			valid=false;
		}
		
	}
	if (valid == false){		
		return(false);
	}
	return(true);
}


function valid(){
	if(trimString(document.frm_contact.contact_name.value)==""){
		alert("Please enter name");
		document.frm_contact.contact_name.focus();
		return false;
	}
	if(trimString (document.frm_contact.contact_email.value)==""){
		alert("Please enter email address");
		document.frm_contact.contact_email.focus();
		return false;
	}else if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.frm_contact.contact_email.value)) == false){
		alert("Please enter valid email address");
		document.frm_contact.contact_email.focus();
		return false;
	}
	if(trimString(document.frm_contact.contact_phone.value)==""){
		alert("Please enter phone no.");
		document.frm_contact.contact_phone.focus();
		return false;
	}else if(check_phonenumber(document.frm_contact.contact_phone)==false){
			alert("Please enter valid phone no.");
			document.frm_contact.contact_phone.focus();
			return(false);		
	}
	if(trimString(document.frm_contact.contact_fax.value)==""){
		/*alert("Please enter fax no.");
		document.frm_contact.contact_fax.focus();
		return false;*/
	}else if(check_phonenumber(document.frm_contact.contact_fax)==false){
			alert("Please enter valid fax no.");
			document.frm_contact.contact_fax.focus();
			return(false);		
	}
	
	return true;
}
function submitForm(){
	if(valid()==true){
		document.getElementById("msg_t").style.display="none";
		document.getElementById("process").style.display="";
		document.frm_contact.submit();
	}
}
function valid_signup(){
	if(trimString(document.getElementById("name").value)==""){
		alert("Please enter name");
		document.getElementById("name").focus();
		return false;
	}
	if(trimString(document.getElementById("phone").value)==""){
		alert("Please enter phone no.");
		document.getElementById("phone").focus();
		return false;
	}else if(check_phonenumber(document.getElementById("phone"))==false){
			alert("Please enter valid phone no.");
			document.getElementById("phone").focus();
			return(false);		
	}
	if(trimString (document.getElementById("email").value)==""){
		alert("Please enter email address");
		document.getElementById("email").focus();
		return false;
	}else if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById("email").value)) == false){
		alert("Please enter valid email address");
		document.getElementById("email").focus();
		return false;
	}
	return true;
}
function submitForm_signup(){
	if(valid_signup()==true){
		document.getElementById("process_signup").style.display = "";
		document.frm_signup.submit();
	}
} 