// JavaScript Document

function parseArgs(args) {
  var AO = new Object();
  var AA = args.split("&");
  var TA = new Array();
  for (var i=0; i<AA.length; i++) {
    TA = AA[ i ].split("=");
    AO[ TA[0] ] = unescape( TA[1] );
  }
  return AO;
}

function iframehighlitefac(num){
  for (var i=0; i<parent.selectForm.ddfacilities.length; i++) {
	if (parent.selectForm.ddfacilities.options[i].value == num){
		parent.selectForm.ddfacilities.selectedIndex = i;
	}
  }
  highlitedist(num);
  return num;
}


function highlitefac(num){
  for (var i=0; i<document.selectForm.ddfacilities.length; i++) {
	if (document.selectForm.ddfacilities.options[i].value == num){
		document.selectForm.ddfacilities.selectedIndex = i;
	}
  }
  highlitedist(num);
  return num;
}


function facCallback(args) {
  var ArgObject = parseArgs(args);	
   
  thedataframe.location = "../facilityhtml/" + ArgObject["id"] + "/" + ArgObject["id"] + suffix + ".html"; 
  highlitefac(ArgObject["id"]);	
}

function synchTab(thisTab,thisTabText) {
var elList, tableList, i, j;
  
	elList = document.getElementsByTagName("A");
	tableList = document.getElementsByTagName("Div");

	
	// Deactivate other active tab
        for (i = 0; i < elList.length; i++)  {
          removeName(elList[i], "active");
        }
	

	// Make seleted tab active
        thisTab.className += " active";
	
	var pos1 = 0;

	// Hide tables
	for (i = 0; i < tableList.length; i++)  {
		 pos1 = tableList[i].className.search(/visible/);
  		 if (pos1!=-1) {
                        removeName(tableList[i], "visible");
			tableList[i].className += " hidden";
		 }
		 if (tableList[i].id==thisTabText) {
     		 	tableList[i].className = "visible";
		 }
        }
}

function removeName(el, name) {
  var i, curList, newList;
  // Remove the given class name from the element"s className property.
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function toggleLegend () {
	var pos1 = 0;
	var divlist = document.getElementsByTagName("Div");
	for (i = 0; i < divlist.length; i++)  {
	    if (divlist[i].id=="legend") {
	      pos1 = divlist[i].className.search(/visible/);
		if (pos1!=-1) {
            	      removeName(divlist[i],"visible");
				divlist[i].className += " hidden";
		} else {
      	            removeName(divlist[i],"hidden");
				divlist[i].className += " visible";
		};
	    };
	}
}


function viewInfo (form, list) {
   if (list.value!="") {		
	var selectPage = list.value;
	var pageName = "../facilityhtml/" + selectPage +"/"+ selectPage + suffix + ".html";
	thedataframe.location = pageName;
        zoomto(selectPage);
        highlitedist(selectPage);
   };	
}


function viewDistrictInfo (form, list) {
	var selectPage = list.value;
	var pageName = "../facilityhtml/district" + selectPage +"/district"+ suffix + ".html";
	thedataframe.location = pageName;

if (selectPage == 2201) {parent.worldkit.SetVariable("JZoomComm","17.38,43.48,2"); }
if (selectPage == 2202) {parent.worldkit.SetVariable("JZoomComm","17.33,43.31,3"); }
if (selectPage == 2203) {parent.worldkit.SetVariable("JZoomComm","17.16,43.3,3"); }
if (selectPage == 2204) {parent.worldkit.SetVariable("JZoomComm","16.96,43.32,4"); }
if (selectPage == 2205) {parent.worldkit.SetVariable("JZoomComm","16.91,43.26,4"); }
if (selectPage == 2206) {parent.worldkit.SetVariable("JZoomComm","16.88,43.19,4"); }
if (selectPage == 2207) {parent.worldkit.SetVariable("JZoomComm","16.69,43.26,3.5"); }
if (selectPage == 2208) {parent.worldkit.SetVariable("JZoomComm","16.71,43.49,3"); }
if (selectPage == 2209) {parent.worldkit.SetVariable("JZoomComm","16.84,43.48,3"); }
if (selectPage == 2210) {parent.worldkit.SetVariable("JZoomComm","17.08,43.52,3"); }
if (selectPage == 2211) {parent.worldkit.SetVariable("JZoomComm","16.88,43.71,2"); }
if (selectPage == 2212) {parent.worldkit.SetVariable("JZoomComm","16.99,43.89,1"); }
if (selectPage == 2213) {parent.worldkit.SetVariable("JZoomComm","16.88,44.3,2.5"); }
if (selectPage == 2214) {parent.worldkit.SetVariable("JZoomComm","17.1,44.39,1"); }
if (selectPage == 2215) {parent.worldkit.SetVariable("JZoomComm","16.9,43.77,4"); }


document.selectForm.ddfacilities.selectedIndex = -1;
document.worldkit.SetVariable("JLayComm","d"+curDist);
document.worldkit.SetVariable("JLayComm","d"+selectPage);
curDist = selectPage;

}

function viewGovernorateInfo(form, list) {
	var selectPage = list.value;
	var pageName = "../facilityhtml/governorate" + selectPage +"/governorate"+ suffix + ".html";
	thedataframe.location = pageName;
      document.worldkit.SetVariable("JZoomComm","1,1,1");
}

function clearlayers() {

document.worldkit.SetVariable("JLayComm","d2201");
document.worldkit.SetVariable("JLayComm","d2202");
document.worldkit.SetVariable("JLayComm","d2203");
document.worldkit.SetVariable("JLayComm","d2204");
document.worldkit.SetVariable("JLayComm","d2205");
document.worldkit.SetVariable("JLayComm","d2206");
document.worldkit.SetVariable("JLayComm","d2207");
document.worldkit.SetVariable("JLayComm","d2208");
document.worldkit.SetVariable("JLayComm","d2209");
document.worldkit.SetVariable("JLayComm","d2210");
document.worldkit.SetVariable("JLayComm","d2211");
document.worldkit.SetVariable("JLayComm","d2212");
document.worldkit.SetVariable("JLayComm","d2213");
document.worldkit.SetVariable("JLayComm","d2214");
document.worldkit.SetVariable("JLayComm","d2215");


}

var secs = 2
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        clearlayers()
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}


