
$(function() {
    initTopnavLinks();
    if ($('#header .hdrLogout').length > 0) {
        $('.hdrLogout a').fadeTo('fast', 0.8);
        $('.hdrLogout a').hover(function() { $(this).fadeTo('fast', 1); }, function() { $(this).fadeTo('fast', 0.8); });
    }


    $('.print a').click(function(e) {
        e.preventDefault();
        window.print();
    });



    $('#oBasket').jqm();

    $('#bContinue').click(function() {
        $('#oBasket').jqmHide();
    });

    $('#bCheckout').click(function() {
        $('#oBasket').jqmHide();
        if (document.location.hostname == "www.spectrum-thea.co.uk") {
            location.href = 'https://www.spectrum-thea.co.uk/shop/paymentType.aspx';
        } else {
            location.href = '/shop/paymentType.aspx';
        }
    });

    $('.btnAddToBasket').click(function(e) {
        e.preventDefault();
        var productID = $(this).parent().find('input[name=hidProductId]').val();
        var userID = $(this).parent().find('input[name=hidUserId]').val();
        var sessionID = $(this).parent().find('input[name=hidSessionId]').val();
        AddToBasket(productID, userID, sessionID);
    });
    
});



function AddToBasket(productID, userID, sessionID) {
    Spectrum.WebServices.Basket.Add(productID, 1, userID, sessionID, AddToBasketComplete);
}

function AddToBasketComplete(result)
{
    if ( result.Success == true ) 
    {
        var text = 'items'
        if (result.ItemsCount.toString() == '1')
            text = 'item'; 
        
        $('#basketItemCount').html(result.ItemsCount.toString() + ' ' + text);
        $('#basketItemValue').html(result.Value);
        $('#oBasket').jqmShow();
    }
}










function fnTrapKBDoNothingOnReturn(event) {
/*
	if (document.all)
	{
		if (event.keyCode == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			//do nothing, don't submit the page
		}
	}
	else if (document.getElementById)
	{
		if (event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			//do nothing, don't submit the page
		}
	}
	else if(document.layers)
	{
		if(event.which == 13)
		{
			event.returnValue=false;
			event.cancel = true;
			//do nothing, don't submit the page
		}
	}
*/
}

function ClearText(ctrlId)
{
    var ctrl = document.getElementById(ctrlId);
    ctrl.value="";
}

function ResetText(ctrlId, text)
{
    var ctrl = document.getElementById(ctrlId);
    //ctrl.value="";
    if(ctrl.value == ""){
        ctrl.value = text}    
}


var alertQty = false;
function basketQtyChanged() {
    alertQty = true;
    //alert('Please press the \'update quantity\' button to see the updated totals.');
}

function alertBasketQuantityChanged(){
    if(alertQty){
        alert('Please press the \'update quantity\' button to see the updated totals.');
    }
}


function initTopnavLinks() {      
    var subOpenClass = 'subOpen';
    $('.nav li div').hover(function() {
        $(this).prev().addClass(subOpenClass);
    }, function() {
        $(this).prev().removeClass(subOpenClass);
    });
}
