// JavaScript Document


//******************************** 
//
// 		FONCTION SCRIPTACULOUS
//
//********************************

function anchorScroll() {

	// when we load, get the string
	var location=window.location.toString();
	// search the string for a #
	if(location.indexOf("#")!=-1) {
		// work out the element
		var element=location.substring((location.indexOf("#")+1));
		new Effect.ScrollTo('m'+element);
	}
}




//******************************** 
//
// 		SHOW HIDE
//
//********************************



function displayDiv(which) {
	if (document.getElementById(which).style.display == String('none'))
	{
	document.getElementById(which).style.display = String ('block');
	}
else
	{
	document.getElementById(which).style.display = String ('none');
	}

return false;
}





/*
name / le nom des div moins l'id
which / l'id à afficher
howmany / le nombre de div total
*/
function showhideAllDiv(name, which, howmany)
{

	for (var x = 0; x < howmany; x++) {	
		hideDiv(name+x);
	}

	showDiv(name+which);
}



function display_sscat(divID,nbr_div)
{
	for (i=0; i<nbr_div; i++)
	{
		if (('sscat'+document.coreform.select_option[i].value)!=divID)
		{		
			cat_val='sscat'+document.coreform.select_option[i].value;
			document.getElementById(cat_val).style.display = "none";
		}
	}
	document.getElementById(divID).style.display = "block";
} 




// DISPLAY DIV WITH IMG CHANGE
function displayDivImg(which,img1,img2) {
	var icon = 'icon_'+which;
if (document.getElementById(which).style.display == String('none'))
	{
		
	document.getElementById(which).style.display = String ('block');
	document[icon].src=img1;
	}
else
	{
	document.getElementById(which).style.display = String ('none');
	document[icon].src=img2;
	}

return false;
}



// display hidden text USE: <INPUT ou A onClick="showDiv(ID_de_la_DIV); return false;">
function showDiv(which) {
	document.getElementById(which).style.display = String ('block');
	return false;
}
function hideDiv(which) { 
	document.getElementById(which).style.display = String ('none'); 
	return false;
} 







//******************************** 
//
// 		VERIFICATION de DONNEES
//
//********************************




// champ vide
//---------------
function checkEmpty(formname,forminput) {
	
   if ((formname.forminput.value.length==0) ||  (formname.forminput.value==null)) 
   {	   return false;   }
   else   
   {	   return true;   }
}



// Check the extension of an input
// ----------------------------------
function checkExt() {
   if ((envoi.photo.value.length==0) ||  (envoi.photo.value==null)) //checks if input is empty or null
   {
	  alert ("Attention, vous devez obligatoirement sélectionner une image");
	  return false;
   }
   else {
  	 var extension;
	 var filext = document.envoi.photo.value;
     extension = filext.substring(filext.length - 3, filext.length); 
	 	 if ((extension.toUpperCase() != 'JPG') && (extension.toUpperCase() != 'PEG'))
    	  {
		  var extension_show;
		  extension_show = filext.substring(filext.length - 4, filext.length); // extension a afficher ds message d'erreur
       	  alert("L'extension du fichier séléctionné ("+extension_show.toUpperCase()+") est invalide. Seules les images .JPG et .JPEG sont admises."); 
		  return false;
     	  }
     	 else
    	  {
	 	  return true;
		  }	
	}
}	 






// Vérification Caractères spéciaux
// ---------------------------------
function checkChars()
{
	var iChars = "éèàçïëêîâûùôò!#$%^&*()+=[]\\\';,/{}|\":<>?";
	var resultChars = true;
	for (var g = 0; g < document.email_form.newemail.value.length; g++) 
		{		
			if (iChars.indexOf(document.email_form.newemail.value.charAt(g)) != -1) 
			{
			alert ("Les caractères spéciaux sont interdits \nCaractère special détecté : "+document.email_form.newemail.value.charAt(g)+" \nMerci de corriger l'adresse e-mail");
			document.email_form.newemail.select(); 
			resultChars = false;
			break;
			}
		}
	return resultChars;
}




// Vérification format d'E-mail
// ---------------------------------
// utilise checkChars() pour ajouter la verif de caracters speciaux
function checkEmail() 
{
if (document.email_form.newemail.value.length >0) 
	{
	 i=document.email_form.newemail.value.indexOf("@")
	 j=document.email_form.newemail.value.indexOf(".",i)
	 k=document.email_form.newemail.value.indexOf(",")
	 kk=document.email_form.newemail.value.indexOf(" ")
	 jj=document.email_form.newemail.value.lastIndexOf(".")+1
	 len=document.email_form.newemail.value.length

	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3))
		{
			if(checkChars())
				{
				return true;
				}
			else
				{
				return false;
				}
		}
	else 
		{
		alert("L'adresse e-mail est invalide. \nMerci de la corriger.");
		document.email_form.newemail.select(); 
		return false;
		}
	}
else 
	{
	alert("Le champ e-mail est vide. \nVous devez obligatoirement le remplir.");
	document.email_form.newemail.select(); 
	return false;
	}
}




/* VERIFICATION DES CHAMPS DU FORMULAIRE DE CONTACT */
/****************************************************/
function checkFormFields() 
{
	if (document.forms['Proj'].proj.value ==""){
		alert ("Merci d'apporter un petit peu plus de précision à votre message");
		return false;
	}
	if (document.forms['Proj'].contact.value ==""){
		alert ("Merci de nous fournir quelques informations sur votre situation géographique et/ou vos coordonnée téléphonique");
		return false;
	}
	if (document.forms['Proj'].mail.value ==""){
		alert ("Votre E-mail facilitera la réponse à votre message");
		return false;
	}
return true;
}

