function enlarge(id,w,h,path,hi) {
	var prev = createpopup("prev"+id,w,h);
	var htm = "<img src='/admin/uploads/"+path+".jpg' width='"+w+"' height='"+h+"' style='margin-bottom:14px;'/><br/>";
	if(hi) htm+= "<a href='/admin/uploads/"+path+"_hi.jpg' target='_blank' class='arrow left'>Download hi-resolution photo</a> ";
	htm+= "<a href='#' onclick='closepopup(\"prev"+id+"\"); return false;' class='arrow right'>Close</a>";
	prev.innerHTML = htm;
	$("page").appendChild(prev);
}

function cart(id) {
	var prev = createpopup("additem"+id,400,84);
	prev.innerHTML = "Loading data...";
	$("page").appendChild(prev);
	new Ajax.Updater("additem"+id, '/ajax/item.en.php', { parameters: { id: id } });
}

function additem(id,quantity) {
	$("itemsubmitter").remove();
	$("submitter").innerHTML = "&nbsp;Wait...";
	new Ajax.Request('/ajax/additem.en.php', {
		parameters: { id: id,quantity: quantity },
		onSuccess: function(response) {
			eval(response.responseText);
		}
	});
}

function removeitem(id) {
	if(confirm("Do you really want to remove this item from your cart?")) {
		$("tr"+id).remove();
		new Ajax.Request('/ajax/removeitem.php', {
			parameters: { id: id },
			onSuccess: function(response) {
				eval(response.responseText);
			}
		});
	}	
}

function changeitem(id,quantity) {
	new Ajax.Request('/ajax/changeitem.php', {
		parameters: { id: id,quantity: quantity },
		onSuccess: function(response) {
			eval(response.responseText);
		}
	});
}

function changecountry(country) {
	switch(country) {
		case "Belgique":
			$("pays").hide();
			$("pays").value="Belgium";
			$("envoi1").value=2; $("envoi2").value=5;
			$("prix1").innerHTML="2"; $("prix2").innerHTML="5";
			break;
		case "Europe":
			$("pays").value="Please enter your country here";
			$("pays").show();
			$("envoi1").value=5; $("envoi2").value=10;
			$("prix1").innerHTML="5"; $("prix2").innerHTML="10";
			break;
		case "Monde":
			$("pays").value="Please enter your country here";
			$("pays").show();
			$("envoi1").value=6; $("envoi2").value=10;
			$("prix1").innerHTML="6"; $("prix2").innerHTML="10";
			break;
	}
}

function validatecart() {
	var args=validatecart.arguments;
	var errors=false;
	var message="Errors:";

	for (a=0; a<(args.length-1); a+=2) {
		if ($F(args[a])=="" || $F(args[a])=="Please enter your country here") {
			errors=true;
			message+="\n- "+args[a+1]+".";
		}
	}

	if(errors) alert(message);
	document.cartvalide = (errors == false);

}

function changebanner() {
	var bhtml = "";
	if(banners[currentbanner][1]!="") bhtml+= '<a href="'+banners[currentbanner][1]+'">';
	bhtml+= '<img src="/admin/uploads/banners/image'+banners[currentbanner][0]+'.jpg" alt="Banner" width="740" height="'+bannerheight+'"/>';
	if(banners[currentbanner][1]!="") bhtml+= '</a>';
	$("banner").innerHTML = bhtml;
	if(banners.length>1) {
		do {
			nextbanner = Math.floor(Math.random()*banners.length);
		} while(nextbanner==currentbanner)
		currentbanner = nextbanner ;
		setTimeout("changebanner()",10000);
	}
}

function createpopup(id,w,h) {
	
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	
	var theblack = document.createElement("div");
	theblack.style.height = getPageHeight()+"px";
	theblack.id = "blackfade";
	theblack.innerHTML="&nbsp;";
	$("page").appendChild(theblack);

	var thepopup = document.createElement("div");
	thepopup.style.width = w+"px";
	thepopup.style.height = (28+h)+"px";
	thepopup.style.left = Math.floor((getViewWidth()-w)/2)+"px";
	thepopup.style.top = (getwScroll()+Math.floor((getViewHeight()-(h+58))/2))+"px";
	thepopup.id = id;
	thepopup.className = "popup";

	return thepopup;
	
}

function closepopup(id) {
	$(id).remove();
	$('blackfade').remove();
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function getwScroll() {
	
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
	
}

function getPageHeight(){
	var yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	return yScroll;
}

function getViewHeight(){
	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	return windowHeight;
}

function getViewWidth(){
	var windowWidth;
	if (self.innerWidth) {	// all except Explorer
		windowWidth = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
	}	
	return windowWidth;
}