// JavaScript Document


function cambiar_capa2(opcion){

  if (opcion=='0'){  
  document.getElementById('insertar_espanyol').style.visibility="hidden";
  document.getElementById('insertar_ingles').style.visibility="visible";  
  document.getElementById('celda_idiomas').style.background="url(../img/gestor/nuestrostrabajos_eng.gif)";
  }else{  
  document.getElementById('insertar_ingles').style.visibility="hidden";
  document.getElementById('insertar_espanyol').style.visibility="visible";
  document.getElementById('celda_idiomas').style.background="url(../img/gestor/nuestrostrabajos_esp.gif)";
  }
}



function cambiar_capa(opcion){

  if (opcion=='0'){  
  document.getElementById('insertar_espanyol').style.display='none';
  document.getElementById('insertar_ingles').style.display='block';  
  document.getElementById('celda_idiomas').style.background="url(../img/gestor/nuestrostrabajos_eng.gif)";
  }else{  
  document.getElementById('insertar_ingles').style.display='none';
  document.getElementById('insertar_espanyol').style.display='block';  
  document.getElementById('celda_idiomas').style.background="url(../img/gestor/nuestrostrabajos_esp.gif)";
  } 
}


function confirmar7(form)
{
alert('eleccion');
var respuesta = confirm("Registrar Venta?");
if (!respuesta){
return false;
}
}
function confirmar(form){
    if (confirm('¿Estas seguro de enviar este formulario?')){
       document.form_insertar.submit()
    }
} 



function IsNumeric(valor)
{
var log=valor.length; var sw="S";
for (x=0; x<log; x++)
{ v1=valor.substr(x,1);
v2 = parseInt(v1);
//Compruebo si es un valor numérico
if (isNaN(v2)) { sw= "N";}
}
if (sw=="S") {return true;} else {return false; }
}

var primerslap=false;
var segundoslap=false;

function formateafecha(fecha)
{
var long = fecha.length;
var dia;
var mes;
var ano;

if ((long>=2) && (primerslap==false)) { dia=fecha.substr(0,2);
if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); primerslap=true; }
else { fecha=""; primerslap=false;}
}
else
{ dia=fecha.substr(0,1);
if (IsNumeric(dia)==false)
{fecha="";}
if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; }
}
if ((long>=5) && (segundoslap==false))
{ mes=fecha.substr(3,2);
if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; }
else { fecha=fecha.substr(0,3);; segundoslap=false;}
}
else { if ((long<=5) && (segundoslap=true)) { fecha=fecha.substr(0,4); segundoslap=false; } }
if (long>=7)
{ ano=fecha.substr(6,4);
if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); }
else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } }
}

if (long>=10)
{
fecha=fecha.substr(0,10);
dia=fecha.substr(0,2);
mes=fecha.substr(3,2);
ano=fecha.substr(6,4);
// Año no viciesto y es febrero y el dia es mayor a 28
if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; }
}
return (fecha);
}


function validar_insertar_evento(form_insertar,descripcion){ //funcion validar insertar evento
  var eleccion = false;
  /*alert('Valor ' + form_contacto.nombre.value);*/
  if(form_insertar.titulo.value == '' ){alert('El campo TITULO es obligatorio');}else{
  if(form_insertar.fecha_ini.value == '' ){alert('El campo FECHA INICIAL es obligatorio');}else{
  if(form_insertar.fecha_fin.value == '' ){alert('El campo FECHA FINAL es obligatorio');}else{
  if(form_insertar.titulo_eng.value == '' ){alert('El campo TITULO de la versión en INGLÉS es obligatorio');}else{
  if(form_insertar.fecha_ini_eng.value == '' ){alert('El campo FECHA INICIAL de la versión en INGLÉS es obligatorio');}else{
  /*if(form.descripcion.value == '' ){alert('dd'+form_insertar.descripcion.value+'El campo DESCRIPCIÓN es obligatorio');}else{ */
  eleccion=true; }}}}}/*}*/
  //alert(eleccion);
  return eleccion;
 }

 
function validar_rrhh(form_rrhh) { //funcion validar formulario de rrhh (curriculum)
  resultado = false; 
  if(form_rrhh.acepto_condiciones.checked == false ){
      alert('Acepte las condiones');
  }else{
      if(form_rrhh.nombre.value == '' ){
          alert('El campo nombre es obligatorio');
      }else{
          if(form_rrhh.apellidos.value == '' ){
	      alert('El campo apellidos es obligatorio');
	  }else{
	      if(form_rrhh.direccion.value == '' ){
	          alert('El campo direccion es obligatorio');
	      }else{	
	          if(form_rrhh.codigo_postal.value == '' ){
		      alert('El campo código postal es obligatorio');
		  }else{
		      if(form_rrhh.telefono.value == '' ){
		          alert('El campo teléfono es obligatorio');
		      }else{
		          if ((form_rrhh.email.value == "") || (form_rrhh.email.value.indexOf('@') == -1) || 
			     (form_rrhh.email.value.indexOf('.') == -1)) {
			     alert('Por favor complete correctamente el campo EMAIL, es obligatorio.');
			  }else{
			      if(form_rrhh.estudios.value == '0' ){
			          alert('El campo estudios es obligatorio, seleccione nivel de estudios');
			      }else{
			          if(form_rrhh.isla.value == '0' ){
				      alert('El campo isla es obligatorio, seleccione isla en la que desea trabajar');
				  }else{
				      if(form_rrhh.idiomas.value == '' ){
				          alert('El campo idiomas es obligatorio');
				      }else{
				          if (confirm('¿Está seguro de enviar el formulario?')){
					      resultado = true;
					  }
				      }
				  }
		              }
			  }
		      }
		  }
	      }
	  }
      }
  }
  return resultado;
}

function validar_rrhh_eng(form_rrhh) { //funcion validar formulario de rrhh (curriculum)
  resultado = false; 
  if(form_rrhh.acepto_condiciones.checked == false ){
      alert('You may accept the conditions');
  }else{
      if(form_rrhh.nombre.value == '' ){
          alert('The Name is obligatory');
      }else{
          if(form_rrhh.apellidos.value == '' ){
	      alert('The Surname is obligatory');
	  }else{
	      if(form_rrhh.direccion.value == '' ){
	          alert('The Address is obligatory');
	      }else{	
	          if(form_rrhh.codigo_postal.value == '' ){
		      alert('The CP is obligatory');
		  }else{
		      if(form_rrhh.telefono.value == '' ){
		          alert('The Phone is obligatory');
		      }else{
		          if ((form_rrhh.email.value == "") || (form_rrhh.email.value.indexOf('@') == -1) || 
			     (form_rrhh.email.value.indexOf('.') == -1)) {
			     alert('Please the field refills correctly E-mail, it is obligatory.');
			  }else{
			      if(form_rrhh.estudios.value == '0' ){
			          alert('The studies is obligatory');
			      }else{
			          if(form_rrhh.isla.value == '0' ){
				      alert('The island is obligatory');
				  }else{
				      if(form_rrhh.idiomas.value == '' ){
				          alert('The Languages is obligatory');
				      }else{
				          if (confirm('¿Are you sure to send the form?')){
					      resultado = true;
					  }
				      }
				  }
		              }
			  }
		      }
		  }
	      }
	  }
      }
  }
  return resultado;
}

 function validar_contacto_eng(form_contacto){ //funcion validar formulario de contacto
  resultado = false;
  if(form_contacto.nombre.value == '' ){alert('The Name is obligatory');}else{
  if(form_contacto.apellidos.value == '' ){alert('The Surname is obligatory');}else{
  if ((form_contacto.email.value == "") || 
   (form_contacto.email.value.indexOf('@') == -1) || 
   (form_contacto.email.value.indexOf('.') == -1)) {alert('Please the field refills correctly E-mail, it is obligatory.');}	else{  	  
  if(form_contacto.telefono.value == '' ){alert('The Phone is obligatory');}else{
  if(form_contacto.asunto.value == '' ){alert('The Subject is obligatory');}else{ 
  if(form_contacto.mensaje.value == '' ){alert('The message is obligatory');}else{
  if (confirm('¿Are you sure to send the form?')){
	  resultado = true; }}}}}}}  
  return resultado;
 }

 function validar_contacto(form_contacto){ //funcion validar formulario de contacto
  resultado = false;  
  if(form_contacto.nombre.value == '' ){alert('El campo nombre es obligatorio');}else{
  if(form_contacto.apellidos.value == '' ){alert('El campo apellidos es obligatorio');}else{
  if ((form_contacto.email.value == "") || 
   (form_contacto.email.value.indexOf('@') == -1) || 
   (form_contacto.email.value.indexOf('.') == -1)) {alert('Por favor complete correctamente el campo EMAIL, es obligatorio.');}	else{  	  
  if(form_contacto.telefono.value == '' ){alert('El campo telefono es obligatorio');}else{
  if(form_contacto.asunto.value == '' ){alert('El campo asunto es obligatorio');}else{ 
  if(form_contacto.mensaje.value == '' ){alert('El campo mensaje es obligatorio');}else{
  if (confirm('¿Está seguro de enviar el formulario?')){
	  resultado = true; }}}}}}}
  return resultado;
 }

function solo_numeros(){
var key=window.event.keyCode;//codigo de tecla.
if (key < 48 || key > 57){//si no es numero 
window.event.keyCode=0;//anula la entrada de texto.
}} 

function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
}


function minifoto(foto,ancho,alto) {
	var newImg = new Image();
        newImg.src = 'img/fotos/'+foto+'.jpg';
	var V = newImg.height;
	var H = newImg.width;
	//alert(H+' * '+V)


        propH = ancho / H;
        propV = alto / V;
        if (propH>propV) {
            anchoF = H * propV;
            altoF = alto;
        }
        else {
            altoF = V * propH;
            anchoF = ancho;	    
        }
        de = (ancho - anchoF) / 2;
        su = (alto - altoF) /2;
        imagen="<div style='width:"+ancho+";height:"+alto+";'>";
        imagen+="<img src='img/fotos/"+foto+".jpg' width="+anchoF+" height="+altoF;
        imagen+=" style='position:relative; left:"+de+";top:"+su+"'>";
        imagen+="</div>";
        document.write(imagen);
    } 

function click_sobre_foto2(i,opcion,foto){
//alert(foto.src);
//alert(i+'.jpg');
if (opcion=='on'){aler('llega');document.getElementById(i).style.background='#656299';
}else{if (opcion=='out'){   
   if (foto.src!='http://localhost/eventos/img/fotos/foto'+i+'.jpg'){    
     document.getElementById('marcador'+i).style.background='#cfcede';}
   else{
     document.getElementById('marcador'+i).style.background='#656299';}
}else{if(opcion=='click'){
   for(j=1;j<=4;j++){     
       document.getElementById('marcador'+j).style.background='#cfcede';
     }   
   document.getElementById('marcador'+i).style.background='#656299';}}}
}

function click_sobre_foto_old(i,opcion,foto,tope){
//alert(foto.src);
//alert(i);
//alert(opcion);
if (opcion=='on'){document.getElementById(i).style.background='#656299';
}else{if (opcion=='out'){   
   if (foto.src!='http://www.eventosencanarias.com/pruebas/esp/img/img_nuestros_trabajos/img/'+i+'.jpg'){
  // if (foto.src!='http://localhost/eventos/esp/img/img_nuestros_trabajos/img/'+i+'.jpg'){    
     document.getElementById(i).style.background='#cfcede';}
   else{
     document.getElementById(i).style.background='#656299';}
}else{

   if(opcion=='click'){
  // alert(foto); 
//  alert(tope);
  
   
     for(j=foto;j<tope;j++){
 // alert(j+'='+i+' tope: '+tope+' foto: '+foto);
     if (j==i){document.getElementById(i).style.background='#656299';}
     else{document.getElementById(j).style.background='#cfcede';}}
  


     
   }}}
}

function click_sobre_foto(i,opcion,id_foto,tope){


if (opcion=='on'){document.getElementById(i).style.background='#656299';
}else{if (opcion=='out'){   

     if (document.getElementById('foto').src!='http://www.eventosencanarias.com/eventosv2/esp/img/img_nuestros_trabajos/img/'+id_foto+'.jpg'){    
     document.getElementById(i).style.background='#cfcede';}
     else{
     document.getElementById(i).style.background='#656299';}
    
}else{

   if(opcion=='click'){
   
//  alert(tope);
  
   
     for(j=1;j<tope;j++){
 //alert(j+'='+i+' tope: '+tope+' foto: '+id_foto);
     if (j==i){document.getElementById(i).style.background='#656299';}
     else{document.getElementById(j).style.background='#cfcede';}}
  


     
   }}}
}


    

