/****************************************************************************************************/	
/****************************************************************************************************/
/*************************** Gift Shop - Shopping Cart - A Kaszmarek June 2007 **********************/	
/****************************************************************************************************/
/****************************************************************************************************/

/***** index.cfm *****/
function showMeThisCat(){
	var thisCat=document.catForm.changeCategory[document.catForm.changeCategory.selectedIndex].value;
	var thisSearchText = '&searchText=' + document.catForm.searchText.value;
	document.catForm.action='index.cfm?category=' + thisCat + thisSearchText;
	document.catForm.submit();
}

function addToCart(prodId, category){
		var thisHRef3 = 'cart_add.cfm?category=' + category + '&product_id=' + prodId;
		document.location.href=thisHRef3;
}

/***** cart_view.cfm *****/
function removeItem(product_id){
	if(confirm('Are you sure that you want to completely remove this product from your shopping cart?')){
		document.productForm.action = 'cart_view.cfm?updateQty=1&removeItem=1&product_id=' + product_id;
		document.productForm.submit();
	}
}

function checkoutCheck(numberOfItems,country){
	var thisHRef2 = '';
	if (country == 0) {
		thisHRef = 'cart_view.cfm';
		alert('Please select your Country from the Shipping Cost for Country drop-down box.');
	} else {
		if(numberOfItems > 0){
			thisHRef2 = 'cart_checkout.cfm?thisCountryId='+country;
		}else{
			thisHRef = 'cart_view.cfm';
			alert('There is nothing in your Shopping Cart. You must select some products before you can checkout.');
		}
	}
	document.location.href = thisHRef2;
}

function updateQuantity(){
	var thisHRef = '';
	if(numberOfItems > 0){
		thisHRef = 'cart_checkout.cfm';
	}else{
		thisHRef = 'cart_view.cfm';
		alert('There is nothing in your Shopping Cart. You must select some products before you can checkout.');
	}
	document.location.href = thisHRef;
}
			
function updatePostage(){
	updateQuantity();
}

/***** cart_checkout.cfm ****/
function validateThis(){
	var sys_message='';

	if(document.forms[0].firstname.value.length==0){
		sys_message=sys_message + 'Please Enter a First Name.\n';
	}
	if(document.forms[0].surname.value.length==0){
		sys_message = sys_message + 'Please enter a surname.\n'; 
	}
	if(document.forms[0].address.value.length==0){
		sys_message = sys_message + 'Please enter an address.\n'; 
	}
	if(document.forms[0].city.value.length==0){
		sys_message= sys_message + 'Please Enter a City/Suburb.\n';
	}
	if(document.forms[0].postcode.value.length==0){
		sys_message= sys_message + 'Please Enter a Postcode.\n';
	}
	if(document.forms[0].email.value.length==0){
		sys_message= sys_message + 'Please Enter an email address.\n';
	}
	if(!document.forms[0].terms.checked){
		sys_message= sys_message + 'You must agree to the terms and conditions before you can proceed.\n To read these please click on the link at the bottom of the page.';
	}
	//if they have entered an email address - check its validity
	if(document.forms[0].email.value.length!=0){
		var str=document.forms[0].email.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(str)==false){
			sys_message= sys_message + 'The email address you entered is invalid. Please try again.\n';
		}
	}
	if(sys_message.length != 0){
		alert(sys_message);
		sys_message='';
		return false;
	}else{
		return true;
	}
}


function submitToGateway(){
	document.location.href='../Mercy_International_Centre_v2/giftshop/cart_gateway.cfm';
}

function showTermsAndConditions() {
	pageurl = "terms.htm";
	window.open(pageurl, "Terms", "resizable=1,menubar=no,location=no,directories=no,scrollbars=yes,status=no,height=550,width=600");
}
