var flag;
var chk_map;
var counter=0;
function sendRequest(url,params,HttpMethod) {
 if(!HttpMethod) { HttpMethod="GET"; }
 req=null;
 if(window.XMLHttpRequest){req=new XMLHttpRequest; }
 else if(window.ActiveXObject){req=new ActiveXObject("Microsoft.XMLHTTP");} 
  if(req) {req.onreadystatechange=onReadyState;req.open(HttpMethod,url,true);req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  req.send(params);}} 
 

    
  function onReadyState() { var ready=req.readyState;var data=null;if(ready==4){
  data=req.responseText;
  
  if(flag==2){
	  var SelectBox = document.getElementById("result");
   	
    // clear out existing options
    while (SelectBox.options.length) 
    {
        SelectBox.options[0] = null;
    }
 
        test1(data);
 
 
 
    }
  
if(flag==3){
	//alert(data);
/*var pointDiv = document.getElementById('load');
   pointDiv.style.visibility = 'hidden';
   pointDiv.style.display = 'none';
*/    
    var SelectBox = document.getElementById("pttt");
   	
    // clear out existing options
    while (SelectBox.options.length) 
    {
        SelectBox.options[0] = null;
    }
 
        test(data);
 
 
 
    }
 
if(flag==4){
	var pointDiv = document.getElementById('load');
   pointDiv.style.visibility = 'hidden';
   pointDiv.style.display = 'none';
    var El = document.getElementById('urll');
    
    El.innerHTML=data;
 alert(El.innerHTML);
    }
 
  }
   
   }

  function trim(stringToTrim) {
 return stringToTrim.replace(/^\s+|\s+$/g,"");
 }  
function removeSpaces(string) {
 var tstring = "";
 string = '' + string;
 splitstring = string.split(" ");
 for(i = 0; i < splitstring.length; i++)
 tstring += splitstring[i];
 return tstring;
}
 
function getdata(){
 
 flag=2;
 var sss=0;
 var vik=new Date();
 sendRequest('election1.jsp?flag='+flag+'&vik='+vik);
 
}
 
function getpt(){
 

 
var stt=document.elec.statename.value;
//alert(stt);
 
 flag=3;
 var vik=new Date();
 sendRequest('parlcons1.jsp?flag='+flag+'&vik='+vik+'&state='+stt);
 
}
 
function geturl(){
 
var pointDiv = document.getElementById('load');
   pointDiv.style.visibility = 'visible';
   pointDiv.style.display = 'block';

var stt=document.elec.statename.value;
//alert(stt);
var pp=document.elec.parl_cons.value;
 
 flag=4;
 var vik=new Date();
 sendRequest('urlfind1.jsp?flag='+flag+'&vik='+vik+'&state='+stt+'&parl='+pp);
 
}
 
function go(){
 

//var goo=document.elec.url.value;
//alert(goo);
 
document.elec.action ='track-your-constituencies.jsp';
document.elec.submit();
 
}
function test(str)
{
//alert(str);
str=removeSpaces(str);
//document.form1.subcat.options="hi";

var brokenstring=str.split("@"); 
var count=brokenstring.length;
//alert(count);
var i;
for(i=0;i<count-1;i++)
	{
//alert(brokenstring[i]);
	var SelectBox = document.getElementById('pttt');
	 SelectBox.options[0] = new Option("------ Select------");
     SelectBox.options[SelectBox.options.length] = new Option(brokenstring[i], brokenstring[i]);
	
	}
SelectBox.selectedIndex=0;
}
function test1(str)
{
//alert(str);
//document.form1.subcat.options="hi";

var brokenstring=str.split("@"); 
var count=brokenstring.length;
//alert(count);
var i;
for(i=0;i<count;i++)
	{
//alert(brokenstring[i]);
	var SelectBox = document.getElementById('result');
	 SelectBox.options[0] = new Option("-- Select --");
     SelectBox.options[SelectBox.options.length] = new Option(brokenstring[i], brokenstring[i]);
	
	}
SelectBox.selectedIndex=0;
}
