//
//  FONCTIONS UTILISEES PAR LES MOTEURS DE RECHERCHE MICE SUR ACCORHOTELS et SOFITEL (en date du 8 mars 2007)
//

//Errors array
var ErrMsgArrayFR = new Array("Certains champs sont incorrects ou obligatoires. Merci de renouveler ou compléter votre saisie.","Le champ {ROW} ne peut pas contenir un nombre négatif. Merci de saisir à nouveau votre demande","Le champ {ROW} ne peut pas contenir un nombre décimal","Le format du champ {ROW} que vous avez saisi n'est pas valide.","Votre demande concerne de la réservation individuelle. Nous vous remercions de bien vouloir effectuer votre demande depuis le site accorhotels.com grand public.");
var ErrMsgArrayGB = new Array("Some information is either incorrect or missing. Please re-enter or add missing data.","Negative numbers cannot be used in the \"{ROW}\" field. Please enter your request again.","Decimal numbers cannot be used in the \"{ROW}\" field.","Invalid format in the \"{ROW}\" field.","Your request concerns an individual reservation. Please go to the accorhotels.com general public site to enter your request.");
var ErrMsgArrayDE = new Array("Manche Felder sind fehlerhaft oder nicht ausgefüllt. Bitte wiederholen oder ergänzen Sie Ihre Eingabe.","Das Feld \"{ROW}\" darf keine negative Zahl enthalten. Bitte geben Sie Ihre Anfrage erneut ein.","Das Feld \"{ROW}\" darf keine Dezimalzahl enthalten.","Das im Feld \"{ROW}\" eingegebene Format ist nicht gültig.","Ihre Anfrage betrifft eine individuelle Zimmerreservierung. Bitte tätigen Sie Ihre Zimmerreservierung über unser Reservierungsportal www.accorhotels.com.");
var ErrMsgArrayES = new Array("Ciertos campos son incorrectos o incompletos. Por favor, complete o añada los campos que faltan.","El campo \"{ROW}\" no puede contener un número negativo. Por favor, introduzca de nuevo su solicitud.","El campo \"{ROW}\" no puede contener un número decimal.","El formato del campo \"{ROW}\" que ha introducido no es válido.","Su solicitud se refiere a la reserva individual. Por favor, realice su solicitud desde el sitio accorhotels.com para el público en general.");
var ErrMsgArrayIT = new Array("Alcune informazioni sono errate o mancanti. Per favore verifica o completa i campi.","Il campo \"{ROW}\" non può contenere un numero negativo. Si prega di inserire nuovamente l'ordine.","Il campo \"{ROW}\" non può contenere un numero decimale.","Il formato inserito nel campo \"{ROW}\" non è valido.","La tua domanda riguarda una prenotazione per privati. Si prega di fare la domanda sul sito accorhotels.com grande pubblico.");
var ErrMsgArrayPT = new Array("Alguns campos est&atilde;o incompletos ou s&atilde;o de preenchimento obrigatório. Favor completá-los ou corrigi-los.","O campo \"{ROW}\" não pode conter um número negativo. Por favor, digite novamente o seu pedido.","O campo \"{ROW}\" não pode conter um número decimal.","O formato do campo \"{ROW}\" que você digitou é inválido.","O seu pedido refere-se a uma reserva individual. Por favor, efetue o seu pedido no site accorhotels.com destinado ao grande público.");
var ErrMsgArrayNL = new Array("Enkele informatie is incorrect of niet ingevuld. Gelieve ontbrekende of incorrecte gegevens opnieuw in te voeren.","Het veld \"{ROW}\" mag geen negatief getal bevatten. Wil uw aanvraag opnieuw invoeren.","Het veld \"{ROW}\" mag geen decimaal getal bevatten.","Het formaat van het veld \"{ROW}\" dat u hebt ingevoerd, is niet geldig.","Uw aanvraag betreft een individuele reservering. Wij danken u om uw aanvraag  te willen uitvoeren via de site accorhotels.com voor het grote publiek.");
var ErrMsgArrayZH = new Array("部分信息错误或缺失。 请重新输入或添加缺失数据。","Negative numbers cannot be used in the \"{ROW}\" field. Please enter your request again.","Decimal numbers cannot be used in the \"{ROW}\" field.","Invalid format in the \"{ROW}\" field.","Your request concerns an individual reservation. Please go to the accorhotels.com general public site to enter your request.");

var minRooms = 7;

/*
* gestion de l'affichage du div d'erreur
*****************************************************************************************************/
var erreur=0;
function show_erreur(errMsg){
	
	if(errMsg.length > 0)
	{
		document.getElementById('erreur').innerHTML="";
		document.getElementById('erreur').innerHTML=errMsg;
		document.getElementById('erreur').style.visibility="visible";
		erreur=1;
	}
}

/*
* verifie que les champs obligatoires ont ete renseignes au submit de la page
*****************************************************************************************************/
function check_form(){
	erreur=0;
	vRooms = 0;
	vDetails = 0;
	vCapacity = 0;
	
	mArray = eval('ErrMsgArray'+langSelected);
	
	var mSpanList = document.getElementsByTagName("span") ; 

	for(i=0;i<mSpanList.length;i++)
	{
		mSpanList[i].style.color='#666666';
		mSpanList[i].style.fontWeight='normal';
	}
	
	if(document.accorhotelform.nb_chambre.value < minRooms && document.accorhotelform.nb_chambre.value > 0)
	{
		show_erreur(mArray[4]);
		colorizeLabel('label_nb_chambre');
		return;
	}

	vRooms = intVerify(document.accorhotelform.nb_chambre);
	if(vRooms > 0){show_erreur(mArray[vRooms].replace('{ROW}',document.getElementById('label_nb_chambre').innerHTML));colorizeLabel('label_nb_chambre');return;}
	
	vDetails = intVerify(document.accorhotelform.nb_salles);
	if(vDetails > 0){show_erreur(mArray[vDetails].replace('{ROW}',document.getElementById('label_nb_salles').innerHTML));colorizeLabel('label_nb_salles');return;}
	
	vCapacity = intVerify(document.accorhotelform.capacite_salles);
	if(vCapacity > 0){show_erreur(mArray[vCapacity].replace('{ROW}',document.getElementById('label_capacite_salles').innerHTML));colorizeLabel('label_capacite_salles');return;}
	
	if (document.accorhotelform.nom_ville.value=="" || document.accorhotelform.nom_ville.value==null) {
		show_erreur(mArray[0]);
		colorizeLabel('label_nom_ville');
	}
	
	if ( (document.accorhotelform.RA1.value=="") || (document.accorhotelform.RA1.value=="null") || (document.accorhotelform.RA1.value=="0") ){
		show_erreur(mArray[0]);
		colorizeLabel('label_type_reunion');
	}
	
	if(erreur==0){
		document.accorhotelform.submit();
	}
}

function colorizeLabel(label)
{
	document.getElementById(label).style.color='#b0232a';
	document.getElementById(label).style.fontWeight='bold';
}

function disabledCheckBox()
{
	document.getElementById('brand_SOF').disabled = false;
	document.getElementById('brand_NOV').disabled = false;
	document.getElementById('brand_MER').disabled = false;
	document.getElementById('brand_IBI').disabled = false;
	document.getElementById('brand_PUL').disabled = false;
	document.getElementById('brand_MGA').disabled = false;
	
	if(!isNaN(document.getElementById('nom_ville').value) && document.getElementById('nom_ville').value.length > 0){
	document.getElementById('brand_SOF').checked = false;
	document.getElementById('brand_NOV').checked = false;
	document.getElementById('brand_MER').checked = false;
	document.getElementById('brand_IBI').checked = false;	
	document.getElementById('brand_PUL').checked = false;	
	document.getElementById('brand_MGA').checked = false;
	
	document.getElementById('brand_SOF').disabled = true;
	document.getElementById('brand_NOV').disabled = true;
	document.getElementById('brand_IBI').disabled = true;
 	document.getElementById('brand_MER').disabled = true;                                                
 	document.getElementById('brand_PUL').disabled = true;
	document.getElementById('brand_MGA').disabled = false;
	}                                                
} 

//return code ErrMsg
function intVerify(input)
{
	if(input.value.length <= 0)
	{
		return 0;
	}
	
	//test if the value is a number
	if(isNaN(input.value))
	{	
		return 3
	}
	else
	{
		//test if the value is negative
		if(input.value < 0)
		{
			return 1;
		}
		//test if the value is float
		if(input.value.toString().indexOf('.') >= 0 || input.value.toString().indexOf(',') >= 0)
		{
			return 2;
		}
	}
	
	return 0;
}

/*
* fonctions utilitaires dreamweaver ...
*****************************************************************************************************/
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/****************************************************************************************************/

/*
* popup d'ouverture du calendrier ... a remplacer par div utilisant scriptaculous ! cf formulaire de resa pro
*****************************************************************************************************/
function calendrier_arrivee_meeting() {
	var d = new Date();
	var anneeActuel = d.getYear();
	//alert(anneeActuel);
	cal_arrivee=window.open(
		'/commun/calendrier.jsp?date_min=21/02/2007&date_max=31/12/2008'+
			'&mois='+(document.accorhotelform.mois_arrivee.selectedIndex+1)+
			'&annee='+(document.accorhotelform.annee_arrivee.selectedIndex+anneeActuel)+
			'&qdate=arrivee',
		'calen_arrivee',
	  'width=246,height=196,toolbar=no,location=no,menubar=no,resizable=no,status=no,screenX=0,left=0,screenY=0,top=0'
	);
}


/*
* fonction qui permet de montrer le bloc optionel des parametres de filtre/recherche mice
*****************************************************************************************************/
var voir_option=0;
function show_option(){
	if(voir_option==0){
		document.getElementById('lb_plusoption').innerHTML		= moinsOption;
		document.getElementById('option').style.display			= "block";
		//document.getElementById('goodies_option').style.display	= "block";
		voir_option=1;
	}else{
		document.getElementById('lb_plusoption').innerHTML		= plusOption;
		document.getElementById('option').style.display			= "none";
		//document.getElementById('goodies_option').style.display	= "none";
		voir_option=0;
	}
}

/*
* Recuperation des parametres de la recherche
*****************************************************************************************************/
function getSearchParameters(){
	// recuperation de la destination
	if(d_destination != null && d_destination !=""){
		document.accorhotelform.nom_ville.value = d_destination;
	}
	// recuperation de la date in et du nombre de nuits
	if (null != d_stayDates){
		if(d_stayDates.monthIn!='' && d_stayDates.dayIn!='' && d_stayDates.yearIn!=''){
			met_arrivee(d_stayDates.dayIn,d_stayDates.monthIn,d_stayDates.yearIn);
		}
		if(d_stayDates.nbNights!='') document.accorhotelform.nb_nuit.value = d_stayDates.nbNights;
	}
	// recuperation du type de reunion choisi
	if (null != d_rfpCriteria ){
		var meetingType = d_rfpCriteria.meetingTypeCode;
		if (null!=meetingType && ""!=meetingType)
			document.getElementById(meetingType).selected=true;
	}
}

/*
* recuperation des parametres d'initialisation des champs du formulaires par passage dans l'url
*****************************************************************************************************/
function getParams(){
  // recuperation des variables
  var ra1 = getParam('RA1');
  var nbChambre = getParam('nb_chambre');
  var numContrat = getParam('num_contrat');
  var numSociete = getParam('num_societe');
  var rfpId = getParam('rfpid');
  var nbSalles = getParam('nb_salles');
  var capaciteSalles = getParam('capacite_salles');
  var nbNuit = getParam('nb_nuit');
  var nomVille = getParam('nom_ville');
  var moisArrivee = getParam('mois_arrivee');
  var jourArrivee = getParam('jour_arrivee');
  var anneeArrivee = getParam('annee_arrivee');
  var eventCode = getParam('event_code');

  // mise a jour du formulaire si donnees recues en url

  if(ra1!='') document.accorhotelform.RA1.value = ra1.toUpperCase();
  if(nbChambre!='' && nbChambre!='0') document.accorhotelform.nb_chambre.value = nbChambre;
  if(numContrat!='') document.accorhotelform.cont.value = numContrat;
  if(numSociete!='') document.accorhotelform.client.value = numSociete;
  if(rfpId!='') document.accorhotelform.rfpid.value = rfpId;
  if(nbSalles!='' && nbSalles!='0') document.accorhotelform.nb_salles.value = nbSalles;
  if(capaciteSalles!='' && capaciteSalles!='0') document.accorhotelform.capacite_salles.value = capaciteSalles;
  if(nbNuit!='') document.accorhotelform.nb_nuit.value = nbNuit;
  if(nomVille!='') document.accorhotelform.nom_ville.value = unescape(nomVille);
  if(moisArrivee!='' && jourArrivee!='' && anneeArrivee!=''){
	met_arrivee(jourArrivee,moisArrivee,anneeArrivee);
  }
  if (eventCode!=''){
	document.accorhotelform.productCodeEvents.value = eventCode;
	show_option();
	}
}

/*
* Recuperation des parametres de la recherche specifique SOFITEL CODE NURUN
*****************************************************************************************************/
function getSearchParametersSOF(){
	// recuperation de la destination
	if(d_destination != null && d_destination !=""){
		document.accorhotelform.nom_ville.value = d_destination;
	}
	// recuperation de la date in et du nombre de nuits
	if (null != d_stayDates){
		if(d_stayDates.monthIn!='' && d_stayDates.dayIn!='' && d_stayDates.yearIn!=''){
			var dateIn = {"d": Number(d_stayDates.dayIn), "m": Number(d_stayDates.monthIn), "y": Number(d_stayDates.yearIn)};
			SOF.dates.update(dateIn, "start");
		}
		if (d_stayDates.nbNights){
			SOF.dates.updateNights(d_stayDates.nbNights);
		}
	}
	// recuperation du type de reunion choisi
	if (null != d_rfpCriteria ){
		var meetingType = d_rfpCriteria.meetingTypeCode;
		if (null!=meetingType && ""!=meetingType)
			SOF.niceforms.update.select('RA1',meetingType);
	}
}

/*
* recuperation des parametres d'initialisation des champs du formulaires par passage dans l'url
* CODE SPECIFIC CODE NURUN (sigh)
*****************************************************************************************************/
function getParamsSOF(){
  // recuperation des variables
  var ra1 = getParam('RA1');
  var nbChambre = getParam('nb_chambre');
  var numContrat = getParam('num_contrat');
  var numSociete = getParam('num_societe');
  var rfpId = getParam('rfpid');
  var nbSalles = getParam('nb_salles');
  var capaciteSalles = getParam('capacite_salles');
  var nbNuit = getParam('nb_nuit');
  var nomVille = getParam('nom_ville');
  var moisArrivee = getParam('mois_arrivee');
  var jourArrivee = getParam('jour_arrivee');
  var anneeArrivee = getParam('annee_arrivee');
  var eventCode = getParam('event_code');
  var meetingPromotionCode = getParam('meetingPromotionCode');

  // mise a jour du formulaire si donnees recues en url

  if(ra1!='') SOF.niceforms.update.select('RA1',ra1);
  if(nbChambre!='' && nbChambre!='0') document.accorhotelform.nb_chambre.value = nbChambre;
  if(numContrat!='') document.accorhotelform.cont.value = numContrat;
  if(numSociete!='') document.accorhotelform.client.value = numSociete;
  if(rfpId!='') document.accorhotelform.rfpid.value = rfpId;
  if(nbSalles!='' && nbSalles!='0') document.accorhotelform.nb_salles.value = nbSalles;
  if(capaciteSalles!='' && capaciteSalles!='0') document.accorhotelform.capacite_salles.value = capaciteSalles;
  if(nbNuit!='') SOF.dates.updateNights(nbNuit);
  if(nomVille!='') document.accorhotelform.nom_ville.value = unescape(nomVille);
  if(moisArrivee!='' && jourArrivee!='' && anneeArrivee!=''){
			var dateIn = {"d": Number(jourArrivee), "m": Number(moisArrivee), "y": Number(anneeArrivee)};
			SOF.dates.update(dateIn, "start");
  }
  if (eventCode!=''){
   SOF.niceforms.update.select('productCodeEvents',eventCode);
   var h3element = document.getElementById("moreOptions");
	SOF.showHide.exe(null, h3element);
	}
	if(meetingPromotionCode!='') document.accorhotelform.meetingPromotionCode.value = meetingPromotionCode;
}


/*
* Fonction utilisee par le onload du moteur de recherche mice
*****************************************************************************************************/
function onRechHotelMiceLoad(){
	// Autres fonctions
	dates_init(document.accorhotelform);
	change_nb_nuit();
	// detection si on est deja passe par le onLoad sur arrivage direct de la page par un lien
	// si on retourne sur la page par un back, on ne veut pas reprendre les valeur d'origine mais les valeur que l'on avait rentre dans le formulaire
	var paramLoaded = document.getElementById("param_loaded_state").value;
	if (paramLoaded=="false"){
		getSearchParameters();
		getParams();
		document.getElementById("param_loaded_state").value = "true";
	}
	brandCriteria_init();	
}

function brandCriteria_init(){	
 var brandCodes=null;	
 var tmp = unescape(window.location.search).substr(1).split("&");
 var inter;
 for ( i=0; i<tmp.length; i++)
 {
  inter=tmp[i].indexOf("=");
  if ( inter>=0 )
    {
     if(tmp[i].substr(0,inter)=='brandCodes');
     brandCodes=tmp[i].substr(inter+1);
    }
 }
	
	if(brandCodes!=null){
		var brandCodesArray = brandCodes.split('|');
		for(var i=0; i<brandCodesArray.length; i++){
			var element = document.getElementById('brand_'+brandCodesArray[i]);			
			if(element!=null)
				element.checked = true;
		}
	}
	else{
		var container = document.getElementById('label_chaines').childNodes;
		for(var i=0; i<container.length; i++){
			if(container[i].type == "checkbox")
				container[i].checked = true;
		}
	}
}

var tabBrand=new Array('SOF','NOV','MER','IBI','PUL', 'MGA');

function brandCriteria_submit(){	
	var brandCodes='';
	//Cas toutes les cases cochees
	var allb = true ;
	for (var i=0 ; i < tabBrand.length ; i++){
		if (document.getElementById('brand_' + tabBrand[i]).checked==true){
			if (brandCodes != '') { brandCodes += '|' ; }
			brandCodes += tabBrand[i]; 
			
		} else allb =false ;
	}
	if (allb) brandCodes = 'ALL'; // toutes les cases cochées
	if (brandCodes == '') brandCodes = 'ALL'; // aucune case cochée
	document.getElementById('code_chaine').value=brandCodes;
}
