//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//   Document JavaScript de fonctions
//
//   SITE: www.nom-ad.ch
//   AUTHOR: Johan Noverraz, www.additive.ch
//   LAST CHANGE: 27.03.07
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// déclaration des variables
initialiseContent1 = 'false';
initialiseContent2 = 'false';
initialiseContent3 = 'false';
initialiseContent4 = 'false';

// ajout de méthode à la fonction String pour la gestion d'espaces dans une châine...
String.prototype.trim = function () {
   return this.replace(/^\s*|\s*$/,"");
}
String.prototype.deleteSpaces= function () {
   return this.replace(/\s+/g,"");
}

function initAlign(){
	// function de replacement du site selon la taille de l'écran...
}

// fonction d'affichage/désaffichage de block css
function change_display(id, display_value) {
	
	if(document.getElementById) {
		document.getElementById(id).style.display = display_value;
	} else if(document.all) {
		document.all(id).style.display = display_value;
	}

}
function change_zindex(id, index) {
	
	if(document.getElementById) {
		document.getElementById(id).style.z_index = index;
	} else if(document.all) {
		document.all(id).style.z_index = index;
	}

}
function replaceDiv(id, top, left){
	if(document.getElementById) {
		document.getElementById(id).style.top = top;
		document.getElementById(id).style.left = left;
	} else if(document.all) {
		document.all(id).style.top = top;
		document.all(id).style.left = left;
	}
}
function change_visibility(id, visibility_value) {
	
	if(document.getElementById) {
		document.getElementById(id).style.visibility = visibility_value;
	} else if(document.all) {
		document.all(id).style.visibility = visibility_value;
	}

}

var allPageTags = new Array(); 

function doSomethingWithClasses(theClass) {
	//Populate the array with all the page tags
	var allPageTags=document.getElementsByTagName("*");
	//Cycle through the tags using a for loop
	for (i=0; i<allPageTags.length; i++) {
	//Pick out the tags with our class name
		if (allPageTags[i].className==theClass) {
			//Manipulate this in whatever way you want
			allPageTags[i].style.display='none';
		}
	}
} 


function changeColorField(typeChange, form, field){
	if(typeChange == 'red'){
		error = true;
		document.forms[form].elements[field].style.backgroundColor = '#531913';
		document.forms[form].elements[field].style.color = '#ffffff';
	} else {
		if(document.forms[form].elements[field].value != ''){
			document.forms[form].elements[field].style.backgroundColor = '#ffffff';
			document.forms[form].elements[field].style.color = '#000000';
		}
	}
}


function checkFormContact() { 
  	error = false;
	msg = '';
	if(document.formContact.eMail.value == ''){
		msg += '<li>Votre <strong>adresse e-mail</strong> est obligatoire.</li>';
		changeColorField('red', 'formContact', 'eMail');
		error = true;
	} else {
		var verif = new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$");
		if (verif.exec(document.formContact.eMail.value) == null){
			msg += '<li>L\'<strong>adresse e-mail</strong> est incorrecte.</li>';
			error = true;
			changeColorField('red', 'formContact', 'eMail');
		} else {
			changeColorField('normal', 'formContact', 'eMail');
		}
	}
	if(document.formContact.message.value == ''){
		msg += '<li>Aucun texte n\'a &eacute;t&eacute; saisi.</li>';
		changeColorField('red', 'formContact', 'message');
		error = true;
	} else {
		changeColorField('normal', 'formContact', 'message');
	}
	if(error == true){
		change_display("errorFormMsg", "block");
		document.getElementById("errorFormMsg").innerHTML = '<hr class="red" /><p>L\'envois du formulaire a g&eacute;n&eacute;r&eacute; les erreurs suivantes:</p><ul id="errorList">' + msg + '</ul><hr class="red" />';
	} else {
		document.formContact.method = "POST";
		document.formContact.action = "siteHtml.php";
		document.formContact.submit();
	}
}

function displayPopup(numContent, version){
	// on désaffiche tous les contenus
	for(i=1;i<5;i++){
		change_display("content"+i, 'none');
		change_zindex("content"+i, '10');
	}
	
	change_display('news', 'none');
	change_display('contact', 'none');
	change_display('menuLargePopup', 'none');
	change_display('largePopup', 'none');
	
	if(numContent>0){
		
		// on replace #site au bon endroit => valeur de base -5000px -5000px (permet de laisser les liens dans flash accessible)
		replaceDiv('site', '80px', '240px');
		
		// on affiche la popup
		change_display('largePopup', 'block');
		
		// on affiche le contenu voulu
		change_display("content"+numContent, 'block');
		
		change_zindex("content"+numContent, '70');
		
		// on change le lien d'impression pour lui donner les bonnes valeures...
		if(document.getElementById) {
			document.getElementById("printLink").innerHTML = '</div><li style="background-image:url(images/bg_menuPopup_li.png);"><a href="javascript:;" onclick="printPage(' + numContent + ');" title="imprimer le menu">imprimer le menu</a></li>';
		} else if(document.all) {
			document.all("printLink").innerHTML = '</div><li style="background-image:url(images/bg_menuPopup_li.png);"><a href="javascript:;" onclick="printPage(' + numContent + ');" title="imprimer le menu">imprimer le menu</a></li>';
		}
		
		// on initialise les scrollbars si ce n'est pas déjà fait...
		if(eval("initialiseContent" + numContent) == 'false'){
			// on initialise la scrollbar
			ScrollLoad ("scrollholder"+numContent, "scroll"+numContent, false);
			eval("initialiseContent" + numContent + "= 'true';");
		}
		
		// on affiche le menu
		change_display('menuLargePopup', 'block');
	
	} else {
		
		replaceDiv('site', '-5000px', '-5000px');
		
		if(version == 'html'){
			displayNews();
		}
		
	}
	
}

function displayNews(){
	// on désaffiche tous les contenus
	for(i=1;i<5;i++){
		change_display("content"+i, 'none');
	}
	
	// on replace #site au bon endroit => valeur de base -5000px -5000px (permet de laisser les liens dans flash accessible)
	replaceDiv('site', '80px', '240px');
	
	change_display('contact', 'none');
	change_display('menuLargePopup', 'none');
	change_display('largePopup', 'none');
	
	change_display('news', 'block');
	
}

function displayContact(){
	// on désaffiche tous les contenus
	for(i=1;i<5;i++){
		change_display("content"+i, 'none');
	}
	
	// on replace #site au bon endroit => valeur de base -5000px -5000px (permet de laisser les liens dans flash accessible)
	replaceDiv('site', '80px', '240px');
	
	change_display('news', 'none');
	
	change_display('menuLargePopup', 'block');
	change_display('largePopup', 'block');
	
	change_display('contact', 'block');
	
}
function printPage(sectionPrint){
	//alert("dw_scrollObjs.scrollholder" + sectionPrint + ".glideTo(0,0);");
	eval("dw_scrollObjs.scrollholder" + sectionPrint + ".glideTo(0,0);");
	
	timeOut = window.setTimeout('change_display(window.print())', 1000 );
	
}