var offsetfrommouse=[15,15]; 
var imageHeight = 320;  
var imageWidth = 200;   
    
if (document.getElementById || document.all)
{
    document.write('<div id="PopupId" style="position:absolute; z-index:99;">');
    document.write('</div>');
}

function PopupIdStyle()
{
    if (document.getElementById)
        return document.getElementById("PopupId").style
    else if (document.all)
        return document.all.PopupId.style
}

function PopupId()
{
    if (document.getElementById)
        return document.getElementById("PopupId")
    else if (document.all)
        return document.all.PopupId
}


function GetBody()
{
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function ShowPopup(imagename,description)
{
    document.onmousemove=PopupFollowMouse;

    newHTML = '<div style="padding: 0px; background: transparent; border: 0px; position:absolute; z-index:100;">';
    newHTML += '<img id="PopupImgId" src="' + imagename + '" border="0" alt="' + description + '"></div>';
    
    PopupId().innerHTML = newHTML;
    PopupIdStyle().display="block";
    PopupIdStyle().left="0px";
    PopupIdStyle().right="0px";
    PopupIdStyle().left="-500px";
}

function HidePopup()
{
    PopupIdStyle().display="none";
    PopupIdStyle().innerHTML = " ";
    document.onmousemove="";
    PopupIdStyle().left="-500px";
}

function PopupFollowMouse(e)
{
    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

    var scrOfX = 0, scrOfY = 0;

    if( typeof( window.pageYOffset ) == 'number' ) 
    {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } 
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } 
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
    {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }

    var docWidth=document.all? scrOfX+GetBody().clientWidth : pageXOffset+window.innerWidth-15
    var docHeight=document.all? Math.min(GetBody().scrollHeight, GetBody().clientHeight) : Math.min(window.innerHeight)
    
    if (document.getElementById)
    {
        imageHeight = document.getElementById("PopupImgId").clientHeight;
        imageWidth = document.getElementById("PopupImgId").clientWidth;
    }
    else if (document.all)
    {
        imageHeight = document.all.PopupImgId.clientHeight;
        imageWidth = document.all.PopupImgId.clientWidth;
    }

    
    PopupId().innerHTML = newHTML;

    if (typeof e != "undefined")
    {
        if (docWidth - e.pageX < (imageWidth+20))
            xcoord = e.pageX - xcoord - (imageWidth+20); // Move to the left side of the cursor
        else 
            xcoord += e.pageX;

        if ( (docHeight - e.pageY) < (imageHeight + 20))
            ycoord += e.pageY - Math.max(0,(20 + imageHeight + e.pageY - docHeight - scrOfY));
        else 
            ycoord += e.pageY;

    } 
    else if (typeof window.event != "undefined")
    {
        if (docWidth - event.clientX < (imageWidth+20) )
            xcoord = event.clientX + scrOfX - xcoord - (imageWidth+20); // Move to the left side of the cursor
        else 
            xcoord += scrOfX+event.clientX

        if (docHeight - event.clientY < (imageHeight + 20))
            ycoord += event.clientY + scrOfY - Math.max(0,(20 + imageHeight + event.clientY - docHeight));
        else 
            ycoord += scrOfY + event.clientY;
    }

    if (ycoord < 0) 
        ycoord = -ycoord;

    PopupIdStyle().left=xcoord+"px";
    PopupIdStyle().top=ycoord+"px";

}

function Download(p)
{
    document.getElementById('download_'+p).submit();
}

function Buy(p)
{
    document.getElementById('buy_'+p).submit();
}

