﻿// This JS file manipulate the web map appliaction properties

var rightPanelWidth = 250;
flag_SignedIn=false;
binX=null;
binY=null;
var currHeight = 0;
var currWidth = 0;
window.onresize = validateAdjustMapSize;
var isLoggodIn;// To get if the user is logined or not

function InitJE()
    {
        var bd = BrowserDetect;
//        if (bd.browser == 'Explorer' && bd.version == '6')
//        {
//            window.location= "incompatible_browser.aspx"
//        }
        var cWidth = GetWinWidth();
        var cHeight = GetWinHeight();
        var welcomeDB = document.getElementById("Wizard1");
        welcomeDB.style.top = Math.abs((cHeight/2)-(400/2))+ "px";
        welcomeDB.style.left = Math.abs((cWidth/2)-(500/2))+ "px";
        initMap();
        
//        Maximize the Browser      
//        try
//        {
//          maximizeBrowser();
//        }
//        catch(e) 
//        {}     

        LoadPluginMenuItems_update('tabs');
        
/************************Reading RemeberMe Cookie************************/
//        var CookieContents=ReadCookie("Cookie");
//        if(CookieContents!="")
//        {
//         userName=CookieContents.split("&")[0].split("=")[1].toString();
//         userCode=CookieContents.split("&")[1].split("=")[1];
//         SignIn();
//        }
/************************************************************************/
        
        var b = document.getElementById("menuItem7");
        XBrowserAddHandler(b, 'click', ActivatePlugin);
        
        if(window.location.search.length == 0)
        {
           // ShowPlugin(0);
            TogglePanelDock(true);
        }
        else
        {
            checkQueryStrings();
        }  
         //CallServer("","ReadSigninCookie");      
        //AdjustMapSize();
    }
    
function checkQueryStrings()
    {
        var pluginName = queryString('Plugin');
        if(pluginName != 0)
        {
            ActivatePlugin_queryString(pluginName);
        }
        
        var searchStr = queryString('SearchStr');
        var searchID = queryString('SearchID');
        if(searchStr != 0 || searchID != 0)
        {
            SearchByQueryString();
        }
        
        var   Plugin_Name  = queryString('PLUGIN');
        var   OBJECTID  = queryString('OBJECTID');
        var   ENADMINTYPE  = queryString('ENADMINTYPE');
        if(Plugin_Name=="WIZARD"&&OBJECTID!=0&&ENADMINTYPE!=0)
        {
            ShowHideLoading(true);
            $("#Wizard1").hide();
            var Arg=OBJECTID+";"+ENADMINTYPE;
            CallServer(Arg,'ZoomToMBR')
        }
    }
    
// Show First load loading..
function ShowFirstLoad()
    {
        var divBody = document.getElementById('divFirstLoad');
        divBody.style.display = 'none';
        
        var divBody = document.getElementById('divBody');
        divBody.style.display = 'block';
        
        setTimeout('AdjustMapSize()',1);	
        
//        window.onbeforeunload = function (evt) {
//        if (confirm("Are You sure?")) {
//            PluginDesc;
//        }
//        }
    }

// disabled, added to checkQueryStrings(), hide the welcome wizard, disabled in default.aspx also
//function ShowItemUsingWizard()
//    {
//         
//         var   Plugin_Name  = queryString('PLUGIN');
//         var   OBJECTID  = queryString('OBJECTID');
//         var   ENADMINTYPE  = queryString('ENADMINTYPE');
//         if(Plugin_Name=="WIZARD"&&OBJECTID!=0&&ENADMINTYPE!=0)
//         {
//            ShowHideLoading(true);
//            var Arg=OBJECTID+";"+ENADMINTYPE;
//            CallServer(Arg,'ZoomToMBR')
//         }
//    }
    
function ActivatePlugin_queryString(pluginName)
    {
        ShowHideLoading(true);
        TogglePanelDock(true);
        //
        var itemNo = pluginName;
//        for(loop = 0 ; loop < pluginMenuItems.length ; loop++)
//        {
//            if(pluginMenuItems[loop] == pluginName)
//            {
//                itemNo = loop;
//                break;
//            }
//        }
        if(itemNo != -1)
            LoadInitialJS(itemNo);
        else
            alert("يوجد بيانات غير صحيحة فى عنوان الرابط، يرجى التأكد منها");
    }
    
//functions for Logging in or out from the system and changing modules to datacollection or celltowers or anything
//function showModalPopupViaClient(ev)
//    {
//        ev.preventDefault();
//        var modalPopupBehavior = $find('programmaticModalPopupBehavior');
//        modalPopupBehavior.show();
//    }

function SignIn() 
    {
        document.getElementById("GuestName").style.display="block";
        document.getElementById("GuestName").innerHTML="مرحبا"+" "+userName;
        document.getElementById("menuItem7").innerHTML="خروج";
        var b = document.getElementById("menuItem7");
        XBrowserAddHandler(b, 'click', SignOut);
        //$addHandler($get("menuItem7"), 'click', SignOut);  
        ShowPluginsByAuthority(userCode);
    }
    
function ShowPluginsByAuthority(Code)
    {
        var Code=userCode.split(',');
        for(var i=0;i<Code.length;i++)
        {
            if(Code[i]=="100433")
            {
                 pluginsShow[4] = true;
                  flag_SignedIn  = true;
            }
        }
        pluginsShow[5] = true;
        pluginsShow[11] = true;
        LoadPluginMenuItems_update('tabs');
        ShowPlugin(0);
        TogglePanelDock(true);
    }
    
function SignOut()
    {
        flag_SignedIn  = false;
        pluginsShow[4] = false;
        pluginsShow[5] = false;
        pluginsShow[11] = false;
        LoadPluginMenuItems_update('tabs');
        document.getElementById("menuItem7").innerHTML="دخول";
        document.getElementById("GuestName").style.display="none";
        userName="";
        
        var b = document.getElementById("menuItem7");
        XBrowserAddHandler(b, 'click', ActivatePlugin);
    }
//end functions

// function for search button on the default page
function DoSearch()
    {   
        //ShowHideLoading(true);
        TogglePanelDock(true);
        
        if(!firstLoad)
            PluginDestructor();
            
       return ValidateSearchText();
    }
    
function GetWinWidth()
    {
        var sWidth = document.documentElement.clientWidth;
        return sWidth;
    }

function GetWinHeight()
    {
        var sHeight = document.documentElement.clientHeight;
        return sHeight;
    }
        
function validateAdjustMapSize()
    {
        var dHeight = Math.abs(document.documentElement.clientHeight - currHeight);
        var dWidth = Math.abs(document.documentElement.clientWidth - currWidth);
	    if( dHeight > 17 || dWidth > 0)
	    {
		    AdjustMapSize();	
	    }
	    if (dHeight > 17 || currHeight < document.documentElement.clientHeight)
	    currHeight = document.documentElement.clientHeight;
	    if (dWidth > 0 || currWidth < document.documentElement.clientWidth)
	    currWidth = document.documentElement.clientWidth;
    }
    
// function for adjusting element sizes when brower is resized
function AdjustMapSize() 
    {       
        //var webMapAppOV = document.getElementById("tblOV");
        var webMapAppTopBannerHeight = 175; //161, 126, 144, 210
        var webMapAppMapDisplay = document.getElementById("Map_Panel");
        var divLegend = document.getElementById("divLegend");
        var divSR = document.getElementById("plugin_pnlDDSearchResults");
        if (document.getElementById("DivDirections") != null)
            var divDir = document.getElementById("DivDirections");
        //get browser window dimensions 
        var sWidth = GetWinWidth();
        var sHeight = GetWinHeight();
        //calc dimensions needed for map
        var mWidth = sWidth;
        var mHeight = sHeight - webMapAppTopBannerHeight;
        if (document.getElementById("divRightPanel")!=null)
        {
            var webMapAppPanelDisplayCell = document.getElementById("divRightPanel");
            if(webMapAppPanelDisplayCell.style.display == "block")
            mWidth = sWidth - webMapAppPanelDisplayCell.clientWidth ;
        }   
        mWidth = mWidth - 5;
        
        if (mWidth<200) mWidth = 200;
        if (mHeight<200) mHeight = 200;  
        webMapAppMapDisplay.style.width =  mWidth + "px";
        webMapAppMapDisplay.style.height =  mHeight + "px";
        
        webMapAppPanelDisplayCell.style.left =  mWidth + "px";
        webMapAppPanelDisplayCell.style.top =  webMapAppTopBannerHeight + "px";
        
        var webMapLoading = document.getElementById("divLoading");
        webMapLoading.style.top =  parseInt(mHeight.toString().replace("px",'')) / 2 + "px";
        webMapLoading.style.left =  parseInt(mWidth.toString().replace("px",'')) / 2 + "px";   
        
        if(divLegend != null)
            divLegend.style.height =  (mHeight - 100) + "px";
        
        if(divSR != null)
            divSR.style.height =  (mHeight - 130) + "px";

        if(divDir != null)
        {
            divDir.style.height =  (mHeight - 215) + "px";
        }
        
        return false;
    }

function maximizeBrowser()
    {
        top.window.moveTo(0,0);
        if (document.all)
        {
            top.window.resizeTo(screen.availWidth,screen.availHeight);
        }
        else if (document.layers||document.getElementById)
        {
            if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
            {
                top.window.outerHeight = screen.availHeight;
                top.window.outerWidth = screen.availWidth;
            }
        }
    }
    
function TogglePanelDock(isSearch)
    {
        var panel = document.getElementById("divRightPanel");
        var divPanel = document.getElementById("Map_Panel");
        //var webMapAppOV = document.getElementById("tblOV");
       
        var mapWidth = parseInt(divPanel.style.width.replace("px",""));
        var mapHeight = parseInt(divPanel.style.height.replace("px",""));
        
        if(panel.style.display == 'none')
        {
            var image = document.images["CollapseImage"];
            panel.style.display = "block";
            image.src = "img/expand_right.gif";
            image.alt = "غلق";
        }
        else if(!isSearch)
        {
            var image = document.images["CollapseImage"];
            panel.style.display = "none";
            image.src = "img/collapse_left.gif";
            image.alt = "فتح";
        }
        AdjustMapSize();
    }
    
// Replaces the Datalist background when mouse over
function SwapItemBG(tbl,mode)
    {
        if(mode == "over")
            tbl.style.backgroundColor = "#dbe6ec";
        else
            tbl.style.backgroundColor = "#f2f4f3";
    }

function CheckNum(e)
    {
        //
        //alert(event.srcElement.id);
        //
        var evnt = window.event;
        var carCode ;
        if(evnt == null)
        {
            evnt = e;
            carCode = evnt.which;
        }
        else
            carCode = evnt.keyCode;
            
        
        if ((carCode < 48) || (carCode > 57))
        {
            alert('مسموح بادخال ارقام فقط');
            evnt.cancelBubble = true
            evnt.returnValue = false;
            
            this.value = "am00r";
        }
    }
    
function SelectLocateIcon(imgName,onOff)
    {
        var img = document.getElementById(imgName);
        if(onOff)
            img.src = "img/query_selected.png";
        else
            img.src = "img/query.png";
    }
    
function GetSearchResultPoints()
    {
        CallServer("","SearchResultPoints");
    }
    
function ValidateSearchText()
    {
        var result = true;
        var txt = document.getElementById("txtSearch");
        if((queryString('SearchID') == 0) && (queryString('SearchStr') == 0) && ((txt.value.trim().length < 4) || (txt.value.trim() == "ادخل جملة البحث هنا")))
        {
            alert("جملة البحث يجب ألا تقل عن أربع حروف");
            result = false;
        }
        else if(txt.value.indexOf(';') > -1 || txt.value.indexOf('&') > -1
                || txt.value.indexOf('#') > -1 || txt.value.indexOf('@') > -1 || txt.value.indexOf('*') > -1
                   || txt.value.indexOf('$') > -1 || txt.value.indexOf('%') > -1 || txt.value.indexOf('.') > -1)
       {
            alert("جملة البحث يجب ألا تحتوى على رموز خاصة، مثل  ; , # $...وهكذا");
            result = false;
       }
       
       return result;
    }
         
function postBack(id) 
    {
//        if(BrowserDetect.browser == "Firefox")
//            __doPostBack2(id,'');
//        else
            __doPostBack(id ,'');
     }
     
function __doPostBack2(eventTarget, eventArgument) 
    {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) 
        {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }         
         
function ShowHideOverview(divID,imgID)
    { 
        var panel = document.getElementById(divID);
        var img = document.getElementById(imgID);

        if(panel.style.display == 'none')
        {
            panel.style.display = 'block';
            img.src = "img/collapse.GIF";
        }
        else
        {
            panel.style.display = 'none';
            img.src = "img/expand.GIF";   
        }
    }
        
function ShowHideLoading(flag)
    {
        var panel = document.getElementById("divLoading");
        
        //alert(panel.style.top + " " + panel.style.left);

        if(flag)
            panel.style.display = 'block';
        else
            panel.style.display = 'none';
    }
    
function ShowHideDiv(divID,flag)
    {
        var div = document.getElementById(divID);
        if(div != null)
        {
            if(divID=="divCat940IT")
            {
                div.style.visibility="visible";
                document.getElementById('divCat940ITTitle').style.visibility="visible";
            }
            if(flag != null)
            {
                if(flag)
                    div.style.display = 'block';
                else
                    div.style.display = 'none';
            }
            else
            {
                if(div.style.display=='none')
                    div.style.display = 'block';
                else
                    div.style.display = 'none';       
            }
        }
    }
        
function ShowHideSearchOption()
    {
        if(document.getElementById("divSearchOptions") != null)
        {
            var srDiv = document.getElementById("divSearchOptions");
            var txtDiv = document.getElementById("txtSearch");
            
            if(srDiv.style.display == 'none')
                {
                    srDiv.style.display = 'inline';
                    txtDiv.style.width = 190;
                }
            else
                {
                    srDiv.style.display = 'none';
                    txtDiv.style.width = 312;
                }
        }
    }        
        
function ShowHideQueryPoint(flag)
    { 
        if(!flag)
        {
            ClearGraphicLayer(queryPointLayer);
        }
    }
        
function popUp(URL) 
     {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=150,left = 256,top = 128');");
        
        return "page" + id;
     }
     
     function popUp(URL,wdth,higt) 
     {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=" + wdth + ",height=" + higt + ",left = 256,top = 128');");
        
        return "page" + id;
     }

function ChangeStyle(id,subId)
    {
        var divs = ['divVector','divSat','divMore'];
        var anchors = ['Raster10','Raster06','MP','SD','RL','GeoEyeJul2009','GeoEyeDec2009']
        //Id Process
        var curItem = document.getElementById(id);
        curItem.setAttribute('className',curItem.className.toString().replace('_un',''));
        curItem.setAttribute('class',curItem.className.toString().replace('_un',''));
       
        var item ;
        for(var l = 0 ; l < divs.length ; l++)
        {
            item = document.getElementById(divs[l]);
            if(id != divs[l])
            {
                if(item.className.toString().indexOf('un') == -1 )
                {
                    item.setAttribute('className',item.className.toString() + '_un');
                    item.setAttribute('class',item.className.toString() + '_un');
                }
            }
        }
        
        //subId Process
        if (document.getElementById(subId) != null)
        {
            if (subId !='Vector')
            {
                var curSubItem = document.getElementById(subId);
                curSubItem.setAttribute('className',curSubItem.parentNode.className.toString().replace('_un',''));
                curSubItem.setAttribute('class',curSubItem.parentNode.className.toString().replace('_un',''))
            }
        }
        
        for(var l = 0 ; l < anchors.length ; l++)
        {
            item = document.getElementById(anchors[l]);
            if(subId != anchors[l])
            {
                if(item.className.toString().indexOf('un') == -1 )
                {
                    item.setAttribute('className','');
                    item.setAttribute('class','');
                }
            }
        }
    }
    
////////////////////ShowDivPanel////////////////////
function ShowSearchPanel()
    {
        //TogglePanelDock(true);
        ShowHideDiv('divSR','block');
//        DeletePublicFacilitiesLayer();
//        DeleteGeo940Layer();
    }    
    
function ShowNSPanel()
    {
        //TogglePanelDock(true);
        ShowHideDiv('divNS','block');
//        DeletePublicFacilitiesLayer();
//        DeleteGeo940Layer();
    }
    
function ShowLGPanel()
    {
        //TogglePanelDock(true);
        ShowHideDiv('divLG','block');   
        nudgeFirefox();
    }
function ShowGeo940Panel()    
    {
        //TogglePanelDock(true);
        ShowHideDiv('Div940','block');
        LoadModules('Geo940');
       // DeletePublicFacilitiesLayer();
    }
    
function ShowLQPPanel()
    {
        //TogglePanelDock(true);
        ShowHideDiv('divLocateQueryPoint','block');
    //        DeletePublicFacilitiesLayer();
    //        DeleteGeo940Layer();
    }
    
/////////////  Search By Query String  ////////////////////
function SearchByQueryString()
{
//    var searchStr = queryString('SearchStr');
//    var searchTable = queryString('SearchTable');
//    if(searchTable == 0)
//        searchTable = '%';
//    
//    CallServer(searchStr + ";" + searchTable,"SearchByQueryString");
//    
    if(queryString("SearchID") == 0)
    {
        var btn = document.getElementById("btnSearchBy_QS");
        btn.click();
    }
    else
    {
        if(queryString('SearchTable') != 0)
        {
            var id = queryString('SearchID');
            var type = queryString('SearchTable');
            var pars = id + ';' + type;
            
            CallServer(pars,'ZoomToMBR');
        }
    }
}
///////////////////////////////////////////////////////////

// function to load JS file
function LoadJavaScriptFile(url, onload, onfail, loadCheck) 
     {
          var script = document.createElement('script');
          script.defer = false;
          script.type = "text/javascript";
          script.id = url;
          script.src = url;
          script.onload = onload;
          script.onerror = onfail;
          script.loadCheck = loadCheck;
    //      if (/MSIE/.test(navigator.userAgent)) {
    //        script.onreadystatechange = this.checkReadyState;
    //      }
          document.getElementsByTagName('head')[0].appendChild(script);
    }

function mapdetails(f)
    {
        if (f.checked) 
        {
            alert(f.name + " is checked");
        }
        else
        {
            alert(f.name + " is unchecked");
        }

    }

function setEDigHTML(response) 
    {
        var edigValue = response.split(',');
        
        if (edigValue.length <=1)
        {
            document.getElementById('nodeList').innerHTML = edigValue[0];
        }
        else
        {   
            document.getElementById('nodeList').innerHTML = "";
            document.getElementById('edigFI').style.display = 'block';
            
            for ( l = 0 ; l < edigValue.length ; l++)
            {
                var j= l+1;
                document.getElementById('Td'+j).innerHTML = edigValue[l];
            }
        }
        SelectLocateIcon('imgQueryPoint',false)
    }

function PrintMap()
    {
        window.open('print.aspx' + document.location.hash);
    }

//*********************Query String Functions**************************//
function PageQuery(q) 
    {
        try
        {
            if(q.length > 1) this.q = q.substring(1, q.length);
            else this.q = null;
            this.keyValuePairs = new Array();
            if(q) 
            {
                for(var i=0; i < this.q.split("&").length; i++) 
                {
                    this.keyValuePairs[i] = this.q.split("&")[i];
                }
            }
            this.getKeyValuePairs = function() 
            { 
                return this.keyValuePairs; 
            }
            this.getValue = function(s) 
            {
                for(var j=0; j < this.keyValuePairs.length; j++) 
                {
                    if(this.keyValuePairs[j].split("=")[0] == s)
                    return this.keyValuePairs[j].split("=")[1];
                }
                return false;
            }
            this.getParameters = function() 
            {
                var a = new Array(this.getLength());
                for(var j=0; j < this.keyValuePairs.length; j++) 
                {
                    a[j] = this.keyValuePairs[j].split("=")[0];
                }
                return a;
            }
            this.getLength = function() 
            { 
                return this.keyValuePairs.length; 
            }
        }
        catch(e){}
    }
    
function queryString(key)
    {
        var page = new PageQuery(window.location.search); 
        if (unescape(page.getValue(key))== "")
        {
            return 0; 
        }
        else if (unescape(page.getValue(key))== 'false')
        {
            return 0; 
        }
        else
        {
            return unescape(page.getValue(key));
        }
    }
    
function GetHashValue(key)
    {
        var page = new PageQuery(window.location.hash); 
        if (unescape(page.getValue(key))== "")
        {
            return 0; 
        }
        else if (unescape(page.getValue(key))== 'false')
        {
            return 0; 
        }
        else
        {
            return unescape(page.getValue(key));
        }
    }
    
function displayItem(key)
    {
        if(queryString(key)=='false') 
        {
            //document.write("you didn't enter a ?name=value querystring item.");
            alert("you didn't enter a ?name=value querystring item.");
        }
        else
        {
            document.write(queryString(key));
        }
    }
//*********************End of Query String Functions**************************//

//*********************javascript Cookie Functions****************************//
function createCookie(name,value,Minutes) 
    {
	    if (Minutes) {
		    var date = new Date();
		    date.setTime(date.getTime()+(Minutes*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
    }
  
function ReadCookie(n)
    {
        var cookiecontent = new String();
        if(document.cookie.length > 0) {
	    var cookiename = n+ '=';
	    var cookiebegin = document.cookie.indexOf(cookiename);
	    var cookieend = 0;
	    if(cookiebegin > -1) {
		    cookiebegin += cookiename.length;
		    cookieend = document.cookie.indexOf(";",cookiebegin);
		    if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		    cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		    }
	    }
        return unescape(cookiecontent);
    } 
    
function delete_cookie ( cookie_name )
    {
//      var cookie_date = new Date ( );  // current date & time
//      cookie_date.setTime ( cookie_date.getTime() - 1 );
      var cookie_date = new Date ( 2003, 01, 15 );
      document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
    }
//    function ClearCookie()
//    {
////        var mydate = new Date();
////        mydate.setTime(mydate.getTime() - 1);
////        document.cookie = "Cookie=; expires=" + mydate.toGMTString(); 
//document.cookies = "";
//    }

//*********************end of cookie  Functions****************************//

//********************* Popup Control ****************************//
// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

/*********************End of Popup Control*********************/