// JavaScript Document
// JavaScript Document
var xmlHttp = createXmlHttpRequestObject();
var rptrname,pname,rptremail,rptrcname,rptros,rtypeflag=0,rtype,rptrrep;

function createXmlHttpRequestObject()
{
  var xmlHttp;
  if(window.ActiveXObject)
	{
		 try  { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		 catch (e)	 {  xmlHttp = false; }
	}
	else
	{
		try {	xmlHttp = new XMLHttpRequest();	}
		catch (e)	{	xmlHttp = false;	}
	}
	if (!xmlHttp)	alert("Error creating the XMLHttpRequest object.");
	else	return xmlHttp;
}
function chkreportentry()
{
	rtypeflag=0;
	rptrname=document.getElementById('rptrname').value;	
	rptremail=document.getElementById('rptremail').value;

	rptrcname=document.getElementById('rptrcname').value
	pname=document.getElementById('pname').value
	if(document.getElementById('rtype1').checked==false)rtype='Feature';
	else rtype='Bug';
	if((document.getElementById('rtype1').checked==false) && (document.getElementById('rtype2').checked==false))rtypeflag=1;

	rptros=document.getElementById('rptros').value
	rptrrep=document.getElementById('rptrrep').value
	if(rptrname=="")  document.getElementById('errmsg').innerHTML='Please enter your Name';
		else if(rptremail=="") document.getElementById('errmsg').innerHTML='Please enter the email id';	
	else if(! isValidEmail(rptremail))
		  document.getElementById('errmsg').innerHTML='Please check the email address';	   
	else if(rptrcname=="")  
		document.getElementById('errmsg').innerHTML='Please enter the Company/Institution name';	
    else if(rtypeflag==1)document.getElementById('errmsg').innerHTML='Please choose the type of Report';
	else if(rptros=="")  document.getElementById('errmsg').innerHTML='Please enter your Operating System';	   
	else if(rptrrep=="")  document.getElementById('errmsg').innerHTML='Please enter the Request/Report Details';	   	
		else
		{
 			 document.getElementById('errmsg').innerHTML='';
			 document.rptrform.submit();
		}
}

function isValidEmail(email)
{
	var pattern = /^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/;
	return  pattern.test(email);
}
function isValidPhone(Value)
{
	if ( Value.length == 0 )		return true;
	var pattern = /^[0-9]*$/;
	var len=Value.length-1;
	var mValue=Value.substring(1,len)
	if(Value.charAt(0) != '+')
		return pattern.test(Value);
	else
		return pattern.test(mValue);
}
function submitreport()
{	
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{	
		var rptrinfo="rptrname="+rptrname+'&rptremail='+rptremail+'&rptrcname='+rptrcname+'&rtype='+rtype+'&pname='+pname+'&rptros='+rptros+'&rptrrep='+rptrrep;		

		xmlHttp.open("GET", "reportajax.php?" + rptrinfo, true);
		xmlHttp.onreadystatechange = rptrchkout;
		xmlHttp.send(null);
	}
	else
		setTimeout('rptrchkout()',1000);
}

function rptrchkout()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			lnameexist= xmlHttp.responseXML.getElementsByTagName('userext')[0].childNodes[0].nodeValue;
			enqsubmit();
		}
		else
		{
			alert("There was a  problem accessing the server: " + xmlHttp.statusText);
		}
	}
}
