
/*************************************************************/
function keyContact(event)
{

if(event.keyCode == 13)
	{
		return checkContact();
	}
}

function checkContact()
{

flag = false;

	if(document.getElementById("cemail").value=="")
	{
		alert("Please Enter Email.");
		document.getElementById("cemail").focus();
	}
	else if(!emailcheck(document.getElementById("cemail").value))
	{
		alert('Please Enter Valid Email.');
		document.getElementById('cemail').focus();
	}
	else
	{
		flag=true;
		sendContact();
	}
return flag;	
}


/*
*	Function take input value on submit of request a quote module
*/

function sendContact()
{

/*
*	Creating XMLHttp object 
*/
	
		xmlHttp=GetXmlHttpObject()
		 
/*
*	If XMLHttp protocol is null then browser is not supporting HTTP request
*/
		if (xmlHttp==null)
		  {
			  alert ("Browser does not support HTTP Request")
			  return
		  } 
		   
/*
*	Defining url and giving string value fetched on keypress then sending it to 
*	default.php file for further processing
*/
		
	
		var cemail = document.getElementById("cemail").value
	
		var url="DA/getContact.php?cemail="+cemail;
	
	
/*
*	If any reponse found then take it then process it to statechaged function
*/
		xmlHttp.onreadystatechange=stateChangedContact 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)

}
	
/*
*	Function that passes reponse to html file
*	If state is 4 or complete then it sends response to suggesion div 
*/
function stateChangedContact() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {

	document.getElementById('cemail').value = '';
	window.location.href="index.php?mode=msg";		
	

 } 
}

/*************************************************************/


function keyRequest(event)
{

	if(event.keyCode == 13)
	{
		return checkRequest();
	}
}


function checkRequest()
{
	
flag = false;
	
	
	if(document.getElementById('fname').value == '')
	{
		alert('Please Enter Name.');
		document.getElementById('fname').focus();	
	
	}
	else if(document.getElementById("email").value=="")
	{
		alert("Please Enter Email.");
		document.getElementById("email").focus();
	}
	else if(!emailcheck(document.getElementById("email").value))
	{
		alert('Please Enter Valid Email.');
		document.getElementById('email').focus();
	}
	else if(document.getElementById('phone').value == '')
	{
		alert('Please Enter Phone No.');
		document.getElementById('phone').focus();
	}
	else if(!onlyNumeric(document.getElementById('phone').value))
	{
		alert('Please Enter Numeric Phone No.');
		document.getElementById('phone').focus();
	}
	else if(document.getElementById('require').value == '')
	{
		alert('Please Enter Requirements.');
		document.getElementById('require').focus();
	}
	else
	{
		flag=true;
		sendMail();
	}
return flag;	
}

/*
*	Function take input value on submit of request a quote module
*/

function sendMail()
{


/*
*	Creating XMLHttp object 
*/
		 xmlHttp=GetXmlHttpObject()
		 
/*
*	If XMLHttp protocol is null then browser is not supporting HTTP request
*/
		if (xmlHttp==null)
		  {
		  alert ("Browser does not support HTTP Request")
		  return
		  } 
		   
/*
*	Defining url and giving string value fetched on keypress then sending it to 
*	default.php file for further processing
*/

		var name = document.getElementById('fname').value;
		var email = document.getElementById('email').value;
		var phone = document.getElementById('phone').value;
		var requirements = document.getElementById('require').value;
		
		var url="DA/getRequest.php?&fname="+name+"&email="+email+"&phone="+phone+"&require="+requirements;


/*
*	If any reponse found then take it then process it to statechaged function
*/
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)

} 
	
/*
*	Function that passes reponse to html file
*	If state is 4 or complete then it sends response to suggesion div 
*/
function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
	document.getElementById('fname').value = 'Name';
	document.getElementById('email').value = 'Email';
	document.getElementById('phone').value = 'Phone';
	document.getElementById('require').value = 'Requirements';
	window.location.href="index.php?mode=msg";
	
	
 } 
}

/*************************************************************/

/*
*	Function for email validation
*/

function emailcheck(str)
{
	emailF = false;
if(str!="")
	{
		var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		var ans = str.match(emailExp);
		if(ans == str)
		{
			emailF = true;
		}
	}	
return emailF;
}


/*
*	Function numeric validation
*/

function onlyNumeric(str)
{
	NumericF = false;
	
	if(str!="")
	{
		
		var numExp = /^[0-9]{1,}$/;
		var ans = str.match(numExp);
		if(ans == str)
		{
			 NumericF = true;	
		}
	}
	else
	{
		NumericF = true;	
	}
	
return NumericF;
}

/*
*	Javascript for sending mail and inserting value in table
*/

var xmlHttp

/*
*	Function that identifies XMLHttp object and passes value based on browser
*/

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;
} 


//xmlHttp.responseText
/*************************************************************/


