function showForm(target) {
	document.getElementById(target).style.display = "block";
}

function getCalendar(){
	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="relative";
				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");
				calendar.showNavigationDropdowns();
				if(this.className == "calendar"){
					calendar.setYearSelectStartOffset(0);
				}
				if(this.className == "calendarBirth"){
					calendar.setYearSelectStartOffset(80);
				}
				calendar.select(calendarTextField.id, 'dd-MM-yyyy');
				
			}
		}		
	} 
}

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 getImageHolder() { 
	try{
		anchor = document.getElementById("image-holder")
		anchor.onload = showMooEffect;   
	} catch(e){
	}
} 

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.style.opacity = 0.2;
			anchor.style.filter = "alpha(opacity=20)";
			anchor.onmouseover = function() {
				this.style.opacity = 1;
				this.style.filter = "alpha(opacity=100)";
			}
			anchor.onmouseout = function() {
				this.style.opacity = 0.2;
				this.style.filter = "alpha(opacity=20)";
			}
			anchor.onclick = doToggle;   
		}		
	}
	getImageHolder();
} 

function doToggle() {

	showPicture.toggle();

	objeto = this;
	setTimeout('changeImage(objeto)', 350);
	showPicture.toggle();

	return false;
}

function changeImage(objeto){
	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 = objeto.href;
	
	oldImage = actualImage.src;
	actualImage.src = newImage;
	newLink = newImage.replace("slideshow_", "");
	newLink = newImage.replace("slideshow/", "");
	actualImage.parentNode.href = newLink;
	//setTimeout('showMooEffect()', 500);

}

function showMooEffect(){
	if(hecho == 1){
		if(showPicture != null){
			showPicture.hide();
			showPicture.toggle();
		}
	}
	hecho = 1;
}

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 checkMooTrigger() {
	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();
			}
		}		
	} 
	var anchors = document.getElementsByTagName("h6"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor2 = anchors[i]; 
		if (anchor2.className == "trigger")  {
		   //var newDestiny = eval(history.back())
			anchor2.style.cursor = "pointer";
			anchor2.title = "Pinche para desplegar los contenidos";
			anchor2.onclick = function() {
				toggleTrigger = this.id;
				foo = toggleTrigger.split("-");
				eval(foo[0]).toggle();
			}
		}		
	} 
}

function addDOMLoadEvent(func){if(!window.__load_events){var init=function(){if(arguments.callee.done)return;arguments.callee.done=true;if(window.__load_timer){clearInterval(window.__load_timer);window.__load_timer=null}for(var i=0;i<window.__load_events.length;i++){window.__load_events[i]()}window.__load_events=null};if(document.addEventListener){document.addEventListener("DOMContentLoaded",init,false)}/*@cc_on @*//*@if (@_win32) document.write("<scr"+"ipt id=__ie_onload defer src=javascript:void(0)><\/scr"+"ipt>");var script=document.getElementById("__ie_onload");script.onreadystatechange=function(){if(this.readyState=="complete"){init()}};/*@end @*/if(/WebKit/i.test(navigator.userAgent)){window.__load_timer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){init()}},10)}window.onload=init;window.__load_events=[]}window.__load_events.push(func)}

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 loadFlash(){
}

window.onload = function() {
	loadFlash();
	clickBack();
	externalLinks();
	getThumbnailImages();
	muestraEstado();
	getCalendar();
	//swapSearch();
}
