var index=0;
function validateForm()
{
errors = '';
email_one      = document.forms["commentForm"]["address1"].value;
email_two      = document.forms["commentForm"]["address2"].value;
name           = document.forms["commentForm"]["firstName"].value;
phone          = document.forms["commentForm"]["tel"].value;
is_propert     = document.forms["commentForm"]["is_propert"].value;
  
errors += required_name(name);
//errors += required_property(is_propert)
errors += validateEmails(email_one,email_two);
if(isNumber(phone)==false && phone != '')
{errors += 'Phone number is not numeric.\n';} 

errors += required_phone(phone);

if(email_one != email_two)
{errors += 'Emails dont match.\n';}
 
if(errors=='')
{event.returnValue = true;}
else
{
 alert('You have the following errors:\n\n'+errors);
 event.returnValue = false;
}
}

function validateEmails(email_one,email_two)
{
	errors2='';
 errors2 += validateEmailOne(email_one);
 errors2 += validateEmailTwo(email_two) ;
 return errors2;
}
function  validateEmailOne(x)
{
errors = '';
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
       errors += "Email address one is not valid.\n"; 
  }
  return errors;  
}

function  validateEmailTwo(x)
{
errors = '';
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
	   errors += "Email address two is not valid.\n";   
  }
  return errors;  
}

function required_name(x)
{
	errors1 = '';
if (x=="")
  {
  errors1 = "Name is empty.\n";   
  index++;
  }
   return errors1; 
}
function required_phone(x)
{
	errors = '';
if (x==null || x=="")
  {
  errors = "Phone is empty.\n";   
  }
   return errors; 
}
function required_property(x)
{
	errors = '';
if (x==null || x=="")
  {
  errors = "Please select an option in property owner.\n";   
  }
   return errors; 
}
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

