function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}
function getHttp()
{
	return window.location.href;
}
function SendMail(name,contact,email,servies,host) 
{
	if(name.replace(/^\s+|\s+$/g, '')==''|| name == "Name(Required)") 
	{
		alert('Enter Name.');
	}	
	else if(contact.replace(/^\s+|\s+$/g, '')=='' || contact == "Day Phone(Required)") 
	{
		alert('Enter contact number.');
	}
	
	else if (echeck(email)==false){	
		return false
	}
	
	else 
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		} 
		var url= "http://www.sandiego-plumbers.com/ajaxcontact.php?name=" + name + "&contact=" + contact + "&email=" + email + "&servies=" + servies + "&host=" + host;
		xmlHttp.onreadystatechange= function () 
		{
			if(xmlHttp.readyState==4)
			{ 
				//alert(xmlHttp.responseText);
				if(xmlHttp.responseText=='ok') 
				{
					alert('Request successfully sent. We will get back to you soon.');
					flagPopout=1;
					popout();
	
				} 
				else 
				{
					alert('Error in sending mail. Please try again.');
				}
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		return false;
	}
	return false;
}



function checkvalidation(frm)
{
	
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		realname=document.getElementById('realname').value;
		Email=document.getElementById('semail').value;
		City=document.getElementById('City').value;
		Zip=document.getElementById('Zip').value;
		Phone=document.getElementById('Phone').value;
		
		var url= "http://www.sandiego-plumbers.com/formvalidate/contactvalidate.php?name=" + realname + "&email=" + Email + "&city=" + City + "&zip=" + Zip + "&phone=" + Phone;
		xmlHttp.onreadystatechange= function () 
		{
			if(xmlHttp.readyState==4)
			{ 
				
				if(xmlHttp.responseText=='') 
				{
					frm.submit();
	
				} 
				else 
				{
					document.getElementById('allerror').innerHTML = xmlHttp.responseText;
					return false;
				}
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		return false;
}


function employement_validation(frm)
{
	
	xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
		position=document.getElementById('em_position').value;
		Phone=document.getElementById('em_phone').value;
		Email=document.getElementById('em_email').value;
		firstname=document.getElementById('em_firstname').value;
		lastname=document.getElementById('em_lastname').value;
		Zip=document.getElementById('em_zip').value;
		
		
		var url= "http://www.sandiego-plumbers.com/formvalidate/employement_validate.php?firstname=" + firstname + "&lastname=" + lastname +"&email=" + Email + "&zip=" + Zip + "&phone=" + Phone +"&position=" + position;
		
		xmlHttp.onreadystatechange= function () 
		{
			if(xmlHttp.readyState==4)
			{ 
				
				if(xmlHttp.responseText=='') 
				{
					frm.submit();
	
				} 
				else 
				{
					document.getElementById('allerror').innerHTML = xmlHttp.responseText;
					return false;
				}
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		return false;
}






function echeck(str) {
	if(str=='Email Address')
	return true;
	else
	{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
	  }
	}
