﻿// Archivo JScript

/************** BASICOS ****************/
function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i) ==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i) ==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}

function getMonth(month){
    
    switch(month){
        case '1':
            return 'Enero';
            break;
        case '2':
            return 'Febrero';
            break;
        case '3':
            return 'Marzo';
            break;
        case '4':
            return 'Abril';
            break;
        case '5':
            return 'Mayo';
            break;
        case '6':
            return 'Junio';
            break;
        case '7':
            return 'Julio';
            break;
        case '8':
            return 'Agosto';
            break;
        case '9':
            return 'Septiembre';
            break;
        case '10':
            return 'Octubre';
            break;
        case '11':
            return 'Noviembre';
            break;
        case '12':
            return 'Diciembre';
            break;
        default: 
            return '';
            break;
    }
}

//********************************************************//
//********* Funciones de codificacion de texto ***********//
//********************************************************//

 function encodeMyHtml(html) {
     encodedHtml = html;
     encodedHtml = encodedHtml.replace(/\//g,"%2F");
     encodedHtml = encodedHtml.replace(/\?/g,"%3F");
     encodedHtml = encodedHtml.replace(/=/g,"%3D");
     encodedHtml = encodedHtml.replace(/&/g,"%26");
     encodedHtml = encodedHtml.replace(/@/g,"%40");
     encodedHtml = encodedHtml.replace(/\+/g,"%2B");
     return encodedHtml;
   } 

/*************** POP UPS **************/

function abrirrecorridos08(tipo){
    _ancho = 500;
    _alto = 630;	
    _left = (document.viewport.getWidth()/2) - (_ancho/2);
	_top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/recorridos08.aspx?r='+tipo, 'recorridos08', 'scrollbars=no,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function abrirmensaje(idu_to, idmensaje, subject){		
	 _ancho = 570;
     _alto = 465;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/mensajes.aspx?idu='+idu_to+'&idm='+idmensaje+'&subject='+subject, 'Mensajes_'+idmensaje, 'scrollbars=no,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function abrircondicioneslopd(){		
	 _ancho = 870;
     _alto = 700;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/condiciones.aspx', 'CondicionesLOPD', 'scrollbars=yes,resizable=yes,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function abrirmensajeenviado(idu, idmensaje){		
	 _ancho = 570;
     _alto = 465;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/mensajes.aspx?ide='+idu+'&idm='+idmensaje, 'Mensajes_'+idmensaje, 'scrollbars=no,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function fotousuario(){
     _ancho = 570;
     _alto = 480;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 
	window.open(Path+'pages/pop/upload.aspx?id=1', 'FotoUsuario', 'scrollbars=yes,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function abrirUpload(entidad,id){
     _ancho = 570;
     _alto = 480;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 
	window.open(Path+'pages/pop/upload.aspx?e='+entidad+'&id='+id, 'Upload', 'scrollbars=yes,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function abrirqec(){
    _ancho = 700;
    _alto = 700;	
    _left = (document.viewport.getWidth()/2) - (_ancho/2);
	_top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/quienestacorriendo.aspx', 'recorridos08', 'scrollbars=no,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function verCorredor(id,k) {
    _ancho = 700;
    _alto = 550;	
    _left = (document.viewport.getWidth()/2) - (_ancho/2);
	_top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/ficha.aspx?k='+k, 'ficha'+id, 'scrollbars=yes,resizable=yes,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);

}

function abrirBuzonEV(id,idpd){		
	_ancho = 700;
    _alto = 500;	
    _left = (document.viewport.getWidth()/2) - (_ancho/2);
	_top = (document.viewport.getDimensions().height/2) - (_alto/2);
	window.open(Path+'pages/pop/evbuzon.aspx?id='+id+'&idpd='+idpd,'buzonev','scrollbars=no,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
	
	
}

function imprimirPlanEntrenamiento(i,m,f){
     _ancho = 700;
     _alto = 480;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 
	window.open(Path+'pages/pop/evprint.aspx?ip='+i+'&m='+m+'&f='+f, 'ImprimirPE', 'scrollbars=yes,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function imprimirJustificante(){
     _ancho = 670;
     _alto = 700;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 
	window.open(Path+'pages/pop/justificante.aspx', 'ImprimirJustificante', 'scrollbars=yes,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function imprimirDiploma(key){
     _ancho = 670;
     _alto = 700;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 
	window.open(Path+'pages/pop/diploma.aspx?k='+key, 'ImprimirDiploma', 'scrollbars=yes,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);

}

function imprimirClasificacion(key){
     _ancho = 670;
     _alto = 700;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 
	window.open(Path+'pages/pop/clasificacionprint.aspx?e='+key, 'ImprimirClasificacion', 'scrollbars=yes,resizable=no,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);

}



function abrirGaleria(e){		
	 _ancho = 750;
     _alto = 548;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 var fecha = new Date();
     var str = '';
     str = fecha.getDay()+'_'+parseInt(fecha.getMinutes())+'_'+parseInt(fecha.getSeconds())+'_'+parseInt(fecha.getMilliseconds())
	window.open(Path+'pages/pop/galeria.aspx?e='+encodeMyHtml(e), 'FotosGaleria_'+str, 'scrollbars=no,resizable=yes,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
}

function abrirThumb(e){		
	 _ancho = 910;
     _alto = 470;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	 var fecha = new Date();
     var str = '';
     str = fecha.getDay()+'_'+parseInt(fecha.getMinutes())+'_'+parseInt(fecha.getSeconds())+'_'+parseInt(fecha.getMilliseconds())
	window.open( e , 'FotosGaleria_'+str, 'scrollbars=no,resizable=yes,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
   }

function subirFotos(tipo){
     _ancho = 750;
     _alto = 560;	
     _left = (document.viewport.getWidth()/2) - (_ancho/2);
	 _top = (document.viewport.getDimensions().height/2) - (_alto/2);
	   
	window.open(Path+'pages/pop/multiupload.aspx?tipo='+tipo, 'SubirFotos', 'scrollbars=yes,resizable=yes,status=no,width='+_ancho+',height='+_alto+',top='+_top+',left='+_left);
    
}


/*********** VALIDACIONES *************/

function IsEmail(sText){
    var s = '';
    s = trim(sText);
    
    if(sText.length == s.length){
        var filter =/^(.+)@(.+)$/;
        if (sText.length == 0 ) return false;
        if (filter.test(sText)){
            return true;
        }else{
            return false;}
    } else {return false;}
}

function IsPhone(sText){
    if (sText.length >0){
			    if(!(IsNumeric(sText))){ return false;}
			    else{
			        if(sText.length < 9){return false;}
			        else
			            return true;
			        }
    } else {return false;}
}

function SoloNumeros(e){
        
    tecla = (document.all) ? e.keyCode : e.which; 
    //alert(tecla);
    if ((tecla < 48 || tecla > 57) && (tecla != 44)) { 
        try{
            e.keyCode=0; 
        } catch(e){}
        
        return false;
    } 
    else {return true; }

}

function SoloAlphaNumericos(e){
        
    tecla = (document.all) ? e.keyCode : e.which; 
    //alert(tecla);
    if ((tecla < 225 || tecla > 255) && (tecla < 65 || tecla > 90) && (tecla < 97 || tecla > 122) && (tecla < 48 || tecla > 57) && (tecla != 8) && (tecla != 32)) { 
        try{
            e.keyCode=0; 
        } catch(e){}
        
        return false;
    } 
    else {return true; }

}

function IsNumeric(sText){
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function IsAlphaNumeric(sText){
   var ValidChars = '0123456789abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ áéíóúÁÉÍÓÚ';
   var IsCorrect=true;
   var Char;
   for (i = 0; i < sText.length && IsCorrect == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsCorrect = false;
         }
      }
   if (sText.length == 0){IsCorrect = false;}
   return IsCorrect;   
}

function IsDNI(sText){
    if ((sText.substr(0,1) =='X') || (sText.substr(0,1) =='x')){
		sText = sText.substr(1,sText.length-1);		
	}
	numero = sText.substr(0,sText.length-1);
	let = sText.substr(sText.length-1,1);
	numero = numero % 23;
	letra='TRWAGMYFPDXBNJZSQVHLCKET';
	letra=letra.substring(numero,numero+1);
	let = let.toUpperCase();
	if (letra!=let){return false;}
	else {return true;}
}

function IsDate(sText){

    var Fecha= new String(sText);	// Crea un string
	var RealFecha= new Date();	// Para sacar la fecha de hoy
	// Cadena Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
	// Cadena Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")));

	// Valido el año
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1800){
        	
		return false;
	}
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		
		return false;
	}
	// Valido el Dia
	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){
		
		return false;
	}
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
			//Si es febrero y dia 29 debo mirar si es año bisiesto
			if(Mes == 2 && Dia == 29){
			    var Resto = Ano%4;
			    if(Resto == 0){
			        Resto = Ano%100;
			        if(Resto == 0) {
			            Resto = Ano%400;
			            if (Resto != 0){
			                return false;
			            }
			           
			        }
			        
			    } else {return false;}
			}
			else {
			    return false;
			}
		}
	}

  return true;	

}

function ocultarMostrarIconosValidacion(imgOk,imgError,correcto){
    if(correcto){
        $(imgOk).setStyle({display:'',visibility:'visible'});
        $(imgError).setStyle({display:'none',visibility:'hidden'});
    } else {
        $(imgOk).setStyle({display:'none',visibility:'hidden'});
        $(imgError).setStyle({display:'',visibility:'visible'});        
    }
}

function ocultarIconosValidacion(imgOk,imgError){
    $(imgError).setStyle({display:'none',visibility:'hidden'});
    $(imgOk).setStyle({display:'none',visibility:'hidden'});
}

/************************** MISCELANEO *************************/

function initGoogle(){
    try{
        initialize();
    }
    catch(e){}
    
}

/********************* NAVEGACION ****************************/
function refreshParentAndClose() {
    try{
        window.opener.location.href=window.opener.location.href;
       }
       catch(e) {}
    window.close();
}

function refreshWindow(){
    location.href = location.href;
}

function backWindow(){
    history.back();
}

function closeWindow(){
    window.close();
}