function devuelve_char_tecla(e)
{
	return( String.fromCharCode(devuelve_codigo_tecla(e)));
}//fun

function devuelve_codigo_tecla(e)
{ 
	var code;
	if (!e) {
		var e = window.event;
	}//if
	 
	if (e.keyCode) {
		 code = e.keyCode;
	} else if (e.which) {
		 code = e.which;
	}//elif

return (code);	
}//fun


//click en la tecla return...
function entrar(frm) {
	var tecla ;
    
    //funcion de control de la tecla return
    function capturaTecla(e) {
        if(document.all) tecla = event.keyCode ;
        else tecla = e.which ;
     	if(tecla == 13) frm.submit() ;
    } 
    document.onkeydown = capturaTecla ;
}


//recortar espacios en blanco por los dos lados de un string
function trim(string) 
{ 
	return string.replace(/(^\s*)|(\s*$)/g,'') ; 
} 

//longitud en textarea
function calc_long(txt, maximo)
{
	var largo ;
	largo = txt.value.length ;
	if (largo > maximo) txt.value = txt.value.substring(0, maximo) ;
}

function check_mail(str)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
    return (filter.test(str)) ;
}



function check_telf(campo)
{
	campo.value = remove_characters(campo.value) ;
	var list=campo.value.split("");
	var listByTotal=new Array();
	var controlTotalNumber=6;
	for(i=0; i<list.length; i++){
		if(listByTotal[list[i]] == undefined){
			listByTotal[list[i]]=0;
		}
		listByTotal[list[i]]++;
	}
	for(i=0; i<listByTotal.length; i++){
		if(listByTotal[i] >= controlTotalNumber){
			return false;
		}
	}
    var charpos = campo.value.search("[^0-9\ \.\,\-]") ;
    if (campo.value.length > 0 &&  charpos >= 0) {
    	return false ;
	} else {
		return true ;
	}
}

function remove_characters(str)
{
    salida = "" ;
    for(i = 0 ; i < str.length ; i++) {
        if(str.charAt(i) != "(" && str.charAt(i) != ")" && str.charAt(i) != "_") 
            salida += str.charAt(i) ;
    }
    return (salida) ;
}

//Abrir un PopUp
function open_popup(src, w, h) {
	window.open(src,"leyenda", "width="+w+",height="+h+"status=yes");
}

//miramos si algun radio button está checked
function algunRadioButtonChequeado(objRadio)
{
	for ( var i = 0; i < objRadio.length; i++ ) 
	{
		if (objRadio[i].checked) {
			return true;
		}
	}
	return false ;
}

//seleccionar una opcion con value = <valor> del <desplegable> en cuestión
function selectOption(desplegable, valor)
{
    for(var i = 0 ; i < desplegable.options.length ; i++)
	{
	    //si el tamanho es 2 me da igual lo que venga en valor, LO SELECCIONAMOS...
        if(desplegable.options[i].value == valor)
		{  
		    desplegable.selectedIndex = i ;
		}
    }
    if(desplegable.options.length == 2) {
        desplegable.selectedIndex = 1 ;
    }
    if(desplegable.options.length == 1) {
        desplegable.selectedIndex = 0 ;
    }
}

/**
 * Esta función sirve para seleccionar un objeto en un combo, Y DA IGUAL EL TAMAÑO QUE TENGA
 * @param desplegable  El combo cuya option se quiere cambiar
 * @param valor  El valor que se quiere dejar seleccionado en el combo
 * @return  Nada, es un procedure
 */
function selectOption_comboNormal(desplegable, valor)
{
	for(var i = 0 ; i < desplegable.options.length ; i++)
	{
	    //si el tamanho es 2 me da igual lo que venga en valor, LO SELECCIONAMOS...
        if(desplegable.options[i].value == valor)
		{  
		    desplegable.selectedIndex = i ;
		}
    }
}

//chequear todos los checkBox de un formulario
function CheckAllCheckBox(formulario, valorCheck, nombreCB)
{
	for (i = 0 ; i < formulario.elements.length ; i++)
    {   
		if (formulario.elements[i].type == "checkbox") formulario.elements[i].checked = valorCheck ;
	}    			
	return false ;

}

//Nos devuelve true si hay algun checkbox con nombre "nombreCB" chequeado
function algunoChecked(formulario, nombreCB)
{
    for (i = 0 ; i < formulario.elements.length ; i++)
    {   
        if (formulario.elements[i].type == "checkbox" && formulario.elements[i].name == nombreCB && formulario.elements[i].checked) return true ;
	}    			
	return false ;
}


/*
//Cogemos un objeto generico del árbol DOM
function getObject(objname) {

    if (document.getElementById) {
        obj = document.getElementById(objname) ;
    } else {
        if (document.all) {
            obj = document.all[objname] ;
        } else {
            if (document.layers) {
                obj = false ;
                }
            } 
        }
    return obj ;
}
*/

//Encontrar un objeto cross-browser a partir de su id
function getObject(objname)
{
    var obj = null ;
    if (document.getElementById) {
        obj = document.getElementById(objname) ;
    } else {
        if (document.all) {
            obj = document.all[objname] ;
            }
        }

    return obj ;
}

// Bookmark del site CROSS BROWSER
function addFavorite(url,title) {

	if (document.all) {
		// Explorer
		window.external.AddFavorite(url, title);
	} else {
		if (window.sidebar) {
			// NS6+
			window.sidebar.addPanel(title, url, "")
			}
		}
}


function get_ajax()
{
  var request = false;
  
	try
	{
	      
    request = new ActiveXObject("MSXML2.XMLHTTP");
	}
	catch (e)
	{
    try
    {
      request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (E)
    {
      request = false;
    }
	}

  
	//ff   
	if (!request && typeof XMLHttpRequest!='undefined')
	{
	  
    request = new XMLHttpRequest();
	    
    if (request.overrideMimeType)
    {
	    request.overrideMimeType('text/xml');
	  }
	  if (!request)
	  {
	    alert('Cannot create XMLHTTP instance');
	    return false;
	  }
	        
  }//if
  
  return(request);
}//fun

/**
 * Esta función sirve para vaciar un SELECT en tiempo de ejecución
 * @param comboVaciar
 * @return
 */
function VaciaCombo(comboVaciar)
{
	if(comboVaciar!=null && comboVaciar.options!=null){
		while (comboVaciar.options.length > 0) 
		{
		    comboVaciar.options[0] = null;
		}
	}
}

/**
 * Esta función sirve para borrar los elementos de los SELECT de Playa, Golf y Ski
 * @return  Nada, es un procedure
 */
function VaciaCombosItems()
{
	combo_playa = document.getElementById("fk_id_tbl_items_playa");
	combo_golf = document.getElementById("fk_id_tbl_items_golf");
	combo_ski = document.getElementById("fk_id_tbl_items_ski");
	VaciaCombo(combo_playa);
	VaciaCombo(combo_golf);
	VaciaCombo(combo_ski);
}


/**
 * Esta función sirve para llenar un objeto de tipo SELECT con una opción proporcionada como argumento a la función
 * @param comboLlenar El objeto tipo SELECT en el que insertar la opción nueva 
 * @param optionValue El id subyacente del OPTION
 * @param optionText El texto del OPTION
 * @return Nada, es un procedure
 */
function LlenaCombo(comboLlenar, optionValue, optionText)
{
	opcionNueva = new Option(optionText, optionValue);
	comboLlenar.options.add(opcionNueva);
}


/**
 * Haz un bind con jquery de handler_numerico sobre un campo input
 * y su evento keypress y no dejara introducir caracteres no
 * numericos en ese campo
 * 
 * @param {Object} e
 * @return bool 
 */
function handler_numerico(e)
{
  /*
    var s_char_tecla =  devuelve_char_tecla(e);
    var i_codigo_tecla = devuelve_codigo_tecla(e);
    //alert(i_codigo_tecla);
    if ((isNaN(s_char_tecla) && (i_codigo_tecla > 46 ) && (i_codigo_tecla < 57 )))
    {      
      return false;
    }//if 
    */

    var charCode = (e.which) ? e.which : e.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    {
      return false;
    }//if

    return true;
}//fun

function visible_invisible(s_id, b_visible) 
{
  
  if (b_visible == 1)
  {
    $("#"+ s_id).css("visibility","visible");
    $("#"+ s_id+ "_loader").css("visibility","hidden");	
  }//if
  else
  {
  	$("#"+ s_id).css("visibility","hidden");
  	$("#"+ s_id+ "_loader").css("visibility","visible");
  }//el
  
}//fun

function contiene_url_email_numeros(field)
{			    
	contiene = false ;
	field = field.toLowerCase() ;	    
    
	//Url
	if (field.indexOf("www.")>=0||field.indexOf("http:")>=0) {
			contiene = true ;            
	}										
	//Email
	if (/^(.+\@.+\..+)$/.test(field)) {
			contiene = true ;            
	}	
	//6 numeros seguidos
	//if (/([0-9][\.\-]*[0-9][\.\-]*[0-9][\.\-]*[0-9][\.\-]*[0-9][\.\-]*[0-9][\.\-]*[0-9])+/.test(field)) {
    if (/([0-9]{7})+/.test(field)) {
			contiene = true ;
	}								
		
	return contiene ;
}

function closeFacebox(){
	$.facebox.close();
	return false;
}

function activeHoverLine(arg){
	$("."+arg.name).each(function(){
		$(this).hover(
			function () {
				$(this).addClass(arg.nameOn);
			}, 
			function () {
				$(this).removeClass(arg.nameOn);
			}
		);
	});	
}

function isValue(name){
	name = $.trim(name);
	if(name.length ==0){
		return false;
	}
	return true;
}

function padText(arg){
	if(arg.char==undefined){
		arg.char=" ";
	}
	if(arg.value.length< arg.total){
		for(l=arg.value.length; l<arg.total; l++){
			if(arg.type=="left"){
				arg.value=arg.char+arg.value;
			} else {
				arg.value+=arg.char;
			}
		}
	}
	return arg.value;
}

function alertFacebox(arg){
	$.facebox({div: '#'+arg.name});
}

function alertFacebox(arg){
	$.facebox({div: '#'+arg.name});
}

function activeConf(arg){
	no=$("#"+arg.id).attr("checked");
	if(!no){
		alertFacebox({'name':arg.divId});
		$("#"+arg.id).attr("checked", true);
	} else if(arg.controlSi){
		alertFacebox({'name':arg.controlSi});
	}
	
}


function confCambio(arg){
	if(arg.value){
		$("#"+arg.id).attr("checked", false);
	}
	closeFacebox();
}

function carga_ofertas_especiales(arg)
{
	url="/index.php/cod.frm_ofertas_especiales/lang."+arg.lang;
	data="tam="+arg.tam;
	if(arg.generica != undefined){
		data+="&generica="+arg.generica;
	}
	if(arg.especial != undefined){
		data+="&especial="+arg.especial;
	}
	getAjax({"type": "POST", "url": url, "data": data, "dataType": "html", "funcion": "print_carga_oferta_especiales"});
}

function getAjax(arg){
	//alert(arg.url+"?"+arg.data);
	$.ajax({
		type: arg.type,
		url: arg.url,
		data: arg.data,
		dataType: arg.dataType,
		success: eval(arg.funcion)
	});
}


function print_carga_oferta_especiales(data){
	$("#ofertas_especiales").html(data);
	if ($("#bloque_red").html() != null){
		setTimeout("changeBanner()", 300);
	}
}

function changeBanner(){
	$("#oferta_premium").each(function(){
		$(this).hover(
			function () {
				$("#bloque_red").css("display", "none");
				$("#bloque_central").css("display", "");
			}, 
			function () {
				$("#bloque_red").css("display", "");
				$("#bloque_central").css("display", "none");
			}
		);
	});
}

function abrir_sello(calcSello)
{
	//antiguedad,validado,nivel_seguridad
	var pintaSep = 0;
	var cadena_inicial='<div class="bloque_detalle_confianza">';
	cadena_inicial+='<div class="bloque_izq_confianza" title="' + $("#sello_seguridad").val() + '">';
	cadena_inicial+='<span class="sello_ini"></span>';
	cadena_inicial+='<span class="sello_centro">' + $("#confianza").val() + '</span>';
	cadena_inicial+='<span class="sello_confianza">'+calcSello.nivel_seguridad+'</span>';
	cadena_inicial+='</div>';
	cadena_inicial+='<div class="bloque_izq_confianza detalle_sello">';
	cadena_inicial+='<ul>';
	if (calcSello.antiguedad!='')
	{
		if(!isNaN(calcSello.antiguedad)){
			antiguedad_n= new Number(calcSello.antiguedad);
			if (antiguedad_n==1)
			{
				cadena_inicial+='<li class="nivel">' + $("#antiguedad_1").val() + '</li>';
			}
			if (antiguedad_n>1)
			{
				cadena_inicial+='<li class="nivel">' + $("#antiguedad_2").val() + '</li>';
			}
			pintaSep = 1;
		}
	}

	if (calcSello.validado!='')
	{
		if (pintaSep == 1)
		{
			cadena_inicial+='<li class="nivel_linea"></li>';
		}		
		cadena_inicial+='<li class="nivel">' + $("#direccion_v").val() + '</li>';
		pintaSep = 1;
	}
	if (calcSello.api)
	{
		if (pintaSep == 1)
		{
			cadena_inicial+='<li class="nivel_linea"></li>';
		}		
		cadena_inicial+='<li class="nivel">' + $("#api").val() + '</li>';
	}
	
	cadena_inicial+='</ul>';
	cadena_inicial+='<div><a href="' + $("#confianza_url").val() + '" target="_blank">' + $("#mas_info").val() + '</a></div>';
	cadena_inicial+='</div>';
	cadena_inicial+='</div>';
	$("#ver").html(cadena_inicial);
	setTimeout('alertFacebox({"name":"ver"})', 500);
	return false;
} 

function inicioReady()
{
}