// 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 == 2101) {parent.worldkit.SetVariable("JZoomComm","15.50787,47.58181,3.5"); }
if (selectPage == 2102) {parent.worldkit.SetVariable("JZoomComm","15.06797,47.38662,3"); }
if (selectPage == 2103) {parent.worldkit.SetVariable("JZoomComm","15.17049,46.6885,2"); }
if (selectPage == 2104) {parent.worldkit.SetVariable("JZoomComm","15.45023,47.13897,3"); }
if (selectPage == 2105) {parent.worldkit.SetVariable("JZoomComm","15.15453,46.00848,3"); }
if (selectPage == 2106) {parent.worldkit.SetVariable("JZoomComm","14.93459,45.59982,3.5"); }
if (selectPage == 2107) {parent.worldkit.SetVariable("JZoomComm","14.76627,45.74,4"); }
if (selectPage == 2108) {parent.worldkit.SetVariable("JZoomComm","14.50185,45.94167,4"); }
if (selectPage == 2109) {parent.worldkit.SetVariable("JZoomComm","14.71584,46.19642,2.5"); }
if (selectPage == 2110) {parent.worldkit.SetVariable("JZoomComm","14.48414,46.48735,3"); }
if (selectPage == 2111) {parent.worldkit.SetVariable("JZoomComm","14.18722,46.43784,4"); }
if (selectPage == 2112) {parent.worldkit.SetVariable("JZoomComm","14.28518,46.8656,4"); }
if (selectPage == 2113) {parent.worldkit.SetVariable("JZoomComm","14.56405,46.82769,3.5"); }
if (selectPage == 2114) {parent.worldkit.SetVariable("JZoomComm","14.30484,47.13712,3.5"); }
if (selectPage == 2115) {parent.worldkit.SetVariable("JZoomComm","14.51011,47.2789,3"); }
if (selectPage == 2116) {parent.worldkit.SetVariable("JZoomComm","14.36608,47.68278,3.5"); }
if (selectPage == 2117) {parent.worldkit.SetVariable("JZoomComm","13.93193,47.84002,3"); }


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","d2101");
document.worldkit.SetVariable("JLayComm","d2102");
document.worldkit.SetVariable("JLayComm","d2103");
document.worldkit.SetVariable("JLayComm","d2104");
document.worldkit.SetVariable("JLayComm","d2105");
document.worldkit.SetVariable("JLayComm","d2106");
document.worldkit.SetVariable("JLayComm","d2107");
document.worldkit.SetVariable("JLayComm","d2108");
document.worldkit.SetVariable("JLayComm","d2109");
document.worldkit.SetVariable("JLayComm","d2110");
document.worldkit.SetVariable("JLayComm","d2111");
document.worldkit.SetVariable("JLayComm","d2112");
document.worldkit.SetVariable("JLayComm","d2113");
document.worldkit.SetVariable("JLayComm","d2114");
document.worldkit.SetVariable("JLayComm","d2115");
document.worldkit.SetVariable("JLayComm","d2116");
document.worldkit.SetVariable("JLayComm","d2117");


}

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)
    }
}


