
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}

// Pone opacidad a un elemento
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

// Efecto fadeIn
function fadeIn(objId,opacity,time) {
   obj = el(objId);
   if (opacity <= 100) {
     setOpacity(obj, opacity);
     opacity += 10;
     window.setTimeout("fadeIn('"+objId+"',"+opacity+","+time+")", time);
   }
}

// Efecto fadeOut
function fadeOut(objId,opacity,time) {
   obj = el(objId);
   if (opacity >= 0) {
     setOpacity(obj, opacity);
     opacity -= 20;
     window.setTimeout("fadeOut('"+objId+"',"+opacity+","+time+")", time);
   }
}

// Busca un valor dentro de un array, sino devuelve el valor por defecto
function getValorInArray(arr, obj, def) {
	str = arr[obj];
	if (str == null) {
		str = def;
	}
	return str;
}

// Abre una ventana
function openWindow(url,name,w,h) {
	var altura = screen.height;
	var anchura = screen.width;
	var vent_x = w;
	var vent_y = h;	
	var posx2 = Math.round(anchura/2-(vent_x/2));
	var posy2 = Math.round(altura/2-(vent_y/2)) - 60;

	newWindow = window.open(url,name,'resizable=0,scrollbars=0,status=0,location=0,toolbar=0,menubar=0,width='+vent_x+',height='+vent_y+',screenX='+posx2+',screenY='+posy2+',left='+posx2+',top='+posy2+'');
	newWindow.focus();
}

function openWindowModal(url,name,w,h){
	if (document.all&&window.print) { //if ie5
		eval('window.showModelessDialog(url,"'+name+'","help:0;resizable:1;dialogWidth:'+w+'px;dialogHeight:'+h+'px")')
	} else {
		eval('window.open(url,"'+name+'","width='+w+'px,height='+h+'px,resizable=1,scrollbars=1")')
	}
}

// Obtiene un elemento a partir del id
function el(id) {
  if (document.getElementById) {
    return document.getElementById(id);
  } else if (window[id]) {
    return window[id];
  }
  return null;
}

var idDisplay = '';
function switchDisplay(id) {
	//if (idDisplay != '') changeDisplay(idDisplay, 'none');
	if (el(id).style.display == 'none') {
		el(id).style.display = '';
	} else {
		el(id).style.display = 'none';
	}
	//idDisplay = id;
}

function changeDisplay(id, q) {
	if (el(id) != null) {
		el(id).style.display = q;
	}
}

function mouseOver(msg) {
	self.status=msg;
}

function mouseOut() {
	// Se podria poner un mensaje por defecto
	self.status="";
}

function findPos(obj) {
	var vueltas = 0;
	var curleft = curtop = 0;
	if ((obj != null) && (obj.offsetParent)) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while ((obj = obj.offsetParent) && (vueltas < 200)) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			vueltas++;
		}
	}
	return [curleft,curtop];
}

function makePopup(url, width, height, overflow) {
	// || !/^(scroll|resize|both)$/.test(overflow)
	if (overflow == '') {
		overflow = 'both';
	}
	//alert(overflow);
	//alert((/^(scroll|both)$/.test(overflow) ? 'yes' : 'no'));
	//alert((/^(resize|both)$/.test(overflow) ? 'yes' : 'no'));
	var win = window.open(url, '',
		'width=' + width + ',height=' + height
		+ ',scrollbars=' + (/^(scroll|both)$/.test(overflow) ? 'yes' : 'no')
		+ ',resizable=' + (/^(resize|both)$/.test(overflow) ?	'yes' : 'no')
		+ ',status=yes,toolbar=no,menubar=no,location=no'
	);
	return win;
}

function anularBotonDerecho(e) {
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)){
		alert('Botón derecho inhabilitado')
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2)){
		alert('Botón derecho inhabilitado')
	}
}
//document.onmousedown=anularBotonDerecho

// Pone un mensaje en el status
function showStatus(sMsg) {
    window.status = sMsg ;
    return true ;
}

// Obtiene el width de un elemento
function widthElement(ta) {
  var w = ta.offsetWidth;
  return w;
}

// Obtiene el width del documento
function widthDocument() {
  var iw;
  if (window.innerWidth == null) {
    iw = document.body.clientWidth;
  }else {
    iw = window.innerWidth;
  }
  return iw;
}

// Obtiene el height del documento
function heightDocument() {
  var ih;
  if (window.innerHeight == null) {
    ih = document.body.clientHeight;
  }else {
    ih = window.innerHeight;
  }
  return ih;
}

// Añade una funcion a un evento
function addLoadEvent(func, event) {
  
   if (typeof func != 'function') {
   	eval("func = function() { "+func+"();}");
   }
   
   var type = eval('typeof window.'+event);
   if (type != 'function') {
      eval('window.'+event+' = '+func+';');
   } else {
	   var oldevent = eval('window.'+event);
      eval('window.'+event+' = function() { oldevent(); func(); }');
   }
   
}

/*
addEvent function found at http://www.scottandrew.com/weblog/articles/cbs-events
*/
function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

/*
createElement function found at http://simon.incutio.com/archive/2003/06/15/javascriptWithXML
*/
function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

function insertTop(obj) {
	// Create the two div elements needed for the top of the box
	d=createElement("div");
	d.className="bt"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.insertBefore(d,obj.firstChild);
}

function insertBottom(obj) {
	// Create the two div elements needed for the bottom of the box
	d=createElement("div");
	d.className="bb"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
	obj.appendChild(d);
}

// Cambiar todos los rel external para abrir en una nueva ventana 
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";
 }
}

// returns amount of vertical scroll
function getScrollY() {
	var scroll_y = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		scroll_y = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scroll_y = document.body.scrollTop; 
	else if (window.pageYOffset)
		scroll_y = window.pageYOffset;
	else if (window.scrollY)
		scroll_y = window.scrollY;
	return scroll_y;
}

// returns amount of horizontal scroll
function getScrollX() {
	var scroll_x = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		scroll_x = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scroll_x = document.body.scrollLeft; 
	else if (window.pageXOffset)
		scroll_x = window.pageXOffset;
	else if (window.scrollX)
		scroll_x = window.scrollX;
	return scroll_x;
}

// functions to get page coordinates of mouse event
function getMouseX(evt) {
	return (evt.pageX)? evt.pageX: evt.clientX + getScrollX();
}

function getMouseY(evt) {
	return (evt.pageY)? evt.pageY: evt.clientY + getScrollY();
}
