// JavaScript Document
var domaine='http://www.clc.fr/';


function lister_detail_sejour(val, divId)
{
	
	div =document.getElementById(divId)	
	
	var res=file(domaine+'ajax_lister_detail_sejour.php?nocache='+new Date().getTime()+'&type='+val);
	
	div.innerHTML=res;
	
	
}

function afficher_detail(detail)
{
	if(detail!="")
	{
		var url=domaine+'administrateur/modifier-detail-sejour.php?id_modif='+detail;
	
		window.location.href=url;
	}
}


function display(divId)
{
	div =document.getElementById(divId)	
	
	if(div.style.display=='block')
	{
		div.style.display='none'; return 0
	}
	else
	{
		div.style.display='block'; return 1
	}
}


function display_img(divId,img_id)
{
	div =document.getElementById(divId);
	img =document.getElementById(img_id);
	src=img.name+'-up.gif';
	src2=img.name+'-down.gif';
		
	if(div.style.display=='block')
	{
		div.style.display='none'; 
		img.src=domaine+'images/'+src;
	}
	else
	{
		div.style.display='block'; 
		img.src=domaine+'images/'+src2;
	}
}



function afficher(divId)
{
	div =document.getElementById(divId)	
		
	div.style.display='block';

}

function cacher(divId)
{
	div =document.getElementById(divId)	
		
	div.style.display='none'; 

}

function submit_form_inscription(id_form, IDabsolue)
{
	
	tmpFormulaire=document.getElementById(id_form);
	tmpFormulaire.IDabsolue.value=IDabsolue;
	tmpFormulaire.submit();
	
}

function submit_form_inscription_se(id_form, IDabsolue)
{
	
	tmpFormulaire=document.getElementById(id_form);
	//tmpFormulaire.IDabsolue.value=IDabsolue;
	
	//popup=window.open('message_attente.php','popupInscription','width=500,height=200,status=yes, scrollbars=yes');
			
	//tmpFormulaire.target=popup.name; //  fonctionnne pas avec le hhtps/http
	//tmpFormulaire.target='popupInscription';
	
	alert('Vous allez entrer en zone sécurisée, merci de patienter durant le chargement.\nCliquez sur OK');
	//popup.window.focus();
	tmpFormulaire.submit();
	
}

function ajouter_panier(ref,type)
{
	//alert(type);
	setCookie('sejour['+ref+']',type,1);
	location.reload(); 
}

function supprimer_panier(ref)
{
	
	setCookie('sejour['+ref+']',ref,-1);
	location.reload(); 
}

function setCookie(nom,valeur,jours)
{
	//alert(nom+' '+valeur);
	var expDate = new Date();
	var path='/';
	expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000));
	
	document.cookie = nom + "=" + escape(valeur)+ ";expires=" + expDate.toGMTString()+"; path="+path;
	//document.cookie = name+"="+value+"; path="+path+";

}
	
	
function calculer(prx, supp)
{
	if(supp!="")
	{
		var res=parseInt(prx)+parseInt(supp);
		document.getElementById('tarif').innerHTML=res;
		
		if(supp>0){document.getElementById('prix_prea').innerHTML=' +'+parseInt(supp);}
		else{document.getElementById('prix_prea').innerHTML='';}
	}
}



function fermer(divId)
{
	var contenant=document.getElementById('contenu_page');
	
	var exist=document.getElementById(divId);
	
	
	if(exist){contenant.removeChild(exist);	}
}


function new_div(adresse,e, haut, classe)
{
	var contenant=document.getElementById('contenu_page');
	
	var exist=document.getElementById('div_inscr_sejour');
	
	if(exist){contenant.removeChild(exist);	}
	
	
	
	var div=document.createElement("div");
	div.id="div_inscr_sejour";
	div.className=classe;
	
	//calcule la position du div désactivé pour l'instant
	//var H=(document.documentElement.scrollTop);
	//var coord=parseInt(H)+parseInt(haut);
	//div.style.top=coord+'px';
	
	div.innerHTML='<div style="padding-top:50px;"><img src="'+domaine+'images/ajax-loader.gif" /></div>';
	
	contenant.appendChild(div);
	
	var contenu=file(adresse);
	
	div.innerHTML=contenu;
}


function trouver_sejour(id)
{
	var fichier=domaine+'ajax_trouver_sejour.php?ref='+id;
	
	var resulat=file(fichier);
	
	var div=document.getElementById('div_inscr_sejour');
	var div_cont=document.getElementById('desc_sejour');
	
	div.style.height='250px';
	
	div_cont.innerHTML=resulat;
	
}

function pop_up (adresse)
{
	window.open(adresse,null,'status=no, directories=no, toolbar=no, location=no, menubar=no, scrollbars=no, resizable=no, width=540, height=330, left=250, top=180');
}


var Coordx = 0;
var Coordy = 0;
e=window.event;

function mousex(e)
{
	var x, y;
	if (ev.x!=null && ev.y!=null)
	{
		x = ev.x;
		y = ev.y;
	}
	
	if (ev.clientX!=null && ev.clientY!=null)
	{
		x = ev.clientX;
		y = ev.clientY;
	}
	
	return (x);
}

function mousey(ev)
{
	var x, y;
	if (ev.x!=null && ev.y!=null)
	{
		x = ev.x;
		y = ev.y;
	}
	
	if (ev.clientX!=null && ev.clientY!=null)
	{
		x = ev.clientX;
		y = ev.clientY;
	}
	
	return (y);
}


function file(fichier)
{
    if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest(); // FIREFOX
     
	 else if(window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");// IE
    
	 else return(false); 
	 xhr_object.open("GET", fichier, false);
     xhr_object.send(null);
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
}

function ecrire(url, divId)
{
	var cont=file(url);
	var div=document.getElementById(divId);
	div.innerHTML=cont;
}

function charger_menu(div_id, nom_menu)
{
	var div_dest=document.getElementById(div_id);	//div_id='div_menu'
	
	var exist=document.getElementById("contenu_"+div_id);
	
	if(exist)
	{
		if(exist.name==nom_menu)
		{
			return;
		}
		else
		{
			div_dest.removeChild(exist);
		}
	}
		
	var new_div= document.createElement("div");
	new_div.id="contenu_"+div_id;
	new_div.name=nom_menu;
	new_div.className='description';
	
	var res=file(domaine+'ajax_charger_menu.php?menu='+nom_menu);
	
	new_div.innerHTML=res;
	
	div_dest.appendChild(new_div);
}


function afficher_desc(div_id, nom_desc)
{
	var res=file(domaine+'ajax_afficher_desc.php?desc='+nom_desc);
	
	
	var div_content=document.getElementById('content');
	
	var exist=document.getElementById("contenu_"+div_id); //div_id='desc_chapitre'
	
	if(exist)
	{
		if(exist.name==nom_desc){return;}
		
		else{div_content.removeChild(exist);}
	}
	div_content.innerHTML='';
	
	var new_div= document.createElement("div");
	new_div.id="contenu_"+div_id;
	new_div.name=nom_desc;
	new_div.className='description';
	
	new_div.innerHTML=res;

	div_content.appendChild(new_div);
}


function afficher_sous_menu(obj, menu)
{
	div_content=document.getElementById('content');
	div_content.innerHTML='';
	
	var res=file(domaine+'ajax_afficher_sous_menu.php?menu='+menu);
	
	
	//var new_div= document.createElement("div");
//	new_div.id="contenu_"+div_id;
//	new_div.name=nom_desc;
	
	
	div_content.innerHTML=res;
}


function afficher_desc2(menu, ss_menu)
{
	var div_content=document.getElementById('content');
	
	var exist=document.getElementById('desc2');
	if(exist){div_content.removeChild(exist);}
	
	var desc2= document.createElement("div");
	desc2.id='desc2';
	desc2.className='desc2';
	
	var res=file(domaine+'ajax_afficher_desc2.php?menu='+menu+'&ss_menu='+ss_menu);
	
	desc2.innerHTML=res;
	
	div_content.appendChild(desc2);
}

function emailCheck(val) 
{
	if (chk(val)){ return true;}
	
	else {return false;}
}




function chk(emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
	return false
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null)
	return false
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255)
			return false
		}
		return true
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null)
	return false
	
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	{
		return false
	}
	
	if (len<2)
	return false
	
	return true;
}


function valider_form_mail(form)
{	
	var err=0;	var msg1='';	var msg2='';
	var email= form.email.value;
	
	if(email=='')
	{
		err=1;
		msg1='\n - votre adresse mail';
	}
	else
	{
		if( VerifAdresseMail(email) ==false )
		{
			msg1='\n - une adresse mail valide';
		}	
		
	}
	
	if(form.message.value=='')
	{
		err=1;
		msg2='\n - un message';
	}
	
	
	
	if(err==1)
	{
		alert('Merci de renseigner :'+msg1+msg2);	
		return false;
	}
	else
	{
		return true;	
	}
}

function envoyer_mail(ref, nom, email, sujet, message)
{
	//alert('&message'+escape(message));
	res=file(domaine+'ajax_envoie_mail.php?ref='+ref+'&nom='+escape(nom)+'&email='+escape(email)+'&sujet='+escape(sujet)+'&message='+escape(message)  );
	div=document.getElementById('div_email');
	
	div.innerHTML=res;
}



function VerifAdresseMail(adresse)
{
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);
	
	if ((place > -1)&&(adresse.length >2)&&(point > 1))
	{
		//formulaire.submit();
		return(true);
	}
	else
	{
		return(false);
	}
}