﻿// JScript File

//sets the action chosen by the user
var FrameTip;

var prefixZoomName;
var prefixSearchName;

function Load(zoomCtrl,searchCtrl)
{ 

//alert(zoomCtrl);
	prefixZoomName=zoomCtrl + "_";//zoomCtrl.substring(0,zoomCtrl.lastIndexOf("_")+1);
	prefixSearchName=searchCtrl + "_";//searchCtrl.substring(0,searchCtrl.lastIndexOf("_")+1);
    //alert(prefixName);
	//document.getElementById("mapframe").src="Map.aspx?extent="+ document.frmMain.extent.value;	


}


function CheckClickedFeature()
{
	var url="utility.aspx";    
	var response="";
	var j=0;
	//
   url=url+ "?action=checkmohafaza" ;
   
   url=url + "&p1=" + document.getElementById("hid_mapxdown").value + "_" + document.getElementById("hid_mapydown").value;  
   url=url + "&p2=CheckMohafaza";
    action="checkmohafaza";
   
	sendHTTPRequest(action,url);
	response=getHTTPResponse();	
	while(response=="-1" && j <100)
	{			
		j=j+1;
		response=getHTTPResponse();	
	}     
	//alert(response);
	
	if (response != false )
	{
	setLayer("MenuDiv",event);
	//SetMap(response);
	}
	else
	{
	setLayer("alertDiv",event);
	
	}
}	

function setLayer(divID,e)
{
    //alert(divID);
    showLayer(divID);
    document.getElementById(divID).style.top=e.clientY; //findPosY(document.getElementById('imgDIV')) + document.getElementById("hid_mousedowny").value;
    document.getElementById(divID).style.left=e.clientX; //findPosX(document.getElementById('imgDIV'))+ document.getElementById("hid_mousedownx").value;

}

function SetMenu(menu)
{

var url="utility.aspx";    
	var response="";
	var j=0;
	

if (menu=="StartLink")
{
//

   url=url+ "?action=SetPoint" ;
  url=url + "&p1=" + document.getElementById("hid_mapxdown").value + "_" + document.getElementById("hid_mapydown").value;  
  url=url + "&p2=Start"; 
    action="SetPoint";
}
if (menu=="StopLink")
{
url=url+ "?action=SetPoint" ;
   
   url=url + "&p1=" + document.getElementById("hid_mapxdown").value + "_" + document.getElementById("hid_mapydown").value;  
  url=url + "&p2=Stop"; 
    action="SetPoint";

}
if (menu=="EndLink")
{

url=url+ "?action=SetPoint" ;
   
   url=url + "&p1=" + document.getElementById("hid_mapxdown").value + "_" + document.getElementById("hid_mapydown").value;  
   url=url + "&p2=End"; 
    action="SetPoint";

}

if (menu=="CalculateLink" || menu=="Calculate2Link")
{

document.frmMap.hid_subaction.value="PlanTheTrip";
document.frmMap.submit();
action="";

}

if (menu=="ResetLink" || menu=="Reset2Link")
{

document.frmMap.hid_subaction.value="";			
document.frmMap.hid_showsymbol.value="";
document.frmMap.hid_showroute.value="";
action="";

SetAction('reset',0);

}

if (menu=="OkButton")
{
hideLayer("alertDiv");
action="";

}

    sendHTTPRequest(action,url);
	response=getHTTPResponse();	
	while(response=="-1" && j <100)
	{			
		j=j+1;
		response=getHTTPResponse();	
	}
	 
	 
	if (response != false)
	{
	
	}
	
}


//locator functionality

function LoadMohafazas()
{

    filterList('','ddlMohafaza','GETMOHAFAZA',this.selectedIndex,'','');
}

//function filters the region list boxes according to users selection
function filterList(actionCntrlId,re_actionCntrlId,action,value,mainCntrlId,additional)
	{
		var url="utility.aspx";    
		var response="";
		var j=0;
		
		//action,p1(value)		
		url=url+ "?action=" + action ;
		if (actionCntrlId.length!=0)
		{
		    url=url + "&p1=" + document.getElementById(actionCntrlId)[value].value;		    
		}
		if(mainCntrlId.length!=0)
		{
		 url =url + "&p2=" + document.getElementById(mainCntrlId)[document.getElementById(mainCntrlId).selectedIndex].value;
		}
		if (additional.length!=0)
		{
			url=url+ "&p3=" + document.getElementById(additional)[document.getElementById(additional).selectedIndex].value;
		}
		//alert(url);
		sendHTTPRequest(action,url);
		response=getHTTPResponse();	
		while(response=="-1" && j <100)
		{			
			j=j+1;
			response=getHTTPResponse();	
		}
		if (j<100)
		{
			LoadValues(response,re_actionCntrlId);
		}
	}

function Locate()
{


	var url="utility.aspx";    
	var response="";
	var j=0;
	//
    if (document.getElementById("ddlPollingStation").selectedIndex>0){
		action="locatePollingCenter"		
	    url=url+ "?action=locatePollingCenter" ;
	    url=url + "&p1=" + document.getElementById("ddlPollingStation")[document.getElementById("ddlPollingStation").selectedIndex].value;  	        
    }else if (document.getElementById("ddlZone").selectedIndex>0){
		action="locatezone"		
	    url=url+ "?action=locatezone" ;
	    url=url + "&p1=" + document.getElementById("ddlZone")[document.getElementById("ddlZone").selectedIndex].value;  
    }else if(document.getElementById("ddlKadaa").selectedIndex>0){
		//action,p1(value)	
		action="locatekadaa"		
	    url=url+ "?action=locatekadaa" ;
	    url=url + "&p1=" + document.getElementById("ddlKadaa")[document.getElementById("ddlKadaa").selectedIndex].value;		          
    }
    else if(document.getElementById("ddlMohafaza").selectedIndex>0){
		//action,p1(value)	
		action="locatemohafaza"		
	    url=url+ "?action=locatemohafaza" ;
	    url=url + "&p1=" + document.getElementById("ddlMohafaza")[document.getElementById("ddlMohafaza").selectedIndex].value;		    	            
    } 
    
    else
    { 
    return false;
    }
    //action="zoomtofeature";
    //alert(url);
	sendHTTPRequest(action,url);
	response=getHTTPResponse();	
	while(response=="-1" && j <100)
	{			
		j=j+1;
		response=getHTTPResponse();	
	}     
	//alert(response);
	RefreshMap(response); 
}

function Refresh1Map(responseStr)
{


    var response_arr;
    if (responseStr.length!=0)
    {
        response_arr=responseStr.split("#");
        document.getElementById("imgmap").src=response_arr[0];
        var extent_arr=response_arr[1].split("_");        
        document.getElementById("hid_minx").value=extent_arr[0];
        document.getElementById("hid_miny").value=extent_arr[1];
        document.getElementById("hid_maxx").value=extent_arr[2];
        document.getElementById("hid_maxy").value=extent_arr[3];
     } 
     //document.getElementById("hid_action").value="select";    
}



function clearSessions(AccordionIndex)
{


var url="../Utility.aspx";    
	var response="";
	var j=0;
	url=url+ "?action=clearSessions" ;
	url=url + "&p1=" + AccordionIndex
	action="clearSessions";
	
	sendHTTPRequest(action,url);
	response=getHTTPResponse();	
	while(response=="-1" && j <100)
	{			
		j=j+1;
		response=getHTTPResponse();	
	}
	 
	 
	if (response != false)
	{
	
	}
}


//this function is used to refresh the map
function RefreshMap(subaction)
{
var checker;
var action;
//alert(prefixZoomName);
    if (subaction != "")
    {    
    
          if (subaction == "search")
          {          
              if (trim(document.getElementById(prefixSearchName + "txtSearch").value) != '')
              {                    
                 action = "SearchSites";
                 subaction= trim(document.getElementById(prefixSearchName + "txtSearch").value);
                 checker=true;          
              }                    
          }  
    
           if (subaction == "locate")
           {   
           
              if (document.getElementById(prefixZoomName + "ddlPollingStation").value!= "")
              {
                action = "locatePollingCenter";
                 subaction= document.getElementById(prefixZoomName + "ddlPollingStation").value;
                checker = true;
             }                   
              else if (document.getElementById(prefixZoomName + "ddlZone").value!= "")
              {              
                action = "locateZone";
                 subaction= document.getElementById(prefixZoomName + "ddlZone").value;
                checker = true;
             }
            else if( document.getElementById(prefixZoomName + "ddlKadaa").value != "" )
            {
                action = "locateKadaa";
                subaction = document.getElementById(prefixZoomName + "ddlKadaa").value;
                checker = true;            
            }
            else if( document.getElementById(prefixZoomName + "ddlMohafaza").value != "-1" )
            {
                action = "locateMohafaza";
                subaction = document.getElementById(prefixZoomName + "ddlMohafaza").value;
                checker = true;            
            }
        }

        if (checker == true )
        {
            //refresh the map for the new changes                            
           window.mapframe.document.getElementById("hid_action").value = action;
           window.mapframe.document.getElementById("hid_subaction").value = subaction;
           window.mapframe.document.forms["frmMap"].submit();
         }                   
    }       
}
function NoResults(action)
{

  if (action == "SearchSites")
      {    
            
          document.getElementById(prefixSearchName + "lblMessage").style('display')='block';
                              
      }  
}

////this function is used to refresh the map
//function RefreshMap(subaction)
//{

//alert(subaction);
//    if (subaction != "")
//    {            
//           window.mapframe.document.getElementById("hid_action").value = subaction;
//           window.mapframe.document.getElementById("hid_subaction").value = subaction;
//           window.mapframe.document.forms["frmMap"].submit();                   
//    }    
//    else
//    {    
//           window.mapframe.document.getElementById("hid_action").value = "";
//           window.mapframe.document.getElementById("hid_subaction").value = "";    
//    }

//}

// Shows DIV popup commands for gridview
function ShowPopup(lbtn1,lbtn2,lbtn3,lbtn4,panel,gridviewRow)
{
    var link1 = document.getElementById(lbtn1);
    var link2 = document.getElementById(lbtn2);
    var link3 = document.getElementById(lbtn3);
    var link4 = document.getElementById(lbtn4);
    var pnl = document.getElementById(panel);
    var row= document.getElementById(gridviewRow);
    pnl.style.display = "block";

    //row.style.backgroundImage = "url(../images/td_mouseover.gif)";
    if(link1 != null)
        link1.style.display = "block";
    if(link2 != null)
        link2.style.display = "block";
    if(link3 != null)
        link3.style.display = "block";
    if(link4 != null)
        link4.style.display = "block";
    //pnl.style.backgroundImage = "url(../images/td_mouseover_inverted.gif)";
}

//Hides DIV popup commands for gridview
function HidePopup(lbtn1,lbtn2,lbtn3,lbtn4,panel,gridviewRow)
{
    var link1 = document.getElementById(lbtn1);
    var link2 = document.getElementById(lbtn2);
    var link3 = document.getElementById(lbtn3);
    var link4 = document.getElementById(lbtn4);

    var pnl = document.getElementById(panel);
    var row= document.getElementById(gridviewRow);
    //row.style.backgroundImage="url(../images/spacer.gif)";
    pnl.style.display = "none";
    if(link1 != null)
        link1.style.display = "none";
    if(link2 != null)
        link2.style.display = "none";
    if(link3 != null)
        link3.style.display = "none";
    if(link4 != null)
        link4.style.display = "none";
        
}

//function used to open the hotels page
function findNearByHotels(building)
	{
	
		window.open("NearByHotels.aspx?building=" + building,"NearByHotels","","scrollbars=1; resizable=yes; width=600; height=450");
		
	}
	
	
	//function used to show more information for a selected site from a dropdown list
	function SeeSearchInfo(value)
        {
        
            if ( value != "" )
             { 
                 window.open("MapTools/DescriptionReport.aspx?action=SearchSites&value=" + value ,"","scrollbars=1, resizable=yes, width=600, height=450");
                 //var url="../MapTools/DescriptionReport.aspx?action=SearchSites&value=" + value;
                 //ShowTipFrame(e,url,'500px','500px')
             
             }
        }
	
	function TreeLoad(cntrlId)
	{	
	    document.getElementById(cntrlId).onclick=function(e) {postBackByObject(e)};
	}
	
	//used to postaback the customize page
	function postBackByObject(e)
        {
         var o ;
        if (isIE) 
        {
            e=event;
            o=e.srcElement;
        }
        else
        {
            o =e.target;
        }
        
           var RootArray=new Array("0","3","7","16","21","28","32","37","39","46","52","59");
           //var RootArray[]={'0','3','7'};
           
            if (o.tagName == "INPUT" && o.type == "checkbox"  )
            {
            
                var i;
                var temp;
            
                 for(i=0;i<RootArray.length;i++)
                 {
                 
                    temp="CategoriesTreeViewn" + RootArray[i] + "CheckBox"
                    if(o.id == temp)
                    {
                      __doPostBack("","");
                      return false;
                    }
                 
                 }
            
               
            } 



}
var n;
var p;
function StartTimer(cntrl)
{

//window.clearTimeout(p);
window.setTimeout("Grow('"+ cntrl + "')",500);

}
function StopTimer(cntrl)
{

window.setTimeout("Shrink('"+ cntrl + "')",2000);
//window.clearTimeout(n);


}
function Grow(cntrl)
{
//window.clearTimeout(p);
document.getElementById(cntrl).style.width='auto';
document.getElementById(cntrl).style.position='absolute';
}
function Shrink(cntrl)
{
document.getElementById(cntrl).style.width='200px';
document.getElementById(cntrl).style.position='static';
}

function showToolTip(cntrl)
{
document.getElementById("ToolTipDiv").style.display="block"; 
document.getElementById("ToolTipDiv").style.visibility="visible";

document.getElementById("ToolTipDiv").style.backgroundColor="AliceBlue"; 
document.getElementById("ToolTipDiv").style.position = "absolute";

//document.getElementById("ToolTipDiv").style.left="140";document.getElementById("ToolTipDiv").style.top="30"; 
 

 len = document.getElementById(cntrl).length;
 var i;
 
     for(i=0;i<len;i++) 
    {

        if(document.getElementById(cntrl).options[i].selected) 
            {

                var v = document.getElementById(cntrl).options[i].text; 
                document.getElementById("ToolTipDiv").innerText = v; 
            }

    }

}

function hideToolTip(cntrl)
{

document.getElementById("ToolTipDiv").style.display="none"; 
document.getElementById("ToolTipDiv").style.visibility="hidden";

document.getElementById("ToolTipDiv").innerText = ""; 

}


//function used from the lebanonAtlas website when the user click on GetMap button
	function PopUpMap(ddl)
        {
        
            var value= document.getElementById(ddl)[document.getElementById(ddl).selectedIndex].value;
           
            if (value != "0" && value !="")
             { 
             
            window.open("../MapTools/PopUpMap.aspx?action=popup&value=" + value,"","scrollbars=0; resizable=yes; width=600; height=450");
             }
        }
        
        
        //function used to show any content in the TipFrame which is in the Inmma Master page
        
        function ShowTipFrame(e,Url,Height,Width)
        {
           
            FrameTip = new ToolTip("TipFrame",true,30,Height,Width);
	          if(FrameTip)FrameTip.Show(e,"<br><br>Loading...");
		     
		       document.getElementById("TipFrame").src = Url;
		       
		       
        
        }
        
        
        //function used to hide the TipFrame which is in the Inmma Master page
        
        function HideTipFrame(e)
        {
           if (parent.document.getElementById("TipFrame"))
           {
           parent.document.getElementById("TipFrame").style.display='none';
           }
           else
           {
            window.close();
           }
		     
		}
		
		
		function ShowHideHelpDiv(cntl,txt)
		{
		
		
		if(document.getElementById(cntl).style.display == 'none')
		     {   
		    
		      document.getElementById(cntl).style.display='block';
		       document.getElementById(cntl).style.top='250px';
		      document.getElementById(cntl).style.left='550px';
		      }
		  else
		     {
		       document.getElementById(cntl).style.display='none';
		     }
		}
        
        
        

