// JavaScript Document
var defaultEmptyOK = false;
var whitespace = " \t\n\r";

function valida_fingreso(formulario){
	var rut = document.getElementById("nRut").value+'-'+document.getElementById("dv").value;
	if (isRut(rut)){
		if(valida_rut(rut)){
			formulario.submit();
		}
		else{
			alert('El RUT ingresado no es válido');	
			document.getElementById("nRut").select();
		}
	}
	else{
		alert('El RUT ingresado no es válido');	
		document.getElementById("nRut").select();
	}
	
}

function isRutDigit (c)
{
	return (((c >= "0") && (c <= "9")) || ((c=="k") || (c=="K")))
}


function isRut (s)
{
    if (isEmpty(s)) 
       if (isRut.arguments.length == 1) return defaultEmptyOK;
       else return (isRut.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "-") && (isDigit(s.charAt(i))) )
    { i++
    }
    
    
    if ( (s.charAt(i) == "-") && ( (i+1)==(sLength-1) ) && (isRutDigit(s.charAt(i+1)) ) && valida_rut(s) )return true;
    else return false;
}

function valida_rut(rut)
{
   var IgStringVerificador, IgN, IgSuma, IgDigito, IgDigitoVerificador, rut;
   for( i=10-rut.length; i>0; i-- ) rut = '0' + rut; 
   IgStringVerificador = '32765432';
   IgSuma = 0;
   for( IgN = 0; IgN < 8 && IgN < rut.length; IgN++)
      IgSuma = eval(IgSuma + '+' + rut.substr(IgN, 1) + '*' + IgStringVerificador.substr(IgN, 1) + ';');
   IgDigito = 11 - IgSuma % 11;
   IgDigitoVerificador = IgDigito==10?'K':IgDigito==11?'0':IgDigito;   
   if (rut.substr(rut.length-1).replace('k','K') == IgDigitoVerificador) {return true;}
   else {return false;}
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function isFecha(fecha) {
 var str, mes, dia, anyo, febrero;  
 expr = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
 str = fecha;
 if((m = str.match(expr))==null) {
	esFecha1 = false;
 }
 else{	
     dia  = fecha.split("/")[0];
     mes  = fecha.split("/")[1];
     anyo = fecha.split("/")[2];   				
	 
     if(anyoBisiesto(anyo)) {febrero=29;} else { febrero=28;}
	 if ((mes<1) || (mes>12)){
		   esFecha1 = false;
	 }
	 else{
	    if ((mes==2) && ((dia<1) || (dia>febrero))){
			   esFecha1 = false;
		}
		else {
		   if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))){
		 	  esFecha1 = false;
		   }
		   else{
			   if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30))){
				   esFecha1 = false;
			   }
			   else{
				  esFecha1 = true;
			   }	  
		   }
		}
	  }
   }
   return ( esFecha1 );
}

function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

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 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 isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    return true;
}


function abrir_ventana(url,nombre,h,w){
	window.open(url,nombre,'height='+h+',scrollbars =1,width='+w)
}

function volver_pregunta(parametros){
	window.location.href='al_pregunta_editar.php?nRut='+parametros;
}


function createXHR() 
{
	var xhr = false;
    if(window.XMLHttpRequest) 
	{
    	try 
		{
			xhr = new XMLHttpRequest();
        } 
		catch(e) 
		{
			xhr = false;
        }
    } 
	else if(window.ActiveXObject) 
	{
       	try 
		{
        	xhr = new ActiveXObject("Msxml2.XMLHTTP");
      	} 
		catch(e) 
		{
        	try 
			{
          		xhr = new ActiveXObject("Microsoft.XMLHTTP");
        	} 
			catch(e) 
			{
          		xhr = false;
        	}
		}
    }
	return xhr;
}



function Ajax(){
 var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 }catch(e){
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }catch(E){
   xmlhttp = false;
  }
 }
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
 }
 return xmlhttp;
}


function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}

/* listbox dependientes: comuna a partir de region*/
var v_comuna;
function getComuna(ide,lb) 
{
	document.getElementById("ap_usuarioslbComuna").options.length = 0;
	if (document.getElementById(lb).selectedIndex != 0)
		{
			v_comuna = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_comuna.open("GET","../biblioteca/region_comuna.php?region=" + ide+ "&rand=" + aleatorio, true);
			v_comuna.onreadystatechange = processComunaRegion;
			v_comuna.send(null);
		}
	else
		{
			document.getElementById("ap_usuarioslbComuna").options[0] = new Option("Seleccionar Comuna", "");
		}
}



function processComunaRegion() {
	if (v_comuna.readyState == 4) {
		if (v_comuna.status == 200){	
			document.getElementById("ap_usuarioslbComuna").options.length = 0;
			document.getElementById("ap_usuarioslbCiudad").options.length = 0;
			document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");			
			var v_ids = v_comuna.responseXML.getElementsByTagName("comun_cod");
			var v_nombres = v_comuna.responseXML.getElementsByTagName("comut_descripcion"); 
			document.getElementById("ap_usuarioslbComuna").options[0] = new Option("Seleccionar Comuna", "");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuarioslbComuna").options[0] = new Option("Seleccionar Comuna", "");			
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					document.getElementById("ap_usuarioslbComuna").options[i] = new Option(v_nombres[i-1].childNodes[0].nodeValue, v_ids[i-1].childNodes[0].nodeValue);	
				} 
			}
		}
		else{
			alert("Se produjo un error: " + v_comuna.statusText);
		}
	}
}


/* listbox dependientes: ciudad a partir de comuna */
var v_ciudad;
var valor_comuna;
function getCiudad(ide) 
{
	document.getElementById("ap_usuarioslbCiudad").options.length = 0;
	valor_comuna = ide;
	if (document.getElementById("ap_usuarioslbComuna").selectedIndex != 0)
		{
			v_ciudad = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_ciudad.open("GET","../biblioteca/comuna_ciudad.php?comuna=" + ide+ "&rand=" + aleatorio, true);
			v_ciudad.onreadystatechange = processCiudadComuna;
			v_ciudad.send(null);
		}
	else
		{
			document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");
		}
}



function processCiudadComuna() {
	if (v_ciudad.readyState == 4) {
		if (v_ciudad.status == 200){	
			document.getElementById("ap_usuarioslbCiudad").options.length = 0;
			var v_ids = v_ciudad.responseXML.getElementsByTagName("ciudn_cod");
			var v_nombres = v_ciudad.responseXML.getElementsByTagName("ciudt_descripcion"); 
			document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");			
			}
			else{
				//document.getElementById("ap_usuarioscomun_cod").value = valor_comuna;
				for (var i = 1; i <= v_ids.length; i++){ 
					//alert(valor_comuna);
					
					document.getElementById("ap_usuarioslbCiudad").options[i] = new Option(v_nombres[i-1].childNodes[0].nodeValue, v_ids[i-1].childNodes[0].nodeValue);	
				} 
				asigna_comuna(valor_comuna);
			}
		}
		else{
			alert("Se produjo un error: " + v_ciudad.statusText);
		}
	}
}


/* listbox dependientes: ies a partir de ties*/
var v_ies;
function getIes(ide,lb) 
{
	document.getElementById("lbIes").options.length = 0;
	if (document.getElementById(lb).selectedIndex != 0)
		{
			v_ies = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_ies.open("GET","../biblioteca/ties_ies.php?ties=" + ide+ "&rand=" + aleatorio, true);
			//alert("../biblioteca/ties_ies.php?ties=" + ide+ "&rand=" + aleatorio);
			v_ies.onreadystatechange = processIesTies;
			v_ies.send(null);
		}
	else
		{
			document.getElementById("lbIes").options[0] = new Option("No existen Instituciones", "");
		}
}



function processIesTies() {
	if (v_ies.readyState == 4) {
		if (v_ies.status == 200){	
			document.getElementById("lbIes").options.length = 0;
			var v_ids = v_ies.responseXML.getElementsByTagName("iesn_cod");
			var v_nombres = v_ies.responseXML.getElementsByTagName("iest_nombre_ies"); 
			document.getElementById("lbIes").options[0] = new Option("Seleccionar Institución", "");
			if (v_ids.length == 0) {
				document.getElementById("lbIes").options[0] = new Option("No existen Instituciones", "");			
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					document.getElementById("lbIes").options[i] = new Option(v_nombres[i-1].childNodes[0].nodeValue, v_ids[i-1].childNodes[0].nodeValue);	
				} 
			}
		}
		else{
			alert("Se produjo un error: " + v_ies.statusText);
		}
	}
}

/* listbox dependientes: ies a partir de ties*/
var v_iesOnLoad;
function getIesOnLoad(ide,lb) 
{
	document.getElementById("lbIes").options.length = 0;
	if (document.getElementById(lb).selectedIndex != 0)
		{
			v_iesOnLoad = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_iesOnLoad.open("GET","../biblioteca/ties_ies.php?ties=" + ide+ "&rand=" + aleatorio, true);
			//alert("../biblioteca/ties_ies.php?ties=" + ide+ "&rand=" + aleatorio);
			v_iesOnLoad.onreadystatechange = processIesTiesOnLoad;
			v_iesOnLoad.send(null);
		}
	else
		{
			document.getElementById("lbIes").options[0] = new Option("No existen Instituciones", "");
		}
}



function processIesTiesOnLoad() {
	if (v_iesOnLoad.readyState == 4) {
		if (v_iesOnLoad.status == 200){	
			document.getElementById("lbIes").options.length = 0;
			var v_ids = v_iesOnLoad.responseXML.getElementsByTagName("iesn_cod");
			var v_nombres = v_iesOnLoad.responseXML.getElementsByTagName("iest_nombre_ies"); 
			document.getElementById("lbIes").options[0] = new Option("Seleccionar Institución", "");
			if (v_ids.length == 0) {
				document.getElementById("lbIes").options[0] = new Option("No existen Instituciones", "");			
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					document.getElementById("lbIes").options[i] = new Option(v_nombres[i-1].childNodes[0].nodeValue, v_ids[i-1].childNodes[0].nodeValue);	
				} 
				var valor_ies = document.getElementById("ap_usuariosiesn_cod").value;
				document.getElementById("lbIes").value = valor_ies ;
			}
		}
		else{
			alert("Se produjo un error: " + v_iesOnLoad.statusText);
		}
	}
}


/* asigna comuna a hidden*/
var v_hid;
function asigna_comuna(ide) 
{
	if (document.getElementById("ap_usuarioslbComuna").selectedIndex != 0)
		{
			v_hid = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_hid.open("GET","../biblioteca/valor_hidden.php?valor=" + ide+ "&rand=" + aleatorio, true);
			v_hid.onreadystatechange = processHidden;
			v_hid.send(null);
		}
}



function processHidden() {
	if (v_hid.readyState == 4) {
		if (v_hid.status == 200){	
			var v_ids = v_hid.responseXML.getElementsByTagName("valor_hidden");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuarioscomun_cod").value='';
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					var valor_asignado = v_ids[i-1].childNodes[0].nodeValue;
					document.getElementById("ap_usuarioscomun_cod").value = valor_asignado;	
				} 
					document.getElementById("ap_usuariosciudn_cod").value = '';
			}
		}
		else{
			alert("Se produjo un error: " + v_hid.statusText);
		}
	}
}


/* asigna ies a hidden*/
var v_hidies;
function asigna_ies(ide) 
{
	if (document.getElementById("lbIes").selectedIndex != 0)
		{
			v_hidies = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_hidies.open("GET","../biblioteca/valor_hidden.php?valor=" + ide+ "&rand=" + aleatorio, true);
			//alert("../biblioteca/valor_hidden.php?valor=" + ide+ "&rand=" + aleatorio);
			v_hidies.onreadystatechange = processHiddenIes;
			v_hidies.send(null);
		}
}



function processHiddenIes() {
	if (v_hidies.readyState == 4) {
		if (v_hidies.status == 200){	
			var v_ids = v_hidies.responseXML.getElementsByTagName("valor_hidden");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuariosiesn_cod").value='';
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					var valor_asignado = v_ids[i-1].childNodes[0].nodeValue;
					//alert('fffccc: '+v_ids[i-1].childNodes[0].nodeValue);
					document.getElementById("ap_usuariosiesn_cod").value = v_ids[i-1].childNodes[0].nodeValue;
				} 
			}
		}
		else{
			alert("Se produjo un error: " + v_hidies.statusText);
		}
	}
}


/* asigna ies a hidden*/
var v_ciu;
function asigna_ciudad(ide) 
{
	if (document.getElementById("ap_usuarioslbCiudad").selectedIndex != 0)
		{
			v_ciu = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_ciu.open("GET","../biblioteca/valor_hidden.php?valor=" + ide+ "&rand=" + aleatorio, true);
			//alert("../biblioteca/valor_hidden.php?valor=" + ide+ "&rand=" + aleatorio);
			v_ciu.onreadystatechange = processHiddenCiudad;
			v_ciu.send(null);
		}
}



function processHiddenCiudad() {
	if (v_ciu.readyState == 4) {
		if (v_ciu.status == 200){	
			var v_ids = v_ciu.responseXML.getElementsByTagName("valor_hidden");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuariosciudn_cod").value='';
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					var valor_asignado = v_ids[i-1].childNodes[0].nodeValue;
					//alert('fffccc: '+v_ids[i-1].childNodes[0].nodeValue);
					document.getElementById("ap_usuariosciudn_cod").value = v_ids[i-1].childNodes[0].nodeValue;
				} 
			}
		}
		else{
			alert("Se produjo un error: " + v_ciu.statusText);
		}
	}
}





/* comuna en onload */
var v_comOnLoad;
function getComunaOnLoad(ide,lb) 
{
	document.getElementById("ap_usuarioslbComuna").options.length = 0;
	if (document.getElementById(lb).selectedIndex != 0)
		{
			v_comOnLoad = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_comOnLoad.open("GET","../biblioteca/region_comuna.php?region=" + ide+ "&rand=" + aleatorio, true);
			v_comOnLoad.onreadystatechange = processComunaRegionOnLoad;
			v_comOnLoad.send(null);
		}
	else
		{
			document.getElementById("ap_usuarioslbComuna").options[0] = new Option("Seleccionar Comuna", "");
		}
}



function processComunaRegionOnLoad() {
	if (v_comOnLoad.readyState == 4) {
		if (v_comOnLoad.status == 200){	
			document.getElementById("ap_usuarioslbComuna").options.length = 0;
			var v_ids = v_comOnLoad.responseXML.getElementsByTagName("comun_cod");
			var v_nombres = v_comOnLoad.responseXML.getElementsByTagName("comut_descripcion"); 
			document.getElementById("ap_usuarioslbComuna").options[0] = new Option("Seleccionar Comuna", "");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuarioslbComuna").options[0] = new Option("Seleccionar Comuna", "");			
			}
			else{
				for (var i = 1; i <= v_ids.length; i++){ 
					document.getElementById("ap_usuarioslbComuna").options[i] = new Option(v_nombres[i-1].childNodes[0].nodeValue, v_ids[i-1].childNodes[0].nodeValue);	
				} 
			}
			document.getElementById("ap_usuarioslbComuna").value = document.getElementById("ap_usuarioscomun_cod").value;
			getCiudadOnLoad(document.getElementById("ap_usuarioscomun_cod").value);
		}
		else{
			alert("Se produjo un error: " + v_comOnLoad.statusText);
		}
	}
}

/* ciudad onload */
var v_cOnLoad;
function getCiudadOnLoad(ide) 
{
	document.getElementById("ap_usuarioslbCiudad").options.length = 0;
	if (document.getElementById("ap_usuarioslbComuna").selectedIndex != 0)
		{
			v_cOnLoad = createXHR();
			var aleatorio = parseInt(Math.random()*999999999);  //no cargar datos desde cache
			v_cOnLoad.open("GET","../biblioteca/comuna_ciudad.php?comuna=" + ide+ "&rand=" + aleatorio, true);
			v_cOnLoad.onreadystatechange = processCiudadComunaOnload;
			v_cOnLoad.send(null);
		}
	else
		{
			document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");
		}
}



function processCiudadComunaOnload() {
	if (v_cOnLoad.readyState == 4) {
		if (v_cOnLoad.status == 200){	
			document.getElementById("ap_usuarioslbCiudad").options.length = 0;
			var v_ids = v_cOnLoad.responseXML.getElementsByTagName("ciudn_cod");
			var v_nombres = v_cOnLoad.responseXML.getElementsByTagName("ciudt_descripcion"); 
			document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");
			if (v_ids.length == 0) {
				document.getElementById("ap_usuarioslbCiudad").options[0] = new Option("Seleccionar Ciudad", "");			
			}
			else{
				//document.getElementById("ap_usuarioscomun_cod").value = valor_comuna;
				for (var i = 1; i <= v_ids.length; i++){ 
					//alert(valor_comuna);
					
					document.getElementById("ap_usuarioslbCiudad").options[i] = new Option(v_nombres[i-1].childNodes[0].nodeValue, v_ids[i-1].childNodes[0].nodeValue);	
				} 
			var v_ciudad = document.getElementById("ap_usuariosciudn_cod").value;
			document.getElementById("ap_usuarioslbCiudad").value = document.getElementById("ap_usuariosciudn_cod").value;
			}
		}
		else{
			alert("Se produjo un error: " + v_cOnLoad.statusText);
		}
	}
}

function devolver(pregunta){
	window.location.href="../responsable/rp_devolver.php?pregn_cod="+pregunta;
}

function devolver_adm(pregunta){
	window.location.href="../admin/ad_devolver.php?pregn_cod="+pregunta;
}


function ejecuta_acordeon(){
	var div_ver		= document.getElementById("ver");
	var div_ocultar = document.getElementById("ocultar");
	var div_dp		= document.getElementById("datosPersonales");
	if (div_ver.style.display == "block"){
		div_ver.style.display = "none";
		div_ocultar.style.display = "block";
		div_dp.style.display = "block";
	}
	else{
		div_ver.style.display = "block";
		div_dp.style.display = "none";
		div_ocultar.style.display = "none";
	}


	/*$(function() 
        {
           $("#accordion").accordion({active: false,speed:50,collapsible:true});
        }
		
); */
}

function resaltar(campo) {
    //campo.bgcolor = campo.parentNode.style.backgroundColor;
    campo.parentNode.style.backgroundColor = "#e5e5e5";
}

function desResaltar(campo) {
    campo.parentNode.style.backgroundColor = "#fffff";
}


function seleccionar(campo) {
    if(campo.checked){  		
		campo.parentNode.parentNode.style.backgroundColor= "#7DB900";
	}
	else
	{
    	campo.parentNode.parentNode.style.backgroundColor= "#e5e5e5";
	}
}

function seleccionar_chk(formulario){
	num=formulario.elements.length;
	c=0;
	for (i=0;i<num;i++){
		nombre = formulario.elements[i].name;
		var elem = new RegExp ("chk","gi");
		if (elem.test(nombre)){
				//alert(formulario.elements[i].name);
				seleccionar(formulario.elements[i]);
		}
	}

}

function resaltarCelda(campo) {
    campo.bgcolor = campo.parentNode.style.backgroundColor;
    campo.style.backgroundColor = "#e5e5e5";
}

function desResaltarCelda(campo) {
    campo.style.backgroundColor = "#C7C7C7";
}



function verifica_check(formulario) {
	num=formulario.elements.length;
	c=0;
	for (i=0;i<num;i++){
		nombre = formulario.elements[i].name;
		var elem = new RegExp ("chk","gi");
		if (elem.test(nombre)){
			if((formulario.elements[i].checked==true)){
				c=c+1;
			}
		}
	}
	if ((c>0)) {
		return true;
	}
	else {
		return (false);
	}
}


function valida_fasignadas(formulario){
	var v_msg = "";
	var v_responsable = document.getElementById("usuan_cod_resp").value;
	if(v_responsable == ''){
		v_msg = v_msg + "Debe seleccionar un Responsable.\n";
	}
	if(!verifica_check(formulario)){
		v_msg = v_msg + "Debe seleccionar al menos una Consulta para reasignar.\n";
	}

	if (v_msg == ""){
		formulario.submit();
	}
	else{
		alert(v_msg);
	}

}

function eliminar(codigo,tipo){
	var msg_conf = "¿Está seguro que desea eliminar";
	switch (tipo){
		case 'c':
			msg_conf = msg_conf + " la categoría seleccionada?";
			break
		case 'u':
			msg_conf = msg_conf + " el usuario seleccionado?";
			break;
		case 'p':
			msg_conf = msg_conf + " la plantilla seleccionada?";
			break;
	}

	
	if(confirm(msg_conf)){
		window.location.href='ad_eliminar.php?codigo='+codigo+'&tipo='+tipo;
	}
}



var nav4 = window.Event ? true : false;
function acceptNum(evt)
{        
	var key = nav4 ? evt.which : evt.keyCode;       
	return (key <= 13 || (key >= 48 && key <= 57));
}
/*cuenta blancos*/
function nEspacios(dato) {
	var contador = 0;
	for (var i = 0; i < dato.length; i ++)
	contador += (dato.charAt(i) == " ") ? 1:0;
	return contador;
}

/* contar caracteres*/
function count_caract(obj){	
	var cant_blancos = nEspacios(obj.value);	
	var cant = obj.value.length;
	//alert(cant_blancos+' ¿? '+cant);
	var resultado = (parseInt((cant)) - parseInt(cant_blancos));
	if(cant > (2000 + cant_blancos)){
		//document.getElementById("lblCaracteres").innerHTML = "&nbsp;<span style='color:#990000;'><b>"+((cant) - cant_blancos)+ "</b></span>&nbsp;";
		$("#lblCaracteres").html("&nbsp;<span style='color:#990000;'><b>"+ resultado + "</b></span>&nbsp;");
	}
	else{
		//document.getElementById("lblCaracteres").innerHTML = "&nbsp;"+((cant) - cant_blancos)+ "&nbsp;";
		$("#lblCaracteres").html("&nbsp;"+resultado+ "&nbsp;");
	}

	//if (cant > (20 + cant_blancos)) 
	//	obj.value = obj.value.substring(0, cant);
	//else 
	//	cuentacampo.value = (20 + cant_blancos) - obj.value.length;


	if(cant >= (2000 + cant_blancos)){
		obj.value = obj.value.substring(0, 2000 + cant_blancos);
	/*	
		if (document.layers)
			document.captureEvents(Event.KEYPRESS);
			var keyCode = event.keyCode;	
			if (keyCode != 8 && (keyCode == 16 || (keyCode >= 32 && keyCode <= 44) || keyCode == 46 || keyCode == 47 || (keyCode >= 58) || keyCode == 45))
				event.returnValue = false;				
				*/
	}
	
}


