// JavaScript Document
    var monthNames = new makeArray(12);
    monthNames[0] = "Enero";
    monthNames[1] = "Febrero";
    monthNames[2] = "Marzo";
    monthNames[3] = "Abril";
    monthNames[4] = "Mayo";
    monthNames[5] = "Junio";
    monthNames[6] = "Julio";
    monthNames[7] = "Agosto";
    monthNames[8] = "Septiembre";filtrar_salones0
    monthNames[9] = "Octubre";
    monthNames[10] = "Noviembre";
    monthNames[11] = "Diciembre";
    
    // Array de los das

    var dayNames = new makeArray(7);
    dayNames[0] = "Domingo";
    dayNames[1] = "Lunes";
    dayNames[2] = "Martes";
    dayNames[3] = "Mi&eacute;rcoles";
    dayNames[4] = "Jueves";
    dayNames[5] = "Viernes";
    dayNames[6] = "S&aacute;bado";
    
    var now = new Date();
    var year = now.getYear();
    
    if (year < 2000) year = year + 1900;
    
    function makeArray(len)    { 
	    for (var i = 0; i < len; i++) this[i] = null;
    	this.length = len;
    }
	function fecha_navegador(){
		document.write( dayNames[now.getDay()] + " " + now.getDate() + " de " + monthNames[now.getMonth()] + " " +" de " + year);
	}
	function ajax_jquery(jurl,jdata,jdiv,funciones){
		$.ajax({ 
			type: "POST",
			url:  jurl,
			data: jdata,
			contentType: "application/x-www-form-urlencoded",
			dataType: "html",
			beforeSend: function(){
				$("#"+jdiv).html(anima('Cargando...'));
			},
			success: function(datos){
				$("#"+jdiv).html(datos);
				if(funciones.length>0){
					funciones;
				}
			}
    	});		
	}
	function anima(texto){
		return "<br><br><br><br><img src='imagenes/animated.gif' align='center'/>"+texto;
	}	
	function ltrim(s) {     
		return s.replace(/^\s+/, ""); 
	}  
	function rtrim(s){     
		return s.replace(/\s+$/, ""); 
	}  
	function trim(s) {     
		if(s==null){
			return '';
		}
	return rtrim(ltrim(s)); 
	}
	function a_entero(valor){
		valor=parseInt(trim(quita_ceros(valor)));

		//comprobamos si es un valor entero  
		if (isNaN(valor)) {  
			  //no es entero 0  
			  return 0;  
		}else{  
			  //es un valor entero  
			  return valor;  
		}  
	}  
	function quita_ceros(cadena){
		if(cadena!='0' && cadena!='00'){
			var noceros='';
			var band=false;
			var i=0;        
			for(i=0; i<cadena.length;i++ )
			{
				if(cadena.charAt(i)=="0"){
					if(band){
						noceros=noceros+cadena.charAt(i);//substring(i, cadena.length);		
					}
				}else{
					noceros=noceros+cadena.charAt(i);//substring(i, cadena.length);	
					band=true;
				}
				
			}
		}else{
			var noceros='0';
		}
		return noceros;
	}
	function a_entero1(valor){  
		var v =trim(valor).toUpperCase();		
	   	valor=parseInt(trim(quita_ceros(valor)));
		//comprobamos si es un valor entero  
		if (isNaN(valor)) {  
			  //no es entero 0  
			if(v != 'A' && v != 'D' && v != 'N' && v != 'I' && v != 'R'){
						return 'x';
			}
			return v;
		}else{  
			  //es un valor entero 
			  return valor;  
		}  
	}
	
	function objetoAjax(){
		var xmlhttp=null;
		try{
			xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch(e){
			try{
				xmlhttp=new ActiveObject('Microsoft.XMLHTTP');
			}
			catch(e){
				xmlhttp=false;
			}
		}
		if(!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
			return xmlhttp;
	}
	
	function guardar_apreciacion(){		
		var valor=$('#aprecia_alumno').serialize();		
		 $.ajax({
			   async:true,
			   type: "POST",
			   dataType: "html",
			   contentType: "application/x-www-form-urlencoded",
			   url:"save_apreciacion.php",
			   data:valor,
			   beforeSend:inicioEnvio2,
			   success:llegadaDatos2,
			   timeout:4000
			 });		
		return false;
		
		/*ajax=objetoAjax();
		var tabla=document.getElementById('tab_apreciac');
		var f=tabla.getElementsByTagName('textarea'); 
		document.getElementById('graba_aprec').innerHTML='<img src="imagenes/animated.gif" style="height:20px"/>';
		for(j=0;j<f.length;j++){
			var cod=f[j].name.split('-');
			var alucod=cod[1];
			var valor=f[j].value;
			valor=escape(valor);
			//valor=valor.replace("'","´"); 
			ajax.open('GET',"save_apreciacion.php?valor="+valor,false);
			ajax.send(null);
		/*}*/
		
	}
	function inicioEnvio2(){
		document.getElementById('graba_aprec').innerHTML='<img src="imagenes/animated.gif" style="height:20px"/>';
	}
	function llegadaDatos2(datos){
		//alert(datos);
		document.getElementById('graba_aprec').innerHTML='';
		if(datos==''){
			alert('Datos Guardados');
			$('textarea').css('background-color','#FFF');
		}
		else{
			document.getElementById('graba_aprec').innerHTML="<font color=\"#990000\">Hay comentarios que no han podido ser guardados, sobrepasaron la cantidad m&eacute;xima de caracteres(150)</font>";
			var campos=datos.split(',');
			for(i=0;i<campos.length-1;i++){
				$('#txtaprec-'+campos[i]).css('background-color','#ff9b9b');				
			}
		}		
	}
	function save_coment_spain(){
		var valor=$('#guarda_spain').serialize();
		$.ajax({
			   async:true,
			   type: "POST",
			   dataType: "html",
			   contentType: "application/x-www-form-urlencoded",
			   url:"../save_coment_spain.php",
			   data:valor,
			   success:llegadaDatos3,
			   timeout:4000
			 }); 
		return false
	}
	function llegadaDatos3(){
		alert('Datos grabados');	
	}
function validar_cat(valor,who){
	document.getElementById('b_grupos').innerHTML='';
	if(who==''){
		if(valor=="P"){
			document.getElementById('t_profes').disabled=false;
			document.getElementById('t_prof_sal').disabled=true;
		}		
		else{
			if(valor=="A"){
				document.getElementById('t_profes').disabled=true;
				document.getElementById('t_prof_mat').disabled=true;
				document.getElementById('t_prof_sal').disabled=false;
				document.getElementById('t_prof_tut').disabled=true;	
				filtros2('alumno',valor);
			}
			else{
				if(valor=="F"){
					document.getElementById('t_profes').disabled=true;
					document.getElementById('t_prof_mat').disabled=true;
					document.getElementById('t_prof_sal').disabled=false;
					document.getElementById('t_prof_tut').disabled=true;	
					filtros('fam',valor);
				}
				else if(valor=="AD"){
					document.getElementById('t_profes').disabled=true;
					document.getElementById('t_prof_mat').disabled=true;
					document.getElementById('t_prof_sal').disabled=true;
					document.getElementById('t_prof_tut').disabled=true;			
					filtros('adm',valor);
				}
				else if(valor=="D"){
					document.getElementById('t_profes').disabled=true;
					document.getElementById('t_prof_mat').disabled=true;
					document.getElementById('t_prof_sal').disabled=true;
					document.getElementById('t_prof_tut').disabled=true;
					filtros('direc',valor);
				}
			}
		}
	}
	else{
		if(valor=="P"){
			document.getElementById('t_profes').disabled=false;
			document.getElementById('t_prof_sal').disabled=true;
			document.getElementById('cbonivel').disabled=true;
		}
		else{
			if(valor=="A"){
				document.getElementById('t_profes').disabled=true;
				document.getElementById('t_prof_mat').disabled=true;
				document.getElementById('t_prof_sal').disabled=false;
				document.getElementById('t_prof_tut').disabled=true;
				document.getElementById('cbonivel').disabled=false;
				filtros2('alumno',valor);
			}
			else{
				if(valor=="F"){
					document.getElementById('t_profes').disabled=true;
					document.getElementById('t_prof_mat').disabled=true;
					document.getElementById('t_prof_sal').disabled=false;
					document.getElementById('t_prof_tut').disabled=true;
					document.getElementById('cbonivel').disabled=true;
					filtros('fam',valor);
				}
				else if(valor=="AD"){
					document.getElementById('t_profes').disabled=true;
					document.getElementById('t_prof_mat').disabled=true;
					document.getElementById('t_prof_sal').disabled=true;
					document.getElementById('t_prof_tut').disabled=true;
					document.getElementById('cbonivel').disabled=true;
					filtros('adm',valor);
				}
			}
		}
	}
}
	
	function validar_contact(valor){
		if(valor=="P"){
			document.getElementById('t_profesor').disabled=false;
		}
		else{
			document.getElementById('t_profesor').disabled=true;
			filtros_contact('adm',valor);
		}
	}
	
	function validar_prof(valor){
		switch(valor){
			case "T": filtros('profe',valor);;break;
			case "M": 
				document.getElementById('t_prof_mat').disabled=false;
				document.getElementById('t_prof_sal').disabled=true;
				document.getElementById('t_prof_tut').disabled=true;
				if(document.getElementById('cbonivel')){
					document.getElementById('cbonivel').disabled=true;
				}
				break;
			case "S": 
				document.getElementById('t_prof_sal').disabled=false;
				document.getElementById('t_prof_mat').disabled=true;
				document.getElementById('t_prof_tut').disabled=true;
				if(document.getElementById('cbonivel')){
					document.getElementById('cbonivel').disabled=true;
				}
				break;
			case "PT": 
				document.getElementById('t_prof_tut').disabled=false;
				document.getElementById('t_prof_sal').disabled=true;
				document.getElementById('t_prof_mat').disabled=true;
				if(document.getElementById('cbonivel')){
					document.getElementById('cbonivel').disabled=true;
				}
				break;
			case "N":
				document.getElementById('t_prof_tut').disabled=true;
				document.getElementById('t_prof_sal').disabled=true;
				document.getElementById('t_prof_mat').disabled=true;
				if(document.getElementById('cbonivel')){
					document.getElementById('cbonivel').disabled=false;
				}
				break;
			case "1":
				document.getElementById('t_prof_tut').disabled=true;
				document.getElementById('t_prof_sal').disabled=true;
				document.getElementById('t_prof_mat').disabled=true;
				if(document.getElementById('cbonivel')){
					document.getElementById('cbonivel').disabled=true;
				}
				filtros('primaria',valor);
				break;
			case "2":
				document.getElementById('t_prof_tut').disabled=true;
				document.getElementById('t_prof_sal').disabled=true;
				document.getElementById('t_prof_mat').disabled=true;
				if(document.getElementById('cbonivel')){
					document.getElementById('cbonivel').disabled=true;
				}
				filtros('secundaria',valor);
				break;
			case 'TO':
				filtros_contact('TO',valor);
				break;
			case 'IN':
				filtros_contact('IN',valor);
				break;
			case 'PR':
				filtros_contact('PR',valor);
				break;
			case 'SE':
				filtros_contact('SE',valor);
				break;
		}
	}

	function validar_filtros(filt,valor){
		if(valor!=0) filtros(filt,valor);
	}
	
	function filtros(opcion,valor){
	
	var otro='';
	if(opcion!='hijo'){
		var categ=document.getElementById('cbocategoria').value;
		
		if(categ=='F') var otro='&otro=familia';
		else{
			if(categ=='A'){ 
				var otro='&otro=alumno';				
			}
		}
	}
	if(opcion=='nivel'){		
		document.getElementById('t_prof_sal').value='0';		
	}
	if(opcion=='salon'){
		if(document.getElementById('cbonivel')){
			document.getElementById('cbonivel').value='0';
		}
	}
	ajax=objetoAjax();
	ajax.open('POST','templates/tpl_filtro_busq.php');
	ajax.onreadystatechange=function(){
		if(ajax.readyState<3)
			document.getElementById('b_grupos').innerHTML="<img src='imagenes/espera.gif' />";
		else{
			document.getElementById('b_grupos').innerHTML=ajax.responseText;
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send('filtro='+opcion+'&valor='+valor+otro);		
	}
	
	
	
	function filtros2(opcion,valor){

		ajax=objetoAjax();
		ajax.open('POST','templates/tpl_filtro_busq.php');
		ajax.onreadystatechange=function(){
			if(ajax.readyState<3)
				document.getElementById('b_grupos').innerHTML="<img src='imagenes/espera.gif' />";
			else{
				document.getElementById('b_grupos').innerHTML=ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send('filtro='+opcion+'&valor='+valor);		
	}
	
	
	
	
	
	
	function filtros_contact(opc,valor){
		ajax=objetoAjax();
		ajax.open('POST','templates/tpl_filtro_contact.php');
		ajax.onreadystatechange=function(){
			if(ajax.readyState<=3)
				document.getElementById('b_contact').innerHTML="<img src='imagenes/espera.gif' />";
			else{
				document.getElementById('b_contact').innerHTML=ajax.responseText;
			}
		}
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		ajax.send('filtro='+opc+'&valor='+valor);
	}

	function validar_hijo(valor){
		if(valor!='0'){
			filtros('hijo',valor);
		}
	}
	function validar_adm(valor){
		if(valor!='0'){
			filtros('adm',valor);
		}
	}
	
	function filtrar_salones(valor){
		if(valor!='0'){			
			ajax=objetoAjax();
			ajax.open('GET','templates/tpl_obt_salon.php?valor='+valor);
			ajax.onreadystatechange=function(){
				if(ajax.readyState==4){
					valores	=ajax.responseText;
					rpta	=valores.split("|");
					combo=document.getElementById('txtsalon').length;
					for(j=0;j<combo;j++){
						document.getElementById('txtsalon').options[j] = null;
						j--;combo--;
					}
					for(i=0;i<rpta.length-1;i++){
						valor=rpta[i].split(',');
						id_prov=valor[0];
						nombre=valor[1];
						document.getElementById('txtsalon').options[i]=new Option(nombre,id_prov);
					}	
				}
			}
			ajax.send(null);
		}
	}
	
	
	
	
		function filtrar_salones0(valor,lis){
		if(valor!='0'){		
		var valor0=$('#cbonivel').attr('value');
			ajax=objetoAjax();
			ajax.open('GET','templates/tpl_obt_salon.php?valor='+valor0+'&list='+lis+'&ano='+lis);
			ajax.onreadystatechange=function(){
				if(ajax.readyState==4){
					valores	=ajax.responseText;
					rpta	=valores.split("|");
					combo=document.getElementById('txtsalon').length;
					for(j=0;j<combo;j++){
						document.getElementById('txtsalon').options[j] = null;
						j--;combo--;
					}
					for(i=0;i<rpta.length-1;i++){
						valor=rpta[i].split(',');
						id_prov=valor[0];
						nombre=valor[1];
						document.getElementById('txtsalon').options[i]=new Option(nombre,id_prov);
					}	
				}
			}
			ajax.send(null);
		}
	}
	
	
	
	
	
	function filtrar_salones2(valor){		
		if(valor!='0'){
			$('#txtsalon').attr('value','00');
			//$('#treeboxbox_tree').html('');
			document.getElementById('treeboxbox_tree').innetHTML='';
			document.getElementById('detalle_fam').innetHTML='';
			//$('#detalle_fam').html('');
			ajax=objetoAjax();
			ajax.open('GET','templates/tpl_obt_salon.php?valor='+valor);
			ajax.onreadystatechange=function(){
				if(ajax.readyState==4){
					valores	=ajax.responseText;
					rpta	=valores.split("|");
					combo=document.getElementById('txtsalon').length;
					for(j=0;j<combo;j++){
						document.getElementById('txtsalon').options[j] = null;
						j--;combo--;
					}
					for(i=0;i<rpta.length-1;i++){
						valor=rpta[i].split(',');
						id_prov=valor[0];
						nombre=valor[1];
						document.getElementById('txtsalon').options[i]=new Option(nombre,id_prov);
					}	
				}
			}
			ajax.send(null);
		}
	}
	
	
	
	
	
	function textarea_maxlength(obj,limit){
		if(obj.value.length > limit){
			obj.value=obj.value.substring(0,limit);
			return false;
		}
	}
	
	function obtener_alumnos(){
		var nemo=$('#txtsalon').attr('value');		
		//ajax_jquery('paginas_request.php','func=1&nemo='+nemo,'txtdominio','');
		$('#txtalumnos').attr('value','00');
		$('#treeboxbox_tree').html('');

		ajax=objetoAjax();
		ajax.open('GET','obtener_alumnos.php?nemo='+nemo);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){							
				valores	=ajax.responseText;
				rpta	=valores.split("|");
				combo=document.getElementById('txtalumno').length;
				for(j=0;j<combo;j++){
					document.getElementById('txtalumno').options[j] = null;
					j--;combo--;
				}
				for(i=0;i<rpta.length-1;i++){
					valor=rpta[i].split('#');
					id_prov=valor[0];
					id_prov = id_prov.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
					nombre=valor[1];
					document.getElementById('txtalumno').options[i]=new Option(nombre,id_prov);
				}				
			}
		}
		ajax.send(null);
	}
	
	function filtrar_grado(valor){
		if(valor!='0'){
			var instrucod=$('#cbonivel').attr('value');
			ajax=objetoAjax();
			ajax.open('GET','templates/tpl_obt_grado.php?instrucod='+instrucod);
			ajax.onreadystatechange=function(){
				if(ajax.readyState==4){
					valores	=ajax.responseText;
					rpta	=valores.split("|");
					combo=document.getElementById('txtgrado').length;
					for(j=0;j<combo;j++){
						document.getElementById('txtgrado').options[j] = null;
						j--;combo--;
					}
					for(i=0;i<rpta.length-1;i++){
						valor=rpta[i].split(',');
						id_prov=valor[0];
						nombre=valor[1];
						document.getElementById('txtgrado').options[i]=new Option(nombre,id_prov);
					}
				}
			}
			ajax.send(null);
		}
	}
	
	
	
	
	function number_format (number, decimals, dec_point, thousands_sep) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');
    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}
