﻿function doOpen(sURL) {
    window.open(sURL, '_blank', 'left=300,top=300,width=330,height=355,toolbar=0,resizable=1,status=0,location=0,scrollbars=1');
}


function doRedirect(sURL)
{
    var sHttp = window.location.hostname;
    window.parent.location = "http://" + sHttp + sURL;
}

function doLogin(sCaller, sProduct)
{
    var sHttp = window.location.hostname;
    var sURL = "";
    if (sCaller == "fastorderpad")
    {
        sURL = "/apps/customerlogin/customerlogin.aspx?Redirect=/apps/ordering/fastorder.aspx?txtProduct=" + sProduct + "&caller=" + sCaller;
         window.parent.location = "http://" + sHttp + sURL;
    }
    else if (sCaller == "price")
    {
        sURL = "/apps/customerlogin/customerlogin.aspx?Redirect=/apps/sitesearch/Search.aspx?query=" + sProduct;
       doCatalog(sURL);
    }

}

function doCatalog(sURL)
{
    if (document.getElementById("ctl00_ctl00_hdnCaller"))
    {    
        document.getElementById("ctl00_ctl00_hdnCaller").value = "price";
        //alert(document.getElementById("ctl00_ctl00_hdnCaller").value);
    }   
    doRedirect(sURL);
}

function doRedirectSecure(sURL)
{
    var sHttp = window.location.hostname;
    window.parent.location = "https://" + sHttp + sURL;
}

function click_AddItem(sProduct, sProdID, sCaller) 
{

    if (document.getElementById("ctl00_ctl00_cp1b_txtOrderQty"))
    {        
        var sQty = document.getElementById("ctl00_ctl00_cp1b_txtOrderQty").value;      
        var sHost = window.location.hostname;
        var sRedirect = "";
     
        sRedirect = "http://" + sHost + "/apps/ordering/fastOrderPad.aspx";

        if (sCaller == "price")
        {
           sCaller = "cat";
        }     

        // at this point sCaller is either cat or fastorderpad (same as "");
        var sURL = "/apps/order/insertItem.asp?hdnRedirect=" + sRedirect + "&refresh=false&caller=" + sCaller + "&Product=" + sProduct + "&Qty=" + sQty + "&ProductID=" + sProdID;        
	    window.location = "http://" + sHost + sURL;
    }
} //click_AddItem


function click_AddSafeliteItem(sProduct, sessionid) {

    if (document.getElementById("ctl00_ctl00_cp1b_txtOrderQty")) {
        var sQty = document.getElementById("ctl00_ctl00_cp1b_txtOrderQty").value;
        var sHost = window.location.hostname;
        var sRedirect = "";

        //alert(sessionid);
        Ordering.Cart.AddACartItem(sQty, sProduct, sessionid, AddItemReturn, ErrorHandler, TimeOutHandler);

        document.getElementById("ctl00_ctl00_cp1b_txtOrderQty").value = "";
        //top.document.forms[0].submit();
        parent.location.reload();
        //window.parent.location.href = window.parent.location.href;
    }
    
} //click_AddSafeliteItem


function AddItemReturn(result) {
    
    //Err is the type of error message that the user should never see.
    if (result.Err) {alert(result.Err); ShowMess(result.Err, true); return; }
    //check for any redirects

    //for testing, just display the location
    if (result.Redirect) { parent.location = result.Redirect; }
    //if(result.Redirect){ShowMess(result.Redirect), true; return;}

    //check for messages for the end user.
    if (result.Mess) { ShowMess(result.Mess, false); }

} //AddItemReturn

function ErrorHandler(result) {
    var msg = result.get_exceptionType() + "\r\n";
    msg += result.get_message() + "\r\n";
    msg += result.get_stackTrace();
    ShowMess(msg, true);
}

function TimeOutHandler(result) {
    ShowMess("Timeout :" + result, true);
}

function ShowMess(sMess, bRealErr) {
        var sClass = "";
        if (sMess == "") { sClass = "hide"; }
        else { sClass = "floatL"; }
        
    document.getElementById("ctl00_ctl00_cp1b_pnlGroup4").className = sClass;
    document.getElementById("ctl00_ctl00_cp1b_lblMessCart").innerHTML = sMess;
        
} //ShowMess
