function Trim(Cadena)
{
	var Devuelta,Encontrada,Espacios;
	Devuelta = '';
	Espacios = '';
	Encontrada = 0;
	Cadena = String(Cadena);
	for(var cont=0;cont<Cadena.length;cont++)
	{
		if (Encontrada==1)
		{
			if(Cadena.charAt(cont)!=' ')
			{
				Devuelta = Devuelta + Espacios + Cadena.charAt(cont);
				Espacios = '';
			}
			else
			{
				Espacios = Espacios + ' ';
			}
		}
		else if(Cadena.charAt(cont)!=' ')
		{
			Devuelta = Cadena.charAt(cont);
			Encontrada = 1;
		}
	}
	return Devuelta;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function ObtenerIDOperacion()
{
	var ahora=new Date();
	return (ahora.getMilliseconds()+ahora.getSeconds()*1000+ahora.getMinutes()*60*1000+ahora.getHours()*24*60*1000);
}

	function Pasa(o)
	{
		o.style.color="#EEEE00"
	}	
	function Pincha(o)
	{
		o.style.color="#FFFFFF"
	}
	function IrContenido(url,parametros)
	{
		if(parametros!=null)
		{
			if(parametros!='')
			{
				document.form.action="frames.asp?" + parametros;
			}
			else
			{
				document.form.action="frames.asp";
			}
		}
		else
		{
			document.form.action="frames.asp";
		}
		
		document.form.cont.value=url;
		document.form.submit();	
	}

	function EjecutarAccion(Accion, Parametros)
	{
	  //alert ("ejecutar accion: "+Accion+"-"+Parametros+"-");
		document.form.Accion.value=Accion;
		document.form.Parametros.value=Parametros;
		//alert ("ejecutar accion: "+document.form.Accion.value+"$"+document.form.Parametros.value+"$");
		document.form.submit();	
	}
	
  
  
//**********PARA INICIALIZAR LOS MENUS DIV AL CARGAR LA PAGE*********
	function inicio() 
	{
		invisibleIt();
		
		//if ((document.form.OpcionMenuPinchado.value!='') && (document.form.OpcionMenuPinchado.value!='undefined'))
		//{
		//	VisibleIt(document.form.OpcionMenuPinchado.value);
		//}	
		
		if (document.layers) 
		{
	       document.captureEvents(Event.MOUSEMOVE); 
	    }
	    document.onmousemove = cliqui;
	}
//*******************************************************************
	
//************FUNCIONES MENU EMERGENTE DIV************************
	var activomenu;
	var activomenuhijos;
	var desplegado;
	var menuvisto;
	var menuvistohijos;
	DHTML_IE = false;
	DHTML_NS = false;
	DHTML_W3C = false;
	
	if (document.all)
	{ 
		DHTML_IE = true;
	}
	else
	{
		if (document.layers) 
		{ 
			DHTML_NS = true;
		}
		else 
		{
			if (document.getElementById) 
			{ 
				DHTML_W3C = true;
			}
		}
	}
	
	menuvisto = false;
	menuvistohijos = false;
	desplegado = false;
	
	function cliqui(e) 
	{
		if (DHTML_W3C) 
		{
		 	id = e.target.id;
		 	if (id) 
		 	{
		 		if (id.charAt(0) == "h") 
				{
					menuvistohijos = true;
				}
				else 
				{
					if (menuvistohijos)
					{
						OcultarTodoHijos();				
					}	
				}
				if (id.charAt(0) == "m") 
				{
					menuvisto = true;
				}
				else 
				{
					if ((menuvisto) && (activomenuhijos==null)) 
					{
						OcultarTodo();				
					}	
				}
			}
		}
		if (DHTML_IE) 
		{
		 	id = event.srcElement.id;
		 	if (id.charAt(0) == "h") 
			{
				menuvistohijos = true
			}
			else 
			{
				if (menuvistohijos)
				{
					OcultarTodohijos();				
				}	
			}
			if (id.charAt(0) == "m") 
			{
				menuvisto = true
			}
			else 
			{
				if ((menuvisto) && (activomenuhijos==null))
				{
					OcultarTodo();				
				}	
			}
		}
		if (DHTML_NS) 
		{
	   		if (e.x == e.pageX) 
	   		{
	   			if (desplegado) 
	   			{ 
	   				OcultarTodo();
	   				desplegado = false;
	   			}
	   		}
	   		else 
	   		{
	   			desplegado = true;
	   		}
	   }
	}

	function OcultarTodo() 
	{
		OcultarTodohijos();
		menuvisto = false;
		if (activomenu !=null) 
		{
			if (DHTML_W3C) {
				eval("document.getElementById('m" + activomenu + "').style.visibility = 'hidden'");
				activomenu = null;		
			}
			if (DHTML_IE) {
				eval("document.all['m" + activomenu + "'].style.visibility = 'hidden'");
				activomenu = null;
			}
			if (DHTML_NS) {
				eval("document.layers['m" + activomenu + "'].visibility = 'hide'");
				activomenu = null;		
			}
		}
	}

	function Muestra(fila,y_relativa_i,y_relativa_n,y_absoluta) 
	{
		OcultarTodo();	
		if (DHTML_W3C)  
		{
			eval("document.getElementById('m" + fila + "').style.display = 'block'");
			eval("posicion = (y_relativa_n-pageYOffset) + pageYOffset - (((y_absoluta-85-pageYOffset)/(screen.availHeight - 85))*14)");
			eval("document.getElementById('m" + fila + "').style.top = posicion + 'px'");	
			eval("document.getElementById('m" + fila + "').style.left = screen.availWidth * 0.1443 + 'px'")
			eval("document.getElementById('m" + fila + "').style.visibility = 'visible'");
			activomenu = fila;
		}
		if (DHTML_IE) 
		{
			eval("document.all['m" + fila + "'].style.display = 'block'");
			eval("posicion = y_relativa_i + document.body.scrollTop - (((y_absoluta-85)/(screen.availHeight - 85))*14)");
			eval("document.all['m" + fila + "'].style.pixelTop = posicion");
			if (screen.availWidth==800){
				eval("document.all['m" + fila + "'].style.pixelLeft = screen.availWidth * 0.1755"); //1468")
			} else {
				eval("document.all['m" + fila + "'].style.pixelLeft = screen.availWidth * 0.1385"); //1468")
			}
			eval("document.all['m" + fila + "'].style.visibility = 'visible'");
			activomenu = fila;
		}
		if (DHTML_NS) 
		{		
			eval("posicion = (y_relativa_n-pageYOffset) + pageYOffset - (((y_absoluta-85-pageYOffset)/(screen.availHeight - 85))*14)");
			eval("document.layers['m" + fila + "'].top = posicion");	
			eval("document.layers['m" + fila + "'].left = screen.availWidth * 0.1443")
			eval("document.layers['m" + fila + "'].visibility = 'show'");
			activomenu = fila;
		}
	}
	function OcultarTodohijos() 
	{
		menuvistohijos = false;
		if (activomenuhijos !=null) 
		{
			if (DHTML_W3C) {
				eval("document.getElementById('h" + activomenuhijos + "').style.visibility = 'hidden'");
				activomenuhijos = null;		
			}
			if (DHTML_IE) {
				eval("document.all['h" + activomenuhijos + "'].style.visibility = 'hidden'");
				activomenuhijos = null;
			}
			if (DHTML_NS) {
				eval("document.layers['h" + activomenuhijos + "'].visibility = 'hide'");
				activomenuhijos = null;		
			}
		}
	}
	function Muestrahijos(fila,y_relativa_i,y_relativa_n,y_absoluta,filapadre) 
	{
		var posicionsegunpadre;
		OcultarTodohijos();	
		if (DHTML_W3C)  
		{
			eval("document.getElementById('h" + fila + "').style.display = 'block'");
			eval("document.getElementById('h" + fila + "').style.top = document.getElementById('m" + filapadre + "').style.top + 'px'");
			eval("posicionsegunpadre = document.getElementById('m" + filapadre + "').style.left + document.getElementById('m" + filapadre + "').style.width");	
			eval("document.getElementById('h" + fila + "').style.left = posicionsegunpadre + 'px'")
			eval("document.getElementById('h" + fila + "').style.visibility = 'visible'");
			activomenuhijos = fila;
		}
		if (DHTML_IE) 
		{
			eval("document.all['h" + fila + "'].style.display = 'block'");
			eval("document.all['h" + fila + "'].style.pixelTop = document.all['m" + filapadre + "'].style.pixelTop");		
			eval("posicionsegunpadre = document.all['m" + filapadre + "'].style.pixelLeft + document.all['m" + filapadre + "'].style.pixelWidth");
			eval("document.all['h" + fila + "'].style.pixelLeft = posicionsegunpadre")
			eval("document.all['h" + fila + "'].style.visibility = 'visible'");
			activomenuhijos = fila;
		}
		if (DHTML_NS) 
		{		
			eval("document.layers['h" + fila + "'].top = document.layers['m" + filapadre + "'].top");	
			eval("posicionsegunpadre = document.layers['m" + filapadre + "'].left + document.layers['m" + filapadre + "'].width");
			eval("document.layers['h" + fila + "'].left = posicionsegunpadre")
			eval("document.layers['h" + fila + "'].visibility = 'show'");
			activomenuhijos = fila;
		}
		
		//menuvistohijos = true;
	}
//***************FIN FUNCIONES MENU EMERGENTE DIV**********************


//**************FUNCIONES MENU NORMAL DIV*************************
	//Para los navegadores
	var bV=parseInt(navigator.appVersion);
	NS4=(document.layers) ? true : false;
	IE4=((document.all)&&(bV>=4))?true:false;
	ver4 = (NS4 || IE4) ? true : false;
	
	function PincharMenu(Div)
	{
		if (ComprobarVisible(Div))
		{
			invisibleIt();
		}
		else
		{
			invisibleIt();
			VisibleIt(Div);
		}
	}
	function ComprobarVisible(Div)
	{
		if (!ver4) return false;
		if (IE4) 
		{
			whichEl = eval("MenuDiv" + Div);
			if (whichEl.style.display == "block")
			{
				return true;
			}
			else
			{
				return false;
			}
		} 
		else 
		{
			whichEl = eval("document.MenuDiv" + Div);
			if (whichEl.visibility == "show")
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		return false;
	}
	//Llamada a distintas formas de hacer invisible según el navegador
	function invisibleIt() 
	{
		if (!ver4) return;
		if (IE4) {invisibleIE()} else {invisibleNS()}
	}
	//Hacer todos los DIV INVISIBLES(para IE)
	function invisibleIE()
	{
		tempColl = document.all.tags("DIV");
		for (i=0; i<tempColl.length; i++) 
		{
			tempColl(i).style.display = "none";
		}
	}
	//Hacer todos los DIV INVISIBLES(para NS4)
	function invisibleNS()
	{
		for (i=0; i<document.layers.length; i++) 
		{
			whichEl = document.layers[i];
			whichEl.visibility = "hide";
		}
	}
	//Llamada a distintas formas de hacer Visible según el navegador
	function VisibleIt(Div) 
	{
		if (!ver4) return;
		if (IE4) {VisibleIE(Div)} else {VisibleNS(Div)}
	}
	//Para el Explorer,hace que los DIV sean visibles si lo estan ya lo hacen invisible
	function VisibleIE(Div) 
	{
		whichEl = eval("MenuDiv" + Div);
		whichEl.style.display = "block";
	}
	//Para el Netscape hace que los DIV sean visibles
	function VisibleNS(Div) 
	{
		whichEl = eval("document.MenuDiv" + Div);
		whichEl.visibility = "show";
	}
//***************FIN FUNCIONES MENU NORMAL DIV**********************


  
 	//function que abre nueva window con params pasados
	//usada en las opciones de la barra de navegacion y en los enlaces de los pedidos en Mi Cuenta>Historico/Mi Pedido
	function abrirVentana(pag,id,barra,ancho,alto,barraEstado,barraScroll,redimen,barraMenu)
	{
	  var sent, ventana;
	  sent = "window.open ('" + pag + "','" + id + "','toolbar=" + barra + ", width=" + ancho + ", height=" + alto + ", status=" + barraEstado + ", scrollbars=" + barraScroll + ", resizable=" + redimen + ", menubar=" + barraMenu + "')";
	  ventana=eval(sent);
	  //ventana=window.open ("cont/VBBTVS_AyOL_0.asp?contenido=1","AyOL","toolbar=no, width=650, height=495, status=no, scrollbar=yes, resize=no, menubar=no");
	}

	//Función que abre window con muestra grande del producto elegido
	function verProducto(id_prod) {
		//Abrimos directamente la ventana con el producto en cuestión...
		window.open ('./cont/VBBTVS_DArt_nuevo.asp?IDProd=' + id_prod, 'vista_producto' , 'toolbar=no,width=425,height=340,status=no,scrollbar=yes,resize=no,menubar=no');
	}

