function destacaFila (objFila, color)
{
    objFila.setAttribute('className', color, 0);
    objFila.setAttribute('class', color, 0);

    return true;
}


function RecargarForm()
{
  //// Ponemos el div que indica que se está cargando.
  ////document.getElementById('cargando').style.visibility = "visible";

  /// Deshabilitamos el botón para que no se pueda pulsar mientras se recarga
  document.getElementById('busq_ini_boton').disabled=true;
  ////document.getElementById('bt_busq_rap').style.visibility = "hidden";

  document.getElementById('form_busq').accion.value = "Empresa_BusqFrame";
  document.getElementById('form_busq').target = "_self";

  document.getElementById('form_busq').submit();

}

function RellenaPoblaciones(id_prov,id_combo_poblacion)
{

////alert('id_combo_poblacion='+ id_combo_poblacion);

  var combo_poblaciones = document.getElementById(id_combo_poblacion);

  if (id_prov>0 && array_prov[id_prov])
  {
    num_elem = array_prov[id_prov].length;
    for (a=0; a<num_elem ; a++)
    {
      id_pobl = array_prov[id_prov][a];
      combo_poblaciones.options[a] = new Option (array_pobl[id_pobl],id_pobl,true,false);
    }
  }else
  {
    combo_poblaciones.options[0] = new Option ('----',0,true,false);
  }

  combo_poblaciones.options[0].selected=true;

}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
    }
    else
    {
	begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
	end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}


function setCookie(name, value)
{
    document.cookie= name + "=" + escape(value);
}

function box_size(size, item_id)
{
//alert ("resize: "+item_id+ " px="+size);
  document.getElementById(item_id).style.height= size;
  if (size=='1px')
  {
	document.getElementById(item_id).style.display="none";
  }
  else
  {
	document.getElementById(item_id).style.display="block";
  }
    
	//// Guardamos en la bbdd el estado de la ventana
	//var sUrl = "http://" + document.domain + "/r2/panel/r2.php?accion=Administrador_DatosCajas&caja=" + item_id + "&size=" + size + "&sesion=" + Global_Sesion_Javascript;
  //CargaURL(sUrl);
}


function boxInfo_Open(id_contenedor,event,id_texto,texto,id_texto_desc,texto_desc)
{
    //// Antes de abrir se pone la opacidad a 0 por si ya está abierta
    document.getElementById(id_contenedor).style.visibility = 'hidden';
    document.getElementById(id_contenedor).style.opacity = 0;

    var attributes_on = {
        opacity: { to: 1 }        
    };

    var anim_on = new YAHOO.util.Anim(id_contenedor, attributes_on,0.3);


    //// Cogemos las coords actuales del raton
    if( typeof( event.pageX ) == 'number' ) 
    {
      // mayoría de navegadores
      var posX = event.pageX;
      var posY = event.pageY;
    } else if( typeof( event.clientX ) == 'number' ) 
    {
      //Internet Explorer and older browsers
      //other browsers provide this, but follow the pageX/Y branch
      var posX = event.clientX;
      var posY = event.clientY;
      
      var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
       ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
       ( navigator.vendor == 'KDE' );
      if( !badOldBrowser ) 
      {
        if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
          //IE 4, 5 & 6 (in non-standards compliant mode)
          posX += document.body.scrollLeft;
          posY += document.body.scrollTop;
        } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
          //IE 6 (in standards compliant mode)
          posX += document.documentElement.scrollLeft;
          posY += document.documentElement.scrollTop;
        }
      }
    }     



    
    document.getElementById(id_contenedor).style.left = posX + 'px';
    document.getElementById(id_contenedor).style.top = posY + 'px';

    document.getElementById(id_texto).innerHTML = texto;
    document.getElementById(id_texto_desc).innerHTML = texto_desc.replace('&lt;','<');
    
    document.getElementById(id_contenedor).style.visibility = 'visible';
    anim_on.animate();
    
} //// fin de "boxInfo_Open"


function boxInfo_Close(id_contenedor)
{
    var attributes_off = {
        opacity: { to: 0 }        
    };

    var ocultaBoxInfo = function(){
      document.getElementById(id_contenedor).style.visibility = 'hidden';
      document.getElementById(id_contenedor).style.opacity = 0;
    }
    
    var anim_off = new YAHOO.util.Anim(id_contenedor, attributes_off,0.2);
    anim_off.onComplete.subscribe(ocultaBoxInfo);

    anim_off.animate();
    
} //// fin de "boxInfo_Close"


function VentanaEliminarElemento(cad_url,texto_body,id_contenedor,texto_boton1,texto_boton2)
{

    YAHOO.namespace("eliminar");

		if (!texto_boton1)
		{
		  texto_boton1 = "¡ELIMINAR!";
		}

		if (!texto_boton2)
		{
		  texto_boton2 = "Cancelar";
		}

		
    // Define various event handlers for Dialog
    var handleYes = function() {
	    ///alert("You clicked yes!");
	    this.hide();
	    if (id_contenedor)
	    {
	      CargaURLenContenedor(id_contenedor, cad_url);
	    }else
	    {
	      window.location = cad_url;
	    }
    };
    var handleNo = function() {
	    this.hide();
    };

    // Instantiate the Dialog
    YAHOO.eliminar.aviso = new YAHOO.widget.SimpleDialog("aviso_eliminar",
				       { width: "300px",
					 fixedcenter: true,
					 visible: false,
					 draggable: false,
					 close: true,
					 text: texto_body,
					 icon: YAHOO.widget.SimpleDialog.ICON_WARN,
					 constraintoviewport: true,
					 buttons: [ { text:texto_boton1, handler:handleYes, isDefault:true },
								{ text:texto_boton2,  handler:handleNo } ]
				       } );
    YAHOO.eliminar.aviso.setHeader("AVISO");

    // Render the Dialog
    YAHOO.eliminar.aviso.render(document.body);

    YAHOO.eliminar.aviso.show();

}



function InitVentanaLoading(id_contenedor)
{

  YAHOO.namespace("cargando");
  
  eval ('YAHOO.cargando.wait' + id_contenedor + ' = new YAHOO.widget.Panel("wait' + id_contenedor + '",   { width: "240px",fixedcenter: true,underlay: "shadow", close: false, draggable: false, modal: true, zindex: 100 } );');

  eval ('YAHOO.cargando.wait' + id_contenedor + '.setHeader("Cargando ...");');
  
  var cad_img_temp = "<img src='/r2/panel/temas/cero/imagenes_comunes/cargando.gif'/>";
  eval ('YAHOO.cargando.wait' + id_contenedor + '.setBody("' + cad_img_temp + '");');

  eval ('YAHOO.cargando.wait' + id_contenedor + '.showMaskEvent.subscribe(fixMask, YAHOO.cargando.wait' + id_contenedor + ', true);');

  if (id_contenedor)
  {
    eval ('YAHOO.cargando.wait' + id_contenedor + '.render(YAHOO.util.Dom.get(id_contenedor));');
  }else
  {
    YAHOO.cargando.wait.render(document.body);
  }

}


function CargaURLenContenedor(id_contenedor, sUrl, tipo_ventanaLoading, ancla_destino)
{
//// la variable tipo_vetanaLoading indica que ventana se va a mostrar
//// - if tipo_vetanaLoading es false o 0, se muestra un 'popup' con un 'gif cargando'
//// - if tipo_vetanaLoading es true o 1, no se muestra nada
//// - if tipo_vetanaLoading es 2, se muestra un 'gif cargango' en el contenedor actual (pero no un popup)

//alert("sUrl=" + sUrl);

  if (!tipo_ventanaLoading)
  {
    InitVentanaLoading(id_contenedor);
  }

  var mostrar_ventana_aviso = false;
  
  var handleSuccess = function(o){
//    alert("todo OK");
    var contenedor = document.getElementById(id_contenedor);
    //contenedor.innerHTML = sUrl;
    
    var patron = /<!-- pide pass -->/i;
    if (o.responseText.search(patron)>=0)
    {
      //// Si ha caducado la sesion ...
      window.location = 'http://' + document.domain + '/r2/panel/r2.php';
    }else
    {
      contenedor.innerHTML = o.responseText;
      mostrar_ventana_aviso = true;
    }    
  
    //// Se oculta la ventana de 'cargando ...'
    if (!tipo_ventanaLoading)
    {
      //YAHOO.cargando.wait.hide();
      eval ('YAHOO.cargando.wait' + id_contenedor + '.hide();');
    }    
    
    if (ancla_destino)
    {
      location.hash = ancla_destino;
    }    
  }

  var handleFailure = function(o){

    //// Se oculta la ventana de 'cargando ...'
    if (!tipo_ventanaLoading)
    {
      //YAHOO.cargando.wait.hide();
      eval ('YAHOO.cargando.wait' + id_contenedor + '.hide();');
    }

    alert("ERROR1");
  }

  var callback =
  {
//    success:handleSuccess, failure: handleFailure, argument: { foo:"foo" }
    success:handleSuccess,
    failure:handleFailure
  };

  //// Se muestra la ventana de 'cargando ...'
  if (!tipo_ventanaLoading)
  {
    //YAHOO.cargando.wait.show();
    eval ('YAHOO.cargando.wait' + id_contenedor + '.show();');
  }else if (tipo_ventanaLoading == "2")
  {
    var contenedor = document.getElementById(id_contenedor);
    contenedor.innerHTML = '<div style="text-align: center; backgroud-color: #FFFFFF;"><div style="margin: 0 auto;"><br/><br/><br/><br/><br/><img src="/r2/panel/temas/cero/imagenes_comunes/loading.gif" /><br/><br/><br/><br/><br/><br/></div></div>';
  }

  var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
  
}


function CargaURL(sUrl)
{
	var handleSuccessTemp = function(o){
//alert("todo OK box_size");
  }

  var handleFailureTemp = function(o){
//alert("ERROR1_box_size");
  }

  var callbackTemp =
  {
//    success:handleSuccess, failure: handleFailure, argument: { foo:"foo" }
    success:handleSuccessTemp,
    failure:handleFailureTemp
  };

  var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackTemp);	  
}


function EnviaFormularioEnContenedor(id_form, action_form, id_contenedor, tipo_ventanaLoading, ancla_destino)
{
////alert("id_form1=" + id_form);
////alert("action_form=" + action_form);
////alert("id_contenedor=" + id_contenedor);
////alert("tipo_ventanaLoading=" + tipo_ventanaLoading);
////tipo_ventanaLoading=true;

  if (!tipo_ventanaLoading)
  {
    InitVentanaLoading(id_contenedor);
  }
  
  var handleSuccess = function(o){
    //alert("todo OK");
    var contenedor = document.getElementById(id_contenedor);
    //contenedor.innerHTML = sUrl;

    var patron = /<!-- pide pass -->/i;
    if (o.responseText.search(patron)>=0)
    {
      //// Si ha caducado la sesion ...
      window.location = 'http://www.viajarporextremadura.com/cubic/panel/cubic.php';
    }else
    {
      contenedor.innerHTML = o.responseText;
    }    

    //// Se oculta la ventana de 'cargando ...'
    if (!tipo_ventanaLoading)
    {
      //YAHOO.cargando.wait.hide();
      eval ('YAHOO.cargando.wait' + id_contenedor + '.hide();');
    }
    
    if (ancla_destino)
    {
      location.hash = ancla_destino;
    }    
  }

  var handleFailure = function(o){
    alert("ERROR2");
//    var contenedor = document.getElementById(id_contenedor);
//    contenedor.innerHTML = "ALGO HA FALLADO!!";
//    contenedor.innerHTML += "<li>Transaction id: " + o.tId + "</li>";
//    contenedor.innerHTML += "<li>HTTP status: " + o.status + "</li>";
//    contenedor.innerHTML += "<li>Status code message: " + o.statusText + "</li>";

    //// Se oculta la ventana de 'cargando ...'
    if (!tipo_ventanaLoading)
    {
      //YAHOO.cargando.wait.hide();
      eval ('YAHOO.cargando.wait' + id_contenedor + '.hide();');
    }

  }

  var callback =
  {
//    success:handleSuccess, failure: handleFailure, argument: { foo:"foo" }
    success:handleSuccess,
    upload:handleSuccess,
    failure:handleFailure,
    timeout: 50000
  };

  var formObject = document.getElementById(id_form);

  // the second argument is true to indicate file upload.
  YAHOO.util.Connect.setForm(formObject, true);

  //// Se muestra la ventana de 'cargando ...'
  if (!tipo_ventanaLoading)
  {
    //YAHOO.cargando.wait.show();
    eval ('YAHOO.cargando.wait' + id_contenedor + '.show();');
  }

  var request = YAHOO.util.Connect.asyncRequest('POST', action_form, callback);

  //// Se tiene que cambiar el contenido del contenedor después de enviar el formulario para que pueda coger los datos del formulario
  if (tipo_ventanaLoading == "2")
  {
    var contenedor_temp = document.getElementById(id_contenedor);
    contenedor_temp.innerHTML = '<div style="text-align: center; backgroud-color: #FFFFFF;"><div style="margin: 0 auto;"><br/><br/><br/><br/><br/><img src="/r2/panel/temas/cero/imagenes_comunes/loading.gif" /><br/><br/><br/><br/><br/><br/></div></div>';
        //contenedor_temp.innerHTML = "toma";
  }
  
}





//// Las siguientes funciones se utilizan para cargar la ventana 'loading' en un determinado div en vez de cargarlo en el body
//// La función fixMask() la asocia al showMaskEvent del panel en cuestión (es decir, se ejecuta cuando se muestra el panel).
//// También redefine las funciones center y sizeMask de la claxe panel

//// Comentarios originales del autor:
//// I have accomplished this by over writing 2 of the Panel's prototype functions (center y sizeMask). Then I attached a custom function called fixMask to the Custom Event showMaskEvent
//// The functions behave the way they do based on where the panel is rendered. If it is rendered to the body, the mask takes up the whole page. If it is rendered inside of another object it will attach to that object.

/*
function fixMask() {
        if (this.mask) {
        var cover = this.element.parentNode.id;
        var xy = YAHOO.util.Dom.getXY(cover);
        this.mask.style.height = YAHOO.util.Dom.getStyle(cover, 'height');
        this.mask.style.width = YAHOO.util.Dom.getStyle(cover, 'width');
        YAHOO.util.Dom.setXY(this.mask, xy);
        }
}


YAHOO.widget.Overlay.prototype.center = function() {

    var elementWidth = this.element.offsetWidth;
    var elementHeight = this.element.offsetHeight;
                
    if (this.element.parentNode == document.body) {
        var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
        var viewPortWidth = YAHOO.util.Dom.getClientWidth();
        var viewPortHeight = YAHOO.util.Dom.getClientHeight();
        var x = (viewPortWidth / 2) - (elementWidth / 2) + scrollX;
        var y = (viewPortHeight / 2) - (elementHeight / 2) + scrollY;
    } else {
            var scrollX = 0;
            var scrollY = 0;
        var cover = this.element.parentNode.id;
        var coverXY = YAHOO.util.Dom.getXY(cover);
        var viewPortWidth = parseInt(YAHOO.util.Dom.getStyle(cover, 'width'));
        var viewPortHeight = parseInt(YAHOO.util.Dom.getStyle(cover, 'height'));
                                if (isNaN(viewPortWidth))                               
                                {
                                  viewPortWidth = 300;
                                }
                                if (isNaN(viewPortHeight))                              
                                {
                                  viewPortHeight = 300;
                                }
                                
        var x = ((viewPortWidth / 2) - (elementWidth / 2) + scrollX) + coverXY[0];
        var y = ((viewPortHeight / 2) - (elementHeight / 2) + scrollY) + coverXY[1];
    }
   
        if (isNaN(x)==false)
        {
          this.element.style.left = parseInt(x, 10) + "px";
        }
        
        if (isNaN(y)==false)
        {
          this.element.style.top = parseInt(y, 10) + "px";
        }
        
        this.syncPosition();

        this.cfg.refireEvent("iframe");
};

YAHOO.widget.Panel.prototype.sizeMask = function() {
        if (this.mask) {
        if (this.element.parentNode == document.body) {
            this.mask.style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
            this.mask.style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
        } else {
                
                   if (this.element.parentNode == null){
                    this.mask.style.height = 300+"px";
                    this.mask.style.width = 300+"px";
                   
                   }else{                               
                    var cover = this.element.parentNode.id;
                                
                    var xy = YAHOO.util.Dom.getXY(cover);
                    this.mask.style.height = YAHOO.util.Dom.getStyle(cover, 'height');
                    this.mask.style.width = YAHOO.util.Dom.getStyle(cover, 'width');
                    YAHOO.util.Dom.setXY(this.mask, xy);
                        }
        }
        }
};
*/


