  /*
	* swapDivSearch(branch, linkbranch, textOpen, textClose )
	*
	* Funcion que oculta o muestra un div y modifica
	* el texto de un elemento en funci?n de si el div
	* se muestra o esta oculto
	*/
  function swapDivSearch(branch, linkbranch, textClose, textOpen, inputAnterior, inputSiguiente, camposFiltro) {
    var objBranch = document.getElementById(branch).style;
    if(objBranch.display=="block") {
      objBranch.display="none";
      document.getElementById(linkbranch).innerHTML='[+] ' + textOpen;
      if (document.getElementById(inputAnterior)!=null) {
      	document.getElementById(inputAnterior).value='off'
      }
      if (document.getElementById(inputSiguiente)!=null) {
      	document.getElementById(inputSiguiente).value='off'
      }
      if (document.getElementById(camposFiltro)!=null) {
      	document.getElementById(camposFiltro).value='off'
      }
    } else {
      objBranch.display="block";
      objBranch.visibility="visible";
      document.getElementById(linkbranch).innerHTML='[-] ' + textClose;
      if (document.getElementById(inputAnterior)!=null) {
      	document.getElementById(inputAnterior).value='on'
      }
      if (document.getElementById(inputSiguiente)!=null) {
      	document.getElementById(inputSiguiente).value='on'
      }
      if (document.getElementById(camposFiltro)!=null) {
      	document.getElementById(camposFiltro).value='off'
      }
    } 
  }
  
  /*
	* swapDiv(branch, linkbranch, text)
	*
	* Funcion que oculta o muestra un div y modifica
	* el texto de un elemento en funcion de si se encuentra
	* el div abierto o cerrado
	*/
  function swapDiv(branch, linkbranch, textClose, textOpen) {
    var objBranch = document.getElementById(branch).style;
    if(objBranch.display=="block") {
      objBranch.display="none";
      document.getElementById(linkbranch).innerHTML='[+] ' + textOpen;
    } else {
      objBranch.display="block";
      objBranch.visibility="visible";
      document.getElementById(linkbranch).innerHTML='[-] ' + textClose;
    } 
  }

  /*
	* seleccionarUnInputCheck(formName, checkName, inputArray )
	*
	* Funcion que deselecciona todos los campos imput excepto uno
	* formName nombre del formulario donde estan los checks
	* chekName nombre del check que se debe activar
	* inputArray lista de todos los checks que se deben contemplar para activar o desactivar 
	*/
	function seleccionarUnInputCheck(form, checkName, inputArray ) {
		for (x=0; x<form.length ; x++ ) {
		    if (form.elements[x].type=="checkbox") { // ?nicamente evalua los que son de tipo checkBox
		    	for (y=0; y<inputArray.length; y++){ // ?nicamente evalua aquellos que se encuentran dentro de la lista
		    		if (inputArray[y]==form.elements[x].name) {
		    			if (form.elements[x].name==checkName ) {  // Caso que se tenga que activar
							form.elements[x].checked=1;
						} else {
							form.elements[x].checked=0;
						}
		    		}
		    	}
			}
		}

	} 
	
	/*
	* checkEnablesInput(form, input, chkInput, defaultValue)
	*
	* Function que al habilitar o deshabilitar un check box habilita o deshabilita
	* un input. En caso de deshabilitar pone el valor por defecto de defaultValue.
	*/
	function checkEnablesInput(form, input, chkInput, defaultValue) {
 		enable = false;
		for (x=0; x<form.length ; x++ ) {
	 		if (chkInput==form.elements[x].name) {
	 			if (form.elements[x].checked) {
	 				enable = true;
	 			}
	 		}
	 	}
	 	for (x=0; x<form.length ; x++ ) {
	 		if (input==form.elements[x].name) {
	 			if (enable) {
		 			form.elements[x].disabled=false;
		 		} else {
			 		form.elements[x].disabled=true;
			 		form.elements[x].value=defaultValue;
		 		}
	 		}
	 	}
 	}
 	
 	/*
	* cleanInputAndCheck(form, inputArray, inputChkArray, defaultValue)
	*
	* Function que deshabilita una lista de inputs y de check, poniendo en los
	* inputs un valor por defecto.
	*/
 	function cleanInputAndCheck(form, inputArray, inputChkArray, defaultValue) {
		for (x=0; x<form.length ; x++ ) {
		    if (form.elements[x].type=="checkbox") { // unicamente evalua los que son de tipo checkBox
		    	for (y=0; y<inputChkArray.length; y++){ // unicamente evalua aquellos que se encuentran dentro de la lista
		    		if (inputChkArray[y]==form.elements[x].name) {
						form.elements[x].checked=0;
		    		}
		    	}
			} else {
				for (y=0; y<inputArray.length; y++){ // unicamente evalua aquellos que se encuentran dentro de la lista
		    		if (inputArray[y]==form.elements[x].name) {
						form.elements[x].disabled=true;
				 		form.elements[x].value=defaultValue;
		    		}
		    	}
			}
		}
	}
	
	/*
	* validateTotalPlazasValues(form, input, inputArray, msgError) 
	*
	* Esta funci?n valida que el numero total de plazas sea igual o superior al numero 
	* de subvalores de plazas ( tipos distintos tarificables ) que el usuario haya 
	* definido
	*
	* form Nombre del formulario
	* input Nombre del input que tiene el total de plazas seleccionadas por el usuario
	* inputArray Array de inputs que en los que el usuario puede indicar subvalores
	* msgError Mensaje de error
	*/
	function validateTotalPlazasValues(form, input, inputArray, msgError) {
 		total = 0;
 		tmpTotal = 0;
		for (x=0; x<form.length ; x++ ) {
	 		if (input==form.elements[x].name) {
	 			total = form.elements[x].value;
	 		}
	 	}
	 	for (x=0; x<form.length ; x++ ) {
			for (y=0; y<inputArray.length; y++){ 
	    		if (inputArray[y]==form.elements[x].name) {
		    		if (form.elements[x].disabled==false) {
	    				tmpTotal = tmpTotal + parseInt(form.elements[x].value,10);
	    			}
	    		}
	    	}
	 	}
	 	
	 	if (tmpTotal>total) {
	 		alert(msgError);
	 		return false;
	 	} else {
		 	return true;
		}
 	}
 	
 	/*
	* convertArrayToJson(array)
	*
	* Esta funcion convierte un array al formato json
	*/
 	function convertArrayToJson(array) {
	 	var jsonArray = '[';
	    for (i=0; i<array.length; i++) {    			    	
	    	if (jsonArray.length>1){
	    		jsonArray =  jsonArray + ' , ';
	    	}
	    	if (array[i]!=null) { 
		    	jsonArray = jsonArray + array[i];
		    }
	    }
	    jsonArray = jsonArray + ']';
	    
	    return jsonArray;
	 }
	 
	/**
	 * Makes pagination
	 */
	function paginate(pos) {
		var form = document.getElementById('paginate');
		form.pos.value=pos;
		form.submit();
	}
	
	/**
	 * Set value date to input 
	 */
	function setDateToInput(inputName, value) {
		$(inputName).value = value;
	}
	
	/**
	 * Se desactivan todos los check hermanos que cumplen un cierto patter ( por ejemplo prio_3_ )
	 * pero que no se corresponden con el nombre del campo ( input )
	 */
	function borrarHermanasChk(form, pattern, input) { 
     	for (x=0; x<form.length ; x++ ) {
            // Todos los campos menos el imput de los checked se deshabilitat
			if (form.elements[x].name.indexOf(pattern)>=0 && form.elements[x].name!=input) {
				form.elements[x].checked = false;
			}
		}
     }
  
