	jQuery(function($) {
		primero();
		if(jQuery("#p1").hasClass("menuOutP")){
			jQuery("#p1").css({'background-color':'#B60D12','color':'#fff'});
		}
		divresize();
	});

	function divresize(){
		dh = document.body.clientHeight-170;
		jQuery("#dvContenido").height(dh);
	}
	function envia(codigo)
	{
		var frm=document.forms[0]
		if (codigo != null )
			frm.txtId.value=codigo
		frm.submit();
	}
	
	function gup( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}

	function pkkgup(name,defecto) {
		if (gup(name)=='') {
			return defecto;
		}
		else {
			return gup(name);
		}
	}

	function envia(codigo)
	{
		var frm=document.forms[0]
		if (codigo != null )
			frm.txtId.value=codigo
		frm.submit();
	}
			
			
	function moveScroll(panel,item) {
	  anchor = document.getElementById('link'+panel+'-'+item);
	  selthis(anchor);
	  //anchor.scrollIntoView();
	}
			
	var detalle= pkkgup("detalle","0");
	var actual = pkkgup("actual","Caracteristicas");
	
	function primero()
	{
		if (detalle!="1")
		{
			if (pkkgup("lstSelector","0") != "0"){
				s = "lnk-item"+pkkgup("lstSelector","0");
				document.onload = displayitem(s);  
			}
			if (pkkgup("txtId","0") != "0"){
				document.onload += moveScroll(pkkgup("lstSelector","2"),pkkgup("txtId","0")) ;   
			}
		}
		else
		{
			s = "lnk-item"+pkkgup("lstSelector","2");
			document.onload = displayitem(s);  
			document.onload += moveScroll(pkkgup("lstSelector","2"),pkkgup("txtId","1"));    
			//alert(jQuery("#td"+actual).children().attr("id"));
			jQuery("#td"+actual).children().css({'background-color':'#B60D12','color':'#fff','cursor':'hand'});
			
			obj=document.getElementById("filaScroll");
			if (obj != null)
			{
				pos=obj.offsetTop;
				document.getElementById("mnuVertProductos").scrollTop=pos ;
			}
		}
	}



	function getItems() {
		var alldivs = document.getElementById('menu-lateral').getElementsByTagName('div');
		var allitems = new Array();
		for (i=0;i<alldivs.length; i++)
		{
			if (alldivs[i].getAttributeNode('class').nodeValue == "item")
			{
				allitems.push(alldivs[i]);
			}
		}
		return allitems
	}

	function changeImage(obj,action) {
		//Pre-carrega les imatges
		var toggleImage = new Array();
			toggleImage['openBlock'] = "hidden";
			toggleImage['closedBlock'] = "visible";
		
		obj.style.visibility=toggleImage[action]
		return
	}


	var activesLI
	function selthis(obj)
	{
		for (j=0; j<activesLI.length; j++) 
		{
			activesLI[j].style.backgroundColor="#D2E1AA";
			activesLI[j].firstChild.className="";
		}
		obj.parentNode.style.backgroundColor="#5C7C3B";
		obj.className="sel";
	}

	function displayitem(id) 
	{
		var idSelItem  = id.substring(4);
		
		var allitems = getItems();
		var subitem
		
		for (i=0; i<allitems.length; i++) 
		{
			if (allitems[i].id==idSelItem) 
			{
				subitem = document.getElementById(('block-'+ allitems[i].id));
				subitemLi = subitem.getElementsByTagName('li');
				activesLI=subitemLi
				
				for (j=0; j<subitemLi.length; j++) 
				{
					if (j==0) {
						//subitemLi[j].style.backgroundColor="#5C7C3B";
						//subitemLi[j].firstChild.className="sel";
					} else {
						subitemLi[j].style.backgroundColor="#D2E1AA";
						subitemLi[j].firstChild.className="";
					}
				}
				
				if ((subitem.style.display == "none") || (subitem.style.display == "")) 
				{
					subitem.style.display = "block";
					if (subitem.firstChild.offsetHeight<subitem.offsetHeight) 
					{
						subitem.style.height = subitem.firstChild.offsetHeight+'px';
					}
					changeImage(subitem.previousSibling.firstChild,'openBlock')
					
				} 
				else 
				{
					subitem.style.display = "none";
					subitem.style.height = 300+'px';
					changeImage(subitem.previousSibling.firstChild,'closedBlock')
				}
			} 
			else 
			{
				subitem = document.getElementById(('block-'+ allitems[i].id));
				subitemLi = subitem.getElementsByTagName('li');
				
				for (j=0; j<subitemLi.length; j++) 
				{
					subitemLi[j].firstChild.className="";
					subitemLi[j].style.backgroundColor="#D2E1AA";
				}
				subitem.style.display = "none";
				subitem.style.height = 300+'px';
				changeImage(subitem.previousSibling.firstChild,'closedBlock')
			}
		}	
	}


	function subitem(obj) 
	{
		if (obj.nextSibling) 
		{
			var subllista = obj.nextSibling;
			if ((subllista.style.display == "none") || (subllista.style.display == "")) 
			{
				subllista.style.display = "block";
			}
			else 
			{
				subllista.style.display = "none";
			}
		}
	}


	function actFrame(destino) 
	{
		//parent.document.getElementById('contentFRM').src=destino;
		window.location.href = destino;
		return false;
	}

	function verProducto(vid,vsubid,vimg) 
	{
		//s="detalle.aspx?id="+vid+"&imgPath="+vimg;    
		s="home.aspx?detalle=1&id="+vsubid+"&imgPath="+vimg+"&lstSelector="+vid+"&txtId="+vsubid;    
		actFrame(s);
	}

	function saltar(vid,vsubid) 
	{
		//s="flash.aspx?rootpath="+miPath+"&txtId="+vsubid+"&lstSelector="+vid;    
		switch(vid)
		{
		case 2:
		  param = 'gama';
		  break;
		case 3:
		  param = 'prescripcion';
		  break;
		case 4:
		  param = 'familia';
		  break;
		}
		s = "home.aspx?lstSelector="+vid+"&txtId="+vsubid+"&"+param+"="+vsubid;
		actFrame(s);
	}


	function runClick(vid,vsubid) 
	{
		displayitem("lnk-item"+vid);
		saltar(vid,vsubid);
	}

	function runSubItem(obj,vid,vsubid) 
	{
		subitem(obj);
		saltar(vid,vsubid);        
	}
	
	function runSubItemP(obj,vid,vsubid,vimg) 
	{
		subitem(obj);
		verProducto(vid,vsubid,vimg);        
	}
	
	//****************** FUNCIONES DE VISTA DETALLE *************************************//
	function colorDefecto(color)
	{
		if (color=="")
			return "B60D12"
		else
			return color;
	}
	function rollOver(td,color)
	{
		jQuery("#"+td.id).css({'background-color':'#'+colorDefecto(color),'color':'#fff','cursor':'hand'});
		
		
		/*
		td.style.cursor='hand';
		td.style.backgroundColor=colorDefecto(color);
		td.style.color="ffffff";					
		*/
		
	}
	
	function rollOut(td,color)
	{
		if (jQuery("#"+td.id).parent().attr("id")=="td" + actual)
			return;
		jQuery("#"+td.id).css({'background-color':'#'+color,'color':'#000','cursor':'default'});
		
		/*
		td.style.cursor='default';
		td.style.backgroundColor=color;
		td.style.color="000000";					
		*/
	}
	
	function ocultaDivs()
	{
		var 
		obj=document.getElementById("Caracteristicas");
		obj.style.display="none";
		obj=document.getElementById("Indicaciones");
		obj.style.display="none";
		obj=document.getElementById("Ingredientes");
		obj.style.display="none";
		obj=document.getElementById("Dosificacion");
		obj.style.display="none";
		obj=document.getElementById("Formatos");
		obj.style.display="none";
	}
	
	function activaDiv(strDiv)
	{
		var obj=eval('document.getElementById("' + strDiv +'")');
		obj.style.display="block";
	}
	
	function escogeOpcion(strDiv,color)
	{
		//Desactivar opción anterior
		var obj=eval('document.getElementById("td' + actual +'")');
		//alert(jQuery("#td"+actual).children("p").attr('id'));
		//jQuery("#td"+actual).children("p").css({'background-color':'pink','color':'#000'});
		obj.firstChild.style.backgroundColor="DAD8D9";
		obj.firstChild.style.color="000000";
		//actual=strDiv;
		actual = strDiv;
		jQuery("#td"+actual+":first-child").css({'background-color':'#fff','color':'#fff'});
		//obj.firstChild.style.backgroundColor=colorDefecto(color);
		//obj.firstChild.style.color="ffffff";
		ocultaDivs();
		activaDiv(strDiv);
	}