function InitAjax()
{
	var Ajax=false; 
	try { 
		Ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
	}catch (e) { 
		try { 
			Ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
		}catch (E) { 
			Ajax = false; 
		} 
	}
	if (!Ajax && typeof XMLHttpRequest!='undefined') { 
		Ajax = new XMLHttpRequest(); 
	} 
	return Ajax;
}

function showPassword(){
	var div = document.getElementById("inputpd");	
	if(getCheckedValue("checksave")==0){
		div.style.display="none";
	}else{
		div.style.display="block";
	}
	
}

function checkRegister(form)
{
    var AlertInput = "s'il vous plaît d'entrée:\n";	
	var mesg = "";
	if(form.nom.value == "") mesg += "nom\n";
	if(form.prenom.value == "") mesg += "prnom\n";
	if(form.tel.value == "") mesg += "Téléphone\n";
	if(form.email.value == "") mesg += "E-mail\n";
	if(form.ville.value == "") mesg += "ville\n";
	if(form.cp.value == "") mesg += "cp\n";
	if(form.adresse.value == "") mesg += "adresse\n";
	
	
	if(mesg != ""){
		mesg = AlertInput + mesg;
		alert(mesg);
		return false;
	}
	
	if (getCheckedValue("checksave") ==1){
		if (form.password1.value=="" || form.password2.value==""){
			var mesg = "s'il vous plaît d'entrée:\n";
			mesg += "mot de passe\n";
			alert(mesg);
			return false;
		}
		if (form.password1.value != form.password2.value){
			alert("Entrez votre mot de passe erroné.");
			return false;
		}
	}

	var postStr = "";
	postStr  = postStr + "nom="+form.nom.value; 
	postStr  = postStr + "&prenom="+form.prenom.value;
	postStr  = postStr + "&tel="+form.tel.value;
	postStr  = postStr + "&email="+form.email.value;
	postStr  = postStr + "&ville="+form.ville.value;
	postStr  = postStr + "&cp="+form.cp.value;
	postStr  = postStr + "&adresse="+form.adresse.value;

	postStr  = postStr + "&piscine1="+ getCheckedValue("piscine1");
	postStr  = postStr + "&piscine2="+ getCheckedValue("piscine2");
	postStr  = postStr + "&forme="+ getCheckedValue("forme");
	
	postStr  = postStr + "&lemoins="+form.lemoins.value;
	postStr  = postStr + "&leplus="+form.leplus.value;
	
	postStr  = postStr + "&taille="+ getCheckedValue("taille");
	
	postStr  = postStr + "&taille_largeur="+form.taille_largeur.value;
	postStr  = postStr + "&taille_longueur="+form.taille_longueur.value;
	
	postStr  = postStr + "&mois="+form.mois.value;
	postStr  = postStr + "&annee="+form.annee.value;
	
	postStr  = postStr + "&localtech="+getCheckedValue("localtech");
	postStr  = postStr + "&chauffage="+getCheckedValue("chauffage");
	postStr  = postStr + "&eclairage="+getCheckedValue("eclairage");
	
	postStr  = postStr + "&check1="+getCheckedValue("check1");
	postStr  = postStr + "&check2="+getCheckedValue("check2");
	postStr  = postStr + "&check3="+getCheckedValue("check3");
	postStr  = postStr + "&check4="+getCheckedValue("check4");
	postStr  = postStr + "&check5="+getCheckedValue("check5");
	postStr  = postStr + "&check6="+getCheckedValue("check6");
	postStr  = postStr + "&check7="+getCheckedValue("check7");
	postStr  = postStr + "&check8="+getCheckedValue("check8");
	postStr  = postStr + "&check9="+getCheckedValue("check9");
	postStr  = postStr + "&check10="+getCheckedValue("check10");
	postStr  = postStr + "&check11="+getCheckedValue("check11");
	postStr  = postStr + "&check12="+getCheckedValue("check12");
	postStr  = postStr + "&check13="+getCheckedValue("check13");
	
	postStr  = postStr + "&checknews="+getCheckedValue("checknews");
	postStr  = postStr + "&checksave="+getCheckedValue("checksave");	
	
	postStr  = postStr + "&other="+form.other.value;
	
	postStr  = postStr + "&password="+form.password1.value;	
	

	var url = "include/ajax.php?A=register";
	var Ajax = InitAjax();			
	Ajax.open("POST", url, true); 					
	Ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 	
	Ajax.send(postStr); 	
	Ajax.onreadystatechange = function() {			
		if (Ajax.readyState == 4 && Ajax.status == 200) {
		  var txt=  Ajax.responseText;
		  var re = /error:/i;
		  if (txt.search(re) == -1){
			    var flashdiv = document.getElementById("flash");				
				flashdiv.innerHTML = txt;		   
        	}else{
				txt = txt.replace(re,"");
			    var error = document.getElementById("checkinfo");				
				error.innerHTML = txt;
			}
		}
	}
	return false;
}


function getWelcome(form)
{  
	if(form.email.value == ""){
		var mesg = "Saisissez votre E-mail s’il vous plaît";			
		alert(mesg);
		return false;		
	}
	if(form.password.value == ""){
		var mesg = "S'il vous plaît entrer votre mot de passe";			
		alert(mesg);
		return false;		
	}

	var url = "include/ajax.php?A=login&email="+form.email.value+"&password="+form.password.value;
	var Ajax = InitAjax();							
	Ajax.open("GET", url, true); 					
	Ajax.onreadystatechange = function() {			
		if (Ajax.readyState == 4 && Ajax.status == 200) {
			 txt = Ajax.responseText;
			if (txt.indexOf("error") != -1){
				alert('erreur de saisie!');
			}else{
				var div = document.getElementById("client");				
				div.innerHTML = txt;
			}
		} 
	}	
	Ajax.send(null); 
	return false;
}

function getPD(form)
{  
	if(form.email.value == ""){
		var mesg = "Saisissez votre E-mail s’il vous plaît";			
		alert(mesg);
		return false;		
	}

	var url = "include/ajax.php?A=getPD&email="+form.email.value;
	var Ajax = InitAjax();							
	Ajax.open("GET", url, true); 					
	Ajax.onreadystatechange = function() {			
		if (Ajax.readyState == 4 && Ajax.status == 200) {
			 txt = Ajax.responseText;
			 alert(txt);
		} 
	}	
	Ajax.send(null); 
	return false;
}


function getView(view)
{  
    var div = document.getElementById("flash");
	var url = "view/control.php?view="+view;
	var Ajax = InitAjax();							
	Ajax.open("GET", url, true); 					
	Ajax.onreadystatechange = function() {			
		if (Ajax.readyState == 4 && Ajax.status == 200) {
			div.innerHTML = Ajax.responseText;
		} 
	}	
	Ajax.send(null); 
	return false;
}

function logout()
{  
	var url = "view/control.php?view=logout";
	var Ajax = InitAjax();							
	Ajax.open("GET", url, true); 					
	Ajax.onreadystatechange = function() {			
		if (Ajax.readyState == 4 && Ajax.status == 200) {
			document.location='index.php';
		} 
	}	
	Ajax.send(null); 
	return false;
}


function getCheckedValue(e){
	var obj=document.getElementsByName(e);
	if (obj.length==0)  return 0;
	for(var i=0;i<obj.length;i++)   
    {
		if(obj[i].checked){
			return obj[i].value;
		}
	}
	return 0;
}

function getAbsLeft(e){
	var l=e.offsetLeft;
	while(e=e.offsetParent) 
		l +=  e.offsetLeft;
	return l;
}   

function getAbsTop(e){
	var t=e.offsetTop; 
	while(e=e.offsetParent)
		t += e.offsetTop; 
	return t;
}   

function locateBox(){
//	document.getElementById("mydiv").offsetHeight
   var h = document.getElementById("bodymain").offsetHeight;
   h = h+10;
   h = h+"px";
   var boxborder=document.getElementById("rightboxborder");
   boxborder.style.height = h;
   var box=document.getElementById("rightbox");
   box.style.height = h;   

   var e=document.getElementById("locate");
   var left = getAbsLeft(e);
   box.style.left = left+"px";
   left = left+3;
   boxborder.style.left = left+"px";   
}


function setCookie(name,value)
{
    var Days = 2000;
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(name)
{

    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}

function deleteCookie(name) {
  var exp = new Date();   
  exp.setTime (exp.getTime() - 1);   
  document.cookie = name + "=null; expires=" + exp.toGMTString(); 
} 


function changeImg(idName,imgname){
  var re =  '.';
  var overimg = imgname.replace(re,'2.');
  var e=document.getElementById(idName);
  e.onmouseover=function() {
  	this.src=overimg;
  }
  e.onmouseout=function(){
  	this.src=imgname;
  }  
}

function changeImgs(){
  var ids= new Array('searchid','loginid');
  var imgs= new Array('search.png','login.png');
  var re =  '.';
  for (i = 0; i < imgs.length; i++)
    {
   		var imgname = "images/"+imgs[i];
		var overimg = imgname.replace(re,'2.');
		var e=document.getElementById(ids[i]);
		e.onmouseover=function() {
	  		this.src=overimg;
		  }
		e.onmouseout=function(){
		  	this.src=imgname;
		  }  		
    }

}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function  flashPlayer(){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="455" id="switcher" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="flash/switcher.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="flash/switcher.swf" quality="high" bgcolor="#ffffff" width="550" height="455" name="switcher" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}


function playswf(sFile,sWidth,sHeight,sbg){
  txt ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
  txt = txt +'" codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ sWidth +'" height="'+ sHeight +'" align="middle">';
  txt = txt +' <param name="allowScriptAccess" value="always" /> ';  
  txt = txt +' <param name="allowFullScreen" value="false" /> ';    
  txt = txt +' <param name="bgcolor" value="'+sbg+'" /> ';      
  txt = txt +' <param name="movie" value="'+ sFile +'" /> ';
  txt = txt +' <param name="quality" value="high" /> ';
  txt = txt +' <embed src="'+ sFile +'" quality="high" bgcolor='+sbg+' align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="'+ sWidth +'" height="'+ sHeight +'"></embed> ';
  txt = txt +'</object> ';
  var show = document.getElementById("flash");
  show.innerHTML = txt;
}
