// Function appellée lorsque le bouton OK des photos est cliqué.
function clicOrdre(id_categ, ordre){
	window.location.href = 'p_produits.php?action=ordre_categ&id_categ='+id_categ+'&ordre='+ordre;
}


function validationpub() { 

	if(document.form_pub.nom.value == "") { 
		alert ("Nom obligatoire"); 
		document.formulaireinsert.nom.focus(); 
		return false; 
	} 

	document.formulaireinsert.submit();
}

function validationinsert() { 
	if(document.formulaireinsert.nom.value == "") { 
		alert ('Veuillez entrer votre nom'); 
		document.formulaireinsert.nom.focus(); 
		return false; 
	} 
	if(document.formulaireinsert.e-mail.value == "") { 
		alert ('Veuillez entrer votre e-mail'); 
		document.formulaireinsert.e-mail.focus(); 
		return false; 
	} 
}

	// Redirige vers lien
function redirectionJavascript(lien){
	window.location.href = lien;
}

// Demande de confirmation
//	--> Affiche le texte txt
//	--> Si l'utilisateur répond 'oui', redirige vers le lien
function confirmation(txt, lien){
	if(confirm(txt)){
		window.location.href = lien;
	}
}

//************** FONCTIONS MACROMEDIA *****************\\

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Functions that handle preload. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// stop hiding -->

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

//************** FONCTIONS PERSO *****************\\

// ouvre un popup au centre de l'écran
function popupCentree(page, largeur, hauteur, opt){
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;

	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+opt);
}

// teste si les fichiers à uploader sont des images jpg ou jpeg.
//	--> Sont passés en paramètres les noms des éléments à tester.
function testFichier(){
	var tab = testFichier.arguments;
	if(tab.length==0){
		//alert("Erreur : pas assez d'arguments pour la fonction testFichier");
		return true;
	}
	else{
		var i = 0, err = false, ch;
		while(i < tab.length && !err){
			ch = document.getElementsByName(tab[i])[0].value;
			if(ch != "")
				err = ((ch.substring(ch.length-3).toLowerCase() != "jpg") && (ch.substring(ch.length-4).toLowerCase() != "jpeg"));

			i = i+1;
		}
		if(err){
			alert("Certains fichiers indiqués ne sont pas des images jpg ou jpeg.");
			return false;
		}
		return true;
	}
}

// Mets à jour la grande photo du descriptif de bien.
function majPhoto(nom){	
		document.getElementsByName('gPhoto')[0].src = nom;
}


// change la couleur de fond d'une balise
//	--> x est l'instance à modifier
//	--> typ = 'e' : onEnter
//	--> typ = 'q' : onBlur
function chgBG(x, typ){
	switch(typ){
		case 'e':
			// jaune pale
			x.style.backgroundColor = "#FFFFC8"
			break;
		case 'q':
			x.style.backgroundColor = "#FFFFFF"
			break;
	}
}


// Ouvre un popup avec l'image agrandie dedans
function zoom(im){
	WW = 400;
	HH = 320;
	TT = screen.height / 2 - HH / 2;
	LL = screen.width / 2 - WW / 2;
	window.open("zoom.php?im="+im,"","width="+WW+",height="+HH+",Top="+TT+",Left="+LL+",status=no");
}

// Demande de confirmation
//	--> Affiche le texte txt
//	--> Si l'utilisateur répond 'oui', redirige vers le lien
function confirmation(txt, lien){
	if(confirm(txt))
		window.location.href = lien;
}

// verification si l'email est correct pour la newsletter
 function verifNewsletter() {
   if ((document.news.email.value=="")) {
	   alert ('Veuillez entrer votre email. Merci.'); 
	return false; 
	 }
	
	 if ((document.news.email.value!="")) {
		 
		var email = document.news.email.value; 
		var verif = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/ 
		if (verif.exec(email) == null){ 
			alert("Votre email est incorrect"); 
			return false; 
		} 
		else
			return true; 
	}
}


// Verifie si un nom de fichier est entré ou pas. Si non, ne rien faire. Ou sinon, valider.
function verifAjoutImage(){
	if ((document.ajoutimage.imageAmodifier.value=="")) {
		alert ('Veuillez selectionner une image. Merci.'); 
		return false; 
	}
	else
		return true;
}

// Pour annuler la fonction "Click to activate" de IE sur les éléments flash
theObjects = document.getElementsByTagName("object"); 
for (var i = 0; i < theObjects.length; i++) { 
theObjects[i].outerHTML = theObjects[i].outerHTML; 
}

function validationinsert(lang) { 
	if(lang == 'fr'){
		var txt1 = 'Nom obligatoire';
		var txt2 = 'Telephone obligatoire';
		var txt3 = 'E-mail obligatoire';
		var txt4 = 'Prénom obligatoire';
		var txt5 = 'Société obligatoire';
	}else if(lang == 'en'){
		var txt1 = 'Name obligatory';
		var txt2 = 'Phone obligatory';
		var txt3 = 'E-mail obligatory';
		var txt4 = 'Firstname obligatory';
	}else{
		var txt1 = 'Name zwingend';
		var txt2 = 'Phone zwingend';
		var txt3 = 'Email zwingend';
		var txt4 = 'Vorname zwingend';
		var txt5 = 'Company zwingend';
	}

	if(document.formulaireinsert.nom.value == "") { 
		alert (txt1); 
		document.formulaireinsert.nom.focus(); 
		return false; 
	} 
	if (document.formulaireinsert.prenom){
		if(document.formulaireinsert.prenom.value == "") { 
			alert (txt4); 
			document.formulaireinsert.prenom.focus(); 
			return false; 
		} 
	}
	if (document.formulaireinsert.societe){
		if(document.formulaireinsert.societe.value == "") { 
			alert (txt5); 
			document.formulaireinsert.societe.focus(); 
			return false; 
		} 
	}
	if(document.formulaireinsert.email.value == "") { 
		alert (txt3); 
		document.formulaireinsert.email.focus(); 
		return false; 
	}

	if (document.formulaireinsert.cv){
		if (document.formulaireinsert.cv.value != ''){
			var t_string = new Array();
			t_string = explode(document.formulaireinsert.cv.value,".");

			var extension = t_string[(t_string.length)-1];

			if(extension != "doc" && extension != "pdf" && extension != "docx"){
				document.formulaireinsert.cv.focus();
				document.formulaireinsert.cv.style.backgroundColor = "#FFFFC8";
				alert("Merci de reformater votre CV dans un des 2 formats suivants: Word, pdf !");
				return false;
			}
		}
	}

	if (document.formulaireinsert.lettre_motivation){
		if (document.formulaireinsert.lettre_motivation.value != ''){
			var t_string = new Array();
			t_string = explode(document.formulaireinsert.lettre_motivation.value,".");

			var extension = t_string[(t_string.length)-1];

			if(extension != "doc" && extension != "pdf" && extension != "docx"){
				document.formulaireinsert.lettre_motivation.focus();
				document.formulaireinsert.lettre_motivation.style.backgroundColor = "#FFFFC8";
				alert("Merci de reformater votre lettre de motivation dans un des 2 formats suivants: Word, pdf !");
				return false;
			}
		}
	}

	document.formulaireinsert.submit();
}

function explode(item,delimiter){
	tempArray=new Array(1); 
	var Count=0; 
	var tempString=new String(item); 

	while (tempString.indexOf(delimiter)>0) { 
		tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter)); 
		tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
		Count=Count+1 
	} 

	tempArray[Count]=tempString; 
	return tempArray; 

}

function validation_reseau(){

	if (document.form_reseau.horaire){
		if (document.form_reseau.horaire.value != ''){
			chaine = document.form_reseau.horaire.value;
			chaine = chaine.replace("h", ":"); 

			var t_string = new Array();
			t_string = explode(chaine,":");

			if(t_string.length>1){
				if(isNaN(t_string[0]) || isNaN(t_string[1]) || t_string.length>2 ||  t_string[0].length>2 ||  t_string[1].length>2){
					document.form_reseau.horaire.focus();
					document.form_reseau.horaire.style.backgroundColor = "#FFFFC8";
					alert("Votre horaire semble incorrecte !");
					return false;
				}
			}
		}
	}

	document.form_reseau.submit();

}

function validationoffre(lang) { 
	if(lang == 'fr'){
		var txt1 = 'Nom obligatoire';
		var txt2 = 'Telephone obligatoire';
		var txt3 = 'E-mail obligatoire';
		var txt4 = 'Prénom obligatoire';
	}else if(lang == 'en'){
		var txt1 = 'Name obligatory';
		var txt2 = 'Phone obligatory';
		var txt3 = 'E-mail obligatory';
		var txt4 = 'Firstname obligatory';
	}else{
		var txt1 = 'Name zwingend';
		var txt2 = 'Phone zwingend';
		var txt3 = 'Email zwingend';
		var txt4 = 'Vorname zwingend';
	}

	if(document.formulaireoffre.nom.value == "") { 
		alert (txt1); 
		document.formulaireoffre.nom.focus(); 
		return false; 
	} 
	if(document.formulaireoffre.prenom.value == "") { 
		alert (txt4); 
		document.formulaireoffre.prenom.focus(); 
		return false; 
	} 
	if(document.formulaireoffre.email.value == "") { 
		alert (txt3); 
		document.formulaireoffre.email.focus(); 
		return false; 
	} 

	if (document.formulaireoffre.cv){
		if (document.formulaireoffre.cv.value != ''){
			var t_string = new Array();
			t_string = explode(document.formulaireoffre.cv.value,".");

			var extension = t_string[(t_string.length)-1];

			if(extension != "doc" && extension != "pdf" && extension != "docx"){
				document.formulaireoffre.cv.focus();
				document.formulaireoffre.cv.style.backgroundColor = "#FFFFC8";
				alert("Merci de reformater votre CV dans un des 2 formats suivants: Word, pdf !");
				return false;
			}
		}
	}

	if (document.formulaireoffre.lettre_motivation){
		if (document.formulaireoffre.lettre_motivation.value != ''){
			var t_string = new Array();
			t_string = explode(document.formulaireoffre.lettre_motivation.value,".");

			var extension = t_string[(t_string.length)-1];

			if(extension != "doc" && extension != "pdf" && extension != "docx"){
				document.formulaireoffre.lettre_motivation.focus();
				document.formulaireoffre.lettre_motivation.style.backgroundColor = "#FFFFC8";
				alert("Merci de reformater votre lettre de motivation dans un des 2 formats suivants: Word, pdf !");
				return false;
			}
		}
	}


	document.formulaireoffre.submit();
}