﻿function QuickAddCart(mfgNumId, cartBundleID, objecttype, PageType)
{
    var txtMfgNum = document.getElementById(mfgNumId); var strValue = txtMfgNum.value.split('─')[0]; strValue = trim(strValue); if (strValue == '')
    { alert("Please enter a Manufacturer Part Number."); return false; }
    var result = ShoppingCartDoAjaxCall('FetchProductsByMfg', strValue, cartBundleID, objecttype); if (result == 0)
    { alert("No product found for given Manufacturer Part Number."); return false; }
    if (result == 1)
        return true;if (result > 1)
    {
        var height = 320; var width = 550; var LeftPosition = (screen.width) ? (screen.width - 700) / 2 : 0; var TopPosition = (screen.height) ? (screen.height - 600) / 2 : 0; var settings = 'height=' + height + ',width=' + width + ',top=' + TopPosition + ',left=' + LeftPosition + ',menubar=0,location=0,scrollbars=0,resizable=0,status=0,toolbar=0';
        var pageURL = '../../UI/Carts/ProductsList.aspx?MfgNum=';
        var IsRedirectionNeededForShoppingCart = false;
        if (PageType == 'SECURE')
        {
            pageURL = '../../Secure/Carts/ProductsList.aspx?MfgNum=';
            IsRedirectionNeededForShoppingCart = true;
        }
        
        window.open(pageURL + strValue + '&cartBundleID=' + cartBundleID + '&type=' + objecttype + '&IsRedirectionNeededForShoppingCart=' + IsRedirectionNeededForShoppingCart, 'XYZ', settings); return false;
    }
}
function HideCartItem(itemid)
{ return confirm("Are you sure you want to delete this item from Cart"); }
function ShoppingCartDoAjaxCall(strEvent, strValue, cartBundleID, type) {
    var requestURL = "../../UI/Common/AjaxCall.aspx";
    var qString = strEvent + "=" + strValue;
    if (cartBundleID != null && cartBundleID != '' && cartBundleID != undefined) {
        qString += "&cartBundleID=" + cartBundleID;
        qString += "&type=" + type;
    }
    else if (type == undefined || type == '') {
        qString += "&type=cart";
    }
    var result = Post_Data(requestURL, qString); return result;
}
function CheckUncheckShippingMtd(rdrClientId, selectedShippingData, hdnRadiobtnID, hdnShippingDataID) {
    document.getElementById(hdnShippingDataID).value = selectedShippingData; var hdnPrevClientId = document.getElementById(hdnRadiobtnID).value; if (hdnPrevClientId == '')
    { document.getElementById(hdnRadiobtnID).value = rdrClientId; document.getElementById(rdrClientId).checked = true; }
    if (hdnPrevClientId != '') {
        if (document.getElementById(hdnPrevClientId).value == rdrClientId); else
        { var prevChecked = document.getElementById(hdnPrevClientId); prevChecked.checked = false; document.getElementById(rdrClientId).checked = true; document.getElementById(hdnRadiobtnID).value = rdrClientId; } 
    } 
}
function CancelClicked()
{ window.close(); }
function AddSelectedProdToCart(cartBundleID, objecttype, IsRedirectionNeededForShoppingCart, shoppingcartURL)
{
    var strValue = document.getElementById('hdnProdData').value; if (document.getElementById('hdnProdData').value == '')
    { alert('Please select at least one product from list.'); return false; }
    else
    { var result = ShoppingCartDoAjaxCall('FetchProductsByMfg', strValue, cartBundleID, objecttype); window.opener.location.href = window.opener.location.href; if (IsRedirectionNeededForShoppingCart != undefined && IsRedirectionNeededForShoppingCart == 'true') { window.opener.location.href = shoppingcartURL; } window.close(); }
    //{ var result = ShoppingCartDoAjaxCall('AddQuickCartItem', strValue, cartBundleID, objecttype); window.opener.location.href = window.opener.location.href; if (IsRedirectionNeededForShoppingCart != undefined && IsRedirectionNeededForShoppingCart == 'true') { window.opener.location.href = shoppingcartURL; } window.close(); } 
}
function CheckUncheckProduct(rdrClientId, selectedProdData) {
    document.getElementById('hdnProdData').value = selectedProdData; var hdnPrevClientId = document.getElementById('hdnRadiobtnClientId').value; if (hdnPrevClientId == '')
    { document.getElementById('hdnRadiobtnClientId').value = rdrClientId; document.getElementById(rdrClientId).checked = true; }
    if (hdnPrevClientId != '') {
        if (document.getElementById(hdnPrevClientId).value == rdrClientId); else
        { var prevChecked = document.getElementById(hdnPrevClientId); prevChecked.checked = false; document.getElementById(rdrClientId).checked = true; document.getElementById('hdnRadiobtnClientId').value = rdrClientId; } 
    } 
}
function ValidateQuotesOrdersTxtBoxes(validatorIds, rdrNewShippingAddress, chkSaveAddress) {
    var validatorIdList = validatorIds.split('µ'); if (document.getElementById(rdrNewShippingAddress).checked == false) {
        for (index = 0; index < validatorIdList.length; index++)
        { ValidatorEnable(document.getElementById(validatorIdList[index]), false); } 
    }
    else {
        var startIndex; if (document.getElementById(chkSaveAddress).checked == true)
        { startIndex = 0; }
        else
        { startIndex = 1; ValidatorEnable(document.getElementById(validatorIdList[0]), false) }
        for (index = startIndex; index < validatorIdList.length; index++)
        { ValidatorEnable(document.getElementById(validatorIdList[index]), true); } 
    } 
}
function ValidateOrderBillingPaymentMethod(validatorIds, rdrNewPayMentOption, rdrOthers, chkSavePaymentMethhod) {
    var validatorIdList = validatorIds.split(','); if (document.getElementById(rdrNewPayMentOption) != null) {
        ValidatorEnable(document.getElementById(validatorIdList[0]), document.getElementById(rdrNewPayMentOption).checked)
        ValidatorEnable(document.getElementById(validatorIdList[1]), document.getElementById(rdrNewPayMentOption).checked)
    }
    if (document.getElementById(rdrNewPayMentOption).checked) {
        if (document.getElementById(rdrOthers).checked) {
            for (index = 2; index < validatorIdList.length; index++)
            { ValidatorEnable(document.getElementById(validatorIdList[index]), false); } 
        }
        else {
            for (index = 2; index < validatorIdList.length; index++)
            { ValidatorEnable(document.getElementById(validatorIdList[index]), true); } 
        } 
    }
    else {
        for (index = 2; index < validatorIdList.length; index++)
        { ValidatorEnable(document.getElementById(validatorIdList[index]), false); } 
    } 
}