﻿function wsfCoupon(coupon)
{
    wsStoreSite.Coupon(coupon,
        wsfCouponOnSucceeded,
        wsfCouponOnFailed);
}
function wsfCouponOnSucceeded(s){}
function wsfCouponOnFailed(s){}
//------------------------------------------------------------------------
//------------------- region SETTING CART PROPERTY -----------------------
function wsfSetCartPropertySelect(iCartRow, idProduct, idGroup, idProperty)
{
    wsStoreSite.SetCartPropertySelect(
        iCartRow,
        idProduct,
        idGroup,
        idProperty,
        wsfSetCartPropertySelectOnSucceeded,
        wsfSetCartPropertySelectOnFailed);
}
function wsfSetCartPropertySelectOnSucceeded(json){ if(json != null) { wsfSetCartProperty(json); }}
function wsfSetCartPropertySelectOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetCartPropertyCheckBox(iCartRow, idProduct, idGroup, idProperty, isChecked)
{
    wsStoreSite.SetCartPropertyCheckBox(
        iCartRow,
        idProduct,
        idGroup,
        idProperty,
        isChecked,
        wsfSetCartPropertyCheckBoxOnSucceeded,
        wsfSetCartPropertyCheckBoxOnFailed);
}
function wsfSetCartPropertyCheckBoxOnSucceeded(json){ if(json != null) { wsfSetCartProperty(json); }}
function wsfSetCartPropertyCheckBoxOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetCartPropertyRadioButton(iCartRow, idProduct, idGroup, idProperty)
{
    wsStoreSite.SetCartPropertyRadioButton(
        iCartRow,
        idProduct,
        idGroup,
        idProperty,
        wsfSetCartPropertyRadioButtonOnSucceeded,
        wsfSetCartPropertyRadioButtonOnFailed);
}
function wsfSetCartPropertyRadioButtonOnSucceeded(json){ if(json != null) { wsfSetCartProperty(json); }}
function wsfSetCartPropertyRadioButtonOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetCartPropertyTextBox(iCartRow, idProduct, idGroup, idProperty, value)
{
    wsStoreSite.SetCartPropertyTextBox(
        iCartRow,
        idProduct,
        idGroup,
        idProperty,
        value,
        wsfSetCartPropertyTextBoxOnSucceeded,
        wsfSetCartPropertyTextBoxOnFailed);
}
function wsfSetCartPropertyTextBoxOnSucceeded(json){ if(json != null) { wsfSetCartProperty(json); }}
function wsfSetCartPropertyTextBoxOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetCartProperty(json)
{
    if((json.sSideCart != null) && (json.sFullCart!=null))
    {
	    if(null != (e = $get('divSideCart')))
	        e.innerHTML = json.sSideCart;

	    if(null != (e = $get('divFullCart')))
	        e.innerHTML = json.sFullCart;
    }
    else
    {
        var id = '@' + json.sPID + '@' + json.sCRI;

	    if(null != (e = $get('spanSideCartCN'+id)))
	        e.innerHTML = json.sCN;

	    if(null != (e = $get('spanSideCartQuantity'+id)))
	        e.innerHTML = json.sQuantity;
	        
	    if(null != (e = $get('spanSideCartPriceSite'+id)))
	        e.innerHTML = json.sPriceSiteFormatted;

	    if(null != (e = $get('spanSideCartPrice'+id)))
	        e.innerHTML = json.sPriceFormatted;
	        
	    if(null != (e = $get('spanFullCartCN'+id))) {
	        e.innerHTML = json.sCN;}

	    if(null != (e = $get('spanFullCartPriceSite'+id)))
	        e.innerHTML = json.sPriceSiteFormatted;

	    if(null != (e = $get('spanFullCartPrice'+id)))
	        e.innerHTML = json.sPriceFormatted;

	    if(null != (e = $get('divFullCartPicture'+id)))
	        e.innerHTML = json.sPicture;

        if(json.csStockLevels!=null)
        {
            for(i = 0; i < json.csStockLevels.length; i++)
            {
                id = '@' + json.csStockLevels[i].sPID + '@' + json.csStockLevels[i].sCRI;
	            if(null != (e = $get('divFullCartStockLevelStatus'+id)))
	                e.innerHTML = json.csStockLevels[i].sStockLevelStatus;
            }
        }
    }

	if(null != (e = $get('divSideCartSummation')))
	    e.innerHTML = json.sSideCartSummation;

	if(null != (e = $get('divFullCartSummation')))
	    e.innerHTML = json.sFullCartSummation;
}
//------------------- endregion SETTING CART PROPERTY --------------------
//------------------------------------------------------------------------
//------------------- region SETTING PROPERTY ----------------------------
function wsfSetPropertySelect(idProduct, idGroup, idProperty)
{
    wsStoreSite.SetPropertySelect(
        idProduct,
        idGroup,
        idProperty,
        wsfSetPropertySelectOnSucceeded,
        wsfSetPropertySelectOnFailed);
}
function wsfSetPropertySelectOnSucceeded(json)
{
	if(null != (e = $get('divSitePrice')))
	    e.innerHTML = json.sCoin + '&nbsp;' + json.sPriceSiteFormatted;

	if(null != (e = $get('divSaving')))
	    e.innerHTML = json.sCoin + '&nbsp;' + json.sSavingFormatted;

//    if(null != (e = $get('divPicture')))
//        e.innerHTML = json.sPicture;

	if(json.sStockMatrix == 'true')
	{
	    if(null != (e = $get('divCN')))
	        e.innerHTML = json.sCN;

	    if(null != (e = $get('divStockLevel')))
	        e.innerHTML = json.sStockLevelMinusQuantity;

	    if(null != (e = $get('divStockLevelStatus')))
	        e.innerHTML = json.sStockLevelStatus;
    }
}
function wsfSetPropertySelectOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetPropertyCheckBox(idProduct, idGroup, idProperty, isChecked)
{
    wsStoreSite.SetPropertyCheckBox(
        idProduct,
        idGroup,
        idProperty,
        isChecked,
        wsfSetPropertyCheckBoxOnSucceeded,
        wsfSetPropertyCheckBoxOnFailed);
}
function wsfSetPropertyCheckBoxOnSucceeded(json)
{
	if(null != (e = $get('divSitePrice')))
	    e.innerHTML = json.sPriceSiteFormatted + json.sCoin;

	if(null != (e = $get('divSaving')))
	    e.innerHTML = json.sSavingFormatted + json.sCoin;
}
function wsfSetPropertyCheckBoxOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetPropertyRadioButton(idProduct, idGroup, idProperty)
{
    wsStoreSite.SetPropertyRadioButton(
        idProduct,
        idGroup,
        idProperty,
        wsfSetPropertyRadioButtonOnSucceeded,
        wsfSetPropertyRadioButtonOnFailed);
}
function wsfSetPropertyRadioButtonOnSucceeded(json)
{
	if(null != (e = $get('divSitePrice')))
	    e.innerHTML = json.sPriceSiteFormatted + json.sCoin;

	if(null != (e = $get('divSaving')))
	    e.innerHTML = json.sSavingFormatted + json.sCoin;
}
function wsfSetPropertyRadioButtonOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateStandardsAcceptance(accepted)
{
    wsStoreSite.UpdateStandardsAcceptance(
        accepted,
        wsfUpdateStandardsAcceptanceOnSucceeded,
        wsfUpdateStandardsAcceptanceOnFailed);
}
function wsfUpdateStandardsAcceptanceOnSucceeded(json){}
function wsfUpdateStandardsAcceptanceOnFailed(err){}
//------------------------------------------------------------------------
function wsfSetPropertyTextBox(idProduct, idGroup, idProperty, value)
{
    wsStoreSite.SetPropertyTextBox(
        idProduct,
        idGroup,
        idProperty,
        value,
        wsfSetPropertyTextBoxOnSucceeded,
        wsfSetPropertyTextBoxOnFailed);
}
function wsfSetPropertyTextBoxOnSucceeded(json){}
function wsfSetPropertyTextBoxOnFailed(err){}
//------------------- endregion SETTING PROPERTY -------------------------
//------------------------------------------------------------------------
function wsfSetProductQuantity(quantity)
{
    wsStoreSite.SetProductQuantity(
        quantity,
        wsfSetProductQuantityOnSucceeded,
        wsfSetProductQuantityOnFailed);
}
function wsfSetProductQuantityOnSucceeded(json)
{
	if(null != (e = $get('divStockLevel')))
	    e.innerHTML = (json.sStockLevelMinusQuantity < 0 ) ?
	        '0' : json.sStockLevelMinusQuantity;

	if(null != (e = $get('divStockLevelStatus')))
	    e.innerHTML = json.sStockLevelStatus;
}
function wsfSetProductQuantityOnFailed(err){}
//------------------------------------------------------------------------
function wsfDeleteCartProduct(idProduct, idCartRowIndex)
{
    wsStoreSite.DeleteCartProduct(
        idProduct,
        idCartRowIndex,
        wsfDeleteCartProductOnSucceeded,
        wsfDeleteCartProductOnFailed);
}
function wsfDeleteCartProductOnSucceeded(json)
{
	if(null != (e = $get('divSideCart')))
	    e.innerHTML = json.sSideCart;

	if(null != (e = $get('divSideCartSummation')))
	    e.innerHTML = json.sSideCartSummation;

	if(null != (e = $get('divFullCart')))
	    e.innerHTML = json.sFullCart;

	if(null != (e = $get('divFullCartSummation')))
	    e.innerHTML = json.sFullCartSummation;

	if(null != (e = $get('divOrderCart')))
	    e.innerHTML = json.sOrderCart;

	if(null != (e = $get('divOrderCartSummation')))
	    e.innerHTML = json.sOrderCartSummation;

	if(null != (e = $get('divCreditCardPayments')))
	    e.innerHTML = json.sCreditCardPayments;
}
function wsfDeleteCartProductOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateCartProductQuantity(idProduct, idCartRowIndex, quantity)
{
    wsStoreSite.UpdateCartProductQuantity(
        idProduct,
        idCartRowIndex,
        quantity,
        wsfUpdateCartProductQuantityOnSucceeded,
        wsfUpdateCartProductQuantityOnFailed);
}
function wsfUpdateCartProductQuantityOnSucceeded(json)
{
    var id = '@' + json.sPID + '@' + json.sCRI;

	if(null != (e = $get('spanSideCartQuantity'+id)))
	    e.innerHTML = json.sQuantity;

	if(null != (e = $get('spanSideCartPrice'+id)))
	    e.innerHTML = json.sPriceFormatted;

	if(null != (e = $get('divSideCartSummation')))
	    e.innerHTML = json.sSideCartSummation;

	if(null != (e = $get('spanFullCartPrice'+id)))
	    e.innerHTML = json.sPriceFormatted;

	if(null != (e = $get('divFullCartSummation')))
	    e.innerHTML = json.sFullCartSummation;

    for(i = 0; i < json.csStockLevels.length; i++)
    {
        id = '@' + json.csStockLevels[i].sPID + '@' + json.csStockLevels[i].sCRI;
	    if(null != (e = $get('divFullCartStockLevelStatus'+id)))
	        e.innerHTML = json.csStockLevels[i].sStockLevelStatus;
    }
}
function wsfUpdateCartProductQuantityOnFailed(err){}
//------------------------------------------------------------------------
function wsfDeleteHistoryProduct(idProductToDelete, idProductException)
{
    wsStoreSite.DeleteHistoryProduct(
        idProductToDelete,
        idProductException,
        wsfDeleteHistoryProductOnSucceeded,
        wsfDeleteHistoryProductOnFailed);
}
function wsfDeleteHistoryProductOnSucceeded(json)
{
	if(null != (e = $get('divHistory')))
	    e.innerHTML = json.sHistory;
}
function wsfDeleteHistoryProductOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateOrderComment(idComment, comment)
{
    wsStoreSite.UpdateOrderComment(
        idComment,
        comment,
        wsfUpdateOrderCommentOnSucceeded,
        wsfUpdateOrderCommentOnFailed);
}
function wsfUpdateOrderCommentOnSucceeded(json){}
function wsfUpdateOrderCommentOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateCustomerDetails(o)
{
    wsStoreSite.UpdateCustomerDetails(o,
        wsfUpdateCustomerDetailsOnSucceeded,
        wsfUpdateCustomerDetailsOnFailed);
}
function wsfUpdateCustomerDetailsOnSucceeded(json){}
function wsfUpdateCustomerDetailsOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateShipmentAddress(o)
{
    wsStoreSite.UpdateShipmentAddress(o,
        wsfUpdateShipmentAddressOnSucceeded,
        wsfUpdateShipmentAddressOnFailed);
}
function wsfUpdateShipmentAddressOnSucceeded(res){}
function wsfUpdateShipmentAddressOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateShipmentDetails(idShipment)
{
    wsStoreSite.UpdateShipmentDetails(idShipment,
        wsfUpdateShipmentDetailsOnSucceeded,
        wsfUpdateShipmentDetailsOnFailed);
}
function wsfUpdateShipmentDetailsOnSucceeded(res){}
function wsfUpdateShipmentDetailsOnFailed(err){}
//------------------------------------------------------------------------
function wsfUpdateCreditCardDetails(o)
{
    wsStoreSite.UpdateCreditCardDetails(o,
        wsfUpdateCreditCardDetailsOnSucceeded,
        wsfUpdateCreditCardDetailsOnFailed);
}
function wsfUpdateCreditCardDetailsOnSucceeded(res){}
function wsfUpdateCreditCardDetailsOnFailed(err){alert('failure');}
//------------------------------------------------------------------------
function wsfUpdatePurchaseDetails(idPurchase)
{
    wsStoreSite.UpdatePurchaseDetails(
        idPurchase,
        wsfUpdatePurchaseDetailsOnSucceeded,
        wsfUpdatePurchaseDetailsOnFailed);
}
function wsfUpdatePurchaseDetailsOnSucceeded(res){}
function wsfUpdatePurchaseDetailsOnFailed(err){}
//------------------------------------------------------------------------
function wsfSignIn(o)
{
    wsStoreSite.SignIn(o,
        wsfSignInOnSucceeded,
        wsfSignInOnFailed);
}
function wsfSignInOnSucceeded(json)
{
    if(json.sID != '0')
    {
        $get('m_cphBody_ucPurchaseStep1_txtCustomerFirstName').value = json.sFirstName;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerLastName').value = json.sLastName;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerCompany').value = json.sCompany;
            wsfSelect('m_cphBody_ucPurchaseStep1_ddlCustomerCountry', json.sCountryID);
        $get('m_cphBody_ucPurchaseStep1_txtCustomerCity').value = json.sCity;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerStreet').value = json.sStreet;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerHome').value = json.sHome;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerZIP').value = json.sZIP;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerPhone').value = json.sPhone;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerCellular').value = json.sCellular;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerFax').value = json.sFax;
            wsfSelect('m_cphBody_ucPurchaseStep1_ddlCustomerBirthdayMonth', json.sBirthday.split('.')[0]);
            wsfSelect('m_cphBody_ucPurchaseStep1_ddlCustomerBirthdayDay', json.sBirthday.split('.')[1]);
            wsfSelect('m_cphBody_ucPurchaseStep1_ddlCustomerBirthdayYear', json.sBirthday.split('.')[2]);
            wsfSelect('m_cphBody_ucPurchaseStep1_ddlCustomerType', json.sCustomerTypeID);
            
        $get('m_cphBody_ucPurchaseStep1_txtCustomerEmail').value = 
            $get('m_cphBody_ucPurchaseStep1_txtCustomerEmailHidden').value = json.sEmail;
            
        $get('m_cphBody_ucPurchaseStep1_txtCustomerPassword').value = 
            $get('m_cphBody_ucPurchaseStep1_txtCustomerPasswordHidden').value = json.sPassword;
            
        $get('m_cphBody_ucPurchaseStep1_txtCustomerComments').value = json.sComments;
        $get('m_cphBody_ucPurchaseStep1_txtCustomerSchoolName').value = json.sSchoolName;

//        $get('m_cphBody_ucPurchaseStep1_txtShipmentFirstName').value = json.sFirstName;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentLastName').value = json.sLastName;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentCompany').value = json.sCompany;
//            wsfSelect('m_cphBody_ucPurchaseStep1_ddlShipmentCountry', json.sCountryID);
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentCity').value = json.sCity;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentStreet').value = json.sStreet;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentHome').value = json.sHome;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentZIP').value = json.sZIP;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentPhone').value = json.sPhone;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentCellular').value = json.sCellular;
//        $get('m_cphBody_ucPurchaseStep1_txtShipmentFax').value = json.sFax;
        
        $get('divUserDoesNotExist').style.display = 'none';
    }
    else $get('divUserDoesNotExist').style.display = '';

    $get('m_cphBody_ucPurchaseStep1_txtSignInEmail').value = '';
    $get('m_cphBody_ucPurchaseStep1_txtSignInPassword').value = '';
}
function wsfSignInOnFailed(err){}
function wsfSelect(id,value)
{
    if(null != (e = $get(id))) {
        for(i=0;i<e.length;i++) {
            if(e.options[i].value == value) {
                e.selectedIndex = i; break; }}}
}
//------------------------------------------------------------------------
function wsfInfiniteSession()
{
    wsStoreSite.InfiniteSession(
        wsfInfiniteSessionOnSucceeded,
        wsfInfiniteSessionOnFailed);
}
function wsfInfiniteSessionOnSucceeded(s){/*alert('infinite');*/}
function wsfInfiniteSessionOnFailed(s){/*alert('failure');*/}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
