/*
 *	Filename:		functions.js
 *	Author:			Rajesh Wadhwani
 *	Created:		14-10-2008
 *	Modified:		Rajesh Wadhani (14-10-2008, 21-11-2008, 28-11-2008)
 *	Purpose:		Function to ask for confirmation to add to the quantity of the existing
				product on the shopping basket. 'Yes' will add, 'Cancel' will return false.
 				@param1 is the productCode
 				@param_of_array is the list of unique product codes on the shopping basket
 					
 				If productCode doesn't match up with the existing product codes on the
 				shopping basket, then it will simple return true to continue add the product.
 *	Copyright:		Room 101 Ltd, 2008.
 */

function confirmAddToBasket() {
	var productCode = arguments[0];
	
	for (i=1 ; i<= arguments.length ; i++) {
		if (productCode == arguments[i]) {
			var add = confirm("This product already exists on your shopping basket.\nDo you wish to add another?");
			if (add == true)
				return true;
			else
				return false;
		}
	}
	
	return true;
}

/* Function to view the website map in a new window */
	function newWindow() {
		mapWindo = window.open('/templates/location.html', 'mapWin', 
			'toolbar=yes, location=yes, width=500, height=400');
	}
	
	function emptyField(field) {
		//if (field == "enter search here")
			field.value = "";
		return false;
	}
	
	function fillField(field, msg) {
		//if (field == "")
			field.value = msg;
		return false;
	}


	
	function Getcat(){
		
		var subcat = document.subcat_search.subcat.options[document.subcat_search.subcat.selectedIndex].value;
		// alert(subcat);
		var destination="http://www.millennium-music.co.uk/home/products.pl?keys=!key!&subcategory_id="+subcat+"&subsubcategory_id=!subsubcategory_id!&category_id=!category_id!&mode=list&Brand=!brand!&page=!thispage!&ppp=!thisppp!";
		location.href = destination;	
	}
	

	function Getbrand(){
		
		var brand = document.brand_search.brands.options[document.brand_search.brands.selectedIndex].value;
	//	alert(brand);
		var destination="http://www.millennium-music.co.uk/home/products.pl?keys=!keys!&subcategory_id=!subcategory_id!&category_id=!category_id!&mode=list&Brand="+brand+"&page=!thispage!&ppp=!thisppp!";
		location.href = destination;
	}
	
	
	
	//products per page
	function changeppp(){
		var pppval = document.ppp_form.ppp.options[document.ppp_form.ppp.selectedIndex].value;
		//alert(pppval);
		var destination="http://www.millennium-music.co.uk/home/products.pl?keys=!keys!&subcategory_id=!subcategory_id!&category_id=!category_id!&mode=list&Brand=!brand!&page=!thispage!&ppp="+pppval;
		location.href = destination;
	
	}
	
	function changepage(){
		var pageval = document.page_form.page.options[document.page_form.page.selectedIndex].value;
		//alert(pageval);
		var destination="http://www.millennium-music.co.uk/home/products.pl?keys=!keys!&subcategory_id=!subcategory_id!&category_id=!category_id!&mode=list&Brand=!brand!&page="+pageval+"&ppp=!thisppp!";
		location.href = destination;
	
	}
	
	function changeppp_b(){
		var pppval = document.ppp_form_b.ppp_b.options[document.ppp_form_b.ppp_b.selectedIndex].value;
		//alert(pppval);
		var destination="http://www.millennium-music.co.uk/home/products.pl?keys=!keys!&subcategory_id=!subcategory_id!&category_id=!category_id!&mode=list&Brand=!brand!&page=!thispage!&ppp="+pppval;
		location.href = destination;
	
	}
	
	function changepage_b(){
		var pageval = document.page_form_b.page_b.options[document.page_form_b.page_b.selectedIndex].value;
		//alert(pageval);
		var destination="http://www.millennium-music.co.uk/home/products.pl?keys=!keys!&subcategory_id=!subcategory_id!&category_id=!category_id!&mode=list&Brand=!brand!&page="+pageval+"&ppp=!thisppp!";
		location.href = destination;
	
	}

/**
 *	Added by:	Rajesh Wadhani on 14-Jan-2009
 *	Purpose:	To stop users to go to checkout if the basket is empty
 */
function checkEmptyBasket() {
	if (document.basket_frm.grandtotal.value == "0.00") {
		alert ("Please add item(s) to your shopping basket before proceeding to checkout!");
		return false;
	}
	return true;
}
