var divobj

function formSubmit()
{
	var str;
	if(divobj=='divQuery')
	{
		str = "?e="+document.frmQuery.txt_email.value;
		str = str + "&t="+document.frmQuery.sel_querytype.value;
		str = str + "&q="+document.frmQuery.txt_query.value;
	}
	else
	{
		str = "?e="+document.frmQueryContact.txt_email_contact.value;
		str = str + "&t="+document.frmQueryContact.sel_querytype_contact.value;
		str = str + "&q="+document.frmQueryContact.txt_query_contact.value;
	}
	submitQuery(str);
}

function validateForm(div_obj)
{
	divobj = div_obj
	if(divobj=='divQuery')
	{
		if(document.frmQuery.txt_email.value=='' || 
		   document.frmQuery.sel_querytype.value == '' || 
		   document.frmQuery.txt_query.value == '')
		{
			alert("The following error occured:"+
				  "\r\n-----------------------------------------"+
				  "\r\nEither 'Your Email' or 'Query' field is empty"+
				  "\r\n-----------------------------------------"+
				  "\r\n\r\nPlease rectify the error and try again");
			document.frmQuery.txt_email.focus();
			return false;
		}
		else
		{
			formSubmit();
		}
	}
	else
	{
		if(document.frmQueryContact.txt_email_contact.value=='' || 
		   document.frmQueryContact.sel_querytype_contact.value == '' || 
		   document.frmQueryContact.txt_query_contact.value == '')
		{
			alert("The following error occured:"+
				  "\r\n-----------------------------------------"+
				  "\r\nEither 'Your Email' or 'Query' field is empty"+
				  "\r\n-----------------------------------------"+
				  "\r\n\r\nPlease rectify the error and try again");
			document.frmQueryContact.txt_email_contact.focus();
			return false;
		}
		else
		{
			formSubmit();
		}
	}
}


var xmlHttp

function submitQuery(str)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	var url="submitquery.php";
	url=url+str;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		if (xmlHttp.responseText=='Success')
		{ 
			document.getElementById(divobj).innerHTML="<font color='blue'>Your query has been submitted successfully. We'll get back to you as soon as possible.</font><br /><br />";
			document.getElementById('txt_email').value = '';
			document.getElementById('txt_query').value = '';
		}
		else if (xmlHttp.responseText=='Email Error')
		{ 
			document.getElementById(divobj).innerHTML="<font color='red'>Sorry, It seems there is a problem with email you provided. <br />Please check it out and try again.</font><br /><br />";
		}
		else
		{
			document.getElementById(divobj).innerHTML="<font color='red'>Due to some technical problems, we could not log your query. Please check back soon.</font><br /><br />";
		}
	}
}

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;
}