
Event.observe(window, "load", function() {
	if($("nlemail"))
		$("nlemail").observe("focus", function(e) {
			if(e.element().value == "Votre email")
				e.element().value = "";
		});
});

function UpdateProduct() {
	c1 = $("c1");
	c2 = $("c2");
	var alwaysDispo = gpTable['nfo']['alwaysDispo'];
	if(!c1) {
		$("pt").update((gpInit.nb()*$F("qte")).nb()+" &euro;");
		var dispo = gpTable['nfo']['dispo'];
		var strictDispo = gpTable['nfo']['strictDispo'];
		$("g").value = gpTable['nfo']['id'];
	}
	else if(!c2) {
		$("pt").update((gpTable['z'+$F(c1)]['nfo']['prix']*$F("qte")).nb()+" &euro;");
		var dispo = gpTable['z'+$F(c1)]['nfo']['dispo'];
		var strictDispo = gpTable['z'+$F(c1)]['nfo']['strictDispo'];
		$("g").value = gpTable['z'+$F(c1)]['nfo']['id'];
	}
	else {
		var select = new Element("select", { id: "c2", name: "c2", onchange: "UpdateProduct()"});
		var curr = $F(c2);
		$H(gpTable['z'+$F(c1)]).each(function(e) {
			if(e.key != "nfo")
				select.insert(new Element("option", Object.extend({value: e.key.gsub(/z/, "")}, e.key.gsub(/z/, "")==curr ? {selected: "selected"} : {})).update(e.value['nom']));
		});
		c2.replace(select);
		$("pt").update((gpTable['z'+$F(c1)]['z'+$F(c2)]['prix']*$F("qte")).nb()+" &euro;");
		var dispo = gpTable['z'+$F(c1)]['z'+$F(c2)]['dispo'];
		var strictDispo = gpTable['z'+$F(c1)]['z'+$F(c2)]['strictDispo'];
		$("g").value = gpTable['z'+$F(c1)]['z'+$F(c2)]['id'];
	}
	if(dispo) {
		$("addToCart").show();
		if(strictDispo)
			$("stock").removeClassName("nondispo").update("En stock").show();
		else $("stock").hide();
	}
	else {
		$("addToCart").hide();
		$("stock").addClassName("nondispo").update("Epuisé").show();
	}
}

function SelectAddress(tp) {
	if(typeof tp == undefined)
		tp = 0;

	return CallAjax($H($("livraison").serialize(true)).merge({"tp": tp}), "SelectAdresses");
}

function getDocumentHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function canalPlayer(id) {
	$$("BODY")[0].insert(new Element("div", {id: "overlayCanalPlayer", style:"position:absolute;left:0;top:0;width:100%;height:"+getDocumentHeight()+"px;background:#000;opacity:0.8"}).observe("click", function() {
		$$("#overlayCanalPlayer", "#modalcanalPlayer").invoke("hide").invoke("remove");
	}));
	var bstats = document.viewport.getDimensions();
	var vstats = document.viewport.getScrollOffsets();
	var top = vstats.top + (bstats.height - 360) / 2;
	var left = vstats.left + (bstats.width - 640) / 2;
	$$("BODY")[0].insert(new Element("div", {id: "modalcanalPlayer", style: "position:absolute;left:"+left+"px;top:"+top+"px;width:640px;height:360px;background:#000"}).insert('<a href="#" onclick="$$(\'#overlayCanalPlayer\', \'#modalcanalPlayer\').invoke(\'hide\').invoke(\'remove\')" class="closePopup" title="Fermer le lecteur"></a><div id="canalPlayer"></div>'));
	flashMe(
		"http://player.canalplus.fr/site/flash/player.swf",
		"canalPlayer",
		640, 360,
		"9.0.0",
		{
			param: "seasons",
			videoId: id
		},
		{
			bgcolor: "#000000",
			menu: "true",
			wmode: "transparent",
			allowfullscreen: "true",
			allowscriptaccess: "always"
		},
		{
			name: "canalPlayer"
		}
	);
	return false;
}

