function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function check_phone(Phone){
	var checkstr = "0123456789 ()[]{}<>-";
	var PhoneValue = Phone;
	var i;

   for (i = 0; i < PhoneValue.length; i++) {
	  if (!(checkstr.indexOf(PhoneValue.substr(i,1)) >= 0)) 
	  {
		  return false;
	  }
   }
   if (PhoneValue.length < 10) {
		return false;
	}
   return true;
}

function ProcessForm()
{

    if (document.forms['contact'].elements['title'].value == "")
    {
		alert ("Please enter your title in the \"Title\" field.");
		document.forms['contact'].elements['title'].focus();  
		return;

    }
	
	if (document.forms['contact'].elements['firstname'].value == "")
    {
		alert ("Please enter your firstname in the \"Firstname\" field.");
		document.forms['contact'].elements['firstname'].focus();  
		return;

    }
	
	if (document.forms['contact'].elements['lastname'].value == "")
    {
		alert ("Please enter your lastname in the \"Lastname\" field.");
		document.forms['contact'].elements['lastname'].focus();  
		return;

    }
	
	if (document.forms['contact'].elements['phone'].value == "")
	{
			alert ("Please enter a phone number in the \"Phone\" field.");
			document.forms['contact'].elements['phone'].focus();  
			return;
	}
		if (!check_phone(document.forms['contact'].elements['phone'].value))
		{
			alert ("Please enter a valid phone number in the \"Phone\" field.");
			document.forms['contact'].elements['phone'].focus();  
			return;
		}		
	
		if (document.forms['contact'].elements['email'].value == "")
	{
		alert ("Please enter an email address in the \"email\" field.");
		document.forms['contact'].elements['email'].focus();  
		return;
	}

	if (!check_email(trim(document.forms['contact'].elements['email'].value)))
	{
		alert("Please enter a complete email address in the \"email\" field: yourname@yourdomain.com");
		document.forms['contact'].elements['email'].focus();  
		return;
	}

	if (document.forms['contact'].elements['email'].value.length < 5)
	{
		alert("Please enter at least 3 characters in the \"email\" field.");
		document.forms['contact'].elements['email'].focus();  
		return;
	}
	
	if (document.forms['contact'].elements['comments'].value == "")
    {
		alert ("Please enter your comments in the \"Comments\" field.");
		document.forms['contact'].elements['comments'].focus();  
		return;

    }
		
  	document.forms['contact'].submit();
}


function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two))
		{
			return (-1);		
		} 
	}

}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
