var bmlpromodisabled;

function showhideattr(i) {

    $("#attr_" + i).toggle();
    $("#attrDetails_" + i).toggle();

    /*
    with (document) {
        var x = getElementById("attr." + i).style;
        x.display = (x.display == "none") ? "block" : "none";

        var y = getElementById("attrDetails." + i).style;
        y.display = (y.display == "none") ? "block" : "none";
    } */   
    
}

function showhideattr_base(i) {
    with (document) {
        var x = getElementById("attr_" + i).style;
        getElementById("showhide_" + i).src = (x.display == "none") ? "/template/default/images/cart/min.jpg" : "/template/default/images/cart/pls.jpg";
        x.display = (x.display == "none") ? "block" : "none";
    }
}

function formatcurr(x) {
	s = "" + x;
	i = s.indexOf(".");  if (i == -1) s = s + ".00"; else if (i == s.length - 2) s = s + "0"; else if (i < s.length - 3) s = s.substr(0, i + 3);
	for (i = s.indexOf(".") - 3; i > 0; i -= 3) s = s.substring(0, i) + ',' + s.substr(i);
	return "&pound;" + s;
}

var subtotal, taxRate, taxsel, ewrf, fuel, tax = new Array();
function calctax() {
  var idx = $('#shipmethod').attr('selectedIndex');
	if (idx>=0){
  	    taxsel = tax[idx];
  	    $('#taxcell').html(formatcurr(taxsel));
  	    calctotal();
  	}
}

var shipchargesel, shipcharge = new Array();
function calcshipcharge() {
  var idx = $('#shipmethod').attr('selectedIndex');
	if (idx>=0){
  	shipchargesel = shipcharge[idx];
  	$('#shipchargecell').html( formatcurr(shipchargesel));
  	calctotal();
  }
}

function calctotal() {
	var total = subtotal + taxsel + shipchargesel;
	$('#totalcell').html( formatcurr(total));
}

function showfinancedetail(i) {
	var w;
	if (w = window.open('/cart/v12_detail.asp?p=' + (subtotal + taxsel + shipchargesel) + '&i=' + i, 'financedetail',
					'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=650,width=560')) w.focus();
}


function delitem(i) {
    with (document) {
        getElementById("qty." + i).value = 0;
        frmCart.submit();
    }
}

function init() {
    with (document.checkout) {
        if (ft.value == "sb") { chkshipmethod(); shipfirstname.select(); shipfirstname.focus(); }
        else if (ft.value == "ai") { sales.select(); sales.focus(); }
        //else if (ft.value == "oc") { placeorder.focus(); }
    }
}

function copyship() {
    with (document.checkout) {
        if (!shipeqbill.checked) {
            billfirstname.select(); billfirstname.focus();
        } else {
            billfirstname.value = shipfirstname.value;
            billlastname.value = shiplastname.value;
            billaddr1.value = shipaddr1.value;
            billaddr2.value = shipaddr2.value;
            billcity.value = shipcity.value;
            billstate.value = shipstate.value;
            billzip.value = shipzip.value;
            billphone.value = shipphone.value;
        }
    }
}

function chkshipmethod() {
    // empty -- no restriction at all
}

function chkpaymentmethod() { //useless for UK site
    /*with (document) {
        if (getElementById("paymethod_bml").checked) {
            getElementById("bmlpromo").disabled = bmlpromodisabled;
            getElementById("ccname").disabled = getElementById("ccnum1").disabled = getElementById("ccnum2").disabled = getElementById("ccnum3").disabled = getElementById("ccnum4").disabled =
			getElementById("ccmonth").disabled = getElementById("ccyear").disabled = getElementById("vcode").disabled = true;
        } else if (getElementById("paymethod_ebm") && getElementById("paymethod_ebm").checked) {
            getElementById("bmlpromo").disabled = true;
            getElementById("ccname").disabled = getElementById("ccnum1").disabled = getElementById("ccnum2").disabled = getElementById("ccnum3").disabled = getElementById("ccnum4").disabled =
			getElementById("ccmonth").disabled = getElementById("ccyear").disabled = getElementById("vcode").disabled = true;
        } else if (getElementById("paymethod_cc").checked) {
            getElementById("bmlpromo").disabled = true;
            getElementById("ccname").disabled = getElementById("ccnum1").disabled = getElementById("ccnum2").disabled = getElementById("ccnum3").disabled = getElementById("ccnum4").disabled =
			getElementById("ccmonth").disabled = getElementById("ccyear").disabled = getElementById("vcode").disabled = false;
        }
    }*/
}
//useless for UK site
/*
function chkamex() { 
    with (document.checkout) {
        var isamex = (ccname.value == 'AMEX');
        ccnum2.maxLength = ccnum2.size = (isamex ? 6 : 4);
        ccnum3.maxLength = ccnum3.size = (isamex ? 5 : 4);
        document.getElementById('cclastdigits').style.display = (isamex ? 'none' : 'inline');
    }
}*/

function trim(s) {
    return s.replace(/^\s*|\s*$/g, "");
}

function checkshippingbillinginfo() {
    with (document.checkout) {
        if (trim(shipfirstname.value) == "") { alert("SHIP TO:\nPlease enter the first name."); shipfirstname.focus(); return false; }
        if (trim(shiplastname.value) == "") { alert("SHIP TO:\nPlease enter the last name."); shiplastname.focus(); return false; }
        if (trim(shipaddr1.value) == "") { alert("SHIP TO:\nPlease enter the address."); shipaddr1.focus(); return false; }
        if (trim(shipcity.value) == "") { alert("SHIP TO:\nPlease enter the city."); shipcity.focus(); return false; }
        if (shipstate.value == "") { alert("SHIP TO:\nPlease enter the state."); shipstate.focus(); return false; }
        if (trim(shipzip.value) == "") { alert("SHIP TO:\nPlease enter the postcode."); shipzip.focus(); return false; }
        if (shipphone.value == "") { alert("SHIP TO:\nPlease enter the phone."); shipphone.focus(); return false; }
        //if (trim(shipphone_code.value + shipphone_prefix.value + shipphone_suffix.value + shipphone_ext.value) != "") {
            //if (trim(shipphone_code.value).length != 3 || trim(shipphone_prefix.value).length != 3 || trim(shipphone_suffix.value).length != 4) { alert("SHIP TO:\nPlease check the phone."); shipphone_code.focus(); return false; }
        //}
		if (!(shipmethod1.checked || shipmethod2.checked || shipmethod3.checked || shipmethod4.checked ||
					shipmethod5.checked || shipmethod6.checked || shipmethod7.checked || shipmethod8.checked) ) { alert("SHIP TO:\nPlease select a shipping method."); shipmethod1.focus(); return false; }

        if (!shipeqbill.checked) {
            if (trim(billfirstname.value) == "") { alert("BILL TO:\nPlease enter the first name."); billfirstname.focus(); return false; }
            if (trim(billlastname.value) == "") { alert("BILL TO:\nPlease enter the last name."); billlastname.focus(); return false; }
            if (trim(billaddr1.value) == "") { alert("BILL TO:\nPlease enter the address."); billaddr1.focus(); return false; }
            if (trim(billcity.value) == "") { alert("BILL TO:\nPlease enter the city."); billcity.focus(); return false; }
            if (billstate.value == "") { alert("BILL TO:\nPlease enter the state."); billstate.focus(); return false; }
            if (trim(billzip.value) == "") { alert("BILL TO:\nPlease enter the postcode."); billzip.focus(); return false; }
            if (billphone.value == "") { alert("BILL TO:\nPlease enter the phone."); billphone.focus(); return false; }
            //if (trim(billphone_code.value + billphone_prefix.value + billphone_suffix.value + billphone_ext.value) == "") { alert("BILL TO:\nPlease enter the phone."); billphone_code.focus(); return false; }
            //else if (trim(billphone_code.value).length != 3 || trim(billphone_prefix.value).length != 3 || trim(billphone_suffix.value).length != 4) { alert("BILL TO:\nPlease check the phone."); billphone_code.focus(); return false; }
        }

		e = email.value
		if (e == "") { alert("E-MAIL:\nPlease enter the e-mail address."); email.focus(); return false; }
		if (e.indexOf(" ") > -1 || e.indexOf("@") == -1 || e.indexOf(".") == -1 || e.length < 7) { alert("E-MAIL:\nPlease check the e-mail address."); email.focus(); return false; }

		if (!(payment_cc.checked || payment_4.checked || payment_5.checked || payment_6.checked)) { alert("PAYMENT METHOD:\nPlease select a payment method."); payment_cc.focus(); return false; }
    }
    return true;
}

function checkshippingbillinginfo_CAN() {
    with (document.checkout) {
        if (shipname.value == "") { alert("SHIP & BILL TO:\nPlease enter the full name."); shipname.focus(); return false; }
        if (shipaddr1.value == "") { alert("SHIP & BILL TO:\nPlease enter the address."); shipaddr1.focus(); return false; }
        if (shipcity.value == "") { alert("SHIP & BILL TO:\nPlease enter the city."); shipcity.focus(); return false; }
        if (shipstate.value == "__") { alert("SHIP & BILL TO:\nPlease select the province."); shipstate.focus(); return false; }
        if (shipzip.value == "") { alert("SHIP & BILL TO:\nPlease enter the postal code."); shipzip.focus(); return false; }
        else if (shipzip.value.length < 6 || shipzip.value.length > 7) { alert("SHIP & BILL TO:\nPlease check the postal code."); shipzip.focus(); return false; }
        else if (shipzip.value.length == 6) { z = shipzip.value; shipzip.value = z.substr(0, 3) + " " + z.substr(3, 3); }
        if (shipphone_code.value + shipphone_prefix.value + shipphone_suffix.value + shipphone_ext.value == "") { alert("SHIP & BILL TO:\nPlease enter the phone."); shipphone_code.focus(); return false; }
        else if (shipphone_code.value.length != 3 || shipphone_prefix.value.length != 3 || shipphone_suffix.value.length != 4) { alert("SHIP & BILL TO:\nPlease check the phone."); shipphone_code.focus(); return false; }
    }
    return true;
}

function checkbmlform() {
    with (document.checkout) {
        if (bdmonth.value == "" || bdday.value == "" || bdyear.value == "") { alert("Please enter the correct Date of Birth."); bdmonth.focus(); return false; }
        if (ssn.value == "" || ssn.value.length < 4) { alert("Please enter the correct Social Security Number."); ssn.focus(); return false; }
        if (!consent.checked) { alert("Please specify if you agree to have the Terms and Conditions presented electronically."); consent.focus(); return false; }
    }
    return true;
}

function checkadditionalinfo() {
    with (document.checkout) {
        if (!(referral1.checked || referral2.checked || referral3.checked || referral4.checked || referral5.checked ||
			referral6.checked || referral7.checked || referral8.checked || referral9.checked || referral10.checked ||
			referral11.checked || referral12.checked || referral13.checked || referral14.checked || referral15.checked ||
			referral16.checked || referral17.checked || referral18.checked || referral19.checked || referral20.checked ||
			referral21.checked || referral22.checked || referral23.checked || referral24.checked || referral25.checked ||
			referral26.checked || referral27.checked || referral28.checked || referral29.checked || referral30.checked ||
			referral31.checked || referral32.checked || referral33.checked || referral34.checked ||referral35.checked ||referral36.checked || referral37.checked
			/* || referral36.checked  || referral38.checked || referral39.checked ||
			referral40.checked || referral41.checked || referral42.checked || referral43.checked || referral44.checked ||
			referral45.checked || referral46.checked || referral47.checked || referral50.checked || referral51.checked || 
            referral52.checked || referral53.checked || referral54.checked || referral55.checked || referral56.checked || referral57.checked ||
			referral100.checked*/)) { alert("REFERENCE:\nPlease select the source."); referral1.focus(); return false; }
        if (referral35.checked && referral_other.value == "") { alert("REFERENCE:\nPlease enter the source."); referral_other.focus(); return false; }
        if (referral29.checked && referral_others.value == "") { alert("REFERENCE:\nPlease enter the source."); referral_others.focus(); return false; }

        if (comment.value.length > 500) { alert("COMMENTS:\nPlease enter max. 500 characters."); comment.focus(); return false; }
    }
    return true;
}

function checkGCO() {
    if ($('#shipmethod').attr('selectedIndex') == 0) {
        alert("Please select a ship method before clicking Google Checkout.");
        return false;
    }
    return true;
}
function checkgooglecheckoutinfo() {
    with (document.checkout) {
        if (!(acceptwarranty.checked)) { alert("WARRANTY INFORMATION:\nPlease check the box underneath our warranty information order to continue."); acceptwarranty.focus(); return false; }
        cancel.disabled = true;
        placeorder.disabled = true; placeorder.value = "Please wait...";
    }
}

function confirmorder() {
    with (document.checkout) {
        if (!(acceptwarranty.checked)) { alert("WARRANTY INFORMATION:\nPlease check the box underneath our warranty information order to continue."); acceptwarranty.focus(); return false; }
        cancel.disabled = true;
        placeorder.disabled = true; placeorder.value = "Please wait...";
    }
}



function openwin(x) {
    window.open(x, "bigpic", "width=640, height=480, resizable=yes, scrollbars=yes").focus();
}

window.onload = function() {

    if (self.myonload) myonload();
}
