﻿var id;
var imgurl;
var clockTimeoutID;

function popup(ID, IMGURL) {
    id = ID;
    imgurl = IMGURL;
    clearTimeout(clockTimeoutID);
    clockTimeoutID = setTimeout("delayProcess()", 0);

}

function delayProcess() {
    setImgPosition(id);
    document.getElementById('popup' + id).style.display = "block";
    LoadImage(id, imgurl);
}

function setImgPosition(id) {
    var Element = document.getElementById('popup' + id);
    Element.style.top = parseFloat(getImgRealTop(id)) + parseFloat(25) + "px";

    var left = parseFloat(getImgRealLeft(id)) - parseFloat(0);
    if ((parseFloat(left) + parseFloat(document.getElementById('popup' + id).style.width)) > screen.width) {
        Element.style.left = parseFloat(parseFloat(getImgRealLeft(id)) - parseFloat(document.getElementById('popup' + id).style.width)) + "px";
    }
    else {
        Element.style.left = parseFloat(parseFloat(getImgRealLeft(id)) + parseFloat(10)) + "px";
    }

}

function getImgRealTop(el) {

    var yPos = document.getElementById(el).offsetTop;
    var tempEl = document.getElementById(el).offsetParent;

    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}
function getImgRealLeft(el) {
    var xPos = document.getElementById(el).offsetLeft;
    var tempEl = document.getElementById(el).offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}
function LoadImage(id, url) {
    var Element = document.getElementById('regimg' + id);
    Element.src = url;
}
function CloseImgDiv(id) {
    clearTimeout(clockTimeoutID);
    document.getElementById('popup' + id).style.display = "none";
}
function OpenLargeProductImage() {
    var MsgWindow;
    var URL;
    if (arguments.length == 3) {
        URL = "include/LargeProductImage.aspx?path=" + arguments[0];
        MsgWindow = window.open(URL, "MsgWindow", "scrollbars=1,width=" + (arguments[1]) + "px,height=" + (arguments[2]) + "px,menubar=0,resizable=1");
    } else if (arguments.length == 4) {
        URL = arguments[0] + "Search/include/LargeProductImage.aspx?path=" + arguments[1];
        MsgWindow = window.open(URL, "MsgWindow", "scrollbars=1,width=" + (arguments[2]) + "px,height=" + (arguments[3]) + "px,menubar=0,resizable=1");
    } else {
        alert("Invaild number of arguments");
    }
}