// JavaScript Document
//******Author : Sandip Chauhan ***********************

function chkValues(obj){
	if(obj.checked)
		obj.value="Yes";
	else
		obj.value="No";
}
function sendRequest()
{   	

	var form = document.getElementById('frmpoll'),errors='';
	with(form){

		if (errors){
			alert('Please fill the following details properly:\n\n'+errors);
		}else{			
			document.getElementById("replaceme").innerHTML="<img src='images/loader.gif'> Registering the details, please wait ...";
		var oForm = document.forms[0];
		var sBody = getRequestBody(oForm);
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request");
			return
		}
		xmlHttp.open("POST",oForm.action ,true);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.onreadystatechange=stateChanged; 
		xmlHttp.send(sBody);	
			
		}
	}
}



function stateChanged(){ 
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			var fil=String(xmlHttp.responseText);
			if(fil.indexOf('Error')==-1){
				var oForm = document.forms[0];
			   // clearControls(oForm);
			} 
			document.getElementById("replaceme").innerHTML=xmlHttp.responseText;
/*
			xmlHttp=GetXmlHttpObject();
			xmlHttp.open("POST",oForm.action ,true);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttp.onreadystatechange=stateChanged; 
			xmlHttp.send(sBody);  

			document.getElementById("poll_list").innerHTML="";  */
			
		} 
}

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 clearControls(frmjob){
	for (var i=0; i<frmjob.elements.length; i++){
		if(frmjob.elements[i].name=='submit' || frmjob.elements[i].name=='reset')
		{continue;}
		else{frmjob.elements[i].value="";}
	}
}

function getRequestBody(frmjob){
	var aParams = new Array();
	
	for (var i=0; i<frmjob.elements.length; i++){
		var sParam = encodeURIComponent(frmjob.elements[i].name);
		sParam += "=";
		sParam += encodeURIComponent(frmjob.elements[i].value);
		aParams.push(sParam);
	}
	return 	aParams.join("&");

}