/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}
	
function isChecked(form, name){
		var elements = form.elements;
		for (i = 0; i < elements.length; i++){
				var element = elements[i];
				if ((element.name == name) && (element.checked))
					return true;
		}
		return false;
}

function initAJAX(){
	try{// Firefox, Opera 8.0+, Safari
    	return new XMLHttpRequest();
    }
  catch (e){
    try{// Internet Explorer
      return new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
      try{
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e){
        alert("Your browser does not support AJAX!");
        return false;
      }
     }
    }
  }
  
  
 function checkSearchFieldIn(){
	if (document.forms[0].text.value == 'Votre recherche')
		document.forms[0].text.value = '';
}

function checkSearchFieldOut(){
	if (document.forms[0].text.value == '')
		document.forms[0].text.value = 'Votre recherche';
}

function searchEngine(){
	if (document.forms[0].text.value == 'Votre recherche'){
			alert("Veuillez saisir un texte à chercher");
			document.forms[0].text.focus();
			return;
	}
	document.forms[0].action = 'search.php';
	document.forms[0].method = 'get';
	document.forms[0].submit();
}

function newsletter(){
	var form = document.forms[0];
	/*
	if (form.p_age.selectedIndex == 0){
		alert("Veuillez préciser votre âge");
		form.p_age.focus();
		return;
	}
	if (form.p_pays.selectedIndex == 0){
		alert("Veuillez préciser votre pays");
		form.p_pays.focus();
		return;
	}	
	*/
	if (!echeck(form.email.value)){
		alert("Veuillez saisir un e-mail valide");
		form.email.focus();
		return;
	}
	form.action = 'newsletter.php';
	form.method = 'get';	
	form.submit();
}

function checkNLFieldIn(){
	if (document.forms[0].email.value == 'Tapez votre e-mail')
		document.forms[0].email.value = '';
}

function checkNLFieldOut(){
	if (document.forms[0].email.value == '')
		document.forms[0].email.value = 'Tapez votre e-mail';
}

function affiche(divID){
		var sousMenuDiv = document.getElementById('sousmenu');
		var buffSousMenuDiv = document.getElementById(divID);
		
		var originalHTMLID = sousMenuDiv.innerHTML;
		var originalColor = sousMenuDiv.style.backgroundColor;
		sousMenuDiv.innerHTML = buffSousMenuDiv.innerHTML;
		sousMenuDiv.style.backgroundColor = buffSousMenuDiv.style.backgroundColor;
}

function reaffiche(){
	var sousMenuDiv = document.getElementById('sousmenu');
	var buffSousMenuDiv = document.getElementById('sousmenuoriginal');
	//sousMenuDiv.innerHTML = buffSousMenuDiv.innerHTML;
	sousMenuDiv.innerHTML = originalHTMLID;
	sousMenuDiv.style.backgroundColor = originalColor;
}

function initMyDivs(){
	originalHTMLID = document.getElementById('sousmenu').innerHTML;
}

function partage(url, targetName){
	window.open(url, targetName, 'width=800&height=500&directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
