	var id=0;
	var renglon = "renglon";
	var tipoSDP  = "";

	function send(method)
	{
		document.forms[0].method.value = method;
		document.forms[0].submit();
		return;
	}
	  
	function displayOtraLey()
	{
		var idLey = document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].value;
		if(idLey == "0"){
		  showBranchAction('datosOtraLey,datosLabelOtraLey', 'block');
		} else {
		  showBranchAction('datosOtraLey,datosLabelOtraLey', 'none');
		  document.forms[0]["voNormatividad.descripcionOtra"].value = "";
		}
		return;
	}
	  
	function limpiarNormatividad()
	{
		document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].value = "-1";
		document.forms[0]["voNormatividad.descripcionOtra"].value = "";
		document.forms[0]["voNormatividad.articulo"].value = "";
		
		return;
	}

	function loadTipoSistema(){
		var categoria = this.document.forms[0].elements['fkTipoSistema.idCategoria'];
		
		creaCombo('./reloadCatalogos.do?methodToCall=tipoSistema&id='+ 
			categoria.options[categoria.selectedIndex].value,'fkTipoSistema.idTipoSistema');
	}


	function checkNorma(normatividad, tipo){
		id = normatividad;
		tipoSDP =  tipo;
		renglon = ((id%2)== 0)?"renglon":"renglonOscuro";
		//loadTipoSistema();
	   //displayOtraLey();
	}

	/* Método que manda a llamar a la petición que actualiza los
	 * catálogos del sistema de Persona a partir de dos combos.
	 * @param control1 el objeto del control 1 que invoca el método
	 * @param control2 el objeto del control 1 que invoca el método, padre de control1
	 * @param catalogo el nombre del catalogo que se esta recargando
	 * @param target el nombre del contro a donde se cargarán los catálogos 
	 * 
	 */
	function reloadCatalogoDosControles(control1,control2,catalogo,target){	
		var id1   = control1.options[control1.selectedIndex].value;
		var id2   = control2.options[control2.selectedIndex].value;
		var path = './reloadCatalogos.do?methodToCall='+catalogo+'&id1='+ id1 + '&id2=' + id2;	
		creaCombo(path,target);
	}

	/* Método que se ejecuta al momento de cambiar un combo padre
	 * para vaciar los combos que dependan de un hijo del mismo
	 * Ej. en el caso de modificar la dependencia, una vez seleccionada la
	 * unidad administrativa, y el SDP, el onchange de dependencia
	 * debe ejecutar este método para limpiar el combo de SDP * 
	 * @param objeto el componente select a vaciar  
	 * 
	 */
	function limpiaCombo(objeto){
		   var select = document.createElement("select");
		   var opciones;        
		   var opcion = document.createElement("option");
		   var id = "-1"
		   var descripcion = "SELECCIONE UNA OPCIÓN";
		   opcion.setAttribute("value", id);
		   opcion.appendChild(document.createTextNode(descripcion));
		   select.appendChild(opcion);        
		   cambiaCombo(select,objeto);
		 }


	/* Método que manda a guardar el registro de un SDP
	 */
	function guardaSDP(mTC){

		/* Esta instrucción despliega toda los controles de la forma de captura, esta es una solución
		 * orientada a IE 6.0, ya que validateFormSDP no puede actual sobre campos no desplegados.
		 */
		var mssg = '';
		if(mTC=='insert'){
			mssg = '\u00BFDesea continuar con la captura del Sistema de Datos Personales?';
		}else{
			mssg = '\u00BFDesea continuar con la modificaci\u00F3n del Sistema de Datos Personales?';	
		}
		if(id==0){
			alert("Normatividad. Debe ingresar el dato de Normatividad, es requerido");
			document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].focus();
			return false;

		}

		if(!longTextArea(document.forms[0]["finalidad"],'700','finalidad')){
			return false;
		}

		if(!longTextArea(document.forms[0]["gruposAfectados"],'256','grupos afectados')){
			return false;
		}

		if(validateFormSDP(this.document.forms[0])&&confirm(mssg)){
			this.document.forms[0].submit();
			return true;
		}

		return false;
	}

	/* Método que pide la confirmación para eliminar un SDP.
	 */
	function eliminaSDP(){
		if(confirm('\u00BFDesea eliminar al Sistema de Datos Personales?')){
			this.document.location = './dispatchActionSDP.do?method=deleteSDP'
			return true;
		}

		return false;
	}

	/* Método que inhabilita los controles del filtro de búsqueda de SDP
	 */
	function disableSDPFilter(folio){
		if(folio.value==''){
			enableAllControls();
		}else{
			disableAllControls();
		}
	}

	function enableAllControls(){
		
		var elements = document.forms[0].elements;

		for (var i=0;i<elements.length ;i++ ){
			elements[i].disabled = false;
		}
		return true;	
	}

	function disableAllControls(){
		
		var elements = document.forms[0].elements;

		for (var i=0;i<elements.length ;i++ ){

			if(!(elements[i].name=='folioCompleto' || elements[i].name=='methodToCall')){
				elements[i].disabled = true;
			}
		}
		return true;	
	}

	function buscarSDP(){
		//Si se trata del usuario público, sólo valida el formato del folio.
		//Atención!!!, si cambia el formato de la UA a más o menos dígitos hay que cambiar este método
		
		if(document.forms[0].usrProfile.value=='0'){
			var patternFolio = /(^$)|(^[0-9]{14}$)/g;

			var exist = document.forms[0].folioCompleto.value.match(patternFolio);
			if(exist==null){
				alert('El Folio debe contener 14 n\u00FAmeros [\#dependencia,\#unidad,clave del sistema].');
				return false;
			} 
		}else{
			
			if(!validateFormConsultaSDP(document.forms[0])){
				return false;	
			}
			else{			 
				this.document.forms[0].elements['pk.fkUnidadAdmva.fkDependencia.idDependencia'].disabled = false;
				this.document.forms[0].elements['pk.fkUnidadAdmva.idUnidad'].disabled = false;
			}
		}

		document.forms[0].submit();
		return true;
	}

	function updateNormatividad(mTC){
		document.forms[0].method.value=mTC;
		document.forms[0].submit();
	}

	function add() {
		idLey = document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"][document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].selectedIndex].value;
		if((idLey == 0)&&(!longTextArea(document.forms[0]["voNormatividad.descripcionOtra"],'250','descripcion de otra ley'))){
			return;
		}
		nombreLey = document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"][document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].selectedIndex].text;
		otra = (idLey == 0)?document.forms[0]["voNormatividad.descripcionOtra"].value:"";
		art = document.forms[0]["voNormatividad.articulo"].value;
		fraccion = document.forms[0]["voNormatividad.fraccion"].value;
		reglamento = document.forms[0]["voNormatividad.reglamento"].value;
		if(!longTextArea(document.forms[0]["voNormatividad.reglamento"],'250','Reglamento, Decreto, Otros')){
			return;
		}
		if(trim(art) == ""){
			alert("El dato de articulo es obligatorio");
			return;
		}
		if((idLey == 0)&&(trim(otra) == "")){
			alert("El dato de otra ley es obligatorio cuando selecciona 'Otro fundamento legal'");
			return;
		}
		document.getElementById("addNormatividad").innerHTML += builTable(id,idLey,nombreLey,otra,art,fraccion,reglamento);
		id++;
		renglon = (renglon == "renglon")?"renglonOscuro":"renglon";
		document.forms[0]["countNormatividad"].value = id;
	}
	function alerta(){
		for(i=0; i<id; i++){
			alert(document.forms[0]["normatividad["+i+"].voNormatividad.pkNormatividad.pkLey.idLey"].value+" "+document.forms[0]["normatividad["+i+"].voNormatividad.descripcionOtra"].value+""+document.forms[0]["normatividad["+i+"].voNormatividad.articulo"].value);
		}
	}
	function eliminar(selected){
		var result = createTableTitle();
		var x = 0;
		for(i=0; i<id; i++){
			if (i != selected){
				ley = document.forms[0]["normatividad["+i+"].voNormatividad.pkNormatividad.pkLey.idLey"].value;
				nombreLey=document.forms[0]["normatividad["+i+"].voNormatividad.pkNormatividad.pkLey.descripcion"].value;
				otra = (ley == 0)?document.forms[0]["normatividad["+i+"].voNormatividad.descripcionOtra"].value:"";
				art = document.forms[0]["normatividad["+i+"].voNormatividad.articulo"].value;
				fraccion = document.forms[0]["normatividad["+i+"].voNormatividad.fraccion"].value;
				reglamento = document.forms[0]["normatividad["+i+"].voNormatividad.reglamento"].value;
				result += builTable(x,ley,nombreLey,otra,art,fraccion,reglamento);
				x++;
				renglon = (renglon == "renglon")?"renglonOscuro":"renglon";
			}
		}
		document.getElementById("addNormatividad").innerHTML = result;
		id--;
		document.forms[0]["countNormatividad"].value = id;
	}

	function modificar(selected){
		var result = createTableTitle();
		var x = 0;
		for(i=0; i<id; i++){
			if (i != selected){
				ley = document.forms[0]["normatividad["+i+"].voNormatividad.pkNormatividad.pkLey.idLey"].value;
				nombreLey=document.forms[0]["normatividad["+i+"].voNormatividad.pkNormatividad.pkLey.descripcion"].value;
				otra = (ley == 0)?document.forms[0]["normatividad["+i+"].voNormatividad.descripcionOtra"].value:"";
				art = document.forms[0]["normatividad["+i+"].voNormatividad.articulo"].value;
				fraccion = document.forms[0]["normatividad["+i+"].voNormatividad.fraccion"].value;
				reglamento = document.forms[0]["normatividad["+i+"].voNormatividad.reglamento"].value;
				result += builTable(x,ley,nombreLey,otra,art,fraccion,reglamento);
				x++;
				renglon = (renglon == "renglon")?"renglonOscuro":"renglon";
			}else{
				ley = document.forms[0]["normatividad["+i+"].voNormatividad.pkNormatividad.pkLey.idLey"].value;
				otra = document.forms[0]["normatividad["+i+"].voNormatividad.descripcionOtra"].value;
				art = document.forms[0]["normatividad["+i+"].voNormatividad.articulo"].value;
				fraccion = document.forms[0]["normatividad["+i+"].voNormatividad.fraccion"].value;
				reglamento = document.forms[0]["normatividad["+i+"].voNormatividad.reglamento"].value;
				document.forms[0]["voNormatividad.descripcionOtra"].value = otra;
				document.forms[0]["voNormatividad.articulo"].value = art;
				document.forms[0]["voNormatividad.fraccion"].value = fraccion;
				document.forms[0]["voNormatividad.reglamento"].value = reglamento;
				if(ley == 0){
					document.getElementById("datosOtraLey").style.display = "block";
					document.getElementById("datosLabelOtraLey").style.display = "block";
				}else{
					document.getElementById("datosOtraLey").style.display = "none";
					document.getElementById("datosLabelOtraLey").style.display = "none";
				}
				for (a=0;a < document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].options.length;a++){
					if(ley == document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].options[a].value){
						document.forms[0]["voNormatividad.pkNormatividad.pkLey.idLey"].selectedIndex = a;
					}
				}
			}
		}
		document.getElementById("addNormatividad").innerHTML = result;
		id--;
		document.forms[0]["countNormatividad"].value = id;
	}

	function builTable(pos, ley, nombreLey, otra, art, fraccion, reglamento){
		var table = ""; 
			table += "<table width='80%' align='center' valign='center' cellpadding='0' cellspacing='0'>";
			table += " <tr class="+renglon+">";
			table += "  <td width='30%'>";
			table += "    <input type='hidden' name='normatividad["+pos+"].voNormatividad.pkNormatividad.pkLey.descripcion' value = '"+nombreLey+"'>";
			table += "    <input type='hidden' name='normatividad["+pos+"].voNormatividad.pkNormatividad.pkLey.idLey' value = '"+ley+"'>";
			table +=       nombreLey;
			table += "  </td>";
			table += "  <td width='20%'>";
			table += "    <input type='hidden' name='normatividad["+pos+"].voNormatividad.descripcionOtra' value = '"+otra+"'>";
			table += "    &nbsp;"+otra;
			table += "  </td>";
			table += "  <td width='10%'>";
			table += "    <input type='hidden' name='normatividad["+pos+"].voNormatividad.articulo' value = '"+art+"'>";
			table += "    &nbsp;"+art;
			table += "  </td>";
			table += "  <td width='10%'>";
			table += "    <input type='hidden' name='normatividad["+pos+"].voNormatividad.fraccion' value = '"+fraccion+"'>";
			table += "    &nbsp;"+fraccion;
			table += "  </td>";
			table += "  <td width='20%'>";
			table += "    <input type='hidden' name='normatividad["+pos+"].voNormatividad.reglamento' value = '"+reglamento+"'>";
			table += "    &nbsp;"+reglamento;
			table += "  </td>";
			table += "  <td width='5%'>";
			table += "    <input type='radio' name='Modificar' onClick='modificar("+pos+")'>";
			table += "  </td>";
			table += "  <td width='5%'>";
			table += "    <input type='radio' name='Eliminar' onClick='eliminar("+pos+")'>";
			table += "  </td>";
			table += " </tr>";
			table += "</table>";
			return table;
	}

	function createTableTitle(){
		var table = ""; 
			table += "<table width='80%' align='center' valign='center' cellpadding='0' cellspacing='0'>";
			table += " <tr class='tituloColumna'>";
			table += "  <td width='30%'>";
			table += "    Ley";
			table += "  </td>";
			table += "  <td width='20%'>";
			table += "    Otra Ley";
			table += "  </td>";
			table += "  <td width='10%'>";
			table += "    Articulo";
			table += "  </td>";
			table += "  <td width='10%'>";
			table += "    Fraccion";
			table += "  </td>";
			table += "  <td width='20%'>";
			table += "    Reglamento";
			table += "  </td>";
			table += "  <td width='5%'>";
			table += "    Modificar";
			table += "  </td>";
			table += "  <td width='5%'>";
			table += "    Eliminar";
			table += "  </td>";
			table += " </tr>";
			table += "</table>";
			return table;
	}	

	function selectTipo(value){
		for (a=0;a < document.forms[0]["fkTipoSistema.idTipoSistema"].options.length;a++){
			if(value == document.forms[0]["fkTipoSistema.idTipoSistema"].options[a].value){
				document.forms[0]["fkTipoSistema.idTipoSistema"].selectedIndex = a;
			}
		}
	}
   
    function cambiaTipoSDP(){
		tipoSDP = document.forms[0]["fkTipoSistema.idTipoSistema"].options[document.forms[0]["fkTipoSistema.idTipoSistema"].selectedIndex].value;
	}
	
	function selectTipoSDP(){
		selectTipo(tipoSDP);
	}

	function openWin(pager){
		var ventana = window.open("./printReportSDP.do?pager.offset="+pager, "Persona_Print","height=200,width=400,status=no,toolbar=no,menubar=no,location=no, resizable=yes,scrollbars=yes");
	}
	function openWinAcuse(rutaAcuse){
		var ventana = window.open(rutaAcuse, "Persona_Acuse","height=200,width=400,status=no,toolbar=no,menubar=no,location=no, resizable=yes,scrollbars=yes");
	}
	
	function cambiaUASDP(){							
		if(!validateFormCambioUASDP(document.forms[0])){
			return false;	
		}
		if(!validateCheckbox(0,'idSDPCambioUA','Seleccione al menos un SDP para modificar su Unidad Administrativa')){
			return false;
		}
		document.forms[0].submit();
		return true;
	}
	function validateCheckbox(formNumber, checkname, msg){
		var forma = document.forms[formNumber];
		var chks = forma.elements[checkname];
		if (chks){ //checkbox(s) existe
			var checked = false;
			if (chks.length){ //multiples checkboxes
				var len = chks.length;
				for (var i=0; i<len; i++){
					if (chks[i].checked){
						checked = true;
						break;
					}
				}
			}
			else{ //solo un checkbox
				checked = chks.checked;
			}
			if (!checked){
				alert(msg);
				return false;
			}
		}
		return true;
	}
	
	function seleccionaTodo(formObj, isInverse){		
	   for (var i=0;i < formObj.length;i++) {
	      fldObj = formObj.elements[i];	      
	      if (fldObj.type == 'checkbox'){ 
	         if(isInverse){
	            fldObj.checked = (fldObj.checked) ? false : true;
	         }else{
	         	fldObj.checked = true;
	         }
	       }
	   }
	}


