function abuscar()
{
	var buscando=document.getElementById('busca').value;
	if (buscando!='')
		location.href="http://www.ojodepez.org/cgi/php/index.php?seccion=busca&abuscar="+buscando;
}
function borrar(inputbox)
{	
	inputbox.value='';
}
function setvalue(inputbox,palabra)
{
	if(inputbox.value==palabra)
		inputbox.value='';		
	else if(inputbox.value=='')
		inputbox.value=palabra;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

ajax=new Ajax();
function abrirVideo(id)
{
	ajax.showModalURL('odptv_visor.php?id='+id,640,500);
}

function abrirMapa(id)
{
	ajax.showModalURL('distribucion_visor.php?id='+id,540,460);
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function Ajax(){

// FUNCIONAMIENTO GENERAL (XML) /////////////////////////////////////////////

	// VARIABLES LOCALES /////////////////////

	var intentos=0;
	var self;
	var indicemodal=0;
	var indicetooltip=0;



	// VARIABLES LOCALES /////////////////////

	var label;
	var modal2Html = '';
	var tooltipTimeout;
	

	// PROPIEDADES ///////////////////////////
	
	this.hideTimeout = 2;
	this.errorTimeout = 5;


		// Ventana modal centrada
	this.showModal = function(html,estilo){
		indicemodal++;
		bgTrans();
		var idventana = '_ajax_modalcontent_'+this.id+'_'+indicemodal;
		
		if(!$(idventana))
		{
			
			var modalcontent = document.createElement('DIV');
			modalcontent.style.cssText = 'position:absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index:'+((1000*indicemodal)+1)+';';
			modalcontent.id = idventana;
			document.body.appendChild(modalcontent);
//			visionCombos('hidden');
		}
		
		$(idventana).innerHTML = '<table border="0" width="100%" height="100%" align="center"><tr><td align="center"><div class="modalstyle'+(estilo?' '+estilo:'')+'">'+html+'</div></td></tr></table>';
		document.body.style.height = '100%'
		$(idventana).style.top = getScrollY() + 'px'

		/*if(document.all)
			document.body.style.overflow = 'hidden';
		else
			window.onscroll = function(){
				if($(idventana)){
					$(idventana).style.top = getScrollY();
				}
			}*/
	}
	
	
	// Ventana modal centrada que carga un iframe con el contenido url con ancho y alto
	this.showModalURL = function(url,ancho,alto){
		this.showModal('<iframe name="frame_ajax" width="'+ancho+'" height="'+alto+'" scrolling="auto" src="'+url+'" frameborder="no"></iframe>');
	}	
	
	

	// Ocultar ventanas modales
	this.hideModal = function(){
		visionCombos('visible');
		
		if($('_ajax_modal2_'+this.id+'_'+indicemodal)){
			document.body.removeChild($('_ajax_modal2_'+this.id+'_'+indicemodal));
			document.body.removeChild($('_ajax_trans_'+this.id+'_'+indicemodal));
			indicemodal--;
		}else if($('_ajax_modalcontent_'+this.id+'_'+indicemodal)){
			document.body.removeChild($('_ajax_modalcontent_'+this.id+'_'+indicemodal));
			document.body.removeChild($('_ajax_trans_'+this.id+'_'+indicemodal));
			indicemodal--;
		}

		if(indicemodal>0 && $('_ajax_modalcontent_'+this.id+'_'+indicemodal))
			$('_ajax_modalcontent_'+this.id+'_'+indicemodal).style.top = getScrollY();
	}

	



	// FUNCIONES PRIVATE ///////////////////////

	/*function crearEtiqueta(){
		if($('_ajax_label'))
			label = $('_ajax_label');
		else{
			label = document.createElement('SPAN');
			label.style.cssText = 'position: absolute; right:0px; padding: 2px 20px 2px 20px; font-family: arial; font-size: 13px; font-weight: bold; z-index:'+((1000*indicemodal)+2);
			
			label.id = '_ajax_label';
			document.body.appendChild(label);
		}

		label.style.top = getScrollY()+'px';
	}


	function modal2mover(){	
		var modal = $('_ajax_modal2_'+self.id+'_'+indicemodal);
		
		if (modal.style.left!='30px'){
			modal.style.left = parseInt(modal.style.left.replace('px','')) + 5 + 'px';
			setTimeout(function(){modal2mover();},1);
		} 
		else {
			setTimeout('document.getElementById(\'_ajax_modal2_'+self.id+'_'+indicemodal+'\').style.background="#FF850D"',100);
			setTimeout('document.getElementById(\'_ajax_modal2_'+self.id+'_'+indicemodal+'\').style.background="#FFF"',200);
			setTimeout('document.getElementById(\'_ajax_modal2_'+self.id+'_'+indicemodal+'\').style.background="#FF850D"',300);
			setTimeout('document.getElementById(\'_ajax_modal2_'+self.id+'_'+indicemodal+'\').style.background="#FFF"',400);
			setTimeout('document.getElementById(\'_ajax_modal2_'+self.id+'_'+indicemodal+'\').style.background="#FF850D"',500);
			setTimeout('document.getElementById(\'_ajax_modal2_'+self.id+'_'+indicemodal+'\').style.background="#FFF"',600);
			setTimeout(function(){modal2resize();},700);
		}
	}

	function modal2resize(){
		var modal = $('_ajax_modal2_'+self.id+'_'+indicemodal);

		if (modal.style.width!=415+'px'){
			modal.style.width = parseInt(modal.style.width.replace('px','')) + 40 + 'px';
			modal.style.height = parseInt(modal.style.height.replace('px','')) + 10 + 'px';
			setTimeout(function(){modal2resize();},20);
		}
		else{
			modal.style.background= 'url(http://www.facilisimo.com/mensajes/expocasa/images/logo.gif) no-repeat top center #FFF';
			modal.style.height = 'auto';
			modal.innerHTML = '<div style="margin: 50px 0 15px 0; text-align: center;">'+modal2Html+'</p>';
		}
	}
*/

	function bgTrans(){
		if(!$('_ajax_trans_'+self.id+'_'+indicemodal))
		{
			var modal = document.createElement('DIV');
			if(document.all)
				modal.style.filter = 'Alpha(Opacity=65)';
			else
				modal.style.MozOpacity='0.65';
			
				/*
				modal.style.backgroundColor = 'transparent'; 
				modal.style.backgroundImage = 'url(/images/px.gif)';
				modal.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader (src="/images/px.png", sizingMethod="scale")';
				*/

				/* modal.style.backgroundImage = 'url(/images/px.png)'; */
			
			//modal.style.backgroundColor = self.transBgColor;
			modal.style.position = 'absolute';
			modal.style.height = (document.body.scrollHeight?document.body.scrollHeight:document.documentElement.scrollHeight)+'px';
			modal.style.top = '0px';
			modal.style.left = '0px';
			modal.style.zIndex = 1000*indicemodal;
			modal.style.width = '100%';
			modal.className = 'ajax_trans';
			modal.id = '_ajax_trans_'+self.id+'_'+indicemodal;

			document.body.appendChild(modal);
			visionCombos('hidden');
		}
	}
/*
	function fadeIn(ventana,opacidad){
		if(document.all)
			ventana.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+opacidad+')';
		else{
			if(opacidad>=100)
				ventana.style.MozOpacity='1.00';
			else
				ventana.style.MozOpacity='.'+opacidad;
		}
		
		if(opacidad<100)
			if(document.all)
				setTimeout(function(){fadeIn(ventana,opacidad+10)},1);
			else
				setTimeout(function(){fadeIn(ventana,opacidad+25)},1);
	}
	
	function fadeOut(ventana,opacidad){
		if(document.all)
			ventana.style.filter='progid:DXImageTransform.Microsoft.Alpha(opacity='+opacidad+')';
		else
			ventana.style.MozOpacity='.'+opacidad;

		if(opacidad>0)
			if(document.all)
				setTimeout(function(){fadeOut(ventana,opacidad-10)},1);
			else
				setTimeout(function(){fadeOut(ventana,opacidad-25)},1);
		else
			self.hideModal();
	}*/

	function visionCombos(opcion){
		if(document.all){
			if(indicemodal<=1)
				var arr = document.getElementsByTagName('select');
			else
				if($('_ajax_modal2_'+self.id+'_'+(indicemodal-1)))
					var arr = $('_ajax_modal2_'+self.id+'_'+(indicemodal-1)).getElementsByTagName('select');
				else
					if($('_ajax_modalcontent_'+self.id+'_'+(indicemodal-1)))
						var arr = $('_ajax_modalcontent_'+self.id+'_'+(indicemodal-1)).getElementsByTagName('select');

			for(i = 0; i < arr.length; i++)
				arr[i].style.visibility = opcion;
				
		}

		// También para flash
		if(document.all)
			var arr = document.getElementsByTagName('object');
		else
			var arr = document.getElementsByTagName('embed');
		
		for(i = 0; i < arr.length; i++)
			arr[i].style.visibility = opcion;
	}

	
	function getScrollY(){
		var scrollY = 0;
		
		if ( document.documentElement && document.documentElement.scrollTop )		{
			scrollY = document.documentElement.scrollTop;
		}else if ( document.body && document.body.scrollTop ){
			scrollY = document.body.scrollTop;
		}else if ( window.pageYOffset ){
			scrollY = window.pageYOffset;
		}else if ( window.scrollY ){
			scrollY = window.scrollY;
		}
		
		return scrollY;
	}
	
	function $(id){return document.getElementById(id);}

	// Necesario para poder instanciar la clase en el onreadystatechange
	self = this;
}
