﻿var sSiteBaseUrl = "http://www.genxpros.net/";
var sSecureSiteBaseUrl = "http://www.genxpros.net/";
var sSiteRoot = "/";
var sDefaultStatus = "GenXPros.net - Expert Web Design and Development.";
var sSearchModeControl = "";
var sSearchActionControl = "";
var sSearchTextBox = "";
var sSearchText = "Enter Search Terms";
var oActiveElement = null;
var iEnterKey = 13;
var iSecond = 1000;
var iMinute = 60 * iSecond;
var radioLists = new Array();
var iProgressID = 0;
var iProgressCount = 0;

function RadioList()
{
    var ID;
    var Radios = new Array();
}

function pageInit(sBodyId, sBodyClass, sFloatMarginId, sSearchModeControlId, sSearchActionControlId, sSearchTextBoxId)
{
    //-- show screen for browsers with javascript enabled --//
    var oBody = document.getElementById(sBodyId);
    oBody.className = sBodyClass;
    oBody.style.visibility = 'visible';
    
    //-- set float margin --//
    var oFloatMargin = document.getElementById(sFloatMarginId);
    oFloatMargin.src = sSiteRoot + "Images/FloatMargin_R1024.gif";    

    if (window.screen.width <= 800)
    {
        oFloatMargin.src = sSiteRoot + "Images/FloatMargin_R800.gif";    
    }
    
    //-- show search controls --//
    sSearchModeControl = sSearchModeControlId;
    sSearchActionControl = sSearchActionControlId;
    sSearchTextBox = sSearchTextBoxId;
}

function bodyKeyPress(e)
{
    //-- quick search? --//
    if (oActiveElement != null)
    {
        if (oActiveElement.id == 'txtSearch')
        {
            if (e.keyCode == iEnterKey)
            {
                window.document.aspnetForm.onsubmit = cancelSubmit;
                quickSearch();
            }
        }
    }
}

function clickControl(sControl)
{
    var oControl = window.document.getElementById(sControl);
    oControl.click();
}

function clientBlur(sControl, dDelay)
{
    dDelay = dDelay * iSecond;
    
    if (dDelay == 0)
    {
        oControl = window.document.getElementById(sControl);
        oControl.focus();
    }
    else
    {
        window.setTimeout("clientBlur('" + sControl + "', 0)", dDelay);
    }
}

function setActiveElement(sControl, iActive)
{
    oActiveElement = null;
    if (iActive == 1)
    {
        oActiveElement = window.document.getElementById(sControl);
    }
}

function resetRadioList(sRadioListID)
{
    var oSettings = new RadioList();
    var bFound = false;
    
    oSettings.ID = sRadioListID;
    oSettings.Radios = new Array();
    
    //-- list exist? --//
    for (var i = 0; i < radioLists.length; i++)
    {
        if (radioLists[i].ID == sRadioListID)
        {
            radioLists[i] = oSettings;
            bFound = true;
        }
    }

    if (!(bFound))
    {
        radioLists.push(oSettings);
    }
}

function addRadio(sRadioListID, sRadioID, iItemIndex)
{
    //-- reset list? --//
    if (iItemIndex == 0)
    {
        resetRadioList(sRadioListID);
    }

    //-- add radio --//
    for (var i = 0; i < radioLists.length; i++)
    {
        if (radioLists[i].ID == sRadioListID)
        {
            radioLists[i].Radios.push(sRadioID);
        }
    }
}

function setRadio(sRadioListID, sRadioID, iSelectedID, sHiddenID)
{
    var oSettings;
    var oHidden = window.document.getElementById(sHiddenID);

    //-- find list --//
    for (var i = 0; i < radioLists.length; i++)
    {
        if (radioLists[i].ID == sRadioListID)
        {
            oSettings = radioLists[i];
        }
    }
    
    //-- clear all radios --//    
    if (oSettings != null)
    {
        for (var j = 0; j < oSettings.Radios.length; j++)
        {
            oRadio = window.document.getElementById(oSettings.Radios[j]);
            oRadio.checked = false;
        }
    }
    
    //-- set selected radio --//
    oRadio = window.document.getElementById(sRadioID);
    oRadio.checked = true;
    
    //-- set hidden element --//
    oHidden.value = iSelectedID;
}

function quickSearch()
{
    var oSearchMode = window.document.getElementById(sSearchModeControl);
    var oSearchAction = window.document.getElementById(sSearchActionControl);
    var oSearchText = window.document.getElementById(sSearchTextBox);
    
    if (oSearchText.value != sSearchText)
    {
        window.location.href = sSiteRoot + 'search.aspx?mode=' + oSearchMode.value + '&do=' + oSearchAction.value + '&keyword=' + oSearchText.value;
    }
}

function quickSearchClick()
{
    var oSearchText = window.document.getElementById(sSearchTextBox);
    if (oSearchText.value == sSearchText)
    {
        oSearchText.value = "";
    }
}

function cancelSubmit()
{
    return false;
}

function mailingListJoinClick(oJoinText)
{
    if (oJoinText.value == "Enter Email Address")
    {
        oJoinText.value = "";
    }
}

function navigateTo(sUrl, bSecure, bNewWindow)
{
    var sBaseUrl = sSiteBaseUrl;
    
    if ((bSecure != null) && bSecure)
    {
        sBaseUrl = sSecureSiteBaseUrl;
    }

    sUrl = sBaseUrl + sUrl;

    if (bNewWindow)
    {
        window.open(sUrl);
    }
    else
    {
        window.location.href = sUrl;
    }
}

function openPopup(sPopup, sClass, sFocus)
{
    var oPopup = window.document.getElementById(sPopup);
    var oFocus = window.document.getElementById(sFocus);
    
    oPopup.className = sClass;
    if (oFocus != null)
    {
        oFocus.focus();
    }
}

function closePopup(sPopup, sFocus)
{
    var oPopup = window.document.getElementById(sPopup);
    var oFocus = window.document.getElementById(sFocus);
    
    oPopup.className = 'clsHidden';
    if (oFocus != null)
    {
        try
        {
            //-- rich textbox may throw errors when setting focus in some browsers --//
            oFocus.focus();
        }
        catch (oError) 
        {
        }
    }
    clearProgress();
}

function centerCoords(iHeight, iWidth)
{
    var oCoords = new Array();
    var iTop = ((window.screen.height - iHeight) / 2) - 40;
    var iLeft = ((window.screen.width - iWidth) / 2) - 10;

    oCoords.push(iTop);
    oCoords.push(iLeft);
    return oCoords;
}

function printWindow(dDelay, bClose)
{
    if (dDelay == null)
    {
        dDelay = 0;
    }
    else
    {
        dDelay = dDelay * iSecond;
    }
    
    if (bClose == null)
    {
        bClose = false;
    }
    
    window.setTimeout('systemPrint(' + bClose + ')', dDelay);
}

function systemPrint(bClose)
{
    window.print();
    
    if (bClose)
    {
        closeWindow(1);
    }
}
        
function closeWindow(dDelay)
{
    if (dDelay == null)
    {
        dDelay = 0;
    }
    else
    {
        dDelay = dDelay * iSecond;
    }

    window.setTimeout('systemClose()', dDelay);
}

function systemClose()
{
    window.close();
}

function printInvoice(sOrderID)
{
    var iHeight = 600;
    var iWidth = 600;
    var oCoords = centerCoords(iHeight, iWidth);
    
    window.open(sSecureSiteBaseUrl + 'merchant/print-invoice.aspx?id=' + sOrderID, '_blank', 'height=' + iHeight + ', width=' + iWidth + ', top=' + oCoords[0].toString() + ', left=' + oCoords[1].toString() + ', resizable=yes, scrollbars=yes');
    window.focus();        
}

function swapText(sSource, sDestination)
{
    var oSource = window.document.getElementById(sSource);
    var oDestination = window.document.getElementById(sDestination);
    
    oDestination.value = oSource.innerHTML;
}

function setStatus(sContext)
{
    var sId = 'ctl00_ctl00_hldMaster_hldContent_hdnStatus';
    var oStatus = window.document.getElementById(sId);
    
    //-- join mailing list status update? --//
    if (sContext == 'MAILING_LIST')
    {
        //-- screens with navigation --//
        sId = 'ctl00_ctl00_hdnStatus';
        oStatus = window.document.getElementById(sId);
        
        //-- screens without navigation? --//
        if (oStatus == null)
        {
            sId = 'ctl00_hdnStatus';
            oStatus = window.document.getElementById(sId);
        }
    }
    
    //-- order detail form status update? --//
    if (sContext == 'ORDER_DETAIL')
    {
        sId = 'ctl00_ctl00_hldMaster_hldContent_OrderDetailForm_hdnStatus';
        oStatus = window.document.getElementById(sId);
    }
    
    //-- status element exist? --//
    if (oStatus != null)
    {
        //-- yes, update status --//
        window.status = oStatus.value;
    }

    //-- reset progress indicators --//
    window.clearInterval(iProgressID);
    iProgressCount = 0;
}

function updateProgress(sMessage, iMax)
{
    //-- update progress --//
    window.status = window.status + '.';
    
    //-- max updates reached? --//
    iProgressCount = iProgressCount + 1;
    if (iProgressCount > iMax)
    {
        clearProgress();
    }
}
function showProgress(sMessage, iInterval, iMax)
{
    //-- set message --//
    if (sMessage == null)
    {
        sMessage = 'Processing Request';
    }
    
    //-- set update interval --//
    if (iInterval == null)
    {
        iInterval = iSecond;
    }
    else
    {
        iInterval = iInterval * iSecond;
    }
    
    //-- set max updates --//
    if (iMax == null)
    {
        iMax = 30; //-- allow one minute for process to complete --//
    }
    
    //-- clear any previous indicators and set initial message --//
    window.clearInterval(iProgressID);
    window.status = sMessage;
    
    //-- update progress indicator --//
    iProgressID = window.setInterval("updateProgress('" + sMessage + "', " + iMax + ")", iInterval);
}

function clearProgress()
{
    window.clearInterval(iProgressID);
    window.status = '';
    iProgressCount = 0;
}

function changeOpacity(iOpacity, sId)
{
    var oStyle = document.getElementById(sId).style;

    oStyle.opacity = (iOpacity / 100);
    oStyle.MozOpacity = (iOpacity / 100);
    oStyle.KhtmlOpacity = (iOpacity / 100);
    oStyle.filter = "alpha(opacity=" + iOpacity + ")"; 
    
    try
    { 
        oStyle.removeAttribute("filter"); 
    } 
    catch (oError) 
    {
    }
}

function toggleShow(sId)
{
    var oControl = document.getElementById(sId);
    
    if (oControl.className == 'clsHide')
    {
        oControl.className = 'clsShow';
    }
    else
    {
        oControl.className = 'clsHide';
    }
}
