// ( by M.S )
//------------------------------------------------------------------------------------------------------------
var action_file = "../library/action_ajax.php";
//----------------------------------------------
function LoadPage(page)
{
	if (page != "")
	{
		var element = document.getElementById("display_content");
		document.getElementById("display_title").innerHTML="<img src='../images/titles/"+page.replace(".php", "")+".gif'>"
		var action = "LoadPage";
		var URL = "../main/"+page;
		Remote(URL, element, action);
	}
}
function LoadPage_map(page){
	if (page != "")
	{
		var element = document.getElementById("display_content");
		
		var action = "LoadPage_Map";
		var URL = "../main/"+page;
		Remote(URL, element, action);
	}
}
//----------------------------------------------
function SearchSubmit()
{
	var action = "Search";
	var element = document.getElementById("search_result");
	var zone = document.getElementById("cmbZone").value;
	var sector = document.getElementById("cmbSector").value;
	var text = document.getElementById("txtSearch").value;
	var layer=document.getElementById("cmblayer").value;
	var URL = action_file+"?action="+action+"&layer="+layer+"&zone="+zone+"&secid="+sector+"&text="+encodeURI(text).replace(/%DB%8C/g,"%D9%8A");
	Remote(URL, element, action);
}
//----------------------------------------------
function EditUser(id)
{
	var row = document.getElementById(id);
	var Element = document.getElementById("hidID");
	Element.value = id;
	var Element = document.getElementById("txtPlace");
	Element.value = row.cells[2].innerHTML;
	var Element = document.getElementById("txtFullName");
	Element.value = row.cells[3].innerHTML;
	var Element = document.getElementById("txtUsername");
	Element.value = row.cells[4].innerHTML;
	document.getElementById("txtFullName").focus();
	//var Element = document.getElementById("txtPassword");
	//Element.value = row.cells[5].innerHTML;
}
//----------------------------------------------
function EditPoint(id)
{
	var row = document.getElementById(id);
	var Element = document.getElementById("hidID");
	Element.value = id;
	var Element = document.getElementById("txtName");
	Element.value = row.cells[2].innerHTML;
	var Element = document.getElementById("txtAddress");
	Element.value = row.cells[3].innerHTML;
	var Element = document.getElementById("txtDescription");
	Element.value = row.cells[4].innerHTML;
}
//----------------------------------------------
function SelectZone()
{
	var List = document.getElementById("cmbZone");
	/*
	if (List[0].value == "")
		List.removeChild(List[0]);
	*/
	var action = "ShowSectors";
	var URL = action_file+"?action="+action+"&zone="+List.value+"&sector=0";
	Remote(URL, "", action);
}
function newSelectZone()
{
	var List = document.getElementById("cmbZone");
	/*
	if (List[0].value == "")
		List.removeChild(List[0]);
	*/

	var action = "ShowAdminSectors";
	var URL = action_file+"?action="+action+"&zone="+List.value+"&sector=0";
	Remote(URL, "", action);
		
}
//----------------------------------------------
function SelectAdminZone()
{
	var List = document.getElementById("cmbZone");
	/*
	if (List[0].value == "")
		List.removeChild(List[0]);
	*/
	var action = "ShowAdminSectors";
	var URL = action_file+"?action="+action+"&zone="+List.value+"&sector=0";
	Remote(URL, "", action);
}
//----------------------------------------------
function SelectAdminSectorDesc()
{
	var List = document.getElementById("cmbSector");
	/*
	if (List[0].value == "")
		List.removeChild(List[0]);
	*/
	var action = "ShowAdminSectorDesc";
	var URL = action_file+"?action="+action+"&sector="+List.value;
	Remote(URL,document.getElementById('txtDescription'), action);	
}

//----------------------------------------------
function SelectSector(zone, sector)
{
	
	LoadPage_map("introduction.php?zone="+zone+"&sector="+sector);
	
	//ReloadMap(zone, sector);
	
	
}
//----------------------------------------------
function ShowSectors(DataString)
{
	var Element = document.getElementById("cmbSector");
	for (var i = 1; i < Element.length; )
	{
		Element.removeChild(Element[i]);
	}
	var n = 1;
	
	var DataArray = DataString.split("|");
	for (var i = 0; i < DataArray.length; i++)
	{
		var A = DataArray[i].split("@");
		Element.options[n++] = new Option(A[1], A[0]);
	}
}
//----------------------------------------------
function ShowAdminSectors(DataString)
{
	var Element = document.getElementById("cmbSector");
	for (var i = 1; i < Element.length; )
	{
		Element.removeChild(Element[i]);
	}
	var n = 1;

	var DataArray = DataString.split("|");
	//var A = DataArray[0].split("@");
//	alert(DataArray[0])
	if (document.getElementById('txtDescription'))
		document.getElementById('txtDescription').value=DataArray[0];
	for (var i = 1; i < DataArray.length; i++)
	{
		var A = DataArray[i].split("@");
		Element.options[n++] = new Option(A[1], A[0]);
	}
}
//----------------------------------------------
function ShowLayers(DataString)
{
	var Element = document.getElementById("cmbSector");
	for (var i = 1; i < Element.length; )
	{
		Element.removeChild(Element[i]);
	}
	var n = 1;
	
	var DataArray = DataString.split("|");
	for (var i = 0; i < DataArray.length; i++)
	{
		var A = DataArray[i].split("@");
		Element.options[n++] = new Option(A[1], A[0]);
	}
}
//----------------------------------------------
function SelectLayer(id)
{
	var box = document.getElementById("chkLayer"+id);
	if (box.checked)
	{
		box.checked = false;
		var status = "deselect";
	}
	else
	{
		box.checked = true;
		var status = "select";
	}
	var action = "SelectLayer";
	var element = document.getElementById("monitor");
	var URL = action_file+"?action="+action+"&layer="+id+"&status="+status;
	Remote(URL, element, action);
}
//----------------------------------------------
function AdvancedSearch()
{
	var element = document.getElementById("advanced_content");
	if (document.getElementById("chkAdvanced").checked)
	{
		var action = "ShowSubLayers";
		var URL = action_file+"?action="+action;
		Remote(URL, element, action);
	}
	else
	{
		element.innerHTML = "";
	}
}
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
function FormLoading()
{
}
//------------------------------------------------------------------------------------------------------------
function GoTo(URL)
{
	window.location = URL;
	//document.forms[0].action = URL;
	//document.forms[0].submit();
}
//------------------------------------------------------------------------------------------------------------
function GoToNew(URL)
{
	var NewWindow = window.open(URL);
	//NewWindow.location = URL;
}
//------------------------------------------------------------------------------------------------------------
function GoToNewBlank(URL)
{
	//var NewWindow = window.open(URL, "", "left=40,top=30,width=800,height=600,status=1,scrollbars=1,menubar=0,toolbar=0,resizable=0");
	window.open(URL, "", "left=80,top=60,width=800,height=600,status=1,scrollbars=1,menubar=0,toolbar=0,resizable=1");
}
//------------------------------------------------------------------------------------------------------------
function ShowHide(Element)
{
	if (Element.currentStyle.visibility == "hidden")
		Element.style.visibility = "visible";
	else if (Element.currentStyle.visibility == "visible")
		Element.style.visibility = "hidden";
}
//------------------------------------------------------------------------------------------------------------
function trim(str)
{
	if (typeof(str) == "string")
		return str.replace(/^\s*|\s*$/,"");
//	return str.replace(/(^ +| +$)/, "");
}
function SetSectorXY(str){
	//alert(str);
		var DataArray = str.split("|");
		xmin=parseFloat(DataArray[0]);
		xmax=parseFloat(DataArray[1]);
		ymin=parseFloat(DataArray[2]);
		ymax=parseFloat(DataArray[3]);
		zone=DataArray[4];
		sector=DataArray[5];
	//	alert(sector);
		myMap.removeOverlayPoints();
		var leyer="tehran";
	if (zone<10) {
		leyer="z0"+zone+" "+leyer;
	}
	if (zone>9) {
		leyer="z"+zone+" "+leyer;
	}

	if (sector<10){
		leyer="s00"+sector+" "+leyer;
	
	}
	if (sector>0 & sector<100){
		leyer="s0"+sector+" "+leyer;
	
	}
	if (sector>99){
		leyer="s"+sector+" "+leyer;
	
	}	
	//alert(leyer);
	myMap.setLayers(leyer);
		myMap.setFullExtent(xmin,xmax,ymin,ymax);
		myMap.redraw(); 
}
function set_desc(){
	var action = "setdesc";
	var parameter="?action="+action+"&zone="+document.getElementById('cmbZone').value+
			  "&sector="+document.getElementById('cmbSector').value+
			  "&desc="+encodeURI(document.getElementById('txtDescription').value ).replace(/%DB%8C/g,"%D9%8A");
	var URL = action_file+parameter;
	Remote(URL, "", action);
	
}
//------------------------------------------------------------------------------------------------------------
