// JavaScript Document


function ShowVignette(ki){
	photo = ki.getElementsByTagName("div");
	photo[0].className = "rollon";
	legende = ki.getElementsByTagName("em");
	legende[0].style.display = "block";
	
	
	
}


function HideVignette(ki){
	photo = ki.getElementsByTagName("div");
	photo[0].className = "";
	legende = ki.getElementsByTagName("em");
	legende[0].style.display = "none";
}


function VerifContact(ki,EnvoiEnCours){
	var erreur = 0;
	if(ki.nom.value==""){ AlertColorChamp(ki.nom); erreur++; }else{RegularColorChamp(ki.nom);}
	if(ki.prenom.value==""){ AlertColorChamp(ki.prenom); erreur++; }else{RegularColorChamp(ki.prenom);}
	if(ki.mail.value==ki.mailconfirm.value){
		if(ki.mail.value=="" && !verifmail(ki.mail.value)){ AlertColorChamp(ki.mail); erreur++; }else{RegularColorChamp(ki.mail);}
		if(ki.mailconfirm.value=="" && !verifmail(ki.mailconfirm.value)){ AlertColorChamp(ki.mailconfirm); erreur++; }else{RegularColorChamp(ki.mailconfirm);}
	}else{
		AlertColorChamp(ki.mail);
		AlertColorChamp(ki.mailconfirm);
		erreur++;		
	}
	if(ki.message.value==""){ AlertColorChamp(ki.message); erreur++; }else{RegularColorChamp(ki.message);}
	
	if(erreur==0){
		ki.valider.value = EnvoiEnCours;
		ki.valider.disabled = true;
		return true;
	}
	
	return false;
}


function VerifAccreditation(ki,EnvoiEnCours){
	var erreur = 0;


	if(ki.support.value==""){ AlertColorChamp(ki.support); erreur++; }else{RegularColorChamp(ki.support);}

	if(!document.getElementById('fonction1').checked && !document.getElementById('fonction2').checked){
		document.getElementById('fonctioncheck').style.border = "1px solid #ff6728";
		document.getElementById('fonctioncheck').style.backgroundColor = "#ffe1d4";
		erreur++;
	}else{
		document.getElementById('fonctioncheck').style.border = "none";
		document.getElementById('fonctioncheck').style.backgroundColor = "#ffffff";
	}

	if(!document.getElementById('cat1').checked && !document.getElementById('cat2').checked && !document.getElementById('cat3').checked && !document.getElementById('cat4').checked && !document.getElementById('cat5').checked && !document.getElementById('cat6').checked){
		document.getElementById('categoriecheck').style.border = "1px solid #ff6728";
		document.getElementById('categoriecheck').style.backgroundColor = "#ffe1d4";
		erreur++;
	}else{
		document.getElementById('categoriecheck').style.border = "none";
		document.getElementById('categoriecheck').style.backgroundColor = "#ffffff";
	}
	
	if(ki.nom.value==""){ AlertColorChamp(ki.nom); erreur++; }else{RegularColorChamp(ki.nom);}
	if(ki.prenom.value==""){ AlertColorChamp(ki.prenom); erreur++; }else{RegularColorChamp(ki.prenom);}

	if(ki.adressesupport.value==""){ AlertColorChamp(ki.adressesupport); erreur++; }else{RegularColorChamp(ki.adressesupport);}
	if(ki.cp.value==""){ AlertColorChamp(ki.cp); erreur++; }else{RegularColorChamp(ki.cp);}
	if(ki.ville.value==""){ AlertColorChamp(ki.ville); erreur++; }else{RegularColorChamp(ki.ville);}

	if(ki.tel.value==""){ AlertColorChamp(ki.tel); erreur++; }else{RegularColorChamp(ki.tel);}
	if(ki.mail.value=="" || !verifmail(ki.mail.value)){ AlertColorChamp(ki.mail); erreur++; }else{RegularColorChamp(ki.mail);}
	
	if(ki.cartepresse.value=="" && ki.upattestation.value==""){
		AlertColorChamp(ki.cartepresse); erreur++;
	}else if(ki.cartepresse.value!=""){
		RegularColorChamp(ki.cartepresse);
	}else{
		
		RegularColorChamp(ki.cartepresse);
		upatteststring = ki.upattestation.value.toLowerCase();

		if(upatteststring.indexOf(".pdf")!="-1"){
			RegularColorChamp(ki.upattestation);
		}else{
			AlertColorChamp(ki.upattestation); erreur++;
		}
	
	}
	


	//if(ki.photo.value==""){ AlertColorChamp(ki.addphoto); erreur++; }else{RegularColorChamp(ki.addphoto);}
	if(ki.photo.value==""){ AlertColorChamp(ki.addphoto); erreur++; }
	
	if(erreur==0){
		ki.valider.value = EnvoiEnCours;
		ki.valider.disabled = true;
		return true;
	}
	
	return false;

}

/*
function VerifAccreditation(ki,EnvoiEnCours){
	var erreur = 0;

	if(ki.support.value==""){ AlertColorChamp(ki.support); erreur++; }else{RegularColorChamp(ki.support);}

	if(!document.getElementById('fonction1').checked && !document.getElementById('fonction2').checked && !document.getElementById('fonction3').checked){
		document.getElementById('fonctioncheck').style.border = "1px solid #ff6728";
		document.getElementById('fonctioncheck').style.backgroundColor = "#ffe1d4";
		erreur++;
	}else{
		document.getElementById('fonctioncheck').style.border = "none";
		document.getElementById('fonctioncheck').style.backgroundColor = "#ffffff";
	}

	if(!document.getElementById('cat1').checked && !document.getElementById('cat2').checked && !document.getElementById('cat3').checked && !document.getElementById('cat4').checked && !document.getElementById('cat5').checked){
		document.getElementById('categoriecheck').style.border = "1px solid #ff6728";
		document.getElementById('categoriecheck').style.backgroundColor = "#ffe1d4";
		erreur++;
	}else{
		document.getElementById('categoriecheck').style.border = "none";
		document.getElementById('categoriecheck').style.backgroundColor = "#ffffff";
	}
	
	if(ki.nom.value==""){ AlertColorChamp(ki.nom); erreur++; }else{RegularColorChamp(ki.nom);}
	if(ki.prenom.value==""){ AlertColorChamp(ki.prenom); erreur++; }else{RegularColorChamp(ki.prenom);}

	if(ki.adressesupport.value==""){ AlertColorChamp(ki.adressesupport); erreur++; }else{RegularColorChamp(ki.adressesupport);}
	if(ki.cp.value==""){ AlertColorChamp(ki.cp); erreur++; }else{RegularColorChamp(ki.cp);}
	if(ki.ville.value==""){ AlertColorChamp(ki.ville); erreur++; }else{RegularColorChamp(ki.ville);}

	if(ki.tel.value==""){ AlertColorChamp(ki.tel); erreur++; }else{RegularColorChamp(ki.tel);}
	if(ki.mail.value=="" || !verifmail(ki.mail.value)){ AlertColorChamp(ki.mail); erreur++; }else{RegularColorChamp(ki.mail);}

	//if(ki.photo.value==""){ AlertColorChamp(ki.addphoto); erreur++; }else{RegularColorChamp(ki.addphoto);}
	if(ki.photo.value==""){ AlertColorChamp(ki.addphoto); erreur++; }
	
	if(erreur==0){
		ki.valider.value = EnvoiEnCours;
		ki.valider.disabled = true;
		return true;
	}
	
	return false;

}
*/

function UpPhoto(){
	window.open ("upload_photo.php", "accreditation", config='height=200, width=350, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
}

function AddPhoto(visuel){
	document.getElementById('photozone').innerHTML = '<img src="FICHIERS/accreditation/'+visuel+'" width="60" onclick="UpPhoto()">';
	document.form.photo.value = visuel;
}

function GoTo(ad){
	document.location.href = ad;
}

function AlertColorChamp(ki){
	ki.style.borderLeft = ki.style.borderTop = ki.style.borderBottom = "1px solid #ff6728";
	ki.style.backgroundImage = "url('imgs/form/fond-input-alert.gif')";
}

function RegularColorChamp(ki){
	ki.style.borderLeft = ki.style.borderTop = ki.style.borderBottom = "1px solid #c8c8c8";
	ki.style.backgroundImage = "url('imgs/form/fond-input.gif')";
}

function NavVertCenter(){
	var MonElement = document.getElementById("nav").getElementsByTagName("strong");
	for(ct=0;ct<MonElement.length;ct++){
		var TailleMonElement = MonElement[ct].offsetHeight;
		var resultat = Math.floor((30-TailleMonElement)/2);
		MonElement[ct].style.margin = resultat+"px";
	}	
	var MesLiens = document.getElementById("nav").getElementsByTagName("a");
	for(ct=0;ct<MesLiens.length;ct++){
		MesLiens[ct].onmouseover = function(){ ShowMe(this); };
	}
	CacheMenus();
}


function ShowMe(ki){
	MonParent = ki.parentNode.innerHTML.toLowerCase();
	
	if(MonParent.indexOf("<strong")!=-1){ //si niveau 1
		CacheMenus();
		document.getElementById("hidelayer").style.display = "block";
		ki.className = "on";
		
	}else{//niveau 2
		document.getElementById("hidelayer").style.display = "block";
		//RAZ des rolls du menu en cours
		MesLiensAvecSousMenu = ki.parentNode.parentNode.getElementsByTagName("ul");
		for(ct=0;ct<MesLiensAvecSousMenu.length;ct++){
			MesLiensAvecSousMenu[ct].style.display="none";
			temp = MesLiensAvecSousMenu[ct].parentNode.getElementsByTagName("a");
			temp[0].className="";
		}
		//si sous menu au roll > allume
		if(MonParent.indexOf("<ul")!=-1){
			ki.className = "on";
			temp = ki.parentNode.getElementsByTagName("span");
			temp[0].style.marginTop = "-"+ki.offsetHeight+"px";
			temp[0].style.height = ki.offsetHeight+"px";
		}
	}

	sousmenu = ki.parentNode.getElementsByTagName("ul");
	if(sousmenu.length){
		sousmenu[0].style.display="block";
		sousmenu[0].style.visibility = "visible";
	}

}


function CacheMenus(){
	var MesMenus = document.getElementById("nav").getElementsByTagName("ul");
	for(ct=0;ct<MesMenus.length;ct++){
		MesMenus[ct].style.display = "none";
		MesMenus[ct].style.visibility = "hidden";
	}
	var MesLiens = document.getElementById("nav").getElementsByTagName("a");
	for(ct=0;ct<MesLiens.length;ct++){
		MesLiens[ct].className = "";
	}	
	document.getElementById("hidelayer").style.display = "none";
}


function verifmail(adrr){
	 var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	 if(reg.test(adrr)==true) return true;
	 else return false;  
}


function CadreOmbre(ki){
	var visuelactuel = document.getElementById("visuel").innerHTML;
	var NewVisuel = '<table border="0", cellpadding="0" cellspacing="0">';
	NewVisuel += '<tr><td><img src="imgs/ombre/haut-gauche.gif" alt="" width="9" height="9" /></td><td background="imgs/ombre/haut.gif"><img src="imgs/ombre/haut.gif" alt="" width="20" height="9" /></td><td><img src="imgs/ombre/haut-droite.gif" alt="" width="9" height="9" /></td></tr>';
	NewVisuel += '<tr><td background="imgs/ombre/gauche.gif"><img src="imgs/ombre/gauche.gif" alt="" width="9" height="20" /></td><td>'+visuelactuel+'</td><td background="imgs/ombre/droite.gif"><img src="imgs/ombre/droite.gif" alt="" width="9" height="20" /></td></tr>';
	NewVisuel += '<tr><td><img src="imgs/ombre/bas-gauche.gif" alt="" width="9" height="9" /></td><td background="imgs/ombre/bas.gif"><img src="imgs/ombre/bas.gif" alt="" width="20" height="9" /></td><td><img src="imgs/ombre/bas-droite.gif" alt="" width="9" height="9" /></td></tr>';
	NewVisuel += '</table>';
	document.getElementById("visuel").innerHTML = NewVisuel;
}

