// JavaScript Document
 function fecha(){
	var dayNames = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");

	var monthNames = new Array("enero","febrero","marzo","abril","mayo","junio","julio",
                           "agosto","septiembre","octubre","noviembre","diciembre");
	var dt = new Date();
	var y  = dt.getYear();
	if (y < 1000) y +=1900;
		document.write(dayNames[dt.getDay()] + ", " + dt.getDate() + " de " + monthNames[dt.getMonth()] + " de " + y);
 }
 
  function muestraSubMenuV(nombre){	 
  	  if(nombre == 'subMPrograma'){		  				  
		  document.getElementById(nombre).style.display = "block";
	  }	  	 
  }
  
  function ocultaSubMenuV(nombre){
	  if(nombre == 'subMPrograma'){		  				  
		  document.getElementById(nombre).style.display = "none";
	  }		 
  }

  //Precarga las imagenes
  if (document.images) {
		fac1 = new Image(37,19); fac1.src = "img/menuV/fb1.gif";
		fac2 = new Image(37,19); fac2.src = "img/menuV/fb2.gif";
		twi1 = new Image(37,19); twi1.src = "img/menuV/tw1.gif";
		twi2 = new Image(37,19); twi2.src = "img/menuV/tw2.gif";
		fli1 = new Image(37,19); fli1.src = "img/menuV/fl1.gif";
		fli2 = new Image(37,19); fli2.src = "img/menuV/fl2.gif";
		can1 = new Image(37,19); can1.src = "img/menuV/cn1.gif";
		can2 = new Image(37,19); can2.src = "img/menuV/cn2.gif";
		you1 = new Image(37,19); you1.src = "img/menuV/yt1.gif";
		you2 = new Image(37,19); you2.src = "img/menuV/yt2.gif";
		rss1 = new Image(37,19); rss1.src = "img/menuV/rs1.gif";
		rss2 = new Image(37,19); rss2.src = "img/menuV/rs2.gif";
		pre1 = new Image(231,76); pre1.src = "img/menuV/preescolar1.gif";
		pre2 = new Image(231,76); pre2.src = "img/menuV/preescolar2.gif";
		pri1 = new Image(231,76); pri1.src = "img/menuV/primaria1.gif";
		pri2 = new Image(231,76); pri2.src = "img/menuV/primaria2.gif";
		sec1 = new Image(231,76); sec1.src = "img/menuV/secundaria1.gif";
		sec2 = new Image(231,76); sec2.src = "img/menuV/secundaria2.gif";		
		actMV1 = new Image(227,63); actMV1.src = "img/menuV/act1.png";
		actMV2 = new Image(227,63); actMV2.src = "img/menuV/act2.png";
		croMV1 = new Image(227,63); croMV1.src = "img/menuV/cro1.png";
		croMV2 = new Image(227,63); croMV2.src = "img/menuV/cro2.png";
		libMV1 = new Image(227,63); libMV1.src = "img/menuV/lib1.png";
		libMV2 = new Image(227,63); libMV2.src = "img/menuV/lib2.png";
		vidMV1 = new Image(227,63); vidMV1.src = "img/menuV/vid1.png";
		vidMV2 = new Image(227,63); vidMV2.src = "img/menuV/vid2.png";
		teo1 = new Image(227,63); teo1.src = "img/menuV/teo1.png";
		teo2 = new Image(227,63); teo2.src = "img/menuV/teo2.png";
		act1 = new Image(141,85); act1.src = "img/inicio/act1.png";
		act2 = new Image(141,85); act2.src = "img/inicio/act2.png";
		cro1 = new Image(141,85); cro1.src = "img/inicio/cro1.png";
		cro2 = new Image(141,85); cro2.src = "img/inicio/cro2.png";
		vid1 = new Image(141,85); vid1.src = "img/inicio/vid1.png";
		vid2 = new Image(141,85); vid2.src = "img/inicio/vid2.png";
		lib1 = new Image(141,85); lib1.src = "img/inicio/lib1.png";
		lib2 = new Image(141,85); lib2.src = "img/inicio/lib2.png";
		cons1 = new Image(124,93); cons1.src = "img/botones/consulta1.png";
		cons2 = new Image(124,93); cons2.src = "img/botones/consulta2.png";
		opi1 = new Image(124,93); opi1.src = "img/botones/opina1.png";
		opi2 = new Image(124,93); opi2.src = "img/botones/opina2.png";
		
		
 }
 
 function hiLite(imgName,imgObjName) {
		if (document.images) {					
		  document.images[imgName].src = eval(imgObjName + ".src");
		}
 }
 function revisaForma(){
	 var mes = document.getElementById("comboMes").value;
	 var anio = document.getElementById("comboAnio").value;
	 if(mes!="" && anio==""){		 
	 	window.alert('Si selecciona un mes debe seleccionar un a\xF1o')
		return false;
	 }	 
	 return true;
 }
 
  function muestraCombo(invoca){
	  var comboMat = document.getElementById('comboMat');	  
	  var comboCiclo = document.getElementById('comboCiclo');
	  var comboNivel = document.getElementById('comboNivel');
	  var comboGrado = document.getElementById('comboGrado');
	  var comboSecreto = document.getElementById('comboSecreto');
	  
	  var valorMat = comboMat.value;	  
	  var hijosSecreto;
	  var temp = "";
	  var bandera = false;
	  if(invoca=='comboMat'){
		  limpiaCombo(comboCiclo);
		  limpiaCombo(comboNivel);
		  limpiaCombo(comboGrado);
		  comboCiclo.style.display = "none";
		  comboNivel.style.display = "none";
		  comboGrado.style.display = "none";		  
		  
		  var i = 1;
		  var nuevaOpc;	
		  temp = comboMat.value + "0910";		  
		  if (existeClave(temp,6)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "2009 - 2010";
			  nuevaOpc.value = "0910";
			  comboCiclo.options[i] = nuevaOpc;
			  i++;
			  bandera = true;
		  }
		  temp = comboMat.value + "1011";
		   if (existeClave(temp,6)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "2010 - 2011";
			  nuevaOpc.value = "1011";
			  comboCiclo.options[i] = nuevaOpc;
			  i++;
			  bandera = true;
		  }
		  temp = comboMat.value + "1112";
		   if (existeClave(temp,6)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "2011 - 2012";
			  nuevaOpc.value = "1112";
			  comboCiclo.options[i] = nuevaOpc;
			  i++;
			  bandera = true;
			  
		   }
		  temp = comboMat.value + "1213";
		   if (existeClave(temp,6)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "2012 - 2013";
			  nuevaOpc.value = "1213";
			  comboCiclo.options[i] = nuevaOpc;
			  i++;
			  bandera = true;
			  
		  }
		  if(bandera){
		  	comboCiclo.style.display = "block";
		  }
	  }
	  else if(invoca=='comboCiclo'){		  
		  limpiaCombo(comboNivel);
		  limpiaCombo(comboGrado);		  
		  comboNivel.style.display = "none";
		  comboGrado.style.display = "none";
		  var i = 1;
		  var nuevaOpc;	
		  temp = comboMat.value + comboCiclo.value + "pre";			  
		  if (existeClave(temp,9)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Preescolar";
			  nuevaOpc.value = "pre";
			  comboNivel.options[i] = nuevaOpc;
			  i++;
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + "pri";		  
		  if (existeClave(temp,9)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Primaria";
			  nuevaOpc.value = "pri";
			  comboNivel.options[i] = nuevaOpc;
			  i++;		
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + "sec";		  
		  if (existeClave(temp,9)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Secundaria";
			  nuevaOpc.value = "sec";
			  comboNivel.options[i] = nuevaOpc;
			  i++;	
			  bandera = true;
		  }	
		  if(bandera){
			  comboNivel.style.display = "block";
		  }
	  }
	  else if(invoca=='comboNivel'){		  
		  limpiaCombo(comboGrado);		  		  
		  comboGrado.style.display = "none";
		  var i = 1;
		  var nuevaOpc;	
		  temp = comboMat.value + comboCiclo.value + comboNivel.value + "1";
		  
		  if (existeClave(temp,10)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Primero";
			  nuevaOpc.value = "1";
			  comboGrado.options[i] = nuevaOpc;
			  i++;	
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + comboNivel.value + "2";			  
		  if (existeClave(temp,10)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Segundo";
			  nuevaOpc.value = "2";
			  comboGrado.options[i] = nuevaOpc;
			  i++;	
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + comboNivel.value + "3";			  
		  if (existeClave(temp,10)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Tercero";
			  nuevaOpc.value = "3";
			  comboGrado.options[i] = nuevaOpc;
			  i++;			 
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + comboNivel.value + "4";			  
		  if (existeClave(temp,10)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Cuarto";
			  nuevaOpc.value = "4";
			  comboGrado.options[i] = nuevaOpc;
			  i++;	
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + comboNivel.value + "5";			  
		  if (existeClave(temp,10)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Quinto";
			  nuevaOpc.value = "5";
			  comboGrado.options[i] = nuevaOpc;
			  i++;	
			  bandera = true;
		  }
		  temp = comboMat.value + comboCiclo.value + comboNivel.value + "6";			  
		  if (existeClave(temp,10)){
			  nuevaOpc = document.createElement('option')
			  nuevaOpc.text = "Sexto";
			  nuevaOpc.value = "6";
			  comboGrado.options[i] = nuevaOpc;
			  i++;	
			  bandera = true;
		  }
		  if(bandera){
			  comboGrado.style.display = "block";
		  }
	  }
  }
  
  function existeClave(clave,cuantos){
	  var comboSecreto = document.getElementById('comboSecreto');
	  var hijosSecreto = comboSecreto.options;
	  var aux = "";
	  for(i=0; i < hijosSecreto.length; i++){
		  aux = hijosSecreto[i].value.substring(0,cuantos);
		  if(clave == aux){
			  return true;
		  }
	  }
	  return false;
  }
  
  function limpiaCombo(comboLimpiar){
	  var i;
	  for(i=1; i <=comboLimpiar.length; i++){
	  	comboLimpiar.options[i] = null;
	  }
	  comboLimpiar.selectedIndex = 0;
  }
  function removeDuplicateElement(arrayName){
	  var newArray=new Array();
	  label:for(var i=0; i<arrayName.length;i++ ){
				for(var j=0; j<newArray.length;j++ ){
					  if(newArray[j]==arrayName[i])
					  continue label;
				}
				newArray[newArray.length] = arrayName[i];
			}
	return newArray;
  }
  
  function consultaHide(){	  
	  var comboMat = document.getElementById('comboMat');	  
	  var comboCiclo = document.getElementById('comboCiclo');
	  var comboNivel = document.getElementById('comboNivel');
	  var comboGrado = document.getElementById('comboGrado');
	  var comboSecreto = document.getElementById('comboSecreto');
	  var oculto = document.getElementById('consOculta');	 
	  var stringTemp = "";	  
	  
	  if (comboMat.selectedIndex != "0" && comboCiclo.selectedIndex != "0" && comboNivel.selectedIndex != "0" && comboGrado.selectedIndex != "0"){
		  stringTemp = comboMat.options[comboMat.selectedIndex].text + "//";
		  stringTemp += comboCiclo.options[comboCiclo.selectedIndex].text + "//";
		  stringTemp += comboNivel.options[comboNivel.selectedIndex].text + "//";
		  stringTemp += comboGrado.options[comboGrado.selectedIndex].text;
		  oculto.value = stringTemp;		  
		  return true
	  }	  
	  else{
		  window.alert('Debe seleccionar todos todos los filtros');
		  return false;
	  }
  }
  
  function muestraLigaEncuesta(){
	  var comboMat = document.getElementById('comboMatEncuesta');	  
	  var comboNivel = document.getElementById('comboNivelEncuesta');
	  var divPrinc = document.getElementById('divContenidoBusqueda');
	  if (divPrinc.hasChildNodes()){
		  for (var i = 0; i < divPrinc.childNodes.length; i++){
			  divPrinc.removeChild(divPrinc.childNodes[i]);
		  }
	  }
	  if (comboMat.selectedIndex == "0" || comboNivel.selectedIndex == "0"){
		  window.alert('Debe seleccionar todos los campos');
		  divPrinc.innerText = "Dentro de esta sección podrás encontrar vínculos hacia las encuestas de los libros relacionados con la RIEB, agradecemos tu interés.";
	  }
	  else{
		  divPrinc.innerText = "";
		  var liga = document.createElement('a');		  
		  liga.setAttribute('target','_blank');
		  if(comboNivel.value == "pre" && comboMat.value == "al"){
			  liga.innerText = "Alumno/Preescolar";
			  liga.setAttribute('href','http://cuestionarios.dgme.sep.gob.mx/cuest_prees_flash/cuestionario_flash.php');
		  }
		  else if(comboNivel.value == "pre" && comboMat.value == "fa"){
			  liga.innerText = "Familia/Preescolar";
			  liga.setAttribute('href','http://cuestionarios.dgme.sep.gob.mx/cuest_padres_flash/cuestionario_flash.php');
		  }
		  else if(comboNivel.value == "pre" && comboMat.value == "ma"){
			  liga.innerText = "Profesores/Preescolar";
			  liga.setAttribute('href','http://basica.sep.gob.mx/seb2008/start.php?act=opipreescolar');
		  }		  
		  else if(comboNivel.value == "pri" && comboMat.value == "al"){
			   liga.innerText = "Alumno/Primaria";
			   liga.setAttribute('href','http://cuestionarios.dgme.sep.gob.mx/cuestalumno_10');
		  }		  
		  else if(comboNivel.value == "pri" && comboMat.value == "fa"){
			   liga.innerText = "Familia/Primaria";
			   liga.setAttribute('href','http://cuestionarios.dgme.sep.gob.mx/fam_libeduprim');
		  }
		  else if(comboNivel.value == "pri" && comboMat.value == "ma"){
			   liga.innerText = "Profesores/Primaria";
			   liga.setAttribute('href','http://cuestionarios.dgme.sep.gob.mx/docentes_libdocente/');
		  }
		  divPrinc.appendChild(liga);
	  }
  }
