

function showTab2 () {
	$('#tab2_content').css('display', 'block');$('#tab1_content').css('display', 'none');
	$("#tab2").attr("class", "selected");
	$("#tab1").removeAttr("class");
}

function showTab1 () {
	$('#tab1_content').css('display', 'block');$('#tab2_content').css('display', 'none');
	$("#tab1").attr("class", "selected");
	$("#tab2").removeAttr("class");
}

function showCart () {
	$.facebox({
		ajax: "cartpopup.asp"
	});
}

function showLogin () {
	$.facebox({
		ajax: "loginfacebox.asp"
	});
}

function checkLogin(username, password) {
	try
	{
		$.post("ajax/checklogin.asp", {username: username, password: password}, function(data) {
			if (data == "yes")
				location.reload();
			else {
				$("#login_msg").html(data);
			}
		});
	}
	catch (e)
	{
	}
	return false;
}


/*Order Form validation*/
function validateEmail( strValue ) {
var objRegExp  =
 /(^[a-z]([a-z\d_\.]*)@([a-z\d_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z\d_\.]*)@([a-z\d_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

//Tab1 Payment Option
function updatePayoption () {
	if ($("#account").attr("checked") == true)
	{
		$("#div_creditcard").css("display", "none");
		$(".ponumber").css("display", "inline");
		$("#payoption").val("account");
	} else {
		$("#div_creditcard").css("display", "block");
		$(".ponumber").css("display", "none");
		$("#payoption").val("creditcard");
	}
}

function updateCardType () {
	if ($("#creditcard1").attr("checked") == true)
		$("#cardtype").val("visa");
	else if ($("#creditcard2").attr("checked") == true)
		$("#cardtype").val("mastercard");
	else if ($("#creditcard3").attr("checked") == true)
		$("#cardtype").val("amex");
	else if ($("#creditcard4").attr("checked") == true)
		$("#cardtype").val("diner");
}

//Tab2 Order Form
function validateForm() {
	var fields = ["contact_fname", "contact_lname", "contact_phone", "contact_email", 
					"delivery_country", "delivery_attention", "delivery_companyname", "delivery_street", "delivery_suburb", "delivery_state", "delivery_postcode", "delivery_phone", 
					"billing_country", "billing_attention", "billing_companyname", "billing_street", "billing_suburb", "billing_state", "billing_postcode", "billing_email"];
	var message = ["contact first name", "contact last name", "contact phone number", "contact email address", 
					"delivery country", "delivery attention", "delivery business name", "delivery address", "delivery suburb", "delivery state", "delivery postcode", "delivery phone number", 
					"billing country", "billing attention", "billing business name", "billing address", "billing suburb", "billing state", "billing postcode", "billing email address"];
	for (var i=0; i<fields.length; i++)
	{
		if ( /^\s*$/.test( $("#"+fields[i]).val()) ) {
			alert("Please provide your " + message[i] + ".");
			$("#"+fields[i]).focus();
			return false;
		}
	}
	return true;
}

function changeAddressType() {
	if ($("#del_business").attr("checked") == true) {
		$("#delivery_companyname").removeAttr("readonly");
		$("#billing_companyname").removeAttr("readonly");
		$("#delivery_companyname").val("");
		$("#billing_companyname").val("");
		$("#delivery_companyname").css("background-color", "#fff");
		$("#billing_companyname").css("background-color", "#fff");
	} else if ($("#del_residential").attr("checked") == true) {
		$("#delivery_companyname").attr("readonly", "readonly");
		$("#billing_companyname").attr("readonly", "readonly");
		$("#delivery_companyname").val("n/a");
		$("#billing_companyname").val("n/a");
		$("#delivery_companyname").css("background-color", "#eee");
		$("#billing_companyname").css("background-color", "#eee");
		$.facebox("Your order will be delivered to you during business hours. You will be required to sign for your goods. <br />Please ensure that someone will be home to accept your order. <br />Or alternatively, please supply us with a business address for delivery.");
	} else if ($("#del_pickup").attr("checked") == true) {
		//alert("Pickup");
	}
}
/*Order Form validation END*/

function sendComment () {
	try {
			var form = $("#commentform");
			var url = form.attr("action");
			if ($('#email').val() == '' || !validateEmail($('#email').val())) {
				alert("Please fill in your contact email address.");
				return false;
			} else if ($('#feedback').val() == '') {
				alert("Please add some comments.");
				return false;
			}
			$.post(url, {action: 'sendcomment', fromemail: $('#email').val(), emailsubject: $('#subject').val(), emailbody: $('#feedback').val()}, function(msg) {
				alert(msg);
				$("#commentform").get(0).reset();
			});
	} catch(e) {
	}
	return false;
}

function forgotpassword() {
	$.facebox({
		ajax: "forgotpassword.asp"
	});
}

function removeItem(pdid) {
		try {
			var form = $("#cartform");
			var url = "ajax/processdata.asp";
			$.post(url, {action: 'removeitem', prodetailid: pdid}, function(msg) {
				//$("#cartmessage").html(msg);
				//$("#item"+pdid).hide();
				//showCart();
				location.reload(true);
			});
		} catch(e) {
		}
		return false;
	}
