﻿
window.onerror = function() {
    return true;
}
var intlogin;
var intmenu;

if (location.toString().indexOf("www.") == -1) {
    location = "http://www." + document.domain;
}


intlogin = setInterval("load_login()", 200);
intmenu = setInterval("load_menu()", 200);

var strServerURL = window.location.toString();
var ftrSecureURL;
var ftrServerURL;
var ftrIsSSL;



if (strServerURL.indexOf('https') > -1) {
    ftrIsSSL = true;
}
else {
    ftrIsSSL = false;
}

ftrServerURL = "http://" + window.location.host;

if (ftrIsSSL == true) {
    ftrSecureURL = "https://" + window.location.host;
}
else {
    ftrSecureURL = ftrServerURL;
}

function search() {
    location = "/apps/sitesearch/search.aspx?query=" + escape(document.getElementById("ctl00_txtProduct").value);
}

function enterForm(e) {
    var evt = e ? e : window.event;
    if (evt.keyCode == 13) {
        return false;
    }
}


function check_email() {
    var special = document.getElementById('ctl00_txtSpecialOff');

    if (special.value == '' || IsValidEmail(special.value) == false) {
        alert('Please enter a valid email address');
        special.focus();
    } else {
        document.forms[0].action = ftrServerURL + '/apps/enews/specialOff.aspx?txtEmail=' + special.value;
        document.getElementById("ctl00_hdnReferer").value = top.location;
        document.forms[0].submit();
    }
}

function changelocation(url) {
    location = ftrSecureURL + url;
    //alert(ftrSecureURL + url);
}

function popUp2(url) {
    window.open(url, "", "width=400,height=500");
}

function IsValidEmail(strEmail) {
    var bReturn = true;
    if (strEmail.indexOf('@') == -1) {
        bReturn = false;
    } else if (strEmail.indexOf('.') == -1) {
        bReturn = false;
    } else if (strEmail.indexOf(' ') != -1) {
        bReturn = false;
    } else if (strEmail.charAt(0) == '@') {
        bReturn = false;
    } else if (strEmail.charAt(0) == '.') {
        bReturn = false;
    } else if (strEmail.charAt(strEmail.length - 1) == '@') {
        bReturn = false;
    } else if (strEmail.charAt(strEmail.length - 1) == '.') {
        bReturn = false;
    } else if (strEmail.indexOf(',') != -1) {
        bReturn = false;
    } else if (strEmail.substr(strEmail.indexOf('@') + 1, strEmail.length - 1).indexOf('@') != -1) {
        bReturn = false;
    } else if (strEmail.toLowerCase().indexOf('mailto') != -1) {
        bReturn = false;
    } else if (strEmail.toLowerCase().indexOf('mailto:') != -1) {
        bReturn = false;
    } else if (strEmail.toLowerCase().indexOf('<') != -1) {
        bReturn = false;
    } else if (strEmail.toLowerCase().indexOf('>') != -1) {
        bReturn = false;
    }
    return bReturn;
}

function getXMLHttpObj_Foot() {
    if (typeof (XMLHttpRequest) != 'undefined')
        return new XMLHttpRequest();

    var axO = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], i;

    for (i = 0; i < axO.length; i++)
        try {
        return new ActiveXObject(axO[i]);
    }
    catch (e) { }

    return null;
}

function loadScript_Foot() {
    var oXML = getXMLHttpObj_Foot();
    oXML.open('GET', '/includes/ServerPort.stm', false);
    oXML.send('');
    eval(oXML.responseText);

}

var server_port = '';
loadScript_Foot();

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write("\<script src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'>\<\/script>");

//alert(typeof(_gat));

if (server_port != '8081' && server_port != '8082') {
    var pageTracker;
    setTimeout('startGoogleA();', 500);
    var loc = new String(window.location);

    function startGoogleA() {
        if (loc.indexOf('.com.au') > 0) {
            //set au tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-2");
            }

        }
        else if (loc.indexOf('.ca') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-3");
            }

        }

        else if (loc.indexOf('.qc.ca') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-15");
            }

        }

        else if (loc.indexOf('.com.mx') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-13");
            }

        }

        else if (loc.indexOf('.fr') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-14");
            }

        }

        else if (loc.indexOf('.es') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-12");
            }

        }

        else if (loc.indexOf('.co.uk') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-7");
            }

        }

        else if (loc.indexOf('.de') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-6");
            }

        }

        else if (loc.indexOf('.eu') > 0) {
            //set ca tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-8");
            }

        }

        else {
            //set us tracker code
            if (typeof (_gat) == "object") {
                pageTracker = _gat._getTracker("UA-3226108-1");
            }

        }

        if (typeof (_gat) == "object") {
            //alert(typeof (_gat));
            pageTracker._initData();
            pageTracker._trackPageview();
        }
    }
}


/* Left Nav Bar --- To save the user preferences */
/* ------------------- Left Nav Bar Start --------------- */
var cookvalue;


function createCookie(name, value, days) {
    readCookie(name);

    if (cookvalue == null || cookvalue == '') {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";

        document.cookie = name + "=" + value + expires + "; path=/";

    }
    else {
        if (cookvalue == '1') {
            cookvalue = '0';
        }
        else {
            cookvalue = '1';
        }

        //eraseCookie(name);
        createCookie1(name, cookvalue, 100);

    }
}

function createCookie1(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";

    document.cookie = name + "=" + value + expires + "; path=/";
}

function click_estatements() {

    var SIG = readCookie("CRLID");
    window.open("https://" + document.domain + "/apps/secure/estatements/default.aspx?SIG=" + SIG, "_parent");
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');

    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) {
            cookvalue = c.substring(nameEQ.length, c.length);
            return c.substring(nameEQ.length, c.length);
        }
    }

    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

var client_hiding = true;

function clickButton(e, buttonid) {
    client_hiding = false;
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

var i = 0;
var watermark = "";

function txtProduct_focus() {
    if (client_hiding == true) {
        var txtProduct = document.getElementById("ctl00_txtProduct");
        if (txtProduct) {
            txtProduct.value = document.getElementById("ctl00_hdnWatermark").value;
            txtProduct.select();
            txtProduct.focus();
        }
    }


}


function master_load() {

    //setTimeout("load_login()", "10");
    load_login();
    //alert(1);
}

function load_login() {
    var login = readCookie("login");

    if (document.getElementById("ctl00_lnkBtnLogin") && document.getElementById("ctl00_lnkBtnLogout")) {
        if (login) {
            document.getElementById("ctl00_lnkBtnLogout").className = "header_logout show";
            document.getElementById("ctl00_lnkBtnLogin").className = "header_login hide";
        } else {
            document.getElementById("ctl00_lnkBtnLogin").className = "header_login show";
            document.getElementById("ctl00_lnkBtnLogout").className = "header_logout hide";
        }
        clearInterval(intlogin);
    }
}

function load_menu() {
    var login = readCookie("login");
    if (document.getElementById("ctl00_divLoggedOut") && document.getElementById("ctl00_divLoggedIn")) {
        if (login) {
            document.getElementById("ctl00_divLoggedIn").className = "show";
            document.getElementById("ctl00_divLoggedOut").className = "hide";
        } else {
            document.getElementById("ctl00_divLoggedIn").className = "hide";
            document.getElementById("ctl00_divLoggedOut").className = "show";
        }

        clearInterval(intmenu);
    }

}

function loadPreSettings() {

}

/* ------------------- Left Nav Bar End --------------- */

/* ------------------- MasterPage Help --------------------------- */
var helpWindow = null;
function popUppdf(URL) {
    helpWindow = window.open(URL, "Help", "width=800,height=600,resizable=0,scrollbars=0,status=0,left=10,top=10");

    if (window.focus)
    { helpWindow.window.focus(); }

}

/* ------------------- MasterPage Help End --------------------------- */

var hoster = window.location.host;


