function setsort(index){
	with(document.navForm){
		sort.value = index;
		submit();
	}
}

function addCart(pid){
	document.location.href='../carts/addCart.php?id='+pid;
}

function openImage(imgname){
	var viewimg = open("../images/products/"+imgname, "btmprodview", 'width=500, height=450, resizable=yes, alwaysRaised=yes, dependent=yes, scrollbars=auto');
	viewimg.focus();
}

function testcookie(){
	document.cookie="verify=test; expire="+(new Date()).toGMTString();
	if(document.cookie.indexOf("verify") < 0){
		alert("Cookie not support on your browser!!\n\nYou may not complete your order on our website.\nPlease enable cookies in your browser or use the browser that support cookies");
	}
	document.cookie ="verify=test; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function selectproduct(pid){
	var f = document.navForm;
	f.pid.value = pid;
	//document.location.href="<?php echo($_SERVER['PHP_SELF']); ?>?pid="+pid;
	//+f.pid[f.pid.selectedIndex].value;
	f.action = "detail.php";
	//f.target = "_blank";
	f.submit();
	return false;
}

function refreshProduct(){
	document.pdlistform.submit();
}

function doAction(actiontype){
	var f = document.pdlistform;
	
	//add product checked
	var id = new Array();
	for (var i=0; i<f.elements.length; i++){
		var e = f.elements[i];
		if (e.type == "checkbox" && e.name == "product_id" && e.checked) id[id.length] = e.value;
	}
	if(id.length > 0){
		f.pid.value = id.join(',').toString();
		
		switch(actiontype){
			case "markview": 
				f.action = "../members/mark_view.php";
				f.submit();
				break;
			case "addfavorite":
				f.action = "../carts/wish_add.php";
				f.submit();
				break;
			case "addreserve":
				f.action = "../members/reserved_add.php";
				f.submit();
				break;
			case "makeoffer":
				f.action = "../carts/offer.php";
				f.submit();
				break;
			case "addcart":
				f.action = "../carts/addCart.php";
				f.submit();
				break;
			default:
		}
	}else{
		alert("You didn't select any items");
	}
}

function navigate(pid){
	var f = document.navForm;
	f.pid.value = pid;
	f.submit();
}
