// JavaScript Document

function add_favori() {
	if ( navigator.appName != 'Microsoft Internet Explorer' )
	{ window.sidebar.addPanel("Internomic Solutions Internet Ergonomiques","http://www.internomic.com",""); }
	else { window.external.AddFavorite("http://www.internomic.com","Internomic Solutions Internet Ergonomiques"); } 

}


function recherche() {
	document.tri.submit();
}

function charge_rs(table,id) {

		document.action.actiontype.value = 'LOAD_RS';	
		document.action.AjaxtableF.value = table;	
		document.action.AjaxFK.value = id;	
		document.action.submit();

}

function reload_rs(id) {

		document.ajouter_produit.actiontype.value = 'LOAD_RS';			
		//document.ajouter_produit.AjaxFK.value = id;	
		document.ajouter_produit.submit();

}

function search() {
	
		document.action.actiontype.value = 'FILTRE';	
		document.action.debut.value = '0';	
		document.action.submit();
	
}	

function tri(id) {
	
		document.action.debut.value = '0';	
		document.action.tri.value = id;			
		document.action.submit();
	
}	

function rewriting(table) {
	if(confirm('Voulez-vous vraiment reg�n�rer tous les mots rewriting des '+table+' ? ')) {
		document.location = 'rewriting_table.php?table='+table;		
	}	
}

function del_favori(id) {

	if(confirm('Voulez-vous vraiment retirer cet enregistrement de la vitrine ?')) {
		document.action.actiontype.value = 'DEL_VITRINE';
		document.action.valeur.value = id;
		document.action.submit();
	}	

}

function send() {
	var msg ="";
	if(document.formSend.dest.value == '') alert("Vous devez choisir un destinataire.");		
	else {
		if(document.formSend.dest.value == 'T') {
			if(check_form_champs_oblig("formSend", "testmail")&& check_mail('formSend','testmail')) msg = "Etes vous sure de vouloir envoyer la newsletter � l'adresse test : "+document.formSend.testmail.value+" ?";
		}	
		else { 		
			msg = 'Etes vous sure de vouloir envoyer la newsletter aux  abonn�s s�lectionn�s ?';
		}	
		if(msg != "") {
			if(confirm(msg)) { 
				document.formSend.actiontype.value='send';
				document.formSend.submit();
			}		
		}
	}
}

function payer(id) {

	if(confirm('Voulez-vous vraiment indiquer la r�ception du paiement de cette commande ?')) {
		document.action.actiontype.value = 'PAYER';
		document.action.valeur.value = id;
		document.action.submit();
	}	

}

function livrer(id) {

	if(confirm('Voulez-vous vraiment indiquer l`exp�dition de cette commande ?')) {
		document.action.actiontype.value = 'EXPEDIER';
		document.action.valeur.value = id;
		document.action.submit();
	}	

}

function del_reduction(id) {

	if(confirm('Voulez-vous vraiment retirer la promotion sur ce produit ?')) {
		document.action.actiontype.value = 'DEL_REDUCTION';
		document.action.valeur.value = id;
		document.action.submit();
	}	

}

function del(table, id) {
	if(confirm('Voulez-vous vraiment supprimer cet enregistrement ?')) {
		document.getElementById('delete_id').value = id;
		document.getElementById('delete_table').value = table;
		document.delete_form.submit();
	}
}

function set_value(table, id, field, value) {
	document.getElementById('set_table').value = table;
	document.getElementById('set_id').value = id;
	document.getElementById('set_field').value = field;
	document.getElementById('set_value').value = value;
	document.set_form.submit();
}

function annule(id) {
	if(confirm('Voulez-vous vraiment annuler cette commande ?')) {
		document.action.actiontype.value = 'ANNULE';
		document.action.valeur.value = id;
		document.action.submit();
	}
}

function dup(id) {
	if(confirm('Voulez-vous vraiment dupliquer cet enregistrement ?')) {
		document.action.actiontype.value = 'DUP';
		document.action.valeur.value = id;
		document.action.submit();
	}
}	



function mdp(id) {
	if(confirm('Voulez-vous vraiment reg�n�rer le mot de passe de cet enregistrement ?')) {
		document.action.actiontype.value = 'MDP';
		document.action.valeur.value = id;
		document.action.submit();
	}
}	

function genere_all_mdp() {
	if(confirm('Voulez-vous vraiment reg�n�rer le mot de passe de tous les contacts ?')) {
		document.location = 'genere_all_mdp.php';	
	}
}	

function send_all_mdp() {
	if(confirm('Voulez-vous vraiment envoyer les mots de passe � chacun des contacts ?')) {
		document.location = 'send_all_mdp.php';	
	}
}	

function envoi_mdp(id) {
	if(confirm('Voulez-vous vraiment envoyer le mot de passe par email au contact ?')) {
		document.action.actiontype.value = 'ENVOI_MDP';
		document.action.valeur.value = id;
		document.action.submit();
	}
}	

function enligne(id) {
	document.action.actiontype.value = 'enligne';
	document.action.valeur.value = id;
	document.action.submit();
}
function horsligne(id) {
	document.action.actiontype.value = 'horsligne';
	document.action.valeur.value = id;
	document.action.submit();
}

function reload(lettre) {
	document.action.actiontype.value = 'RELOAD';
	document.action.valeur.value = lettre;
	document.action.debut.value = 0;
	document.action.submit();
}

function addline() {
	document.action.actiontype.value = 'ADDLINE';		
	document.action.submit();
}
	
function next_page(debut) {

		document.action.debut.value = debut;
		document.action.submit();

}	

function documents() {
	if(valid_form()) {
		document.ajouter_produit.actiontype.value = 2;
		document.ajouter_produit.submit();
	}
}

/* Fonctions de formulaires */
function check_form_champs_oblig (form1, lst_chps) {

	
	tab_chps = lst_chps.split(",");
	for (i=0; i<tab_chps.length;i++) {
		if (isInForm(tab_chps[i], form1)) {	
			eval ("var monchps = document."+form1+"."+tab_chps[i]+".value");	
			 if (monchps=="" || monchps==null)	
			 {		
			 	alert("Vous devez remplir le champ "+tab_chps[i]);
				eval ("document."+form1+"."+tab_chps[i]+".focus();");
				color_form("input");
				return false; 
				
			}	
		}
	}
	return true;
}
function check_form_champs_un_oblig (form1, lst_chps) {
	tab_chps = lst_chps.split(",");
	for (i=0; i<tab_chps.length;i++) {
		if (isInForm(tab_chps[i], form1)) {	
			eval ("var monchps = document."+form1+"."+tab_chps[i]+".value");	
			 if (monchps!="" && monchps!=null)	
			 {		
				alert("Vous devez remplir le champ "+tab_chps[i]);
				eval ("document."+form1+"."+tab_chps[i]+".focus();");
				color_form("input");
				return false;
			}	
		}
	}
	return false;
}



//prise en charge du focus par IE
function color_form(nom){
 if(document.getElementsByTagName(nom)){
   for(i=0;i<document.getElementsByTagName(nom).length;i++){
     document.getElementsByTagName(nom)[i].onfocus=colour;
     document.getElementsByTagName(nom)[i].onblur=none;    
   }
 }
}
//Couleur du focus
function colour(event){
/** this.style.backgroundColor='#eee';
 this.style.border='#27A6BA 1px solid';
 **/
 
 this.style.backgroundColor='#d4ccc5';  
 this.style.border='#c8bab0 1px solid';
 
 
}
//Pas de couleur
function none(event){
 this.style.backgroundColor='#e4dfdb';  
 this.style.border='#dbd1cb 1px solid';
}



function check_form_champs_oblig_menu_deroulant (form1, lst_chps) {
	tab_chps = lst_chps.split(",");
	for (i=0; i<tab_chps.length;i++) {	
		eval ("var monIndexSel = document."+form1+"."+tab_chps[i]+".selectedIndex");	
		 if (monIndexSel==0)	
		 {			
		 	alert("Vous devez remplir le champ "+tab_chps[i]);
			eval ("document."+form1+"."+tab_chps[i]+".focus();");
			return false; 
		}	
	}
	return true;
}

function check_form_champs_egal (form1, champs, valeur) {
	eval ("var monchps = document."+form1+"."+champs+".value");
	if (monchps==valeur)	{			
		return true; 
	}	
	return false;
}

function check_form_liste_egal (form1, champs, valeur) {
	eval ("var monIndexSelected = document."+form1+"."+champs+".selectedIndex");
	eval ("var maValeur = document."+form1+"."+champs+".options["+monIndexSelected+"].value");
	if (maValeur==valeur) {			
		return true; 
	}	
	return false;
}

function get_valeur_list (form1, champs) {
	eval ("var monIndexSelected = document."+form1+"."+champs+".selectedIndex");
	eval ("var maValeur = document."+form1+"."+champs+".options["+monIndexSelected+"].value");
	return maValeur;
}

function check_form_case_a_cocher_egal (form1, champs, valeur) {
	var ret_val = false;
	var debut = IndicePremierElem (form1, champs);
	var fin = IndiceFinElem (form1, champs,debut);
	for (i=debut; i<=fin; i++) {	
		eval ("var elemcour = document."+form1+".elements["+i+"].checked");	
		if (elemcour == true) {
			eval ("var valeurElem = document."+form1+".elements["+i+"].value");	
			if (valeurElem==valeur) { 
				ret_val = true;
			}
		}	
	}
	return ret_val;
}


function unecasecoche (form1, champ) {
	var debut = IndicePremierElem (form1, champ);
	var fin = IndiceFinElem (form1, champ,debut);
	for (i=debut; i<=fin; i++) {	
		eval ("var elemcour = document."+form1+".elements["+i+"].checked");	
		if (elemcour == true) {
			 return true;
		}	
	}
	alert("Merci de choisir une des case "+champ);
	return false;
}


function estvide (form1, chps) {
	eval ("var val1 = document."+form1+"."+chps+".value");
	if (val1==null || val1 =="") {
		return true;
	} else {
		return false;
	}
}

function pasvide (form1, chps) {
	eval ("var val1 = document."+form1+"."+chps+".value");
	if (val1!=null && val1 !="") {
		return true;
	} else {
		return false;
	}
}


function sont_egaux (form1, chp1, chp2) {
	eval ("var val1 = document."+form1+"."+chp1+".value");
	eval ("var val2 = document."+form1+"."+chp2+".value");
	if (val1 != val2) {
		return false;
	}
	return true;
}


function isInForm(myvalue, form1) {
	eval ("var nb_elem = document."+form1+".elements.length");
	for (j=0;j<nb_elem;j++) {	
		eval ("var maval = document."+form1+".elements["+j+"].name");
		if (maval==myvalue) {
			return true;
		}
	}
	return false;
}


function IndicePremierElem (form1, champ) {
	eval ("var nbelem = document."+form1+".elements.length");
	for (i=0; i<nbelem; i++) {
		eval ("var elemcour = document."+form1+".elements["+i+"].name");
		if (elemcour == champ) {
			return i;
		}	
	
	}
	return 0;
}


function IndiceFinElem (form1, champ,debut) {
	eval ("var nbelem = document."+form1+".elements.length");
	for (i=debut; i<nbelem; i++) {
		eval ("var elemcour = document."+form1+".elements["+i+"].name");
		if (elemcour != champ) {
			return i-1;
		}	
	}
	return nbelem-1;
}


function IndiceFinElem2 (form1, champ,debut,pas) {
	eval ("var nbelem = document."+form1+".elements.length");
	for (i=debut+pas; i<nbelem; i=i+pas) {
		eval ("var elemcour = document."+form1+".elements["+i+"].name");
		if (elemcour != champ) {
			return i-pas;
		}	
	}
	return nbelem-1;
}


function check_mail (form1, chps) {
eval ("var email=document."+form1+"."+chps+".value");
	if (email != "" && email != null) {
		var aroba = email.indexOf("@");	
		if (aroba == -1) {	 
		  alert("Votre email n'est pas valide");	
		  eval ("document."+form1+"."+chps+".focus();");
		  color_form("input");
		  return false;
		}
		
		var point = email.indexOf(".", aroba);
		if ((point == -1) || (point == (aroba + 1))) {	
		  alert("Votre email n'est pas valide");	
		  eval ("document."+form1+"."+chps+".focus();");
		  color_form("input");	
		  return false;
		}
		
		var point = email.lastIndexOf(".");
		if ((point + 1) == email.length) {	
		   alert("Votre email n'est pas valide");	
		  eval ("document."+form1+"."+chps+".focus();");
		  color_form("input");	
		  return false;
		}	
		point = email.indexOf("..")
		if (point != -1) {	  
		   alert("Votre email n'est pas valide");	
		  eval ("document."+form1+"."+chps+".focus();");
		  color_form("input");	
		  return false;
		}
	}
	return true;
}

function check_site (form1, chps) {

eval ("var email=document."+form1+"."+chps+".value");

if (email != "" && email != null) {

	var aroba = email.indexOf("http://");	
	if (aroba == -1) {	 
	  return false;
	}
	
	var point = email.indexOf(".", aroba);
	if ((point == -1) || (point == (aroba + 1))) {	
	  return false;
	}
	
	var point = email.lastIndexOf(".");
	if ((point + 1) == email.length) {	
	  return false;
	}	
	point = email.indexOf("..")
	if (point != -1) {	  
	  return false;
	}
}
return true;

}


function isAdate (form1, champ) {

var madate = format_date (form1,champ+"jour", champ+"mois", champ+"annee");

eval ("var indicejj = document."+form1+"."+champ+"jour.options.selectedIndex");		
eval ("var monjour = document."+form1+"."+champ+"jour.options[indicejj].value");

if (madate.getDate() != monjour) {	
	return false;
}

return true;

}

function Date2SupDate1 (form1, champ1, champ2) {


	var madate1 = format_date (form1,champ1+"jour", champ1+"mois", champ1+"annee");
	var madate2 = format_date (form1,champ2+"jour", champ2+"mois", champ2+"annee");
	if (madate2<=madate1) {
		return false;
	}
	return true;
}

function DateSupAuj (form1, champ) {

	var TodayDate = new Date;
	var madate = format_date (form1, champ+"jour", champ+"mois", champ+"annee");
	
	if (madate<=TodayDate) {	
		return false;
	
	}
	return true;

}

function isChampsNumeric (champ, form1) {

	eval ("var chp = document."+form1+"."+champ+".value");
	if (isNaN (chp)) {
		return false;
	}
	return true;
}


function is_a_pourcentage (champs, form1) {

	if (isInForm(champs, form1)) {		
			eval ("var mavaleur = document."+form1+"."+champs+".value");
			if (mavaleur >=0 && mavaleur <= 100) return true;
			else return false;
			
		}	
	return true;
}

function isListChampsNumeric (lstchps, form1) {
	
	
	tab_chps = lstchps.split(",");	
	for (i=0; i<tab_chps.length;i++) {			
		if (isInForm(tab_chps[i], form1)) {		
			if (isChampsNumeric (tab_chps[i], form1) ==false) return false; 
		}	
	}
	return true
	
}

function TourChampsNumeric (tabnom, form1, pas) {

var indice1 = IndicePremierElem (form1, tabnom);
var indice2 = IndiceFinElem2 (form1, tabnom, indice1, pas);
var nomchps;

	for (i=indice1; i<=indice2;i=i+pas) {
		eval (" nomchps = document."+form1+".elements["+i+"].value");						
		if (nomchps !="") {					
			if (isNaN (nomchps)) return false; 
		}
	}
	return true;
}

function senddata(form1) {

	eval ("document."+form1+".submit()");

}

function senddata_changeval(form1, champ, newval) {

	eval ("document."+form1+"."+champ+".value='"+newval+"'");
	eval ("document."+form1+".submit()");

}

function senddata_changeval_niv (form1, champ, newval, level) {

	
	eval ("document."+form1+"."+champ+".value='"+newval+"'");
	
	enleve_valeur_menu (level+1, "tidcat[]",form1);
	eval ("document."+form1+".submit()");
}

function enleve_valeur_menu (level, champ, form1) {

	var debut = IndicePremierElem (form1, champ);
	var fin = IndiceFinElem (form1, champ,debut);
	//alert (debut);
	//alert (fin);
	var debuti = new Number (debut);
	var leveli = new Number (level);
	var indice_debut = new Number (debuti + leveli);	
	//alert (indice_debut);
	for (i=indice_debut;i<=fin;i++)	{			
		eval ("document."+form1+".elements["+i+"].value='';");	
	}

}

function senddata_changeval_action(form1, champ, newval, newaction) {

	eval ("document."+form1+"."+champ+".value='"+newval+"'");
	eval ("document."+form1+".action='"+newaction+"'");
	eval ("document."+form1+".submit()");

}


function senddata_changeval_action2(form1, champ, newval, newaction, niveau_act) {

	eval ("document."+form1+"."+champ+".value='"+newval+"'");
	eval ("var niveau = document."+form1+".niveau_actuel.value");
	if (niveau_act == niveau) niveau++;
	eval ("document."+form1+".niveau_actuel.value=niveau");
	eval ("document."+form1+".action='"+newaction+"'");
	eval ("document."+form1+".submit()");

}

function senddata_changeval_action3(form1, champ, newval, newaction) {

	eval ("document."+form1+"."+champ+".value='"+newval+"'");	
	eval ("document."+form1+".niveau_actuel.value=0");
	eval ("document."+form1+".action='"+newaction+"'");
	eval ("document."+form1+".submit()");

}

function senddata_newurl(form1, newurl) {

 eval ("document."+form1+".action="+newurl);
 eval ("document."+form1+".submit()");

}

function format_date (form1,jour, mois, an) {

eval ("var indiceaa = document."+form1+"."+an+".options.selectedIndex");		
eval ("var indicejj = document."+form1+"."+jour+".options.selectedIndex");		
eval ("var indicemm = document."+form1+"."+mois+".options.selectedIndex");		
eval ("var madate = new Date (document."+form1+"."+an+".options[indiceaa].value, document."+form1+"."+mois+".options[indicemm].value-1, document."+form1+"."+jour+".options[indicejj].value)");		
return madate;

}


function chp1_sup_valeur (form1, chp1, chp2) {

eval ("var val1 = document."+form1+"."+chp1+".value");
eval ("var val2 = document."+form1+"."+chp2+".value");
if (val1 > val2) return true;	
else return false;

}

function contient_char (form1, chp1, monchar) {

	eval ("var val1 = document."+form1+"."+chp1+".value");
	if (val1.indexOf(monchar) == -1) return false;
	else return true;

}



function checkformLoggue(nameform) {
	if (check_form_champs_oblig (nameform, "login,mdp")==false) alert("Pour vous identifier, merci de bien vouloir renseigner votre login et mot de passe.");		
	else eval("document."+ nameform + ".submit();");
}

function gotoTo(adresse) {

document.location.href=adresse;

}

function gotoBlank(adresse) {

window.open(adresse);

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Site specific
function deconnexion() {
	document.logout.submit();
}

function perdu_mdp() {
	window.open('perdu_mdp.php','perdu_mdp','width=320,height=182,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
}
function recommander(id) {
	window.open('recommander.php?id_produit='+id,'recommander','width=434,height=313,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
}
function logout() {
	document.login.submit();
}

