// KEENPOINT JavaScript Document

function initKP(){
	initScrollLayers();	
}


function initScrollLayers() {
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
 // var wndo1 = new dw_scrollObj('wn1', 'lyr1');
  var wndo1 = new dw_scrollObj('wn1', 'lyr1');
  populate();
  //var wndo3 = new dw_scrollObj('wn2', 'lyr2');
  // Read instructions if your scrolling layers are inside tables 
}

function initKPScrollers(container,layer) {
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
 // var wndo1 = new dw_scrollObj('wn1', 'lyr1');
 // var wndo2 = new dw_scrollObj('wn2', 'lyr2');
  // Read instructions if your scrolling layers are inside tables 
}

function initselected(idselected){
var ullist=document.getElementById("maintab").getElementsByTagName("li");
for (var i=0; i<ullist.length; i++){
	if(ullist[i].id == idselected){
		ullist[i].className="selected" 
	}
	else{
		ullist[i].className="";
	}
}
}

control=true;
compteur=0;
function clignote(div,src1,src2)
{
	
	var tabimage = document.getElementById(div.id).getElementsByTagName("img");
	//alert(parseInt((Math.random()*1000)%tabimage.length));
	
	for(var i=0; i<tabimage.length; i++){
		//if(i == parseInt((Math.random()*1000)%tabimage.length))
		if(i == compteur)
			tabimage[i].src = src1;
	}
	if(compteur < tabimage.length){
		compteur++;
	}
	else{
		compteur=0;
	}
	window.setTimeout("clignote2("+div.id+",\""+src1+"\",\""+src2+"\");",(Math.random()*300));
	
}

function clignote2(div,src1,src2)
{
	if (control!=false)
	{
	var tabimage = document.getElementById(div.id).getElementsByTagName("img");
	for(var i=0; i<tabimage.length; i++){
		//if(i == parseInt((Math.random()*1000)%tabimage.length))
		if(i == compteur)
			tabimage[i].src = src2;
	}
	window.setTimeout("clignote("+div.id+",\""+src1+"\",\""+src2+"\");",(Math.random()*300));
	}
}

function stopit()
{
	control=false;
}

function doit()
{
	control=true;
	clignote();
}

function fadein(src){
	if(DivimgTopRight.filters != null){
	DivimgTopRight.filters.revealTrans.apply()
	DivimgTopRight.innerHTML = '<p><img src="./media/'+src+'" width="160" height="150"/></p>';
	DivimgTopRight.filters.revealTrans.play()
	}
	else{
	DivimgTopRight.innerHTML = '<img src="./media/'+src+'" width="164" height="154"/>';
	}
}

function showInfo(divtoshow)
{
	var tabdiv = document.getElementById("showinfo").getElementsByTagName("div");
	for(var i=0; i<tabdiv.length; i++){
		if(tabdiv[i].id == divtoshow){
			tabdiv[i].style.visibility = "visible";
		}
		else{
			tabdiv[i].style.visibility = "hidden";
		}
		
	}
}

function checkConnection(formulaire){
	formulaire.action="struct.php?menu=contact&sousmenu=rencontre";
	formulaire.submit();	
}

function verifContactForm(formulaire){
	var boolalert = false;
	var contactalert = "La saisie des champs suivants est obligatoire : \n (";
	if(formulaire.nom.value == ""){
			boolalert = true;
			contactalert += "  Nom ";
	}
	if(formulaire.prenom.value == ""){
			boolalert = true;
			contactalert += "  Prenom ";
	}
	if(formulaire.mail.value == ""){
			boolalert = true;
			contactalert += "  Mail ";
	}
	
	if(boolalert){
		contactalert += ")";
		alert(contactalert);
	}
	else{
		var testmail = verifMail(formulaire.mail.value);
		if(testmail == true){
			formulaire.submit();
		}
	}
}

function verifInscriptionForm(formulaire){
	var boolalert = false;
	var inscriptionalert = "La saisie des champs suivants est obligatoire : \n (";
	if(formulaire.nom.value == ""){
			boolalert = true;
			inscriptionalert += "  Nom ";
	}
	if(formulaire.prenom.value == ""){
			boolalert = true;
			inscriptionalert += "  Prenom ";
	}
	if(formulaire.mail.value == ""){
			boolalert = true;
			inscriptionalert += "  Mail ";
	}
	
	if(boolalert){
		inscriptionalert += ")";
		alert(inscriptionalert);
	}
	else{
		var testmail = verifMail(formulaire.mail.value);
		if(testmail == true){
			if(formulaire.manif.value=="0"){
				alert("Veuillez sélectionner une manifestation");
			
			}
			else{
			formulaire.submit();
			}
		}
	}
	
}

function verifMail(a) {

testm = false ;
for (var j=1 ; j<(a.length) ; j++) {
  if (a.charAt(j)=='@') {
   if (j<(a.length-4)){
    for (var k=j ; k<(a.length-2) ; k++) {
     if (a.charAt(k)=='.') testm = true;
    }
   }
  }
 }


if (testm==false) alert('Votre adresse e-mail est incorrecte. Vérifier les informations'); 

return testm ;

}

function displaynewsinfo(newsresume,newsinfo,linkshow,linkhide){
	//newsresume.style.display = "none";
	//newsresume.style.visibility = "hidden";
	newsinfo.style.display = "block";
	newsinfo.style.visibility = "visible";
	linkshow.style.display = "none";
	linkhide.style.display = "block";
}

function hidenewsinfo(newsresume,newsinfo,linkshow,linkhide){

	//newsresume.style.display = "block";
	//newsresume.style.visibility = "visible";
	newsinfo.style.display = "none";
	newsinfo.style.visibility = "hidden";
	linkshow.style.display = "block";
	linkhide.style.display = "none";
}