// Fichier JScript
/**
* Prototype :
* Purpose :
* History :
*/
function nightChange()
{
	UpdateTotal();
}

/**
* Prototype :
* Purpose :
* History :
*/
function UpdateTotal()
{
    // on vÃ©rifie que le nombre de nuits est correct.
	//nbnights = document.getElementById ("numberofnights").options[document.getElementById("numberofnights").selectedIndex].value;

    // parcourir les chambres
    var room_id = 0;
    var total_room_object = document.getElementById("total_room_"+room_id);
    var l_intTotalStay = 0.0;

    while((total_room_object = document.getElementById("total_room_" + room_id)) != null)
    {
        total_room_object = document.getElementById("total_room_" + room_id);
        selector_room_object = document.getElementById("selector_room_" + room_id);
        var room_selected = selector_room_object.options[selector_room_object.selectedIndex].value;
 
 
        l_intTotalStay += room_selected * parseFloat(total_room_object.value.replace(',','.'))/1;
	
	    room_id++;
	}
	
	document.getElementById ("sum" ).innerHTML = Math.round(l_intTotalStay * 100)/100 + "&euro;" ;//Moved from top on 07-06-2007
	
}

/**
* Prototype :
* Purpose :
* History :
*/
function SearchDispoSubmit()
{
    //alert ("SearchDispoSubmit" + document.getElementById ("ctl00_Main_TextBoxStart" ).value);
    //Get start date
    var l_obj = document.getElementById ("ctl00_Main_TextBoxStart");
    if (l_obj == null)  return;
    var l_startdate = l_obj.value;
    
    //Get end date
    l_obj = document.getElementById ("ctl00_Main_TextBoxEnd");
    if (l_obj == null)  return;
    var l_enddate = l_obj.value;
    
    //Get Pax
    l_obj = document.getElementById ("ctl00_Main_DropDownListPax");
    if (l_obj == null)  return;
    var l_pax = l_obj.value;
    
    //Get Child Pax
    l_obj = document.getElementById ("ctl00_Main_DropDownListChildPax");
    if (l_obj == null)  return;
    var l_child_pax = l_obj.value;

    //Get Promocode
    l_obj = document.getElementById ("ctl00_Main_TextBoxPromo");
    if (l_obj == null)  return;
    var l_promo = l_obj.value;
    
    //2DO Check dates entries 
    //Modified by PMAB on 24-05-2007 window.open("propositions.aspx?startdate="+l_startdate+ "&enddate="+l_enddate /*+"&startday="+l_startday*/); 
    document.location.href = "propositions.aspx?startdate="+l_startdate+ "&enddate="+l_enddate+"&pax="+l_pax+"&child_pax="+l_child_pax+"&promo_code="+l_promo;

}


/**
* Prototype : HasRoomSelection
* Purpose :
* History :
*/
function HasRoomSelection()
{

    // parcourir les chambres
    var room_id = 0;
    var total_room_object = document.getElementById("total_room_"+room_id);
    var l_intTotalStay = 0;
    
    l_sFormURL = "";
    l_sroomtypeid = "0";
    l_sroomcount = "0";
    l_sroomtotal = "0";
    room_sequential_id = 0;
    while((total_room_object = document.getElementById("total_room_" + room_id)) != null)
    {
        total_room_object = document.getElementById("total_room_" + room_id);
        selector_room_object = document.getElementById("selector_room_" + room_id);
        var room_selected = selector_room_object.options[selector_room_object.selectedIndex].value;
        
        if (room_selected > 0)
        {
            room_sequential_id++;
            
        	l_sroomtypeid = l_sroomtypeid + "|" +  selector_room_object.name;
        	l_sroomcount = l_sroomcount + "|" +  room_selected;
        	l_sroomtotal = l_sroomtotal + "|" +  total_room_object.value;
        	
        	room_sequential_id++;
        }
	    room_id++;
	}
	
	if (room_sequential_id == 0)
        alert(GetValue("dico_room_required"));
        
	return (room_sequential_id > 0);
}


/**
* Prototype :
* Purpose :
* History :
*/
function RoomSelectionSubmit()
{
    //alert ("SearchDispoSubmit" + document.getElementById ("ctl00_Main_TextBoxStart" ).value);
    //Chexk user selelection
    
    
    // on vÃ©rifie que le nombre de nuits est correct.
	//nbnights = document.getElementById ("numberofnights").options[document.getElementById("numberofnights").selectedIndex].value;

    // parcourir les chambres
    var room_id = 0;
    var total_room_object = document.getElementById("total_room_"+room_id);
    var l_intTotalStay = 0;
    //var obj = document.getElementById("__EVENTTARGET");
    //alert(total_room_object.value);
    
    l_sFormURL = "";
    l_sroomtypeid = "0";
    l_sroomcount = "0";
    l_sroomtotal = "0";
    room_sequential_id = 0;
    while((total_room_object = document.getElementById("total_room_" + room_id)) != null)
    {
        total_room_object = document.getElementById("total_room_" + room_id);
        selector_room_object = document.getElementById("selector_room_" + room_id);
        var room_selected = selector_room_object.options[selector_room_object.selectedIndex].value;
        
        if (room_selected > 0)
        {
            room_sequential_id++;
            
        	l_sroomtypeid = l_sroomtypeid + "|" +  selector_room_object.name;
        	l_sroomcount = l_sroomcount + "|" +  room_selected;
        	l_sroomtotal = l_sroomtotal + "|" +  total_room_object.value;
        	
        	room_sequential_id++;
        }
	    room_id++;
	}
	
	/**/
	l_sFormURL = "agora_formulaire.php?p=0"
	            + "&roomtypeid=" + l_sroomtypeid
                + "&roomcount="+ l_sroomcount
                + "&roomtotal=" + l_sroomtotal
	            + GetHiddenFieldsAsUrl();
	            /**/

	            alert(l_sFormURL);
	            
		return 	l_sFormURL;
	            
	if (room_sequential_id > 0)
        document.location.href = l_sFormURL;
    else
        alert("Vous devez sélectionner au moins une chambre !!!!");
}


/**
* Prototype : IsEmpty()
* Purpose :
* History : Created on 14-01-2008
*/
function IsEmpty(p_sObjectName)
{
	var l_objSelector = document.getElementById(p_sObjectName);
    if (l_objSelector == null) return true;
    return (l_objSelector.value.length == 0);
    return false;
}

/**
* Prototype : GetValue()
* Purpose :
* History : Created on 17-02-2008
*/
function GetValue(p_sObjectName)
{
	var l_objSelector = document.getElementsByName(p_sObjectName)[0];
    if (l_objSelector == null) return "<Not Found in dico>";
    return (l_objSelector.value);
}

/**
* Prototype : IsEmpty()
* Purpose :
* History : Created on 14-01-2008
*/
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

	function IsEmailValid(p_sObjectName) {
		
		var l_objSelector = document.getElementById(p_sObjectName);
    	if (l_objSelector == null) return false;
    	var str = l_objSelector.value;
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var err_message=GetValue("dico_email_invalid");
		
		
		if (str.indexOf(at)==-1){
		   alert(err_message)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(err_message)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(err_message)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(err_message)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(err_message)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(err_message)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(err_message)
		    return false
		 }

 		 return true					
	}


/*
* PROTOTYPE : getSelector
* PURPOSE : return input parameter value
* HISTORY : CREATED BY PMAB on 14-01-2008
*/
function getSelector(p_sSelectorName)
{
    var l_objInput = document.getElementById (p_sSelectorName);
    if (l_objInput == null) return;
    return l_objInput.value;
}


/**
* Prototype : OwnerFormSubmit()
* Purpose :
* History :
*/
function OwnerFormSubmit()
{
	//nom
	 if(IsEmpty("nom"))
	 {
	 	alert(GetValue("dico_name_required"));
	 	return false;
	 }

	//prenom
	 if(IsEmpty("prenom"))
	 {
		alert(GetValue("dico_firstname_required"));
	 	return false;
	 }

	//adresse
	 if(IsEmpty("adresse"))
	 {
		alert(GetValue("dico_address_required"));
	 	return false;
	 }
	 
	//tel
	 if(IsEmpty("tel"))
	 {
	 	alert(GetValue("dico_phone_required"));
	 	return false;
	 }

	//Email
	 if(IsEmpty("mail"))
	 {
		alert(GetValue("dico_email_required"));
	 	return false;
	 }
	 
	 //Email validation
	 if (!IsEmailValid("mail"))
	 	return false;
	 	
	 return true;
	 
}

/**
* Prototype :
* Purpose :
* History :
*/
function OnNightSelectorClick()
{
    //Compute end date 
	//var dt_datetime = new Date('06/12/2007');
    var l_objStartDate = document.getElementById ("ctl00_Main_TextBoxStart");
    var l_objEndDate   = document.getElementById ("ctl00_Main_TextBoxEnd");
    if (l_objStartDate == null)  return;
    var l_startdate = l_objStartDate.value;
	
//	var dt_datetime = new Date(l_startdate);
	var dt_datetime = new Date();
	
	var l_intDebug = 0;
	//Debug	
	var l_sday = l_startdate.substr(0,2);
	var l_smonth = l_startdate.substr(3,2);
	var l_syear = l_startdate.substr(6,4);
	
	if (l_sday.substr(0,1)=="0") l_sday=l_sday.substr(1,1);//Remove first zero
	if (l_smonth.substr(0,1)=="0") l_smonth=l_smonth.substr(1,1);//Remove first zero

	if (l_intDebug == 1) alert(l_startdate + "=> l_sday=" + l_sday + " l_smonth = " + l_smonth + " l_syear=" + l_syear);
	if (l_intDebug == 1) alert("ParseInt(09)=" + parseInt("09") +" ParseInt=" + parseInt(l_sday) + "/" + parseInt(l_smonth) + "/" + parseInt(l_syear));
	
	dt_datetime.setDate(parseInt(l_sday));
	dt_datetime.setMonth(parseInt(l_smonth));
	dt_datetime.setFullYear(parseInt(l_syear));
    
    
    //Retrieve nights selection
    var l_objNightsSelector = document.getElementById ("SelectNights");
    if (l_objNightsSelector == null) return;
    var l_intNights = l_objNightsSelector.value;// .options[l_objNightsSelector.selectedIndex].value;
    
    //Debug 
    if (l_intDebug == 1) alert(l_intNights);
    //Compute end date
    if (l_intDebug == 1) alert('dt_datetime.getDate()='+dt_datetime.getDate()); 
    if (l_intDebug == 1) alert('dt_datetime.getMonth()='+dt_datetime.getMonth()); 
    if (l_intDebug == 1) alert('dt_datetime.getYear()='+dt_datetime.getYear()); 
    
	dt_datetime.setDate(dt_datetime.getDate() + parseInt(l_intNights));

	//Set new end date
	l_objEndDate.value =
	    (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/"
		    + (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth()) + "/"
		    + (dt_datetime.getFullYear());

}

/*
* PROTOTYPE : SearchDispoSubmit_combo
* PURPOSE : return stay parameters from combobox, Easier Way
* HISTORY : CREATED BY PMAB on 01-12-2007
*/
function getSelector(p_sSelectorName)
{
    var l_objSelector = document.getElementById (p_sSelectorName);
    if (l_objSelector == null) return;
    return l_objSelector.value;// .options[l_objNightsSelector.selectedIndex].value;
}

/*
* PROTOTYPE : SearchDispoSubmit_combo
* PURPOSE : return stay parameters from combobox, Easier Way
* HISTORY : CREATED BY PMAB on 30-11-2007
*/
function SearchDispoSubmit_combo()
{
    //Retrieve nights selection
    var l_intNights = getSelector("SelectNights");// .options[l_objNightsSelector.selectedIndex].value;

    //Retrieve day, month, year selection
    var l_intDay = getSelector("SelectDay");// .options[l_objNightsSelector.selectedIndex].value;
    var l_intMonth = getSelector("SelectMonth");// .options[l_objNightsSelector.selectedIndex].value;
    var l_intYear = getSelector("SelectYear");// .options[l_objNightsSelector.selectedIndex].value;
    
    //Get Pax
    var l_pax = getSelector("SelectPax");
    
    //Get Child Pax
    var l_child_pax = getSelector("SelectChildPax");

    //Get Promocode
    l_obj = document.getElementById ("ctl00_Main_TextBoxPromo");
    if (l_obj == null)  return;
    var l_promo = l_obj.value;
    
    //2DO Check dates entries 
    //Modified by PMAB on 24-05-2007 window.open("propositions.aspx?startdate="+l_startdate+ "&enddate="+l_enddate /*+"&startday="+l_startday*/); 
    //Modified by PMAB document.location.href = "propositions.aspx?startdate="+l_startdate+ "&enddate="+l_enddate+"&pax="+l_pax+"&child_pax="+l_child_pax+"&promo_code="+l_promo;
    document.location.href = "propositions.aspx?startday="+l_intDay+ "&startmonth="+l_intMonth+ "&startyear="+l_intYear+"&pax="+l_pax+"&nights="+l_intNights+"&child_pax="+l_child_pax+"&promo_code="+l_promo;
}


/*
* PROTOTYPE : Get Hidden Fields
* PURPOSE : return stay parameters from combobox, Easier Way
* HISTORY : CREATED BY PMAB on 30-11-2007
*/
function GetHiddenFieldsAsUrl()
{
	var l_sUrl = "";
	var i;
	
	if (document.persistent_form != null)
	{
		for(var i=0; i<document.persistent_form.length; ++i)
		 {
		 	l_sUrl = l_sUrl + "&" + document.persistent_form.elements[i].name+ "=" + document.persistent_form.elements[i].value;
		 }
	}

	 return l_sUrl;
	/*
	for(var i=0;i<document.persistent_form.length;++i)
	 {
	    document.write("<br>name: " + document.persistent_form.elements[i].name);
	    document.write(", type: " + document.persistent_form.elements[i].type);
	    document.write(", value: " + document.persistent_form.elements[i].value);
	 }
	 */	
}


/*
* PROTOTYPE : transportationSort()
* PURPOSE : sort result following given transportation id
* HISTORY : CREATED BY JULIO on 24-06-2009
*/

function transportationSort()
{
 /* alert("appel transportationSort");*/
  
  var fr = "fr";
  var gb = "gb";
  
  var transportation_selector_object =	document.getElementById("sort_proximity");
  var lang_object = document.getElementById("lang");
  
  var lang = lang_object.value;
   
/*   alert("appel transportationSort 2 transportation_selector_object="+transportation_selector_object);**/
  
 var selected_transportation_id= transportation_selector_object.value;
 
 /*alert("selected_transportation_id="+selected_transportation_id+"lang="+lang);*/
 
 if(selected_transportation_id > 0)
 { 
   if(lang==gb)
   {
    var param= "../en/hotel_list.php?proximite="+selected_transportation_id;
   }
   else
   {
    param= "../fr/hotel_list.php?proximite="+selected_transportation_id;
   }

   window.location.href = param;
 }
 else
 {
     return;
 }
   


}

/*
* PROTOTYPE : rateSort()
* PURPOSE : sort result following given field id
* HISTORY : CREATED BY JULIO on 24-06-2009
*/

function rateSort()
{
  //alert("appel");
  
   var fr = "fr";
  var gb = "gb";
  
  var rate_selector_object =document.getElementById("sort_rate");
  var lang_object = document.getElementById("lang");
  
  var lang = lang_object.value
  
  var selected_rate_order= rate_selector_object.value;
  
 if(selected_rate_order!="")
 {
  
  if(lang==gb)
  {
   var param = "../en/hotel_list.php?sortfield=Rate&sortorder="+selected_rate_order;
  }
  else
  {
	  param = "../fr/hotel_list.php?sortfield=Rate&sortorder="+selected_rate_order;
  }
  
  	window.location.href = param;
 }
 
 else
 {
   return;
 } 


}


/*
* PROTOTYPE : sortResult()
* PURPOSE : sort result following given field id
* HISTORY : CREATED BY JULIO on 24-06-2009
*/

function sortResult()
{
	 alert("appel");
	 
	 var fr = "fr";
     var gb = "gb";
	 
	 var sortSelector_object = document.getElementById("sortSelector");
	 var lang_object = document.getElementById("lang");
	 
	 var sort_city = (document.getElementById("sort_city")).value;
	 var sort_day = (document.getElementById("sort_day")).value;
	 var sort_month = (document.getElementById("sort_month")).value;
	 var sort_year = (document.getElementById("sort_year")).value;
	 var sort_nights = (document.getElementById("sort_nights")).value;
	 var sort_adults = (document.getElementById("sort_adults")).value;
	 var sort_transportation = (document.getElementById("sort_transportation")).value;
	 var sort_budget = (document.getElementById("sort_budget")).value;
	 
	 //var sort_gds_guid = (document.getElementById("sort_gds_guid")).value;
	 
	 var lang = lang_object.value;
	 
	 var sort_param = sortSelector_object.value;
	 var sort_field = sortSelector_object.options[sortSelector_object.selectedIndex].text;
	 
	 alert("appel 2 \n sort_field=" + sort_field +"\n sort_param=" + sort_param);
	 
	if(lang==gb)
	 {
		//var urlRedirection = "../en/hotel_list.php?";
		var urlRedirection = "reserve_hotel.php?"; //MODIFIED BY JULIO ON 14-12-2009 FOR MEEDEX
	    var prix = "rate";
		var transport= "transportation";
		var rating = "rating";
	 
	 }
	 else
	 {
	    //urlRedirection = "../fr/hotel_list.php?";
		urlRedirection = "reserve_hotel.php?";
		prix = "prix";
		transport= "trajet";
		rating = "étoile";
	 }
	 
	 //alert("appel 3");
	 
	 
	 if(sort_param !="" && sort_field !="")
	 {
	   //alert("appel 4 \n prix="+ prix);
		if((sort_field.toLowerCase().indexOf(prix.toLowerCase()))!= -1) //to check if the combo selected label is about rate
		{
		  //alert("appel 5");
		  

		 //MODIFIED BY JULIO ON 29-10-2009
		 /*urlRedirection += "sortfield=Rate&sortorder="+ sort_param +"&city="+ sort_city +"&day="+ sort_day +"&month="+ sort_month + "&year=" + sort_year + "&nights=" + sort_nights +"&adults=" + sort_adults +"&proximite=" + sort_transportation+"&ASYNC_MODE=READ&GDS_SESSION="+sort_gds_guid;*/
		 urlRedirection += "sortfield=Rate&sortorder="+ sort_param +"&city="+ sort_city +"&day="+ sort_day +"&month="+ sort_month + "&year=" + sort_year + "&nights=" + sort_nights +"&adults=" + sort_adults +"&proximite=" + sort_transportation+"&resa_flag=1";
		}
		
		//else
		else if((sort_field.toLowerCase().indexOf(transport.toLowerCase()))!= -1) //to check if the combo selected label is about transportation
		{
			//alert("appel 6")
						
		
			//MODIFIED BY JULIO ON 29-10-2009
			/*urlRedirection += "sortfield=Duration&sortorder="+ sort_param +"&city="+ sort_city +"&day="+ sort_day +"&month="+ sort_month + "&year=" + sort_year + "&nights=" + sort_nights +"&adults=" + sort_adults +"&proximite=" + sort_transportation+"&ASYNC_MODE=READ&GDS_SESSION="+sort_gds_guid;*/
			urlRedirection += "sortfield=Duration&sortorder="+ sort_param +"&city="+ sort_city +"&day="+ sort_day +"&month="+ sort_month + "&year=" + sort_year + "&nights=" + sort_nights +"&adults=" + sort_adults +"&proximite=" + sort_transportation+"&resa_flag=1";
		}
		
		//else if((sort_field.toLowerCase().indexOf(rating.toLowerCase()))!= -1) //to check if the combo selected label is about rating
		else
		{
			//alert("appel 7")
		

			//MODIFIED BY JULIO ON 29-10-2009
			/*urlRedirection += "sortfield=Rating&sortorder="+ sort_param +"&city="+ sort_city +"&day="+ sort_day +"&month="+ sort_month + "&year=" + sort_year + "&nights=" + sort_nights +"&adults=" + sort_adults +"&proximite=" + sort_transportation+"&ASYNC_MODE=READ&GDS_SESSION="+sort_gds_guid;*/
			urlRedirection += "sortfield=Rating&sortorder="+ sort_param +"&city="+ sort_city +"&day="+ sort_day +"&month="+ sort_month + "&year=" + sort_year + "&nights=" + sort_nights +"&adults=" + sort_adults +"&proximite=" + sort_transportation+"&resa_flag=1";
		}
		
		alert("urlRedirection"+urlRedirection);
		document.location.href = urlRedirection;
	 }
	 
}


/** Prototype : intval()
  * Purpose : Recupérer partie entière
  * History : Created by JULIO on 23-10-2009
**/
function intval (mixed_var, base) {
var tmp;
var type = typeof( mixed_var );
 
	if (type === 'boolean') {
		return (mixed_var) ? 1 : 0;
	} else if (type === 'string') {
		tmp = parseInt(mixed_var, base || 10);
		return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
	} else if (type === 'number' && isFinite(mixed_var) ) {
		return Math.floor(mixed_var);
	} else {
		return 0;
	}
}


/** Prototype : UpdateDays_init()
  * Purpose : To valid the dates
  * History : Created by JULIO on 10-07-2009
**/

function UpdateDays_init()
{
  var year_selector_object = document.getElementById("year");
  var selected_year = year_selector_object.value;
  var month_selector_object = document.getElementById("month");
  var day_selector_objet = document.getElementById("day");
  var selected_month =  month_selector_object.value;
  
  
if((selected_year/4) == (intval((selected_year/4)))){    //ANNEE BISSEXTILE

	if(selected_month == 2) // FEVRIER
 {
	  if(day_selector_objet.length == 31)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.length == 30)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.length == 28)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
	  }
 }
 else
 {
 	if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.length == 31) // AVRIL, JUIN
  	{
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.length == 31)// SEPTEMBRE, NOVEMBRE
  	{
 		day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.length == 30) // JANVIER, MARS, MAI, JUILLET
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.length == 30) // AOUT, OCTOBRE, DECEMBRE 
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	
	else if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.length == 29) // AVRIL, JUIN
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
    else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.length == 29)// SEPTEMBRE, NOVEMBRE
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
	
	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.length == 29) // JANVIER, MARS, MAI, JUILLET
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
    else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.length == 29) // AOUT, OCTOBRE, DECEMBRE 
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 }
	   
}else{    											//ANNEE NON BISSEXTILE

	if(selected_month == 2) // FEVRIER
 {
	  if(day_selector_objet.length == 31)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.length == 30)

	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.length == 29)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
 }
 else
 {
 	if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.length == 31) // AVRIL, JUIN
  	{
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.length == 31)// SEPTEMBRE, NOVEMBRE
  	{
 		day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.length == 30) // JANVIER, MARS, MAI, JUILLET
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.length == 30) // AOUT, OCTOBRE, DECEMBRE 
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	
	else if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.length == 28) // AVRIL, JUIN
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
    else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.length == 28)// SEPTEMBRE, NOVEMBRE
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
	
	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.length == 28) // JANVIER, MARS, MAI, JUILLET
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
    else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.length == 28) // AOUT, OCTOBRE, DECEMBRE 
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 }
 
  
}
  
  
}


/** Prototype : UpdateDays()
  * Purpose : To valid the dates
  * History : Created by JULIO on 10-07-2009
**/

function UpdateDays()
{
  var year_selector_object = document.getElementById("year");
  var selected_year = year_selector_object.value;
  var month_selector_object = document.getElementById("month");
  var day_selector_objet = document.getElementById("day");
  var selected_month =  month_selector_object.value;
  
 if((selected_year/4) == (intval((selected_year/4)))){    //ANNEE BISSEXTILE

	if(selected_month == 2) // FEVRIER
 {
	  if(day_selector_objet.options[day_selector_objet.options.length-1].value == 31)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.options[day_selector_objet.options.length-1].value == 30)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.options[day_selector_objet.options.length-1].value == 28)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
	  }
 }
 else
 {
 	if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 31) // AVRIL, JUIN
  	{
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 31)// SEPTEMBRE, NOVEMBRE
  	{
 		day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 30) // JANVIER, MARS, MAI, JUILLET
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 30) // AOUT, OCTOBRE, DECEMBRE 
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	
	else if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 29) // AVRIL, JUIN
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
    else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 29)// SEPTEMBRE, NOVEMBRE
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
	
	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 29) // JANVIER, MARS, MAI, JUILLET
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
    else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 29) // AOUT, OCTOBRE, DECEMBRE 
	{
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 }
	   
}else{    											//ANNEE NON BISSEXTILE

	if(selected_month == 2) // FEVRIER
 {
	  if(day_selector_objet.options[day_selector_objet.options.length-1].value == 31)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.options[day_selector_objet.options.length-1].value == 30)

	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
	  else if(day_selector_objet.options[day_selector_objet.options.length-1].value == 29)
	  {
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
	  }
 }
 else
 {
 	if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 31) // AVRIL, JUIN
  	{
	  	day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 31)// SEPTEMBRE, NOVEMBRE
  	{
 		day_selector_objet.options[day_selector_objet.options.length-1] = null;
  	}
 	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 30) // JANVIER, MARS, MAI, JUILLET
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 30) // AOUT, OCTOBRE, DECEMBRE 
  	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 	
	else if(selected_month != 2 && selected_month < 7 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 28) // AVRIL, JUIN
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
    else if(selected_month != 2 && selected_month > 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 28)// SEPTEMBRE, NOVEMBRE
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
  	}
	
	else if(selected_month != 2 && selected_month <= 7 && selected_month %2 != 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 28) // JANVIER, MARS, MAI, JUILLET
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
    else if(selected_month != 2 && selected_month >= 8 && selected_month %2 == 0 && day_selector_objet.options[day_selector_objet.options.length-1].value == 28) // AOUT, OCTOBRE, DECEMBRE 
	{
	   	day_selector_objet.options[day_selector_objet.options.length] = new Option(29,29);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(30,30);
		day_selector_objet.options[day_selector_objet.options.length] = new Option(31,31);
  	}
 }
 
  
}
  
  
}


/** Prototype : UpdateMonths()
  * Purpose : To valid the Month because conflict
  * History : Created by JULIO on 10-07-2009
**/

function UpdateMonths()
{
	UpdateDays();
}



/** Prototype : setCalendarEnding_safi()
  * Purpose : To set the booking calendar ending
  * History : Created by JULIO on 10-07-2009
**/

function setCalendarEnding_safi()
{
	var lang = document.getElementById("lang").value;
	var searchedMonth = document.getElementById("search_month").value; //GET SELECTED MONTH IN CONTEXT
	var year_selector_object = document.getElementById("year");
     var selected_year = year_selector_object.value;
	 var month_selector_object = document.getElementById("month");
     var selected_month = month_selector_object.value;
	 var day_selector_object = document.getElementById("day");
     var selected_day = day_selector_object.value;
	 
	
	 
	var dt_datetime = new Date();
	var current_day = dt_datetime.getDate();		 
	var current_month_org = dt_datetime.getMonth();
	var current_month = current_month_org +1; 			//DECALAGE DE 1 DANS LES MOIS EN JAVASCRIPT !!!!!
	var current_year = dt_datetime.getFullYear();
	
	

	 var index_month = 1;
	 var index_month_1 = 0;
	 var index_day = 1;
	 
	 
	 
	 


	if(selected_year == current_year) //2009					// effacement des mois anterieurs du mois courant.
	{
	  	//*******************************************TRAITEMENT MOIS ************************************/
		for(var i = 0; i<= 12; i++) // 1-SUPPRIMER LISTE INITIALE DES MOIS
		 {
			month_selector_object.options[0] = null;
		 }
		 
		 if(lang =="fr")
		 {
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Janvier",1); // 2-RECREER LISTE COMPLETE DES MOIS FR
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Février",2);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Mars",3);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Avril",4);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Mai",5);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Juin",6);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Juillet",7);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Août",8);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Septembre",9);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Octobre",10);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Novembre",11);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Décembre",12);
		 }
		 else
		 {
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("January",1); // 2-RECREER LISTE COMPLETE DES MOIS GB
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("February",2);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("March",3);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("April",4);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("May",5);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("June",6);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("July",7);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("August",8);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("September",9);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("October",10);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("November",11);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("December",12);
		 }
		//***********************************************************************************************/

		
		//*******************************************TRAITEMENT JOURS ************************************/
		/*for(var j = 0; j<=31;j++)
		{
			day_selector_object.options[0] = null;
		}
		
		for(var k = 1 ; k <= 31; k++)
		{
			day_selector_object.options[day_selector_object.options.length] = new Option (k,k);	
		}*/
		//***********************************************************************************************/
		
		while (index_month < current_month)
		 {
		  	month_selector_object.options[0] = null;
			
			index_month++;
		 }
		 
		 //***********************************TO SET THE SELECTED MONTH IN THE LIST**********************/
		 for(var i = 0; i<month_selector_object.length;i++)
		 {
			if(month_selector_object.options[i].value == searchedMonth)
			{
			  month_selector_object.options[i].selected = "selected";
			}
		 }
		 /**********************************************************************************************/
		 
		/*if(selected_month == current_month)			// effacement des jours anterieurs du jour courant.
		   {
			
			while (index_day < current_day)
			 {
				day_selector_object.options[0] = null;
				index_day++;
			 }
		   }*/
	}
	else if(selected_year == (current_year + 1)) //2010
	{
		//*******************************************TRAITEMENT MOIS ************************************/
		for(var i = 0; i<= 12; i++) // 1-SUPPRIMER LISTE INITIALE DES MOIS
		 {
			month_selector_object.options[0] = null;
		 }
		 
		if(lang =="fr")
		 {
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Janvier",1); // 2-RECREER LISTE COMPLETE DES MOIS FR
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Février",2);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Mars",3);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Avril",4);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Mai",5);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Juin",6);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Juillet",7);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Août",8);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Septembre",9);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Octobre",10);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Novembre",11);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("Décembre",12);
		 }
		 else
		 {
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("January",1); // 2-RECREER LISTE COMPLETE DES MOIS GB
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("February",2);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("March",3);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("April",4);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("May",5);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("June",6);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("July",7);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("August",8);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("September",9);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("October",10);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("November",11);
		 	month_selector_object.options[month_selector_object.options.length] = new Option ("December",12);
		 }
		//***********************************************************************************************/
		
				
		
	     
		 while(index_month_1 < 11) // 3-SUPPRIMER DE LA LISTE DES MOIS INUTILES 
		{
		  	month_selector_object.options[month_selector_object.options.length-1] = null;
		  
		  	index_month_1 ++;
		}
		
		//month_selector_object.options[month_selector_object.options.selectedIndex] = 1;
		
		//***********************************TO SET THE SELECTED MONTH IN THE LIST**********************/
		 for(var i = 0; i<month_selector_object.length;i++)
		 {
			if(month_selector_object.options[i].value == searchedMonth)
			{
			 month_selector_object.options[i].selected = "selected";
			}
		 }
		 /**********************************************************************************************/

		
		//*******************************************TRAITEMENT JOURS ************************************/
		/*for(var j = 0; j<=31;j++)
		{
			day_selector_object.options[0] = null;
		}
		
		for(var k = 1 ; k <= 31; k++)
		{
			day_selector_object.options[day_selector_object.options.length] = new Option (k,k);	
		}*/
		//***********************************************************************************************/
	   
	}

}



function choix_annee()
{
  var selected_month = document.getElementById("month").value;
  var selected_year_object = document.getElementById("year");
   var selected_year2_object = document.getElementById("year2"); 
  if(selected_month ==01)
  {
	 selected_year_object.value=2010; 
	 	 selected_year2_object.value=2010; 
  }
  else
  {
	  selected_year_object.value=2009; 
	  	 selected_year2_object.value=2009; 
  }
  
  //alert(selected_month+" "+selected_year_object.value+" "+selected_year2_object.value);
  
}


