	/**
 * 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.searchform.text.value == 'Mots cles')
		document.searchform.text.value = '';
}

function checkSearchFieldOut(){
	if (document.searchform.text.value == '')
		document.searchform.text.value = 'Mots cles';
}

function recherche(){
	var query = document.searchform.query.value;
	if (query.length == 0){
			alert("Veuillez saisir un texte à chercher");
			document.searchform.query.focus();
			return;
	}
	var _radio = document.getElementById('jcdsearchjdc');
	if (_radio.checked)
		url = 'search.php?p=1&q=';
	else
		url = 'http://www.google.fr/search?q=';
		
	url += encodeURIComponent(query);
		
	window.location = url;
}
function newsletter(){
	var form = document.nlform;
	if (form.p_pays.selectedIndex == 0){
		alert("Veuillez préciser votre pays");
		form.p_pays.focus();
		return;
	}	
	if (!echeck(form.p_mail.value)){
		alert("Veuillez saisir un e-mail valide");
		form.p_mail.focus();
		return;
	}
	
	if (form.p_mail.value != form.p_mail2.value){
		alert("les e-mails saisis sont différents");
		form.p_mail2.focus();
		return;
	}
	form.submit();
}

function checkNLFieldIn(){
	if (document.nlform.p_mail.value == 'Votre adresse e-mail')
		document.nlform.p_mail.value = '';
}

function checkNLFieldOut(){
	if (document.nlform.p_mail.value == '')
		document.nlform.p_mail.value = 'Votre adresse e-mail';
}

function changeto(highlightcolor){
  obj=event.srcElement
  if (obj.tagName=="TR" || obj.tagName=="TABLE") return
  while(obj.tagName!="TD") obj=obj.parentElement
  if (obj.style.backgroundColor!=highlightcolor && obj.id!="ignore")
    obj.style.backgroundColor=highlightcolor
  }


function changeback(originalcolor){
  if (event.fromElement.contains(event.toElement) || obj.contains(event.toElement) || obj.id=="ignore")
      return
  if (event.toElement!=obj) obj.style.backgroundColor=originalcolor
  }
  
  
 function mySetHomePage(){
	 this.style.behavior='url(#default#homepage)';
	 this.setHomePage('http://www.journaldumali.com');
 }
 
 function myFavorites(){
			url = "http://www.journaldumali.com";
			titre = "Journal du Cameroun.com";
			if (document.all)
				window.external.AddFavorite(url, titre);	 
 }
 
 	function commente(){
		var form = document.postform;
		var ctr = form.ctr.value;
		
		if (ctr != ctrInit){
			alert("Le nombre de confirmation anti-SPAM est erroné");
			form.ctr.focus();
			return;
		}
		if (form.auteur.value.length == 0){
			alert("Veuillez saisir votre pseudo");
			form.auteur.focus();
			return;
		}

		var email = form.mail.value;
		if ((email.length != 0) && !echeck(email)){
			alert("Veuillez saisir un e-mail valide");
			form.mail.focus();
			return;
		}

		if (form.titre.value.length == 0){
			alert("Veuillez saisir le titre de votre commentaire");
			form.titre.focus();
			return;
		}

		if (form.msg.value.length == 0){
			alert("Veuillez saisir votre commentaire");
			form.msg.focus();
			return;
		}
		
		var radio = document.getElementById('agree');
		if (!radio.checked){
			alert("Vous devez accepter les conditions d'utilisation");
			return;
		}
		
		form.action = 'artdisti.php';
		form.method = 'post';

		form.submit();
	}
