	
        /*  ~ Ajax ~ (oh, the joy...)
        
            General:
            
		    * ajax doesnt allow you to directly take values from server dps on postback eg. when a button is clicked
		    the solution is to use html dps and hidden fields (runat server). On the Onchange event fill the 
		    corresponding hidden fields with the dps value. On the server button click use the runat server hidden
		    field value
		    
		    * its advisible to have the Ajax.Utility.RegisterTypeForAjax(typeof(class name here)) to be outside the 
		    !Page.IsPostBack check on page load
		    
			    
		    Specific:
		    
		    * the ajax banner was placed in a frame but when a button in another frame was clicked, the dps lost their 
		    values. 
		    the solution is to use the hidden fields and when filling the dps (the ?_CallBack methods) check if these
		    hidden fields have values. If so loop thru each item of the alreday filled list and select the value that
		    matches the one in the hidden field. Then call the next levels fill method eg. prov --> munic
		    
		    
		    * the province dp had to be loaded on page load but it was an html dp using ajax
		    the solution so to call the loadProvince method on body load 
		    
		    
		    */		

		
		function loadProvince()//gets province list (initally on body load) 
		{
		    dpClear("dpProv","Province");//clear dps
		    dpClear("dpMunic","Municipality");
			dpClear("dpWard","Ward");
			
			DBHandler.getProvDS(loadProvince_CallBack);	
		}                                               



		function loadProvince_CallBack(response)//assigns province list to dpProv
        {
			if(response.error != null) 
			{
				window.alert(response.error); 
				return;
			}


			var dt	= response.value;
			if (dt == null || typeof(dt) != "object") {return;}
			var provList = document.getElementById("dpProv");
			
	
    		for(var i =0; i < dt.Rows.length; i++)//assign listitems to dp
			{		
				var opt	    = document.createElement("OPTION");
				opt.text    = dt.Rows[i].PROVINCE;//exact data column name
			    opt.value	= dt.Rows[i].PROVINCE;

			try {		
			    provList.add(opt);
				}
			catch (e) {
			   provList.add(opt,null);
			}
			}		
			
			/*var opt	    = document.createElement("OPTION");//add the default selected listitem
			opt.text    = "-- Select a Province --";
			opt.value	= "-1";		
			provList.add(opt);*/
			
			

			if (document.getElementById("hdnProv").value != "")   //if there's previous value, select that
			{
    		    for(var i =0; i < document.getElementById("dpProv").options.length; i++)
			    {		
			        if (document.getElementById("dpProv").options[i].value==document.getElementById("hdnProv").value)
			            {
			                document.getElementById("dpProv").options[i].selected = true;
			            }
			    }
	
    		    getMunics();//munic fill
			} 
			
       }//eof
		
		
		
		
		
		function getMunics()//gets munic list (generally dpProv onchange)
		{
			dpClear("dpMunic","Municipality");
			dpClear("dpWard","Ward");
			
			
			document.getElementById("hdnProv").value = document.getElementById("dpProv").value;//fill hidden field
						
			
			if (document.getElementById("dpProv").value != "-1")//is valid selection
			{
				DBHandler.getMunicDT(document.getElementById("dpProv").value,getMunics_CallBack);//gets list	
			}
		}
		
		
		
		function getMunics_CallBack(response)//assigns munic list to dpMunic 
		{
			if(response.error != null) 
			{
				window.alert(response.error); 
				return;
			}
				

			var dt	= response.value;
	    	if (dt == null || typeof(dt) != "object") {return;}
			var municList = document.getElementById("dpMunic");
		
						
			for(var i =0; i < dt.Rows.length; i++)//assign listitems to dp
			{		

				var opt	= document.createElement("OPTION");
				
				switch(dt.Rows[i].MUNITYPE)//insert muniType as prefix to mdbName value eg. KZ211 --> LKZ211
				{
					case "Local": //has --- to indicate falls under a district header; has wards
						opt.text			= "--- " + dt.Rows[i].MUNICNAME //+ "(" + dt.Rows[i].NEWCODE + ")";
						opt.value			= "L" + dt.Rows[i].MDBNAME;//exact data column name
					break;
					
					case "District"://header; has no wards
						opt.text			= dt.Rows[i].MUNICNAME  //+ "(" + dt.Rows[i].NEWCODE + ")";
						opt.value			= "D" + dt.Rows[i].MDBNAME;
					break;
					
					case "Metropolitan"://displayed as district (header) but has wards
						opt.text			= dt.Rows[i].MUNICNAME //+ "(" + dt.Rows[i].NEWCODE + ")";
						opt.value			= "M" + dt.Rows[i].MDBNAME;
					break;					
				}
				//municList.add(opt);

			try {		
			    municList.add(opt);
				}
			catch (e) {
			   municList.add(opt,null);
			}
			}
			
			
			
			if (document.getElementById("hdnMunic").value != "")//if there's previous value, select that
			{
			    for(var i =0; i < document.getElementById("dpMunic").options.length; i++)
			    {		
			        if (document.getElementById("dpMunic").options[i].value==document.getElementById("hdnMunic").value)
			        {
			            document.getElementById("dpMunic").options[i].selected = true;
			        }
			    }

			    getWards();//wards fill
			 } 
		}//eof
		
		
		
		
		
		
		
		
		function getWards()//gets wards list (generally dpMunic onchange)
		{
			dpClear("dpWard","Ward");
			
			document.getElementById("hdnMunic").value  = document.getElementById("dpMunic").value;//fill hidden field
			
									
			if (document.getElementById("dpMunic").value != "-1")//is valid selection
			{

			    document.getElementById("btMunic").disabled = false; //dont allow defaultt value to pass thru

			
				var muniType = document.getElementById("dpMunic").value;//get muniType (L,D,M)
				muniType = muniType.substr(0,1);
				
				var mdbName = document.getElementById("dpMunic").value;//get mdbName eg. KZ211
				mdbName = mdbName.substr(1,mdbName.length-1);
				
				switch(muniType)
				{
					case "L"://local has wards
						DBHandler.getWardDT(mdbName,getWards_CallBack);
					break;
					
					case "D"://district has no wards
					
					break;
					
					case "M"://metropolitan displayed in district style (as header) but it has wards
						DBHandler.getWardDT(mdbName,getWards_CallBack);
					break;
				}

			}
			else
			{
			    document.getElementById("btMunic").disabled = true;//invalid selection so u dont get to play with this
			}
		}	


		
		function getWards_CallBack(response)//assigns ward list to dpWard
		{
			if(response.error != null) 
			{
				window.alert(response.error); 
				return;
			}
			

			var dt	= response.value;
			if (dt == null || typeof(dt) != "object") {return;}
			var wardList = document.getElementById("dpWard");


			for(var i =0; i < dt.Rows.length; i++)
			{			
				var opt				= document.createElement("OPTION");//assign listitems to dp
				opt.text			= dt.Rows[i].WARD_NO;//exact data column name
				opt.value			= dt.Rows[i].WARD_ID;
				//wardList.add(opt);
			try {		
			    wardList.add(opt);
				}
			catch (e) {
			   wardList.add(opt,null);
			}
			
			}


			
			if (document.getElementById("hdnWard").value != "")//if there's previous value, select that
			{
			    for(var i =0; i < document.getElementById("dpWard").options.length; i++)
			    {		
			        if (document.getElementById("dpWard").options[i].value==document.getElementById("hdnWard").value)
			        {
			            document.getElementById("dpWard").options[i].selected = true;
			        }
			     }
			}		
		}//eof			
		



		
		function keepWard()//keeps selected ward value (on ward OnChange)
		{
			document.getElementById("hdnWard").value  = document.getElementById("dpWard").value;//fill hidden field
			
			
			if (document.getElementById("dpWard").value != "-1")//valid selection
			{
			    document.getElementById("btWard").disabled = false;			
			}
			else
			{
			    document.getElementById("btWard").disabled = true;//invalid selection so u dont get to play with this :-(
			}
		}
		
	
	
	
	
		
		function dpClear(id,msg)//clears specified dp and sets defaultt value
		{
			for (var i= document.getElementById(id).options.length-1;i>-1;i--)//remove all listitems
			{
				document.getElementById(id).options[i] = null;
			}
				
			var defaultt = document.createElement("OPTION");
			defaultt.text = "-- select a " + msg + " --";
			defaultt.value = "-1";
			document.getElementById(id).options.add(defaultt);	
			
			
		
//			alert("b4 hdnProv: " + document.getElementById("hdnProv").Value);
//			alert("b4 hdnMunic: " + document.getElementById("hdnMunic").Value);
//			alert("b4 hdnWard: " + document.getElementById("hdnWard").Value);
//			
//			switch(id)//clear hidden field value as well so dont go to previuos selection when defaultt is selected
//			{
//			    case "dpProv":
//				    document.getElementById("hdnProv").Value = "";
//				    //alert("hdnProv: " + document.getElementById("hdnProv").Value);
//				break;
//				
//			    case "dpMunic":
//				    document.getElementById("hdnMunic").Value = "";
//				    //alert("hdnMunic: " + document.getElementById("hdnMunic").Value);
//				break;
//				
//			    case "dpWard":
//				    document.getElementById("hdnWard").Value = "";
//				    //alert("hdnWard: " + document.getElementById("hdnWard").Value);
//				break;								
//			}
//			
//			alert("atr hdnProv: " + document.getElementById("hdnProv").Value);
//			alert("atr hdnMunic: " + document.getElementById("hdnMunic").Value);
//			alert("atr hdnWard: " + document.getElementById("hdnWard").Value);
		}