﻿//This JavaScript is linked to page Explorer.aspx

//This function sets the name
function setName(comboid,value)
{	
	
	//var url = "/KenticoCMS/CMSTemplates/elections09/Maps/ajaxeng.aspx";
	var url = "ajaxeng.aspx";
	
	var strname;
	switch (comboid)
	{
		case "selReligiousGender":
		{
			var strgetaction;
			
			document.getElementById("ReligiousSpan").innerHTML = "";
			//
			strvalue = document.getElementById("selDistribution").value;
			document.getElementById("selReligiousGender").disabled = false;
			switch (strvalue)
			{
				
				case "0": //-Choose a Distribution Type
				{
					ClearTheCombo(comboid);
					//
					if (document.getElementById(prefixName + "hid_lang").value!="ar")
						document.getElementById("ReligiousSpan").innerHTML = "";
					else
						document.getElementById("ReligiousSpan").innerHTML = "احدى الخصائص الديموغرافية";
					//
					//
					document.getElementById("Tip3").innerHTML = "";
					break;
				}
				
				//case "Gender":
				case "1": //Gender
				{
					if (document.getElementById(prefixName + "hid_lang").value!="ar")
					{
						document.getElementById("ReligiousSpan").innerHTML = "Gender ";
						//document.getElementById("Tip1").innerHTML = "Click on a district on the map to see a detailed chart";
						document.getElementById("Tip3").innerHTML = "Choose a specific demographic group below to see its geographic concentration across Lebanon";
						//alert("Click on a district on the map to see a detailed chart");
					}
					else
					{
						document.getElementById("ReligiousSpan").innerHTML = "الجنس";
						//document.getElementById("Tip1").innerHTML = "انقر على دائرة معينة في الخريطة لترى رسم  بياني مفصّل";
						document.getElementById("Tip3").innerHTML = "اخترة مجموعة ديموغرافية محددة من الاسفل لترى الكثافة الجغرافية في كل لبنان";
						//alert("انقر على دائرة معينة في الخريطة لترى التفاصيل");
					}
					strgetaction = "getGender";
					sendxmlrequest(url,comboid, strgetaction ,'',document.getElementById(prefixName + "hid_lang").value);
					break;
				}
				
				//case "Age":
				case "2": // Age
				{
					if (document.getElementById(prefixName + "hid_lang").value!="ar")
					{
						document.getElementById("ReligiousSpan").innerHTML = "Age   ";
						//document.getElementById("Tip1").innerHTML = "Click on a district on the map to see a detailed chart";
						document.getElementById("Tip3").innerHTML = "Choose a specific demographic group below to see its geographic concentration across Lebanon";
						alert("Click on a district on the map to see a detailed chart");
					}
					else
					{
						document.getElementById("ReligiousSpan").innerHTML = "العمر";
						//document.getElementById("Tip1").innerHTML = "انقر على دائرة معينة في الخريطة لترى رسم  بياني مفصّل";
						document.getElementById("Tip3").innerHTML = "اخترة مجموعة ديموغرافية محددة من الاسفل لترى الكثافة الجغرافية في كل لبنان";
						alert("انقر على دائرة معينة في الخريطة لترى التفاصيل");
					}
					strgetaction = "getAge";
					//sendxmlrequest(url,comboid, strgetaction ,'');
					ClearTheCombo(comboid);
					AddTheElementsToListBox(comboid,strvalue);//strname);
					break;
				}
				
				//case "Religious Community":
				case "3": //Religious Community
				{
					if (document.getElementById(prefixName + "hid_lang").value!="ar")
					{
						document.getElementById("ReligiousSpan").innerHTML = "<font size=1>Religious Community</font>";
						//document.getElementById("Tip1").innerHTML = "Click on a district on the map to see a detailed chart";
						document.getElementById("Tip3").innerHTML = "Choose a specific demographic group below to see its geographic concentration across Lebanon";
						alert("Click on a district on the map to see a detailed chart");
					}
					else
					{
						document.getElementById("ReligiousSpan").innerHTML = "الديانة";
						//document.getElementById("Tip1").innerHTML = "انقر على دائرة معينة في الخريطة لترى رسم  بياني مفصّل";
						document.getElementById("Tip3").innerHTML = "اخترة مجموعة ديموغرافية محددة من الاسفل لترى الكثافة الجغرافية في كل لبنان";
						alert("انقر على دائرة معينة في الخريطة لترى التفاصيل");
					}
					strgetaction = "getReligiousCommunity";
					//AddTheElementsToListBox(comboid);
					sendxmlrequest(url,comboid, strgetaction ,'',document.getElementById(prefixName + "hid_lang").value);
					break;
				}
				
				//case "Summary of Constituency":
				case "4": //Summary of Constituency
				{
					document.getElementById("ReligiousSpan").innerHTML = "";
					strgetaction = "getSummary";
					//sendxmlrequest(url,comboid, strgetaction ,'');
					document.getElementById("selReligiousGender").disabled = true;
					ClearTheCombo(comboid);
					if (document.getElementById(prefixName + "hid_lang").value!="ar")
					{
						//document.getElementById("Tip1").innerHTML = "Click on a District on the Map to See the Detail";
						document.getElementById("Tip3").innerHTML = "";
						alert("Click on a district on the map to see a detailed chart");
					}
					else
					{
						//document.getElementById("Tip1").innerHTML = "انقر على دائرة معينة في الخريطة لترى التفاصيل";
						document.getElementById("Tip3").innerHTML = "";
						alert("انقر على دائرة معينة في الخريطة لترى التفاصيل");
					}
					break;
				}
			}	
			break;
		}	
		
		/*case "selRegion_d":
		{
			ClearTheCombo(comboid);
			
			if ((document.getElementById("selReligiousGender").value != "0") && (document.getElementById("selReligiousGender").value != "r4"))
			{
				AddTheElementsToListBox(comboid);
			}
			break;
		}*/
		
		case "selDistrictType":
		{
		    
			var strgetaction;
			//strname = document.getElementById("ctl00_ContentPlaceHolder1_ctl00_ContentPlaceHolder1_selElectorallaw")[document.getElementById("ctl00_ContentPlaceHolder1_ctl00_ContentPlaceHolder1_selElectorallaw").selectedIndex].text
			if(value.length!=0)
			    strvalue=value;
			else
			{
			if(document.getElementById("ctl00_ContentPlaceHolder1_selElectorallaw"))
			    strvalue = document.getElementById("ctl00_ContentPlaceHolder1_selElectorallaw").value;
			}
			    
			  
			switch (strvalue)
			{
				/*case "Administrative":
				{
					//strgetaction = "getadministrative";
					document.frmMain.selDistrictType.disabled = false;
					AddTheElementsToListBox(comboid,strname);
					break;
				}*/
				
				//case "-Choose a District Division-":
				case "0": //-Choose a District Division-
				{
					ClearTheCombo(comboid);
					break;
				}
				
				//case "2000 Electoral Law":
				case "1": //2000 Electoral Law
				{
					//strgetaction = "get2000elections";
					//document.frmMain.selDistrictType.disabled = true;
					ClearTheCombo(comboid);
					//AddTheElementsToListBox(comboid);
					//sendxmlrequest(url,comboid, strgetaction ,'');
					strgetaction = "GET2000CONSTITUENCIES";//"getmohafaza";
					sendxmlrequest(url,'selDivision', strgetaction ,'',document.getElementById(prefixName + "hid_lang").value);
					break;
				}
				
				//case "Proposed Electoral Law":
				case "2": //Proposed Electoral Law
				{					
					//strgetaction = "get2000elections";
					//document.frmMain.selDistrictType.disabled = true;
					ClearTheCombo(comboid);
					//AddTheElementsToListBox(comboid);
					//sendxmlrequest(url,comboid, strgetaction ,'');
					strgetaction = "GET2005CONSTITUENCIES";//"getmohafaza";
					sendxmlrequest(url,'selDivision', strgetaction ,'',document.getElementById(prefixName + "hid_lang").value);
					break;
				}
				
				//case "Doha Law":
				case "3": //Doha Law
				{
					//strgetaction = "get2000elections";
					//document.frmMain.selDistrictType.disabled = true;
					ClearTheCombo(comboid);
					//AddTheElementsToListBox(comboid);
					//sendxmlrequest(url,comboid, strgetaction ,'');
					strgetaction = "GETDOHACONSTITUENCIES";//"getmohafaza";
					sendxmlrequest(url,'selDivision', strgetaction ,'',document.getElementById(prefixName + "hid_lang").value);
					break;
				}
				
			}
			break;
		}
			
		
		
		
	}
}

//This function sends map request to ajaxfnc.js
function seeonmap()
{
	alert("Hi");
	alert(document.getElementById("selRegion_r").options[document.getElementById("selRegion_r").selectedIndex].value + ", " + document.getElementById("selDivision").options[document.getElementById("selDivision").selectedIndex].value);
}


//function adds Elements to the List Box
function AddTheElementsToListBox(listboxid,value)
{  
	/*if (name == "Administrative")
	{
		document.getElementById(listboxid).options[0] = new Option('Mohafaza', 1);
		document.getElementById(listboxid).options[1] = new Option('Kadaa', 2);
	}
	else */

	//else if (name == "Age")
	if ((listboxid == "selReligiousGender") && (value == "2"))
	{
		if (document.getElementById(prefixName + "hid_lang").value!="ar")
		{
			document.getElementById(listboxid).options[0] = new Option('-Choose an Age Range-', 0);
			document.getElementById(listboxid).options[1] = new Option('21-25', 1);
			document.getElementById(listboxid).options[2] = new Option('26-30', 2);
			document.getElementById(listboxid).options[3] = new Option('31-35', 3);
			document.getElementById(listboxid).options[4] = new Option('36-40', 4);
			document.getElementById(listboxid).options[5] = new Option('41-45', 5);
			document.getElementById(listboxid).options[6] = new Option('46-50', 6);
			document.getElementById(listboxid).options[7] = new Option('51-55', 7);
			document.getElementById(listboxid).options[8] = new Option('56-60', 8);
			document.getElementById(listboxid).options[9] = new Option('61 and above', 9);
		}
		else
		{
			document.getElementById(listboxid).options[0] = new Option('-اختر اعمار بينية-', 0);
			document.getElementById(listboxid).options[1] = new Option('21-25', 1);
			document.getElementById(listboxid).options[2] = new Option('26-30', 2);
			document.getElementById(listboxid).options[3] = new Option('31-35', 3);
			document.getElementById(listboxid).options[4] = new Option('36-40', 4);
			document.getElementById(listboxid).options[5] = new Option('41-45', 5);
			document.getElementById(listboxid).options[6] = new Option('46-50', 6);
			document.getElementById(listboxid).options[7] = new Option('51-55', 7);
			document.getElementById(listboxid).options[8] = new Option('56-60', 8);
			document.getElementById(listboxid).options[9] = new Option('61 وما فوق', 9);
		}
		
	}
}


//function clears a listbox/combo box
function ClearTheCombo(listboxid)
{
 if(document.getElementById(listboxid))
 {
 while(document.getElementById(listboxid).options.length > 0)
	document.getElementById(listboxid).options[document.getElementById(listboxid).options.length-1]=null;
}
}

//function opens a pop-up window
function closepop()
{
	var NewWindow = window.open('','Identify') ;
	NewWindow.close();
}

//function enables or disables drop down lists based on electoral law selected
function EnableDisableDropDownLists()
{
    var selectedVal="-1";
    
    if(document.getElementById('ctl00_ContentPlaceHolder1_selElectorallaw'))
        selectedVal=document.getElementById('ctl00_ContentPlaceHolder1_selElectorallaw').value;
    
    if(selectedVal=="2")
    {
       if(document.getElementById('selDistribution'))
        document.getElementById('selDistribution').disabled=false;
       if (document.getElementById('selReligiousGender'))
        document.getElementById('selReligiousGender').disabled=false;
    }
    else
    {
       if(document.getElementById('selDistribution'))
        {
            document.getElementById('selDistribution').selectedIndex=0;
            document.getElementById('selDistribution').disabled=true;
         }
       if (document.getElementById('selReligiousGender'))
        {
            document.getElementById('selReligiousGender').selectedIndex=-1;
            document.getElementById('selReligiousGender').disabled=true;    
        }
    }
}
