var xmlHttp;
var geo;
    var reasons=[];
	var map;
	var tooltip = document.createElement("div");
     //alert(document.getElementById("se").value);
//var html=document.getElementById("se").value;
var html;
/** autosuggest function for tags */
function lookupkey(inputString) 
{var data="";
	//alert(inputString);
	//var temp =inputString;
	var temp = document.search.search_pc.value;
	var help_state=document.getElementById("showdiv1").value;
	//var temp = document.getElementById("keywords").value;
	//alert(document.getElementById("keywords").value);
	//alert("Cat "+temp);
	if(inputString.length == 0)
	{// alert("yeppi");
		// Hide the suggestion box.
		document.getElementById('autoSuggestionsListkey').style.visibility ='hidden';
		document.getElementById('autoSuggestionsListkey').style.display = 'none';
		document.getElementById("suggestionskey").style.display = 'none';
			document.getElementById("suggestionskey").style.visibility ='visible';
	}
	else
	{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="rpc.php";
//str=str.replace("&","%26");
url=url+"?queryString="+temp+"&help_state="+help_state;
url=url+"&sid="+Math.random();
//alert(url);
xmlHttp.onreadystatechange=function()
{ //alert(xmlHttp.readyState);
if (xmlHttp.readyState==4)
{ 
	//alert(xmlHttp.responseText);
	var data=xmlHttp.responseText;
	//alert(data.length);
		if(data.length >31) {
	//alert(data.length);
	document.getElementById("suggestionskey").style.visibility ='visible';
	document.getElementById("suggestionskey").style.display = 'block';
			//$('#suggestionskey').show();
			document.getElementById("autoSuggestionsListkey").style.visibility ='visible';
			document.getElementById("autoSuggestionsListkey").innerHTML=data;
			//alert(document.getElementById("autoSuggestionsListkey").innerHTML);
			document.getElementById("autoSuggestionsListkey").style.display = 'block';
			//$('#autoSuggestionsListkey').html(data);
		}
		else if(data.length==31)
	{//alert("yes");
			//alert(data.length);
			document.getElementById('suggestionskey').style.visibility ='hidden';
document.getElementById("suggestionskey").style.display = 'none';

	}
	}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
	}
	
}// lookup

function fill(thisValue)
{//alert(thisValue);
	//var temp1 = document.getElementById("tags").value;
	var temp1 =document.search.search_pc.value;
	num = temp1.lastIndexOf(",");
	num++;
	temp1 = temp1.substr(0,num);
		
	temp1 = temp1+thisValue;
	//alert(temp1);
	document.search.search_pc.value=temp1;
	//alert(document.getElementById("keywords").value);
document.getElementById('suggestionskey').style.visibility ='hidden';
document.getElementById("suggestionskey").style.display = 'none';
}
/** function to get xmlhttp object */
function GetXmlHttpSiteObject(){
	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 showCustomer1(id2)
{ 
	//alert("ghgh");


//idchange3();
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getdata1.php";
//alert(url);
xmlHttp.onreadystatechange=function()
{ 
if (xmlHttp.readyState==4)
{ 
	//alert(document.getElementById(id2));
	var SelectBox1 = document.getElementById(id2);
   	
var string=xmlHttp.responseText;
//alert(xmlHttp.responseText);
test1(string);
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function getresult_1()
{ 
	var search_pc=document.getElementById("search_pc").value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getresult.php";
//str=str.replace("&","%26");
url=url+"?search_pc="+search_pc;
//url=url+"&sid="+Math.random();
//alert(url);
xmlHttp.onreadystatechange=function()
{ 
if (xmlHttp.readyState==4)
{ 

//alert(xmlHttp.responseText);

var string=xmlHttp.responseText;
string1=string.split("*");
document.getElementById("se").value=string1[0];
document.getElementById("state_nm").value=string1[4];
if(string1[4]=="Bihar" || string1[4]=="Orissa" || string1[4]=="Maharashtra" || string1[4]=="Punjab" || string1[4]=="Rajasthan")
	{
	var s_nm=string1[4].toLowerCase();

image_nm1=string1[0].toLowerCase();
reg =/\s+/;
     image_nm1= image_nm1.replace(reg,"-");
image_nm=s_nm+"/"+image_nm1+"-constituency-map-"+s_nm;
	}
	else if(string1[4]=="Haryana")
	{
var s_nm=string1[4].toLowerCase();

image_nm1=string1[0].toLowerCase();
reg =/\s+/;
     image_nm1= image_nm1.replace(reg,"-");
image_nm=s_nm+"/"+image_nm1+"-constituency-map";
	}
	else if(string1[4]=="Delhi")
	{
image_nm="delhi";
	}
		else if(string1[4]=="nagaland")
	{
image_nm="nagaland";
	}

	else
	{
		
var image_nm=string1[0].toLowerCase();
//alert(image_nm);
reg =/\s+/;
     image_nm= image_nm.replace(reg,"-");
		//alert(image_nm);
	}
	if(string1[3]=="NA" || string1[3]=="")
	{
		url="http://www.mapsofindia.com/parliamentaryconstituencies/";
	}
	else
	{
		url=string1[3];
	}
//alert(url);
document.getElementById("se3").value="<table cellspacing='0' cellpadding='0' border='0' width='350px'><tr><td width='20%'><a href='"+url+"'><img src='thumbnails/"+image_nm+".jpg'  border='0' length='50px' width='50px' /></a></td><td width='80%' align='left'><span><font color='Black' face='verdana' size='2'><b>Parliamentay Constituency</b>-</font>"+string1[0]+"</span><br /><span><font color='Black' face='verdana' size='2'><b>Assembly Constituency</b>-</font>"+string1[1]+"</span><br /><span><font color='Black' face='verdana' size='2'><b>Location</b>-</font>"+string1[2]+"</span><br /><span><font color='Black' face='verdana' size='2'><b>State</b>-</font>"+string1[4]+"</span></td></tr></table>";
//alert(document.getElementById("se").value);
delayer();
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(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 for district party /////////////////

function test1(str)
{
	//alert(str);
//document.form1.subcat.options="hi";

var brokenstring1=str.split("##"); 
var count1=brokenstring1.length;
//alert(count);
var j;
for(j=0;j<count1;j++)
	{
//alert(brokenstring1[j]);
	var SelectBox1 = document.getElementById('state');
	 SelectBox1.options[0] = new Option("-- Select Your State --");
     SelectBox1.options[SelectBox1.options.length] = new Option(brokenstring1[j], brokenstring1[j]);
	
	}
SelectBox1.selectedIndex=0;
}

function idchange3()
{//alert("ddsf");
	//alert(document.form1.id2.value=document.form1.district.selectedIndex);
	document.search.id2.value=document.search.state.selectedIndex;
	document.search.id3.value=document.search.party.selectedIndex;
}
function showdiv(val_state)
{

			document.getElementById("showdiv").style.visibility ='visible';
	
			document.getElementById("showdiv").style.display = 'block';
			document.getElementById("showdiv1").value=val_state;
			//alert(document.getElementById("showdiv1").value);

}
//function getresult()
//{
//	alert("dfd");
//var companyNm=document.form1.zone.options[form1.zone.selectedIndex].text;
//	var districtNm=document.form1.district.options[form1.district.selectedIndex].text;
//	var variantNm=document.form1.party.options[form1.party.selectedIndex].text;
//sendRequest('getresult.php?companyNm='+companyNm+'&districtNm='+districtNm+'&variantNm='+variantNm+'&flag=11');
//}
function delayer()
{
	//alert("df");
	//setTimeout('alert(\'hello\')',1250);
	drawmap();
}
function drawmap()
{
showAddress();
}
function showAddress() {

  map = new GMap2(document.getElementById("map"));
//map.addControl(new GLargeMapControl3D());
//map.addControl(new GScaleControl());
var mapControl = new GMapTypeControl();
map.addControl(mapControl);
map.addControl(new GLargeMapControl());

//map.setCenter(new GLatLng(19.017656,72.856178),14);	
geo = new GClientGeocoder(); 
reasons[G_GEO_SUCCESS] = "Success";

var geo;
geo = new GClientGeocoder(); 
if(document.getElementById("se").value=="JaipurRural")
	{
document.getElementById("se").value="Jaipur";
	}
	if(document.getElementById("se").value=="outer manipur" || document.getElementById("se").value=="Inner Manipur")
	{
document.getElementById("se").value="manipur";
	}
	if(document.getElementById("se").value=="Karauli –Dholpur")
	{
document.getElementById("se").value="Karauli";
	}
		if(document.getElementById("se").value=="Karauli –Dholpur")
	{
document.getElementById("se").value="Karauli";
	}
	
if(document.getElementById("se").value=="" && document.getElementById("state_nm").value=="")
	{
	var search = "";
	}
else if(document.getElementById("state_nm").value=="")
	{
	var search = document.getElementById("se").value+",india";
	}
	else if(document.getElementById("se").value=="")
{
		var search = document.getElementById("se").value;
	}
		else
	{
			var search = document.getElementById("se").value+","+document.getElementById("state_nm").value+",india";
	}

  
//alert(search);
  geo.getLocations(search, function (result)
    {
map.clearOverlays(); 
if (result.Status.code == G_GEO_SUCCESS) {
  
    var p = result.Placemark[0].Point.coordinates;
    place(p[1],p[0]);
  
}

else {
  var reason="Code "+result.Status.code;
  if (reasons[result.Status.code]) {
    reason = reasons[result.Status.code]
  } 
  //alert('Could not find "'+search+ '" ' + reason);
  alert('Could not find');
			  drawmap2();
}
    }
  );
}
	  function place(lat,lng) {
lat1=lat-1;
  var point = new GLatLng(lat,lng);
var point1 = new GLatLng(lat1,lng);
  map.setCenter(point1,8); 

 var baseIcon = new GIcon();
    baseIcon.iconSize=new GSize(22,23);
    baseIcon.shadowSize=new GSize(56,32);
    baseIcon.iconAnchor=new GPoint(16,32);
    baseIcon.infoWindowAnchor=new GPoint(16,0);
    
var martini = new GIcon(baseIcon, "images/ballot.jpg", null);
  var marker = createMarker(point,html,martini);
  map.addOverlay(marker);}
		
		 function showhint(str)
{
	//alert(str);
document.getElementById("se2").value=str;
}
		
		function createMarker(point,html,icon)
{
  var marker = new GMarker(point,icon);

  GEvent.addListener(marker, "mouseover", function() {
			//alert(point);
   showhint(point);	
var	 ztml=document.getElementById("se3").value;
//alert(ztml);
		 marker.tooltip = '<div class="tooltip">'+ztml+'</div>';
showTooltip(marker);
    marker.openInfoWindowHtml(ztml);
  });
GEvent.addListener(marker,"mouseout", function() {
		tooltip.style.visibility="hidden"
  });  
  return marker;
}
	  
	  function showTooltip(marker) 
	 {
	 //alert("ff");
	tooltip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
}
	 
// for first onload map
	 function drawmap2()
{
showAddress2();
}
function showAddress2() {
//alert("ff");
  map = new GMap2(document.getElementById("map"));
//map.addControl(new GSmallMapControl());
//map.addControl(new GScaleControl());
var mapControl = new GMapTypeControl();
map.addControl(mapControl);
map.addControl(new GLargeMapControl());
//map.setCenter(new GLatLng(19.017656,72.856178),14);	
geo = new GClientGeocoder(); 
reasons[G_GEO_SUCCESS] = "Success";

var geo;
geo = new GClientGeocoder(); 
 // var search = document.getElementById("se").value;
	   var search = "india";
//alert(search);
  geo.getLocations(search, function (result)
    {
map.clearOverlays(); 
if (result.Status.code == G_GEO_SUCCESS) {
  
    var p = result.Placemark[0].Point.coordinates;
    place2(p[1],p[0]);
  
}

else {
  var reason="Code "+result.Status.code;
  if (reasons[result.Status.code]) {
    reason = reasons[result.Status.code]
  } 
 //alert('Could not find "'+search+ '" ' + reason);
}
    }
  );
}
	   function place2(lat,lng) {
  var point = new GLatLng(lat,lng);
map.setCenter(new GLatLng(22.59368400000001,79.96288),5);



  var marker = createMarker(point,html);
}
		
