function checkContact() 
{
email_to=trimSpaces(document.forms[0].emailto.value);
uname=trimSpaces(document.forms[0].uname.value);
email=trimSpaces(document.forms[0].email.value);
address=trimSpaces(document.forms[0].address.value);
phone=trimSpaces(document.forms[0].phone.value);
  	if(!checkEmail(email_to)) {
			document.forms[0].emailto.focus();
			return false;
	 }
  if(uname.length<=0)
  { 
	 alert("You have to enter your name.");
		document.forms[0].uname.focus();
		return false;
  }

  if(address.length<=0)
  { 
	 alert("You have to enter your address.");
		document.forms[0].address.focus();
		return false;
  }
  if(phone.length<=0)
  { 
	 alert("You have to enter your phone number.");
		document.forms[0].phone.focus();
		return false;
  }
  
		if(!checkEmail(email)) {
			document.forms[0].email.focus();
			return false;
	 }
  
	return true;
}
function checkEmail(emailString) {
	splitVal = emailString.split('@');
	if(splitVal.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) {
		alert("Please enter a valid email address");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////
// Removes the leading and trailing spaces in a strings and returns the trimmed string
/////////////////////////////////////////////////////////////////////////////////////////
function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}


//Javascript Function for FeedBack
function validateContact()
{
	
	if (document.forms[0].fname.value=="")
	{
		alert("Please enter name");  				
		document.forms[0].fname.focus();
		return false;
	}
	
	if (document.forms[0].email.value=="")
	{
		alert("Please enter email address");
		document.forms[0].email.focus();
		return false;
	}
	
	splitVal = document.forms[0].email.value.split('@');
	if(splitVal.length <= 1) 
	{
		alert("Please enter a valid email address");
		document.forms[0].email.focus();
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0)
	{
		alert("Please enter a valid email address");
		document.forms[0].email.focus();
		return false;
	}
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1)
	{
		alert("Please enter a valid email address");
		document.forms[0].email.focus();
		return false;
	}
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1)
	{
		alert("Please enter a valid email address");
		document.forms[0].email.focus();
		return false;
	}
	
	
	if (document.forms[0].interest.value=="")
	{
		alert("Please enter your interest");  				
		document.forms[0].interest.focus();
		return false;
	}
	document.contactus.submit();
	return true;
	
}
