﻿//This JavaScript is linked to page Explorer.aspx\



var xmlObj;
var xmlDoc; //XML document that will hold the data
var loaded;


function sendxmlrequest(url,comboid,action,value,lang)
{ 	
	
	var skip=true;
	
	if (action == "getmohafaza" )
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	 
	if (action == "getkadaa"  ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();		
	}

	if (action == "getzone" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}

	if (action == "gettown" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "get2000elections" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "getreformlaw" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "getGender" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "getAge" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "getReligiousCommunity" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
		skip=false;
	}
	
	if (action == "getSummary" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}

	if (action == "GETSMALLCONSTITUENCIES" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "GETSLARGECONSTITUENCIES" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
	
	if (action == "GET2000CONSTITUENCIES" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}

	if (action == "GET2005CONSTITUENCIES" ) 
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
		
	if (action == "GETDOHACONSTITUENCIES")
	{
		url=url+"?straction="+action;
		url=url+"&sid="+Math.random();
	}
		url=url + "&ln=" + lang;
		
	ajaxRead(url);
	
	//Read XML and Add Names to list box
	if (loaded)
	{
	ClearCombo(comboid);
	var j=0;
	if(!skip)
	{	
		//if (document.getElementById(comboid).options[document.getElementById(comboid).selectedIndex].text == "Religious Community")
		//{
			AddtoList(comboid);
			j=4;
		//}
	}
	if(xmlObj.readyState == 4){
		var colData = xmlDoc.getElementsByTagName('options');
		for (i=0;i<colData[0].childNodes.length;i++)
		{
			if (colData[0].childNodes[i].nodeType != 1) continue;	
			AddElementsToListBox(comboid,i+j,colData[0].childNodes[i].getAttribute('value'),colData[0].childNodes[i].getAttribute('name'));							
		}				
	}//end if(xmlObj.readyState == 4)
	}//end if loaded
}
//=====================================================

		
//function gets the HTML of a page. In our case the page is in XML format
//so this function reads the XML and saves it in XML object
function ajaxRead(file){

  xmlObj = null;
  if(window.XMLHttpRequest){
      xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
      return;
  }
  
    xmlObj.open ('GET', file, false);
    //xmlObj.SetRequestHeader ("Content-Type","text/xml");
    xmlObj.send ('');  
    
	//xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4)
    {
		if (window.ActiveXObject)//IE
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
			xmlDoc.async = false;		
			loaded = xmlDoc.loadXML(xmlObj.responseText);
			if (loaded==false) alert ("cant get XML doc");
		}
		else//Mozilla,FireFox,Opera...
		{
		  var parser=new DOMParser();
		  var str=xmlObj.responseText;		  
		  xmlDoc=parser.parseFromString(str,"text/xml");
		  loaded=true;
		}
     }
     //}
  }
  
//=====================================================

//function adds only when the user choses "Demographic Distr. of Religious Community"
function AddtoList(listboxid)
{
	if (document.getElementById(prefixName + "hid_lang").value!="ar")
	{
		document.getElementById(listboxid).options[0] = new Option('-Choose a Religious Community-', '0');
		document.getElementById(listboxid).options[1] = new Option('Christian','111');
		document.getElementById(listboxid).options[2] = new Option('Muslim','222');
		document.getElementById(listboxid).options[3] = new Option('______','333');
	}
	else
	{
		document.getElementById(listboxid).options[0] = new Option('-اختر الديانة-', '0');
		document.getElementById(listboxid).options[1] = new Option('مسيحيين','111');
		document.getElementById(listboxid).options[2] = new Option('222','مسلمين');
		document.getElementById(listboxid).options[3] = new Option('______','333');
	}
}

//function adds options to a list box dynamically
//function takes listbox id,elementid, and element name
  function AddElementsToListBox(listboxid,index, elementid,elementname)
  {   
	document.getElementById(listboxid).options[index] = new Option(elementname,elementid);
  }

//function clears a listbox/combo box
function ClearCombo(listboxid)
{
 while(document.getElementById(listboxid).options.length > 0)
	document.getElementById(listboxid).options[document.getElementById(listboxid).options.length-1]=null;
}
//=====================================================