function getCalendar(idioma){
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("span"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		
		if (anchor.className == "calendar" || anchor.className == "calendarBirth")  {

			anchor.innerHTML = "";
			
			var calendarImg = document.createElement("img");
			calendarImg.setAttribute("src","/images/calendar.jpg");
			calendarImg.setAttribute("alt","");
			anchor.appendChild(calendarImg);

			if(!document.getElementById("calendarDiv")){
				calendarDiv = document.createElement("div");
				calendarDiv.setAttribute("id","calendarDiv");
				calendarDiv.style.position="absolute";
				calendarDiv.style.background="#ffffff";
				anchor.parentNode.parentNode.appendChild(calendarDiv);
			}

			calendarTextField = anchor.previousSibling;
			if(calendarTextField.id == null){
				calendarTextField = calendarTextField.previousSibling;
			}
			
			calendarTextField.readOnly = true;
			anchor.onclick = function() {
				calendarTextField = this.previousSibling;
				if(calendarTextField.id == null){
					calendarTextField = calendarTextField.previousSibling;
				}
				var calendar = new CalendarPopup("calendarDiv", idioma);
				//calendar.showNavigationDropdowns();
				if(this.className == "calendar"){
					calendar.setYearSelectStartOffset(0);
				}
				if(this.className == "calendarBirth"){
					calendar.setYearSelectStartOffset(80);
				}
				if(idioma == 'es'){
					if(document.getElementById("DateIn_es") && calendarTextField.id == "DateOut_es")
						calendar.addDisabledDates(null, switchDate(document.getElementById("DateIn_es").value));					

					calendar.select(calendarTextField.id, 'dd-MM-yyyy');
				} else {
					if(document.getElementById("DateIn_en") && calendarTextField.id == "DateOut_en")
						calendar.addDisabledDates(null, document.getElementById("DateIn_en").value);					
					
					calendar.select(calendarTextField.id, 'MM-dd-yyyy');
				}
				
				if (document.getElementById('Adults')) {
					document.getElementById('Adults').style.display = "none";
				}
				if (document.getElementById('Length')) {
					document.getElementById('Length').style.display = "none";
				}
				if (document.getElementById('Children')) {
					document.getElementById('Children').style.display = "none";
				}
				
			}
		}		
	} 
}

function switchDate(val){
	var solution = val.split("-");
	return solution[1]+"-"+solution[0]+"-"+solution[2];	
}

function clickBack() {
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.className == "linkback")  {
		   //var newDestiny = eval(history.back())
			anchor.onclick = goBack;
		}		
	} 
} 

function goBack() {
		history.back();
		return false;
}


function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
	} 
} 

function getThumbnailImages() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.className == "thumbnail")  {
			anchor.onclick = changeImage;   
		}		
	} 
} 

function changeImage() {
	var actualImage = document.getElementById('image-holder');
	var actualSliceImage = (actualImage.src).split("/");
	
	var newThumbnail = actualSliceImage[0]+"//"+actualSliceImage[2]+"/"+actualSliceImage[3]+"/"+actualSliceImage[4]+"/"+actualSliceImage[5]+"/thumb_"+actualSliceImage[6];

	var newImage = this.firstChild.src;
	var newImage = this.href;
	//this.href = actualImage.src;
	//alert(this.title);
	//document.getElementById('imagen-principal-txt').innerHTML = this.title;
	//this.firstChild.src = newThumbnail;
	actualImage.src = newImage;
	newLink = newImage.replace("mid_", "");
	actualImage.parentNode.href = newLink;

	//location.href= "#image-holder";
	return false;
}

function swapSearch() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("strong"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.className == "triggerDrop")  {
			anchor.parentNode.nextSibling.style.display = "none";
			anchor.style.cursor = "pointer";
			anchor.onclick = function() {
				if (anchor.parentNode.nextSibling.style.display == "none") {
					anchor.parentNode.nextSibling.style.display = "block";   
				} else {
					anchor.parentNode.nextSibling.style.display = "none";   
				} // end if
			} // end function
		}		
	} 
} 

function checkIconCalendar() {
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("img"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.className == "openCalendar")  {
		   //var newDestiny = eval(history.back())
			anchor.style.cursor = "pointer";
			anchor.previousSibling.readOnly = true;
			anchor.nextSibling.style.display = "none";
			anchor.onclick = launchCalendar;
		}		
	} 
}

function launchCalendar() {
	var Destination = this.previousSibling.id;
	var iLang = this.lang;
	CreateCal(Destination, iLang);
}
var iWindow = null;

function CreateCal(Destination, iLang) {
	var arTranslation = [
		["x"],
		[ "Solo un calendario a la vez."], 
		[ "Only one calender opens at a time."], 
		[ "---"]
	];
	if(iWindow != null){
		if(iWindow.closed){
			iWindow = window.open("/includes/calendar.php?casilla="+Destination, "", "menubar='no',resize='no',status=no,width=250,height=215, dependent=yes");
		} else {
			window.alert(arTranslation[iLang]);
		}
	} else {
		iWindow = window.open("/includes/calendar.php?casilla="+Destination, "", "menubar='no',resize='no',status=no,width=250,height=215, dependent=yes");
	}
}

function checkMooTrigger() {
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("h6"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.className == "trigger")  {
		   //var newDestiny = eval(history.back())
			anchor.style.cursor = "pointer";
			anchor.title = "Pinche para desplegar los contenidos";
			anchor.innerHTML = anchor.innerHTML+" <span class='indicador'>[ + más ]</span>";
			anchor.onclick = function() {
				if (this.nextSibling.nodeName.toLowerCase() == "div") {
					Origen = this.nextSibling;
				} else {
					Origen = this.nextSibling.nextSibling;
				} // end if
				toggleTrigger = this.id;
				foo = toggleTrigger.split("-");
				//textoInterior = Origen.innerHTML;
				//textoInteriorMod = textoInterior+"<p id='algo"+foo[0]+"'><a href='#"+toggleTrigger+"' onclick='"+foo[0]+".toggle(); return true;'>&#094; Subir</a></p>";
				//if (!document.getElementById("algo"+foo[0])) {
				//	Origen.innerHTML = textoInteriorMod;
				//}
				eval(foo[0]).toggle();
			}
		}		
	} 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("h5"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.className == "trigger")  {
		   //var newDestiny = eval(history.back())
			anchor.style.cursor = "pointer";
			anchor.title = "Pinche para desplegar los contenidos";
			anchor.innerHTML = anchor.innerHTML+" <span class='indicador'>[ + más ]</span>";
			anchor.onclick = function() {
				if (this.nextSibling.nodeName.toLowerCase() == "div") {
					Origen = this.nextSibling;
				} else {
					Origen = this.nextSibling.nextSibling;
				} // end if
				toggleTrigger = this.id;
				foo = toggleTrigger.split("-");
				textoInterior = Origen.innerHTML;
				textoInteriorMod = textoInterior+"<p id='algo"+foo[0]+"'><a href='#"+toggleTrigger+"' onclick='"+foo[0]+".toggle(); return true;'>&#094; Subir</a></p>";
				if (!document.getElementById("algo"+foo[0])) {
					Origen.innerHTML = textoInteriorMod;
				}
				eval(foo[0]).toggle();
			}
		}		
	} 
}

function activateMenuHover() {
	if (!document.getElementsByTagName) return; 
	var menuContainer = document.getElementById('menu');
	var anchors = menuContainer.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		anchor.onmouseover = showMenuImage;
		anchor.onmouseout = hideMenuImage;
	}
}

function showMenuImage() {
	if (this.childNodes[1]) {
		if (this.childNodes[1].nodeName == "SPAN") {
			this.childNodes[1].className = "hover";
		}
	}
}

function hideMenuImage() {
	if (this.childNodes[1]) {
		if (this.childNodes[1].nodeName == "SPAN") {
			this.childNodes[1].className = "";
		}
	}
}

function loadFlash(){
}

window.onload = function() {
	loadFlash();
	clickBack();
	externalLinks();
	getThumbnailImages();
	//getCalendar();
	activateMenuHover();

//swapSearch();

}
/*
function itravelformchange () {
	var itravel = document.getElementById("itravel");
	var ihotelier = document.getElementById("ihotelier");
       itravel.style.display = "inline";
       ihotelier.style.display = "none"; 	
}
	
function ihotelierformchange () {
	var ihotelier = document.getElementById("ihotelier");
		var itravel = document.getElementById("itravel");
       ihotelier.style.display = "inline";
       itravel.style.display = "none"; 	
       
	 
} */
function ihotelierformchange () {
 		document.getElementById("switch").submit();
	}
function itravelformchange (){
		document.getElementById("switch").submit();
	}
function itravelhotel_code () {
	    var itravelform = document.getElementById("Reservas");
		select_option = itravelform.area2;
		prop_id = select_option.selectedIndex;
		if (prop_id == 0) {
			itravelform.hotel_code.value = "WV|WV13824";
			itravelform.track.value = "3846";
		}
		else if (prop_id == 1) {	
			itravelform.hotel_code.value = "WV|WV13825";
			itravelform.track.value = "3847";		
		}
		else if (prop_id == 2) {
			itravelform.hotel_code.value = "WV|WV15015";
			itravelform.track.value = "3848";						
		}
}
function showChildren () 
{
			if(!document.getElementById("Children"))
				numChildren = 0;
			else
	            numChildren = document.getElementById("Children").value;

            if (numChildren == 0) {
                        document.getElementById("childId1").style.display = "none";
                        document.getElementById("childId2").style.display = "none";
                        document.getElementById("childId3").style.display = "none";
            } 
            else
			{    for (i = numChildren; i <= 3; i++) {
					if (i > 0) {
						child_id = "childId" + i;
						document.getElementById(child_id).style.display = "none";
					}
					
				}
					// show children
				for (i=1; i<=numChildren; i++) {
		       		child_id = "childId" + i;
			   		document.getElementById(child_id).style.display = "block";
				}
    		}
}
function getHotelsRequest(id_city,lang){
	var list_hotels = document.getElementById("HotelID");

	var strParams = 'function=getHotels';

	try {
		strParams += '&GeoID_6='+id_city+"&lang="+lang;
	} catch(e){
	}

	var url = '/includes/functions.ajax.php';
	var loader1 = new net.ContentLoader(url,getHotelsResponse,null, "POST", strParams);
}
function getHotelsResponse(){

	var texto = this.req.responseText;
	var elem = document.getElementById("hotels");
	elem.innerHTML = texto;
	
}
