﻿

function getMonitorSize(Cwidth, Cheight, ParentWin) {

    var myWidth = 0, myHeight = 0;
    var xOffset = 0, yOffset = 0;
    
    if (typeof (window.innerWidth) == 'number')
    {
        //Non-IE
        if (!ParentWin)
        {
            myWidth = window.innerWidth;
            myHeight = window.innerHeight;
        }
        else
        {
            myWidth = parent.window.innerWidth;
            myHeight = parent.window.innerHeight;
        }
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        if (!ParentWin)
        {
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        }
        else
        {
            myWidth = parent.document.documentElement.clientWidth;
            myHeight = parent.document.documentElement.clientHeight;
        }
    }
    
    var version = parseFloat(navigator.appVersion.split("MSIE")[1]);

    if (version == 7 && !ParentWin) {
        xOffset = +17;
    }
    else if (ParentWin){
        xOffset = +17;
    }
    
    document.getElementById(Cwidth).value = myWidth + xOffset;
    document.getElementById(Cheight).value = myHeight + yOffset;
}

function copyToClpBrd_ORG(StrDivID) {
    var div = document.getElementById(StrDivID);
    div.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
        controlRange = document.body.createControlRange();
        controlRange.addElement(div);
        controlRange.execCommand('Copy');
    }
    div.contentEditable = 'false';
}


//function EnableImg() {
//    var divLoadingImg = document.getElementById('loadingImg');
//    divLoadingImg.style.display = "";
//    var imgCenterY = document.getElementById('ImageButtonMap').offsetHeight / 2;
//    var imgCenterX = document.getElementById('ImageButtonMap').offsetWidth / 2;
//    var divLoadingImgWidth = divLoadingImg.offsetWidth;
//    var divLoadingImgHeight = divLoadingImg.offsetHeight;
//    divLoadingImg.style.left = imgCenterX - (divLoadingImgWidth / 2);
//    divLoadingImg.style.top = imgCenterY - (divLoadingImgHeight/2);
//}


/////////////// FINDING ELEMENTS POSISION //////////
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function getX(obj) {
    return obj.offsetLeft + (obj.offsetParent ? getX(obj.offsetParent) : obj.x ? obj.x : 0);
}
function getY(obj) {
    return (obj.offsetParent ? obj.offsetTop + getY(obj.offsetParent) : obj.y ? obj.y : 0);
}

/////////////////////INFO///////////////////////////////////

function Info(firstX, firstY, lastX, lastY) {
    // in this application the top-left position ImgPositionX,ImgPositionY have values(0,0),because 
    // we user <body rightmargin="0px" leftmargin="0" topmargin="0" bottommargin="0"> in the html
    // if you remove these properties from the body of html the result will be different.
    imgMap = document.getElementById('ImageButtonMap');
    ImgPositionX = findPosX(imgMap);
    ImgPositionY = findPosY(imgMap);
    firstX = firstX - ImgPositionX;
    firstY = firstY - ImgPositionY;
    lastX = lastX - ImgPositionX;
    lastY = lastY - ImgPositionY;
    var linkAdress = 'Info.aspx?firstX=' + firstX + '&firstY=' + firstY + '&lastX=' + lastX + '&lastY=' + lastY;
    //alert('ImgPositionX:'+ImgPositionX+' ImgPositionY:'+ImgPositionY+' firstX:'+firstX+' firstY:'+firstY+' lastX:'+lastX+' lastY:'+lastY);
    parent.window.radopen(linkAdress, "WinInfo");
    return false;
}


function readCoordinateForPan(readX,readY) {
    var komer = ',';
    var punkt = '.';
    imgMap = document.getElementById('ImageButtonMap');
    // in this application the top-left position ImgPositionX,ImgPositionY have values(0,0),because 
    // we user <body rightmargin="0px" leftmargin="0" topmargin="0" bottommargin="0"> in the html
    // if you remove these properties from the body of html the result will be different.
    ImgPositionX = findPosX(imgMap);
    ImgPositionY = findPosY(imgMap);
    document.getElementById('imgStartPostX').value = ImgPositionX; // For ZOOMBOX
    document.getElementById('imgStartPostY').value = ImgPositionY; // For ZOOMBOX

    xScal = document.getElementById('Hid_ScalX').value.replace(komer, punkt);
    geoXMin = document.getElementById('Hid_GeoXMin').value.replace(komer, punkt);

    yScal = document.getElementById('Hid_ScalY').value.replace(komer, punkt);
    geoYMax = document.getElementById('Hid_GeoYMax').value.replace(komer, punkt);

    parent.document.getElementById('label_CoorX').innerText = Math.round(((readX - ImgPositionX) * xScal) + (geoXMin * 1.0));
    parent.document.getElementById('label_CoorY').innerText = Math.round((geoYMax * 1.0) - ((readY - ImgPositionY) * yScal));
}


/////////////AutoLER And Adress Search///////////////////
function GenerateRandomID(sessionID) {
    randomNr = Math.random();
    return sessionID + '_' + randomNr;
}


/////////////////////EDIT layers items///////////////////////////////////

function FollowLink(x, y) {
    // in this application the top-left position ImgPositionX,ImgPositionY have values(0,0),because 
    // we user <body rightmargin="0px" leftmargin="0" topmargin="0" bottommargin="0"> in the html
    // if you remove these properties from the body of html the result will be different.
    imgMap = document.getElementById('ImageButtonMap');
    ImgPositionX = findPosX(imgMap);
    ImgPositionY = findPosY(imgMap);
    x = x - ImgPositionX;
    y = y - ImgPositionY;
    var linkAdress = 'Follow_Link.aspx?x=' + x + '&y=' + y;
    parent.window.radopen(linkAdress, "WinLoading");
    return false;
}

////////////////////SELECT itmes for WKD/////////////////////////////////
function SelectElements(firstX, firstY, lastX, lastY) {

    // in this application the top-left position ImgPositionX,ImgPositionY have values(0,0),because 
    // we user <body rightmargin="0px" leftmargin="0" topmargin="0" bottommargin="0"> in the html
    // if you remove these properties from the body of html the result will be different.
    imgMap = document.getElementById('ImageButtonMap');
    ImgPositionX = findPosX(imgMap);
    ImgPositionY = findPosY(imgMap);
    firstX = firstX - ImgPositionX;
    firstY = firstY - ImgPositionY;
    lastX = lastX - ImgPositionX;
    lastY = lastY - ImgPositionY;
    var linkAdress = 'Select.aspx?firstX=' + firstX + '&firstY=' + firstY + '&lastX=' + lastX + '&lastY=' + lastY;
    //alert('ImgPositionX:'+ImgPositionX+' ImgPositionY:'+ImgPositionY+' firstX:'+firstX+' firstY:'+firstY+' lastX:'+lastX+' lastY:'+lastY);
    parent.window.radopen(linkAdress, "WinLoading");
    return false;
}
