$(document).ready(function() {


    // Product page delivery regions
//    DeliveryRegions();

    // Sidebar search
//    FindProductID();


});

/*

function DeliveryRegions() {
    $('#accordion1').accordion({
        header: "h3.deliveryregion"
    });
}


*/



function FindProductID() {

	$("#mainsearch").autocomplete("ajax.aspx", {
    	selectFirst: false,
		width:300,
		matchSubset:false,
		extraParams: { requesttype: 1 }
    }).result(function(event, item) {
    location.href = 'product.aspx?sidebarsearch=' + String(item).split(":")[0];
		
});


}


function BasketAdd(skudeliveryregionid) {
    $.post('ajax.aspx', {
        skudeliveryregionid: skudeliveryregionid,
        requesttype: 1
    }, function() {
        alert('The item has been added to your basket');
    });
}


function SaveGeoCoordinatesToSession(geo) {
    $.post('ajax.aspx', {
        geo: geo,
        requesttype: 2
    }, function() {
        alert('The co-ordinates have been saved and will be added to your delivery address at the checkout');
    });
}



function ConfirmCancel(f) {
    if (confirm('Are you sure you want to cancel this order?'))
        {
    document.frmmain.actionx.value = 3;
    document.frmmain.submit();
    }
}





function ValidateRegistration(f) {


    if (f.email.value == "") {
        alert('Please enter your email address');
        f.email.focus();
        return false;
    }

    else if ((f.firstname.value == "") || (f.lastname.value == "")) {
        alert('Please enter your firstname and lastname');
        return false;
    }

    else if (f.pwd.value == "") {
        alert('Please choose a password for your account');
        f.pwd.focus();
        return false;
    }


    else
        return true;

}





function ValidateCheckoutBillingAddress(f) {

    if ((f.invoiceaddr1.value == "") || (f.invoicecity.value == "") || (f.invoicepostcode.value == "")) {
        alert('Please make sure you have entered a valid billing address, including a city and postcode');
        return false;
    }

    else
        return true;

}


function ValidateCheckoutDeliveryAddress(f) {

    if ((f.deliveryaddr1.value == "") || (f.deliverycity.value == "") || (f.deliverypostcode.value == "")) {
        alert('Please make sure you have entered a valid delivery address, including a city and postcode');
        return false;
    }

    else
        return true;

}

