// JavaScript Document
function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}
function echeck(str) {

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(str.match(emailExp)){
		return true;
	}else{
		return false;
	}
}
function check_phone(str)
{
	var flag=0
	var i
		
	for(i=0;i<str.length;i++)
	{
		if(str.charAt(i)=="1" || str.charAt(i)=="2" || str.charAt(i)=="3" || str.charAt(i)=="4" || str.charAt(i)=="5" || str.charAt(i)=="6" || str.charAt(i)=="7" || str.charAt(i)=="8" || str.charAt(i)=="9" || str.charAt(i)=="0" || str.charAt(i)=="+" || str.charAt(i)=="-" || str.charAt(i)=="." || str.charAt(i)==" " || str.charAt(i)=="(" || str.charAt(i)==")")
		{
		}
		else
			flag=1;
	}
	if(flag==1)
		return false;
	else	
		return true;
}

function echeck(str) {

	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(str.match(emailExp)){
		return true;
	}else{
		return false;
	}
}
function check_phone(str)
{
	var flag=0
	var i
		
	for(i=0;i<str.length;i++)
	{
		if(str.charAt(i)=="1" || str.charAt(i)=="2" || str.charAt(i)=="3" || str.charAt(i)=="4" || str.charAt(i)=="5" || str.charAt(i)=="6" || str.charAt(i)=="7" || str.charAt(i)=="8" || str.charAt(i)=="9" || str.charAt(i)=="0" || str.charAt(i)=="+" || str.charAt(i)=="-" || str.charAt(i)=="." || str.charAt(i)==" " || str.charAt(i)=="(" || str.charAt(i)==")")
		{
		}
		else
			flag=1;
	}
	if(flag==1)
		return false;
	else	
		return true;
}

function Validate_Request_Form(){
	var name=trim(document.form1.name.value);
	var phone=trim(document.form1.phone.value);
	var email=trim(document.form1.email.value);
	var description=trim(document.form1.description.value);
	/*	if (name=="Enter Your Name" && phone=="Phone" && email=="Email" && description == "")
	{
	return false;	
	}
	*/
	var id=document.form1.id.value;
	var focusto="";
	var validationstr="";
	if(name == ""||name=="Enter Your Name"){
		validationstr+="Name Field is Required\n";
		document.getElementById('star1').style.display = 'inline';
		if(!focusto){focusto="name"};
	
	}
	if(phone == ""||phone=="Phone"){
		if(!focusto){focusto="phone"};
	}
	else if(check_phone(phone) == false){
		validationstr+="Phone Appears To Incorrect\n";
		if(!focusto){focusto="phone"};	
	}
	if(email == ""||email=="Email"){
		validationstr+="Email Field is Required\n";
		document.getElementById('star3').style.display = 'inline';
		if(!focusto){focusto="email"};
	}
	else if(echeck(email) == false){
		validationstr+="Email Appears To Incorrect\n";
		document.getElementById('star3').style.display = 'inline';
		if(!focusto){focusto="email"};	
	}

	if(description == ""||description=="Description"){
		validationstr+="Description Field is Required\n";
		document.getElementById('star4').style.display = 'inline';
		if(!focusto){focusto="description"};
	}

	if(validationstr != ""){
		alert(validationstr);
		document.getElementById(focusto).focus();
		return false;
	}else{
		return true;	
	}
}
