// JavaScript Document

function addToCart(form, personalised, artno)
{
  var check = true;
  if ( personalised == "1") {
	  if (form.personalise.value == "")
	    check = confirm("This item may be personalised - are you sure you do NOT wish to enter some text?");
  }
  if (check) {
	form.catalogue_action.value = "CART_ADD";
	form.submit();
  }
}

function removeFromCart(form)
{
  if (confirm("Are you sure you wish to remove this item from your Shopping Cart?")) {
		form.catalogue_action.value = "CART_REMOVE";
		form.submit();
  }
}

function getPage(i)
{
	document.paginate.page_number.value = i;
	document.paginate.submit();
}

function matchOptions(theButtons, theFields)
{
	for (i=0;i<theButtons.length;i++) {
		if(theButtons[i].checked)
			theFields[i].value = theButtons[i].value;
		else 
			theFields[i].value = '0';
	}
}

function changeRows(i) {
	document.selectRange.rowsperpage.value=i;
	document.selectRange.submit();
}

function matchButton(form, button1, button2)
{
	var element1 = "document."+form+"."+button1;
	var element2 = "document."+form+"."+button2;
	if (eval(element1).checked == false) {
		eval(element2).disabled=true;
	}
	else if (eval(element1).checked=true) {
		eval(element2).disabled=false;
	}
}

function confirmCancel() {
	if ( confirm('Are you sure you wish to cancel this order?')) {
		document.forms[0].action.value='cancelOrder';
		document.forms[0].submit();
	}
}

function confirmOrder(i, ptype) {
	if( confirm('You have elected to pay by ' + ptype + '.\rAre you sure this is correct?')) {
		if ((i==1) || (i==2) || (i==3)) {
			document.payment_options.paytype.value=i;
			document.payment_options.action.value='proceed';
			document.payment_options.submit();
		}
		else if (i==4) {
			document.payment_options.paytype.value=i;
			document.payment_options.action.value='<?php echo CATALOGUE_ECOMMERCE_GATEWAY; ?>';
			document.payment_options.submit();
		}
		else if (i==5) {
			document.payment_options.paytype.value=i;
			document.payment_options.action.value='paypal';
			document.payment_options.submit();
		}
	}
}

function cancelOrder() {
	if( confirm('You are about to cancel your order.\rAre you sure this is correct?')) {
		document.payment_options.action.value='stop';
		document.payment_options.submit();
	}
}


