// LIBRAIRE JavaScript
// Version 1.0
// 01-02-2001
// Lionel

// Permet d'interdire la saisi du champs elt + init
//elt.value = "";
//elt.blur();


// Attention a la caste des noms, respecter les majuscules et minuscules,
// pas de majuscules pour les operateurs

// --------------------------------------------
// --- Acces a un RadioBox et/ou Checkbox : ---
// --------------------------------------------
// F = Nom du formulaire
// X = Index des Radio OU checkbox
// YYYY = Propriete de la Radio / Checkbox (value, checked, length ...)
// document.nomduform.nom_elt[X].YYYY;
// document.forms[F].elements[nom_elt][X].YYYY;
// Nota: On utilise cette syntaxe pour le Checkbox seulement si l'on a plusieurs boutons checkbox ayant le meme nom.
// celle ci permet donc d'acceder aux differents sous elements d'un element principal.

// Attention la syntaxe d'acces est differente quand il y a un seul bouton radio ou plusieurs boutons radio:
// if (document.F1.radio_ftp.value)
// {
	// si un seul radio
	// traitement
// }
// else
// {
	// si plusieurs radio
	// traitement
// }

// ------------------------------------
// --- Acces a une liste deroulante ---
// ------------------------------------
// Index qui a ete selectionne
// document.forms[F].elements[L].selectedIndex
// libelle du champs de la liste selectionne
// document.forms[f].elements[l].options[document.forms[f].ville.selectedindex].text
// Valeur du champs de la liste selectionne
// document.forms[f].elements[l].options[document.forms[f].ville.selectedindex].value

// --------------
// Index du char.
//index = stringValue.indexOf(",");

// ---------------------------------------------
// Cette fonction permet de formater la chaine
// pour qu'elle puisse etre passe en param en URL
// url = escape(document.nomduform.nomchamps.value);


// ----------------------------
// --- LISTE DES FONCTIONS: ---
// ----------------------------
// init_Checkbox()
// isNumeric(str)
// checkradio(radioName,F)
// check_box(F,C)
// check_decimals(fieldName, fieldValue, decimals)
// check_date(F,C)
// check_list(F,L)
// check_list2(F,L)
// ouverture(url, toolbar, location, directories, status, menubar, scrollbars, resizable, width, height)
// fermer()
// checkEmail(emailInputBox)  [emailInputBox --> Objet]
// isEntier(str)
// Calendier

// BR 02/11/04 - changeMenuAol - l'action dans AOL s'appelle action1 et non plus action


function init_checkbox(){
	Nb = document.forms["comm"].Reg_Rattach.length;
	for (var i=0; i< Nb; i++)
	{
	document.comm.Reg_Rattach[i].checked = false;
	}
}

// --- PopUp
function popup(url, w, h, sc)
{
openpopup=window.open(url, 'popup', 'resizable=no,scrollbars=' + sc + ',width=' + w + ',height=' + h + ',menubar=no');
}
function openWindow(url,width,height,scrollbar,resiz) {
	x=(640-width)/2; y=(640-height)/2;
	if (screen) {
		y=(screen.availHeight-height)/2;
		x=(screen.availWidth-width)/2;
		}
	if (screen.availWidth>1800) {
		x=((screen.availWidth/2)-width)/2;
		}
	newwindow=window.open(url,'','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',SCROLLBARS=' + scrollbar +',RESIZABLE=' + resiz);
	newwindow.focus();
}

//---------------------------------------------------
// Fonction qui arrondi
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}


// ---------------------------------------------
// Test si la chaine est Numerique
function isNumeric(str)
{
	for (var i=0; i < str.length; i++)
	{
		var ch= str.substring(i,i+1);
		if (ch < "0" || ch > "9")
		{ return false; }
	}
	return true;
}

// ---------------------------------------------
// Ajout YQ pour champ montant avec "." pour les centimes
// Test si la chaine est Numerique
function isMontant(str)
{
	var a = str.split(".");
	if (a.length >2)
		return false;
	else if (a.length==2)
		if (a[1].length>2) return false;
		
	for (var i=0; i < str.length; i++)
	{
		var ch= str.substring(i,i+1);
		if (ch!=".")
		{
		if (ch < "0" || ch > "9")
		{ return false; }
		}
	}
	return true;
}
// ---------------------------------------------
// Test si la chaine est Numerique
function isNumericNegatif(str)
{
	for (var i=0; i < str.length; i++)
	{
		var ch= str.substring(i,i+1);
		if (i != 0 ) {
			if (ch < "0" || ch > "9")
			{ return false; }
		} else {
			if ( (ch < "0" || ch > "9") && ch != "-" )
			{ return false; }

		}
	}
	return true;
}

// ---------------------------------------------
// Test si l'un des boutons radio a ete coche
// IN:
// F = Nom du formulaire ou Index
// radioListName = Nom du bouton radio
// Appel : OnSubmit, OnClick ..
// Nota : Ne pas oublier le return lors de l'appel de la fonction: return XXX(Y,Z);
function checkradio(radioName,F) {
	var radioList=document.forms[F].elements[radioName];
	radioValue = null;
	for (i=0; i < radioList.length; i++) {
		if (radioList[i].checked) {
			radioValue = radioList[i].value;
			break;
		}
	}
	if (radioValue == null) {
		alert("Veuillez faire votre choix!");
		return false;
	} else {
		return true; // in operation would be "return true"
	}
	return false;
}

// ---------------------------------------------
// Test si l'on a coche au moins UN bouton
// IN:
// F = Nom du formulaire ou Index
// C = Nom du checkbox ou Index
// Appel : OnSubmit, OnClick ..
// Nota : Ne pas oublier le return lors de l'appel de la fonction: return XXX(Y,Z);
function check_box(F,C)
{
	result = 0;
	for (i in document.forms[F].elements[C])
	{
		if (document.forms[F].elements[C][i].checked)
		{
			result = 1;
		}
	}

	if (result == 0)
	{
		alert("Veuillez faire votre choix !");
		return false;
	}
	else
	{
		return true;
	}
}

// ---------------------------------------------
// Test si la valeur est de type decimal et qu'elle ne depasse pas les limites specifies
// IN:
// fieldName = Nom du champs
// fieldValue = Valeur du champs
// Decimals = Nombre limite de decimal
// Appel: OnChange
function check_decimals(fieldName, fieldValue, decimals)
{
	//decimals = 2;  //nombre de decimales

	if (isNaN(fieldValue))
	{
		alert("Oops!  cela ne ressemble pas à une valeur numérique.\n Exemples : 45   ou  52.50 .");
		// Mise du curseur sur l'input ou se trouve le probleme
		fieldName.select();
		fieldName.focus();
	}
	else
	{
		timeshundred = parseFloat(fieldValue * Math.pow(10, decimals));
		integervalue = parseInt(parseFloat(fieldValue) * Math.pow(10, decimals));
		if (timeshundred != integervalue)
		{
			alert ("Oops!  il faut entrer un nombre avec un maximum de " + decimals + " decimale(s).");
			// Mise du curseur sur l'input ou se trouve le probleme
			fieldName.select();
			fieldName.focus();
		}
	}
}

// ---------------------------------------------
// Test la date saisie
// IN :
// F = Nom du formulaire ou Index
// C = Nom du champs
// Appel : OnSubmit, OnClick ..
// Nota : Ne pas oublier le return lors de l'appel de la fonction: return XXX(Y,Z);
function check_date(F,C)
{
	/*var err = 0;
	string = document.forms[F].elements[C].value;
	var valid = "0123456789/"
	//var valid = "0123456789-";
	var ok = "yes";
	var temp;
	for (i=0; i< string.length; i++)
	{
		temp = "" + string.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") err = 1;
	}
	if (string.length != 10) err=1;

	//format francais jj-mm-aaaa
	b = string.substring(0, 2); // day
	c = string.substring(2, 3); // '/' ou -
	d = string.substring(3, 5); //  month
	e = string.substring(5, 6); // '/' ou -
	f = string.substring(6, 10); // year

	//format de date anglais aaaa-mm-jj
	//b = string.substring(8, 10); // day
	//c = string.substring(4, 5); // '/' ou -
	//d = string.substring(5, 7); //  month
	//e = string.substring(7, 8); // '/' ou -
	//f = string.substring(0, 4); // year

	if (b<1 || b>31) err = 1;
	if (c != '/') err = 1
	//if (c != '-') err = 1;
	if (d<1 || d>12) err = 1;
	if (e != '/') err = 1
	//if (e != '-') err = 1;
	if (f<0 || f>9999) err = 1;
	if (err==1)
	{
		//alert('La date n\'est pas valide');
		return false;
	}
	else
	{
		return true;
	}*/
	str = document.forms[F].elements[C].value;
	if (str=="")
	 return true;
  reg = new RegExp("^([0-9]{1,2})[ \/]([0-9]{1,2})[ \/]([0-9]{4})$", "g");
  result = reg.exec(str);
  if (result) {
   DateStrUser = eval(result[1]) + " " + eval(result[2] - 1) + " " + eval(result[3]);
   DateUser = new Date(result[3], eval(result[2] - 1), result[1]);
   VerifiedDateStr = DateUser.getDate() + " " + DateUser.getMonth() + " " + DateUser.getFullYear();
   if (DateStrUser == VerifiedDateStr)
    return DateUser.getFullYear()>1870;
   else
    return false;
  }
  else return false;
}

function check_date_us(F,C)
{

	str = document.forms[F].elements[C].value;
	if (str=="")
	 return true;
  reg = new RegExp("^([0-9]{1,2})[ \/]([0-9]{1,2})[ \/]([0-9]{4})$", "g");
  result = reg.exec(str);
  if (result) {
   DateStrUser = eval(result[2]) + " " + eval(result[1] - 1) + " " + eval(result[3]);
   DateUser = new Date(result[3], eval(result[1] - 1), result[2]);
   VerifiedDateStr = DateUser.getDate() + " " + DateUser.getMonth() + " " + DateUser.getFullYear();
   if (DateStrUser == VerifiedDateStr)
    return DateUser.getFullYear()>1870;
   else
    return false;
  }
  else return false;
}


//Verif de date extranet avec dd/mm/yy
function check_date_yy(F,C)
{

	str = document.forms[F].elements[C].value;
	if (str=="")
	 return true;
  reg = new RegExp("^([0-9]{1,2})[ \/]([0-9]{1,2})[ \/]([0-9]{2})$", "g");
  result = reg.exec(str);
  if (result) {
   DateStrUser = eval(result[2]) + " " + eval(result[1] - 1) + " " + eval(2000+result[3]);
   DateUser = new Date(eval(2000+result[3]), eval(result[1] - 1), result[2]);
   VerifiedDateStr = DateUser.getDate() + " " + DateUser.getMonth() + " " + DateUser.getFullYear();
   if (DateStrUser == VerifiedDateStr)
    return DateUser.getFullYear()>1870;
   else
    return false;
  }
  else return false;
}

//Verif de date extranet avec mm/dd/yy
function check_date_us_yy(F,C)
{

	str = document.forms[F].elements[C].value;
	if (str=="")
	 return true;
  reg = new RegExp("^([0-9]{1,2})[ \/]([0-9]{1,2})[ \/]([0-9]{2})$", "g");
  result = reg.exec(str);
  if (result) {
   DateStrUser = eval(result[2]) + " " + eval(result[1] - 1) + " " + eval(2000+result[3]);
   DateUser = new Date(eval(2000+result[3]), eval(result[1] - 1), result[2]);
   VerifiedDateStr = DateUser.getDate() + " " + DateUser.getMonth() + " " + DateUser.getFullYear();
   if (DateStrUser == VerifiedDateStr)
    return DateUser.getFullYear()>1870;
   else
    return false;
  }
  else return false;
}


// ---------------------------------------------
// Renvoie true si date1>date2
// IN :
// F = Nom du formulaire ou Index
// date1, date2 = Nom des champs dates
// Appel : OnSubmit, OnClick ..
// Nota : Ne pas oublier le return lors de l'appel de la fonction: return XXX(Y,Z);
function compareDate(F,date1,date2)
{
	var err = 0;
	stringD1 = document.forms[F].elements[date1].value;
	stringD2 = document.forms[F].elements[date2].value;

	//format francais jj-mm-aaaa
	b1 = stringD1.substring(0, 2); // day
	c1 = stringD1.substring(2, 3); // '/' ou -
	d1 = stringD1.substring(3, 5); //  month
	e1 = stringD1.substring(5, 6); // '/' ou -
	f1 = stringD1.substring(6, 10); // year

	b2 = stringD2.substring(0, 2); // day
	c2 = stringD2.substring(2, 3); // '/' ou -
	d2 = stringD2.substring(3, 5); //  month
	e2 = stringD2.substring(5, 6); // '/' ou -
	f2 = stringD2.substring(6, 10); // year

	if (f1<f2)
		return false;
	else if(f1==f2)
	{
		if(d1<d2)
			return false;
		else if(d1==d2)
		{
			if(b1<=b2)
				return false;
			else
				return true;
		}
		else return true;
	}
	else
		return true;
}

// ---------------------------------------------
// Renvoie true si date1>=date2
// IN :
// F = Nom du formulaire ou Index
// date1, date2 = Nom des champs dates
// Appel : OnSubmit, OnClick ..
// Nota : Ne pas oublier le return lors de l'appel de la fonction: return XXX(Y,Z);
function compareDateEqual(F,date1,date2)
{
	var err = 0;
	stringD1 = document.forms[F].elements[date1].value;
	stringD2 = document.forms[F].elements[date2].value;

	//format francais jj-mm-aaaa
	b1 = stringD1.substring(0, 2); // day
	c1 = stringD1.substring(2, 3); // '/' ou -
	d1 = stringD1.substring(3, 5); //  month
	e1 = stringD1.substring(5, 6); // '/' ou -
	f1 = stringD1.substring(6, 10); // year

	b2 = stringD2.substring(0, 2); // day
	c2 = stringD2.substring(2, 3); // '/' ou -
	d2 = stringD2.substring(3, 5); //  month
	e2 = stringD2.substring(5, 6); // '/' ou -
	f2 = stringD2.substring(6, 10); // year

	if (f1<f2)
		return false;
	else if(f1==f2)
	{
		if(d1<d2)
			return false;
		else if(d1==d2)
		{
			if(b1<b2)
				return false;
			else
				return true;
		}
		else return true;
	}
	else
		return true;
}
//---------------------------------------
// TEST LA VALEUR D'UNE LISTE DEROULANTE
// 1- : Cas ou l'on ne selectionne aucune ligne
// 2- : Cas ou la 1ere ligne = " -------"
//---------------------------------------
// Cas ou les listes deroulantes sont vides
function check_list(F,L)
{
	i = 0;
	i=document.forms[F].elements[L].length;
	if (i > 0) { return true; }
	else
	{
		alert ("L'action est impossible car la liste est vide");
		return false;
	}
}

function check_list2(F,L)
{
	// Si liste deroulante = " Choisissez une ville"
	if (document.forms[F].elements[L].selectedIndex == 0)
	{
		alert("Choisissez une ville !!! ");
		return false;
	}
	else
	{
		return true;
	}
}


// ---------------------------------------------
// Ouverture d'une nouvelle fenetre
function ouverture(url, toolbar, location, directories, status, menubar, scrollbars, resizable, width, height)
{
	if (toolbar == "") { toolbar = "yes"; }
	if (location == "") { location = "no"; }
	if (directories == "") { directories = "no"; }
	if (status == "") { status = "no"; }
	if (scrollbars == "") { scrollbars = "yes"; }
	if (resizable == "") { resizable = "yes"; }
	if (width == "") { width = "750"; }
	if (height == "") { height = "450"; }
	return window.open(url,"","toolbar="+toolbar+",location="+location+",directories="+directories+",status="+status+", menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable+",width="+width+",height="+height);
}


// ---------------------------------------------
// Fermeture d'une fenetre
function fermer()
{
	self.close();
}

// ----------------------------------
// Verification de la syntax du mail
// IN :
// emailInputBox = OBJET du champs
// OUT: True / False
// Appel : Onsubmit, OnChange ...
//  if (!checkEmail(document.form1.email))
function checkEmail(emailInputBox) {
	var emailString = emailInputBox.value;
	var addressIsValid = false;
	var invalidPatterns = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var validPatterns = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

	if (window.RegExp){

		if (!invalidPatterns.test(emailString) && validPatterns.test(emailString)) {
			addressIsValid = true;
		} else {
			addressIsValid = false;
		}
	} else {
		if(emailString.indexOf("@") >= 0)
			addressIsValid = true;
	}

	if (!addressIsValid) {
		//alert(" Mauvaise syntaxe du mail : \"" + emailString + "\"");

		//emailInputBox.focus();
		//emailInputBox.select();
		return false;
	}

	return addressIsValid;
}

// -------------------------
// Test si STR est un entier
// IN: Chaine
// OUT: True / False
function isEntier(str)
{
		var a=parseInt(str);
		if (isNaN(a))
		{
			alert ("Le champs doit etre un entier");
			return false;
		}
		else
		{ return true; }
}

// Fonction permettant d'initialiser l'element E en fonction de l'action desiree
// puis de submitter le form concerne.
// F = Nom du formulaire
// V = Valeur par laquelle il faut initialiser E
function go_form(F,V,E)
{
    document.forms[F].elements[E].value = V;
	document.forms[F].submit();
}


//verifie si on a bien un entier (avec espace => possible)
function isNumber(InString)
{
        RefString="1234567890 .";
        for (Count=0; Count < InString.length; Count++)
        {
                TempChar= InString.substring (Count, Count+1);
                if (RefString.indexOf (TempChar, 0)==-1)

                return (false);
        }
        return (true);
}

//change la ',' en '.'
function makeNumber(InString)
{
        var i;
        i = InString.indexOf (',', 0);
        if ( i != -1)
        {
                InString = InString.substring (0, i)+'.'+InString.substring (i+1);
        }
        return InString;
}



//verifie si on a bien une valeur booleenne (f ou t)
function isBool(InString)
{
        RefString="ft01";
        if (InString.length > 1) return (false);
        for (Count=0; Count < InString.length; Count++)
        {
                TempChar= InString.substring (Count, Count+1);
                if (RefString.indexOf (TempChar, 0)==-1)

                return (false);
        }
        return (true);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changeMenu(TheForm)
{
	TheForm.action.value ="rechargePage";
	return TheForm.submit();
}

function changeMenuAol(TheForm)
{
	TheForm.action1.value ="rechargePage";
	return TheForm.submit();
}


// ---------------------------------------------
// EVO71 : Ajout BR pour verifier que la date de depart est un samedi et que la zone est en mediterranée
function isHighSeason(day,month,year,zoneId,nbjours,langue)
{
	year = eval(year+2004);
	
	var startDate = new Date(year,month,day);
	var endDate = new Date(year,month,day);
	endDate.setDate(startDate.getDate()+nbjours);
	
	var zonesMediterranee = new Array(3,5,6,8,9,10,19,21,22,23,24,28,29,30,43,48,50,51,52,53,54);
	var txtConfirm;
	
	//on verifie si la zone est en mediterranee ou non		
	for (var i=0; i < zonesMediterranee.length; i++)
	{
		var zone = zonesMediterranee[i];
		if (zoneId == zone)
		{
		break;
		}
		if(i == zonesMediterranee.length-1)
		{
		return true;
		}
	}
	
	//on verifie que la date est un samedi et qu'on est en haute saison juin-septembre	
	if (startDate.getDay()==6 && endDate.getDay()==6)
		return true;
	else if((startDate.getDay()!=6 && startDate.getMonth() >= 5 && startDate.getMonth() <= 8) || (endDate.getDay()!=6 && endDate.getMonth() >= 5 && endDate.getMonth() <= 8))
		{
		// on propose à l'utilisateur de continuer ou non
		switch (langue)
			{
			  case 1:
			    txtConfirm = "The start or return date you have chosen is not on a Saturday. In the high season, start and return dates are generally on a Saturday. If you click on \"OK\", you might have a limited number of results. Click on \"Cancel\" to change your search criteria.";
			  break;
			  case 2:
			    txtConfirm = "La date de départ (ou de retour) que vous avez choisi n'est pas un samedi. En haute saison (de juin à septembre), les départs et les retours se font généralement le samedi. Nous vous suggérons de modifier vos dates pour obtenir un maximum d'offres. Cliquez sur \"Annuler\" pour modifier vos critères de recherche.";
			  break;
			  case 3:
			    txtConfirm = "The start or return date you have chosen is not on a Saturday. In the high season, start and return dates are generally on a Saturday. If you click on \"OK\", you might have a limited number of results. Click on \"Cancel\" to change your search criteria.";
			  break;
			  // Italien
			  case 4:
			    //txtConfirm = "The start or return date you have chosen is not on a Saturday. In the high season, start and return dates are generally on a Saturday. If you click on \"OK\", you might have a limited number of results. Click on \"Cancel\" to change your search criteria.";
				txtConfirm = "La data di partenza e di ritorno che e' stata scelta  non e' Sabato. In alta stagione  il check in ed il check out avvengono prevalentemente Sabato. Se clikka su \"OK\" potrà ottenere un numero limitato di risultati. Clikka su \"Cancel\" per cambiare i criteri della ricerca .";
			  break;
			  case 5:
			    txtConfirm = "The start or return date you have chosen is not on a Saturday. In the high season, start and return dates are generally on a Saturday. If you click on \"OK\", you might have a limited number of results. Click on \"Cancel\" to change your search criteria.";
			  break;
			  case 6:
			    txtConfirm = "The start or return date you have chosen is not on a Saturday. In the high season, start and return dates are generally on a Saturday. If you click on \"OK\", you might have a limited number of results. Click on \"Cancel\" to change your search criteria.";
			  break;
			  case 7:
			    txtConfirm = "The start or return date you have chosen is not on a Saturday. In the high season, start and return dates are generally on a Saturday. If you click on \"OK\", you might have a limited number of results. Click on \"Cancel\" to change your search criteria.";
			  break;
		  } 

		
		var submitOK = confirm(txtConfirm);
		if ( submitOK )
            return true;
        else
         	return false;
		}
		// on est pas en haute saison
		else
			return true;
}
function NewWindow(mypage,myname,w,h,scroll,size) //Ajout YQ
{
var fenetre=null;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+size;
  fenetre=window.open(mypage,myname,settings);
  fenetre.focus();
}


