
function emailVal(string){
valid = false
for (n=3;n<string.length;n++){
 	if(string.charAt(n)=="@" && n < (string.length - 5) ){
		for(nn=string.length-5;nn<string.length-2;nn++){
		if(string.charAt(nn)=="."){
		valid = true
		}		
		}	
	}		
}
return valid
}
function phoneVal(string){
	string = string.split(" ");
	string = string.join("");
	string = string.split("-");
	string = string.join("");
	p_phone_digits = 0
	re  = false
	for (n=0;n< string.length;n++){
			if (!isNaN(string.charAt(n))){
			p_phone_digits++
					if(p_phone_digits>7){
						re = true
						break;
					}
			} else {
			 p_phone_digits = 0	
			}
	}
	return re;
}


function reseter(){
document.form01.reset();
document.form01.p_name.value = "";
document.form01.p_email.value = "";
document.form01.p_phone.value = "";
document.form1.p_message.value = "";
};
function validateForm(){
	if (document.form01.p_name.value.length < 2){
	alert("Enter a valid name into \"from\" field")
	window.form01.p_name.focus()
	}else{
	
		if (form01.p_email.value.length > 3 || form01.p_phone.value.length > 2 ){
		//chacking email validation
			if (form01.p_email.value == ""  || form01.p_email.value.length > 3 && emailVal(form01.p_email.value) ){
				valid01 = true
				
			}else{
			valid01 = false
			
			}
		/*phone validation*/
			if(phoneVal(form01.p_phone.value) || form01.p_phone.value == "" ){
			valid02 = true;
			}else{
			valid02 = false;
			}
			
				
						
				var	MSG01= "*The E-Mail address you have entered is not valid .\r\n";
		var	MSG02 = "* The Phone Number You Have Entered Is Not Valid .\r\n";
					
			if (!valid01 || !valid02  ){
			
				tex = "The Following Error Has Occurred: \r\n";
				if(!valid01){tex=tex+ MSG01;}
				if(!valid02){tex=tex+ MSG02;}
				alert(tex)
			}else
			document.form01.submit()
			
			
		}else{
		alert("* You must enter either a valid phone number or e-mail address ")
		
		}
	}
	
}