﻿function addToCart_success(e)
{
    if ($get("CartSummary") != null)
        $get("CartSummary").innerHTML = e.toString();
}

function addToCart_failed()
{
}

function setAffiliate_success(e)
{
    //alert(e.toString());
}

function setAffiliate_failed()
{
}

function getHomPromoChart_success(e)
{
    if ($get("scrollPaneHorz") != null)
        $get("scrollPaneHorz").innerHTML = e.toString();
    scrollPosHorz=0;
	$("#scrollPaneHorz").animate( { marginLeft: '0px'}, 400 );
    $(".addCartBtn").click(function() {
        var prodId = $(this).parent("div").find("input").attr("value");
        $(this).html("IN BASKET");
        Sanity.Public.Services.UserCart.AddToCart(prodId, addToCart_success, addToCart_failed);
        return false;
    });
}

function getHomPromoChart_failed()
{

}

function showMap_success(e)
{
    $(".mapPanel").html("");
    $(".mapPanelVisible").html(e.toString());
    return false;
}

function showMap_failed()
{

}

function setRating(sender, rating)
{  
    var hiddenField = $("#ctl00_BodyCph_RatingHf").attr("value", rating);
    $(".rating").removeClass("selected");

    $("#"+sender.id).addClass("selected");
    
    return false;
}

function locatorShowMap(storeId)
{
    $(".mapPanelVisible").addClass("mapPanel");
    $(".mapPanelVisible").removeClass("mapPanelVisible");

    var newMapId = "#mapEmbed"+storeId;

    if ($(newMapId) != null)
        $(newMapId).addClass("mapPanelVisible");

	Sanity.Public.Services.ShowMap.GetMap(storeId, showMap_success, showMap_failed);
}

function stateChanged()
{
    var billCountry = document.getElementById("ctl00_BodyCph_BillCountryDdl");
    var billState = document.getElementById("ctl00_BodyCph_BillStateTb");
    var billStateDdl =  document.getElementById("ctl00_BodyCph_BillStateDdl");

    var delCountry = document.getElementById("ctl00_BodyCph_DelCountryDdl");
    var delState = document.getElementById("ctl00_BodyCph_DelStateTb");
    var delStateDdl = document.getElementById("ctl00_BodyCph_DelStateDdl");

    if (delCountry != null)
    {
        if (delCountry.selectedIndex == 0)
        {
            delState.className = "hide";
            delStateDdl.className = "show";
        }
        else
        {
            delState.className = "show";
            delStateDdl.className = "hide";
        }
    }
    if (billCountry != null)
    {
        if (billCountry.selectedIndex == 0)
        {
            billState.className = "hide";
            billStateDdl.className = "show";
        }
        else
        {
            billState.className = "show";
            billStateDdl.className = "hide";
        }
    }
    
    return false;
}

function copyEmail(emailTb)
{
    var emailSpan = document.getElementById("ShowEmailSp");
    if (emailTb.value == "")
        emailSpan.innerHTML = "Enter email above";
    else
        emailSpan.innerHTML = emailTb.value;
}

function copyAddressFields()
{
    var billSalutation = document.getElementById("ctl00_BodyCph_BillSalutationDdl");
    var billFirstName = document.getElementById("ctl00_BodyCph_BillFirstNameTb");
    var billLastName = document.getElementById("ctl00_BodyCph_BillLastNameTb");
    var billCompany = document.getElementById("ctl00_BodyCph_BillCompanyTb");
    var billPhone = document.getElementById("ctl00_BodyCph_BillPhoneTb");
    var billAddress1 = document.getElementById("ctl00_BodyCph_BillAddress1Tb");
    var billAddress2 = document.getElementById("ctl00_BodyCph_BillAddress2Tb");
    var billSuburb = document.getElementById("ctl00_BodyCph_BillSuburbTb");
    var billCountry = document.getElementById("ctl00_BodyCph_BillCountryDdl");
    var billState = document.getElementById("ctl00_BodyCph_BillStateTb");
    var billStateDdl =  document.getElementById("ctl00_BodyCph_BillStateDdl");
    var billPostCode = document.getElementById("ctl00_BodyCph_BillPostCodeTb");
    
    var delSalutation = document.getElementById("ctl00_BodyCph_DelSalutationDdl");
    var delFirstName = document.getElementById("ctl00_BodyCph_DelFirstNameTb");
    var delLastName = document.getElementById("ctl00_BodyCph_DelLastNameTb");
    var delCompany = document.getElementById("ctl00_BodyCph_DelCompanyTb");
    var delAddress1 = document.getElementById("ctl00_BodyCph_DelAddress1Tb");
    var delAddress2 = document.getElementById("ctl00_BodyCph_DelAddress2Tb");
    var delSuburb = document.getElementById("ctl00_BodyCph_DelSuburbTb");
    var delCountry = document.getElementById("ctl00_BodyCph_DelCountryDdl");
    var delState = document.getElementById("ctl00_BodyCph_DelStateTb");
    var delStateDdl = document.getElementById("ctl00_BodyCph_DelStateDdl");
    var delPostCode = document.getElementById("ctl00_BodyCph_DelPostCodeTb");
    
    delSalutation.selectedIndex = billSalutation.selectedIndex;
    delStateDdl.selectedIndex = billStateDdl.selectedIndex;
    delFirstName.value = billFirstName.value;
    delLastName.value = billLastName.value;
    delCompany.value = billCompany.value;
    delAddress1.value = billAddress1.value;
    delAddress2.value = billAddress2.value; 
    delSuburb.value = billSuburb.value;
    delCountry.selectedIndex = billCountry.selectedIndex;
    delState.value = billState.value;
    delPostCode.value = billPostCode.value;
    
    stateChanged();
    return false;    
}
