﻿
// open a window in a popup
function wopen(url, name, w, h)
{
    var win = window.open(url,
    name, 
    'width=' + w + ', height=' + h + ', ' +
    'location=no, menubar=no, ' +
    'status=yes, toolbar=no, scrollbars=yes, resizable=yes');
    //win.resizeTo(w, h);
    win.focus();
}

function ShowSearchBox()
{
    offset = 0;
    obj = ___getAbsolute(document.getElementById('btnSearch'), false);
    document.getElementById('SearchBox').style.left = obj.left; 
    document.getElementById('SearchBox').style.top = obj.top + obj.height + 5;
    if (document.getElementById('SearchBox').style.display == "none")
        document.getElementById('SearchBox').style.display = "block";
    else
        document.getElementById('SearchBox').style.display = "none";
        
}
 
function SearchButtonGo(formname)
{
    obj = document.getElementById('searchboxtext');
    document.getElementById('SearchBox').style.display = "none";
    
    if (obj != null)
    {
        if (obj.value != "")
        {
            window.location = "http://www.google.co.uk/search?hl=en&q=site%3Awww.qeeps.com+" + obj.value.replace(" ", "+");
        }
    }
}
        
function fixflash(containerID)
{
    var flashContainer = document.getElementById(containerID);
    var flashMovie = document.createElement("div");
    flashMovie.innerHTML = flashContainer.innerHTML.replace(/</g, "<").replace(/>/g, ">");
    flashContainer.parentNode.insertBefore(flashMovie, flashContainer);
    flashContainer.parentNode.removeChild(flashContainer);
    flashMovie.setAttribute("id",containerID);
}

function ___cssUnit(value)
{
    var result      = 0;
    var stringValue = String(value);
    
    if (stringValue != "")
    {
        if (stringValue.indexOf("px") == stringValue.length - 2)
            result = parseInt(stringValue.substr(0, stringValue.indexOf("p")), 10);
        else if (stringValue.indexOf("%") == stringValue.length - 1)
            result = parseInt(stringValue.substr(0, stringValue.indexOf("%")), 10);
        else if (stringValue.indexOf("em") == stringValue.length - 2)
            result = parseInt(stringValue.substr(0, stringValue.indexOf("e")), 10);
        else if (!isNaN(stringValue))
            result = parseInt(stringValue, 10);
    }
    
    return result;  
}

function ___getAbsolute(obj, includeWindowScroll)
{
    var element = obj;
    var top     = 0;
    var left    = 0;
    var width   = 0;
    var height  = 0;  
    
    while (element != null) 
    {
        top  += element.offsetTop;  // - element.scrollTop;
        left += element.offsetLeft; // - element.scrollLeft;
 	    
        element = element.offsetParent;
    }
    
    var bx = 0;
    var by = 0;
    var px = 0;
    var py = 0;
    var mx = 0;
    var my = 0;
    
    if(navigator.mozilla)  
    {    
        //todo: only be tested with IE and Mozilla
        bx = ___cssUnit(obj.currentStyle.borderLeftWidth) + ___cssUnit(obj.currentStyle.borderRightWidth);
        by = ___cssUnit(obj.currentStyle.borderTopWidth)  + ___cssUnit(obj.currentStyle.borderBottomWidth);
    }
             
    px = ___cssUnit(obj.currentStyle.paddingLeft)     + ___cssUnit(obj.currentStyle.paddingRight);
    py = ___cssUnit(obj.currentStyle.paddingTop)      + ___cssUnit(obj.currentStyle.paddingBottom);
    mx = ___cssUnit(obj.currentStyle.marginLeft)      + ___cssUnit(obj.currentStyle.marginRight);
    my = ___cssUnit(obj.currentStyle.marginTop)       + ___cssUnit(obj.currentStyle.marginBottom);
      
    
    width  = obj.offsetWidth - (px + mx + bx);
    height = obj.offsetHeight - (py + my + by); 

    if (includeWindowScroll)
    {
//        top  -= document.body.scrollTop;
//        left -= document.body.scrollLeft;
    }

    return { top: top, left: left, width: width, height: height };
}
