/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/

function ouvrir_accordeon(id_accordion) {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$(id_accordion).removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$(id_accordion).slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
}



/**
 * Fonction pour creation de l'objet XMLRequest AJAX
 */
function createRequestObject() {
    
    var xhr;
    
    try {
    	xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (err) {
    	try {
    		xhr = new ActiveXObject("Microsoft.XMLHTTP");
    	} catch(err) {
    		xhr = false;
    	}
    }
    
    if(!xhr && typeof XMLHttpRequest != 'undefined') {
    	xhr = new XMLHttpRequest();
    }
    
    return xhr;
}

var http = createRequestObject();


// Ajax pour liste personne qui partagent une chambre
function request_detail_prestation(idDiv,key,nomAction,langue) {

	// Loading
	document.getElementById(idDiv).innerHTML = '<div align="center"><img src="/images/design/ajax-loader.gif"  alt="" border="0" /></div>';
	
	// Ouverture de la requete GET
	 http.open('get', 'detail_prestation_ajax.php?action='+ nomAction +'&key=' + key + '&langue=' + langue);
	 
	 // Recupération du retour de la fonction
	 http.onreadystatechange = function() {
         if(http.readyState == 4){
         	
	        var response = http.responseText;
	        var html = new String();
	        
	        // Récupération du code HTML (echo)
	        html = response;
			  
	       document.getElementById(idDiv).innerHTML = html;
	    }
    }
	http.send(null);
}

function popup_images_prestataire(typeprest,code){
	var page;
	page = 'image_prestataire.php?TYPREST=' + typeprest + '&CODE=' + code;
	var win = window.open (page,'', config='height=80, width=250, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
    if(win.focus){win.focus();} 
}

function popup_images_prestation(typeprest,code,codeprest){
	var page;
	page = 'image_prestation.php?TYPREST=' + typeprest + '&CODE=' + code + '&CODEPREST=' + codeprest;
	var win = window.open (page,'', config='height=80, width=250, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
    if(win.focus){win.focus();} 
}

function popup_plan_situation(typeprest,code,lot){
	var page;
	page = 'plan_de_situation.php?typeprest=' + typeprest + '&presta=' + code + '&lot=' + lot;
	var win = window.open (page,'', config='height=200, width=300, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
    if(win.focus){win.focus();} 
}

/**
 * Fonction pour mettre à jour les durées proposées en fonction de la date d'arrivée
*/
function init_durees_proposees(date_debut, traduction_semaine, traduction_jour, emplacement_liste_duree, id_duree_sejour, nom_form) {           

    var html = '<select class="zoneform_recherche_resa" id="' + id_duree_sejour + '" name="duree" onchange="init_nb_resultats_ajax(\'recherche\',\'' + nom_form + '\')">';                                       
    
    switch(date_debut) {
        // --- Pour le 16/12/2011 : 8 et 10 nuits --- //
        case '16/12/2011' :        
            html = html + '<option value="8" >8 ' + traduction_jour + 's</option>';
            html = html + '<option value="10" >10 ' + traduction_jour + 's</option>';        
            break;
        // --- Pour le 17/12/2011 : 7 et 9 nuits --- //
        case '17/12/2011' :        
            html = html + '<option value="7" >7 ' + traduction_jour + 's</option>';
            html = html + '<option value="9" >9 ' + traduction_jour + 's</option>';        
            break;
        // --- Pour le 26/12/2011 : 7 nuits --- //
        case '26/12/2011' :        
            html = html + '<option value="7" >7 ' + traduction_jour + 's</option>';        
            break;
        // --- Pour le 14/04/2012 : 7 et 8 nuits --- //
        case '14/04/2012' :        
            html = html + '<option value="7" >7 ' + traduction_jour + 's</option>';
            html = html + '<option value="8" >8 ' + traduction_jour + 's</option>';        
            break;
        default :        
           // Durée Normale
           for(iDuree=1; iDuree<=4; iDuree++){ 
               if(iDuree>1){s = "s";}else{s = "";}
               html = html + '<option value="' + (iDuree*7) + '" >' + iDuree + ' ' + traduction_semaine + s + '</option>';
           }        
           break; 
    }
                                          
    
    html = html + '</select>';        
    if(emplacement_liste_duree != ''){           
    	document.getElementById(emplacement_liste_duree).innerHTML = html;                       
    }else{
    	document.getElementById('duree_sejour_proposee').innerHTML = html;           
    }
}


function change_date_cross_selling_prestation_jour(sdate,requete) {
    url_envoi = 'index.php?dateRechercheDispoPrestationJour=' + sdate + '&' + requete;
	document.location.href =  url_envoi;
}
