// JavaScript Document
var bool1 = false;
var bool3 = false;
var bool4 = true;
var bool5 = true;
var xmlHttp;


//function to return an xmlhttp object
function getObject()
{
var xmlHttpObject;
try
  {  xmlHttpObject = new XMLHttpRequest();  }
catch (e)
  { try {    xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
  {    try  { 	xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");      }    
	catch(e) { xmlHttpObject = null;}
	
	} 
}
return xmlHttpObject;
}


//function to validate email address
function isValidEmail(strValue)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(filter.test(strValue))
	{
		return true;
	}
	else
	{
		return false;
	}
}


//function to validate phone number
function isValidPhone(strValue)
{
	return true;
}


//function to check the form
function checkForm(intField, strValue)
{
	switch(intField)
	{
		case 1:
		if(strValue != "")
		{
			bool1 = true;
		}
		else
		{
			bool1 = false;
		}
		break;
		
		
		case 3:
		if((strValue != "") && (isValidEmail(strValue)))
		{
			bool3 = true;
		}
		else
		{
			bool3 = false;
		}
		break;
		
		
		case 4:
		if((strValue != "") && (isValidPhone(strValue)))
		{
			bool4 = true;
		}
		else
		{
			bool4 = false;
		}
		break;
		
		
		case 5:
		if(strValue != "")
		{
			bool5 = true;
		}
		else
		{
			bool5 = false;
		}
		break;
	}
	
	if((bool1) && (bool3) && (bool4) && (bool5))
	{
		document.contact.send.disabled = false;
	}
	
}

//function to send the email
function sendEmail(strName, strEmail, strTele, strComments)
{
	document.getElementById("mailstatus").innerHTML = "Sending...";
	
	xmlHttp = getObject();
	xmlHttp.onreadystatechange = stateChangedUp;
	
	var url = "mail.php?n="+strName+"&e="+strEmail+"&t="+strTele+"&c="+strComments;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
	document.contact.send.disabled = true;

}

//function to handle the xml object's state change
function stateChangedUp()
{
	if((xmlHttp.readyState == 4) && (xmlHttp.status == 200))
	{
		if(xmlHttp.responseText == "Validated")
		{
			document.getElementById("mailstatus").innerHTML = "Mail sent!";
		}
		else
		{
			document.getElementById("mailstatus").innerHTML = "Problem sending mail!";
		}
	}
}