﻿var tmp = "<div align='center' style='background-color:white;width:100%;font-weight:bold;color:red;'>ATTENTION: From 4pm - 5pm Central time, we will be performing a Partners upgrade. While you won't experience any downtime, you may be randomly logged out of Partners during that time, or may experience an error when searching for orders. Also, please refrain from creating, editing, or deleting Partners accounts during that time.<br />The upgrade will be complete when this message disappears. We apologize for any inconvenience.</div>";
//document.write(tmp);

var prefix = "ctl00_cph1_";

function randomBackground(url,siteID)
{
    var totImages = (siteID == 1) ? 17 : 11;

    var img = url + rand(1,totImages) + ".jpg";
    var bodyObj = $get("body");
    bodyObj.style.backgroundImage = "url(" + img + ")";
}
function rand(l,u)
{
    return Math.floor((Math.random() * (u-l + l)) + l);
}
function catalogWindow(siteID)
{
	// 1 - Tech Full Line
	// 2 - LBL Full Line
	// 3 - Tech 2012 Supplement

    if (siteID == 1)
        window.open("http://www.techlighting.com/CatalogView.aspx?693Op2R6i5TInYqgnjgLBov1/AZlOjLZ+iWS89Q4NF+4tTalTImaALgSNPSVeZePETjGrqgCsRwTug6lQB1UX1LO0lKskE15WAA8Pu1xlJ9iorJd2ny2tJuP6o0VfaPU", "_blank", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height=600,width=800");
    else if (siteID == 2)
        window.open("http://www.lbllighting.com/CatalogView.aspx?X0oxlrxPfLsUAr6XfxgFueG+jjXLMS/0UHJvVG30zHEyc0ooFRRPJPZuiGf1xQwKcDrhRuooZs1Y3fBCd3pMWXlPLEyIQS8DQxKLp1f1wygOQqOm7Npg5cLHxt6d2GMO", "_blank", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height=600,width=800");
    else if (siteID == 3)
        window.open("http://www.techlighting.com/CatalogView.aspx?693Op2R6i5TInYqgnjgLBov1/AZlOjLZ+iWS89Q4NF+4tTalTImaALgSNPSVeZePETjGrqgCsRwTug6lQB1UX0fhH9GzbmHi6SVQFCEmpfc=", "_blank", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height=600,width=800");
}
function catalogWindow2()
{
	window.open("http://www.techlighting.com/CatalogView.aspx?693Op2R6i5TInYqgnjgLBov1/AZlOjLZ+iWS89Q4NF+4tTalTImaALgSNPSVeZePETjGrqgCsRwTug6lQB1UX0fhH9GzbmHi6SVQFCEmpfc=", "_blank", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height=600,width=800");
}

function showHelp(which)
{
    var msg = null;
    if (which == "username")
    {
        msg = "<strong class='helpHeader'>Account Username</strong><br /><br />";
        msg += "This is your account username you will use to access Partners.<br /><br />";
        msg += "<strong>REQUIREMENTS</strong><br />";
        msg += "<li>Numbers and letters only.</li>";
        msg += "<li>No special characters or spaces allowed.</li><br />";
        msg += "<strong>ADDITIONAL NOTES</strong>";
        msg += "<li>Usernames are retrievable if forgotten.</li>";
        msg += "<li>Must know your registered email address to retrieve your username.</li>";
    }
    else if (which == "password")
    {
        msg = "<strong class='helpHeader'>Account Password</strong><br /><br />";
        msg += "This is the password you will use to access Partners.<br /><br />";
        msg += "<strong>REQUIREMENTS</strong>";
        msg += "<li>Minimum of 6 characters</li>";
        msg += "<li>Cannot be the same as your username</li><br />";
        msg += "<strong>SUGGESTIONS</strong>";
        msg += "<li>Include numbers, upper and lower case letters</li>";
        msg += "<li>Use special characters like !, % or, &amp;.</li><br />";
        msg += "<strong>ADDITIONAL NOTE</strong>";
        msg += "<li>Passwords cannot be retrieved, only reset.</li>";
    }
    else if (which == "security")
    {
        msg = "<strong class='helpHeader'>Security Question/Answer</strong><br /><br />";
        msg += "You will need this to reset your password should you forget it.<br /><br />";
        msg += "Passwords cannot be retrieved, only reset.";
    }
    else if (which == "email")
    {
        msg = "<strong class='helpHeader'>Account Email Address</strong><br /><br />";
        msg += "This is the primary email address on your account. All notifications and confirmations will be sent to this address. ";
        msg += "You will also need to know this email address if you have forgotten your username and are trying to retrieve it.";
    }
    if (which == "accountTech")
    {
        msg = "<strong class='helpHeader'>Tech Account Number</strong><br /><br />";
        msg += "This number can be obtained from an invoice, by calling your local representative, or by calling customer service.";
    }
    else if (which == "accountLBL")
    {
        msg = "<strong class='helpHeader'>LBL Account Number</strong><br /><br />";
        msg += "This number can be obtained from an invoice, by calling your local representative, or by calling customer service.";
    }
    else if (which == "shiptoTech")
    {
        msg = "<strong class='helpHeader'>Tech Account \"Ship To\" Number</strong><br /><br />";
        msg += "This number can be obtained from an invoice, by calling your local representative, or by calling customer service.";
    }
    else if (which == "shiptoLBL")
    {
        msg = "<strong class='helpHeader'>LBL Account \"Ship To\" Number</strong><br /><br />";
        msg += "This number can be obtained from an invoice, by calling your local representative, or by calling customer service.";
    }
    if (which == "con")
    {
        msg = "<strong class='helpHeader'>Confidential Reports</strong><br /><br />";
        msg += "These reports include Commission Reports, Commission Summaries, and Aging Reports. At this time, this applies to Reps only.";
    }
    else if (which == "gen")
    {
        msg = "<strong class='helpHeader'>General Reports</strong><br /><br />";
        msg += "These reports include Display Reports, Sales Reports, Invoices, and Credit Memos. At this time, this applies to Reps only.";
    }
    else if (which == "statusChange")
    {
        msg = "<strong class='helpHeader'>Order Status Change</strong><br /><br />";
        msg += "This includes the lifecycle of an order. An order's status changes as it goes through a typical Order-to-Ship process. This includes RGAs.";
    }
    else if (which == "shiptos")
    {
        msg = "<strong class='helpHeader'>View All Ship To Locations</strong><br /><br />";
        msg += "One customer could have multiple ship to locations, ie: if they have multiple store locations. By allowing the user to view all ship to locations, ";
        msg += "they will be able to view orders not only for their store location, but for all locations the customer may have.";
    }
    else if (which == "principle")
    {
        msg = "<strong class='helpHeader'>The Principle Account</strong><br /><br />";
        msg += "This designates that the account is the principle account. This account is usually reserved for the principle owner(s) of a company.";
    }
    else if (which == "orders")
    {
        msg = "<strong class='helpHeader'>View Orders</strong><br /><br />";
        msg += "This allows the user to look up company/customer orders, search orders, and view shipping information.";
    }
    else if (which == "stock")
    {
        msg = "<strong class='helpHeader'>Product Availability</strong><br /><br />";
        msg += "This allows the user to look up stock and list pricing depending on the user's permission level.";
    }
    else if (which == "manage")
    {
        msg = "<strong class='helpHeader'>Can Manage Accounts</strong><br /><br />";
        msg += "This allows the user to manage accounts. This means the use can add, edit, and delete accounts as well as manage Email-Only Accounts.";
    }
    else if (which == "recentOrders")
    {
        msg = "<strong class='helpHeader'>Orders & Recent Orders</strong><br /><br />";
        msg += "By default, recent orders show the last 15 days worth of orders. ";
        msg += "You can change the number of days, up to 90 days, by clicking on \"Dashboard Management\" at the top of your screen.<br /><br />\n"; 
        msg += "<strong>NOTE:</strong> To help with loading time, orders accessed for the first time are loaded from the database and stored in your browser's cache for one hour. ";
        msg += "This means that all subsequent visits to the order page will load very quickly from your browser's memory. ";
        msg += "However, this also means that orders that have been recently been uploaded to the system may not show up until the cache has been cleared. ";
        msg += "You can manually reload the orders at any time by clicking the reload icon (<img src='images/icons/refresh_14.gif' />). ";
        msg += "Note that it may take anywhere from 15 to 60 seconds for the page to reload, depending on how many orders you have.";
    }
    else if (which == "otherAccount")
    {
        msg = "<strong class='helpHeader'>Importing Another Account</strong><br /><br />";
        msg += "For our customers that have another account, we are allowing the use of one username and password for both sites. ";
        msg += "Your other account information will be imported to the primary account and you will be able to login to both sites with one username and password. ";
        msg += "Please note that you will still need to log into the respective sites to access its information.";
    }
    else if (which == "needAccount")
    {
        msg = "<strong class='helpHeader'>Need an Account?</strong><br /><br />";
        msg += "<em>Showrooms/Distributors</em> - please contact your company principle, your company's designated account manager, or your sales rep.<br /><br />";
        msg += "<em>Existing Sales Reps</em> - please contact your company principle or your company's designated account manager.<br /><br />";
        msg += "<em>New Sales Reps</em> - please fill out this form<br /><br />";
        msg += "<em>Employees</em> - please contact the IT Department";
    }
    else if (which == "noReload")
    {
        msg = "<strong class='helpHeader'>Why Can't I Reload My Orders or RGAs?</strong><br /><br />";
        msg += "To prevent unnecessary burden on our servers, you can only reload your orders or RGAs once per hour."
    }
    else if (which == "noPrint")
    {
        msg = "<strong class='helpHeader'>Why Can't I Print or Download My Orders and RGAs?</strong><br /><br />";
        msg += "Printing and downloading orders and RGAs gives you orders for the past 90 days. This is a large set of data that would place unnecessary burden on our servers should they repeatedly be downloaded. You can print or download orders/RGAs once per hour.<br /><br />";
        msg += "If you need to see an order older than 15 days, try the Search function."
    }
    else if (which == "pricing")
    {
        msg = "<strong class='helpHeader'>View List Pricing</strong><br /><br />";
        msg += "This applies to product avilability searches. Pricing can only be viewed by Reps and Showrooms. Pricing <strong>is not</strong> available to distributors.";
    }
    
    popItUp(msg);
}

function showNews(title, date, desc, pdf, url)
{
    msg = "<strong style='font-family:Calibri, Sans-Serif;'>" + title + "</strong><br />";
    msg += "<label style='font-family:Calibri, Sans-Serif;'>" + date + "</label><br /><br />";
    
    if (desc && desc != "") msg += "<label style='font-family:Calibri, Sans-Serif;'>" + desc + "</label><br /><br />";
    if (pdf && pdf != "") msg += "<a href='" + url + pdf + "' target='_blank' style='text-decoration:underline;color:#000;'>Download PDF</a>";
    
    popItUp(msg);
}

function popItUp(msg)
{
    var label = $get('helpLabel');
    label = (!label) ? $get('helpLabel') : label;
    label = (!label) ? $get('ctl00_helpLabel') : label;
    
    label.innerHTML = msg;
    
    var panel = $get('helpPanelMPE');
    panel = (!panel) ? $find('helpPanelMPE') : panel;
    panel = (!panel) ? $find('ctl00_helpPanelMPE') : panel;
    
    panel.show();
}

function otherAccount(t)
{
    var divObj = $get("doYouHas");
    
    if (t.value == "yes") divObj.style.display = "block";
    else
    {
        var otherErrLabel = $get("ctl00_cph1_otherErrLabel");
        var objPassword = $get("otherPassword");
        var objUsername = $get("otherUsername");
        
        objPassword.value = "";
        objUsername.value = "";
        otherErrLabel.innerHTML = "";
        
        divObj.style.display = "none";
    }
}

function checkOtherAccountCredentials(t, siteID)
{
    var otherErrLabel = $get(prefix + "otherErrLabel");
    var usernameObj = $get("otherUsername");
    var btnObj = $get(prefix + "button1");
    var pwdValue = t.value;
    
    btnObj.disabled = true;
    otherErrLabel.innerHTML = "<strong style='color:#00C;'>Checking the database. Please wait...</strong>\n";

    if (t.value && siteID)
    {
        // (Username, Password, siteID)
        Services.CheckOtherAccountCrednetials(usernameObj.value, pwdValue, siteID, CheckOtherAccountCredentialsComplete); 
    }
}
function CheckOtherAccountCredentialsComplete(arg)
{
    var otherErrLabel = $get(prefix + "otherErrLabel");
    var objPassword = $get("otherPassword");
    var objUsername = $get("otherUsername");
    var btnObj = $get(prefix + "button1");
    
    if (!arg)
    {
        otherErrLabel.innerHTML = "<strong style='color:#C00;'>That username/password combination does not exist.</strong>\n";
        objUsername.value = "";
        objPassword.value = "";
    }
    else otherErrLabel.innerHTML = "<strong style='color:#0C0;'>Account verified!</strong>\n";
    
    btnObj.disabled = false;
}

function orderSearch(id)
{
    var obj = $get(id);
    
    var soDiv = $get('so');
    var poDiv = $get('po');
    var rgaDiv = $get('rga');
    var custDiv = $get('custnum');
    var skuDiv = $get('sku');
    
    var soTxtBox = $get('soNum');
    var poTxtBox = $get('poNum');
    var rgaTxtBox = $get('rgaNum');
    var custTxtBox = $get('byCust');
    var skuTxtBox = $get('bySku');
    
    soDiv.style.visibility = "hidden";
    soDiv.style.display = "none";
    poDiv.style.visibility = "hidden";
    poDiv.style.display = "none";
    rgaDiv.style.visibility = "hidden";
    rgaDiv.style.display = "none";
    skuDiv.style.visibility = "hidden";
    skuDiv.style.display = "none";
    
    if (custDiv)
    {
        custDiv.style.visibility = "hidden";
        custDiv.style.display = "none";
        custTxtBox.value = "";
    }
    
    soTxtBox.value = "";
    poTxtBox.value = "";
    rgaTxtBox.value = "";
    skuTxtBox.value = "";
    
    obj.style.visibility = "visible";
    obj.style.display = "block";
}


// - retrieve username by email
function retrieveUsernameByEmail(t, siteID)
{
    if (t.value && siteID) Services.GetUsernameByEmail(t.value, siteID, RetrieveUsernameComplete);
}
function RetrieveUsernameComplete(arg)
{
    var usernameLabel = $get('retrievedUsernameLabel');
    usernameLabel = (!usernameLabel) ? $get('retrievedUsernameLabel') : usernameLabel;
    usernameLabel = (!usernameLabel) ? $get(prefix + 'retrievedUsernameLabel') : usernameLabel;
    
    var arrayArg = arg.split("|");
    
    if (arrayArg[1] == 0)
    {
        usernameLabel.innerHTML = "&nbsp;That email address does not exist in our database.";
    }
    else
    {
        var username = arrayArg[0];
        var userid = arrayArg[1];
        
        var email = $get('email');
        var eBox = $get('emailForPwd');
        var uBox = $get('usernameForPwd');
        var useridObj = $get('userid');
        
        email = (!email) ? $get('email') : email;
        email = (!email) ? $get(prefix + 'email') : email;
        
        eBox = (!eBox) ? $get('emailForPwd') : eBox;
        eBox = (!eBox) ? $get(prefix + 'emailForPwd') : eBox;
        
        uBox = (!uBox) ? $get('usernameForPwd') : uBox;
        uBox = (!uBox) ? $get(prefix + 'usernameForPwd') : uBox;
        
        useridObj = (!useridObj) ? $get('userid') : useridObj;
        useridObj = (!useridObj) ? $get(prefix + 'userid') : useridObj;
    
        usernameLabel.innerHTML = "&nbsp;Your username is: <label style='color:Black'>" + username + "</label>";
        
        // Populate text boxes 
        if (eBox && uBox && arg && useridObj)
        {
            var resetbtn = $get('resetBtn');
            resetbtn = (!resetbtn) ? $get('resetBtn') : resetbtn;
            resetbtn = (!resetbtn) ? $get(prefix + 'resetBtn') : resetbtn
    
            useridObj.value = userid;
            eBox.value = email.value;
            uBox.value = username;
            resetbtn.disabled = false;
        }
    }
}

// - check email username for password reset
function checkEmailUsernameForPwdReset(siteID)
{
    var eBox = $get('emailForPwd');
    var uBox = $get('usernameForPwd');
    var resetbtn = $get('resetBtn');
    
    eBox = (!eBox) ? $get('emailForPwd') : eBox;
    eBox = (!eBox) ? $get(prefix + 'emailForPwd') : eBox;
    
    uBox = (!uBox) ? $get('usernameForPwd') : uBox;
    uBox = (!uBox) ? $get(prefix + 'usernameForPwd') : uBox;
    
    resetbtn = (!resetbtn) ? $get('resetBtn') : resetbtn;
    resetbtn = (!resetbtn) ? $get(prefix + 'resetBtn') : resetbtn
    
    if (eBox.value && uBox.value) Services.GetSecurityQuestion(eBox.value, uBox.value, siteID, CompleteCheckEmailUsernameForPwdReset);
    else resetbtn.disabled = true;
}
function CompleteCheckEmailUsernameForPwdReset(arg)
{
    var resetbtn = $get('resetBtn');
    var useridObj = $get('userid');
    
    resetbtn = (!resetbtn) ? $get('resetBtn') : resetbtn;
    resetbtn = (!resetbtn) ? $get(prefix + 'resetBtn') : resetbtn
        
    useridObj = (!useridObj) ? $get('userid') : useridObj;
    useridObj = (!useridObj) ? $get(prefix + 'userid') : useridObj;
    
    var err = $get('err');
    err = (!err) ? $get('err') : err;
    err = (!err) ? $get(prefix + 'err') : err;
    
    if (arg == "null" || !arg)
    {
        resetbtn.disabled = true;
        err.innerHTML = "&nbsp;&nbsp;That username/email combo is not valid";
    }
    else
    {
        var arrayArg = arg.split('|');
        var secQuestion = arrayArg[0];
        useridObj.value = arrayArg[1];
    
        if (secQuestion)
        {
            err.innerHTML = "";
            resetbtn.disabled = false;
        }
        else 
        {
            resetbtn.disabled = true;
            err.innerHTML = "&nbsp;&nbsp;<br />You have not yet set a security question.<br />Please contact your principle, account manager or rep to modify your password.<br />";
        }
    }
}

// - check security answer
function checkSecurityAnswer(t, username, email, siteID)
{
    if (t.value)
    {
        Services.CheckSecurityAnswer(t.value, username, email, siteID, CompleteCheckSecurityAnswer);
    }
    else
    {
        var btn = $get('');
        btn = (!btn) ? $get('btn') : btn;
        btn = (!btn) ? $get(prefix + 'btn') : btn;
        
        btn.disabled = true;
    }
}
function CompleteCheckSecurityAnswer(arg)
{
    var err = $get('err');
    err = (!err) ? $get('err') : err;
    err = (!err) ? $get(prefix + 'err') : err;
    
    var btn = $get('');
    btn = (!btn) ? $get('btn') : btn;
    btn = (!btn) ? $get(prefix + 'btn') : btn;
    
    if (!arg)
    {
        btn.disabled = true;
        err.innerHTML = "&nbsp&nbsp;That is not a correct answer to the security question.";
    }
    else
    {
//        var username = $get('username');
//        username = (!username) ? $get('username') : username;
//        username = (!username) ? $get(prefix + 'username') : username;
//        
//        var pwd1 = $get('pwd1');
//        pwd1 = (!pwd1) ? $get('pwd1') : pwd1;
//        pwd1 = (!pwd1) ? $get(prefix + 'pwd1') : pwd1;
//        
//        var pwd2 = $get('pwd2');
//        pwd2 = (!pwd2) ? $get('pwd2') : pwd2;
//        pwd2 = (!pwd2) ? $get(prefix + 'pwd2') : pwd2;
//    
//        if ( (pwd1.value != username.value) && (pwd1.value == pwd2.value) && pwd1.value.length >= 6 && pwd1.value && pwd2.value )
//        {
            err.innerHTML = "";
            btn.disabled = false;
        //}
    }
}


function checkPwdUsername(sender, args)
{
    var username = $get('username');
    username = (!username) ? $get('username') : username;
    username = (!username) ? $get(prefix + 'username') : username;
    
    var pwd = args.Value;
    
    if (pwd == username.value)
        args.IsValid = false;
    else
        args.IsValid = true;
}
function checkPwdLength(sender, args)
{
    var pwd = args.Value;
    
    if (pwd.length < 6)
        args.IsValid = false;
    else
        args.IsValid = true;
}

function checkPwds(t)
{
        var username = $get('username');
        username = (!username) ? $get('username') : username;
        username = (!username) ? $get(prefix + 'username') : username;
        
        var pwd1 = $get('pwd1');
        pwd1 = (!pwd1) ? $get('pwd1') : pwd1;
        pwd1 = (!pwd1) ? $get(prefix + 'pwd1') : pwd1;
        
        var pwd2 = $get('pwd2');
        pwd2 = (!pwd2) ? $get('pwd2') : pwd2;
        pwd2 = (!pwd2) ? $get(prefix + 'pwd2') : pwd2;
    
        if ( (pwd1.value != username.value) && (pwd1.value == pwd2.value) && pwd1.value.length >= 6 && pwd1.value && pwd2.value )
        {
            t.submit();
        } 
}


function CheckUsername(t, cur, siteID)
{
    if (t.value != cur)
    {
        Services.ValueCheck("USERNAME", t.value, siteID, UsernameComplete);
    }
}
function UsernameComplete(arg)
{
    var usernameErr = $get('usernameErrLabel');
    var username = $get('username');
    
    usernameErr = (!usernameErr) ? $get('usernameErrLabel') : usernameErr;
    usernameErr = (!usernameErr) ? $get(prefix + 'usernameErrLabel') : usernameErr;
    
    username = (!username) ? $get('username') : username;
    username = (!username) ? $get(prefix + 'username') : username;
    
    if (!arg)
    {
        usernameErr.innerHTML = "That&nbsp;username&nbsp;already&nbsp;exists.";
        
        if (!document.form1)
            username.select();
        else
            form1.username.select();
    }
    else
    {
        usernameErr.innerHTML = "";
    }
}

function showHideOrders(id)
{
    var img = $get("img_" + id);
    var obj = $get(id);
    
    if (obj.style.visibility == "hidden")
    {
        obj.style.visibility = "visible";
        obj.style.display = "block";
        
        img.src = "http://images.techlighting.com/Partners/icons/minus.gif";
    }
    else
    {
        obj.style.visibility = "hidden";
        obj.style.display = "none";
        
        img.src = "http://images.techlighting.com/Partners/icons/plus.gif";
    }
}

function showHideAccounts(obj)
{
    var accountObj = $get(obj);
    var img = $get('expCon_' + obj);
    
    if (accountObj.style.visibility == "hidden")
    {
        accountObj.style.visibility = "visible";
        accountObj.style.display = "block";
        
        img.src = "http://images.techlighting.com/Partners/icons/minus.gif";
    }
    else
    {
        accountObj.style.visibility = "hidden";
        accountObj.style.display = "none";
        
        img.src = "http://images.techlighting.com/Partners/icons/plus.gif";
    }
}

function hideLoading()
{
    var loadingObj = $get("progressBG");
    if (loadingObj.style.visibility == "visible") 
    {
        loadingObj.style.visibility = "hidden";
        loadingObj.style.display = "none";
    }
}
function showLoading()
{
    var loadingObj = $get("progressBG");
    if (loadingObj)
    {
        loadingObj.style.visibility = "visible";
        loadingObj.style.display = "block";
    }
}

function populateOrderDetail(orderNum, numType, isRep, jde, viewShipTos, customerJDE)
{
    showLoading();
    
    if (numType == "rga")
        Services.GetRGADetail(orderNum, isRep, jde, viewShipTos, CompletePopulateOrderDeatil);
    else
        Services.GetOrderDetail(orderNum, numType, isRep, jde, viewShipTos, customerJDE, CompletePopulateOrderDeatil);
}
function populateOrderDetail2(qs)
{
    window.open ("OrderDetail.aspx?" + qs, "_blank", "status=0,toolbar=0,location=0,menubar=1,directories=0,resizable=1,scrollbars=1,height=400,width=975");
}
function CompletePopulateOrderDeatil(arg)
{
    var panel = $find(prefix + "orderPanelMPE");
    var label = $get(prefix + "orderLabel");
    
    if (!arg || arg == '') arg = "The order you are looking for does not exist.<br />";
    //arg = arg.replace("'", "").replace("\"", "")
    
    label.innerHTML = arg;
    
    hideLoading();
    panel.show();
}

function checkAvailability(isPricing)
{
    var skuList = "";
    var qtyList = "";
    var err = "";

    for (i = 0; i < 10; i++)
    {    
        var sku = $get("sku_" + i).value;
        var qty = $get("qty_" + i).value;
        
        if (sku && qty)
        {
            skuList += sku + ",";
            qtyList += qty + ","
        }
        if ( (sku && !qty) || (!sku && qty) ) err = "boo!";
    }
    
    if (err != "boo!")
        Services.CheckAvailability(skuList, qtyList, isPricing, CompleteCheckAvailability);
    else
        alert("There is an error.\nMake sure you have inputed a valid quantity in the field.");
}
function CompleteCheckAvailability(arg)
{
    var panel = $find(prefix + "orderPanelMPE");
    var label = $get(prefix + "orderLabel");
    
    if (!arg || arg == '') arg = "The SKUs you are looking for either do not exist or are not available.<br />";
    
    label.innerHTML = arg;
    panel.show();
}

function showFiles(t, id, domain)
{
    var obj = $get(id);
    
    if (t.alt == "Expand")
    {
        obj.style.visibility = "visible";
        obj.style.display = "block";
        t.alt = "Collapse";
        t.src = domain + "/Partners/icons/minus.gif";
    }
    else
    {
        obj.style.visibility = "hidden";
        obj.style.display = "none";
        t.alt = "Expand";
        t.src = domain + "/Partners/icons/plus.gif";
    }
}

function displayFileData(title, desc, path, isLink, imgURL, ext)
{
    var bucketObj = $get("bucket");
    var imgObj = $get("dataIcon");
    var titleObj = $get("dataTitle");
    var descObj = $get("dataDescription");
    var iconObj = $get("dataIconSmall");
    var linkObj = $get("dataLink");
    
    // Show <DIV>
    bucketObj.style.visibility = "visible";
    bucketObj.style.display = "block";
    
    // Show Icons
    imgObj.src = imgURL + "/Partners/icons/" + ext + "_lrg.gif";
    iconObj.src = imgURL + "/Partners/icons/" + ext + ".gif";
    
    // Show Title
    titleObj.innerHTML = title;
    
    // Show Description
    descObj.innerHTML = desc;
    
    // Show Link
    if (isLink == "true") linkObj.innerHTML = "<a href='OpenLink.aspx?" + path + "' target='_blank'>Open Link in New Window</a>";
    else linkObj.innerHTML = "<a href='FileDownload.aspx?" + path + "'>Get \"" + title + "\" File</a>";
}

function hideFileData()
{
    var bucketObj = $get("bucket");
    bucketObj.style.visibility = "hidden";
    bucketObj.style.display = "none";
}

function showHideOrderDetails(id)
{
    var idObj = $get(id);
    
    if (idObj.style.display == "none")
        idObj.style.display = "block";
    else
        idObj.style.display = "none";
}

function checkTrainingCampFields(t,f)
{
    var addyObj = $get("addy");
    var cityObj = $get("city");
    var stateObj = $get("state");
    var zipObj = $get("zip");
    var companyObj = $get("company");
    
    if (!addyObj.value || !cityObj.value || !stateObj.value || !zipObj.value || !companyObj.value) alert("All fields are required");
    else 
    {
        t.disabled = true;
        f.submit();
    }
}

function doPromptRep()
{
    var rep = prompt("Please enter the rep's account number.", "");
    if (rep && rep != "" && !isNaN(rep))
    {
        var url = "action=editAccount&rep=" + rep
        Services.EncryptForRegionalManager(url, DoPromptRepComplete);
    }
    else alert("Invalid Rep Number");
}
function DoPromptRepComplete(arg)
{
    if (arg != null) window.location = "UserManagement.aspx?" + arg;
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
