//window.onload = function () {
//    //parent.parent.header.document.getElementById('img1').style.display='none'; 
//}

var menuskin = "skin1"; // skin0, or skin1
var display_url = 0; // Show URLs in status bar?

function tempContextMenu() {
    return false;
}

function highlightie5() {
    if (event.srcElement.className == "menuitems") {
        event.srcElement.style.backgroundColor = "highlight";
        event.srcElement.style.color = "white";
        if (display_url)
            window.status = event.srcElement.url;
    }
}
function lowlightie5() {
    if (event.srcElement.className == "menuitems") {
        event.srcElement.style.backgroundColor = "";
        event.srcElement.style.color = "black";
        window.status = "";
    }
}
function jumptoie5() {
    if (event.srcElement.className == "menuitems") {
        if (event.srcElement.getAttribute("target") != null)
            window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
        else
            window.location = event.srcElement.url;
    }
}

function contextMenuShowHide(state, pageIndex) {//ie5menu.className = menuskin;
    if (document.all && window.print) {
        if (state) {
            //disable right-click menu
            document.oncontextmenu = tempContextMenu;
            document.body.onclick = tempContextMenu;
        }
        else {
            document.oncontextmenu = ""; //reenable right-click menu
            //hide all visible panels
            document.body.onclick = function () {
                deselectAll(pageIndex);
            }
        }
    }
}

function contextMenuShowHideSpecific(e, row, panelID, datagridID, pagingIndex, myControlID) {
    if (e.button == 2)//rightclick
    {
        if (document.all && window.print) {
            //if(state)
            //{
            //disable right-click menu
            //ie5menu.className = menuskin;
            document.oncontextmenu = tempContextMenu;
            document.body.onclick = tempContextMenu;
            // }
            //else
            //{
            //document.oncontextmenu ="";
            //}
        }
        //make the panel for the current row visible and hide the rest
        select_deselectAll(row, panelID, datagridID, pagingIndex, myControlID);
    }
    else if (e.button == 1)//on left click
    {
        //    document.getElementById('ctl00_cpGridArea_lnkDisplay').click();
        //var myControl = document.getElementById(myControlID);
        //myControl.click();
    }

}
//window.onload = function() { temp = true; }
//do
//{
//    foo();
//    //parent.parent.header.document.getElementById('img1').style.display='';
//}
//while (!window.parent.document.readyState)

//function foo()
//{

//    if(window.parent.document.readyState )
//    {
//    parent.parent.header.document.getElementById('img1').style.display='none';
//    }
//    else
//    {
//    parent.parent.header.document.getElementById('img1').style.display='';
//    }
//}

//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp() {
    //Creating object of XMLHTTP in IE
    try {
        XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttp = null;
        }
    }
    //Creating object of XMLHTTP in Mozilla and Safari 
    if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
        XmlHttp = new XMLHttpRequest();
    }
}



//Called when response comes back from server
function HandleResponse() {
    // To make sure receiving response data from server is completed
    if (XmlHttp.readyState == 4) {
        // To make sure valid response is received from the server, 200 means response received is OK
        if (XmlHttp.status == 200) {

        }
        else {
            //alert("There was a problem retrieving data from the server." );
        }
    }
}

function deselectAll(pagingIndex) {

    for (i = 2; i < pagingIndex + 3; i++) {
        if (i < 10) {
            var myPnlAll = document.getElementById(myGrid + '_ctl0' + i + '_gridPopup');
        }
        else {
            var myPnlAll = document.getElementById(myGrid + '_ctl' + i + '_gridPopup');
        }

        if (myPnlAll != null) {
            if (myPnlAll.style.display != "none") {
                // myPnlAll.style.top = myPnlAll.offsetTop-10; 
                if (therow != null) {
                    //therow.style.color="#000000";
                }
            }
            myPnlAll.style.display = "none";
            //myrow.style.color="#000000";
        }
    }
}

var therow;
var isOn;

// position of the tooltip relative to the mouse in pixel //
var offsetx = 12;
var offsety = -10;
var myGrid;
function select_deselectAll(row, panelID, datagridID, pagingIndex, myControlID) {
    myGrid = datagridID;
    //	var link1 = document.getElementById(lbtn1);
    //    var link2 = document.getElementById(lbtn2);
    var pnl = document.getElementById(panelID);
    var myrow = document.getElementById(row);
    var myControl = document.getElementById(myControlID);


    for (i = 2; i < pagingIndex + 3; i++) {
        if (i < 10) {
            var myPnlAll = document.getElementById(datagridID + '_ctl0' + i + '_gridPopup');
        }
        else {
            var myPnlAll = document.getElementById(datagridID + '_ctl' + i + '_gridPopup');
        }

        //if last page contains less records than pageIndex size the rest of the records ID
        //will return null. This causes a javascript error so we do not do anything if our
        //object returns null.
        if (myPnlAll != null) {
            myPnlAllRow = myPnlAll.parentElement.parentElement;

            //		     myPnlAllRow.style.backgroundColor = "#FFFFFF";
            //		     myPnlAllRow.style.borderWidth="0px";
            //		     myPnlAllRow.style.borderColor="Transparent";
            //		     myPnlAllRow.style.borderBottomWidth="1px";
            //            myPnlAllRow.style.borderBottomColor="#000000";

            //		    myPnlAllRow.style.backgroundColor = "#FFFFFF";
            //            myPnlAllRow.style.borderColor="#000000";
            myPnlAll.style.display = "none";
        }
    }

    //make current panel visible
    pnl.style.display = "block";

    //findPos(myrow);
    findPos(myControl);
    pnl.style.top = curtop + myControl.offsetHeight;
    pnl.style.left = curleft; //+myControl.offsetWidth; 

    //row.style.backgroundImage = "url(../images/td_mouseover.gif)";
    //    myrow.style.backgroundColor = "#CCCCCC";
    //    myrow.style.borderColor="#FFFFFF";
    //    if(link1 != null)
    //        link1.style.display = "block";
    //    if(link2 != null)
    //        link2.style.display = "block";
    //pnl.style.backgroundImage = "url(../images/td_mouseover_inverted.gif)";
    //pnl.style.backgroundColor = "#DCDCDC";
    //pnl.style.top = pnl.offsetTop+10; 
    // myrow.style.color="red";
    therow = myrow;

    //     document.body.style.cursor = 'hand';

    //change the global variable to let the system know that we are on a row
    isOn = true;
}


var curleft = curtop = 0;
function findPos(obj) {
    curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    //return [curleft,curtop];
}

function ShowPopup(gridviewRow) {
    var row = document.getElementById(gridviewRow);
    row.style.backgroundColor = "#DCDCDC";
    document.body.style.cursor = 'hand';

}

function HidePopup(gridviewRow) {
    var row = document.getElementById(gridviewRow);
    row.style.backgroundColor = "#FFFFFF";
    document.body.style.cursor = 'default';
}


// Shows DIV popup commands for gridview
var offsetX = 0;
var offsetY = 5;
var opacity = 100;
var myPnl;

function ShowPopup2(lbtn1, lbtn2, panel, gridviewRow) {
    var link1 = document.getElementById(lbtn1);
    var link2 = document.getElementById(lbtn2);
    var pnl = document.getElementById(panel);
    var row = document.getElementById(gridviewRow);
    pnl.style.display = "block";

    //row.style.backgroundImage = "url(../images/td_mouseover.gif)";
    //    row.style.backgroundColor = "#DCDCDC";
    if (link1 != null)
        link1.style.display = "block";
    if (link2 != null)
        link2.style.display = "block";
    //pnl.style.backgroundImage = "url(../images/td_mouseover_inverted.gif)";
    // pnl.style.backgroundColor = "#DCDCDC";
    myPnl = panel;
    isOn = true;

}

function temp(lbtn1, lbtn2, panel, gridviewRow) {
    if (isOn == false) {
        try {
            var link1 = document.getElementById(lbtn1);
            var link2 = document.getElementById(lbtn2);

            var pnl = document.getElementById(panel);
            var row = document.getElementById(gridviewRow);
            //row.style.backgroundImage="url(../images/spacer.gif)";
            //         row.style.backgroundColor = "#FFFFFF";
            //	     row.style.borderWidth="0px";
            //	     row.style.borderColor="Transparent";
            //	     row.style.borderBottomWidth="1px";
            //         row.style.borderBottomColor="#000000";
            pnl.style.display = "none";
            if (link1 != null)
                link1.style.display = "none";
            if (link2 != null)
                link2.style.display = "none";

            //        document.body.style.cursor = 'default';
        }
        catch (e) {
            //in case we press paging too fast and there is not the same index of row to hide the panel
            //in the second(last) page
        }
    }
}

//Hides DIV popup commands for gridview
function HidePopup2(lbtn1, lbtn2, panel, gridviewRow) {
    isOn = false;
    setTimeout("temp('" + lbtn1 + "','" + lbtn2 + "','" + panel + "','" + gridviewRow + "')", 500);
}






// position of the tooltip relative to the mouse in pixel //
//var offsetx = 12;
//var offsety =  -10;

//function newelement(newid)
//{ 
//    if(document.createElement)
//    { 
//        var el = document.createElement('div'); 
//        el.id = newid;     
//        with(el.style)
//        { 
//            display = 'none';
//            position = 'absolute';
//        } 
//        el.innerHTML = '&nbsp;'; 
//        document.body.appendChild(el); 
//    } 
//} 
//var ie5 = (document.getElementById && document.all); 
//var ns6 = (document.getElementById && !document.all); 
//var ua = navigator.userAgent.toLowerCase();
//var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);
//function getmouseposition(e)
//{
//    if(document.getElementById)
//    {
//        var iebody=(document.compatMode && 
//        	document.compatMode != 'BackCompat') ? 
//        		document.documentElement : document.body;
//        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
//        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
//        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
//        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

//        var lixlpixel_tooltip = document.getElementById(myPnl);
//        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
//        lixlpixel_tooltip.style.top = (10) + 'px';
//    }
//}
//function ShowPopup(lbtn1,lbtn2, panel, gridviewRow)
//{
//    myPnl=panel;
//     var link1 = document.getElementById(lbtn1);
//    var link2 = document.getElementById(lbtn2);
//    //if(!document.getElementById(myPnl)) newelement(myPnl);
//    var lixlpixel_tooltip = document.getElementById(myPnl);
//    //lixlpixel_tooltip.innerHTML = tip;
//     if(link1 != null)
//        link1.style.display = "block";
//    if(link2 != null)
//        link2.style.display = "block";
//    lixlpixel_tooltip.style.display = 'block';
//    
//    //getDetails(lixlpixel_tooltip);
////    if(lixlpixel_tooltip.style.display == 'block')
////    {
////    x = event.x + document.body.scrollLeft;
////    y = event.y + document.body.scrollTop;
////    lixlpixel_tooltip.style.left = x + offsetx+'px';
////  lixlpixel_tooltip.style.top = y + offsety+'px';
////  }
////     var iebody=(document.compatMode && 
////        	document.compatMode != 'BackCompat') ? 
////        		document.documentElement : document.body;
////        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
////        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
////        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
////        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

////        var lixlpixel_tooltip = document.getElementById(myPnl);
////        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
////        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
//    //document.onclick = getmouseposition;
//}

//function HidePopup2(lbtn1,lbtn2, panel, gridviewRow)
//{
//    var link1 = document.getElementById(lbtn1);
//    var link2 = document.getElementById(lbtn2);

//    var pnl = document.getElementById(panel);
//    var row= document.getElementById(gridviewRow);
//    //row.style.backgroundImage="url(../images/spacer.gif)";
//     row.style.backgroundColor = "#FFFFFF";
//    pnl.style.display = "none";
//    if(link1 != null)
//        link1.style.display = "none";
//    if(link2 != null)
//        link2.style.display = "none";
//}
//function HidePopup(lbtn1,lbtn2, panel, gridviewRow)
//{
//    document.getElementById(myPnl).style.display = 'none';
//}

//function getDetails(obj){ 
//clickX = window.event.x-obj.offsetLeft; 
//clickY = window.event.y-obj.offsetTop; 
//alert(clickX); 
//alert(clickY); 
//}










//Gets called when baseList combo box selection changes
function ddd() {

    //this is needed to store in the cache a different page for every page call 
    //so that XML files do not get mixed up!
    var CurrentDateTime = document.lastModified;

    // URL to get conditions for a given base
    var requestUrl = '/zeContent/AJAXServerPage.aspx' + "?CurrentDateTime=" + CurrentDateTime;

    CreateXmlHttp();

    // If browser supports XMLHTTPRequest object
    if (XmlHttp) {
        //Setting the event handler for the response
        XmlHttp.onreadystatechange = HandleResponse;

        //Initializes the request object with GET (METHOD of posting), 
        //Request URL and sets the request as synchronous.
        XmlHttp.open("GET", requestUrl, false);

        //Sends the request to server
        XmlHttp.send(null);
    }

}
