String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function checkEmail(inEmailAddress) {
    inEmailAddress = inEmailAddress.trim();
      // Find positions of email address characters 
      var AtSym    = inEmailAddress.indexOf('@'); 
      var Period   = inEmailAddress.lastIndexOf('.'); 
      var Space    = inEmailAddress.indexOf(' '); 
      var Length   = inEmailAddress.length - 1   
            
      if ((AtSym < 1) ||           // '@' cannot be in first position 
          (Period <= AtSym+1) ||   // Must be atleast one valid char btwn '@' and '.' 
          (Period == Length ) ||   // Must be atleast one valid char after '.' 
          (Space  != -1))          // No empty spaces permitted 
         {
         return false;
         } 
         
      return true;  
    
    }  
	
	
function checkAddForm()
{
	valid = true;

		if (!checkEmail(document.forms['addListingForm'].email.value))
			{
			valid=false;
			alert("Please enter a valid email address")
			}
		if (valid && document.forms['addListingForm'].company.value.length ==0)
			{
			valid=false;
			alert("Please enter your Company Name")
			}
		if (valid && document.forms['addListingForm'].phone.value.length ==0)
			{
			valid=false;
			alert("Please enter your Phone number")
			}
	return valid;	
}		

function checkEmailForm()
{
	valid = true;

		if (!checkEmail(document.getElementById('email').value))
			{
			valid=false;
			alert("Please enter a valid email address")
			}
		if (valid && document.getElementById('name').value.length ==0)
			{
			valid=false;
			alert("Please enter your Name")
			}
		if (valid && document.getElementById('message').value.length ==0)
			{
			valid=false;
			alert("Please enter your Message")
			}
	return valid;	
}		
