/*************************************************************************
 * $Id: advancedsearch.js ,v 1.2 2009/09/29 10:30:40 
 
 * author: Najima Muhammad 
 
 * modifications by : Najima Muhammad 
 
 * Copyright (c) 2009, Keltron Consultancy services.
 
**************************************************************************/
var elementFlag=0;
var officename="",placename="",panchayathname="";
var Places;
var similarFlagPanchayath=0;
var subdepartmentDivNo=0;subdeptflag=0;
var searchForDiv=0,officeParamDiv=0;
var withinParamDiv=0,withinflag=0;
var advStore;
var refreshDiv=0;
var DepartmentStore = new dojo.data.ItemFileReadStore({url:"/igsg/dept/"});
var servicetypeStore = new dojo.data.ItemFileReadStore({url:"/igsg/service/"});
var DistrictStore =new dojo.data.ItemFileReadStore({url:"/igsg/list/?layer=District&name="});
var corporationStore =new dojo.data.ItemFileReadStore({url:"/igsg/list/?layer=Corporation&name="});
var municipalityStore=new dojo.data.ItemFileReadStore({url:"/igsg/list/?layer=Municipality&name="});
var panchayathStore=new dojo.data.ItemFileWriteStore({url:"/igsg/list/?layer=Panchayath&name="});
var blockStore = new dojo.data.ItemFileReadStore({url:"/igsg/list/?layer=Block&name="});
var placestore=new dojo.data.ItemFileWriteStore({url:"/igsg/list/?layer=Place&name="});
/******* CREATE ADVNCED SEARCH FORM ***************************/
function createSearchOption()
{
	showSidebar();
	var parentDiv=document.getElementById("sidebarContent");
	parentDiv.innerHTML="";
	elementFlag++;
	var searchOptionDiv=document.createElement("div");
	searchOptionDiv.setAttribute('id','searchOptions');
	searchOptionDiv.className="searchOptionDiv";
	searchOptionDiv.innerHTML="<div id=searchContainer"+elementFlag+" style='height: 100%; overflow: hidden;'><div id=searchPane_1"+elementFlag+" style='height:auto;overflow:hidden;visibility:hidden;padding-left:5%;'><center><div id=searchtable><table width=100% ><tr ><td>Search for</td><td id=searchForTd ></td></tr><tr><td id=nameTd1></td>	<td id=nameTd2></td></tr><tr><td id=deptTd1></td><td id=deptTd2></td></tr><tr><td id=subdeptTd1></td><td id=subdeptTd2></td></tr><tr><td id=serviceTd1></td><td id=serviceTd2></td></tr><tr><td id=within1Td1></td><td id=within1Td2></td></tr><tr><td id=within2Td1></td><td id=within2Td2></td></tr><tr><td colspan=2><center><span id=cancelButtonTd  ></span><span id=searchButtonTd align=left></span><span id=refreshButtonTd align=right></span></center></td></tr></table></div></center></div><div id=searchPane_2"+elementFlag+" style='height:auto;overflow:hidden;visibility:hidden;padding-left:7%;background-color:#f3fcfd;'><div id=hilight></div><div id=advresult></div></div><div id=searchPane_3"+elementFlag+" style='height:auto;overflow:hidden;visibility:hidden;padding-left:7%;'></div></div>";
	parentDiv.appendChild(searchOptionDiv);
	adjustCenter();
	
	var searchForStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'option', items:[{"option": "Government Offices"}, {"option": "Place Name"}, {"option": "Corporation"},{"option": "Municipality"},{"option": "Grama Panchayath"},{"option": "Block Panchayath"}]}});
	var searchForTd=document.getElementById("searchForTd");
	var searchForCombobox= new dijit.form.FilteringSelect(
	{
		value: '--Select  --',
		name:"searchFor",
		id:"searchFor"+elementFlag,
		store: searchForStore,
		searchAttr:"option",
		onChange:getSearchFor
		},  document.createElement('div'));	
	searchForTd.appendChild(searchForCombobox.domNode);
	searchForCombobox.startup();
	
	var searchButtonTd=document.getElementById("searchButtonTd");
	var  searchButton= new dijit.form.Button(
	{ 
		id:"searching"+elementFlag,
		label: "Search",
		alt: "My button",
		title: "Search Button",
		onClick:getAdvancedSearchResult
	}, document.createElement('div'));
        searchButtonTd.appendChild(searchButton.domNode);
	searchButton.startup();
		
		
	var cancelButtonTd=document.getElementById("cancelButtonTd");
	var  cancelButton= new dijit.form.Button(
	{ 
		id:"cancel"+elementFlag,
		onClick:killMe,
		label: "Cancel",
		alt: "My button",
		title: "Cancel Button"
	}, document.createElement('div'));
        cancelButtonTd.appendChild(cancelButton.domNode);
	cancelButton.startup();
	
	var acp1=new dijit.layout.AccordionPane(
	{
		title:'Advanced Search',
		id:"searchFields"+elementFlag,
		selected:true
	}, document.getElementById("searchPane_1"+elementFlag));
	acp1.startup();
	var acp2=new dijit.layout.AccordionPane(
	{
		title:'Search Result',
		id:"resulfFields"+elementFlag				
	}, document.getElementById("searchPane_2"+elementFlag));
	acp2.startup();
	var acp3=new dijit.layout.AccordionPane(
	{
		title:' ',
		id:"bl"+elementFlag				
	}, document.getElementById("searchPane_3"+elementFlag));
	acp3.startup();
	var ac=new dijit.layout.AccordionContainer(
	{
		duration:200,
		id:"searchPane"+elementFlag
				
	}, document.getElementById("searchContainer"+elementFlag));
	ac.startup();
}

/******* CREATE REMAINING PORTION OF ADVNCED SEARCH FORM  ACCORDING TO THE SERACH TYPE ************/
function getSearchFor(value)
{
	var nametd1=document.getElementById("nameTd1");
	nametd1.innerHTML=" ";
	var nametd2=document.getElementById("nameTd2");
	nametd2.innerHTML=" ";
	
	var depttd1=document.getElementById("deptTd1");
	depttd1.innerHTML=" ";
	var depttd2=document.getElementById("deptTd2");
	depttd2.innerHTML="  ";
	
	var subdepttd1=document.getElementById("subdeptTd1");
	subdepttd1.innerHTML=" ";
	var subdepttd2=document.getElementById("subdeptTd2");
	subdepttd2.innerHTML=" ";
	
	var servicetd1=document.getElementById("serviceTd1");
	servicetd1.innerHTML=" ";
	var servicetd2=document.getElementById("serviceTd2");
	servicetd2.innerHTML=" ";
	
	var within1td1=document.getElementById("within1Td1");
	within1td1.innerHTML=" ";
	var within1td2=document.getElementById("within1Td2");
	within1td2.innerHTML=" ";
	
	var within2td1=document.getElementById("within2Td1");
	within2td1.innerHTML=" ";
	var within2td2=document.getElementById("within2Td2");
	within2td2.innerHTML=" ";
	
	officeParamDiv++;
	
	if(value=='Government Offices')
	{
		nametd1.innerHTML="Office Name";
		var officeNameTaxbox= new dijit.form.TextBox(
		{
			name:"officeName",
			id:"officeName"+officeParamDiv			
			},  document.createElement('div'));	
		nametd2.appendChild(officeNameTaxbox.domNode);
		officeNameTaxbox.startup();
		
		depttd1.innerHTML="Department";
		var departmentCombobox= new dijit.form.ComboBox(
		{
			name:"department",
			id:"department"+officeParamDiv,
			store: DepartmentStore,
			searchAttr:"department",
			onChange:getSubDept
		},  document.createElement('div'));	
		depttd2.appendChild(departmentCombobox.domNode);
		departmentCombobox.startup();
		
		
		/*servicetd1.innerHTML="Providing Service";
		var serviceTextbox= new dijit.form.TextBox(
		{
			name:"service",
			id:"service"+officeParamDiv			
		},  document.createElement('div'));	
		servicetd2.appendChild(serviceTextbox.domNode);
		serviceTextbox.startup();*/
		
		var withinStore = new dojo.data.ItemFileWriteStore({data: {identifier: 'option', items:[{"option": "District"}, {"option": "Corporation"},{"option": "Municipality"},{"option": "Grama Panchayath"},{"option": "Block Panchayath"}]}});
		within1td1.innerHTML="Within";
		var withinCombobox= new dijit.form.ComboBox(
		{
			value: '--Select  --',
			name:"within",
			id:"within"+officeParamDiv,
			store: withinStore,
			searchAttr:"option",
			onChange:getWithin
		},  document.createElement('div'));	
		within1td2.appendChild(withinCombobox.domNode);
		withinCombobox.startup();		
	}
	else if(value=='Place Name')
	{
		nametd1.innerHTML="Place Name";
		var selectPlaceTextbox= new dijit.form.TextBox(
		{
			name:"selectPlace",
			id:"selectPlace"+officeParamDiv
		},  document.createElement('div'));	
		nametd2.appendChild(selectPlaceTextbox.domNode);
		selectPlaceTextbox.startup();
	}
	else if(value=='Corporation')
	{
		nametd1.innerHTML="Corporation";		
		var corporationCombobox= new dijit.form.ComboBox(
		{
			name:"corporation",
			id:"corporation"+officeParamDiv,
			store: corporationStore,
			searchAttr:"name"
			},  document.createElement('div'));	
		nametd2.appendChild(corporationCombobox.domNode);
		corporationCombobox.startup();
		
		
	}
	else if(value=='Municipality')
	{
		nametd1.innerHTML="Municipality";
		var municipalityCombobox= new dijit.form.ComboBox(
		{
			name:"municipality",
			id:"municipality"+officeParamDiv,
			store: municipalityStore,
			searchAttr:"name"
			},  document.createElement('div'));	
		nametd2.appendChild(municipalityCombobox.domNode);
		municipalityCombobox.startup();
		
	}
	else if(value=='Grama Panchayath')
	{
		nametd1.innerHTML="Grama Panchayath";
		var panchayathTextbox= new dijit.form.TextBox(
		{
			name:"panchayath",
			id:"panchayath"+officeParamDiv
			},  document.createElement('div'));	
		nametd2.appendChild(panchayathTextbox.domNode);
		panchayathTextbox.startup();	
	}
	else if(value=='Block Panchayath')
	{
		nametd1.innerHTML="Block Panchayath";
		/*var blockTextbox= new dijit.form.TextBox(
		{
			name:"block",
			id:"block"+officeParamDiv
		},  document.createElement('div'));*/
		var blockTextbox= new dijit.form.ComboBox(
		{
			name:"block",
			id:"block"+officeParamDiv,
			store: blockStore,
			searchAttr:"name"
		},  document.createElement('div'));		
		nametd2.appendChild(blockTextbox.domNode);
		blockTextbox.startup();
	}
	else
		nametd2.innerHTML="<td></td><td id=WrongSelId >(Selection is not proper)</td>";	
}

/******* GET SUB-DEPARTMENT ACCORDING TO THE DEPARTMENT **********************/
function getSubDept(dept)
{
	
	var subdepttd1=document.getElementById("subdeptTd1");
	subdepttd1.innerHTML="Sub Department";
	var subdepttd2=document.getElementById("subdeptTd2");
	subdepttd2.innerHTML=" ";
	subdepartmentDivNo++;
	var SubDepartmentStore = new dojo.data.ItemFileReadStore({url:"/igsg/subdept/?dept="+dept});
	var subdepartmentCombobox= new dijit.form.ComboBox(
	{
		value: '--Select  --',
		name:"subdepartment",
		id:"subdepartment"+subdepartmentDivNo,
		store: SubDepartmentStore,
		searchAttr:"subdept"
	},  document.createElement('div'));	
	subdepttd2.appendChild(subdepartmentCombobox.domNode);
	subdepartmentCombobox.startup();		
	subdeptflag=1;
}
/******* PREPARE SERCH LINK ACCORDING TO THE INPUTS AND SAVE THE RESULT IN A JSON STORE **********************/
function getAdvancedSearchResult()
{
	var corporation="",municipality="",panchayath="",block="",name1="",service="";
	var dept="",subdept="",place="",within="",withinname="";
	var x,y;
	var content="";
	var name1=new Array();
	var gid=new Array();
	var x=new Array();
	var y=new Array();
	var searchType=dijit.byId("searchFor"+elementFlag).value;
	showLoader("advresult");
	if(searchType=='Government Offices')
	{
		name1=dijit.byId("officeName"+officeParamDiv).value;officename=name1;			
		//service=dijit.byId("service"+officeParamDiv).value;
		(dijit.byId("department"+officeParamDiv).value!='--Select  --')?dept=dijit.byId("department"+officeParamDiv).value:dept="";
		if(subdeptflag==1)
			(dijit.byId("subdepartment"+subdepartmentDivNo).value!='--Select  --')?subdept=dijit.byId("subdepartment"+subdepartmentDivNo).value:subdept="";
		(dijit.byId("within"+officeParamDiv).value!='--Select  --')?within=dijit.byId("within"+officeParamDiv).value:within="";
		if(within=='Grama Panchayath')
			within='Panchayath';
		if(within=='Block Panchayath')
			within='Block';	
		if(withinflag==1)
		{
			(dijit.byId("withinValue"+withinParamDiv).value!='--Select  --')?withinname=dijit.byId("withinValue"+withinParamDiv).value:withinname="";
			gotoExtendWithin();
		}
		//params="layer=Office&name="+name1+"&service="+service+"&dept="+dept+"&subdept="+subdept+"&within_layer="+within+"&within_name="+withinname;
		params="layer=Office&name="+name1+"&dept="+dept+"&subdept="+subdept+"&within_layer="+within+"&within_name="+withinname;
		advancedStore = new dojo.data.ItemFileReadStore({url: "/igsg/office/?"+params});
		var request=advancedStore.fetch({onComplete:advancedSearchFetch,onError:showError});
	}
	
	else if(searchType=='Place Name')
	{
		var divid=document.getElementById("advresult");			
		divid.innerHTML="";
		document.getElementById("hilight").innerHTML="";
		place=dijit.byId("selectPlace"+officeParamDiv).value;
		placename=place;
		var param="layer=Place&name="+place;
		Places = new dojo.data.ItemFileReadStore({url: "/igsg/list/?"+param});
		showLoader("advresult");
		var request=Places.fetch({onComplete:placeFetch,onError:showError});			
	}
		
	else if(searchType=='Corporation')
	{
		(dijit.byId("corporation"+officeParamDiv).value!='--Select  --')?corporation=dijit.byId("corporation"+officeParamDiv).value:corporation="";
		dispalyAdvancedSearchResult(corporation,'Corporation');
	}
	else if(searchType=='Municipality')
	{
		(dijit.byId("municipality"+officeParamDiv).value!='--Select  --')?municipality=dijit.byId("municipality"+officeParamDiv).value:municipality="";
		dispalyAdvancedSearchResult(municipality,'Municipality');
	}
	else if(searchType=='Grama Panchayath')
	{
		(dijit.byId("panchayath"+officeParamDiv).value!='--Select  --')?panchayath=dijit.byId("panchayath"+officeParamDiv).value:panchayath="";
		dispalyAdvancedSearchResult(panchayath,'Panchayath');
	}
	else if(searchType=='Block Panchayath')
	{
		(dijit.byId("block"+officeParamDiv).value!='--Select  --')?block=dijit.byId("block"+officeParamDiv).value:block="";
		dispalyAdvancedSearchResult(block,'Block');
	}
	dijit.byId("searchFields"+elementFlag).setSelected(false);
	dijit.byId("resulfFields"+elementFlag).setSelected(true);
	dijit.byId("searchPane"+elementFlag).selectChild(dijit.byId("resulfFields"+elementFlag));	
}
/******* PREPARE PLACE SEARCH OUTPUT **********************/
function placeFetch(items, request)
{
	var content="";
	var name1=new Array();
	var gid=new Array();
	var x=new Array();
	var y=new Array();
	var divid=document.getElementById("advresult");
	if(items.length==0)
	{
		content="<div class=serchloading style='color:red;font-weight:bold;line-height:1;font-size:12px;'><center><br><br><b>No matching Data found !!!</b><br><br><a href=# onClick=getSimilarPlace();>Search for similar words</a></center></div>";
	}
	else
	{
		for(var i=0;i<items.length;i++)
		{
			name1[i]=Places.getValue(items[i],'name');
			gid[i]=Places.getValue(items[i],'gid');
			x[i]=Places.getValue(items[i],'x');
			y[i]=Places.getValue(items[i],'y');
			//param="layer=Place&gid="+gid[i]+"&name="+name1[i];
			content +="<ul ><li><b><a href=# onclick=markPlace("+x[i]+","+y[i]+")>"+name1[i]+"</a></b></li></ul><br>";
		}
	}
	divid.innerHTML="<div class=advresult><br>"+content+"</div>";
}
/******* PREPARE SIMILAR PLACE SERCH LINK ACCORDING TO THE INPUT AND SAVE THE RESULT IN A JSON STORE ********/
function getSimilarPlace()
{
	var params="sdata="+placename+"&layers=place";
	Places = new dojo.data.ItemFileReadStore({url: "/igsg/similar/?"+params});
	showLoader("advresult");
	var request=Places.fetch({onComplete:placeFetch,onError:showError});
}

/******* ZOOM TO THE SPECIFIED REGION ***********/
function gotoExtendWithin()
{
	var extendStore,name1;
	var within=dijit.byId("within"+officeParamDiv).value;
	var withinValue=dijit.byId("withinValue"+withinParamDiv).value;
	if (within=='District')
		extendStore=DistrictStore;
	else if(within=='Corporation')
		extendStore=corporationStore;
	else if(within=='Municipality')
		extendStore=municipalityStore;
	else if(within=='Grama Panchayath')
		extendStore=panchayathStore;
	else if(within=='Block Panchayath')
		extendStore=blockStore;
	var request=extendStore.fetch({onComplete:function(items, request)
	{
		for(var i=0;i<items.length;i++)
		{				
			name1=extendStore.getValue(items[i],"name");
			if(name1==withinValue)
			{
				Ext=extendStore.getValue(items[i],'extent');				
			}
		}
	
	var ext=Ext.split(",");//alert(ext);
	map.zoomToExtent(new OpenLayers.Bounds(ext[0],ext[1],ext[2],ext[3]));
	}});
	
	
}

/******* DESTROY THE ADVANCED SERCH FORM ***********/
function killMe()
{
	if(document.getElementById("searchOptions")!=null)
		removeElement("searchOptions");
	serchDivFlag=0;
	subdeptflag=0;
	withinflag=0;
	getHelp();
	adjustCenter();
	if(highlitelayer)
	{
		map.removeLayer(highlitelayer);
		highlitelayer.destroy();
		highlitelayer=null;
		//dijit.byId('highliteRemove').hide();
	}
	
}

/******* CREATE WITHIN STORE AND SHOW IT IN A COMBOBOX ***********/
function getWithin(within)
{
	var within2td1=document.getElementById("within2Td1");
	within2td1.innerHTML=within;
	var within2td2=document.getElementById("within2Td2");
	within2td2.innerHTML=" ";
	withinParamDiv++;
	var withinValuestore,searchAttribute;
	if(within=='District')
		withinValuestore=DistrictStore;		
	else if(within=='Corporation')
		withinValuestore=corporationStore;
	else if(within=='Municipality')
		withinValuestore=municipalityStore;	
	else if(within=='Block Panchayath')
		withinValuestore=blockStore;	
	else
		withinValuestore=panchayathStore;	
	var withinValueCombobox= new dijit.form.ComboBox(
	{
		name:"service",
		id:"withinValue"+withinParamDiv,
		store: withinValuestore,
		searchAttr:'name'
			
	},  document.createElement('div'));	
	within2td2.appendChild(withinValueCombobox.domNode);
	withinValueCombobox.startup();
	withinflag=1;	
}

/******* ADVANCED OFFICE SERCH ***********/
function advancedSearchFetch(items, request)
{
	var id = new Array();
	var name1 = new Array();
	var x = new Array();
	var y = new Array();
	var officeContent="";
	showLoader("advresult");
	var divid=document.getElementById("advresult");			
	divid.innerHTML="";
	var placeName;
	var place;
	var placeid;
	if(moveSetFlag==1)
		center=center1;
	else
		center=cen;
	if(movepointflag==1)
		center=reflonglat;
	document.getElementById("hilight").innerHTML="";
	
	if(items.length<1)
		divid.innerHTML="<div id=advserchloading class=advserchloading style='color:red;font-weight:bold'><center><br><br><b>No matching data found !!!</b><br><br><a href=# onClick=getSimilarOffice();>Search for similar words</a></center></div>";
	else
	{
		for(var i=0;i<items.length;i++)
		{
			name1[i]=advancedStore.getValue(items[i],'name');
			if(name1[i]==undefined)
			{
				
				name1[i]=advancedStore.getValue(items[i],'err');
				officeContent +="<span style=color:red;font-size:14px;line-height:10px;><br><br><center>"+name1[i]+"</center></span>";
			}
			else
			{
				id[i]=advancedStore.getValue(items[i],'gid');
				x[i]=advancedStore.getValue(items[i],'x');
				y[i]=advancedStore.getValue(items[i],'y');
				officeContent +="<ul><li><b><a href=# onclick=getSearchCloud("+id[i]+",'Office*"+x[i]+"|"+y[i]+"');>"+name1[i]+"</a></b></li></ul><br>";
			}
					
			
		}
		divid.innerHTML="<div class=advresult><br>"+officeContent+"</div>";		
	}
	
}
/******* CALL SIMILAR OFFICE SEARCH ***********/
function getSimilarOffice()
{
	params="sdata="+officename+"&layers=office";
	advancedStore = new dojo.data.ItemFileReadStore({url: "/igsg/similar/?"+params});
	var request=advancedStore.fetch({onComplete:advancedSearchFetch,onError:showError});
}

/******* SHOWING ERROR MESSAGE ***********/
function showError(err)
{
	//alert(err);
	var divid=document.getElementById("advresult");			
	divid.innerHTML="";
	divid.innerHTML="<div id=advserchloading class=advserchloading style=color:red;><center>Unable to load the result !!!<br>Please try after some time...</center></div>";
}


/******* MARK THE PLACE BY A MARKER ***********/
function markPlace(x,y)
{
	var coords=new OpenLayers.LonLat(x,y);
	map.setCenter(coords,5);
	var size = new OpenLayers.Size(20,34);
	var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
	var icon = new OpenLayers.Icon('/giskerala/images/AQUA.png',size,offset);
	if(placePoint!=undefined) 
	{
		placePointMarker.removeMarker(placePoint);
	}	
	placePoint=new OpenLayers.Marker(coords,icon);
	placePointMarker.addMarker(placePoint);
	//dijit.byId('placeIndicator').show();
}

/******* DISPLAY ADVANCED SEACH RESULT EXCEPT FOR GOVT. OFFICES ***********/
function dispalyAdvancedSearchResult(value,searchType)
{
	var params,param;
	document.getElementById("hilight").innerHTML="<span style=margin-left:50%;>Highlight <input type='checkbox' id='chk' checked=true onclick='deleteHighlight();' /></span>";
	var content="";
	var name1=new Array();
	var gid=new Array();
	params="layer="+searchType+"&name="+value;
	
	advStore = new dojo.data.ItemFileReadStore({url: "/igsg/list/?"+params});
	var divid=document.getElementById("advresult");			
	divid.innerHTML="";
	showLoader("advresult");
	if(searchType=='Panchayath')
	{
		panchayathname=value;
		var request=advStore.fetch({onComplete:panchayathFetch,onError:showError});
	}
	else
	{
		var request=advStore.fetch({onComplete:function(items, request)
		{
			
			if(items.length<1)
			{			
				divid.innerHTML="<div class=serchloading style='color:red;font-weight:bold'><center><b>No matching Data found !!!</b></center></div>";				
			}
			else
			{
				for(var i=0;i<items.length;i++)
				{
					name1[i]=advStore.getValue(items[i],'name');
					if(searchType=='Block')
						gid[i]=advStore.getValue(items[i],'id');
					else
				
						gid[i]=advStore.getValue(items[i],'gid');
					param="layer="+searchType+"&gid="+gid[i];
					content +="<ul ><li><b><a href=# onclick=hilightMe('"+searchType+"','"+gid[i]+"','Adv');gotoExtends('"+searchType+"','"+gid[i]+"');>"+name1[i]+"</a></b></li></ul><br>";
				}
				divid.innerHTML="<div class=advresult><br>"+content+"</div>";
			}
		
		}});
	}
}
/******* SHOW PANCHAYATH SEARCH RESULT ***********/
function panchayathFetch(items, request)
{
	var content="";
	var name1=new Array();
	var gid=new Array();
	var x=new Array();
	var y=new Array();
	var divid=document.getElementById("advresult");
	if(items.length<1)
	{
		divid.innerHTML="<div class=serchloading style='color:red;font-weight:bold'><center><br><br><b>No matching Data found !!!</b><br><br><a href=# onClick=getSimilarPanchayath();>Search for similar words</A></center></div>";
		
	}
	else
	{
		for(var i=0;i<items.length;i++)
		{
			name1[i]=advStore.getValue(items[i],'name');
			gid[i]=advStore.getValue(items[i],'gid');
			if(similarFlagPanchayath==0)
				content +="<ul ><li><b><a href=# onclick=hilightMe('Panchayath','"+gid[i]+"','Adv');gotoExtends('searchType','"+gid[i]+"');createRefreshButton(); >"+name1[i]+"</a></b></li></ul><br>";
			else
				content +="<ul ><li><b><a href=# onclick=hilightMe('Panchayath','"+gid[i]+"','Adv');gotoExtendsSpanchayath('searchType','"+gid[i]+"');createRefreshButton(); >"+name1[i]+"</a></b></li></ul><br>";
		}
		divid.innerHTML="<div class=advresult><br>"+content+"</div>";
	}
	similarFlagPanchayath=0;
	
}
/******* CALL SIMILAR PANCHAYATH SEARCH ***********/
function getSimilarPanchayath()
{
	var params="sdata="+panchayathname+"&layers=panchayat";
	//alert(params);
	showLoader("advresult");
	advStore = new dojo.data.ItemFileReadStore({url: "/igsg/similar/?"+params});
	similarFlagPanchayath=1;
	var request=advStore.fetch({onComplete:panchayathFetch,onError:showError});
}

/******* ZOOM TO THE EXTEND ***********/
function gotoExtends(layer,id)
{
	var name1,Ext,gid;
	var request = advStore.fetch({onComplete:function(items, request)
	{
		for(var i=0;i<items.length;i++)
		{				
			layer=advStore.getValue(items[i],"layer");
			if(layer=='Block')
				gid=advStore.getValue(items[i],"id");
			else
				gid=advStore.getValue(items[i],"gid");
			if(gid==id)
			{
				Ext=advStore.getValue(items[i],'extent');				
			}
		}
	
	var ext=Ext.split(",");
	map.zoomToExtent(new OpenLayers.Bounds(ext[0],ext[1],ext[2],ext[3]));}});
}
/******* ZOOM TO THE EXTEND OF PANCHAYATH ***********/
function gotoExtendsSpanchayath(layer,id)
{
	var name1,Ext,gid;
	var request = advStore.fetch({onComplete:function(items, request)
	{
		for(var i=0;i<items.length;i++)
		{				
			//layer=advStore.getValue(items[i],"layer");
			gid=advStore.getValue(items[i],"gid");
			if(gid==id)
			{
				Ext=advStore.getValue(items[i],'xnt');				
			}
		}
	
	var ext=Ext.split(",");
	map.zoomToExtent(new OpenLayers.Bounds(ext[0],ext[1],ext[2],ext[3]));}});
}




