﻿// JScript File
var wnd;
var store;

function open_info_center(postId)
{
    var url = "infocenter_view.aspx?id=" + postId;
    if(postId == null || postId  == '')
    {
        url = 'info_center.aspx';
    }
    if(window.opener)
    {
        window.opener.location.href = url;
        if (window.focus) {window.opener.focus()}
    }
    else
    {
        wnd = window.open(url, 'infocenter', 'width=1000,height=800,menubar=0,resizable=1,scrollbars=1,toolbar=0');
        if (window.focus) {wnd.focus()}
    }
}

function back_to_store()
{
    if(window.opener && window.opener.focus)
    {
        window.opener.focus();
    }
    else if(store)
    {
        store.focus();
    }
    else
    {
        store = window.open('default.aspx', 'beldiamoStore', 'width=1000,height=800,menubar=1,resizable=1,scrollbars=1,toolbar=1');
        if (window.focus) {store.focus()}
    }
    return false;
}

function store_open_product(cat, productId)
{
    if(window.opener && window.opener.focus)
    {
        window.opener.location.href = 'view_product.aspx?c=' + cat + '&p=' + productId;
        window.opener.focus();
    }
    else if(store)
    {
        store.location.href = 'view_product.aspx?c=' + cat + '&p=' + productId;
        if (window.focus) {store.focus()}
    }
    else
    {
        store = window.open('view_product.aspx?c=' + cat + '&p=' + productId, 'beldiamoStore', 'width=1000,height=800,menubar=1,resizable=1,scrollbars=1,toolbar=1');
        if (window.focus) {store.focus()}
    }
    return false;
}

var xstooltip_handler = null;

function xstooltip_reset()
{
    clearTimeout(xstooltip_handler);
    xstooltip_handler = null;
}

function xstooltip_hide_action(id)
{
    document.getElementById(id).style.visibility = 'hidden';
}

function xstooltip_hide(id)
{
    xstooltip_handler = setTimeout("xstooltip_hide_action('"+id+"')", 500);
}


function xstooltip_findPosX(obj) 
{
  var curleft = 0;
  if (obj.offsetParent) 
  {
    while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}


function xstooltip_findPosY(obj) 
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}


function xstooltip_show(tooltipId, parentObj, posX, posY)
{
    it = document.getElementById(tooltipId);
    
//    if ((it.style.top == '' || it.style.top == 0) 
//        && (it.style.left == '' || it.style.left == 0))
//    {
        // need to fixate default size (MSIE problem)
//        it.style.width = it.offsetWidth + 'px';
//        it.style.height = it.offsetHeight + 'px';
        
        img = parentObj;//document.getElementById(parentId); 
    
        // if tooltip is too wide, shift left to be within parent 
        if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
        if (posX < 0 ) posX = 0; 
        
        x = xstooltip_findPosX(img) + posX;
        y = xstooltip_findPosY(img) + posY;
        
        it.style.top = y + 'px';
        it.style.left = x + 'px';
//    }
    
    it.style.visibility = 'visible'; 
}
