// ver contenidos //

function fijarcolor(opcion){
	document.getElementById('pos1').style.visibility="hidden";
	document.getElementById('pos2').style.visibility="hidden";
	document.getElementById('pos3').style.visibility="hidden";	
	document.getElementById('pos4').style.visibility="hidden";
	document.getElementById('pos5').style.visibility="hidden";	
	document.getElementById('pos6').style.visibility="hidden";
	document.getElementById(opcion).style.visibility="visible";
}

function fijarcolor2(opcion){
	document.getElementById('presen').style.visibility="hidden";
	document.getElementById('perfil').style.visibility="hidden";
	document.getElementById('metodo').style.visibility="hidden";	
	document.getElementById('admision').style.visibility="hidden";
	document.getElementById('calidad').style.visibility="hidden";	
	document.getElementById('seminarios').style.visibility="hidden";
	document.getElementById(opcion).style.visibility="visible";
}

function vercon(capaid) {
	for (x = 1; x < 14; x++){document.getElementById('content'+ x).style.display="none";}
	document.getElementById(capaid).style.display="block";
}

function vercon3(capaid) {
	for (x = 1; x < 9; x++){document.getElementById('content'+ x).style.display="none";}
	document.getElementById('content'+ capaid).style.display="block";
}

function vercon4(serie,capaid,tot) {
	for (x = 1; x < tot; x++){document.getElementById(serie+x).style.display="none";}
	document.getElementById(serie+capaid).style.display="block";
}
	
// main function to process the fade request //
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}

// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}

// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}

// ver capas // onmouseover="colorFade('boton','background','C4D6D1','598F94',25,25)" onmouseout="colorFade('boton','background','598F94','C4D6D1',25,25)"
function ver(capaid) {
	document.all['texto'].style.display="none";
	document.all['texto2'].style.display="none";
  	for (x = 1; x < 10; x++){document.all['boton'+ x+'p' ].style.display="none";}
	if (capaid == "boton3p"){
		document.all['texto'].style.display="block";
		document.all[capaid].style.display="block";
		vercon(capaid);}
	else{ if (capaid == "boton4p"){
		document.all['texto2'].style.display="block";
		document.all[capaid].style.display="block";
		vercon(capaid);}
		else{
		document.all[capaid].style.display="block";
		vercon(capaid);}}
}

function ver2(capaid) {
  	for (x = 1; x < 9; x++){document.all['boton'+ x+'p' ].style.display="none";}
		document.all[capaid].style.display="block";
		vercon(capaid);
}

//solicitud informacion//
function valuenotempty(element,message){
	if (element.value!='') return '';
	if (message=='') message="Por favor introduzca "+element.name+".\n";
	return message;
}

function validemail(element,message){
	var check=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(!check.test(element.value)){
		if(message=='')message=element.name+" no es un email v&aacute;lido.\n";
		return message;
	}
	return '';
}

function submitForm(){
	document.formularioSolicitud.submit();
}

function submitForm2(){
	document.formularioSolicitud2.submit();
}

function validacion(page){
	error='';
	error+=valuenotempty(document.formularioSolicitud.nombre,"Debe introducir un Nombre\n");
	error+=valuenotempty(document.formularioSolicitud.apellidos,"Debe introducir un Apellido\n");
	error+=valuenotempty(document.formularioSolicitud.localidad,"Debe introducir su Población\n");
	error+=validemail(document.formularioSolicitud.email,"Debe introducir una dirección de correo válida.\n");
	error+=valuenotempty(document.formularioSolicitud.telefono1,"Debe introducir un Teléfono de contacto\n");
	error+=esFecha(document.formularioSolicitud,"Debe introducir fecha correctamete dd/mm/aaaa\n");
	error+=confirmar(document.formularioSolicitud.confirmar,"Debe confirmar que da el consentimiento expreso");
    return error;
}

function validacion2(page){
	error='';
	error+=valuenotempty(document.formularioSolicitud2.nombre1,"Debe introducir un Nombre\n");
	error+=valuenotempty(document.formularioSolicitud2.apellidos1,"Debe introducir un Apellido\n");
	error+=valuenotempty(document.formularioSolicitud2.localidad1,"Debe introducir su Población\n");
	error+=validemail(document.formularioSolicitud2.email1,"Debe introducir una dirección de correo válida.\n");
	error+=valuenotempty(document.formularioSolicitud2.telefono11,"Debe introducir un Teléfono de contacto\n");
	error+=confirmar(document.formularioSolicitud2.confirmar1,"Debe confirmar que da el consentimiento expreso");
    return error;
}

function validarSubmit(element,action){
	error=validacion(0);if(error!=''){alert(error);}else submitForm();
}

function validarSubmit2(element,action){
	error=validacion2(0);if(error!=''){alert(error);}else submitForm2();
}

function resetForm(){
	document.formularioSolicitud.reset();
}

function resetForm2(){
	document.formularioSolicitud2.reset();
}

function esFecha(formulario,message)
{
	var elDia=formulario.dia.value;
	var elMes=formulario.mes.value;
	var elAnio=formulario.anio.value;
	if(elDia=="" && elMes=="" && elAnio=="")return "";
	elMes = elMes-1;
	var ff = new Date(elAnio, elMes, elDia);
	if ( ff.getDate() != elDia ) return message;
	if ( ff.getMonth() != elMes ) return message;
	if ( ff.getFullYear() != elAnio ) return message;
	return "";
}
function confirmar(element,message){
	if(element.checked==false)return message;
	return "";
}


function mostrar(valor) {
	elem=document.getElementById("tabla");
	fila=elem.getElementsByTagName('tr');
	var yea=document.getElementById("tabla").rows.length;
	for(i=0;i<yea;i++) {
		if(document.getElementById("tabla").rows[i].cells[0].innerHTML==valor){fila[i].style.display='block';}
		else{fila[i].style.display='none';}
	}}

function mostrartodo(){
	var yea=document.getElementById("tabla").rows.length;	
	for(j=0;j<yea;j++){fila[j].style.display='block';}
  	}
	
function valida_envia(){
    //valido el nombre
	nb = document.getElementById("nombre") 
    if (nb.value==''){
       alert("Debe escribir su nombre")
       document.getElementById("nombre").focus()
       return 0;
    }
	
	//valido los apellidos
	nb = document.getElementById("apellidos") 
    if (nb.value==''){
       alert("Debe escribir sus apellidos")
       document.getElementById("apellidos").focus()
       return 0;
    }
	
	//valido la localidad
	nb = document.getElementById("localidad") 
    if (nb.value==''){
       alert("Debe escribir una localidad")
       document.getElementById("localidad").focus()
       return 0;
    }
	
	//valido la provincia
	nb = document.getElementById("idProvincia") 
    if (nb.value==0){
       alert("Debe seleccionar una provincia")
       document.getElementById("idProvincia").focus()
       return 0;
    }
	
	//valido el email
	nb = document.getElementById("email") 
    if (nb.value==''){
       alert("Debe indicarnos un email")
       document.getElementById("email").focus()
       return 0;
    }
	
	//valido el pais
	nb = document.getElementById("idPais") 
    if (nb.value==0){
       alert("Debe indicarnos un País")
       document.getElementById("idPais").focus()
       return 0;
    }

	//valido el tlf1
	nb = document.getElementById("telefono1") 
    if (nb.value==0){
       alert("Debe indicarnos un teléfono")
       document.getElementById("telefono1").focus()
       return 0;
    }
	
	//valido el checkbox
	nb = document.getElementById("confirmar") 
	if (nb.checked==false){
	alert("Por favor, marque la casilla de dar su consentimiento");return false; }


    //el formulario se envia
    alert("Gracias por enviar su solicitud. Un Consultor se pondrá en contacto con usted en unos días");
     document.getElementById("formularioSolicitud").submit();
}

