/***** start generate random function*****/
rnd.today=new Date();rnd.seed=rnd.today.getTime();
function rnd() {rnd.seed = (rnd.seed*9301+49297) % 233280;return rnd.seed/(233280.0);
};
function rand(number) {return Math.ceil(rnd()*number);};
/***** end generate random function *****/
/**start show banniere image function**/
function renderBanniereImage(id,strImage,strPopup,strUrl){
    var buffer = "";
    if((strPopup != null) && (strPopup!="")){buffer = "<a href=\""+strPopup+"\" onclick=\"return OpenPopup('"+strPopup+"');\" ><img src=\""+strImage+"\" alt=\"Banniere haut\" /></a>"
    }else if((strUrl != null) && (strUrl!="")){buffer = "<a href=\""+strUrl+"\" ><img src=\""+strImage+"\" alt=\"Banniere haut\" /></a>"
    }else if((strPopup=="") && (strUrl=="")){buffer ="<img src=\""+strImage+"\" alt=\"Banniere haut\" />"}
    if(buffer==""&&id=="gaucheBanniere"){document.getElementById(id).className = '';}
    document.getElementById(id).innerHTML = buffer;
}
/** removeAccent enables to remove all the specific characters in a string
* @param input the input string
* @return String the input string without the sepcific character*/
function removeAccent(input) {
	var temp = "";
	if (input != null) {
        temp = input;
        temp = temp.replace(/\u00e9/g, 'e' ); // eacute
        temp = temp.replace(/\u00e8/g, 'e' ); // egrave
        temp = temp.replace(/\u00f9/g, 'u' ); // ugrave
        temp = temp.replace(/\u00e0/g, 'a' ); // agrave
        temp = temp.replace(/\u00ea/g, 'e' ); // ecirc
        temp = temp.replace(/\u00f4/g, 'o' ); // ocirc
        temp = temp.replace(/\u00ee/g, 'i' ); // icirc
        temp = temp.replace(/\u00fb/g, 'u' ); // ucirc
        temp = temp.replace(/\u00e2/g, 'a' ); // acirc
        temp = temp.replace(/\u00eb/g, 'e' ); // euml
        temp = temp.replace(/\u00f6/g, 'o' ); // ouml
        temp = temp.replace(/\u00ef/g, 'i' ); // iuml
        temp = temp.replace(/\u00fc/g, 'u' ); // uuml
        temp = temp.replace(/\u00e4/g, 'a' ); // auml
        temp = temp.replace(/\u00e7/g, 'c');  // ccedil
        temp = temp.replace(/\u00c1/g, 'A');
        temp = temp.replace(/\u00c2/g, 'A');
        temp = temp.replace(/\u00c3/g, 'A');
        temp = temp.replace(/\u00c4/g, 'A');
        temp = temp.replace(/\u00c5/g, 'A');
        temp = temp.replace(/\u00c8/g, 'E');
        temp = temp.replace(/\u00c9/g, 'E');
        temp = temp.replace(/\u00ca/g, 'E');
        temp = temp.replace(/\u00cb/g, 'E');
        temp = temp.replace(/\u00cc/g, 'I');
        temp = temp.replace(/\u00cd/g, 'I');
        temp = temp.replace(/\u00ce/g, 'I');
        temp = temp.replace(/\u00cf/g, 'I');
        temp = temp.replace(/\u00d2/g, 'O');
        temp = temp.replace(/\u00d3/g, 'O');
        temp = temp.replace(/\u00d4/g, 'O');
        temp = temp.replace(/\u00d5/g, 'O');
        temp = temp.replace(/\u00d6/g, 'O');
        temp = temp.replace(/\u00d9/g, 'U');
        temp = temp.replace(/\u00da/g, 'U');
        temp = temp.replace(/\u00db/g, 'U');
        temp = temp.replace(/\u00dc/g, 'U');
      }
      temp = temp.replace(/\u00A0/g, '');
      temp = temp.replace(/\s/g, '');
      return temp;
    }
String.prototype.trim = function() {return this.replace(/^\s+/, '').replace(/\s+$/, '');}
/**start submit search engine form function**/
function submitSearchForm(){
	var form=document.getElementById('searchForm');
	var formule=document.getElementById('formule').value;
	var destinationCode=document.getElementById("arrival").options[document.getElementById("arrival").selectedIndex].value;
	var destinationText=removeAccent(document.getElementById("arrival").options[document.getElementById("arrival").selectedIndex].text);
	var sAction = form.action;
	var urlDestination;
	var duration="";
	var dpci="";
	if(document.getElementById("departure")){dpci=document.getElementById("departure").options[document.getElementById("departure").selectedIndex].value;dpci=(dpci=="")?"":"&dpci="+dpci;}
	var dd=document.getElementById("dd").options[document.getElementById("dd").selectedIndex].value;dd=(dd=="")?"":"&dd="+dd;
	var dmy=document.getElementById("yearmonth").options[document.getElementById("yearmonth").selectedIndex].value;dmy=(dmy=="")?"":"&dmy="+dmy;
	var aj=document.getElementById("aj").options[document.getElementById("aj").selectedIndex].value;
	var date1=document.getElementById('date1').value;date1=(date1=="")?"":"&date1="+date1;
	if(document.getElementById("duration")){duration=document.getElementById("duration").options[document.getElementById("duration").selectedIndex].value;duration=(duration=="")?"":"&minMan="+duration;}
	if(dd!=""&&dmy==""){alert("Veuillez s\xE9lectionner votre mois de d\xE9part");return;}
	urlDestination=destinationText.toLowerCase()+"-"+destinationCode;
	if(destinationCode==""||duration!=""||dmy!=""||dpci!=""||window.location.href.indexOf("destination.html")>-1){
		if(document.getElementById("departure"))regionaliser("departure",false);
		if(destinationCode=="")
			var parameters="c.fo="+formule+dpci+dmy+dd+"&aj="+aj+duration+date1;
		else
			var parameters="c.fo="+formule+dpci+"&c.de="+destinationCode+dmy+dd+"&aj="+aj+duration+date1;
		window.location.href=sAction+"recherche-produits.html?"+parameters;
	}else{
		if(document.getElementById("departure"))regionaliser("departure",false);
		form.action=removeAccent(sAction+formule+"/"+urlDestination+".html");
		form.submit();
	}
}
/**end submit search engine form function**/
function initSearchEngineRetour(aj,formule){
	if(aj!=null&&(aj>=0&&aj<5))document.getElementById('aj').value=aj;
	var rubrique=document.getElementById('formule');
	rubrique.value=formule;
}
function affinerSearch(){
	var form=document.getElementById('filter-retour');
	var formule=document.getElementById('formule').value;
	var mmp=document.getElementById("mmp").options[document.getElementById("mmp").selectedIndex].value;
	mmp=(mmp=="")?"":"&mmp="+mmp;
	var pe=document.getElementById("c.pe").options[document.getElementById("c.pe").selectedIndex].value;
	pe=(pe=="")?"":"&c.pe="+pe;
	var th=document.getElementById("c.th").options[document.getElementById("c.th").selectedIndex].value;
	th=(th=="")?"":"&c.th="+th;
	var st=document.getElementById("st").options[document.getElementById("st").selectedIndex].value;
	var show=document.getElementById("show").options[document.getElementById("show").selectedIndex].value;

	var sAction = form.action;
	var affinerUrl=document.getElementById('searchEngineUrl').value;
	var elements=affinerUrl.split("&");
	var nb=elements.length;
	var parameters="";
	var name="";
	var value="";
	for(var i=0;i<nb;i++){
		name="";
		value="";
		name=elements[i].split("=")[0];
		value=elements[i].split("=")[1];
		if(name!=""&&value!=""){parameters+=name+"=" +value+"&" ;}
	}
	var date=document.getElementById('date').value;
	date=(date=="")?"":"date1="+date;
	var location=window.location.href;
	var pageName="recherche-produits.html?";
	parameters+=date;parameters+=mmp;parameters+=pe;parameters+=th;

	if(location.indexOf("recherche-produits-selection.html")>-1){pageName="recherche-produits-selection.html?";parameters+="&st="+st;parameters+="&show="+show;}
	window.location.href=sAction+pageName+parameters;
}
function initAffinerRetour(mmp){if(mmp!=null&&mmp!="null")document.getElementById('mmp').value=mmp;}
function staticPageStyle(name){
	document.getElementById('qui-sommes-nous').className = '';
	document.getElementById('assurances').className = '';
	document.getElementById('aide').className = '';
	document.getElementById('brochure-en-ligne').className = '';
	document.getElementById('contact').className = '';
	document.getElementById('conditions-generales-de-vente').className = '';
	document.getElementById('plan-du-site').className = '';
	document.getElementById('mentions-legales').className = '';
	document.getElementById(name).className = 'on';
}
function initOnglets(name){
	document.getElementById('accueil').className = '';
	document.getElementById('france').className = '';
	document.getElementById('circuit').className = '';
	document.getElementById('sejour').className = '';
	document.getElementById('croisiere').className = '';
	document.getElementById('location').className = '';
	document.getElementById('week-end').className = '';
	document.getElementById('bien-etre').className = '';
	if(document.getElementById(name)){document.getElementById(name).className = 'on';}
}
// popup For the printable product description.
function popupPrint(url) {window.open(url,"print","resizable=yes,width=730,height=680,left=100,top=100,dependent=no,scrollbars=yes");}
function check_number(e){
    ok = "1234567890";
    if(e.length!=5) return (false);
    for(i=0; i < e.length ;i++){if(ok.indexOf(e.charAt(i))<0){return (false);}}
    return (true);
}
//function popupNewsletter() {
//    var email=document.getElementById('email').value;
//    var codepostal=document.getElementById('codepostal').value;
//    if(codepostal=="Votre code postal"||!check_number(codepostal))window.open('/CS/static-pages/newsletter_error_codePostal.htm',"print","resizable=yes,width=705,height=375,left=100,top=100,dependent=no,scrollbars=yes");
//    else window.open('/newsletter-form.jsp?CODE_POSTAL_FIELD='+codepostal+'&EMAIL_FIELD='+email,"print","resizable=yes,width=705,height=375,left=100,top=100,dependent=no,scrollbars=yes");
//}
function popupNewsletter() {
    var email=document.getElementById('email').value;
    var codepostal=document.getElementById('codepostal').value;
    var parameters = "zipcode="+codepostal+"&dolist_form_email="+email;
    if(codepostal=="Votre code postal"||!check_number(codepostal))window.open('/CS/static-pages/newsletter_error_codePostal.htm',"print","resizable=yes,width=705,height=375,left=100,top=100,dependent=no,scrollbars=yes");
    else {
		$.ajax({
		        url: "/alert/addContact",
		        type: "POST",
		        data: parameters,
		        success: function(msg){
							 if(msg == "ok"){
				        window.open('/CS/static-pages/newsletter_ok.htm',"print","resizable=yes,width=705,height=375,left=100,top=100,dependent=no,scrollbars=yes");
				      }else if(msg == "error"){
				        window.open('/CS/static-pages/newsletter_error.htm',"print","resizable=yes,width=705,height=375,left=100,top=100,dependent=no,scrollbars=yes");
				      }
		        },
		        error: function(){
							window.open('/CS/static-pages/newsletter_error.htm',"print","resizable=yes,width=705,height=375,left=100,top=100,dependent=no,scrollbars=yes");
		        }
		    });
    }
}

function popupNewsletterPage() {
	var parameters = "";
	if(Get_Cookie( 'departement' )&&Get_Cookie( 'regionName' )){
	    parameters = Get_Cookie( 'departement' );
	}else if(Get_Cookie( 'regionName' )){
	    parameters = Get_Cookie( 'regionName' );
	}
	if (parameters == "") {
	    window.open('/newsletter.html',"print","resizable=yes,width=705,height=775,left=100,top=100,dependent=no,scrollbars=yes,location=yes,status=yes,toolbar=yes,menubar=yes");
	} else {
	    window.open('/newsletter-'+parameters+'.html',"print","resizable=yes,width=705,height=775,left=100,top=100,dependent=no,scrollbars=yes,location=yes,status=yes,toolbar=yes,menubar=yes");
	}
}


function popupNewsletterUrl(siteRoot){
	var parameters = "";
	var url = "";
	if(Get_Cookie( 'departement' )&&Get_Cookie( 'regionName' )){
	    parameters = Get_Cookie( 'departement' );
	}else if(Get_Cookie( 'regionName' )){
	    parameters = Get_Cookie( 'regionName' );
	}
	if(parameters == ""){
		url = siteRoot + 'newsletter.html';
	}else {
		url = siteRoot + 'newsletter-' + parameters + '.html';
	}
	return url;
}
// email JavaScript check
function check_email(e){
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
    for(i=0; i < e.length ;i++){if(ok.indexOf(e.charAt(i))<0){return (false);}}
    if (document.images){
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)){return (-1);}
    }
}
function submitEnvoiMailForm() {
	var buffer = "";var obj;var lobj;
	var f=document.getElementById("frmEnvoiMail");
	obj = f['contactEmail'];
	tmp = f['contactEmail'].value;
	tmp = tmp.trim();
	if (!check_email(tmp)) {buffer += "\n -Email de votre contact doit \xEAtre renseign\xE9 et valide";lobj = obj;}
	obj = f['email'];
	tmp = f['email'].value;
	tmp = tmp.trim();
	if (!check_email(tmp)) {buffer += "\n -Votre email doit \xEAtre renseign\xE9 et valide";lobj = obj;
	}
	buffer += "\n" ;
	if (buffer!="\n") {
	buffer = "Veuillez corriger les champs suivants:" + buffer;
	alert(buffer);
	return false;
	}else f.submit();
}
function getQueryString(url,name){
	var queryString = url;
	var parameters = queryString.split("&");
	var pos, paraName, paraValue;
	for(var i=0; i<parameters.length; i++){
		pos = parameters[i].indexOf('=');
		if(pos == -1) { continue; }
		paraName = parameters[i].substring(0, pos);
		paraValue = parameters[i].substring(pos + 1);
		if(paraName == name){return unescape(paraValue.replace(/\+/g, " "));}
	}
	return '';
};
function initialSelectionRegion(){
	var dpci=Get_Cookie( 'selectedCity' );
	if(dpci!=""){
		var elDpci=document.getElementById("dpci1");
		for (var i = 0; i < elDpci.length; i++){if(elDpci[i].value==dpci)elDpci[i].selected=true;}
		fillSelectBoxDispo('departure-dates1', 'dpci1', disposArray, null);
		updateDispo("1","2", disposArray);
	}

}
function initialSelection(criteria){
	var dpci=getQueryString(criteria,'dpci');
	var destination=getQueryString(criteria,'c.de');
	var destination=getQueryString(criteria,'c.de');
	var date=getQueryString(criteria,'date1');
	var aj=getQueryString(criteria,'aj');
	var duration=getQueryString(criteria,'minMan');
	if(document.getElementById('departure')){
		var el=document.getElementById('departure').options;
		for (var i = 0; i < el.length; i++){if(el[i].value==dpci)el[i].selected=true;}
	}
	if(document.getElementById('arrival'))document.getElementById('arrival').value=destination;
	if(document.getElementById('date1')){
		document.getElementById('date1').value=date;
		document.getElementById('date').value=date;
	}
	if(document.getElementById('aj'))document.getElementById('aj').value=aj;
	if(document.getElementById('duration'))document.getElementById('duration').value=duration;

	if(dpci!=""){
		var elDpci=document.getElementById("dpci1");
		for (var i = 0; i < elDpci.length; i++){if(elDpci[i].value==dpci)elDpci[i].selected=true;}
		fillSelectBoxDispo('departure-dates1', 'dpci1', disposArray, null);
		updateDispo("1","2", disposArray);
	}
	if(date!="NaN"&&date!=""){selectDateDuration(date,dpci,aj,duration);}
	else if(duration!=""){selectDuration(dpci,duration);}
}
function selectDateDuration(date,dpci,aj,duration){
	var noDay=false;
	var year=date.substring(0,4);
	var month=date.substring(4,6);
	var day=date.substring(6,8);
	if(day==""){day="01";noDay=true;}

	var chosenDate=new Date();
	chosenDate.setFullYear(parseFloat(year));
	chosenDate.setMonth(parseFloat(month)-1);
	chosenDate.setDate(parseFloat(day));
	var dateValue=getNearDateDuration(dpci,chosenDate,disposArray,noDay,aj,duration);

	document.getElementById("departure-dates1").value=dateValue;
	document.getElementById("departure-dates2").value=dateValue;
}

function selectDuration(dpci,duration){
	var minNights=parseInt(duration.split(',')[0]);
	var maxNights=parseInt(duration.split(',')[1]);
	if(maxNights=="")maxNights=100;
	var minPrice=0;
	var selectedIndex=0;
	if(dpci!=""){
		for (var i = 0; i < disposArray.length; i++){
			if(disposArray[i].depCityCode==dpci&&disposArray[i].nbNigths>=minNights&&disposArray[i].nbNigths<=maxNights){
				if(minPrice==0){minPrice=disposArray[i].price;selectedIndex=i;}
				else if(parseFloat(minPrice)>parseFloat(disposArray[i].price)){minPrice=disposArray[i].price;selectedIndex=i;}
			 }
		}
	}else{
		for (var i = 0; i < disposArray.length; i++){
			if(disposArray[i].nbNigths>=minNights&&disposArray[i].nbNigths<=maxNights){
				if(minPrice==0){minPrice=disposArray[i].price;selectedIndex=i;}
				else if(parseFloat(minPrice)>parseFloat(disposArray[i].price)){minPrice=disposArray[i].price;selectedIndex=i;}
			 }
		}
	}
	var dateValue=disposArray[selectedIndex].depDate2+'-'+disposArray[selectedIndex].nbDays+'-'+disposArray[selectedIndex].nbNigths;
	document.getElementById("departure-dates1").value=dateValue;
	document.getElementById("departure-dates2").value=dateValue;
}
function getNearDateDuration(city,chosenDate,dateArray,noDay,aj,duration){
	var minNights=0;var maxNights=100;
	if(duration!=""){
		minNights=parseInt(duration.split(',')[0]);
		if(duration.split(',')[1]!=" ")maxNights=parseInt(duration.split(',')[1]);
	}
	var minPrice=0;var minDiff=0;var depDate="";var smallestDiff=0;;var index=0;
	if(city!=""){
	    for (var i = 0; i < dateArray.length; i++) {
	        if(dateArray[i].depCityCode==city&&dateArray[i].nbNigths>=minNights&&dateArray[i].nbNigths<=maxNights){
	            depDate="";
	            depDate=disposArray[i].depDate2;
	            var date = depDate.split("-");
	            var tempDate=new Date();
	            tempDate.setFullYear(parseFloat(date[2]));
	            tempDate.setMonth(parseFloat(date[1])-1);
	            tempDate.setDate(parseFloat(date[0]));
	            var difference=Math.abs(daysElapsed(chosenDate,tempDate));
				if(difference<=aj||noDay){
	            	if(minPrice==0){minPrice=dateArray[i].price;minDiff=difference;index=i;}
					else if(parseFloat(minPrice)>parseFloat(dateArray[i].price)){minPrice=dateArray[i].price;index=i;if(difference<minDiff)minDiff=difference;}
					else if(minPrice==dateArray[i].price&&difference<minDiff){minPrice=dateArray[i].price;minDiff=difference;index=i;}
			    }
	        }
	    }
	}else{
	    for (var i = 0; i < dateArray.length; i++) {
			if(dateArray[i].nbNigths>=minNights&&dateArray[i].nbNigths<=maxNights){
	            depDate="";
	            depDate=disposArray[i].depDate2;
	            var date = depDate.split("-");
	            var tempDate=new Date();
	            tempDate.setFullYear(parseFloat(date[2]));
	            tempDate.setMonth(parseFloat(date[1])-1);
	            tempDate.setDate(parseFloat(date[0]));

	            var difference=Math.abs(daysElapsed(chosenDate,tempDate));
				if(difference<=aj||noDay){
	            	if(minPrice==0){minPrice=dateArray[i].price;minDiff=difference;index=i;}
					else if(parseFloat(minPrice)>parseFloat(dateArray[i].price)){minPrice=dateArray[i].price;index=i;if(difference<minDiff)minDiff=difference;}
					else if(minPrice==dateArray[i].price&&difference<minDiff){minPrice=dateArray[i].price;minDiff=difference;index=i;}
			    }
			}
	    }
	    var depCityCode=dateArray[index].depCityCode;
	    document.getElementById("dpci1").value = depCityCode;
	    fillSelectBoxDispo('departure-dates1', 'dpci1', disposArray, null);
	    updateDispo("1","2", disposArray);
	}
	var dateValue=dateArray[index].depDate2+'-'+dateArray[index].nbDays+'-'+dateArray[index].nbNigths;
	return dateValue;
}
function daysElapsed(date1,date2) {
    var difference = Date.UTC(date1.getYear(),date1.getMonth(),date1.getDate(),0,0,0)- Date.UTC(date2.getYear(),date2.getMonth(),date2.getDate(),0,0,0);
    return difference/1000/60/60/24;
}
function initialPath(sRoot,formuleCode,formule){
	var buffer = "";
	var criteria=Get_Cookie( 'search-criteria' );
	if(criteria==null)criteria="c.fo="+formuleCode;
	buffer ="<a href=\""+sRoot+"recherche-produits.html?"+criteria+"\">R&eacute;sultats "+formule+"</a>";
	document.getElementById("parcour").innerHTML = buffer;
}
function addBookmark(title,url) {
	var addFav = "";
	var title=document.title;
	var StrAlert='';
	if(window.sidebar) {addFav ="<a href=\"javascript:void(0);\" onclick=\"window.sidebar.addPanel('Voyages Auchan','"+url+"','');\">Ajouter &agrave; mes favoris<\/a>";
	}else if( isIE ) {addFav ="<a href=\"javascript:void(0);\" onclick=\"window.external.AddFavorite('"+url+"','Voyages Auchan');\">Ajouter &agrave; mes favoris<\/a>";
	}else {addFav ="<a href=\"javascript:void(0);\" onclick=\"addBookmark2()\">Ajouter &agrave; mes favoris<\/a>";}
	return addFav;
}
function addBookmark2(){
	if (navigator.appVersion.indexOf("Mac",0)>0){alert('Cette fonction n\'est pas r\xE9alisable sur Macintosh.');
	}else{alert('Cette fonction n\'est pas r\xE9alisable sur votre navigateur.');}
}
