﻿// Functions to maintain scroll position of a div
function SetDivPosition(element)
{
    var intY = document.getElementById(element).scrollTop;
    var date = new Date();
    date.setTime(date.getTime()+(1*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    document.cookie = "cookie_"+ element + "="+intY+expires+"; path=/";
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    
    for(var i=0;i < ca.length;i++) 
    {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }

    return null;
}

function getBrowserHeight() {
    var intH = 0;
    var intW = 0;
   
    if(typeof window.innerWidth  == 'number' ) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        intH = document.documentElement.clientHeight;
        intW = document.documentElement.clientWidth;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }

    return { width: parseInt(intW), height: parseInt(intH) };
}  

function showLayer(popid, width, height, contentid, posx, posy) 
{
    popupid = popid;
    storex = posx;
    storey = posy;
    var blackout = document.getElementById("blackout");
    var popup = document.getElementById(popid);
    var content = document.getElementById(contentid);
    var bws = getBrowserHeight();
    blackout.style.width = bws.width + "px";
    blackout.style.height = bws.height + "px";
    blackout.style.display = "block"; 
    popup.style.display = "block";
    popup.style.width = width + "px";
    popup.style.height = height + 10 + "px";
    content.style.width = width + "px";
    content.style.height = height + "px";

    if (document.getElementById(posx).value != "")
    {
        popup.style.left = document.getElementById(posx).value + "px";;
    }

    if (document.getElementById(posy).value != "")
    {
        popup.style.top = document.getElementById(posy).value + "px";;
    }

    blackout = null;
    popup = null;             
    content = null;
    
    //window.onscroll = resizeBlackout; 
    //window.onresize = resizeBlackout;    
    document.onmousedown=selectmouse;
    document.onmouseup=new Function("isdrag=false");
}

function resizeBlackout() 
{
    //var blackout = document.getElementById("blackout");
    //var bws = getBrowserHeight();
    //blackout.style.width = bws.width + "px";
    //blackout.style.height = bws.height + "px";
}

function hideLayer(conid) {
    var blackout = document.getElementById("blackout");
    var popup = document.getElementById(conid);
    blackout.style.display = "none"; 
    popup.style.display = "none";
    popup.style.width = "0px";
    popup.style.height = "0px";
    blackout = null;
    popup = null; 
}

var popupid;
var storex;
var storey;
var ie = document.all;
var nn6 = document.getElementById &&! document.all;
var isdrag = false;
var x, y;
var dobj;

function movemouse(e) 
{
    if (isdrag) 
    {
        document.getElementById(storex).value = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
        document.getElementById(storey).value = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
        dobj.style.left = document.getElementById(storex).value + "px";
        dobj.style.top = document.getElementById(storey).value + "px";
        return false;
    }
}

function selectmouse(e) 
{
    var fobj = nn6 ? e.target : event.srcElement;
    var topelement = nn6 ? "HTML" : "BODY";

    while (fobj.tagName != topelement && fobj.className != "dragme") 
    {
        fobj = nn6 ? fobj.parentNode : fobj.parentElement;
    }

    if (fobj.className=="dragme") 
    {
        isdrag = true;
        dobj = document.getElementById(popupid);
        tx = parseInt(dobj.style.left+0);
        ty = parseInt(dobj.style.top+0);
        x = nn6 ? e.clientX : event.clientX;
        y = nn6 ? e.clientY : event.clientY;
        document.onmousemove=movemouse;
        return false;
    }
}