	
// Enero 2009: 2 funciones introducidas para el nuevo comportamiento de combos de comunidad y tienda:
        function closepp(o){
            o.size=1;
			o.style.marginTop='0px';
        }

		function pp(o,e){
			if(typeof(old_object)!='undefined' && old_object!=o){
				if(old_object.size==11){
					old_object.size=1;
					old_object.style.marginTop='0px';
				}
			}
			if(document.all)
				e=event;
			if(e.clientY>160){
				o.style.position='relative';
				o.size=11;
				o.style.zIndex=999;
				o.style.marginTop=(o.offsetHeight*(-1))+'px';
				if(document.all){
//                  Por conflictos con otros handlers necesarios para la gestion del evento onchange gestionaremos el cierre desde closepp().
//					o.onchange=function(){
//						this.size=1;
//						this.style.marginTop='0px';						
//					}
//                    W3C:					
//                    o.addEventListener('change',function(){
//						this.size=1;
//						this.style.marginTop='0px';						
//				    },false);
//                    MS:
//                    o.attachEvent('onchange',function(){
//						this.size=1;
//						this.style.marginTop='0px';						
//				    });
				}
				else{
					o.onclick=function(){
						this.size=1;
						this.style.marginTop='0px';
					}
				}
				document.onclick=function(){
					var cas=true;
					if(document.all){
						if(event.srcElement.tagName=='SELECT')
							cas=false;
					}
					if(cas){
						o.size=1;
						o.style.marginTop='0px';
					}
				}
			}
			old_object=o;
		}

/*Gestión de cookies en cliente*/
function creaCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

/* Control de seleccion de comunidad */
function OnSelectCombo(idElement,param)
      {
      var combo = document.getElementById(idElement);
      
      if (combo.value==null)
        return;              
        
      document.getElementById(param).value=escape(combo.value);
      
      document.getElementById("main").submit();

      //window.location=window.location.pathname + "?" + param + "=" + combo.value;
      }
      
  /* Control de seleccion de comunidad */
function ChangeComunity(param)
      {
            
      document.getElementById("com").value=escape(param);     
      
      document.getElementById("main").submit();

      //window.location=window.location.pathname + "?" + param + "=" + combo.value;
      }    
function OnSelectComboWithPage(page, idElement, param, tail)
{
      var combo = document.getElementById(idElement);
      
      if (combo.value==null)
        return;                            

      //Atencion: se cuenta con que "page" comience con "/":
      window.location.href="http://" + window.location.host + page + "?" + param + "=" + combo.value + tail;
}
      
      
      

function createCookie(name,idElement,days,pageToSubmit)
      {
      var combo=document.getElementById(idElement);
      var value=combo.value;
      
      if (value!="tienInit") {

      /*creaCookie(name,value,days);*/
      document.getElementById("shop").value=value;

      document.getElementById("main").action=pageToSubmit;        
      document.getElementById("main").submit();
      
      }
      
      }
      

function SetComboValue(idCombo,idParam)
{

    var parameter=document.getElementById(idParam);
    
    if (parameter.value!=null)
    {
        document.getElementById(idCombo).value=parameter.value;
    }                    
         
    
}

function SetComboValueFromCookie(idCombo,idCookie)
{
    return;
    var valor=readCookie(idCookie);
    
    alert(valor);
    
    if (valor==null)
        return;
        
    var combo=document.getElementById(idCombo);
    alert(combo.value);
    combo.value=valor;
        
}
      
      
function Enviar(idElement)   {
      var combo = document.getElementById(idElement);
      var valor = combo.value;
      if (valor == "-1"){
        return false;
      }
      else{
          if (valor.indexOf("http")!= -1)
             window.open(valor);
          else
              window.location=valor;
      }
}

//Funciones para paginacion
function ChangeYear(year)
{
    document.getElementById("year").value=year;
    document.getElementById("pg").value=1;
    document.getElementById("main").submit();
}

function ChangeYearPage(year,page)
{

    document.getElementById("year").value=year;
    document.getElementById("pg").value=1;
    //Atencion: se cuenta con que "page" comience con "/":
    document.getElementById("main").action="http://" + window.location.host + page;
    document.getElementById("main").submit();
}


function ChangeYearComboPage(idElement,page)
{        
    var combo = document.getElementById(idElement);
      
    if (combo.value==null)
        return;    
            
    document.getElementById("year").value=combo.value;
    document.getElementById("pg").value=1;
    document.getElementById("main").action="http://" + window.location.host + page;
    document.getElementById("main").submit();
}


   function siguiente(x,flechas) {
  
  /*alert(" x "+x)
  alert(" pgFin "+pgFin)
  alert(" pgIni "+pgIni)
  alert(flechas)*/
  
  if(x>pgFin)
        {
        document.getElementById("pgIni").value= pgFin+1 ;
        document.getElementById("pgFin").value= pgFin+maxPg
        
        }
   
    if(x<pgFin && flechas==false)     
        {
        document.getElementById("pgIni").value= pgIni ;
        document.getElementById("pgFin").value= pgFin
        }
    if(x<pgFin && flechas==true)
        {
     
        document.getElementById("pgIni").value= pgIni-maxPg ;
        document.getElementById("pgFin").value= x
        flechas=false
        }    
        document.getElementById("pg").value= x
        
       /*
        alert(document.getElementById("pgIni").value)
        alert(document.getElementById("pgFin").value)
        alert(document.getElementById("pg").value)*/
        
       document.getElementById("main").submit();
  }
 
  
   function fpaginacion() {
   
        
     var paginacion=0;
     var formato="";
     var ini="";
     var fin="";
     flechaAtras="";
     flechaAlante="";
      if (pgIni == '')    
         pgIni = 1;
      if (pgFin == '')    
         pgFin = 5;
   if (totalResult <=pageSize)
      return;
   if (division.indexOf('.')!=-1)
        {
          donde =division.indexOf('.');
          paginacion=parseInt(division.substring(0,donde))+1
        }else{paginacion = parseInt(division)}
        for(var x=pgIni; x<=paginacion;x++)
        {
         if(x<=pgFin)
         {
            if (x==pg)
                {  formato+="<li><span>"+x+"</span> |</li>"; }
                 else
                { 
                  flechitas ="false";
                   formato+="<li><a href='#' onclick='javascript:siguiente("+x+","+flechitas+");return false;' title='Ir a pagina'>"+x+"</a> |</li> "}
                }
         }  
        if ((paginacion>pageSize)&& (paginacion>pgFin) )
        {
            
            flechaAlante ="<li class='flecha'><a href='#' onclick='javascript:siguiente("+(pgFin+1)+");return false;' title='anterior'>&raquo;</a></li>"
        } 
       
        if ((paginacion>pageSize) && (pgIni!=1))
        {
            flechitas ="true";
            flechaAtras="<li class='flecha'><a href='#' onclick='javascript:siguiente("+(pgIni-1)+","+flechitas+");return false;' title='atras'>&laquo;</a></li>";
        } 
        
        document.getElementById("objPaginacion").innerHTML=flechaAtras+formato+flechaAlante;
       
  }
  
  
      //Submite el formulario pasando 2 parametros
    //Hay que hacer una funcion general que pase tantos parametros
    //como necesitemos 
    function submitHref(location,parametro1,valor1,parametro2,valor2)
    {
       if (location != '')
          document.getElementById("main").action = location;
       if (parametro1 != '')   
          document.getElementById(parametro1).value = valor1;
       if (parametro2 != '')   
          document.getElementById(parametro2).value = valor2;
 
       document.getElementById("main").submit();
    }  
  