/*
 *  common.js
 *
 *  General scripting functionality.
 */


// Define mouseover images.
navHomeOn=new Image();
navHomeOn.src="/images/navHome_on.gif";
navHomeOff=new Image();
navHomeOff.src="/images/navHome_off.gif";

navProductsOn=new Image();
navProductsOn.src="/images/navProducts_on.gif";
navProductsOff=new Image();
navProductsOff.src="/images/navProducts_off.gif";

navDesignsOn=new Image();
navDesignsOn.src="/images/navDesigns_on.gif";
navDesignsOff=new Image();
navDesignsOff.src="/images/navDesigns_off.gif";

navAboutOn=new Image();
navAboutOn.src="/images/navAbout_on.gif";
navAboutOff=new Image();
navAboutOff.src="/images/navAbout_off.gif";

btnCloseOn=new Image();
btnCloseOn.src="/images/btnClose_on.gif";
btnCloseOff=new Image();
btnCloseOff.src="/images/btnClose_off.gif";

btnAddToCartOn=new Image();
btnAddToCartOn.src="/images/btnAddToCart_on.gif";
btnAddToCartOff=new Image();
btnAddToCartOff.src="/images/btnAddToCart_off.gif";

btnAddToCartSmallOn=new Image();
btnAddToCartSmallOn.src="/images/btnAddToCartSmall_on.gif";
btnAddToCartSmallOff=new Image();
btnAddToCartSmallOff.src="/images/btnAddToCartSmall_off.gif";

btnAddYourPhotoOn=new Image();
btnAddYourPhotoOn.src="/images/btnAddYourPhoto_on.gif";
btnAddYourPhotoOff=new Image();
btnAddYourPhotoOff.src="/images/btnAddYourPhoto_off.gif";

btnAddYourPhotoSmallOn=new Image();
btnAddYourPhotoSmallOn.src="/images/btnAddYourPhotoSmall_on.gif";
btnAddYourPhotoSmallOff=new Image();
btnAddYourPhotoSmallOff.src="/images/btnAddYourPhotoSmall_off.gif";

btnCreateAccountOn=new Image();
btnCreateAccountOn.src="/images/btnCreateAccount_on.gif";
btnCreateAccountOff=new Image();
btnCreateAccountOff.src="/images/btnCreateAccount_off.gif";

btnLoginOn=new Image();
btnLoginOn.src="/images/btnLogin_on.gif";
btnLoginOff=new Image();
btnLoginOff.src="/images/btnLogin_off.gif";

btnResetPasswordOn=new Image();
btnResetPasswordOn.src="/images/btnResetPassword_on.gif";
btnResetPasswordOff=new Image();
btnResetPasswordOff.src="/images/btnResetPassword_off.gif";

btnChangePasswordOn=new Image();
btnChangePasswordOn.src="/images/btnChangePassword_on.gif";
btnChangePasswordOff=new Image();
btnChangePasswordOff.src="/images/btnChangePassword_off.gif";

btnContinueOn=new Image();
btnContinueOn.src="/images/btnContinue_on.gif";
btnContinueOff=new Image();
btnContinueOff.src="/images/btnContinue_off.gif";

btnSubmitOn=new Image();
btnSubmitOn.src="/images/btnSubmit_on.gif";
btnSubmitOff=new Image();
btnSubmitOff.src="/images/btnSubmit_off.gif";

btnSubmitSmallOn=new Image();
btnSubmitSmallOn.src="/images/btnSubmitSmall_on.gif";
btnSubmitSmallOff=new Image();
btnSubmitSmallOff.src="/images/btnSubmitSmall_off.gif";

btnKeepShoppingOn=new Image();
btnKeepShoppingOn.src="/images/btnKeepShopping_on.gif";
btnKeepShoppingOff=new Image();
btnKeepShoppingOff.src="/images/btnKeepShopping_off.gif";

btnCheckoutOn=new Image();
btnCheckoutOn.src="/images/btnCheckout_on.gif";
btnCheckoutOff=new Image();
btnCheckoutOff.src="/images/btnCheckout_off.gif";

btnPlaceOrderOn=new Image();
btnPlaceOrderOn.src="/images/btnPlaceOrder_on.gif";
btnPlaceOrderOff=new Image();
btnPlaceOrderOff.src="/images/btnPlaceOrder_off.gif";

btnMakePaymentOn=new Image();
btnMakePaymentOn.src="/images/btnMakePayment_on.gif";
btnMakePaymentOff=new Image();
btnMakePaymentOff.src="/images/btnMakePayment_off.gif";

btnConfirmOn=new Image();
btnConfirmOn.src="/images/btnConfirm_on.gif";
btnConfirmOff=new Image();
btnConfirmOff.src="/images/btnConfirm_off.gif";

prodBgOff=new Image();
prodBgOff.src="/images/prodBg_off.png";
prodBgOn=new Image();
prodBgOn.src="/images/prodBg_on.png";


/*
 *  Get a reference to an object from it's name.
 *  If an object is provided, just return the object.
 */
function getObject(nameOrObj) {

    // See if we're dealing with a name or an object.
    if (typeof nameOrObj != "string") {
        // It's not a string, so assume it's the object.
        return nameOrObj;
    }

    // It's a name.
    var name = nameOrObj;

    if (document.getElementById) {
        return document.getElementById(name);
    }
    else if (document.all) {
        return document.all(name);
    }
    else {
        return null;
    }
}

/*
 *  Show the "on" form of a nav image when the mouse is moved over it.
 */
function imgOn(imgId) {

    var img = getObject(imgId);

    if (img != null) {
        img.src = eval(img.name + "On.src");
    }
}

/*
 *  Show the "off" form of a nav image when the mouse is moved over it.
 */
function imgOff(imgId) {

    var img = getObject(imgId);

    if (img != null) {
        img.src = eval(img.name + "Off.src");
    }
}

/*
 *  Return the provided numeric value formatted as a dollar amount
 *  beginning with a dollar sign.
 */
function formatDollarAmt(num) {
    return formatDollarAmt(num, true);
}

/*
 *  Return the provided numeric value formatted as a dollar amount,
 *  optionally beginning with a dollar sign.
 */
function formatDollarAmt(num, dollarSign) {

    var numStr = new String(num);

    // If there's no period, add one at the end.
    if (numStr.indexOf(".") < 0) {
        numStr = numStr + ".";
    }

    // Find the period.
    var idx = numStr.indexOf(".");

    // Start with the optional dollar sign.
    var str = "";
    if (dollarSign) {
        str = "$";
    }

    // Add characters until 2 past the period.
    for (var i=0; i<=idx+2; i++) {

        if (i >= numStr.length) {
            str += "0";
        }
        else {
            str += numStr.charAt(i);
        }
    }

    return str;
}

/*
 *  Function from Direct Agents used for tracking.
 */
function gup(name) {

    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec(window.location.href);

    if (results == null) {
        return "";
    }
    else {
        return results[1];
    }
}
