var reAlphanumericEmail =/^[^@]+@[^@]+.[a-z]{2,}$/i;
/* mail*/
evt = ""; // Defeat the Chrome bug

function SoloFecha(eventObj, obj){
	var keyCode;
	if (document.all){
		keyCode=eventObj.keyCode;
	}else{
		keyCode=eventObj.which;
	}
	if((keyCode<48 || keyCode>58)  &&  (keyCode != 45)){
		return false;
	}
	return true;
}
function validaValor(obj){
	var valor = parseInt(obj.value);
	if (valor <= 100){
		return true;
	}else{
		alert('El valor debe ser menor o igual a 100');
		obj.focus();
	}
}

function OnlyNumbers(e)
{
var keynum;
var keychar;
var numcheck;

    if(window.event) // IE
	    {
	    keynum = e.keyCode;
	    }
    else if(e.which) // Netscape/Firefox/Opera
	    {
	    keynum = e.which;
	    }
    keychar = String.fromCharCode(keynum);
    numcheck = /\d/;
    if(!numcheck.test(keychar))
    {
        alert("El n\u00famero de empleado debe ser n\u00famerico");
    }
return numcheck.test(keychar);
}

function SoloNumerico(eventObj){   
    var keyCode;
	if (document.all){
		keyCode=eventObj.keyCode;
	}else{
	    alert(eventObj);
		keyCode=eventObj.which;
	}
	if((keyCode<48 || keyCode >58)){
    	return false;
	}
	return true;
}
		
function SoloNumericoPunto(eventObj, obj){   
	var keyCode;
    if (document.all){
		keyCode=eventObj.keyCode;
	}else{
		keyCode=eventObj.which;
	}
    if((keyCode<48 || keyCode >57) ){
    	if(keyCode != 46){
	    	return false;
	    }	
	}
	return true;
}

   // Creación de un objeto para manejar los errores
   var error= new crear_error();
   
   // Crea un objeto que guarda un mensaje de error y un 
   // indice a la posición donde se ha producido dentro de una cadena
   function crear_error()
   {
   this.mensaje="";
   this.posicion=0;
   this.rellenar=rellenar;
   }
  
   // Método del objeto "crearerror" que rellena el error con un mensaje
   // explicativo y la posición donde se produjo dentro de la cadena validada
   function rellenar(mensaje,posicion)
   {
   this.mensaje=mensaje;
   this.posicion=posicion;
   return false;
   }

   // Determina si un carácter es un número
   function es_numero(car)
   {
   var NUMEROS="0123456789";
   return (NUMEROS.indexOf(car) >= 0)
   }
   
   // Determina si un año es bisiesto
   function es_bisiesto(anio) 
   {
   if (((anio % 4 == 0) && anio % 100 != 0) ||
       anio % 400 == 0) 
      return true;
   return false;
   }

   // Comprueba si una fecha es correcta
   function comprobar_fecha(contenido,error)
   {
   var separador_fecha="/";
   var numero_separadores=0;

   if ((contenido.length == 0))
      return error.rellenar("Campo vacío no contiene ningún valor ",1);

   // Comprobación de la sintáxis de una fecha 
   for (var i=0; i < contenido.length; i++)
      {
      var caracter=contenido.charAt(i);
      if (!es_numero(caracter) && caracter != separador_fecha)
         return error.rellenar("Carácter ilegal en una fecha",i+1); 
      if (caracter == separador_fecha)
        numero_separadores++ 
      }
   if (numero_separadores != 2)
      return error.rellenar("Faltan separadores en una fecha",i+1); 
    
   // Comprobación de la semántica de una fecha
   /*var posicion_separador_1=contenido.indexOf(separador_fecha);
   var dia=contenido.substring(0,posicion_separador_1);
   var posicion_separador_2=contenido.indexOf(separador_fecha,
                                                        posicion_separador_1+1);
   var mes=contenido.substring(posicion_separador_1+1,posicion_separador_2); 
   var anio=contenido.substring(posicion_separador_2+1,10);
   */
   datos = contenido.split("/");
   var dia = datos[1];
   var mes = datos[0];
   var anio = datos[2];
   //alert (dia+" "+mes+" "+anio);
   if (anio.length != 4)
      return error.rellenar("Año incorrecto",6); 
   if (mes < 1 || mes > 12)
      return error.rellenar("Mes incorrecto",4);
   if ((dia < 1 || dia > 31) || (mes == 4 && dia > 30) ||
       (mes == 6 && dia > 30) || (mes == 9 && dia > 30) ||
       (mes == 11 && dia > 30) || (mes == 2 && es_bisiesto(anio) && dia > 29) ||
       (mes == 2 && !es_bisiesto(anio) && dia > 28))
      return error.rellenar("Día incorrecto en una fecha",2);
   return true 
   }
       
function SoloAlfanumerico(eventObj, obj){
	var keyCode;
	if (document.all){
		keyCode=eventObj.keyCode;
	}else{
		keyCode=eventObj.which;
	}
	if((keyCode>90 || keyCode<65) && (keyCode>122 || keyCode<97) && (keyCode>57 || keyCode<48)){
		return false;
	}
	return true;
}

function SoloLetras(eventObj, obj){
	var keyCode;
	if (document.all){
		keyCode=eventObj.keyCode;
	}else{
		keyCode=eventObj.which;
	}
    if((keyCode>90 || keyCode<65) && (keyCode>122 || keyCode<97)){
		return false;
	}
	return true;
}
     
function SoloFecha(eventObj, obj){
	var keyCode;
	if (document.all){
		keyCode=eventObj.keyCode;
	}else{
		keyCode=eventObj.which;
	}
	if((keyCode<48 || keyCode>58)  &&  (keyCode != 45)){
		return false;
	}
	return true;
}

function RangoFechas(FI,FF){
        if ((FI == '') || (FF == '')){
            alert("El rango de fechas es requerido");
            return false;
        }
        var FIA = FI.substring(0,FI.indexOf('-'));
        var FIM = FI.substring(FI.indexOf('-')+1,FI.lastIndexOf('-'));
        var FID = FI.substring(FI.lastIndexOf('-')+1);
        var FFA = FF.substring(0,FF.indexOf('-'));
        var FFM = FF.substring(FF.indexOf('-')+1,FF.lastIndexOf('-'));
        var FFD = FF.substring(FF.lastIndexOf('-')+1);
        var a = 0;
        if (FIA > FFA){
            a=1;
        }
        if ((FIA == FFA) && (FIM > FFM)){
            a=1;
        }
        if ((FIA == FFA) && (FIM == FFM) && (FID > FFD)){
            a=1;
        }
        if (a == 1){
            alert("Debe teclear un rango de fechas valido");
            a=0;
            return false;
        }
        else{
            return true;
        }


}
function FormatoFolio(txt){
        var Folio = trim(txt.value);
        var a=0
        if (!((Folio.length == 17) || (Folio.length == 14) || (Folio.length == 16))){
            a=1;
        }
        else {
            for(i=0;i<Folio.length;i++){
                if((Folio.charCodeAt(i)>90 || Folio.charCodeAt(i)<65) && (Folio.charCodeAt(i)>122 || Folio.charCodeAt(i)<97) && (Folio.charCodeAt(i)>57 || Folio.charCodeAt(i)<48)){ 
                    a=1;
                }
            }    
            for(i=0;i<6;i++){
                if(Folio.charCodeAt(i)<48 || Folio.charCodeAt(i)>58){
                    a=1;
                }
            }
            switch(Folio.length){
                case 17:
                    var parte = Folio.substring(10,12);
                    if(!inicio(parte)){
                        a=1;
                    }
                    var fin = Folio.substring(12,Folio.length);
                    if(!final(fin)){
                        a=1;  
                    }
                    break;
                case 14:
                    var parte = Folio.substring(6,8);
                    if(!inicio(parte)){
                        a=1;
                    }
                    var fin = Folio.substring(9,Folio.length);
                    if(!final(fin)){
                        a=1;
                    }
                    break;
                case 16:
                    var parte = Folio.substring(6,8);
                    if(!inicio(parte)){
                        a=1;
                    }
                    var fin = Folio.substring(11,Folio.length);
                    if(!final(fin)){
                        a=1;                        
                    }
                    break;
            }    
        }
        if (a==1){
            alert("Debe proporcionar un folio de llamada correcto");
            return false;
        }
        else{
            return true;
        }

}
function inicio(parte){
         for(i=0;i<parte.length;i++){
            if((parte.charCodeAt(i)>90 || parte.charCodeAt(i)<65) && (parte.charCodeAt(i)>122 || parte.charCodeAt(i)<97)){ 
                return false; 
            }
         }
         return true;
}
function final(fin){
         for(i=0;i<fin.length;i++){
            if(fin.charCodeAt(i)<48 || fin.charCodeAt(i)>58){
                return false; 
            }
         }
         return true;
}

function vAsignar(forma){
        if(forma["Form1:cmbUsuarios"].selectedIndex < 0){
            alert("Debe seleccionar un Usuario Disponible");
            return false;
        }
   		txt="";
   		Queja = forma.Quejas;
		for (i=0;i<Queja.length;++ i) {
			if (Queja[i].checked) {
				txt=txt + Queja[i].value + "@";
			}
		}
		if (txt == ""){
			alert("Debe seleccionar al menos una Queja para asignar");
			return false;
		}
		forma["Form1:txtFolio"].value = txt;
}
function trim(item) {
    worker = new String(item);
    if (worker.indexOf(" ") != -1) {
     if (worker.indexOf(" ") == 0) {
      worker = worker.substring(1,worker.length);
      trim(worker);
     }
    }
  if (worker.lastIndexOf(" ") != -1) {
    if (worker.lastIndexOf(" ") >= worker.length-1) {
      worker = worker.substring(0,worker.length-1);
      trim(worker);
    }
  }
  return worker;
}


function IndexChar(str2)
{
  var str1 = "°¿´¡¨|@$^()_~`!&#[]{}\"'<>?=%/\\;,:*+-"
  var s = str1.indexOf(str2);
  return(s);
}

function EvitaCaracteres(eventObj) { 
       
       var hh;
	   if (document.all)
		{
			hh=eventObj.keyCode;
		}
	   else
		{
			hh=eventObj.which;
		}
		
       if(IndexChar(String.fromCharCode(hh)) > -1)
         { 
           return false; 
         } 
 
  return true; 
 } 
 
 function IndexCharTelefono(str2)
{
  var str1 = "°¡~`$^!&#[]{}\"'<>?=%/\\;,:*+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.@"
  var s = str1.indexOf(str2);
  return(s);
}
 
 function EvitaCaracteresTelefono(eventObj) { 
       
       var hh;
	   if (document.all)
		{
			hh=eventObj.keyCode;
		}
	   else
		{
			hh=eventObj.which;
		}
		
       if(IndexCharTelefono(String.fromCharCode(hh)) > -1)
         { 
           return false; 
         } 
 
  return true; 
 } 

function IndexCharFecha(str2)
{
  var str1 = "0123456789/-()"
  var s = str1.indexOf(str2);
  return(s);
}

function EvitaCaracteresFecha(eventObj) { 
       
       var hh;
	   if (document.all)
		{
			hh=eventObj.keyCode;
		}
	   else
		{
			hh=eventObj.which;
		}
		
       if(IndexCharFecha(String.fromCharCode(hh)) > -1)
         { 
           return true; 
         } 
 
  return false; 
 }

 
function IndexCharEmail(str2)
{
  var str1 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_.@"
  var s = str1.indexOf(str2);
  return(s);
}

function EvitaCaracteresEmail(eventObj) { 
       
       var hh;
	   if (document.all)
		{
			hh=eventObj.keyCode;
		}
	   else
		{
			hh=eventObj.which;
		}
		
       if(IndexCharEmail(String.fromCharCode(hh)) > -1)
         { 
           return true; 
         } 
 
  return false; 
 }
 

 function validacionEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("El campo Correo Electrónico requiere una dirección de correo valida")
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("El campo Correo Electrónico requiere una dirección de correo valida")
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("El campo Correo Electrónico requiere una dirección de correo valida")
	    return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    alert("El campo Correo Electrónico requiere una dirección de correo valida")
	    return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("El campo Correo Electrónico requiere una dirección de correo valida")
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    alert("El campo Correo Electrónico requiere una dirección de correo valida")
	    return false
	}
	if (str.indexOf(" ")!=-1){
		alert("El campo Correo Electrónico requiere una dirección de correo valida")
		return false
	}
	return true					
 }

function ShowMessage(message)
{
    alert(message);
}

function CountVisit(url)
{
    document.forms[0]['ctl00_cphBody_transferHidden'].value = url;
    document.forms[0]['ctl00_cphBody_VisitaButton'].click();
    document.forms[0]['ctl00_cphBody_transferHidden'].value = '';
}

function open_win(url)
{
window.open(url,'_blank','top=200,left=100,width=350,height=290,resizable=no,location=no')
}
function open_win_youtube(url)
{
window.open(url,'_blank','top=200,left=100,width=590,height=390,resizable=no,location=no')
}
function open_win_audio(url)
{
window.open(url,'_blank','top=200,left=100,width=300,height=100,resizable=no,location=no')
}
function open_evoice(url)
{
window.open(url,"_blank","top=0,left=0,width="+screen.availWidth+",height="+(screen.availHeight-30)+",resizable=yes,location=no,menubar=no,scrollbars=no,status=no,titlebar=yes,toolbar=no")
}