var selectevents = {
	/*'SoftvoyageVolsDepart' : function(value) {
		setNewOptions('VacancesDepart',gateways[value]['destinations']);
	},
	'SoftvoyageVacancesDepart' : function(value) {
		setNewOptions2('SoftvoyageVacancesDestination',gateways_full[value]);
	},*/
	'VacancesDepart' : function(value) {
		setNewOptions('VacancesDestination',destinations[value]);
	},
	'DerniereDepart' : function(value) {
		setNewOptions('DerniereDestination',destinations[value]);
	},
	/*'VolsDepart' : function(value) {
		setNewOptions2('VolsDest',flight_gateways[value]);
	},*/
	'VacancesPriceSelect' : function(value) {
		val_minmax = value.split('-');
		$('#VacancesPriceMin').val(val_minmax[0]);
		$('#VacancesPriceMax').val(val_minmax[1]);
	},
	'DernierePriceSelect' : function(value) {
		val_minmax = value.split('-');
		$('#DernierePriceMin').val(val_minmax[0]);
		$('#DernierePriceMax').val(val_minmax[1]);
	}
};

function openPopup(url) {
	alert(url);
}

$(function(e) {
	/*$('iframe a.popup').click(function(e1) {
		alert('Sdf');
	
		e1.preventDefault();
	});*/

	var h = window.location.host.toLowerCase();
	$("a[href^='http']:not(a[href^='http://" + h + "']):not(a[href^='http://www." + h + "']), a[href$='.pdf']").attr("target", "_blank");
	
	/*var YQB_options = new Array();
	$.each(gateways['YQB']['destinations'], function(k, v) {

		YQB_options.push('<option value="'+k+'">'+v+'</option>');
	});

	$('#VolsDestination').html(YQB_options.join(''));
	
	var YQB_options2 = new Array();
	$.each(gateways_full['YQB'], function(k, v) {
		var classname = '';
		if(v.group == 1) {
			classname = 'group';
		}

		YQB_options2.push('<option value="'+v.code+'" class="'+classname+'">'+v.name+'</option>');
	});

	$('#SoftvoyageVacancesDestination').html(YQB_options2.join(''));
	$('#SoftvoyageDerniereDest').html(YQB_options2.join(''));*/

	/* Recherche par mot clé */
	$('#PageQ').focus(function() {
		if($(this).val() == 'Recherche' || $(this).val() == 'Search') {
			$(this).val('');
		}
	});
	
	var $popup = $('#popup');
	var $popup_content = $('#popup_content');
	
	/* Popup */
	$('#popup_close').click(function() {
		$popup.css('top', '-9999px');
	});
	
	var $popup = $('#popup');
	var $popup_content = $('#popup_content');
	
	/* Popup */
	$('div.close').click(function() {
		$popup.css('top', '-9999px');
	});
	
	$('a.GoogleMap').click(function(e1) {
		$('div.GoogleMap').css('top', '-9999px');
		var rev = $(this).attr('rel');
		$('div[rev="'+rev+'"]').css('top', $(this).position().top - 235 + 'px').css('left', '20px');
	
		e1.preventDefault();
	});
	
	$('div.close').click(function() {
		$(this).parent().css('top', '-9999px');
	});
	
	$('li.infolettre li').html($('#infolettre_form').html());
	$('#infolettre_form').html('');
	
	$('li.extranet li').html($('#extranet_form').html());
	$('#extranet_form').html('');
	
	/*$('li.cadeau li').html($('#cadeau_slide').html());
	$('#cadeau_slide').html('');*/
	
	/* Extranet Login */
	$('#ExtranetUsername').focus(function() {
		if($(this).val() == "Nom d'usager" || $(this).val() == 'Username') {
			$(this).val('');
		}
	});
	
	$('#ExtranetPasswordFake').focus(function() {
		if($(this).val() == "Mot de passe" || $(this).val() == 'Password') {
			$(this).hide();
			$('#ExtranetPassword').show().focus();
		}
	});
	
	$('#NewsletterEmailEmail').focus(function() {
		if($(this).val() == 'Entrez votre courriel' || $(this).val() == 'Enter your email') {
			$(this).val('');
		}
	});
	
	$('#NewsletterEmailPostalcode').focus(function() {
		if($(this).val() == 'Entrez votre code postal' || $(this).val() == 'Enter your postal code') {
			$(this).val('');
		}
	});
	
	
	/* Destionation slideshow */
	$('ul.slideshow_pagesbox li').click(function() {
		$(this).addClass('active').siblings().removeClass('active');
		var page = parseInt($(this).text(), 10) - 1;
		var $table = $(this).parent().prev().children('table');
		$table.animate({'right': 598 * page + 'px'});
	});
	
	$('#virtuoso a.popup').click(function(e1) {
		// Open window
		$popup.css('top', '1300px');
		$popup_content.html('<div style="width:545px;margin-top: 135px;text-align:center;"><img src="http://www.laurierduvallon.com/img/ajax.gif" /></div>');
		
		// Load content
		$popup_content.load($(this).attr('href'), { 'ajax':'true' });
	
		e1.preventDefault();
	});
	
	$('#services_deux a.popup, #services_un a.popup').click(function(e1) {
		// Open window
		if($(this).closest('div').hasClass('services_links_gv')){
			$popup.css('top', '400px');
		} else if($('body').hasClass('affaires')){
			$popup.css('top', '600px');
		} else{
			$popup.css('top', '1175px');
		}
		
		
		
		$popup_content.html('<div style="width:545px;margin-top: 135px;text-align:center;"><img src="http://www.laurierduvallon.com/img/ajax.gif" /></div>');
		
		// Load content
		$popup_content.load($(this).attr('href'), { 'ajax':'true' });
	
		e1.preventDefault();
	});

	
	$('#services_un a.infolettre').click(function(e1) {
		// Open window
		$(this).next().slideToggle();
	
		e1.preventDefault();
	});
	
	$('#services_un a.extranet').click(function(e1) {
		// Open window
		$(this).next().slideToggle();
	
		e1.preventDefault();
	});
	
	$('#services_un a.cadeau').click(function(e1) {
		// Open window
		$(this).next().slideToggle();
	
		e1.preventDefault();
	});
	
	$('span.video_dispo a').click(function(e1) {
		// Open window
		$popup.css('top', '800px');
		$popup_content.html('<div style="width:545px;margin-top: 135px;text-align:center;"><img src="http://www.laurierduvallon.com/img/ajax.gif" /></div>');
		
		// Load content
		$popup_content.load($(this).attr('href'), { 'ajax':'true' });
	
		e1.preventDefault();
	});

	/////////////////////////////////////////////////////////////////
	//////////// zone de recherche : changement d'onglet ////////////
	/////////////////////////////////////////////////////////////////
	$('.zone_boutons_item').click(function(e){
		//menu
		$('.zone_boutons_item .btn').removeClass('active')							   
		$(this).find('.btn').addClass('active');
		$('.zone_boutons_item .zone_boutons_titre a').removeClass('active')							   
		$(this).find('.zone_boutons_titre a').addClass('active');
		$('.zone_boutons_item .fleche_bouton').removeClass('fleche_active')							   
		$(this).find('.fleche_bouton').addClass('fleche_active');
		
		//formulaire
		var target = $(this).attr('target');
		var group = $(this).attr('group');
		$("."+group).addClass('hidden');
		$("#"+target).removeClass('hidden')							   
	});
	/*$('.selectbox_box input.text_input').each(function (i) { 
		$(this).attr("empty",$(this).val);
	});*/
	//$('.selectbox_box input.text_input').focus(function(e){
		//if($(this).val()==$(this).attr("empty")){
	//		$(this).val("");
		//}
	//});

	///////////////////////////////////////////
	//////////// selectbox stylisé ////////////
	///////////////////////////////////////////
	$('#zone_reservation').find('select').selectbox();
	//setNewOptions('SoftvoyageVolsDestination', { 'ABC' : 'Allo', 'DEF' : 'Test' });

	////////////////////////////////////////////
	//////////// sélection de dates ////////////
	////////////////////////////////////////////
	
	var today = new Date();
	var tomorrow = new Date();
	tomorrow.setDate(tomorrow.getDate()+1);
	
	$('#VolsDateDepart').datepicker({ dateFormat: 'yy/mm/dd', minDate: today, onSelect: function(dateText, inst) {
		var selectedDatePlusOne = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay - (-1));
		$('#VolsDateArrive').datepicker('option', 'minDate', selectedDatePlusOne);
	} });
	$('#VolsDateArrive').datepicker({ dateFormat: 'yy/mm/dd', minDate: tomorrow });
	
	$('#VoitureDatePrise').datepicker({ dateFormat: 'yy/mm/dd', minDate: today, onSelect: function(dateText, inst) {
		var selectedDatePlusOne = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay - (-1));
		$('#VoitureDateRetour').datepicker('option', 'minDate', selectedDatePlusOne);
	}  });
	$('#VoitureDateRetour').datepicker({ dateFormat: 'yy/mm/dd', minDate: tomorrow });
	
	$('#HotelDateArrive').datepicker({ dateFormat: 'yy/mm/dd', minDate: today, onSelect: function(dateText, inst) {
		var selectedDatePlusOne = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay - (-1));
		$('#HotelDateDepart').datepicker('option', 'minDate', selectedDatePlusOne);
	}  });
	$('#HotelDateDepart').datepicker({ dateFormat: 'yy/mm/dd', minDate: tomorrow });
	
	$('#VacanceDateDepart').datepicker({ dateFormat: 'yy/mm/dd', minDate: today });
	$('#VacanceDateDepart2').datepicker({ dateFormat: 'yy/mm/dd', minDate: today });
	//$('#DerniereMinuteDateDepart').datepicker({ dateFormat: 'yy/mm/dd', minDate: today });

	///////////////////////////////////////////////////////
	//////////// fait apparaître une sugestion ////////////
	///////////////////////////////////////////////////////
	$('.recherche_item_boutons .btn_reserver').click(function(e){
		var parent_div = $(this).parents('.recherche_item');
		show_sugest(parent_div);
	});
	function show_sugest(parent_div){
		parent_div.find('.recherche_suggestion').slideDown("slow");
		parent_div.find('.recherche_item_boutons .btn_reserver').hide();
		parent_div.find('.btn_continuer').show()
	}
	function hide_sugest(parent_div){
		parent_div.find('.recherche_suggestion').slideUp("slow");
	}

	/////////////////////////////////////////////////////
	//////////// fait apparaître les détails ////////////
	/////////////////////////////////////////////////////
	$('div.btn_plusdinfo').click(function(e){
		var parent_div = $(this).closest('div.special_item');
		if($(this).hasClass("minus")){
			hide_detail(parent_div);
		}else{
			show_detail(parent_div);
		}
	});
	$('span.video_dispo').click(function(e){
		var parent_div = $(this).closest('div.special_item');
		if($(this).hasClass("minus")){
			hide_detail(parent_div);
		}else{
			show_detail(parent_div);
		}
	});
	
	
	function show_detail(parent_div){
		
		hide_sugest(parent_div);
		parent_div.find('.recherche_fiche').slideDown();
		parent_div.find('.slideshow').slideDown("normal",function(e){
			parent_div.find('.slideshow .slideshow_pagesbox').show();														   
		});
		parent_div.find('.btn_plusdinfo').addClass("minus");
	}
	function hide_detail(parent_div){
		parent_div.find('.recherche_fiche').slideUp();
		parent_div.find('.slideshow').slideUp();
		parent_div.find('.slideshow .slideshow_pagesbox').hide();
		parent_div.find('.btn_plusdinfo').removeClass("minus");
	}

});

function print_r (array, return_val) {
    // Prints out or returns information about the specified variable  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/print_r
    // +   original by: Michael White (http://getsprink.com)
    // +   improved by: Ben Bryan
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +      improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: echo
    // *     example 1: print_r(1, true);
    // *     returns 1: 1
    
    var output = "", pad_char = " ", pad_val = 4, d = this.window.document;
    var getFuncName = function (fn) {
        var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn);
        if (!name) {
            return '(Anonymous)';
        }
        return name[1];
    };

    var repeat_char = function (len, pad_char) {
        var str = "";
        for (var i=0; i < len; i++) {
            str += pad_char;
        }
        return str;
    };

    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        if (cur_depth > 0) {
            cur_depth++;
        }

        var base_pad = repeat_char(pad_val*cur_depth, pad_char);
        var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";

        if (typeof obj === 'object' && obj !== null && obj.constructor && getFuncName(obj.constructor) !== 'PHPJS_Resource') {
            str += "Array\n" + base_pad + "(\n";
            for (var key in obj) {
                if (obj[key] instanceof Array) {
                    str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char);
                } else {
                    str += thick_pad + "["+key+"] => " + obj[key] + "\n";
                }
            }
            str += base_pad + ")\n";
        } else if (obj === null || obj === undefined) {
            str = '';
        } else { // for our "resource" class
            str = obj.toString();
        }

        return str;
    };

    output = formatArray(array, 0, pad_val, pad_char);

    if (return_val !== true) {
        if (d.body) {
            this.echo(output);
        }
        else {
            try {
                d = XULDocument; // We're in XUL, so appending as plain text won't work; trigger an error out of XUL
                this.echo('<pre xmlns="http://www.w3.org/1999/xhtml" style="white-space:pre;">'+output+'</pre>');
            }
            catch (e) {
                this.echo(output); // Outputting as plain text may work in some plain XML
            }
        }
        return true;
    } else {
        return output;
    }
}

function echo ( ) {
    // !No description available for echo. @php.js developers: Please update the function summary text file.
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/echo
    // +   original by: Philip Peterson
    // +   improved by: echo is bad
    // +   improved by: Nate
    // +    revised by: Der Simon (http://innerdom.sourceforge.net/)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Eugene Bulkin (http://doubleaw.com/)
    // +   input by: JB
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: If browsers start to support DOM Level 3 Load and Save (parsing/serializing),
    // %        note 1: we wouldn't need any such long code (even most of the code below). See
    // %        note 1: link below for a cross-browser implementation in JavaScript. HTML5 might
    // %        note 1: possibly support DOMParser, but that is not presently a standard.
    // %        note 2: Although innerHTML is widely used and may become standard as of HTML5, it is also not ideal for
    // %        note 2: use with a temporary holder before appending to the DOM (as is our last resort below),
    // %        note 2: since it may not work in an XML context
    // %        note 3: Using innerHTML to directly add to the BODY is very dangerous because it will
    // %        note 3: break all pre-existing references to HTMLElements.
    // *     example 1: echo('<div><p>abc</p><p>abc</p></div>');
    // *     returns 1: undefined
    var arg = '', argc = arguments.length, argv = arguments, i = 0;
    var win = this.window;
    var d = win.document;
    var ns_xhtml = 'http://www.w3.org/1999/xhtml';
    var ns_xul = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'; // If we're in a XUL context

    var holder;

    var stringToDOM = function (str, parent, ns, container) {
        var extraNSs = '';
        if (ns === ns_xul) {
            extraNSs = ' xmlns:html="'+ns_xhtml+'"';
        }
        var stringContainer = '<'+container+' xmlns="'+ns+'"'+extraNSs+'>'+str+'</'+container+'>';
        if (win.DOMImplementationLS &&
            win.DOMImplementationLS.createLSInput &&
            win.DOMImplementationLS.createLSParser) { // Follows the DOM 3 Load and Save standard, but not
            // implemented in browsers at present; HTML5 is to standardize on innerHTML, but not for XML (though
            // possibly will also standardize with DOMParser); in the meantime, to ensure fullest browser support, could
            // attach http://svn2.assembla.com/svn/brettz9/DOMToString/DOM3.js (see http://svn2.assembla.com/svn/brettz9/DOMToString/DOM3.xhtml for a simple test file)
            var lsInput = DOMImplementationLS.createLSInput();
            // If we're in XHTML, we'll try to allow the XHTML namespace to be available by default
            lsInput.stringData = stringContainer;
            var lsParser = DOMImplementationLS.createLSParser(1, null); // synchronous, no schema type
            return lsParser.parse(lsInput).firstChild;
        }
        else if (win.DOMParser) {
            // If we're in XHTML, we'll try to allow the XHTML namespace to be available by default
            return new DOMParser().parseFromString(stringContainer, 'text/xml').documentElement.firstChild;
        }
        else if (win.ActiveXObject) { // We don't bother with a holder in Explorer as it doesn't support namespaces
            var d = new ActiveXObject('MSXML2.DOMDocument');
            d.loadXML(str);
            return d.documentElement;
        }
        /*else if (win.XMLHttpRequest) { // Supposed to work in older Safari
            var req = new win.XMLHttpRequest;
            req.open('GET', 'data:application/xml;charset=utf-8,'+encodeURIComponent(str), false);
            if (req.overrideMimeType) {
                req.overrideMimeType('application/xml');
            }
            req.send(null);
            return req.responseXML;
        }*/
        else { // Document fragment did not work with innerHTML, so we create a temporary element holder
            // If we're in XHTML, we'll try to allow the XHTML namespace to be available by default
            //if (d.createElementNS && (d.contentType && d.contentType !== 'text/html')) { // Don't create namespaced elements if we're being served as HTML (currently only Mozilla supports this detection in true XHTML-supporting browsers, but Safari and Opera should work with the above DOMParser anyways, and IE doesn't support createElementNS anyways)
            if (d.createElementNS &&  // Browser supports the method
                d.documentElement.namespaceURI && (d.documentElement.namespaceURI !== null || // We can use if the document is using a namespace
                d.documentElement.nodeName.toLowerCase() !== 'html' || // We know it's not HTML4 or less, if the tag is not HTML (even if the root namespace is null)
                (d.contentType && d.contentType !== 'text/html') // We know it's not regular HTML4 or less if this is Mozilla (only browser supporting the attribute) and the content type is something other than text/html; other HTML5 roots (like svg) still have a namespace
            )) { // Don't create namespaced elements if we're being served as HTML (currently only Mozilla supports this detection in true XHTML-supporting browsers, but Safari and Opera should work with the above DOMParser anyways, and IE doesn't support createElementNS anyways); last test is for the sake of being in a pure XML document
                holder = d.createElementNS(ns, container);
            }
            else {
                holder = d.createElement(container); // Document fragment did not work with innerHTML
            }
            holder.innerHTML = str;
            while (holder.firstChild) {
                parent.appendChild(holder.firstChild);
            }
            return false;
        }
        // throw 'Your browser does not support DOM parsing as required by echo()';
    };


    var ieFix = function (node) {
        if (node.nodeType === 1) {
            var newNode = d.createElement(node.nodeName);
            var i, len;
            if (node.attributes && node.attributes.length > 0) {
                for (i = 0, len = node.attributes.length; i < len; i++) {
                    newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i].nodeName));
                }
            }
            if (node.childNodes && node.childNodes.length > 0) {
                for (i = 0, len = node.childNodes.length; i < len; i++) {
                    newNode.appendChild(ieFix(node.childNodes[i]));
                }
            }
            return newNode;
        }
        else {
            return d.createTextNode(node.nodeValue);
        }
    };

    for (i = 0; i < argc; i++ ) {
        arg = argv[i];
        if (this.php_js && this.php_js.ini && this.php_js.ini['phpjs.echo_embedded_vars']) {
            arg = arg.replace(/(.?)\{\$(.*?)\}/g, function (s, m1, m2) { 
                // We assume for now that embedded variables do not have dollar sign; to add a dollar sign, you currently must use {$$var} (We might change this, however.)
                // Doesn't cover all cases yet: see http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double
                if (m1 !== '\\') {
                    return m1+eval(m2);
                }
                else {
                    return s;
                }
            });
        }
        if (d.appendChild) {
            if (d.body) {
                if (win.navigator.appName == 'Microsoft Internet Explorer') { // We unfortunately cannot use feature detection, since this is an IE bug with cloneNode nodes being appended
                    d.body.appendChild(ieFix(stringToDOM(arg)));
                }
                else {
                    var unappendedLeft = stringToDOM(arg, d.body, ns_xhtml, 'div').cloneNode(true); // We will not actually append the div tag (just using for providing XHTML namespace by default)
                    if (unappendedLeft) {
                        d.body.appendChild(unappendedLeft);
                    }
                }
            } else {
                d.documentElement.appendChild(stringToDOM(arg, d.documentElement, ns_xul, 'description')); // We will not actually append the description tag (just using for providing XUL namespace by default)
            }
        } else if (d.write) {
            d.write(arg);
        }/* else { // This could recurse if we ever add print!
            print(arg);
        }*/
    }
}


