var smart_crit_list = new Array();
var smart_crit_mode = 'AND';
var infos_buffer = new Array(); //buffer pour la mise en cache d'infos
var tab_com = new Array();

function initSmartCrit() {
	smart_crit_list = new Array();
	smart_crit_mode = 'AND';
}

function toggleCB(cb) {
	if(cb.checked) cb.checked = false;
	else cb.checked = true;
}

function pushHelp(str) {
	infos_buffer.push(document.getElementById('xeoweb_live_help').innerHTML);
	document.getElementById('xeoweb_live_help').innerHTML = str;
	//document.getElementById('xeoweb_live_help').style.display = 'block';
	//alert($('#xeoweb_live_help').get(0).style.display);
	//if($('#xeoweb_live_help').get(0).style.display=='' || $('#xeoweb_live_help').get(0).style.display=='none')
	//$('#xeoweb_live_help').stop().animate({opacity: 1},500).show();
}

function popHelp() {
	var txt = infos_buffer.pop();
	if(txt == undefined || txt.length == 0) {
		//document.getElementById('xeoweb_live_help').style.display='none';
		//alert($('#xeoweb_live_help').get(0).style.display);
		//if($('#xeoweb_live_help').get(0).style.display=='block')
		//$('#xeoweb_live_help').stop().animate({opacity: 1},500).animate({opacity: 0},1000);
		document.getElementById('xeoweb_live_help').innerHTML = '';
	} else document.getElementById('xeoweb_live_help').innerHTML = txt;
}

function checkSmartCrit(checkbox, mode, champ, val) {
	//on a activé un critère
	if(checkbox.checked) {
		if(smart_crit_list["_"+champ] == undefined) smart_crit_list["_"+champ] = new Array();
		smart_crit_list["_"+champ]["_"+val] = true;
	
	//on a désactivé un critère
	} else {
		smart_crit_list["_"+champ]["_"+val] = false;
	}
	
	refreshSmartCrit();
}

function refreshSmartCrit() {
	var str = '';
	for (cle_champ in smart_crit_list) {
		tmp = ";;"+cle_champ;
		for (cle_val in smart_crit_list[cle_champ]) {
			if(smart_crit_list[cle_champ][cle_val] == true) {
				if(tmp.length>0) {
					str += tmp;
					tmp = '';
				}
				str += ","+cle_val+":"+smart_crit_list[cle_champ][cle_val];	
			}
		}
	}
	//alert(document.getElementById('xeoweb_crit_selec').value);
	xajax_smart_crit_filter(str, document.getElementById('xeoweb_crit_selec').value);
}

function xeoweb_highlight(liste, val) {
	var tab = liste.split(',');
	for(i=0; i<tab.length; i++) {
		if(tab[i] != val) document.getElementById('xeoweb_mini_img_'+tab[i]).style.border='0px';
		else document.getElementById('xeoweb_mini_img_'+tab[i]).style.border='1px solid red';
	}
}

function dispTR(id, num, search) {
	
	
	if(num == 'prev'){
		var ref = $("span[class='xeoweb_selected_page']:first").attr('ref');
		if(parseInt(ref)!=0)
			num = parseInt(ref)-1;
		else
			num = 0;
	}else if(num == 'next'){
		var ref = $("span[class='xeoweb_selected_page']:first").attr('ref');
		var comp = $("span[name^='button_num2_page_']:last").attr('ref');
		if((parseInt(ref)+1)>parseInt(comp)){
			num = parseInt(comp);
		}else{
			num = parseInt(ref)+1;
		}
	}
		
	$("span[name^='button_num1_page_']").attr('class', '');
	$("span[name='button_num1_page_"+num+"']").attr('class', 'xeoweb_selected_page');
	$("span[name^='button_num2_page_']").attr('class', '');
	$("span[name='button_num2_page_"+num+"']").attr('class', 'xeoweb_selected_page');
	
	
	if(search != ''){
		//xajax_search_plain(search, 'xeoweb_main', '', num, 0);
	}else{
		num++;
		var selec = $("tr[id^='"+id+"']");
		for(i=0; i<selec.length; i++) {
			selec.get(i).style.display='none';
		}
		
		selec = $("tr[id^='"+id+num+"']");
		for(i=0; i<selec.length; i++) {
			selec.get(i).style.display='';
		}
		$("span[name^='button_num2_page_']").attr('style', 'cursor:pointer;color:#808080;');
		$("span[name='button_num2_page_"+(num-1)+"']").attr('class', 'xeoweb_selected_page');
	}
}

function getFormAccount() {
	var tab = new Array();
	var liste_input = $("input[id^='xeoweb_account_']");
	for(i=0; i<liste_input.length; i++) {
		tab[liste_input.get(i).id] = liste_input.get(i).value;
	}
	tab[document.getElementById("xeoweb_account_pays_select").id] = document.getElementById("xeoweb_account_pays_select").value;
	xajax_creer_account(tab);
}

function getFormAccountComande() {
	var tab = new Array();
	var liste_input = $("input[id^='xeoweb_commandeaccount_']");
	for(i=0; i<liste_input.length; i++) {
		tab[liste_input.get(i).id] = liste_input.get(i).value;
	}
	xajax_creer_account_commande(tab);
}

function checkAccountModif(modif) {
	var tab = new Array();
	var liste_input = $("input[id^='xeoweb_account_']");
	for(i=0; i<liste_input.length; i++) {
		if(liste_input.get(i).type == "checkbox"){
			tab[liste_input.get(i).id] = liste_input.get(i).checked;
		}else{
			tab[liste_input.get(i).id] = liste_input.get(i).value;
		}
	}
	var liste_select = $("select[id^='xeoweb_account_']");
	for(i=0; i<liste_select.length; i++) {
		tab[liste_select.get(i).id] = liste_select.get(i).value;
	}
	xajax_save_account_modif(modif,tab);
}

function checkPanierCommandeInvalid(mode) {
	var tab = new Array();
	var tous = false;
	var liste_input = $("input[id^='xeoweb_chk_commande_']");
	if(liste_input.length == 0){
		alert('Vous devez selectionner une ou plusieurs commandes en attentes');
	}else{
		var valid = false;
		for(i=0; i<liste_input.length; i++) {
			tab_id=liste_input[i].id.split("_");
			id_commande = tab_id[3];
			if(liste_input[i].checked == true)
				valid = true;
			tab[id_commande] = liste_input[i].checked;
		}
		if(!valid){
			alert('Vous devez selectionner une ou plusieurs commandes en attentes');
			tab= new Array();
		}
	}
	if(tab.length>0 && confirm("Voulez vous refuser les commandes selectionnées ?"))
		xajax_invalider_commande(tab,mode);
}

function checkPanierCommande(mode) {
	var tab = new Array();
	var tous = false;
	var liste_input = $("input[id^='xeoweb_chk_commande_']");
	if(liste_input.length == 0){
		if(mode != "pr")
			tous = confirm('Voulez vous envoyer toutes les commandes ?');
		else
			tous = confirm('Voulez valider toutes les commandes ?');
	}else{
		var valid = false;
		for(i=0; i<liste_input.length; i++) {
			tab_id=liste_input[i].id.split("_");
			id_commande = tab_id[3];
			if(liste_input[i].checked == true)
				valid = true;
			tab[id_commande] = liste_input[i].checked;
		}
		if(!valid){
			if(mode != "pr")
				tous = confirm('Voulez vous envoyer toutes les commandes ?');
			else
				tous = confirm('Voulez valider toutes les commandes ?');
			if(!tous)
				tab= new Array();
		}
	}
	if(mode != "pr")
		xajax_envoyer_commande_popup(tab,tous,mode,"commande");
	else
		xajax_envoyer_commande_popup(tab,tous,mode,"commande_pr");
	//xajax_commande_to_panier(tab,tous,mode);
}
// timer qui lance la verification des champ du cartouche creation des comptes : xeoweb_xjx_account
var timeout_account = 0 ;
function timeoutStartAccountCheck() {
	timeout_account = setTimeout("xajax_verifie_donne_account(document.getElementById('xeoweb_account_login_input').value,document.getElementById('xeoweb_account_nom_input').value,document.getElementById('xeoweb_account_prenom_input').value,document.getElementById('xeoweb_account_mdp_input').value,document.getElementById('xeoweb_account_confirm_input').value)",1000);
}

function timeoutStopAccountCheck() {
	if(timeout_account>0)
	{
		clearTimeout(timeout_account) ;
	}
}

var timeout_account_commande = 0 ;
function timeoutStartAccountCommandeCheck() {
	timeout_account_commande = setTimeout("xajax_verifie_donne_account_commande(document.getElementById('xeoweb_commandeaccount_mail_input').value,document.getElementById('xeoweb_commandeaccount_nom_input').value,document.getElementById('xeoweb_commandeaccount_prenom_input').value,document.getElementById('xeoweb_commandeaccount_phone_input').value)",1000);
}

function timeoutStopAccountCommandeCheck() {
	if(timeout_account_commande>0)
	{
		clearTimeout(timeout_account_commande) ;
	}
}

//timer qui lance la modification la qte d'un objet dans le panier
var timeout_commandeqte = 0 ;
function timeoutStartCommandeQteCheck(id) {
	clearTimeout(timeout_commandeqte);
	timeout_commandeqte = setTimeout("xajax_compte_panier_element(document.getElementById('xeoweb_panier_commande_qte_input_"+id+"').value,"+ id +");",1500);
}

var timeout_commandeqteCom = 0 ;
function timeoutStartCommandeQteCheckCom(id,com,mode) {
	
	timeout_commandeqteCom = setTimeout("xajax_compte_panier_element(document.getElementById('xeoweb_panier_commande_qte_input_"+id+"').value,"+ id +","+com+",'"+mode+"')",1500);
}

function timeoutStopAccountCheck() {
	if(timeout_commandeqte>0)
	{
		clearTimeout(timeout_commandeqte) ;
	}
	if(timeout_commandeqteCom>0)
	{
		clearTimeout(timeout_commandeqteCom) ;
	}
}

function confirm_envoyer(mod) {
	if(mod=="panier"){
		xajax_envoyer_commande_popup("","","",mod);
	}else if(mod=="commande"){
		xajax_envoyer_commande_popup(tab_com,false,"",mod);
	}else if(mod=="commande_pr"){
		xajax_envoyer_commande_popup(tab_com,false,"pr",mod);
			
	}
}


