
var BrowserDetect = {
       init: function () {
          this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
          this.version = this.searchVersion(navigator.userAgent)
             || this.searchVersion(navigator.appVersion)
             || "an unknown version";
          this.OS = this.searchString(this.dataOS) || "an unknown OS";
       },
    searchString: function (data) {
       for (var i=0;i<data.length;i++) {
          var dataString = data[i].string;
          var dataProp = data[i].prop;
          this.versionSearchString = data[i].versionSearch || data[i].identity;
          if (dataString) {
             if (dataString.indexOf(data[i].subString) != -1)
                return data[i].identity;
          }
          else if (dataProp)
          return data[i].identity;
       }
    },
    searchVersion: function (dataString) {
       var index = dataString.indexOf(this.versionSearchString);
       if (index == -1) return;
       return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
       { string: navigator.userAgent,
          subString: "OmniWeb",
          versionSearch: "OmniWeb/",
          identity: "OmniWeb"
       },
    {
       string: navigator.vendor,
       subString: "Apple",
       identity: "Safari"
    },
    {
       prop: window.opera,
       identity: "Opera"
    },
    {
       string: navigator.vendor,
       subString: "iCab",
       identity: "iCab"
    },
    {
       string: navigator.vendor,
       subString: "KDE",
       identity: "Konqueror"
    },
    {
       string: navigator.userAgent,
       subString: "Firefox",
       identity: "Firefox"
    },
    {
       string: navigator.vendor,
       subString: "Camino",
       identity: "Camino"
    },
    { // for newer Netscapes (6+)
       string: navigator.userAgent,
       subString: "Netscape",
       identity: "Netscape"
    },
    {
       string: navigator.userAgent,
       subString: "MSIE",
       identity: "Explorer",
       versionSearch: "MSIE"
    },
    {
       string: navigator.userAgent,
       subString: "Gecko",
       identity: "Mozilla",
       versionSearch: "rv"
    },
    { // for older Netscapes (4-)
       string: navigator.userAgent,
       subString: "Mozilla",
       identity: "Netscape",
       versionSearch: "Mozilla"
    }
    ],
    dataOS : [
    {
       string: navigator.platform,
       subString: "Win",
       identity: "Windows"
    },
    {
       string: navigator.platform,
       subString: "Mac",
       identity: "Mac"
    },
    {
       string: navigator.platform,
       subString: "Linux",
       identity: "Linux"
    }
]

};
BrowserDetect.init();

//script para poner estilos distintos para cada navegador
if (BrowserDetect.browser == "Firefox") {
    document.write("<link href='styles_neu_2_firefox.css' rel='stylesheet' type='text/css' />");
}
else {
    if (BrowserDetect.browser == "Explorer"){
       if (BrowserDetect.version>=7){
          document.write("<link href='styles_neu_2_ie7.css' rel='stylesheet' type='text/css' />");
       }else{
          document.write("<link href='styles_neu_2_ie7.css' rel='stylesheet' type='text/css' />");
       }
    }else{
       if (BrowserDetect.browser == "Opera"){
          if (BrowserDetect.version<9){
             document.write("<link href='styles_neu_2_firefox.css' rel='stylesheet' type='text/css' />");
          }else{
             document.write("<link href='styles_neu_2_firefox.css' rel='stylesheet' type='text/css' />");
          }
       }else{
          document.write("<link href='styles_neu_2_firefox.css' rel='stylesheet' type='text/css' />");
       }
    }
} 



function motivos_mostrarimagen(imagen){ // Mostrar imagen en motivos (En mitransportista para mostrar laiamgen de las estadísticas);
document.getElementById(imagen).style.display="";
document.location.href="#imagen";
}

function limita_caracteres(area_texto,max){
	if(area_texto.value.length>=max){
		area_texto.value=area_texto.value.substring(0,max);
		alert("Máximo número de carácteres permitidos: "+max);
	}
}

function color(recibe_color){
var color2=mod_3colores(recibe_color,60,60,60);


var color=mod_color(recibe_color,60);
document.getElementById('head_h1_sombra').style.color=color;
document.getElementById('head_h1_fondo_sombra').style.color=color;
document.getElementById('encabezado_seccion_color').style.backgroundColor=color;

/*document.getElementById('fondo_empresa').style.color=recibe_color;*/

document.getElementById('boletin_nombre').focus();
}
function check_buscador(form3,links){
	if (document.form3.buscado.value==""){
		alert('Por favor escriba el término que está buscando. Gracias');	
		document.getElementById('buscado').focus();
	}else{		
		form3.action='index.php?buscar=1'+links;
		document.form1.submit();
	}	
}
function check_contacto(form1){
	if (document.form1.name.value=="" || document.form1.email.value=="" || document.form1.message.value==""){
		alert('Por favor rellene al menos Nombre, Email y Mensaje');	
	}else{		
		form1.action="envio_contacto.php"
		document.form1.submit();
	}	
}

function check_boletin(boletin,links){

	if (document.boletin.boletin_nombre.value=="" || document.boletin.boletin_empresa.value=="" || document.boletin.boletin_email.value=="" || document.boletin.boletin_sector.value=="" || document.boletin.boletin_email.value.indexOf('@', 0) == -1 || document.boletin.boletin_email.value.indexOf('.', 0) == -1){
		if (document.boletin.boletin_email.value.indexOf('@', 0) == -1 ||
			document.boletin.boletin_email.value.indexOf('.', 0) == -1){
			alert("Dirección de e-mail inválida");
			document.boletin.boletin_email.focus();
			return;
		}
		alert('Si desea darse de alta en nuestro boletín (Newsletter), debe introducir su nombre, su empresa, su email y elejir el sector de su empresa.');	
	}else{		
		document.boletin.action="index.php?boletin=1"+links;
		document.boletin.submit();
	}	
}


function check_amigo(form1,url){
	if (document.form1.nombre_amigo.value=="" || document.form1.email_amigo.value=="" || document.form1.nombre.value==""){
		alert('Por favor rellene al menos su nombre y el nombre y dirección de correo a quien desea enviar la información. Gracias.');	
	}else{		
		form1.action="index.php?enviar_amigo=1"+url;
		document.form1.submit();
	}	
}

function mod_3colores(color,graduacion1,graduacion2,graduacion3){
	rgb = new Array(3);
	rgb[0] = hexadec(color.substr(0, 2));
	rgb[1] = hexadec(color.substr(2, 2));
	rgb[2] = hexadec(color.substr(4, 2));
	//alert(rgb[0]+" "+rgb[1]+" "+rgb[2]);

		rgb[0]=(rgb[0]+graduacion1);
		if(rgb[0]>255){rgb[0]=255;}
		if(rgb[0]<0){rgb[0]=0;}
		//alert("0 "+rgb[0]);

		rgb[1]=(rgb[1]+graduacion2);
		if(rgb[1]>255){rgb[1]=255;}
		if(rgb[1]<0){rgb[1]=0;}

		rgb[2]=(rgb[2]+graduacion3);
		if(rgb[2]>255){rgb[2]=255;}
		if(rgb[2]<0){rgb[2]=0;}

	rgb[0]=decahex(rgb[0]);
	rgb[1]=decahex(rgb[1]);
	rgb[2]=decahex(rgb[2]);
	
	//alert("#"+rgb[0]+" "+rgb[1]+" "+rgb[2]);
	return rgb[0]+rgb[1]+rgb[2];
}

function mod_color(color,graduacion){
	rgb = new Array(3);
	rgb[0] = hexadec(color.substr(0, 2));
	rgb[1] = hexadec(color.substr(2, 2));
	rgb[2] = hexadec(color.substr(4, 2));
	//alert(rgb[0]+" "+rgb[1]+" "+rgb[2]);
	if(rgb[0]>=rgb[1] && rgb[0]>=rgb[2]){
		rgb[0]=(rgb[0]+graduacion);
		if(rgb[0]>255){rgb[0]=255;}
		if(rgb[0]<0){rgb[0]=0;}
		//alert("0 "+rgb[0]);
	}else if (rgb[1]>=rgb[0] && rgb[1]>=rgb[2]){
		rgb[1]=(rgb[1]+graduacion);
		if(rgb[1]>255){rgb[1]=255;}
		if(rgb[1]<0){rgb[1]=0;}
		//alert("1 "+rgb[1]);
	}else{
		rgb[2]=(rgb[2]+graduacion);
		if(rgb[2]>255){rgb[2]=255;}
		if(rgb[2]<0){rgb[2]=0;}
		//alert("2 "+rgb[2]);
	}
	rgb[0]=decahex(rgb[0]);
	rgb[1]=decahex(rgb[1]);
	rgb[2]=decahex(rgb[2]);
	
	//alert("#"+rgb[0]+" "+rgb[1]+" "+rgb[2]);
	return rgb[0]+rgb[1]+rgb[2];
}

function ini(colorphp)    { 
    var colores = transitar(colorphp, "ffffff", 64);
    var elFondo = document.getElementById("fondo").style; 
    var ancho = document.body.clientWidth; 
    var alto =  document.body.clientHeight; 
    elFondo.width = ancho; 
    elFondo.height = alto; 
    var altoCelda = alto / 256; 
    var tabla = "<table cellpadding=0 cellspacing=0 width=100% height=100%>"; 
    for (var i = 0; i < colores.length; i ++) 
        tabla += "<tr><td width=100% height=" + altoCelda + " style='background-color: " + colores[i] + "' ></td></tr>" 
    tabla += "</table>"; 
    document.getElementById("fondo").innerHTML = tabla; 
} 

function decahex(n) {
	return hexa.charAt(n / 16) + hexa.charAt(n % 16);
}

function colorHexa(c) {
	return "#" + decahex(c[0]) + decahex(c[1]) + decahex(c[2]);
}

function transitar(ini, fin, pasos) {
	var dato = desglose(ini);
	var rIni = dato[0];
	var gIni = dato[1];
	var bIni = dato[2];

	var intermedios = new Array(pasos);
	intermedios[0] = dato;

	var dato = desglose(fin);

	intermedios[pasos - 1] = dato;

	var rFin = dato[0];
	var gFin = dato[1];
	var bFin = dato[2];

	var rMed = (rFin - rIni) / (pasos - 1);
	var gMed = (gFin - gIni) / (pasos - 1);
	var bMed = (bFin - bIni) / (pasos - 1);

	for (var i = 1; i < pasos - 1; i ++)	{
		var rgb = new Array(3);
		rgb[0] = parseInt(rIni + (rMed * i));
		rgb[1] = parseInt(gIni + (gMed * i));
		rgb[2] = parseInt(bIni + (bMed * i));
		intermedios[i] = rgb;
	}
	for (i = 0; i < intermedios.length; i ++)
		intermedios[i] = colorHexa(intermedios[i]);

	return intermedios;
}

function desglose(color) {
	if (color.length != 6)
		return "poblema";
	else	{
		devolver = new Array(3);
		devolver[0] = hexadec(color.substr(0, 2));
		devolver[1] = hexadec(color.substr(2, 2));
		devolver[2] = hexadec(color.substr(4, 2));
	}
	return devolver;
}
var hexa = "0123456789abcdef";

function hexadec(x) {
	x = x.toLowerCase();
	return parseInt(hexa.indexOf(x.charAt(0))) * 16 + parseInt(hexa.indexOf(x.charAt(1)))
}
function printWindow() {
bV = parseInt(navigator.appVersion);
if (bV >= 4) window.print();
}

function compruebavacio(){
	var control=1;	
	var cadena="";
	if(document.form1.titulo.value==''){
		cadena+="- Título.\n";
		control=0;
	}
	if(document.form1.url.value==''){
		cadena+="- Url.\n";
		control=0;
	}
	if(document.form1.url_reciproco.value==''){
		cadena+="- Url del enlace recíproco.\n";
		control=0;
	}
	if(document.form1.nombre.value==''){
cadena+="- Persona de contacto.\n";
		control=0;
	}
	if(document.form1.email.value==''){
		cadena+="- Email.\n";
		control=0;
	}else if (document.form1.email.value.indexOf('@', 0) == -1 ||
		form1.email.value.indexOf('.', 0) == -1){
		cadena+="- La dirección de Email Introducida es incorrecta.\n";
		document.boletin.boletin_email.focus();
	}

	
	if(form1.CAPTCHA_CODE.value=='')
	{
		cadena+="- Código de validación.\n";
		control=0;
	}
	if(control==1){
		form1.submit();
	}else{
		alert("Por favor, complete los campos: \n"+cadena);
	}
}