N = navigator.userAgent;
N = N.toLowerCase();
var isGecko  = (navigator.product == "Gecko");
var isIE     = ((N.indexOf("msie") != -1) && (N.indexOf("opera") == -1));
var stopCalk = false;
var IE_DIALOG_OPTIONS = 'dialogWidth:710; dialogHeight:450; center: yes; scroll: Yes; edge: Raised; center: Yes; help: No; resizable: No; status: off;  status: 0;  location: 0;;  status: 0;';
var GO_DIALOG_OPTIONS = 'width=710px, height=500px, dialog=Yes, modal=Yes, popup=Yes, toolbar=No, location=No, menubar=No, personalbar=No, status=No, status=0, scrollbars=Yes, resizable=No';

function editBlur(sender, defValue)
{
    if (trim(sender.value)=='')
       sender.value = defValue;
}
function editFocus(sender, defValue)
{
    if (trim(sender.value)==defValue)
       sender.value = '';
}

function trim(text)
{
    text = text.replace(/^\s+/, '');
    return text.replace(/\s+$/, '');
}

function clearIfZero(sender)
{
    stopCalk = true;
    if (trim(sender.value) == 0)
        sender.value = '';
}
function realFormat(sender)
{
    if (trim(sender.value) == '')
        sender.value = 0;
    sender.value = sender.value.replace(/^\s+/, '');
    sender.value = sender.value.replace(/\s+$/, '');
    sender.value = sender.value.replace(',','.');
}
function float_box()
{    
/* 
    obj = document.getElementById("calc_result_top");
    if (obj)
    {
        obj.style.position = 'absolute';
        if (document.documentElement && document.documentElement.scrollTop)
           obj.style.top = (document.documentElement.scrollTop + 90) + 'px';
        else
        if (document.body)
           obj.style.top = (document.body.scrollTop + 90) + 'px';
        else
           obj.style.top = (window.pageYOffset + 90) + 'px';
        if (isIE)
           obj.style.marginLeft = '145px';
        else
           obj.style.marginLeft = '446px';
        obj.style.zIndex = 100;
    }
    obj2 = document.getElementById("calc_result_top2");
    if (obj2)
    {
        obj2.style.position = 'absolute';
        try
        {
           if (document.documentElement && document.documentElement.scrollTop)
           {
              obj2.style.top  = (410 + document.documentElement.scrollTop ) + 'px';
              //obj2.style.left = (document.documentElement.width - obj2.offsetWidth - 27) + 'px';
           }
           else
           if (document.body)
           {
              obj2.style.top  = (410 + document.body.scrollTop) + 'px';
              obj2.style.left = ((document.body.offsetWidth / 2) + 320 - obj2.offsetWidth) +'px';
           }
           else
           {
              obj2.style.top  = (410 + window.pageYOffset) + 'px';
              obj2.style.left = (document.width /2) + 'px';
              // document.title = obj2.style.top;
           }
        }
        catch(e)
        {
        }
        obj2.style.zIndex = 100;
    }     
 */
}
 
function showWin(pFile, pTop, pWidth, pHeight)
{
    objBody = document.getElementsByTagName("body").item(0);
    shadow  = document.getElementById("shadow");
    iframe  = document.getElementById('iframe_dialog');
    iframeb = document.getElementById('iframe_dialog_bg');

    if (!shadow)
    {
        shadow     = document.createElement('img');
        shadow.id             = 'shadow';
        shadow.src            = '/_img/shadow.png';
        shadow.style.position = 'absolute';
        shadow.style.top      = '0px';
        shadow.style.left     = '0px';
        shadow.style.zIndex   = '90';
        shadow.style.width    = '100%';
        shadow.style.height   = document.body.offsetHeight+'px';
        shadow.onclick     = hideWin;
        if (objBody.firstChild)
            objBody.insertBefore(shadow, objBody.firstChild);
    }
    else
        shadow.style.display = 'block';

    if (!iframeb)
    {
        iframeb = document.createElement('div');
        iframeb.id             = 'iframe_dialog_bg';
        iframeb.style.left     = '100px';
        iframeb.style.top      = '100px';
        iframeb.style.width    = '100px';
        iframeb.style.height   = '100px';
        iframeb.style.zIndex   = '91';
        iframeb.style.position = 'absolute';
        iframeb.style.backgroundColor = 'ButtonFace';
        if (objBody.firstChild)
            objBody.insertBefore(iframeb, objBody.firstChild);
    }
    else
        iframeb.style.display = 'block';

    if (!iframe)
    {
        iframe = document.createElement('iframe');

        iframe.id             = 'iframe_dialog';
        iframe.frameBorder    = '0';
        iframe.scrolling      = 'no';
        iframe.style.left     = '100px';
        iframe.style.top      = '100px';
        iframe.style.width    = '100px';
        iframe.style.height   = '100px';
        iframe.style.zIndex   = '92';
        iframe.style.position = 'absolute';
        if (objBody.firstChild)
            objBody.insertBefore(iframe, objBody.firstChild);
    }
    else
        iframe.style.display = 'block';

    if (!(!iframeb))
    {
        iframeb.style.width  = pWidth+'px';
        iframeb.style.height = pHeight+'px';
        if (typeof document.height == "undefined")
        {
            iframeb.style.left   = ((document.body.offsetWidth / 2)  - (pWidth / 2)) +'px';
            iframeb.style.top    = pTop+'px'; //((document.body.offsetHeight / 2) - (pHeight / 2))+'px';
        }
        else
        {
            iframeb.style.left   = ((window.innerWidth / 2)  - (pWidth / 2)) +'px';
            iframeb.style.top    = pTop+'px'; //((window.innerHeight / 2) - (pHeight / 2))+'px';
        }
    }
    if (!(!iframe))
    {
        iframe.src          = pFile;
        iframe.style.width  = iframeb.style.width;
        iframe.style.height = iframeb.style.height;
        iframe.style.left   = iframeb.style.left;
        iframe.style.top    = iframeb.style.top;
    }
}

function hideWin()
{
    shadow = document.getElementById("shadow");
    if (!(!shadow))
       shadow.style.display = 'none';
    iframeb = document.getElementById("iframe_dialog_bg");
    if (!(!iframeb))
       iframeb.style.display = 'none';
    iframe  = document.getElementById('iframe_dialog');
    if (!(!iframe))
    {
        iframe.src           = 'about:blank';
        iframe.style.display = 'none';
    }
}

function openDialog(_dialog_url)
{
   if (isIE)
      window.open(_dialog_url, 'stv_calculator', GO_DIALOG_OPTIONS);
   else
      window.open(_dialog_url, 'stv_calculator', GO_DIALOG_OPTIONS);
}
