var divCurMonth;

var divNextMonth;

var _idHotel;

var _idRoom;

var _month;

var _year;



var months = new Array(13);

months[0]  = "January";

months[1]  = "February";

months[2]  = "March";

months[3]  = "April";

months[4]  = "May";

months[5]  = "June";

months[6]  = "July";

months[7]  = "August";

months[8]  = "September";

months[9]  = "October";

months[10] = "November";

months[11] = "December";



/** CURRENT MONTH CALENDAR */

var curSelected = new Array();

var curMin;

var curMax;



var hotel = "";

var room = "";

var externalUser = "";



var qtyRooms = 0;

var qtyNights = 0;

var subtotal = 0;

var taxes = 0;

var currentImage =0;

var roomsboxEmpty = "";



var saveURL;



var usePreviousDates = false;



var checkinStartValue = "";

var checkoutStartValue = "";



var previousReservation = null;

var modeCancel = false;







/** Initialize this module */

function initialize(idHotel,month,year){

	changeHotel(idHotel);

	_month = month;

	_year = year;

	roomsboxEmpty = Page.FindControl("roomsbox").innerHTML;

	hotel.idHotel = 0;

	room.idRoom = 0;



	checkinStartValue = Page.FindControl("spCheckinDate").innerHTML;

	checkoutStartValue = Page.FindControl("spCheckoutDate").innerHTML;



}



/** Reloads the home page */

function redirecthome(){

	window.location="index.php?module=home";

}





/** Manages image navigation for the rooms images. */

function nextImage ( ) {



	ind = currentImage+1;



	if (room && room.images){



		if ( room.images[ind] ) {

			Page.FindControl("imgRoom").src = room.images[ currentImage+1 ].filePath;

			Page.FindControl("imagedescriptionbox").innerHTML = room.images[currentImage+1].description;

			currentImage++;

		}



	}else if(hotel && hotel.images){

		if (hotel.images[ind]) {

			Page.FindControl("imgRoom").src = hotel.images[ currentImage+1 ].filePath;

			Page.FindControl("imagedescriptionbox").innerHTML = hotel.images[currentImage+1].description;

			currentImage++;

		}



	}

}



/** Manages image navigation for the rooms images. */

function previousImage ( ){



	ind = currentImage-1;



	if (room && room.images){



		if (room.images[ind]){

			Page.FindControl("imgRoom").src = room.images[ currentImage-1 ].filePath;

			Page.FindControl("imagedescriptionbox").innerHTML = room.images[currentImage-1].description;

			currentImage--;

		}



	}else if(hotel.images){



		if (hotel.images[ind]){

			Page.FindControl("imgRoom").src = hotel.images[ currentImage-1 ].filePath;

			Page.FindControl("imagedescriptionbox").innerHTML = hotel.images[currentImage-1].description;

			currentImage--;

		}



	}

}







/** selects a Credit Card*/

function selectCC(idCC){

	for (i = 0; i < document.frmHome.idGuaranteeCredCardCode.length; i++)

	{

		if ( document.frmHome.idGuaranteeCredCardCode[i].value == idCC ) {

			document.frmHome.idGuaranteeCredCardCode[i].checked = true;

		}

	}

}







/** Calls the ajax module that returns the states for the selected country*/

function changeCountry(obj){

	xmlhttpPost(

		"index.php",

		"module=ajax_getstates&idCountry="+obj.value,

		"processChangeCountry"

	);

}



/** Loads the state combobox with the data returned by the ajax_getstates module */

function processChangeCountry(res){

	eval ("options = " + res);



	objCombo = Page.FindControl("idState");

	objCombo.options.length = 0;

	for(i=0;i<options.states.length;i++){

		Combo.addOption("idState",options.states[i].idState,options.states[i].name,false);

	}

    impuestos();

    objCombo.style.width="120px";

}



function getSaveUrl(){

	var url = "";
	
	url += "&idRoom=" + _idRoom;

	url += "&curMax=" + escape(Convert.FormatDate(curMax));

	url += "&curMin=" + escape(Convert.FormatDate(curMin));

	url += "&qtyAdults=" + Page.FindControl("qtyAdults").value;

	url += "&qtyChildren=" + Page.FindControl("qtyChildren").value;

	url += "&qtyRooms=" + Page.FindControl("qtyRooms").value;



	url += "&firstName=" + escape(Page.FindControl("firstName").value);

	url += "&lastName=" + escape(Page.FindControl("lastName").value);

	url += "&streetAddress=" + escape(Page.FindControl("streetAddress").value);

	url += "&city=" + escape(Page.FindControl("city").value);

	url += "&idState=" + escape(Page.FindControl("idState").value);

	url += "&idCountry=" + escape(Page.FindControl("idCountry").value);

	url += "&zipCode=" + escape(Page.FindControl("zipCode").value);

	url += "&email=" + escape(Page.FindControl("email").value);

	url += "&phoneNumber=" + escape(Page.FindControl("phoneNumber").value);

	url += "&faxNumber=" + escape(Page.FindControl("faxNumber").value);



	for (i = 0; i < document.frmHome.idGuaranteeCredCardCode.length; i++){

		if (document.frmHome.idGuaranteeCredCardCode[i].checked){

			url += "&idGuaranteeCredCardCode=" + escape(document.frmHome.idGuaranteeCredCardCode[i].value);

		}

	}



	url += "&guaranteeName=" + escape(Page.FindControl("guaranteeName").value);

	url += "&guaranteeCredCardExpiration=" + escape(Page.FindControl("guaranteeCredCardExpiration").value);

	url += "&guaranteeCredCardNumber=" + escape(Page.FindControl("guaranteeCredCardNumber").value);

	url += "&securityCode=" + escape(Page.FindControl("securityCode").value);

	url += "&arrivalInformation=" + escape(Page.FindControl("arrivalInformation").value);

	url += "&comments=" + escape(Page.FindControl("comments").value);
    
    url += "&capcha=" + escape(Page.FindControl("capcha").value);

	url += "&price=" + subtotal;

	url += "&tax=" + taxes;

	url += "&totalPrice=" + (subtotal + taxes);


	if (externalUser.idExternalUser){

		url += "&idExternalUser=" + externalUser.idExternalUser;

	}else if (Page.FindControl("idExternalUser")){

		url += "&idExternalUser=" + Page.FindControl("idExternalUser").value;

	}



	if (Page.FindControl("idReservation").value){

		url += "&idReservation=" + Page.FindControl("idReservation").value;

	}



	saveURL = url;

	return (url);

}



function recoverConfirmationNumber(){

	Modal.Close();

	Modal.Window("index.php?module=modal_recoverconfirmation&idHotel="+_idHotel,310,150,false);

}



function findRecoverNumber(){

	var guestname = Page.FindControl("guestname");

	var ccfourdigits = Page.FindControl("ccfourdigits");



	var url = "index.php?module=modal_getreservationsbycustomer";

	url += "&guestname="+guestname.value;

	url += "&ccfourdigits="+ccfourdigits.value;

	url += "&idHotel="+_idHotel;



	Modal.Close();

	Modal.Window(url,310,158);

}



function processFindRecoverNumber(res){

	alert(res);



}



function clearInvalidFields(){

	if (!Page.FindControl("clearmail")) return;

	if (Page.FindControl("clearmail").value == "true"){

		Page.FindControl("email").value = Page.FindControl("email").LastValue;

	}



}



function selectReservationByCustomer(lastName,confirmationNumber){

	var url = "module=ajax_findreservation&lastName="+lastName+"&confirmationNumber="+confirmationNumber;



//	window.prompt("url",url);



	xmlhttpPost(

		"index.php",

		url,

		"processFindModifyReservation"

	);



	Modal.Close();

}



function showNewStyle(idHotel){

	if(Page.FindControl('noStyles').value.match(','+idHotel+',') == ','+idHotel+',')

		idHotel = Page.FindControl('defStyle').value;

	var newClass = 'hotel'+idHotel;

	setClass('pagehead',newClass);

	setClass('subheader',newClass);

	setClass('homecalendar',newClass);

	setClass('homerooms',newClass);

	setClass('homepayment',newClass);

	setClass('homeback',newClass);

	setClass('homelegend',newClass);

	setClass('homefooter',newClass);

	setClass('homefooterpromotional',newClass);

	setClass('homefooterterms',newClass);

	setClass('homefooterrequiried',newClass);

	setClass('homebutton',newClass);



	var obj = document.getElementsByClassName('homeroomsshadow-default');

	obj[0].style.background = " url(project/output/hotels/" + idHotel + "/shadows/sombra_01.gif) ";

	obj = Page.FindControl('shadow1');

	obj.src = "project/output/hotels/" + idHotel + "/shadows/sombra_01.gif";

	obj = document.getElementsByClassName('homepaymentshadow-default');

	obj[0].style.background = " url(project/output/hotels/" + idHotel + "/shadows/sombra_02.gif) ";

	obj = Page.FindControl('shadow2');

	obj.src = "project/output/hotels/" + idHotel + "/shadows/sombra_02.gif";

	obj = document.getElementsByClassName('homebackshadow-default');

	obj[0].style.background = " url(project/output/hotels/" + idHotel + "/shadows/sombra_03.gif) ";

	obj[1].style.background = " url(project/output/hotels/" + idHotel + "/shadows/sombra_03.gif) ";

	obj = Page.FindControl('shadow3');

	obj.src = "project/output/hotels/" + idHotel + "/shadows/sombra_03.gif";

	obj = Page.FindControl('shadow4');

	obj.src = "project/output/hotels/" + idHotel + "/shadows/sombra_04.gif";



	//Page.FindControl("imgDetailAvailable").src = "project/output/hotels/"+idHotel+"/calendar/detail_available.gif";

	//Page.FindControl("imgDetailSelected").src = "project/output/hotels/"+idHotel+"/calendar/detail_selected.gif";

	//Page.FindControl("imgDetailUnavailable").src = "project/output/hotels/"+idHotel+"/calendar/detail_unavailable.gif";

	//Page.FindControl("imgDetailCheckOut").src = "project/output/hotels/"+idHotel+"/calendar/detail_check-out.gif";



	//Page.FindControl("imgCalendarArrowBack").src = "project/output/hotels/"+idHotel+"/calendar/arrowback.gif";

	//Page.FindControl("imgCalendarArrowNext").src = "project/output/hotels/"+idHotel+"/calendar/arrow.gif";



	var logo = Page.FindControl('businesslogo');

	logo.src = 'project/output/hotels/'+idHotel+'/logo/logo.gif';

	classNameDefault = newClass;

}



function setClass(nameObj,clsName){

	var objs = document.getElementsByClassName(nameObj+'-'+classNameDefault);

	if(typeof(objs)=='object'){

		for(var i=0; i<objs.length; i++){

			objs[i].className = objs[i].className.replace(classNameDefault,clsName);

		}

	}else{

		objs.className = objs.className.replace(classNameDefault,clsName);

	}

}



function impuestos() {



    regionId = Page.FindControl("idRegion").options[Page.FindControl("idRegion").selectedIndex].value;	
    

    calculatePrice(); 



}
