
var popupWindow = '';
var refreshInterval;

function ShowPopup(url)
{
        if (!popupWindow.closed && popupWindow.location)
        {
                popupWindow.location.href = url;
        }
        else
        {
                popupWindow = window.open(url, 'Popup', 'height=675,width=675,scrollbars=1,resizable=1');

                if (!popupWindow.opener)
                {
                    popupWindow.opener = self;
                }
        }

    if (window.location && window.location.search.search(/preval=1/i) != -1 &&
        ( url.search(/edititem.aspx/i) != -1 || url.search(/editgiftmessage.aspx/i) != -1))
    {
        if (window.setInterval)
        {
            refreshInterval = window.setInterval('FireRefreshEvent()', 750);
        }
    }

    if (window.focus)
        {
            popupWindow.focus();
        }

        return false;
}

var newWindow = '';

function OpenWindow(url)
{
    if (!newWindow.closed && newWindow.location)
    {
        newWindow.location.href = url;
    }
    else
    {
        newWindow = window.open(url, 'new_window');

        if (!newWindow.opener)
        {
            newWindow.opener = self;
        }
    }

    if (window.focus)
    {
        newWindow.focus();
    }

    return false;
}

function ClosePopup(thisIsIgnored)
{
    window.close();
}

function FireRefreshEvent()
{
    if (popupWindow == null || popupWindow.closed)
    {
        if (refreshInterval && window.clearInterval)
        {
            window.clearInterval(refreshInterval);
        }

        if (window.location)
        {
            if (window.location.search.search(/preval=1/i) != -1)
            {
                window.location.reload();
            }
        }
    }
}

function ThrowPopup(popUrl, mainUrl)
{
        if (!popupWindow.closed && popupWindow.location)
        {
                popupWindow.location.href = popUrl;
        }
        else
        {
                popupWindow = window.open(popUrl, 'Popup', 'height=675,width=675,scrollbars=1,resizable=1');

                if (!popupWindow.opener)
                {
                    popupWindow.opener = self;
                }
        }

    if (window.self != popupWindow)
    {
            window.location.href = mainUrl;

        if (window.focus)
            {
                popupWindow.focus();
            }
    }

        return false;
}

function SearchOnFocus(search)
{
    if (search.value=='keyword search') {search.value=''}
}
