﻿function SelectProduct(apnum, type, sizedesc, ship, price, imageid, zoneproductid)
{
    var selectAFormat = document.getElementById("selectAFormat");
    selectAFormat.innerHTML = sizedesc;
    var itemNumberText = document.getElementById("itemNumberText");
    itemNumberText.innerHTML = "<b>Price: " + price + "</b><br>Item #: " + apnum + "-" + imageid + "<br>Usually ships in " + ship + "<br>";
    var itemNumber = document.getElementById("itemNumber");
    itemNumber.value = apnum;
    var zoneProductId = document.getElementById("zoneProductId");
    zoneProductId.value = zoneproductid;
    
    document.getElementById("addtocartbtnactive").style.display="block";
    var seeframedbtn = document.getElementById("seeframedbtn");
    var seeframedbtnactive = document.getElementById("seeframedbtnactive");
    if(type.indexOf("Original")==-1)
    {
        seeframedbtn.style.display = "none";
        seeframedbtnactive.style.display = "block";
    }
    else
    {
        seeframedbtn.style.display = "block";
        seeframedbtnactive.style.display = "none";
    }
    
    var PopupDiv = GetDivByName("PopupDivSelectAFormat");
    PopupDiv.style.display = "none";
    PopupDiv.innerHTML = "";
}

function PopupWindow(url, width, height, title)
{
    var newwindow=window.open(url,title,"height="+height+",width="+width);
    if (window.focus) {newwindow.focus()}
}

function showLongDiv(enableLong, longDiv, shortDiv, plusImage, minusImage, morelink)
{
    if(morelink!="0")
    {
        var mlink= document.getElementById(morelink);
        if(mlink==null) return;
    }
    
    if(enableLong)
    {
        var longDivVar = document.getElementById(longDiv);
        longDivVar.style.display="block";
        var shortDivVar = document.getElementById(shortDiv);
        shortDivVar.style.display="none";
        
        var plusImage = document.getElementById(plusImage);
        if(plusImage!=null) plusImage.style.display = 'none';
        var minusImage = document.getElementById(minusImage);
        if(minusImage!=null) minusImage.style.display = 'block';
    }
    else
    {
        var longDivVar = document.getElementById(longDiv);
        longDivVar.style.display="none";
        var shortDivVar = document.getElementById(shortDiv);
        shortDivVar.style.display="block"; 
        
        var plusImage = document.getElementById(plusImage);
        if(plusImage!=null) plusImage.style.display = 'block';
        var minusImage = document.getElementById(minusImage);
        if(minusImage!=null) minusImage.style.display = 'none';       
    }
}

function closeReviewWindow(cls)
{
    var writeReviewDiv = document.getElementById("writeReviewDiv");
    var writeReviewLink = document.getElementById("writeReviewLink");
    if(cls)
    {
        writeReviewDiv.style.display = "none";
        writeReviewLink.style.display = "block";
    }
    else
    {
        writeReviewDiv.style.display = "block";
        writeReviewLink.style.display = "none";
    }
}
 
function ILikeThisArtistWork(artistId)
{
    Stn.WebService.ILikeThisArtistWork(artistId, OnComplete); 
}

function OnComplete(result)
{
    var ilikeitspan = document.getElementById("ilikeitspan");
    ilikeitspan.innerHTML = result;
    ilikeitspan.style.cursor = 'pointer';    
}

var the_timeout;
var xoff, yoff;

function ShowQuoteDiv(display)
{
    var longQuoteDiv = document.getElementById("longQuoteDiv");
    longQuoteDiv.style.display = display;
    longQuoteDiv.style.position = "absolute";
}

function DisplayElement(display, id)
{
    var elm = document.getElementById(id);
    elm.style.display = display;
    elm.style.position = "absolute";
}

function ShowPopup(type, val, xoff, yoff, delay)
{
    this.xoff = xoff + mouseX;
    this.yoff = yoff + mouseY;
    var PopupDiv = GetDivByName("PopupDiv");
    the_timeout = setTimeout("SetupPopup('"+type+"', '"+val+"');", delay);
}

function ShowPopupSelectAFormat(type, val, delay)
{
    the_timeout = setTimeout("SetupPopupSelectAFormat('"+type+"', '"+val+"');", delay);
}

function CancelPopup()
{
    clearTimeout(the_timeout);
}

function ClosePopup(obj)
{
    obj.parentNode.style.display="none";
}

function ClosePopup4(obj)
{
    obj.parentNode.parentNode.parentNode.parentNode.parentNode.style.display="none";
}

function SetupPopupSelectAFormat(type, val)
{
    Stn.WebService.GetPopupHtml(type, val, OnSucceededSelectAFormat, OnFailed);
}

function SetupPopup(type, val)
{
    Stn.WebService.GetPopupHtml(type, val, OnSucceeded, OnFailed);
}

function OnSucceededSelectAFormat(result)
{
    var PopupDiv = GetDivByName("PopupDivSelectAFormat");
    PopupDiv.style.display="block";
    PopupDiv.innerHTML = result;
    document.getElementById("selectAFormat").style.cursor = "pointer";
}

function OnSucceeded(result)
{
    var PopupDiv = GetDivByName("PopupDiv");
    PopupDiv.style.top = yoff + "px";
    PopupDiv.style.left = xoff + "px";
    PopupDiv.style.display="block";
    PopupDiv.style.position = "absolute";
    PopupDiv.innerHTML = result;
    setTimeout("setXYScreenAdjusted(get$('PopupDiv'),"+xoff+","+yoff+",5)",300);
}

function OnFailed(error)
{
    var PopupDiv = GetDivByName("PopupDiv");
    PopupDiv.style.top = yoff + "px";
    PopupDiv.style.left = xoff + "px";
    PopupDiv.style.display="block";
    PopupDiv.style.position = "absolute";
    PopupDiv.style.background="white";
    PopupDiv.className = "error";
    PopupDiv.style.width = "300px";
    PopupDiv.style.padding = "20px";
    PopupDiv.style.border = "solid 1px #dbdbdb";
    PopupDiv.innerHTML = error.get_message();
    
    setTimeout("document.getElementById('PopupDiv').style.display='none'", 5000);
}

function GetDivByName(name)
{
    var PopupDiv = document.getElementById(name);
    if(PopupDiv==null)
    {
        PopupDiv = document.body.insertBefore(document.createElement("div"), document.body.firstChild);
    }
    return PopupDiv;
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var mouseX, mouseY;

function getMouseXY(e) {

    if (IE) {
        mouseX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;;
        mouseY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    } else {
        mouseX = e.pageX;
        mouseY = e.pageY;
    }
    if (mouseX < 0){mouseX = 0}
    if (mouseY < 0){mouseY = 0}

    return true
}