//Function to trim the string
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function validEmailAddress(email)
{
		invalidChars = " /:,;~"
		if (email == "") 
		{
			return (false);
		}
		for (i=0; i<invalidChars.length; i++) 
		{
			badChar = invalidChars.charAt(i)
			if (email.indexOf(badChar,0) != -1) 
			{
				return (false);
			}
		}
		atPos = email.indexOf("@",1)
		if (atPos == -1) 
		{
			return (false);
		}
		if (email.indexOf("@",atPos+1) != -1) 
		{
			return (false);
		}
		periodPos = email.indexOf(".",atPos)
		if (periodPos == -1) 
		{
			return (false);
		}
		if (periodPos+3 > email.length)	
		{
			return (false);
		}
			
		return (true);
}

//function to check validation of th form objects
function validate_form(objfrm)
{
	msg="Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	if(trim(objfrm.name.value)=='' || trim(objfrm.name.value)=='Name :')	msg+='- Please enter Name. \n';
	if(trim(objfrm.email.value)=='' || trim(objfrm.email.value)=='Email :')	msg+='- Please enter Email address. \n';		
	if(trim(objfrm.phone.value)=='' || trim(objfrm.phone.value)=='Phone No :')	msg+='- Please enter Phone No. \n';
	if(trim(objfrm.info.value)=='' ||trim(objfrm.info.value)=='Project Description :' )	msg+='- Please enter your Project Description. \n';	
		
	
	else if(!validEmailAddress(trim(objfrm.email.value)))
	{
		msg +=  "- Please enter valid email address.\n";		
	}	

	if(msg!="Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n")
	{
		alert(msg);
		return false;
	}
	else
	{
		objfrm.method = "POST";
		objfrm.action="hrequest_quote.php";
		objfrm.submit();
		
		return true;
	}
	
}
function clearName()
{
	if(trim(document.mail.name.value) == 'Name :')
	{
		document.mail.name.value = '';
	}
}
function setName()
{
	if(trim(document.mail.name.value) == '')
	{
		document.mail.name.value = 'Name :';
	}
}
function clearEmail()
{
	if(trim(document.mail.email.value) == 'Email :')
	{
		document.mail.email.value = '';
	}
}
function setEmail()
{
	if(trim(document.mail.email.value) == '')
	{
		document.mail.email.value = 'Email :';
	}
}
function clearPhone()
{
	if(trim(document.mail.phone.value) == 'Phone No :')
	{
		document.mail.phone.value = '';
	}
}
function setPhone()
{
	if(trim(document.mail.phone.value) == '')
	{
		document.mail.phone.value = "Phone No :";
	}
}
function clearpdesc()
{
	if(trim(document.mail.info.value) == 'Project Description :')
	{
		document.mail.info.value = '';
	}
}
function setpdesc()
{
	if(trim(document.mail.info.value) == '')
	{
		document.mail.info.value = "Project Description :";
	}
}

