// JavaScript Document

function get_xhr()
{
var xhr = null;
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
			//	alert("Msxml2.XMLHTTP");
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				//				alert("ActiveXObject.XMLHTTP");
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
					//		alert("XMLHttpRequest.XMLHTTP");
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return null;
	}
	return xhr;
}

/* mes fonction */

//pagination 


function set_pagination(page)
{
	 var xhr=get_xhr();
		xhr.onreadystatechange = function() { 
			if (xhr.readyState==4) {	
				
				
					//document.location.href=document.location.href;
					document.location.reload();
					document.getElementById('loading_pagination').innerHTML='';				
				// var scripts = document.getElementsByTagName('script');	
				 //for (var i=0;i<scripts.length;i++)	eval(scripts[i].innerHTML); 
			}
		};   
	
	document.getElementById('loading_pagination').innerHTML='<img src="images/loading.gif" style=" float:left; ">';
	var url="ajax/libs_ajax.php?pagination="+page;	
	
	xhr.open("GET",url,true);
	xhr.send(null);		
}
function  page(lien,page)
{
		location.href=lien+'?page='+page;
	
}

function set_semaine(date)
{
	 var xhr=get_xhr();
		xhr.onreadystatechange = function() { 
			if (xhr.readyState==4) {	
				
				
					//document.location.href=document.location.href;
					document.location.reload();
					document.getElementById('loading_semaine').innerHTML='';				
				// var scripts = document.getElementsByTagName('script');	
				 //for (var i=0;i<scripts.length;i++)	eval(scripts[i].innerHTML); 
			}
		};   
	
	document.getElementById('loading_semaine').innerHTML='<img src="images/loading.gif" style=" float:left; ">';
	var url="ajax/libs_ajax.php?date="+date;	
	
	xhr.open("GET",url,true);
	xhr.send(null);		
}
function annuler()
{
	 var xhr=get_xhr();
		xhr.onreadystatechange = function() { 
			if (xhr.readyState==4) {	
				
				
					//document.location.href=document.location.href;
					document.location.reload();
					document.getElementById('loading_pagination').innerHTML='';				
				// var scripts = document.getElementsByTagName('script');	
				 //for (var i=0;i<scripts.length;i++)	eval(scripts[i].innerHTML); 
			}
		};   
	
	document.getElementById('loading_pagination').innerHTML='<img src="images/loading.gif" style=" float:left; ">';
	var url="ajax/libs_ajax.php?action=annuler";	
	
	xhr.open("GET",url,true);
	xhr.send(null);		
}
var onclik="";
function onselect(id)
{
	if(onclik!=id)
		document.getElementById(id).style.backgroundColor="#ccc";
		
	
}
function onout(id)
{
	if(onclik!=id)
		document.getElementById(id).style.backgroundColor="#f6fbff";
	
}
function onclique(id)
{
		if(onclik!=id)
		{	
				if(onclik!="")
				document.getElementById(onclik).style.backgroundColor="#f6fbff";
				document.getElementById(id).style.backgroundColor="#999";
				
		}
		else document.getElementById(id).style.backgroundColor="#f6fbff";
		onclik=id;
		
	
}
function vider_champs(obj)
{
		obj.value='';
		document.getElementById('newsletter').style.color='#999';
}

function remplir_champs(obj,value)
{
		if(obj.value=='')
			obj.value=value;
}
function select_lien(lien)
{
	document.getElementById(lien).style.backgroundImage='url(images/picto4.jpg)';
	document.getElementById(lien+'_a').style.color='#4c94b6';	
}
function newsletter(){
	
	email=document.getElementById('newsletter').value; 
	if(!VerifierAdresseMail(email))
	{
		document.getElementById('newsletter').value='  e-mail invalide...'; 
		document.getElementById('newsletter').style.color='#FF9900';
	    return;		
	}

	var xhr = get_xhr();
    xhr.onreadystatechange= function()
    { 
         if(xhr.readyState== 4)
         {
          
               document.getElementById('loading_emial').innerHTML=xhr.responseText;
			   rep=new String(xhr.responseText);
				
			   document.getElementById('newsletter').value=xhr.responseText; 
  			   if(rep.indexOf('Merci')==-1)  document.getElementById('newsletter').style.color='#f00';
			   else document.getElementById('newsletter').style.color='#03529d';
		
         }
        
    }; 
	 document.getElementById('loading_emial').innerHTML='<img src="admin/images/loading2.gif"  style=" width:100px; height:10px;margin-top:20px; float:left">';
	 
   
    var url="ajax/email.php?email="+email;	
	xhr.open("GET",url,true);

   xhr.send(null); 

} 

function VerifierAdresseMail(mailteste) 
{ 
  var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(reg.test(mailteste))
	{
		return true;
	}
	else
	{
		return false;
		
	}

}
function verfier_form_contact()
{
	table_samps=new Array('nom','email','tel','message');
	submite=true;
	for(i=0;i<4;i++)
	{
		if(document.getElementById(table_samps[i]).value=='' || document.getElementById(table_samps[i]).value=='-1') {
			document.getElementById(table_samps[i]).style.border='#f00 solid 1px';
			 submite=false;
		}
		else document.getElementById(table_samps[i]).style.border='#009900 solid 1px';
		
	}
	
	if(!valider_mail()) submite=false ;
	
	if(submite==false) 
	{
		document.getElementById('message1').innerHTML='Verfiez les Champs Obligatoire en rouge ';
		document.getElementById('message2').innerHTML='Verfiez les Champs Obligatoire en rouge ';
	}

	return submite;
}

function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

