// JavaScript Document
//Affiche ou non un objet
function show_hideObj(param1) { 

	
	dd =document.getElementById(param1);

 	if(dd.style.display == "") {
		dd.style.display = 'none';
	} else {
		dd.style.display = '';
	}
	
	return false;
  
}


function show_DIV(param){
	 // Booléen reconnaissant le navigateur (vu en partie 2)
  isIE = (document.all) ;
  isNN6 = (!isIE) && (document.getElementById);
  if (isIE) DIV = document.all[param];
  if (isNN6) DIV = document.getElementById(param);	
  DIV.style.display = ""
  return false;
}
function hide_DIV(param){
  
  isIE = (document.all) ;
  isNN6 = (!isIE) && (document.getElementById);
  if (isIE) DIV = document.all[param];
  if (isNN6) DIV = document.getElementById(param);	
  DIV.style.display = "none"
  return false;
}

function showhide_DIV(param) {
  isIE = (document.all) ;
  isNN6 = (!isIE) && (document.getElementById);
  if (isIE) DIV = document.all[param];
  if (isNN6) DIV = document.getElementById(param);
  if(DIV.style.display == "") {
    DIV.style.display = "none";
  } else {
    DIV.style.display = "";
  }
  return false;
}


//Fonction modifiée pour afficher le popup au centre de l'écran
function openCenteredWindow(theURL,winName,width,height,features) { //v2.0
	var top=(screen.height-height)/2;
    var left=(screen.width-width)/2;
	window.open(theURL,winName,"top="+top+",left="+left+",width="+width+",height="+height+","+features);
}
function searchCatAndGo(cat_nom){
	
	//Si on a le moteur de recherche affiché
	var locat = new String(window.location);
	if(document.all['moreSearch'] || document.getElementById('moreSearch')){
	
		for(var i = 0;i< document.forms[0].searchCat.options.length;i++){
			if(document.forms[0].searchCat.options[i].text == cat_nom){
				document.forms[0].searchCat.selectedIndex =i;
			}
		}
		document.forms[0].submit();
	}
}
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Personnalisation des <input type="checkbox">

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function chgCB(){
  try{
	  CHKB = document.getElementById('newCB').getElementsByTagName('input');
	  for(i=0; i < CHKB.length; i++){
		if(CHKB[i].type == "checkbox"){
		  IMG = document.createElement('img');
		  CHKB[i].parentNode.insertBefore(IMG, CHKB[i]);
		  IMG.src = "img/ico/cbnormal.gif";
		  if(CHKB[i].checked  == true) IMG.src = "img/ico/cbcheck.gif";
		  if(CHKB[i].disabled == true) IMG.src = "img/ico/cbdisable.gif";
		  else{ // Les comportements de changement d'état ne sont appliqués que si la checkbox est cliquable !
			CHKB[i].onchange = function(){
			  IMG = this.parentNode.getElementsByTagName('img')[0];
			  if(this.checked == true) IMG.src = 'img/ico/cbcheck.gif'
			  else IMG.src = 'img/ico/cbnormal.gif'
			}
			if(!window.sidebar){
			  CHKB[i].parentNode.onclick = function(){
				CHK = this.getElementsByTagName('input')[0];
				CHK.checked = (CHK.checked == true) ? false : true;
				CHK.onchange()
			  }
			}
		  }
		  CHKB[i].style.visibility = 'hidden';
		  CHKB[i].style.position   = 'absolute';
		}
	  }
  }catch(e){}
}
 
window.onload = chgCB;

/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Personnalisation des <input type="radiobutton">

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function chgRB(){
  try{
	  CHKB = document.getElementById('newRB').getElementsByTagName('input');
	  for(i=0; i < CHKB.length; i++){
		if(CHKB[i].type == "radio"){
		  IMG = document.createElement('img');
		  CHKB[i].parentNode.insertBefore(IMG, CHKB[i]);
		  IMG.src = "img/ico/cbnormal.gif";
	
		  IMG.id = 'img'+CHKB[i].id;
		  IMG.relation = CHKB[i].name;
	
		  if(CHKB[i].checked  == true) IMG.src = "img/ico/cbcheck.gif";
		  if(CHKB[i].disabled == true) IMG.src = "img/ico/cbdisable.gif";
		  else{ // Les comportements de changement d'état ne sont appliqués que si la checkbox est cliquable !
			CHKB[i].onchange = function(){
	 
			  IMG = document.getElementById('newRB').getElementsByTagName('img');
			  for(i=0; i < IMG.length; i++){
				if(IMG[i].relation != this.name) continue;
				if(IMG[i].src.indexOf('cbperso2.gif') != -1) continue;
				if(IMG[i].id == 'img'+this.id) IMG[i].src = 'img/ico/cbcheck.gif';
				else IMG[i].src = 'img/ico/cbnormal.gif'
			  }
	
			}
			if(!window.sidebar){
			  CHKB[i].parentNode.onclick = function(){
				CHK = this.getElementsByTagName('input')[0];
				CHK.checked = (CHK.checked == true) ? false : true;
				CHK.onchange()
			  }
			}
		  }
		  CHKB[i].style.visibility = 'hidden';
		  CHKB[i].style.position   = 'absolute';
		}
	  }
  }catch(e){}
}
 
window.onload = chgRB;


function getRadioValue(radios) {
  for(var i=0; i<radios.length; ++i) {
    if(radios[i].checked){
			return radios[i].value;
	}
  } 
  return '';
}


/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
fonctions propres au site 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

function ImprimerFiche(produit_id) {
  window.open('imprimer.php?produit_id='+produit_id,'Imprimer','left=20,top=20,width=520,height=500,toolbar=0,resizable=0,scrollbars=1');
}

function EnvoyerMail(produit_id,model) {
  window.open('envoyer.php?produit_id='+produit_id+'&model='+model,'Envoyer','left=20,top=20,width=500,height=300,toolbar=0,resizable=0');       
}

function VoirDetail(sejour_key) {
  window.open('detail.php?sejour_id='+sejour_key,'Envoyer','left=20,top=20,width=580,height=300,toolbar=0,resizable=0,scrollbars=1');       
}

function CreerPDF(sejour_key) {
  window.open('detail_pdf_export.php?sejour_id='+sejour_key,'Envoyer','left=20,top=20,width=580,height=300,toolbar=0,resizable=1,scrollbars=1');       
}

function clean_url() {
	
	c = document.getElementById('centre');
	var cells = c.getElementsByTagName("a"); 
	for (var i = 0; i < cells.length; i++) { 
			var str = cells[i].href;
			//str = str.replace(/<\/?[^>]+(>|$)/g, "");
			str = str.replace(/ /g, "");
			str = str.replace(/%20/g, "");
			str = str.replace(/&nbsp;/g, "");	
			str  = str.replace('http://www.stagesenvo.lan/www.',"http://www.");
			str  = str.replace('http://www.stagesenvo.com/www.',"http://www.");	
			str  = str.replace('http://www.vacancesenvo.lan/www.',"http://www.");	
			str  = str.replace('http://www.vacancesenvo.com/www.',"http://www.");	

			str  = str.replace('http://www.stagesenvo.lan/www.',"http://www.");
			str  = str.replace('http://www.stagesenvo.com/www.stagesenvo.com',"http://www.stagesenvo.com");	
			str  = str.replace('http://www.vacancesenvo.lan/www.',"http://www.");	
			str  = str.replace('http://www.vacancesenvo.com/www.vacancesenvo.com',"http://www.vacancesenvo.com");	
			
			var str_check = String(str).toLowerCase();
			//if(str_check.substring(0,4) != 'http' && str_check.substring(0,5) != "https"  && str_check.substring(0,6) != "mailto" && str_check.substring(0,3) != "ftp") {
			//	str = "http://" + str;
			//}
			
			
			if(str_check.substring(0,3) == 'www'){
				str = "http://" + str;
			}
			
			
			cells[i].href = str;										
			//cells[i].target = '_blank';
			
			
			str = cells[i].innerHTML;
			//str = str.replace(/<\/?[^>]+(>|$)/g, "");
			//str = str.replace(/ /g, "");
			//str = str.replace(/&nbsp;/g, "");		
			
			var str_check = String(str).toLowerCase();
			str_check= str_check.replace(/<\/?[^>]+(>|$)/g, "");
			if((str_check.substring(0,7) == 'http://' || str_check.substring(0,3) == 'www')	&& 	str_check.length > 60) {				
				 cells[i].innerHTML =  String(str).substring(0,60) + "[...]";
			}
			
	}
	c.style.width = '100%';
}

ville_sh_segment = function(id) {
	// désactivé sur demande de cdh
	return;
	
	for(i=0;i<3;i++) {
		if($('ville_segment_' + i) != undefined) {
			$('ville_segment_' + i).style.display = "none";	
		}
	}
	$('ville_segment_' + id).style.display = "";	
	
}

promo_plusinfo = function(id) {
	$('promo_info_' + id).style.display = "none";	
	$('promo_info_btn_'+ id).style.display = "none";
	$('promo_info_full_' + id).style.display = "";	
}

sejour_by_mail_click = function(these, clique) {
	if(clique == 1) {
		these.value = "";
	} else {
		if(these.value == "") {
			if(these.id != "email_comment") {
				these.value = these.title;
			}
		}
	}
}

sejour_by_mail_send = function() {
	e_to = $('email_to').value;
	e_from = $('email_from').value;
	e_nom = $('email_nom').value;
	e_comment = $('email_comment').value;
	if(e_to == "" || checkEmail(e_to) == false || e_to == $('email_to').title) {
		alert("Vous devez donner une adresse de destinataire valide.");
		return false;
	}
	
	if(e_from == "" || checkEmail(e_from) == false || e_from == $('email_from').title) {
		alert("Votre adresse email est invalide.");
		return false;
	}

	if(e_nom == "" || e_nom == $('email_nom').title) {
		alert("Vous devez renseigner le champ nom, prénom.");
		return false;
	}
	
	e_comment = $('email_comment').value;
	if(e_comment == $('email_comment').title) {
		e_comment = "";
	}
	
	prod_id = $('email_produit_id').value;
	model = $('email_model').value;
	langue = $('email_langue').value;

		var url = '/ajax/send_sejour_by_email.php';
		var pars = 'model=' + model + '&langue=' + langue + '&produit_id=' + prod_id  + '&to=' + e_to  + '&from=' + e_from  + '&nom=' + e_nom  + '&comment=' + e_comment;
		
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: sejour_by_mail_response
			});


}

sejour_by_mail_response = function(originalRequest) {
	alert(originalRequest.responseText);
}

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	} else {
		return true;
	}
}

devis_by_mail_send = function() {
	e_to = $('email_to').value;
	e_from = $('email_from').value;
	e_nom = $('email_nom').value;
	e_comment = $('email_comment').value;
	if(e_to == "" || checkEmail(e_to) == false || e_to == $('email_to').title) {
		alert("Vous devez donner une adresse de destinataire valide.");
		return false;
	}
	
	if(e_from == "" || checkEmail(e_from) == false || e_from == $('email_from').title) {
		alert("Votre adresse email est invalide.");
		return false;
	}

	if(e_nom == "" || e_nom == $('email_nom').title) {
		alert("Vous devez renseigner le champ nom, prénom.");
		return false;
	}
	
	e_comment = $('email_comment').value;
	if(e_comment == $('email_comment').title) {
		e_comment = "";
	}
	
	sejour = $('email_sejour_id').value;
	produit = $('email_produit_id').value;
	model = $('email_model').value;
	langue = $('email_langue').value;

		var url = '/ajax/send_devis_by_email.php';
		var pars = 'produit=' + produit + '&model=' + model + '&langue=' + langue + '&sejour=' + sejour  + '&to=' + e_to  + '&from=' + e_from  + '&nom=' + e_nom  + '&comment=' + e_comment;
		
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: sejour_by_mail_response
			});


}

devis_by_mail_response = function(originalRequest) {
	alert(originalRequest.responseText);
	window.close();
}

//-->
