﻿function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
    ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString() + ";path=/");
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function taLimit(taObj) {
    if (taObj.value.length >= 250) {
        return false;
    } else return true;
}

function taCount(taObj, Cnt) {
    objCnt = createObject(Cnt);
    objVal = taObj.value;
    if (objVal.length > 250) objVal = objVal.substring(0, 250);
    if (objCnt) {
        if (navigator.appName == "Netscape") {
            objCnt.textContent = 250 - objVal.length;
        }
        else { objCnt.innerText = 250 - objVal.length; }
    }
    return true;
}
function createObject(objId) {
    if (document.getElementById) return document.getElementById(objId);
    else if (document.layers) return eval("document." + objId);
    else if (document.all) return eval("document.all." + objId);
    else return eval("document." + objId);
}

/*function openChatWindow() 
{
window.open('https://admin.instantservice.com/links/7508/39905','custclient','width=600,height=324,scrollbars=0');
}*/
function agents_available() {
    jQuery("#chat_button_on").css('display', 'inline');
    jQuery("#chat_button_off").css('display', 'none');
    jQuery(".chat_button_on").css('display', 'inline');
    jQuery(".chat_button_off").css('display', 'none');

    //    document.getElementById('smartbutton').innerHTML = 
    //    '<a href="" onClick="window.open(\'https://admin.instantservice.com/links' +
    //    '/7508/39905\',\'chat_client\',\'width=600,height=324,scrollbars=0\');' +
    //    'cmCreatePageviewTag(\'Chat : Customer Entered Queue\',\'CHAT\',\'\',\'\');' +
    //    'return false;"><img src="/_buttons/chat_Button.jpg" border="0" style="height:76px;width:222px;"></a>';
    return true;
}

function agents_not_available() {
    jQuery("#chat_button_on").css('display', 'none');
    jQuery("#chat_button_off").css('display', 'inline');
    jQuery(".chat_button_on").css('display', 'none');
    jQuery(".chat_button_off").css('display', 'inline');
    //document.getElementById('smartbutton').innerHTML = '';
    return true;
}


// hides button if all validators are valid
function HideIfValid(buttonToHide) {
    var validator;

    for (var i = 0; i < Page_Validators.length; i++) {
        validator = Page_Validators[i];
        //Don't validate search box validator
        if (validator.controltovalidate) {
            if (validator.controltovalidate.indexOf('SearchBox') < 0) {
                ValidatorValidate(validator);
                // validation fails if at least one validator fails
                if (!validator.isvalid)
                    return false;
            }
        }
    }

    // Hide checkout and show processing (don't hide button for firefox or netscape, they go poopy)
    if ((!(navigator.userAgent.indexOf("Firefox") > -1)) && (!(navigator.userAgent.indexOf("Netscape") > -1))) buttonToHide.style.display = 'none';
    //if((!(navigator.userAgent.indexOf("Firefox") > -1)) && (!(navigator.userAgent.indexOf("Netscape")> -1))) document.getElementById('checkout_Buttons').style.display='none';
    //Show order message boxes
    if (document.getElementById('OrderMessage')) document.getElementById('OrderMessage').style.display = 'inline';
    if (document.getElementById('OrderMessage2')) document.getElementById('OrderMessage2').style.display = 'inline';
    if (document.getElementById('BML_OrderMessage')) document.getElementById('BML_OrderMessage').style.display = 'inline';

    // set it to true to post back page
    return true;
}

// hides button if all validators are valid
function HideAndShowIfValid(eHide, eShow) {
    var validator;

    for (var i = 0; i < Page_Validators.length; i++) {
        validator = Page_Validators[i];
        //Don't validate search box validator
        if (validator.controltovalidate) {
            if (validator.controltovalidate.indexOf('SearchBox') < 0) {
                ValidatorValidate(validator);
                // validation fails if at least one validator fails
                if (!validator.isvalid)
                    return false;
            }
        }
    }

    // Hide checkout and show processing (don't hide button for firefox or netscape, they go poopy)
    if ((!(navigator.userAgent.indexOf("Firefox") > -1)) && (!(navigator.userAgent.indexOf("Netscape") > -1))) eHide.style.display = 'none';
    //if((!(navigator.userAgent.indexOf("Firefox") > -1)) && (!(navigator.userAgent.indexOf("Netscape")> -1))) document.getElementById('checkout_Buttons').style.display='none';
    //Show order message boxes
    eShow.style.display = 'inline';

    // set it to true to post back page
    return true;
}

function HideBMLIfValid(buttonToHide) {
    var validator;

    for (var i = 0; i < Page_Validators.length; i++) {
        validator = Page_Validators[i];
        ValidatorValidate(validator);

        // validation fails if at least one validator fails
        if (!validator.isvalid)
            return false;
    }

    // Hide checkout and show processing (don't hide button for firefox or netscape, they go poopy)
    //if((!(navigator.userAgent.indexOf("Firefox") > -1)) && (!(navigator.userAgent.indexOf("Netscape")> -1))) buttonToHide.style.display='none';
    if ((!(navigator.userAgent.indexOf("Firefox") > -1)) && (!(navigator.userAgent.indexOf("Netscape") > -1))) document.getElementById('BML_checkout_Buttons').style.display = 'none';
    document.getElementById('BML_OrderMessage').style.display = 'inline';


    // set it to true to post back page
    return false;
}

//function registerRealEstateTags(pageid) {
//    foreach(e in document.anchors)
//    {
//        if (e.attributes['manual_cm_re'] != null) {
//            cmCreateManualImpressionTag(pageid, '', e.attributes['manual_cm_re']);
//        }
//    }
//    ;
//}

function clientSideInclude(url) {
    var req = false;
    // For Safari, Firefox, and other non-MS browsers
    if (window.XMLHttpRequest) {
        try {
            req = new XMLHttpRequest();
        } catch (e) {
            req = false;
        }
    } else if (window.ActiveXObject) {
        // For Internet Explorer on Windows
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                req = false;
            }
        }
    }
    if (req) {
        // Synchronous request, wait till we have it all
        req.open('GET', url, false);
        req.send(null);
        document.write(req.responseText);
    }
}
var flashTakeover = {
    open: function () {
        if (swfobject.hasFlashPlayerVersion("9.0.0")) {
            // has Flash
            fatheadModalPopup.centerPopup("#takeover", "#popupBackground");
            fatheadModalPopup.loadPopup("#takeover", "#popupBackground");
            var flash_contentVersion = 9;
            var flash_swfUrl = 'http://content.fathead.com/flash/splash051010-1.swf';
            var flash_bgcolor = "#1a1c29";
            var flash_width = "960";
            var flash_height = "540";
            var flash_id_name = "flashtakeover";
            var flash_align = "middle";
            var flash_parms = {
                wmode: "transparent",
                align: "middle",
                menu: "false",
                allowscriptaccess: "always"
            };
            swfobject.embedSWF(flash_swfUrl, flash_id_name, flash_width, flash_height, "9.0.0", null, null, flash_parms, null);
        }
    },
    close: function () {
        jQuery("#flashtakeover").remove();
        jQuery("#takeover").html("<div id=\"flashtakeover\"></div>");
        var options = { to: "#watchnowbutton", className: 'ui-effects-transfer' };
        jQuery("#popupBackground").fadeOut("slow", function () {
            jQuery("#takeover").fadeOut("slow", function () {
                jQuery("#takeover").hide("transfer", options, 500, function () { });
            });
        });
//        cmCreatePageviewTag('TAKEOVER-CLOSE', 'FLASH', '', '');
    },
    skip: function () {
        jQuery("#flashtakeover").remove();
        jQuery("#takeover").html("<div id=\"flashtakeover\"></div>");
        var options = { to: "#watchnowbutton", className: 'ui-effects-transfer' };
        jQuery("#popupBackground").fadeOut("slow", function () {
            jQuery("#takeover").fadeOut("slow", function () {
                jQuery("#takeover").hide("transfer", options, 500, function () { });
            });
        });
//        cmCreatePageviewTag('TAKEOVER-SKIP', 'FLASH', '', '');
    }
};

var fatheadModalPopup = {
    closePopup: function (tagPopupID, tagBkgrnd) {
        jQuery(tagBkgrnd).fadeOut("slow");
        jQuery(tagPopupID).fadeOut("slow");
    },
    loadPopup: function (tagPopupID, tagBkgrnd) {
        //loads popup only if it is disabled  
        jQuery(tagBkgrnd).css({
            "opacity": "0.7"
        });
        jQuery(tagBkgrnd).delay(100).fadeIn("slow");
        jQuery(tagPopupID).delay(100).fadeIn("slow");
    },
    //centering popup  
    centerPopup: function (tagPopupID, tagBkgrnd) {
        //request data for centering  
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = jQuery(tagPopupID).height();
        var popupWidth = jQuery(tagPopupID).width();
        //centering  
        if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
            jQuery(tagPopupID).css({
                "position": "absolute",
                "top": windowHeight / 2 - popupHeight / 2,
                "left": windowWidth / 2 - popupWidth / 2
            });
        }
        else {
            jQuery(tagPopupID).css({
                "position": "fixed",
                "top": windowHeight / 2 - popupHeight / 2,
                "left": windowWidth / 2 - popupWidth / 2
            });
        }
        //only need force for IE6  

        jQuery(tagBkgrnd).css({
            "height": windowHeight
        });
    }
}
jQuery(document).ready(function () {
    jQuery(".menu_holder").each(function (index) {
        var e = jQuery(this);
        e.children('.menumask').height(e.children('.menudropdown').height());
        e.children('.menumask').width(e.children('.menudropdown').width());
        e.parent().hover(function () {
            jQuery(this).addClass("over");
        }, function () {
            jQuery(this).removeClass("over");
        });
    });
});

function openWindowScroll(URL, width, height) {
    popupWin = window.open(URL, 'popup', 'menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable,width=' + width + ',height=' + height + ',left=70,top=50')
}

function openWindowNoScroll(URL, width, height) {
    popupWin = window.open(URL, 'popup', 'menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable,width=' + width + ',height=' + height + ',left=70,top=50')
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function setWatermark(textboxid) {
    // Got Focus
    jQuery('#' + textboxid).focus(function () {
        jQuery(this).filter(function () {
            return jQuery(this).val() == "" || jQuery(this).val() == "Enter your email address..."
        }).removeClass("textboxWatermark").val("");

    });

    // Lost Focus
    jQuery('#' + textboxid).blur(function () {
        jQuery(this).filter(function () {
            return jQuery(this).val() == ""
        }).addClass("textboxWatermark").val("Enter your email address...");
    });
}
var fathead = {
    config: {
        server: '',
        //        pageName: function () {
        //            var catagory = 'landing';
        //            var name = 'default';
        //            var nodes = fathead.url.getPathNodes();
        //            switch (nodes.length) {
        //                case 1:
        //                case 2:
        //                    name = '';
        //                    catagory = 'homepage';
        //                    break;
        //                case 3:
        //                    name = nodes[1];
        //                    catagory = 'landing';
        //                    break;
        //                case 4:
        //                    switch (nodes[1]) {
        //                        case 'sweepstakes':
        //                            name = nodes[2];
        //                            catagory = 'sweepstakes';
        //                            break;
        //                        default:
        //                            if (nodes[2] == 'products')
        //                                name = nodes[1];
        //                            else
        //                                name = nodes[2];
        //                            catagory = 'catalog';
        //                            break;
        //                    }
        //                    break;
        //                case 5:
        //                    name = nodes[3];
        //                    catagory = 'detail';
        //                    break;
        //            }
        //            return 'FH:' + catagory + ':' + name;
        //        },
        pageName: '',
        channel: 'shop',
        campaign: 'TEST',
        variant: 'A',
        errorPage: false
    },
    tabs: {
        init: function (tabname) {
            jQuery(tabname).click(function () {
                jQuery(tabname).removeClass('selected');
                jQuery(this).addClass('selected');
                jQuery(jQuery(this).attr('data-tab-panel')).show();
                return false;
            });
            if (jQuery(tabname).length > 0)
                jQuery(tabname).first().click();
        }
    },
    url: {
        getParameterByName: function (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 decodeURIComponent(results[1].replace(/\+/g, " "));
        },
        getPathNodes: function () {
            var href = window.location.href;
            var t1 = href.split("//");
            var path = t1[1].split("/");
            return path;
        }
    },
    omniture: {
        createPageView: function () {
            s.pageName = fathead.config.pageName;
            s.server = fathead.config.server;
            if (typeof activemenu === 'undefined')
                s.channel = fathead.config.channel;
            else
                s.channel = activemenu;
            s.eVar13 = s.prop13 = fathead.config.variant;
            s.prop20 = fathead.config.campaign;
            s.prop21 = s.pageName + ':' + s.prop20 + ':' + s.prop13;
        },
        createCustomPageView: function (pagename) {
            var s = s_gi(s_account);
            s.pageName = pagename;
            s.server = fathead.config.server;
            if (typeof activemenu === 'undefined')
                s.channel = fathead.config.channel;
            else
                s.channel = activemenu;
            s.eVar13 = s.prop13 = fathead.config.variant;
            s.prop20 = fathead.config.campaign;
            s.prop21 = s.pageName + ':' + s.prop20 + ':' + s.prop13;
            s.pageType = null;
            void (s.t());
        },
        createProductView: function () {
        },
        addProductToCart: function (sku, newcart) {
            var s = s_gi(s_account);
            s.linkTrackVars = 'products,events';

            s.products = ';' + sku + '';
            if (newcart) {
                s.events = 'scOpen,scAdd';
                s.linkTrackEvents = 'scOpen,scAdd';
            }
            else {
                s.events = 'scAdd';
                s.linkTrackEvents = 'scAdd';
            }
            s.tl(this, 'o', 'Cart Ad');
            return false;
        },
        removeProductFromCart: function (sku) {
            var s = s_gi(s_account);
            s.linkTrackVars = 'products,events';
            s.linkTrackEvents = 'scRemove';
            s.products = ';' + sku + '';
            s.events = 'scRemove';
            s.tl(this, 'o', 'Cart Removal');
            return false;
        },
        completeOrder: function () {
        },
        render: function () {
            // Run Omniture with updated s object
            var renderOmniture = s.t();
            if (renderOmniture) {
                document.write(renderOmniture);
            }
        },
        enterPromotion: function (code) {
            var s = s_gi(s_account);
            s.linkTrackVars = 'eVar33,events';
            s.linkTrackEvents = 'event12';
            s.events = 'event12';
            s.eVar33 = code;
            s.tl(this, 'o', 'Cart Promo');
        },
        viewForm: function () {
        },
        completeForm: function (code) {
        },
        chatOffer: function () {
            var s = s_gi(s_account);
            s.pageName = 'FH: chat offered';
            s.eVar35 = 'Offered';
            s.server = fathead.config.server;
            if (typeof activemenu === 'undefined')
                s.channel = fathead.config.channel;
            else
                s.channel = activemenu;
            s.eVar13 = s.prop13 = fathead.config.variant;
            s.prop20 = fathead.config.campaign;
            s.prop21 = s.pageName + ':' + s.prop20 + ':' + s.prop13;
            s.pageType = null;
            void (s.t());
        },
        chatAccept: function () {
            var s = s_gi(s_account);
            s.pageName = 'FH: chat accepted';
            s.eVar35 = 'Accepted';
            s.server = fathead.config.server;
            if (typeof activemenu === 'undefined')
                s.channel = fathead.config.channel;
            else
                s.channel = activemenu;
            s.eVar13 = s.prop13 = fathead.config.variant;
            s.prop20 = fathead.config.campaign;
            s.prop21 = s.pageName + ':' + s.prop20 + ':' + s.prop13;
            s.pageType = null;
            void (s.t());
        },
        chatDecline: function () {
            var s = s_gi(s_account);
            s.pageName = 'FH: chat declined';
            s.eVar35 = 'Declined';
            s.server = fathead.config.server;
            if (typeof activemenu === 'undefined')
                s.channel = fathead.config.channel;
            else
                s.channel = activemenu;
            s.eVar13 = s.prop13 = fathead.config.variant;
            s.prop20 = fathead.config.campaign;
            s.prop21 = s.pageName + ':' + s.prop20 + ':' + s.prop13;
            s.pageType = null;
            void (s.t());
        }
    },
    window: {
        openWindowScroll: function (URL, width, height) {
            popupWin = window.open(URL, 'popup', 'menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable,width=' + width + ',height=' + height + ',left=70,top=50')
        },

        openWindowNoScroll: function (URL, width, height) {
            popupWin = window.open(URL, 'popup', 'menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable,width=' + width + ',height=' + height + ',left=70,top=50')
        },
        centerPopup: function (e) {
            //request data for centering  
            var windowWidth = document.documentElement.clientWidth;
            var windowHeight = document.documentElement.clientHeight;
            var popupHeight = jQuery(e).height();
            var popupWidth = jQuery(e).width();
            //centering
            if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
                jQuery(e).css({
                    "position": "absolute",
                    "top": windowHeight / 2 - popupHeight / 2,
                    "left": windowWidth / 2 - popupWidth / 2
                });
            }
            else {
                jQuery(e).css({
                    "position": "fixed",
                    "top": windowHeight / 2 - popupHeight / 2,
                    "left": windowWidth / 2 - popupWidth / 2
                });
            }
            //only need force for IE6  

            jQuery("#backgroundPopup").css({
                "height": windowHeight
            });

        }


    },
    utility: {
        setWatermark: function (textboxid) {
            jQuery(textboxid).addClass("textboxWatermark").val(jQuery(textboxid).attr('data-wmtext'))
            // Got Focus
            jQuery(textboxid).focus(function () {
                jQuery(this).filter(function () {
                    return jQuery(this).val() == "" || jQuery(this).val() == jQuery(this).attr('data-wmtext')
                }).removeClass("textboxWatermark").val("");

            });

            // Lost Focus
            jQuery(textboxid).blur(function () {
                jQuery(this).filter(function () {
                    return jQuery(this).val() == ""
                }).addClass("textboxWatermark").val(jQuery(this).attr('data-wmtext'));
            });
        }
    }

};
//temporary stub
function cmCreatePageElementTag(a, b) {
}
