var popupStatus = 0;
var JsHost = (('https:' == document.location.protocol) ? 'https://' : 'http://');
//alert(JsHost);
var script = JsHost+"www.book-your-hotel.com/reservation_honotel/ajax-call/ajax-call.php";
//var script = JsHost+"localhost/v3.book-your-hotel.com/reservation_honotel/ajax-call/ajax-call.php";

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#popupTypeChambre").fadeIn("slow");
		popupStatus = 1;
	}
}

//loading popup with jQuery magic!
function loadPopupFormContact(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#formContactPopup").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupTypeChambre").fadeOut("slow");
		popupStatus = 0;
	}
}

//disabling popup with jQuery magic!
function disablePopupFormContact(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#formContactPopup").fadeOut("slow");
		popupStatus = 0;
	}
}

//loading popup with jQuery magic!
function loadPopupTermesConditions(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#popupTermesConditions").fadeIn("slow");
		popupStatus = 1;
	}
}

//centering popup
function centerPopupTermesConditions(){
	//request data for centering
	//$(window).width(), $(window).height()
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupTermesConditions").height();
	var popupWidth = $("#popupTermesConditions").width();
	//centering
	$("#popupTermesConditions").css({
		"position": "absolute",
		"top": 235,
		"left": 360
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}



//centering popup
function centerPopup(){
	//request data for centering
	//$(window).width(), $(window).height()
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupTypeChambre").height();
	var popupWidth = $("#popupTypeChambre").width();
	//centering
	$("#popupTypeChambre").css({
		"position": "absolute",
		"top": 235,
		"left": 360
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//centering popup
function centerFormContactPopup(){
	//request data for centering
	//$(window).width(), $(window).height()
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#formContactPopup").height();
	var popupWidth = $("#formContactPopup").width();
	//centering
	$("#formContactPopup").css({
		"position": "absolute",
		"top": 160,
		"left": 360
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
//centering popup
function centerPopupNewsLetter(){
	//request data for centering
	//$(window).width(), $(window).height()
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupNewsLetter").height();
	var popupWidth = $("#popupNewsLetter").width();
	//centering
	$("#popupNewsLetter").css({
		"position": "absolute",
		"top": 190,
		"left": 500
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function loadPopupNewsLetter(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		/*$("#backgroundPopup").css("opacity", "0.7");
		$("#backgroundPopup").fadeIn("slow");*/
		$("#popupNewsLetter").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupNewsLetter(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		//$("#backgroundPopup").fadeOut("slow");
		$("#popupNewsLetter").fadeOut("slow");
		popupStatus = 0;
	}
}


/**
*
*/
function getTypeChambreInfos(idHotel, idTypeChambre, lang){
	var content = "";
	$("#popupTypeChambre").html("&nbsp;");
	$.ajax({
		type: "POST",
		url: script,
		data: "action=infos-type-chambre&idHotel="+idHotel+"&idTypeChambre="+idTypeChambre+"&lang="+lang,
		success: function(msg){
			//content = msg;
			//alert(msg);
			$("#popupTypeChambre").html(msg);
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function getRateCodeInfos(rateCode, lang, taxe_sejour){
	var content = "";
	//$("#popupTermesConditions").html("&nbsp;");
	//alert(script);
	$.ajax({
		type: "POST",
		url: script,
		data: "action=infos-rate-code&rateCode="+rateCode+"&lang="+lang+"&taxe_sejour="+taxe_sejour,
		success: function(msg){
			//content = msg;
			//alert(msg);
			//cnt_termes_conditions
			document.getElementById('popupTermesConditions').style.display='block';
			$("#cnt_termes_conditions").html(msg);
			centerPopupTermesConditions();
			loadPopupTermesConditions();
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function getRateCodeInfosByHotel(code_hotel, rateCode, lang, taxe_sejour){
	var content = "";
	//alert(code_hotel +","+ rateCode);
	//$("#popupTermesConditions").html("&nbsp;");
	$.ajax({
		type: "POST",
		url: script,
		data: "action=infos-rate-code-by-hotel&code_hotel="+code_hotel+"&rateCode="+rateCode+"&lang="+lang+"&taxe_sejour="+taxe_sejour,
		success: function(msg){
			//content = msg;
			//alert(msg);
			//cnt_termes_conditions
			document.getElementById('popupTermesConditions').style.display='block';
			$("#cnt_termes_conditions").html(msg);
			centerPopupTermesConditions();
			loadPopupTermesConditions();
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function getFormContact(code_hotel, lang){
	var content = "";
	$("#formContactPopup").html("&nbsp;");
	$.ajax({
		type: "POST",
		url: script,
		data: "action=form_contact_popup_fiche_hotel&code_hotel="+code_hotel+"&lang="+lang,
		success: function(msg){
			//content = msg;
			//alert(msg);
			$("#formContactPopup").html(msg);
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function getTypeChambreMonthlyPrice(idHotel, idTypeChambre, rateCode,lang){
	///var rateCodeBugHotel = rateCode.replace(" ", "-");
	
	var content = "";
	var currentId = "content-monthly-price-" + idTypeChambre + "-" + rateCode.replace(" ", "-");
	$("#"+currentId).css("display", "block");
	$("#"+currentId).html("<img class='loader' src='http://www.book-your-hotel.com/media/images/ajax-loader.gif' />");	
	
	//alert($("#DateRangeStartResa").val()+ " *****  " + $("#DateRangeEndResa").val());
	$.ajax({
		type: "POST",
		url: script,
		data: "action=calendar-type-chambre&idHotel="+idHotel+"&idTypeChambre="+idTypeChambre+"&lang="+lang+"&rateCode="+rateCode+"&DateRangeStart="+$("#DateRangeStartResa").val()+"&DateRangeEnd="+$("#DateRangeEndResa").val()+"&duration="+$("#duration").val(),
		success: function(msg){
			//content = msg;

			$("#"+currentId).html(msg);
			displayCalendarBYH(currentId);
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}
/**
*
*/
function closeCalendarBYH(currentId){
	$("#"+currentId).css("display", "none");
	$("#"+currentId).html("&nbps;");
}
/**
* 
*/
function displayCalendarBYH(currentId){
	$("#"+currentId).css("display", "block");
	$("div").each(function(i){
	 	if(this.className == "content-monthly-price" ){
	 		if(this.id != currentId){
	 			$("#"+this.id).css("display", "none");
	 			$("#"+this.id).html("&nbps;");
	 		}	
	 	}
	 });
}


function getPopUpInfosTypeChambre(code_hotel, code_type_chambre, lang){
	getTypeChambreInfos(code_hotel,code_type_chambre, lang);
	//centering with css
	centerPopup();
	//load popup
	loadPopup();	
}

function getPopUpFormContact(code_hotel, lang){
	getFormContact(code_hotel, lang);
	//centering with css
	centerFormContactPopup();
	//load popup
	loadPopupFormContact();	
}

/**
*
*/
function saveNewsLetter(lang){
	var content = "";
	$("#popupNewsLetter").html("&nbsp;");
	$("#loading").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	$("#loading").css("display", "block");	
	$.ajax({
		type: "POST",
		url: script,
		data: "action=save-news-letter&emailNewsLetter="+$("#emailNewsLetter").val()+"&lang="+lang,
		success: function(msg){
			//content = msg;
			
			//centering with css
			
			//load popup
			$("#popupNewsLetter").html(msg);
			centerPopupNewsLetter();
			loadPopupNewsLetter();
			$("#loading").html('&nbsp;');
			$("#loading").css("display", "none");	
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function saveFormulaireContactFicheHotel(lang){
	var cont = $('div.container');
	// validate the form when it is submitted
	$("#contact_hotel_form").validate({	
         submitHandler: function(form) {
             form.submit();
         },	
		errorContainer: cont,
		errorLabelContainer: $("ol", cont),
		wrapper: 'li',
		meta: "validate"	
	});		
	$('#contact_hotel_form').submit();

	/****************************************************************/
	
	var content = "";
	$("#loading_contact").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	$("#loading_contact").css("display", "block");	

	var list_emails_responsable_resa = "";
	var list_hiddens = document.getElementsByName("email_responsable_reservation");	
	for(i = 0; i < list_hiddens.length; i++){
		list_emails_responsable_resa += "&email_responsable_reservation_"+i+"="+document.getElementById(list_hiddens[i].id).value;
	}
	
	$.ajax({
		type: "POST",
		url: script,
		data: "action=send-contact-hotel&objet="+$("#objet").val()+"&nom_hotel="+$("#nom_hotel").val()+"&nom="+$("#nom").val()+"&prenom="+$("#prenom").val()+"&phone="+$("#phone").val()+"&message="+$("#message").val()+"&mail="+$("#mail").val()+"&lang="+lang+list_emails_responsable_resa,
		success: function(msg){
			//centering with css
			$("#loading_contact").html('&nbsp;');
			$("#loading_contact").css("display", "none");
			$("#msg_confirmation_contact").html('<b>'+msg+'</b>');
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

function saveFormulaireContactPopupFicheHotel(lang){
	var cont2 = $('div.container_2');
	// validate the form when it is submitted
	$("#contact_hotel_form_2").validate({	
        submitHandler: function(form) {
            form.submit();
        },	
		errorContainer: cont2,
		errorLabelContainer: $("ol", cont2),
		wrapper: 'li',
		meta: "validate"	
	});			
	$('#contact_hotel_form_2').submit();

	/*********************************************/
	
	var content = "";
	$("#loading_contact_2").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	$("#loading_contact_2").css("display", "block");	

	var list_emails_responsable_resa = "";
	var list_hiddens = document.getElementsByName("popup_contact_email_responsable_reservation");	
	for(i = 0; i < list_hiddens.length; i++){
		list_emails_responsable_resa += "&email_responsable_reservation_"+i+"="+document.getElementById(list_hiddens[i].id).value;
	}
	
	$.ajax({
		type: "POST",
		url: script,
		data: "action=send-contact-hotel&objet="+$("#objet_2").val()+"&nom_hotel="+$("#nom_hotel_2").val()+"&nom="+$("#nom_2").val()+"&prenom="+$("#prenom_2").val()+"&phone="+$("#phone_2").val()+"&message="+$("#message_2").val()+"&mail="+$("#mail_2").val()+"&lang="+lang+list_emails_responsable_resa,
		success: function(msg){
			//centering with css
			$("#loading_contact_2").html('&nbsp;');
			$("#loading_contact_2").css("display", "none");
			$("#msg_confirmation_contact_2").html('<b>'+msg+'</b>');
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function saveFormulaireSeminaireFicheHotel(lang){
	var cont = $('div.container');
	// validate the form when it is submitted
	$("#contact_hotel_form").validate({	
         submitHandler: function(form) {
             form.submit();
         },	
		errorContainer: cont,
		errorLabelContainer: $("ol", cont),
		wrapper: 'li',
		meta: "validate"	
	});		
	$('#contact_hotel_form').submit();
	
	/****************************************************************/
	
	var content = "";
	$("#loading_seminaire").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	$("#loading_seminaire").css("display", "block");	

	var list_emails_responsable_resa = "";
	var list_hiddens = document.getElementsByName("email_responsable_reservation");	
	for(i = 0; i < list_hiddens.length; i++){
		list_emails_responsable_resa += "&email_responsable_reservation_"+i+"="+document.getElementById(list_hiddens[i].id).value;
	}
	
	$.ajax({
		type: "POST",
		url: script,
		data: "action=send-seminaire-hotel&objet="+$("#objet").val()+"&nom_hotel="+$("#nom_hotel").val()+"&nom="+$("#nom").val()+"&prenom="+$("#prenom").val()+"&phone="+$("#phone").val()+"&message="+$("#message").val()+"&mail="+$("#mail").val()+"&lang="+lang+list_emails_responsable_resa,
		success: function(msg){
			//centering with css
			$("#loading_seminaire").html('&nbsp;');
			$("#loading_seminaire").css("display", "none");
			$("#msg_confirmation_seminaire").html('<b>'+msg+'</b>');
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

/**
*
*/
function saveFormulaireContactByh(lang){
	var cont = $('div.container');
	// validate the form when it is submitted
	$("#contact_hotel_form").validate({	
         submitHandler: function(form) {
             form.submit();
         },	
		errorContainer: cont,
		errorLabelContainer: $("ol", cont),
		wrapper: 'li',
		meta: "validate"	
	});		
	$('#contact_hotel_form').submit();

	/****************************************************************/
	
	var content = "";
	$("#loading_contact").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	$("#loading_contact").css("display", "block");	

	$.ajax({
		type: "POST",
		url: script,
		data: "action=send-contact-byh&objet="+$("#objet").val()+"&nom="+$("#nom").val()+"&prenom="+$("#prenom").val()+"&phone="+$("#phone").val()+"&message="+$("#message").val()+"&mail="+$("#mail").val()+"&lang="+lang,
		success: function(msg){
			//centering with css
			$("#loading_contact").html('&nbsp;');
			$("#loading_contact").css("display", "none");
			$("#msg_confirmation_contact").html('<b>'+msg+'</b>');
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}

function saveFormulaireContactEntrepriseByh(lang){
	var cont = $('div.container');
	// validate the form when it is submitted
	$("#contact_hotel_form").validate({	
         submitHandler: function(form) {
		//$("#msg_confirmation_contact").html('<b>test</b>');
           form.submit();
         },	
		errorContainer: cont,
		errorLabelContainer: $("ol", cont),
		wrapper: 'li',
		meta: "validate"	
	});	
	$('#contact_hotel_form').submit();

	/****************************************************************/
	
	var content = "";
	//$("#loading_contact").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	//$("#loading_contact").css("display", "block");	

	$.ajax({
		type: "POST",
		url: script,
		data: "action=send-contact-entreprise-byh&objet="+$("#objet").val()+"&nom="+$("#nom").val()+"&prenom="+$("#prenom").val()+"&nom_entreprise="+$("#nom_entreprise").val()+"&phone="+$("#phone").val()+"&message="+$("#message").val()+"&mail="+$("#mail").val()+"&lang="+lang,
		success: function(msg){
			//centering with css
			$("#loading_contact").html('&nbsp;');
			$("#loading_contact").css("display", "none");
			//$("#msg_confirmation_contact").html('<b>'+msg+'</b>');
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;		
}

function saveFormulaireAffiliationByh(lang){
	var cont = $('div.container');
	// validate the form when it is submitted
	$("#contact_hotel_form").validate({	
         submitHandler: function(form) {
             form.submit();
         },	
		errorContainer: cont,
		errorLabelContainer: $("ol", cont),
		wrapper: 'li',
		meta: "validate"	
	});		
	$('#contact_hotel_form').submit();

	/****************************************************************/
	
	var content = "";
	$("#loading_contact").html("<img src='http://www.book-your-hotel.com/media/images/ajax-loader-news-letter.gif' alt='Veuillez patienter pendant le traitement de votre demande' title='Veuillez patienter pendant le traitement de votre demande'  />");
	$("#loading_contact").css("display", "block");	

	$.ajax({
		type: "POST",
		url: script,
		data: "action=send-affiliation-byh&objet="+$("#objet").val()+"&nom="+$("#nom").val()+"&prenom="+$("#prenom").val()+"&phone="+$("#phone").val()+"&message="+$("#message").val()+"&mail="+$("#mail").val()+"&lang="+lang,
		success: function(msg){
			//centering with css
			$("#loading_contact").html('&nbsp;');
			$("#loading_contact").css("display", "none");
			$("#msg_confirmation_contact").html('<b>'+msg+'</b>');
		},
		error: function(msg){
		  	content = msg;
		}
	});
	//return content;
}
