// CAMBIA EL COLOR DE FONDO Y BORDE EL OBJETO SELECCIONADO
// EJEMPLO: onmouseover(this); onmouseout(this); 
function rOver(object){ 
	fondo_old = object.style.background; 
	object.style.background = '#f0f0f0'; 
}
function rOut(object) { 
	object.style.background = fondo_old; 
}


function popup_redimensionar() {
	ancho =  document.getElementById('popup_redimensionar').offsetWidth;
	alto =  document.getElementById('popup_redimensionar').offsetHeight;
	if(ancho >= screen.width){ ancho = screen.width; }
	if(alto >= screen.height){ alto = screen.height; }
	top.resizeTo(ancho,alto);
	window.resizeBy(24,47);
	// Centrando Ventana
	iz=(screen.width-document.body.clientWidth) / 2; 
	de=(screen.height-document.body.clientHeight) / 2; 
	moveTo(iz,de);
}
	


function popup(url,ancho,alto) { 
	// Abre una ventana y la centra
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-ancho)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alto)/2 : 0;
	settings = 'height='+alto+',width='+ancho+',top='+TopPosition+',left='+LeftPosition+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,dependent=0,channelmode=0';
	win = window.open(url,'',settings);
	//window.open(url , "" , "width="+ancho+",height="+alto+",toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=1,copyhistory=0,dependent=0,channelmode=0"); 
}



function button_op(form,op){
	eval("document."+form+".op.value=op");
	eval("document."+form+".submit()");
}



// Busca un valor en un array
Array.prototype.in_array = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}





// --------------------------------------------------------------------------------------------------------------------
// --- Muestra ventanitas tooltip
// --------------------------------------------------------------------------------------------------------------------
var tooltipID = function(){
	// --- Esta funcion muestra el contenido de un div en un tooltip
	return{
		show:function(div_id){
			contenido = document.getElementById(div_id).innerHTML;
			tooltip.show(contenido);
		},
		hide:function(){
			tooltip.hide();
			
		}
	
	};	
}();


var tooltip=function(){
	// --- Esta funcion muestra un ToolTip
	// --- Forma de usar:
	// --- onmouseover="tooltip.show('texto');"  onmouseover="tooltip.hide();"
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 500;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();




// ------------------------------------------------------------------------------------------
// --- DIV EMERJENTES AL LADO DE UN OBJETO PULSADO
// ------------------------------------------------------------------------------------------

	function div_menu(obj_boton,div_id,direccion){
		// --- Muestra un DIV con respecto al objeto pulsado
		pos_boton = findPos(obj_boton);	// --- Array con x,y,width,height
		
		//alert(pos_boton[0]+' - '+pos_boton[1]+' | '+pos_boton[2]+'x'+pos_boton[3]);
		obj_div = document.getElementById(div_id);
		obj_div.style.position = 'absolute';
		obj_div.style.display =  'block';		
		
		pos_div = findPos(obj_div);
		//alert(pos_div[0]+' - '+pos_div[1]+' | '+pos_div[2]+'x'+pos_div[3]);


		if(direccion == 1){	// -- arriba, derecha
			obj_div.style.left = pos_boton[0];
			obj_div.style.top = pos_boton[1]-pos_div[3];
		}else if(direccion == 2){	// -- arriba, izquierda
			obj_div.style.left = pos_boton[0]+pos_boton[2]-pos_div[2];
			obj_div.style.top = pos_boton[1]-pos_div[3];
		}else if(direccion == 3){	// -- derecha, abajo
			obj_div.style.left = (pos_boton[0]+pos_boton[2]);
			obj_div.style.top = pos_boton[1];			
		}else if(direccion == 4){	// -- derecha, arriba
			obj_div.style.left = (pos_boton[0]+pos_boton[2]);
			obj_div.style.top = pos_boton[1]+pos_boton[3]-pos_div[3];
		}else if(direccion == 5){	// -- abajo, derecha
			obj_div.style.left = pos_boton[0];
			obj_div.style.top = pos_boton[1]+pos_boton[3];			
		}else if(direccion == 6){	// -- abajo, izquierda
			obj_div.style.left = (pos_boton[0]+pos_boton[2]-pos_div[2]);
			obj_div.style.top = pos_boton[1]+pos_boton[3];
		}else if(direccion == 7){	// -- izquierda, abajo
			obj_div.style.left = (pos_boton[0]-pos_div[2]);
			obj_div.style.top = pos_boton[1];
		}else if(direccion == 8){	// -- izquierda, arriba
			obj_div.style.left = (pos_boton[0]-pos_div[2]);
			obj_div.style.top = pos_boton[1]+pos_boton[3]-pos_div[3];
		}else{
			// --- Por defecto es el 3
			obj_div.style.left = (pos_boton[0]+pos_boton[2]);
			obj_div.style.top = pos_boton[1];	
		}
	}
	
	function div_menu_close(div_id){
		obj_div = document.getElementById(div_id);
		obj_div.style.display =  'none';
	}


	function findPos(obj){
		// --- Devuelve un array con la posicion y tamaņo de un objeto en el navegador
		// --- x,y,width,height
		var curleft = curtop = obj_width = obj_height = 0;
		obj_width = obj.offsetWidth;
		obj_height = obj.offsetHeight;
		
		if (document.getElementById || document.all){
			while (obj.offsetParent){
				curtop += obj.offsetTop
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}else if(document.layers){
			curleft += obj.x;
			curtop += obj.y;
			
		}
	 	return [curleft,curtop,obj_width,obj_height];
	}