// JavaScript Document

if (navigator.userAgent.indexOf('Opera') != -1 ) {
document.write('<link rel="stylesheet" type="text/css" href="/css/operahack.css">');
}

if (navigator.userAgent.indexOf("Safari") != -1) {
document.write('<link rel="stylesheet" type="text/css" href="/css/safarihack.css">');
}


function mod_qty(zone,qty) {
	var new_qty=parseInt($(zone).value)+qty;
	if (new_qty<0) new_qty=0;
	$(zone).value=new_qty;
}

function ajax_com_update(obj) {
	new Ajax.Request('/_includes/mods/csc/com_updater.php',	{
						method: 'POST',
						asynchronous: true,
						parameters: {text: obj.value, oid: obj.getAttribute("id")},
						onSuccess: function(transport, json) { 
							
						}
	});
}

function add_to_favorites(pid,oid,uid) {
		new Ajax.Request('/_includes/mods/csc/com_updater.php',	{
						method: 'POST',
						asynchronous: true,
						parameters: {'what':'cart', 'product_id': pid, 'qty': $("amount_"+oid).value, 'user_id':uid},
						onSuccess: function(transport, json) { 
							$("btn_adder_"+oid).innerHTML = "<img src='/design/favorite.png' align='absmiddle'> Ajouté ŕ la liste de favoris";
							new Effect.Puff("btn_adder_"+oid);
						}
	});
}

function fast_add_to_favorites(pid,uid) {
		new Ajax.Request('/_includes/mods/csc/com_updater.php',	{
						method: 'POST',
						asynchronous: true,
						parameters: {'what':'cart', 'product_id': pid, 'qty': 1, 'user_id':uid},
						onSuccess: function(transport, json) { 
							$("addto_fav_"+pid).innerHTML = "Ajouté ŕ la liste de favoris";
							new Effect.Puff("addto_fav_"+pid);
						}
	});
}

function _carts_delete(pid, uid) {
	new Ajax.Request('/_includes/mods/csc/com_updater.php',	{
						method: 'POST',
						asynchronous: true,
						parameters: {'what':'delete', 'product_id': pid, 'user_id':uid},
						onSuccess: function(transport, json) { 
								document.location.href = document.location.href;
						}
	});
}

function re_store_fav(uid) {
	var xfav = document.getElementsByClassName("_cart_input");
	var parameters = {};
	parameters["what"] = "re_store";
	parameters["user_id"] = uid;
	for (var x=0;x<xfav.length;x++) {
		parameters[xfav[x].getAttribute("pid")] = xfav[x].value;
	}
	new Ajax.Request('/_includes/mods/csc/com_updater.php',	{
						method: 'POST',
						asynchronous: true,
						parameters: parameters,
						onSuccess: function(transport, json) { 
								document.location.href = document.location.href;
						}
	});
}

function add_full_cart(uid) {
	var xfav = document.getElementsByClassName("_cart_input");
	var parameters = {};
	parameters["what"] = "add_full_cart";
	parameters["user_id"] = uid;
	for (var x=0;x<xfav.length;x++) {
		parameters[xfav[x].getAttribute("pid")] = xfav[x].value;
	}
	new Ajax.Request('/_includes/mods/csc/com_updater.php',	{
						method: 'POST',
						asynchronous: true,
						parameters: parameters,
						onSuccess: function(transport, json) { 
								document.location.href = "/fr/list-products.html?target=_carts";
						}
	});
}

function add_from_fav() {
	var temp = {};
	var elms = document.getElementsByClassName("fav_cbx");
	for(var x=0;x<elms.length;x++) {
		var idx = elms[x].getAttribute("id").replace("qq_","");
		temp[idx] = $("amount_of_"+idx).value;
		if (!elms[x].checked) $("amount_of_"+idx).value = 0;
	}
	$('_carts_form').submit();
	for(x in temp) {
		$("amount_of_"+x).value = temp[x];
	}
}
