	// DA UN FORMATO AL RUT (11.111.111-1)
	function FormatoRut(rut) {
		
		var valor = "";
		var valor2 = "";
		var RutOk = "";
		var largo = 0;
		var i = 0;
		var n = 0;
		var y = 0;
	
		valor = String(rut);
		i = valor.length;
		y = i;
		while (n<i) {
			valor2 = valor.substr(y - 1, 1);
			if ((valor2=="1") || (valor2=="2") || (valor2=="3") || (valor2=="4") || (valor2=="5") || (valor2=="6") || (valor2=="7") || (valor2=="8") || (valor2=="9") || (valor2=="0") || (valor2=="k") || (valor2=="K")) {
				RutOk = valor2 + RutOk;
			}
			y = y - 1;
			n = n + 1;
		}

		largo = RutOk.length;
		if (largo==10) {
			RutOk = RutOk.substr(0, 3) + "." + RutOk.substr(3, 3) + "." + RutOk.substr(6, 3) + "-" + RutOk.substr(9, 1);
		}
		if (largo==9) {
			RutOk = RutOk.substr(0, 2) + "." + RutOk.substr(2, 3) + "." + RutOk.substr(5, 3) + "-" + RutOk.substr(8, 1);
		}
		if (largo==8) {
			RutOk = RutOk.substr(0, 1) + "." + RutOk.substr(1, 3) + "." + RutOk.substr(4, 3) + "-" + RutOk.substr(7, 1);
		}
		if (largo==7) {
			RutOk = RutOk.substr(0, 3) + "." + RutOk.substr(3, 3) + "-" + RutOk.substr(6, 1);
		}
		if (largo==6) {
			RutOk = RutOk.substr(0, 2) + "." + RutOk.substr(2, 3) + "-" + RutOk.substr(5, 1);
		}
		if (largo==5) {
			RutOk = RutOk.substr(0, 1) + "." + RutOk.substr(1, 3) + "-" + RutOk.substr(4, 1);
		}
		if (largo==4) {
			RutOk = RutOk.substr(0, 3) + "-" + RutOk.substr(3, 1);
		}
		if (largo==3) {
			RutOk = RutOk.substr(0, 2) + "-" + RutOk.substr(2, 1);
		}
		if (largo==2) {
			RutOk = RutOk.substr(0, 1) + "-" + RutOk.substr(1, 1);
		}
		return RutOk;
	}

	function datediff(strdate1,strdate2) {
		aaaa1 = parseInt(strdate1.substring(6,10));
		mm1   = parseInt(eval(strdate1.substring(3,5)))-1;
		dd1   = parseInt(eval(strdate1.substring(0,2)));

		aaaa2 = parseInt(strdate2.substring(6,10));
		mm2   = parseInt(eval(strdate2.substring(3,5)))-1;
		dd2   = parseInt(eval(strdate2.substring(0,2)));
		var date1=new Date(aaaa1,mm1,dd1);
		var date2=new Date(aaaa2,mm2,dd2);
		if (date1.getTimezoneOffset() > date2.getTimezoneOffset()) {
			delta = 1;
		} else {
			delta = 0;
		}
		var one_day=1000*60*60*24;
		return Math.ceil((date1.getTime()-date2.getTime())/(one_day)-delta);
	}
	
	function trim(cadena){
		texto = cadena.replace(/ /g,"");
		return texto;
	}
	
	// VALIDA EL DIGITO VERIFICADOR DEL RUT
	function ValidaDigito(rut) {
		var valor = "";
		var valor2 = "";
		var valor3 = "";
		var DV = "";
		var RutOk;
		var valorfin = 0;
		var largo = 0;
		var i = 0;
		var n = 0;
		var y = 0;
		var SumaRR = 0;
		var valorX = 2;
		var divi = 0;
		var digito = "";
		
		valor = String(rut);
		i = valor.length;
		y = i;
		while (n<i) {
			valor2 = valor.substr(y - 1, 1);
			if ((valor2=="1") || (valor2=="2") || (valor2=="3") || (valor2=="4") || (valor2=="5") || (valor2=="6") || (valor2=="7") || (valor2=="8") || (valor2=="9") || (valor2=="0") || (valor2=="k") || (valor2=="K")) {
				valor3 = valor2 + valor3;
			}
			y = y - 1;
			n = n + 1;
		}
		n = 0;
		y = 0;
		largo = valor3.length;
		if (largo>1) {
			valorfin = valor3.substr(0, largo - 1);
			DV = valor3.substr(largo - 1, 1);
			if (DV=="K") {
				DV="k";
			}
			largo = largo - 1;
			y = largo -1;
			   while (n < largo) {
				   i = parseInt(valorfin.substr(y, 1));
				   SumaRR = SumaRR + i * valorX;
				   if (valorX == 7) {
				      valorX = 2;
				   }
				   else {
				      valorX = valorX + 1;
				   }
				   y = y - 1
				   n = n + 1
			   }
			  divi = 11 - SumaRR % 11;
 			  if (divi == 10) {
 			   digito = "k"
			  }
			  if (divi == 11) {
			   digito = "0";
			  }
			  if (divi >= 0 && divi <= 9) {
			   digito = divi;
			  }
		      if (DV==digito) {
				RutOk = true;
				return RutOk;
			  }
			  else {
				//window.alert("Rut Incorrecto...");
				RutOk = false;
				return RutOk;
			  }
		}
		else {
			//window.alert("Error de ingreso en el Rut...");
			RutOk = false;
			return RutOk;
		}		
	}
	
	function FormatDate(i, delKey,direction) {
	 if (i.value.length < 10) {
	  	if (delKey!=9) { //tab
		  	if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41)){ 
	  			var fieldLen = i.value.length
	   			if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) {
	   				if (fieldLen == 2 || fieldLen == 5) {
	      				i.value = i.value + "-";
			     	}
	   			} else {
	   				if (direction == "up") {
	     				if (i.value.length == 0) {
	      					i.value = ""
		     			} else {
			      			i.value = i.value.substring(0,i.value.length-1)
		   				}
	    			}
		 		}
	  			i.focus()
		  	}
	 	} else {
	 		if (direction == "down") {
		 		CheckDate(i)
	  		}
	  	}
	 }
	}
	function CheckDate(THISDATE) {
		var err=0
		a=THISDATE.value
		if (a.length != 10) err=1
		b = a.substring(0, 2)// month - dia
		c = a.substring(2, 3)// '/'
		d = a.substring(3, 5)// day - mes
		e = a.substring(5, 6)// '/'
		f = a.substring(6, 10)// year
		if (d<1 || d>12) err = 1
		if (b<1 || b>31) err = 1
		if (f<1900) err = 1
		if (d==4 || d==6 || d==9 || d==11){
			if (b==31) err=1
		}
		if (d==2){
			var g=parseInt(f/4)
			if (isNaN(g)) {
				err=1
			}
			if (b>29) err=1
			if (b==29 && ((f/4)!=parseInt(f/4))) err=1
		}
		if (err==1) {		
			//alert(THISDATE.value + ' Error: Fecha No Valida...');
			return false;
		}
		else {		
			return true;
		}		
	}

	function FormatTime(i, delKey,direction) {
	 if (i.value.length < 10) {
	  	if (delKey!=9) { //tab
		  	if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41)){ 
	  			var fieldLen = i.value.length
	   			if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105)) {
	   				if (fieldLen == 2 || fieldLen == 5) {
	      				i.value = i.value + ":";
			     	}
	   			} else {
	   				if (direction == "up") {
	     				if (i.value.length == 0) {
	      					i.value = ""
		     			} else {
			      			i.value = i.value.substring(0,i.value.length-1)
		   				}
	    			}
		 		}
	  			i.focus()
		  	}
	 	} else {
	 		if (direction == "down") {
		 		CheckTime(i)
	  		}
	  	}
	 }
	}
	function CheckTime(THISTIME) {
		var err=0
		a=THISTIME.value
		if (a.length != 8) err=1;
		b = a.substring(0, 2)// hora
		c = a.substring(2, 3)// ':'
		d = a.substring(3, 5)// minuto
		e = a.substring(5, 6)// ':'
		f = a.substring(6, 10)// segundo
		if (b<0 || b>23) err = 1;
		if (d<0 || d>59) err = 1;
		if (f<0 || f>59) err = 1;
		if (err==1) {		
			alert(THISTIME.value + ' Error: Hora No Válida...');
			return false;
		}
		else {		
			return true;
		}		
	}
	
	function verifica_numeros(){ // numero enteros
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 47) ||
			(window.event.keyCode >= 58 && window.event.keyCode <= 255)){
			return false;	
				} 
		}
		
	var ap=true;
	function verifica_numeros_modif()
	{
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 47) ||
			(window.event.keyCode >= 58 && window.event.keyCode <= 255))
		{
			if (window.event.keyCode != 44) 
			{
				ap=false
			}
			else{
				ap=true
			}
		} 
		return ap
	}

	function verifica_decimales(tex){ // decimales con punto
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 43) ||
			(window.event.keyCode == 45) || (window.event.keyCode == 47) ||
			(window.event.keyCode >= 58 && window.event.keyCode <= 255)){
			return false;	
				} 
		else{
			str_c = tex.indexOf(',');
			str_p = tex.indexOf('.');
			if (window.event.keyCode == 44 || window.event.keyCode == 46){
				if (str_c != -1 || str_p != -1){
					return false;
					}
				}	
			}
		}
		
	function verifica_decimales_c(){ // decimales con coma
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 43) || 
			(window.event.keyCode >= 45 && window.event.keyCode <= 47) || 
			(window.event.keyCode >= 58 && window.event.keyCode <= 255)) {
			return false;	
		} 
	
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 43) ||
			(window.event.keyCode == 45) || (window.event.keyCode == 47) ||
			(window.event.keyCode >= 58 && window.event.keyCode <= 255)){
			return false;	
		} 
	}

	function verifica_rut(){ // rut sin puntos
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 44) || 
			(window.event.keyCode >= 46 && window.event.keyCode <= 47) || 
			(window.event.keyCode >= 58 && window.event.keyCode <= 74) ||
			(window.event.keyCode >= 76 && window.event.keyCode <= 106) ||
			(window.event.keyCode >= 108 && window.event.keyCode <= 255)) {
			return false;	
		} 
	}

	function verifica_dv(){ // dígito verificador
		if ((window.event.keyCode >= 0 && window.event.keyCode <= 47) || 
			(window.event.keyCode >= 58 && window.event.keyCode <= 74) ||
			(window.event.keyCode >= 76 && window.event.keyCode <= 106) ||
			(window.event.keyCode >= 108 && window.event.keyCode <= 255)) {
			return false;	
		} 
	}

var defaultEmptyOK = false;
var digits = "0123456789";
function IsEmpty(obj) 
{ 
	if (obj=="")
   		{return true;}
   	return false;
}
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}
function valida_entero(text){
	
	if (!isInteger(text.value)){
		alert("El valor debe ser entero")
		text.focus();
	}
}
function isNumber (s)
{   var i;
    var dotAppeared;
    dotAppeared = false;
    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isNumber.arguments[1] == true);
    
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( c == "," ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else      
                if (!isDigit(c)) return false;
        } else { 
            if ( c == "," ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c) && (c != "-") || (c == "+")) return false;
        }
    }
    return true;
}

		function MM_openBrWindow(theURL,winName,features) { //v2.0
		  window.open(theURL,winName,features);
		}
		
		function MM_reloadPage(init) {  //reloads the window if Nav4 resized
		  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
		  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
		}

		MM_reloadPage(true);

		function MM_swapImgRestore() { //v3.0
			var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
		}

		function MM_preloadImages() { //v3.0
			var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
			var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
		}

		function MM_swapImage() { //v3.0
			var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
			if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
		}

		function MM_findObj(n, d) { //v4.0
			var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
			d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
			if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
			for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
			if(!x && document.getElementById) x=document.getElementById(n); return x;
		}

		function MM_showHideLayers() { //v3.0
		  var i,p,v,obj,args=MM_showHideLayers.arguments;
		  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		    obj.visibility=v; }
		}

function flipImage(objimg,url){
//	document.formulario.imagen.src = url;
	objimg.src = url;
}

function expandir(num_niveles) {
	if (num_niveles>1) {
		num_niv_1 = document.cuentas.num_niv_1.value;
		for(i=1;i<=num_niv_1;i++) {
			document.getElementById('uno'+i).style.display="block";
			if (document.getElementById('imagen_uno'+i)) {
				document.getElementById('imagen_uno'+i).src="../images/minus_m.gif";
				document.getElementById('estado1_'+i).value = "2";
				if (num_niveles>2) {
					num_niv_2 = document.getElementById('num_niv_2_'+i).value;
					for(k=1;k<=num_niv_2;k++) {
						document.getElementById('dos'+i+'_'+k).style.display="block";
						if (document.getElementById('imagen_dos'+i+'_'+k)) {
							document.getElementById('imagen_dos'+i+'_'+k).src="../images/minus_l.gif";
							document.getElementById('estado2_'+i+'_'+k).value = "2";
							if (num_niveles>3) {
								num_niv_3 = document.getElementById('num_niv_3_'+i+'_'+k).value;
								for(j=1;j<=num_niv_3;j++) {
									document.getElementById('tres'+i+'_'+k+'_'+j).style.display="block";
									if (document.getElementById('imagen_tres'+i+'_'+k+'_'+j)) {
										document.getElementById('imagen_tres'+i+'_'+k+'_'+j).src="../images/minus_l.gif";
										document.getElementById('estado3_'+i+'_'+k+'_'+j).value = "2";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function contraer(num_niveles) {
	if (num_niveles>1) {
		num_niv_1 = document.cuentas.num_niv_1.value;
		for(i=1;i<=num_niv_1;i++) {
			document.getElementById('uno'+i).style.display="none";
			if (document.getElementById('imagen_uno'+i)) {
				document.getElementById('imagen_uno'+i).src="../images/plus_m.gif";
				document.getElementById('estado1_'+i).value = "1";
				if (num_niveles>2) {
					num_niv_2 = document.getElementById('num_niv_2_'+i).value;
					for(k=1;k<=num_niv_2;k++) {
						document.getElementById('dos'+i+'_'+k).style.display="none";
						if (document.getElementById('imagen_dos'+i+'_'+k)) {
							document.getElementById('imagen_dos'+i+'_'+k).src="../images/plus_l.gif";
							document.getElementById('estado2_'+i+'_'+k).value = "1";
							if (num_niveles>3) {
								num_niv_3 = document.getElementById('num_niv_3_'+i+'_'+k).value;
								for(j=1;j<=num_niv_3;j++) {
									document.getElementById('tres'+i+'_'+k+'_'+j).style.display="none";
									if (document.getElementById('imagen_tres'+i+'_'+k+'_'+j)) {
										document.getElementById('imagen_tres'+i+'_'+k+'_'+j).src="../images/plus_l.gif";
										document.getElementById('estado3_'+i+'_'+k+'_'+j).value = "1";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
function exportar(opc,cod) {
	if (opc=='POPUP') {
		reporte = document.getElementById('reporte').value;
		modulo  = document.getElementById('modulo').value;
		if (reporte=='V') {
			window.open("detalle-canal_excel.asp?codigo="+cod+"&modulo="+modulo);
		}
		else {
			window.open("indicadores_agentes_excel.asp?codigo="+cod+"&modulo="+modulo);
		}
	}
	else {
		reporte = parent.frames.datos.document.getElementById('reporte').value;
		if (reporte=='V') {
			parent.frames.encabezado.document.formulario.action = "framecontenido_excel.asp";
			parent.frames.encabezado.document.formulario.method = "post";
			parent.frames.encabezado.document.formulario.target = "_blank";
			parent.frames.encabezado.document.formulario.submit();
		}
		else {
			parent.frames.encabezado.document.formulario.action = "indicadores_excel.asp";
			parent.frames.encabezado.document.formulario.method = "post";
			parent.frames.encabezado.document.formulario.target = "_blank";
			parent.frames.encabezado.document.formulario.submit();
		}
	}
}

	var lfl1=0;
	var xv1=0;
	
	function tmr() {
		if(document.all) {
			if(!lfl1) {
				xv1=document.body.scrollTop;
			}
			document.all.titulo.style.top=xv1+=parseInt((document.body.scrollTop-xv1)+6/4);
			if(!lfl1) {
				document.all.titulo.style.visibility='visible';
			}
		}
		else {
			document.titulo.top+=(window.pageYOffset-document.layer2.top)+6/4;
			if(!lfl1) {
				document.titulo.visibility='visible';
			}
		}
		lfl1=1;
		setTimeout("tmr()",50);
	}

	function hideshow(which){
		if (!document.getElementById)
			return
		if (which.style.display != "none")
			which.style.display="none"
		else
			which.style.display="block"
	}
	function cambiarimagen(which,estado) {
		if (estado.value == "1"){		   
			which.src="../images/minus_m.gif"
			estado.value = "2";
			}
		else{
			which.src="../images/plus_m.gif";	
			estado.value = "1";
			}
	} 
	function cambiarimagen2(which,estado) {
		if (estado.value == "1"){		   
			which.src="../images/minus_l.gif"
			estado.value = "2";
			}
		else{
			which.src="../images/plus_l.gif";	
			estado.value = "1";
			}
	} 


function expandir_reporte(mnid,num_niveles) {
	if (num_niveles>1) {
		num_niv_1 = document.getElementById(mnid+'num_niv_0').value;
		for(i=1;i<=num_niv_1;i++) {
			document.getElementById(mnid+'uno'+i).style.display="block";
			if (document.getElementById(mnid+'imagen_uno'+i)) {
				document.getElementById(mnid+'imagen_uno'+i).src="../images/minus_m.gif";
				document.getElementById(mnid+'estado1_'+i).value = "2";
				if (num_niveles>2) {
					num_niv_2 = document.getElementById(mnid+'num_niv_1_'+i).value;
					for(k=1;k<=num_niv_2;k++) {
						document.getElementById(mnid+'dos'+i+'_'+k).style.display="block";
						if (document.getElementById(mnid+'imagen_dos'+i+'_'+k)) {
							document.getElementById(mnid+'imagen_dos'+i+'_'+k).src="../images/minus_l.gif";
							document.getElementById(mnid+'estado2_'+i+'_'+k).value = "2";
							if (num_niveles>3) {
								num_niv_3 = document.getElementById(mnid+'num_niv_2_'+i+'_'+k).value;
								for(j=1;j<=num_niv_3;j++) {
									document.getElementById(mnid+'tres'+i+'_'+k+'_'+j).style.display="block";
									if (document.getElementById(mnid+'imagen_tres'+i+'_'+k+'_'+j)) {
										document.getElementById(mnid+'imagen_tres'+i+'_'+k+'_'+j).src="../images/minus_l.gif";
										document.getElementById(mnid+'estado3_'+i+'_'+k+'_'+j).value = "2";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function contraer_reporte(mnid,num_niveles) {
	if (num_niveles>1) {
		num_niv_1 = document.getElementById(mnid+'num_niv_0').value;
		for(i=1;i<=num_niv_1;i++) {
			document.getElementById(mnid+'uno'+i).style.display="none";
			if (document.getElementById(mnid+'imagen_uno'+i)) {
				document.getElementById(mnid+'imagen_uno'+i).src="../images/plus_m.gif";
				document.getElementById(mnid+'estado1_'+i).value = "1";
				if (num_niveles>2) {
					num_niv_2 = document.getElementById(mnid+'num_niv_1_'+i).value;
					for(k=1;k<=num_niv_2;k++) {
						document.getElementById(mnid+'dos'+i+'_'+k).style.display="none";
						if (document.getElementById(mnid+'imagen_dos'+i+'_'+k)) {
							document.getElementById(mnid+'imagen_dos'+i+'_'+k).src="../images/plus_l.gif";
							document.getElementById(mnid+'estado2_'+i+'_'+k).value = "1";
							if (num_niveles>3) {
								num_niv_3 = document.getElementById(mnid+'num_niv_2_'+i+'_'+k).value;
								for(j=1;j<=num_niv_3;j++) {
									document.getElementById(mnid+'tres'+i+'_'+k+'_'+j).style.display="none";
									if (document.getElementById(mnid+'imagen_tres'+i+'_'+k+'_'+j)) {
										document.getElementById(mnid+'imagen_tres'+i+'_'+k+'_'+j).src="../images/plus_l.gif";
										document.getElementById(mnid+'estado3_'+i+'_'+k+'_'+j).value = "1";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function playSound(opc) {
	if (opc==1) {
	  document.all.base.src = "chunk.mp3";
	}
}
