var xmlHttp = null;
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 ajaxuser()
{
	
	var name=document.getElementById("reg_username").value ;
	if(name.length >4)
	{
		document.getElementById("validuser").style.display='inline';
		document.getElementById("name").style.display="none";
		document.getElementById("text_display").style.display="none";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="ajax.php";
		var q="getuser";
		url=url+"?method="+q+"&username="+name;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				
				if(xmlHttp.responseText!=0)			
				{
				
					document.getElementById('validuser').innerHTML=xmlHttp.responseText;	
					document.getElementById("fullname_inforeg_username").className='info_show';
				}
				else
				{		
					document.getElementById('validuser').innerHTML="<span style='color:green'>Available</span>";	
					//document.getElementById("fullname_inforeg_username").className='info_hide';
				}
			}
		}
	}
}
function ajaxmail()
{
	
	var email=document.getElementById("reg_email").value ;	
	if(email=="")
	return false;
	xmlHttp2=GetXmlHttpObject();
	if (xmlHttp2==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="getemail";
	url=url+"?method="+q+"&email="+email;	
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
	xmlHttp2.onreadystatechange=function()
	{
		if(xmlHttp2.readyState==4)
		{
			if(xmlHttp2.responseText!=0)			
			{
				
				document.getElementById('fullname_inforeg_email').innerHTML=xmlHttp2.responseText;	
				document.getElementById("fullname_inforeg_email").className='info_show';
			}
			else
			{
				document.getElementById('fullname_inforeg_email').innerHTML='Enter your email';	
				document.getElementById("fullname_inforeg_email").className='info_hide';
			}
		}
	}
	
}
function ajaxState()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="getstates";
	url=url+"?method="+q;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('reg_state').innerHTML=xmlHttp.responseText;
		}
	}
}

function ajaxDistrict(str)
{
	var id=str;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="getDistricts";
	url=url+"?method="+q+"&stateid="+id;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('reg_district').innerHTML=xmlHttp.responseText;
	
		}
	}
}

function ajaxconstituency(str,val)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="getConstituency";
	url=url+"?method="+q+"&districtid="+str+"&selval="+val;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('reg_constituency').innerHTML=xmlHttp.responseText;
		}
	}
}
function getPolls(polltype,ccid,page)//ccid -- candidate id or constituency id
{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="getPolls.php";
	url=url+"?polltype="+polltype+"&ccid="+ccid+"&page="+page;
	//alert(url);
	xmlHttp.open("GET",url,true);	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('selectedpolls').innerHTML=xmlHttp.responseText;
			if(document.getElementById("pollChart") != null)
			{
				var electionresultsX = Left(document.getElementById("pollChart"));
				var electionresultsY = Top(document.getElementById("pollChart"));
				var electionresultsW = document.getElementById("pollChart").offsetWidth;
				var electionresultsH = document.getElementById("pollChart").offsetHeight;
				//alert(electionresultsH);
				var elcetionresultsTop = document.getElementById("pollChartTop");
				elcetionresultsTop.style.top = electionresultsY + "px";
				elcetionresultsTop.style.left = electionresultsX + "px";
				elcetionresultsTop.style.width = electionresultsW + "px";
				elcetionresultsTop.style.height = electionresultsH + "px";
			}
		}
	}	
	xmlHttp.send(null);
}
function setPolls(polltype,ccid,count)//ccid -- candidate id or constituency id
{
	
	if(document.getElementById('loggedinuser').value=='no')
	{		
		document.getElementById('Loginfailed').innerHTML="<a style='color:red;cursor:pointer' href='index.php?task=userlogin'>Please login to vote</a>";
		return false;
	}
	var option=0;
	for(i=0;i< count;i++)
	{
		if(document.getElementById('check'+i).checked==true)
		{
			option=document.getElementById('check'+i).value;
		}
		
	}	
	if(option==0)
	return false;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="getPolls.php";
	url=url+"?polltype="+polltype+"&ccid="+ccid+"&polloption="+option;
	
	xmlHttp.open("GET",url,true);	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{	
			document.getElementById('selectedpolls').innerHTML=xmlHttp.responseText;
		}
	}	
	xmlHttp.send(null);
	
}
function pollDisplay(pollid)
{
	
	if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
	
		var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		if(hasRightVersion) { 
			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
				'width', '220',
				'height', '180',
				'scale', 'noscale',
				'salign', 'TL',
				'bgcolor', '#ff7733',
				'wmode', 'opaque',
				'movie', 'charts_library/charts',
				'src', 'charts_library/charts',
				'FlashVars', 'library_path=charts_library&xml_source=charts_library/question'+pollid+'.xml', 
				'id', 'my_chart',
				'name', 'my_chart',
				'menu', 'true',
				'allowFullScreen', 'true',
				'allowScriptAccess','sameDomain',
				'quality', 'high',
				'align', 'middle',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'play', 'true',
				'devicefont', 'false'
				); 
				
		} else { 
		
			var alternateContent = 'This content requires the Adobe Flash Player. '
			+ '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
			document.getElementById('pollresults').innerHTML = alternateContent;
			
		}
	}
}
function constituencychange(str)
{
	
	var id=str;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="getchangeconst";
	url=url+"?method="+q+"&constid="+id;
	url=url
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('reg_updateconst').innerHTML=xmlHttp.responseText;
			
	
		}
	}
}
function getcandidate(str)
{
	
	var id=str;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="getcandidate";
	url=url+"?method="+q+"&candidate="+id;
	url=url
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('reg_candidate').innerHTML=xmlHttp.responseText;	
		}
	}
}

function getsearchcandidates(id,Page,Can)
{
	
	if(isNaN(Page))
		Page=1;
	if(Can == 'candidate')
	{	
		searchBy="candidate";
		Page=1;
	}
	var chi=document.getElementById("default_td").getElementsByTagName("span");
	for(var i=0;i<chi.length;i++)
	{
		chi[i].className='prevdefaultcolor';
	}
	 
	document.getElementById(id).className='changedefaultcolor';
	if(document.getElementById('get_by_constituency').checked == true)
	{
			searchBy="constituency";
	}
	if(document.getElementById('get_by_candidate').checked == true)
	{
		searchBy="candidate";
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="ajax.php";
	var q="Get_Search_Candidates_Constituncy";
	url=url+"?method="+q+"&searchBy="+searchBy+"&alphabet="+id+"&page="+Page;
	url=url
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('display_search_candid_const').innerHTML=xmlHttp.responseText;	
		}
	}
	
}
