
prueba = function(){
	alert("prueba");
}



ActivaVentanaDelantera = function (obj){
	

	var url = obj.href;

	var id_capa = 'capa_delantera_tabla_' + obj.id;
	
	$(id_capa).innerHTML = "";

	llamarasincrono ( id_capa , url, 'GET');
   
	$('capa_delantera').style.display			= '';
	//Effect.Appear( id_capa , {duration:0.4});
	//Effect.BlindDown('capa_delantera_tabla', {scaleX:true});
	
	$(id_capa).style.display	= '';
	//$('capa_delantera_contenido').innerHTML	= '<br /><br /><br /><br /><br /><center><strong>CARGANDO...</strong></center>';
}



DesactivaVentanaDelantera = function (){
	DesactivaCapa();

	if ($('capa_delantera_tabla')){
	   $('capa_delantera_tabla').style.display='none';	
	}

	if ($('capa_delantera_tabla_link_lloweb')){
		$('capa_delantera_tabla_link_lloweb').style.display='none';	
	}
	if ($('capa_delantera_tabla_link_trabajo')){
		$('capa_delantera_tabla_link_trabajo').style.display='none';	
	}
	if ($('capa_delantera_tabla_link_servicios')){
		$('capa_delantera_tabla_link_servicios').style.display='none';	
	}
	if ($('capa_delantera_tabla_link_contacto')){
		$('capa_delantera_tabla_link_contacto').style.display='none';	
	}
}

DesactivaCapa = function (){
	$('capa_delantera').style.display='none';
}



//AJAX
llamarasincrono = function  (id_contenedor, url, metodo , mensaje )
{
//<![CDATA[

	if (!metodo) metodo = "GET";

	//le aņado el valor para detectarr ajax c=o	
	if (NumParametros(url) == 0){

	   url = url + "?c=o";
	}else{

		url = url + "&c=o";
	}

	var myhash = new Hash();

	if (metodo == "POST"){
		MetodoDetector_hash('INPUT' , myhash);
		MetodoDetector_hash('TEXTAREA' , myhash );
		MetodoDetector_hash('SELECT' , myhash );
		MetodoDetector_hash('CHECKBOX' , myhash );
	}	
	

	if (metodo == 'GET'){
	   new Ajax.Updater(id_contenedor, url, { evalScripts:true, method:'get', encoding:'iso-8859-1', onComplete: function() {   }	});
	} else {
		//alert(myhash.inspect());
		new Ajax.Updater(id_contenedor, url, { parameters: myhash,  evalScripts:true, method:'post', encoding:'iso-8859-1', onComplete: function() { } 	});
	}

   //]]>
}








html_entity_decode = function (str) {
	  var ta = document.createElement("textarea");

	  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");

	  toReturn = ta.value;

	  ta = null;

	  return toReturn
}

NumParametros = function (url){
	

	url = url.substring(url.lastIndexOf('/')+1); 
	
	var regex = new RegExp ( "[?]" );
	var results = regex.exec( url );
	if (results == null)
	   return 0;
	url = url.split('&'); 
	return url.length;

}



MetodoDetector_hash = function (tag, myhash){
	var inputs = document.getElementsByTagName(tag);
	for (i=0; i < inputs.length; i++){
		var nombre = inputs[i].name;
		if (!nombre)  nombre = inputs[i].id;
		if (nombre){
			var valor = "";
	
		   //CASOS RAROS
		   //TIPO RADIO: Hay que escoger el que esta a checked
		   if (inputs[i].type == "radio"){
			  //Si no esta seleccionado no lo tengo en cuenta
			  if (! inputs[i].checked ) continue;
		   }

		   
			
			//CASO CON EL FCKEDITOR
			if (nombre == "fck_noticia"){
				var referencia = FCKeditorAPI.GetInstance("fck_noticia");  
            valor = referencia.GetHTML();  
				valor = html_entity_decode(valor); //LE QUITO EL htmlentities()
				
			}
			
			//CASO CHECKBOX
			if (inputs[i].type == "checkbox"){
				if (inputs[i].checked)
					valor = "on";
				else
					valor = "off";
			}
			
			if (valor == ""){
				valor = inputs[i].value;
			}
			myhash.set(nombre, escape(valor));
		   //post_send += nombre + "=" + escape(valor);
		}
	}
	//return post_send;
}



function Aparece_Aviso_Mensaje(){
	
	
	setTimeout("Effect.BlindDown('capa_inferior')",1000);

	setTimeout("Effect.BlindUp('capa_inferior')",7000);
	
	//$('capa_inferior').style.display='';		
}



Insertar = function (array, dato){
	array.push(dato);
}

FormateaNum = function(num, decimales){ 
	decimales = typeof(decimales) != 'undefined' ? decimales : 2;
	var original=parseFloat(num); 		
	var result=Math.round(original*100)/100 ; 
	
	return result.toFixed( decimales ); 	
}










SetHTML = function (campo , valor){
	try{
		//if (document.getElementById(campo)){
  			document.getElementById(campo).innerHTML = valor;	
		//}
  	} catch(err) {
	  txt="SetHTML('"+campo+"', '"+valor+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

GetHTML = function (campo){
	
	
	
	try{
		//if (document.getElementById(campo)){
  			return document.getElementById(campo).innerHTML;	
		//}
  	} catch(err) {
	  txt="GetHTML('"+campo+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

SetDisplay = function (campo, valor){
	try{
		//if (document.getElementById(campo)){
			document.getElementById(campo).style.display = valor;	
		//}
	} catch(err) {
	  txt="SetDisplay('"+campo+"', '"+valor+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

GetDisplay = function (campo){
	try{
		return document.getElementById(campo).style.display ;	
	} catch(err) {
	  txt="GetDisplay('"+campo+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

GetText = function (campo){
		
	
	try{
		return document.getElementById(campo).value ;
	} catch(err) {
	  txt="GetText('"+campo+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

SetText = function (campo, valor){
	
	
	try{
		document.getElementById(campo).value = valor;
	} catch(err) {
	  txt="SetText('"+campo+"', '"+valor+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

GetCheckBox = function (campo){
	
	
	try{
		return document.getElementById(campo).checked ;	
	} catch(err) {
	  txt="GetCheckBox('"+campo+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

SetCheckBox = function (campo, valor){
		
	
	try{
		document.getElementById(campo).checked = valor ;
	} catch(err) {
	  txt="SetCheckBox('"+campo+"', '"+valor+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

GetClass = function (campo){
	
	
	try{
		return document.getElementById(campo).className ;		
	} catch(err) {
	  txt="GetClass('"+campo+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

SetClass = function (campo, valor){
		
	
	try{
		document.getElementById(campo).className = valor ;
	} catch(err) {
	  txt="SetClass('"+campo+"', '"+valor+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

GetSelected = function (campo){
	
	try{
		return document.getElementById(campo).value;
	} catch(err) {
	  txt="GetSelected('"+campo+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}

SetSelected = function (campo, value){
	
	try{
		var combo = document.getElementById(campo);
		var cantidad = combo.length;
		for (i = 0; i < cantidad; i++) {
			if (combo[i].value == value) {
				combo[i].selected = true;
			}   
		}	
	} catch(err) {
	  txt="SetSelected('"+campo+"','"+value+"') - > Error.\n";
	  txt+="Error: " + err.description;
	  alert(txt);
  }
}


























/* PROTOTYPE *****************************************/

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}


// Array.concat() - Join two arrays
if( typeof Array.prototype.concat==='undefined' ) {
 Array.prototype.concat = function( a ) {
  for( var i = 0, b = this.copy(); i<a.length; i++ ) {
   b[b.length] = a[i];
  }
  return b;
  };
}

// Array.copy() - Copy an array
if( typeof Array.prototype.copy==='undefined' ) {
 Array.prototype.copy = function() {
  var a = [], i = this.length;
  while( i-- ) {
   a[i] = typeof this[i].copy!=='undefined' ? this[i].copy() : this[i];
  }
  return a;
 };
}

// Array.pop() - Remove and return the last element of an array
if( typeof Array.prototype.pop==='undefined' ) {
 Array.prototype.pop = function() {
  var b = this[this.length-1];
  this.length--;
  return b;
 };
}

// Array.push() - Add an element to the end of an array, return the new length
if( typeof Array.prototype.push==='undefined' ) {
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
}

// Array.shift() - Remove and return the first element
if( typeof Array.prototype.shift==='undefined' ) {
 Array.prototype.shift = function() {
  for( var i = 0, b = this[0], l = this.length-1; i<l; i++ ) {
   this[i] = this[i+1];
  }
  this.length--;
  return b;
 };
}

// Array.slice() - Copy and return several elements
if( typeof Array.prototype.slice==='undefined' ) {
 Array.prototype.slice = function( a, c ) {
  var i, l = this.length, r = [];
  if( !c ) { c = l; }
  if( c<0 ) { c = l + c; }
  if( a<0 ) { a = l - a; }
  if( c<a ) { i = a; a = c; c = i; }
  for( i = 0; i < c - a; i++ ) { r[i] = this[a+i]; }
  return r;
 };
}

// Array.splice() - Remove or replace several elements and return any deleted elements
if( typeof Array.prototype.splice==='undefined' ) {
 Array.prototype.splice = function( a, c ) {
  var i = 0, e = arguments, d = this.copy(), f = a, l = this.length;
  if( !c ) { c = l - a; }
  for( i; i < e.length - 2; i++ ) { this[a + i] = e[i + 2]; }
  for( a; a < l - c; a++ ) { this[a + e.length - 2] = d[a - c]; }
  this.length -= c - e.length + 2;
  return d.slice( f, f + c );
 };
}

// Array.unshift() - Add an element to the beginning of an array
if( typeof Array.prototype.unshift==='undefined' ) {
 Array.prototype.unshift = function() {
  this.reverse();
  var a = arguments, i = a.length;
  while(i--) { this.push(a[i]); }
  this.reverse();
  return this.length;
 };
}

// -- 4umi additional functions

// Array.forEach( function ) - Apply a function to each element
Array.prototype.forEach = function( f ) {
 var i = this.length, j, l = this.length;
 for( i=0; i<l; i++ ) { if( ( j = this[i] ) ) { f( j ); } }
};

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function( i, v ) {
 if( i>=0 ) {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
};

// Array.lastIndexOf( value, begin, strict ) - Return index of the last element that matches value
Array.prototype.lastIndexOf = function( v, b, s ) {
 b = +b || 0;
 var i = this.length; while(i-->b) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.random( range ) - Return a random element, optionally up to or from range
Array.prototype.random = function( r ) {
 var i = 0, l = this.length;
 if( !r ) { r = this.length; }
 else if( r > 0 ) { r = r % l; }
 else { i = r; r = l + r % l; }
 return this[ Math.floor( r * Math.random() - i ) ];
};

// Array.shuffle( deep ) - Randomly interchange elements
Array.prototype.shuffle = function( b ) {
 var i = this.length, j, t;
 while( i ) {
  j = Math.floor( ( i-- ) * Math.random() );
  t = b && typeof this[i].shuffle!=='undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
};

// Array.walk() - Change each value according to a callback function
Array.prototype.walk = function( f ) {
 var a = [], i = this.length;
 while(i--) { a.push( f( this[i] ) ); }
 return a.reverse();
};


Function.prototype.defaults = function()
{
  var _f = this;
  var _a = Array(_f.length-arguments.length).concat(
    Array.prototype.slice.apply(arguments));
  return function()
  {
    return _f.apply(_f, Array.prototype.slice.apply(arguments).concat(
      _a.slice(arguments.length, _a.length)));
  }
}


