// JavaScript Document

	// My DHTML micro-API, see http://www.xs4all.nl/~ppk/js/index.html?dhtmloptions.html
function getObj(name)
{
	if(document.all) return	document.all[name];
	else if(document.getElementById) {
		//alert("hola");
		if(document.getElementById(name))
			return document.getElementById(name);
		else
			return document.getElementsByName(name);
	}
	else if (document.layers) return getObjNN4(document,name);
}

function getObjNN4(obj,name)
{
	var x = obj.layers;
	var thereturn;
	for (var i=0;i<x.length;i++) {
		if (x[i].id == name) thereturn = x[i];
		else if (x[i].layers.length) var tmp = getObjNN4(x[i],name);
		if (tmp) thereturn = tmp;
	}
	return thereturn;
}
	// End mini-API

function getNewXmlHttpRequest() {
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	return xmlhttp;
}

function hideLayer(obj, e)
{
	var targ;

	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;

	if(targ==obj && !isParent(targ, e.toElement)) obj.style.visibility="hidden";
	if(isParent(e.toElement, obj)) obj.style.visibility="hidden";
//		result='';
//		for (var i in e) result += "e." + i + " = " + e[i] + "\n";
//			alert('Vengo de= ' + targ.id + '\nY su padre es=' + targ.parentElement.id + '\nVoy a= ' + e.toElement.id + '\ny su padre es=' + e.toElement.parentElement.id +'\n'+ result);
}

function isParent(possibleParent, son)
{
	var aux=son.parentElement;
	while (aux!=null && aux!=possibleParent) aux=aux.parentElement;
	return aux==possibleParent;
}

function changeButtonState(button, textColor, fondoColor)
{
	button.style.color=textColor;
	button.style.borderColor=textColor;
	button.style.backgroundColor=fondoColor;
}

function SwapImage(oImg, sPathNew)
{
	oImg.src=sPathNew;
}

function getDimensions(elm) {
	var box = { x:0, y:0, w:0, h:0 };
	if(document.getBoxObjectFor) {
		var boxRef = document.getBoxObjectFor(elm);
		box.x = boxRef.x;
		box.y = boxRef.y;
		box.w = boxRef.width;
		box.h = boxRef.height;
	}
	else if(elm.getBoundingClientRect) {
		var rxIE50 = /MSIE 5\.0/g;
		//alert(rxIE50 + '.test("' + navigator.appVersion + '" = ' + rxIE50.test(navigator.appVersion));
		var boxRef = elm.getBoundingClientRect();
		box.x = boxRef.left;
		box.y = boxRef.top;
		box.w = (boxRef.right - boxRef.left);
		box.h = (boxRef.bottom - boxRef.top);
		//var s='';for(p in boxRef) s+=p+'    '; alert(s);
		// Damn IE...
		if(document.compatMode && document.compatMode != 'BackCompat') {
			// IE6/compliance mode
			box.x += document.documentElement.scrollLeft - 2;
			box.y += document.documentElement.scrollTop - 2;
		}
		else //if(!gClientIsIE5) {
			{
			// IE5.5
			box.x += document.body.scrollLeft - 2;
			box.y += document.body.scrollTop - 2;
		}
	}
	else {
		// No known box information available, walking
		// manually through offsetParents to calculate x/y coordinates
		box.w = elm.offsetWidth;
		box.h = elm.offsetHeight;
		while(elm) {
			box.x += elm.offsetLeft;
			box.y += elm.offsetTop;
			if(elm.offsetParent) // Required for Safari 1.3 :(
				elm = elm.offsetParent;
			else
				break;
		}
	}
	var cc;
	if(cc = document.getElementById('bodyconstraint'))
		box.x -= cc.offsetLeft;
	return box;
}

/*
	SEARCH OBJECTS FUNCTIONS
*/
var wSO=null;
var iNBichos=0;

function showImg(oImg)
{
	iNBichos++;
	if(wSO!=null) {
		wSO.close();
	}
	img=new Image();
	img.src=oImg.src;
	wSO=window.open('', 'winObjetiki'+iNBichos, 'directories=no, location=no, menubar=no, scrollbars=no, status=no, toolbar=no, width=' + img.width + ', height=' + img.height);
	wSO.document.write("<html>\n<head>\n\t<title>See Image</title>\n</head>\n<body bgcolor='darkblue' leftmargin='0' topmargin='0'>\n<img src=" + oImg.src + "></img></body></html>");
}

function hideImg()
{
	if(wSO!=null) {
		wSO.close();
		wSO=null;
	}
}

function GetPageName()
{	var i,s;

	i=location.href.indexOf("lang");
	if (i>0) {
		s=location.href.substr(0,i-1);
	}
	else s=location.href;
	i=s.indexOf("?");

	if (i>0) s+="&";
	else s+="?";

	return s;
}

function MostrarFotos(sPathRuta,iImgShow,sLang) {
	/*if(wSO!=null) {0
		wSO.close();
	}*/
	var sUrl;
	if (location.href.indexOf("/naturarea/")>0) sUrl='/naturarea/MostrarImatges.php?Lang=' + sLang + '&NomRuta='+ sPathRuta + '&NumImg=' + iImgShow;
	else sUrl='/MostrarImatges.php?Lang=' + sLang + '&NomRuta='+ sPathRuta + '&NumImg=' + iImgShow;
	wSO=window.open(sUrl, 'Rutes', 'directories=no, location=no, menubar=no, scrollbars=yes, status=no, toolbar=no, width=1224,height=810,resizable=1');
}

