// JavaScript Functions

/*
onerror=handleErr

//CAPTURA LOS ERRORES JAVASCRIPT
function handleErr(msg,url,l)
{
var txt=""
txt="There was an error on this page.\n\n"
txt+="Error: " + msg + "\n"
txt+="URL: " + url + "\n"
txt+="Line: " + l + "\n\n"
txt+="Click OK to continue.\n\n"
alert(txt)
return true
}
//-----------------------------
*/


//=-=-=-=-=-=-=-=-//
//===VALIDATION===//
//=-=-=-=-=-=-=-=-//

//---VALIDACIÓN DE CAMPOS GENERAL--->
	//arr_campos[][0] = "TITULO"
	//arr_campos[][1] = "id_objeto"
	//arr_campos[][2] = int_tipo
	  //0 = Texto Plano
	  //1 = Combo
	  //2 = Combo de Año
	  //3 = Número Entero
	  //4 = Número que acepta decimales
	  //5 = Dia Mes Año
	  //6 = EMail
	  //7 = CUIT
	  //8 = OptionButtons (arr_campos[i][1] = id_sexo-2, donde 2 es la cantidad de opciones -0 y 1 en este caso-)
	  //9 = Contraseña -> ???
	  //10 = Nro de Teléfono.
	//arr_campos[][3] = bool_nulleable
	  //0 = No acepta nulls
	  //1 = Acepta nulls
	function validacion(campos) {
		var arr_campos = campos.split(";");
		var cosa;
		var i;
		for (i=0;i<arr_campos.length;i++) {
			arr_campos[i] = arr_campos[i].split("|");
		}
		
		for (i=0;i<arr_campos.length;i++) {
			//alert("titulo:"+arr_campos[i][0]+";id_objeto="+arr_campos[i][1]+";tipo="+arr_campos[i][2]+";nulleable="+arr_campos[i][3]+";");
			cosa = document.getElementById(arr_campos[i][1])
			if (arr_campos[i][2] == 0) {
				if (cosa.value == "") {
					if (arr_campos[i][3] == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						cosa.focus();
						pintar(cosa.id);
						return false;
					}
				}
			} else if (arr_campos[i][2] == 1 || arr_campos[i][2] == 2) {
				if (cosa.value == "-1") {
					if (arr_campos[i][3] == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						cosa.focus();
						pintar(cosa.id);
						return false;
					}
				}
			} else if (arr_campos[i][2] == 3) {
				if (cosa.value == "") {
					if (arr_campos[i][3] == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						cosa.focus();
						pintar(cosa.id);
						return false;
					}
				} else {
					if (isNumeric(cosa.value) == false) {
						alert("El campo '"+arr_campos[i][0]+"' tiene un valor inválido");
						cosa.select();
						pintar(cosa.id);
						return false;
					}
				}
			} else if (arr_campos[i][2] == 4) {
				if (cosa.value == "") {
					if (arr_campos[i][3] == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						cosa.focus();
						pintar(cosa.id);
						return false;
					}
				} else {
					if (isCommaNumeric(cosa.value) == false) {
						alert("El campo '"+arr_campos[i][0]+"' debe ser un número positivo");
						cosa.select();
						pintar(cosa.id);
						return false;
					}
				}
			} else if (arr_campos[i][2] == 5) {
				var dia = document.getElementById(arr_campos[i][1]+"-d");
				var mes = document.getElementById(arr_campos[i][1]+"-m");
				var año = document.getElementById(arr_campos[i][1]+"-a");
				if (dia.value != -1 && mes.value != -1 && año.value != -1) {
				} else {
					if (dia.value == -1 && mes.value == -1 && año.value == -1) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						dia.focus();
						pintar(dia.id);
						pintar(año.id);
						pintar(mes.id);
						return false;
					} else {
						if (año.value == -1 ) {
							pintar(año.id);
							año.focus();
						}
						if (mes.value == -1) {
							pintar(mes.id);
							mes.focus();
						}
						if (dia.value == -1) {
							pintar(dia.id);
							dia.focus();
						}
						alert("El campo '"+arr_campos[i][0]+"' no está completo");
						return false
					}
				}
			} else if (arr_campos[i][2] == 6) {
				if (cosa.value == "") {
					if (arr_campos[i][3] == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						cosa.focus();
						pintar(cosa.id);
						return false;
					}
				} else {
					if (checkMail(cosa.value) == false) {
					//if (isAlphanumeric(cosa.value, "@_.-") == false || isEmail(cosa.value) == false) {
						alert("El campo '"+arr_campos[i][0]+"' no tiene una dirección de e-mail correcta");
						cosa.select();
						pintar(cosa.id);
						return false;
					}
				}
			} else if (arr_campos[i][2] == 7) {
				if (cosa.value == "") {
					if (arr_campos[i][3] == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						cosa.focus();
						pintar(cosa.id);
						return false;
					}
				} else {
					if (isValidCuit(cosa.value) == false) {
						alert("El campo '"+arr_campos[i][0]+"' no tiene un número de CUIT válido");
						cosa.select();
						pintar(cosa.id);
						return false;
					}
				}
			} else if (arr_campos[i][2] == 8) {
				var opciones = arr_campos[i][1].split(",");
				var estado = 0;
				if (arr_campos[i][3] == 0) {
					for (n=0;n<opciones[1];n++) {
						try {
							if (document.getElementById(opciones[0]+"-"+n).checked == true) {
								estado = 1;
							}
						}
						catch (ex) {
							continue;
						}
					}
					if (estado == 0) {
						alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
						//document.getElementById(opciones[0]+"-0").focus();
						return false;
					}
				}
			} else if (arr_campos[i][2] == 9) {
				valida_contraseña();
			} else if (arr_campos[i][2] == 10) {
				if (cosa.value == "") {
					alert("El campo '"+arr_campos[i][0]+"' no puede estar vacío");
					cosa.focus();
					pintar(cosa.id);
					return false;
				} else if (!checkTel(cosa.value)) {
					alert("El campo '"+arr_campos[i][0]+"' no tiene un teléfono válido");
					cosa.focus();
					pintar(cosa.id);
					return false;
				}
			} else {
				
			}
		}
		return true;
	}
//----->

//---VALIDACIÓN EXTRA PARA LOS IDIOMAS--->
	function valida_idiomas() {
		var idioma = document.getElementById("lang-idioma");
		var nivel = document.getElementById("lang-nivel");
		for (i=0;i<c_idiomas;i++) {
			try {
				if (idioma.options[idioma.selectedIndex].text == document.getElementById("id-lang-idioma-"+i).value) {
					alert("El idioma '"+idioma.options[idioma.selectedIndex].text+"' ya fue ingresado");
					idioma.focus();
					pintar(idioma.id);
					return false;
					break;
				}
			}
			catch(ex) {
				continue;
			}
		}
		return true;
	}
//----->

//---VALIDACIÓN EXTRA PARA LA CONTRASEÑA--->
	function valida_contraseña() {
		var pass = document.getElementById("id_password");
		var pass2 = document.getElementById("id_password2");
		if (pass.value.length < 8 || isAlphanumeric(pass.value, "") == false) {
			alert ("La contraseña debe tener 8 caracteres como mínimo y debe ser alfanumérica");
			pintar(pass.id);
			pass.select()
			return false;
		}
		if (pass.value != pass2.value) {
			alert ("Las contraseñas ingresadas no son iguales");
			pintar(pass.id);
			pintar(pass2.id);
			pass.select();
			return false;
		}
		return true;
	}
//----->

	function validacion_anios(primero, segundo) {
		var anio_ingreso = document.getElementById(primero);
		var anio_egreso = document.getElementById(segundo);
		if (anio_ingreso.value != -1 && anio_egreso.value != -1) {
			if (anio_ingreso.value > anio_egreso.value) {
				alert ("El año de egreso no puede ser anterior al año de ingreso");
				pintar(anio_ingreso.id);
				pintar(anio_egreso.id);
				anio_ingreso.focus();
				return false
			}
		}
		return true
	}
	
	
	function valida_titulos_habilitantes() {
		return validacion_anios("th-anio_ingreso", "th-anio_egreso");
	}	
	function valida_otros_titulos() {
		return validacion_anios("ot-anio_ingreso", "ot-anio_egreso");
	}
	function valida_antecedentes_docentes() {
		if (validacion_anios("ad-anio_desde", "ad-anio_hasta") == false) {
			return false;
		} else {
			for (i=0;i<20;i++) {
				if (document.getElementById("edades_educandos-"+i).checked == true) {
					return true;
				}
			}
			alert("El campo 'Edades en años de los educandos' no puede estar vacío");
			return false
		}
		
	}
	function valida_antecedentes_no_docentes() {
		return validacion_anios("and-anio_desde", "and-anio_hasta");
	}
	function valida_casillas_institucion() {
		return validacion("Casilla|eml-casilla|6|0");
	}
	function valida_contactos_institucion() {
		return validacion("e-Mail|con-email|6|1");
	}





//---DECIDE SI UNA CADENA ES NUMÉRICA (CON COMAS)---//
	function isCommaNumeric(sText) {
	var ValidChars = "1234567890";
	var otros = ",.";
	var numcount = 0;
	var comacount = 0;
	var Char;
		for (i=0;i<sText.length;i++) {
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1) {
				if (otros.indexOf(Char) == -1) {
					return false
				} else {
					comacount++;
				}
			} else {
				numcount = 1;
			}
			if (comacount > 1) {
				return false;
			}
		}
		if (numcount == 1) {
			return true;
		} else {
			return false;
		}
	}
//----->
	
//---DECIDE SI UNA CADENA ES NUMÉRICA (SIN COMAS)--//
	function isNumeric(sText) {
	var ValidChars = "1234567890";
	var Char;
		for (i=0;i<sText.length;i++) {
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1) {
				return false
			}
		}
		return true
	}
//----->>
	
//---DECIDE SI UNA CADENA ES ALFANUMÉRICA---//
	function isAlphanumeric(texto, extras) {
		var numeros = "1234567890";
		var letras = "abcdefghijklmnñopqrstuvwxyzçáéíóúäëïöüABCDEFGHIJKLMNÑOPQRSTUVWXYZÇÁÉÍÓÚÄËÏÖÜ";
		var char;
		var cuenta = Array()
		cuenta[0] = 0;
		cuenta[1] = 0;
		for (i=0;i<texto.length;i++) {
			char = texto.charAt(i);
			if (numeros.indexOf(char) != -1) {
				cuenta[0] = 1;
			} else {
				if (letras.indexOf(char) != -1) {
					cuenta[1] = 1;
				} else {
					if (extras.indexOf(char) != -1) {
						cuenta[2] == 1;
					} else {
						return false;
					}
				}
			}
		}
		if (cuenta[0] == 1 || cuenta[1] == 1) {
			return true;
		} else {
			return false;
		}
	}
//----->>
	
//---DECIDE SI UN CAMPO TIENE UN EMAIL CORRECTO--//
	function isEmail (texto) {
		var a = Array();
		a[0] = "@";
		a[1] = ".";
		var char;
		var count = Array();
		count[0] = 0;
		count[1] = 0;
		for (i=0;i<texto.length;i++) {
			char = texto.charAt(i);
			if (a[0].indexOf(char) != -1) {
				count[0] = 1;
			} else {
				if (a[1].indexOf(char) != -1) {
					count[1] = 1;
				}
			}
		}
		if (count[0] != 1 || count[1] != 1) {
			return false;
		} else {
			return true;
		}
	}
//----->

function checkMail(dir) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(dir)) {
		return true
	} else {
		return false
	}
}


function checkTel(dir) {
	var filter  = /^(\([0-9]{2,4}\))*(([0-9])+-)+([0-9])+$/;
	if (filter.test(dir)) {
		return true
	} else {
		return false
	}
}


//---DECIDE SI UN CAMPO TIENE UN CUIT CORRECTO--//
function isValidCuit(cuit) {
	if (cuit.length != 13) {
		return false;
	}
	if (cuit.charAt(2) != "-" || cuit.charAt(11) != "-") {
		return false
	}	
	var auxcuit = "";
	for (i=0;i<cuit.length;i++)
		if (cuit.charAt(i) != "-") 
			auxcuit += cuit.charAt(i);
	cuit = auxcuit;
	if (cuit.length != 11) {
		return false;
	}
	var suma = 0;
	var aux = "5,4,3,2,7,6,5,4,3,2";
	var productos = aux.split(",");
	for (i=0;i<10;i++)
		suma += cuit.charAt(i) * productos[i];
	var resto = suma % 11;
	var digito
	if (resto == 0) {
		aux = 0;
	} else if (resto == 1) {
		aux = 9;
	} else {
		aux = 11 - resto;
	}
	if (cuit.charAt(10) == aux) {
		return true;
	} else {
		return false;
	}
}
//----->

//=-=-=-=-=-=-=-=-=-=-//






//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=//
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=//





//=-=-=-=-=-=-=-=//
//===MECHANICS===//
//=-=-=-=-=-=-=-=//

	function irA(loc) {
		document.location = loc;
	}

//---REMUEVEN ESPACIOS SOBRANTES EN UNA CADENA--->
	function LTrim( value ) {
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	}
	function RTrim( value ) {
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
	}
	function trim( value ) {
		return LTrim(RTrim(value));
	}
//----->

//---FUNCIONES DE MANEJO DE COLORES--->
	function restartcolor(id) {
		document.getElementById(id).style.backgroundColor = "#FFFFFF";
	}
	function pintar(id) {
		document.getElementById(id).style.backgroundColor = "#FFAAAA";
	}
//----->
	
//---MOVIMIENTOS ENTRE DIVS--->
	function avanzar_a(div) {
		
		document.getElementById("d"+(div-1)).className="closed";
		document.getElementById("d"+div).className="opened";
		/*
		document.getElementById("d"+(div-1)).style.display="none";
		document.getElementById("d"+div).style.display="block";
		*/
	}
	function volver_a(div) {
		document.getElementById("d"+(div+1)).className="closed";
		document.getElementById("d"+div).className="opened";
		/*
		document.getElementById("d"+(div+1)).style.display="none";
		document.getElementById("d"+div).style.display="block";
		*/
	}
//----->
	
//---AGREGA UNA FILA A LA TABLA--->
	function addRow(table, campos, cuenta, estilo) {
		var tabla = document.getElementById(table);
		var rows = tabla.rows.length;
		var arr_campos = campos.split(";");
		var i = 0;
		for (i=0;i<arr_campos.length;i++) {
			arr_campos[i] = arr_campos[i].split("|");
		}
		var x = Array();
		var t = tabla.insertRow(rows-1);
		var str_aux = "";
		for (i=0;i<arr_campos.length;i++) {
			//alert("0:"+arr_campos[i][0]+";1="+arr_campos[i][1]+";");
			x[i] = t.insertCell(i);
			x[i].className = estilo;
			str_aux = '<input type="hidden" name="'+arr_campos[i][0]+'['+cuenta+']" id="id-'+arr_campos[i][0]+'-'+cuenta+'" value="'+document.getElementById(arr_campos[i][0]).value+'">'; //id="id-'+arr_campos[i][0]+'['+cuenta+']" 
			if (arr_campos[i][1] == 1 || arr_campos[i][1] == 2) {
				str_aux += document.getElementById(arr_campos[i][0]).options[document.getElementById(arr_campos[i][0]).selectedIndex].text;
			} else if (arr_campos[i][1] == 11) {
				if (document.getElementById(arr_campos[i][0]).value == 1) {
					str_aux += "Sí";
				} else {
					str_aux += "No";
				}
			} else {
				str_aux += document.getElementById(arr_campos[i][0]).value;
			}
			x[i].innerHTML = str_aux;
		}
		x[arr_campos.length] = t.insertCell(arr_campos.length);
		x[arr_campos.length].className = estilo;
		x[arr_campos.length].innerHTML = '<img src="imagenes/cross.gif" style="cursor:pointer;" onClick="delRow('+"'"+table+"'"+', this.parentNode.parentNode.rowIndex);">';
		
	}
//----->


//---VACIAR CAMPOS SEGUN TIPO--->
function vaciar(campos) {
	var arr_campos = campos.split(";");
	var cosa;
	var i = 0;
	for (i=0;i<arr_campos.length;i++) {
		arr_campos[i] = arr_campos[i].split("|");
	}
	for (i=0;i<arr_campos.length;i++) {
		cosa = document.getElementById(arr_campos[i][0]);
		if (arr_campos[i][1] == 0) { //Text
			cosa.value = "";
		} else if (arr_campos[i][1] == 1 || arr_campos[i][1] == 2) { //Select
			cosa.value = "-1";
		} else if (arr_campos[i][1] == 3 || arr_campos[i][1] == 11) { //CheckBox
			cosa.checked = false;
			cosa.value = 0;
		} else if (arr_campos[i][1] == 4) { //PassingList
			var count = cosa.options.length
			var coso = document.getElementById("vuelta-"+arr_campos[i][0].substr(2));
			for (n=0;n<count;n++) {
				cosa.selectedIndex = 0;
				coso.click();
			}
		} else if (arr_campos[i][1] == 5) { //CheckBoxRush
			var partes = arr_campos[i][0].split("-");
			for (n=0;n<partes[0];n++) {
				document.getElementById(partes[1]+"-"+n).checked=false;
			}
		}
	//restartcolor(cosa.id);
	}
	try {
		document.getElementById("TE-CodArea").value="11";
	}
	catch(e) {
	}
}
//----->


//---ELIMINA UNA FILA DE LA TABLA--->
	function delRow(tabla, id) {
		if (confirm("¿Está seguro de que quiere eliminar la fila?") == true) {
			document.getElementById(tabla).deleteRow(id);
		}
	}
//----->
	
//---PASA UN ITEM DE LA LISTA DE ORIGEN A LA LISTA DE DESTINO--->
	function pasar_listas(id_o, id_d) {
		var origen = document.getElementById(id_o);
		var destino = document.getElementById(id_d);
		if (origen.selectedIndex != -1) {
			var nueva_opcion = document.createElement('option');
			if (id_o.substr(0,1) == "o") {
				nueva_opcion.ondblclick = function(){document.getElementById("vuelta-"+id_o.substr(2)+"").click();};
			} else {
				nueva_opcion.ondblclick = function(){document.getElementById("ida-"+id_o.substr(2)+"").click();};
			}
			nueva_opcion.text = origen.options[origen.selectedIndex].text;
			nueva_opcion.value = origen.options[origen.selectedIndex].text;
			nueva_opcion.title = origen.options[origen.selectedIndex].text;
			nueva_opcion.id = origen.options[origen.selectedIndex].id;
			
			try {
				destino.add(nueva_opcion, null); // standards compliant; doesn't work in IE
			}
			catch(ex) {
				destino.add(nueva_opcion); // IE only
			}
			origen.remove(origen.selectedIndex);
		} else {
			origen.selectedIndex = 0;
		}
	}
//----->
	
//---AGREGA UN ITEM A UNA LISTA--->
	function agregar_listas(texto, id_d) {
		var destino = document.getElementById(id_d);
		if (texto != "") {
			var nueva_opcion = document.createElement('option');
			nueva_opcion.text = texto;
			nueva_opcion.value = texto;
			nueva_opcion.title = texto;
			
			try {
				destino.add(nueva_opcion, null); // standards compliant; doesn't work in IE
			}
			catch(ex) {
				destino.add(nueva_opcion); // IE only
			}
		}
	}
//----->

//---BORRA EL ITEM SELECCIONADO DE LA LISTA--->
	function rem_item(id_d) {
		var destino = document.getElementById(id_d);
		var index = destino.selectedIndex;
		try {
			destino.remove(index, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			destino.remove(index); // IE only
		}
	}
//----->
	
//---BORRA TODOS LOS ITEMS DE LA LISTA--->
	function rem_all(id) {
		var lista = document.getElementById(id);
		var i;
		var largo = lista.options.length;
		//var inicial = lista.selectedIndex
		for (i=0;i<largo;i++) {
			try { //Borro el Index=0, xq cdo borro el item 0, el siguiente se hace 0, y si uso i, borro intercalado.
				lista.remove(0, null); // standards compliant; doesn't work in IE
			}
			catch(ex) {
				lista.remove(0); // IE only
			}
		}
	}
//----->

//---BORRA TODOS LOS ITEMS DE LA LISTA (OTRA)--->
	function vaciar_combos(id) {
		var combo = document.getElementById(id);
		var cuenta = combo.options.length;
		var i = 0;
		for (i=0;i<cuenta-1;i++) {
			combo.remove(1);
		}
	}
//----->

	
//---CARGA UN CONJUNTO DE ITEMS A LA LISTA--->
	//Modo de USO:
	/* Antes de usar definir los siguientes arrays
		//Defino Array de Listas
		var list = new Array(); //Array principal
		//Primer lista
		list[1]="Item1;Item2;Item3"
	*/
	function load_list(lista,id_d) {
		//lista: es el index del array listas, correspondiente a la que queremos cargar.
		rem_all(id_d); //Limpia la lista para volver a cargarla
		if (lista != "-1"){
		var items = new Array();
		items = list[lista].split(";");
		for (i=0;i<items.length;i++) {
		agregar_listas(items[i],id_d); //Agrega los items uno por uno
		}
		}
	}
//----->

//---SELECCIONA TODOS LOS ITEMS DE LA LISTA--->
	function select_all(id) {
		var lista = document.getElementById(id)
		var i;
		lista.multiple = true;
		for (i=0;i<lista.length;i++) {
			lista.options[i].selected = true;
		}
	}
//----->
	
//---AGREGA UN VALOR NO NORMATIZADO EN UNA LISTA--->
	//En el argumento "tipo" va 0 si es un AddingList y 1 si es un PassingList
	function agregar_otro(id, maxlength, tipo, caracteres_permitidos) {
		if (tipo == 0) {
			var lista = document.getElementById(id)
			if (lista.selectedIndex == lista.length-1) {
				var texto = prompt("Ingrese el nuevo valor", "");
				if (texto == "" || texto == null) {
					lista.selectedIndex = 0;
					return
				} else if (texto.length > maxlength) {
					alert("El valor no puede tener más que "+maxlength+" caracteres");
					lista.selectedIndex = 0;
					return
				} else if (isAlphanumeric(texto, caracteres_permitidos) != true) {
					alert("El valor tiene caracteres no válidos");
					lista.selectedIndex = 0;
					return
				}
				if (lista.length > 0) {
					var nueva_opcion = document.createElement('option');
					nueva_opcion.text = texto;
					nueva_opcion.value = texto;
					var vieja_opcion = lista.options[lista.length-1];  
					try {
						lista.add(nueva_opcion, vieja_opcion); // standards compliant; doesn't work in IE
					}
					catch(ex) {
						lista.add(nueva_opcion, lista.selectedIndex); // IE only
					}
					lista.options[lista.length-2].selected = true;
				} else {
					lista.selectedIndex = 0;
				}
			}
		} else if (tipo == 1) {
			var lista = document.getElementById(id)
			var texto = prompt("Ingrese el nuevo valor", "");
			if (texto == "" || texto == null) {
				return
			} else if (texto.length > maxlength) {
				alert("El valor no puede tener más que "+maxlength+" caracteres");
				lista.selectedIndex = 0;
				return
			} else if (isAlphanumeric(texto, caracteres_permitidos) != true) {
				alert("El valor tiene caracteres no válidos");
				lista.selectedIndex = 0;
				return
			}
			var nueva_opcion = document.createElement('option');
			nueva_opcion.ondblclick = function(){document.getElementById("vuelta-"+id.substr(2)+"").click();};
			nueva_opcion.text = texto;
			nueva_opcion.value = texto;
			nueva_opcion.title = texto;
			try {
				lista.add(nueva_opcion, null); // standards compliant; doesn't work in IE
			}
			catch(ex) {
				lista.add(nueva_opcion); // IE only
			}
			//asdasd
		}
	}
//----->

	
	function reemplazar(texto, a, b) {
		//alert("remp: "+a+" por "+b+" en "+texto);
		var aux = "";
		for (i=0;i<texto.length;i++) {
			if (texto.charAt(i) == a) {
				aux += b;
			} else {
				aux += texto.charAt(i);
			}
		}
		//alert("return: "+aux);
		return aux;
	}

	
	function LC(texto) {
		//alert("a limpiar: "+texto);
		if (texto == null || texto == "") {
			return "";
		}
		texto = reemplazar(texto, "'", "\\\'");
		texto = reemplazar(texto, '"', '&quot;');
//		texto = reemplazar(texto, '"', '');
		
		//alert("return: "+texto);
		return texto;
	}
	
//---Devuelve el keyascii de la tecla presionada--->
	function capturaTeclas(e) {
		var keynum;
		if ( window.event ) {
			keynum = e.keyCode;
		} else if(e.which) {
			keynum = e.which;
		}
		return keynum;
	}
//----->
	
	
//---AGREGA UN VALOR A LA DERECHA EN UN ToRightList--->
	function addRight2 (id_d, campos, valores, cuenta, prefijo) {
		tabla_destino = document.getElementById(id_d);
		var rows = tabla_destino.rows.length;
		var arr_campos = campos.split(";");
		for (i=0;i<arr_campos.length;i++) {
			arr_campos[i] = arr_campos[i].split("|");
		}
		var arr_valores = valores.split(";");
		var i;
		var x;
		var t = tabla_destino.insertRow(rows);
		x = t.insertCell(0);
		x.id = prefijo+"-newtd-"+cuenta;
		x.innerHTML = "&nbsp;";
		var td = document.getElementById(prefijo+"-newtd-"+cuenta);
		var straux = "";
		straux = '<table><tr><td><img id="'+prefijo+'--'+cuenta+'" src="../imagenes/show_more2.bmp" style="cursor:pointer;" onClick="if(document.getElementById('+"'"+prefijo+'-'+cuenta+"'"+').className=='+"''"+') {document.getElementById('+"'"+prefijo+'-'+cuenta+"'"+').className='+"'closed'"+';document.getElementById(this.id).src='+"'../imagenes/show_more2.bmp'"+'}else{document.getElementById('+"'"+prefijo+'-'+cuenta+"'"+').className='+"''"+';document.getElementById(this.id).src='+"'../imagenes/show_less2.bmp'"+'};">';
		straux += '</td><td><input type="hidden" name="'+prefijo+'-'+arr_campos[0][0]+'[]" value="'+LC(arr_valores[0])+'">'+arr_valores[0]+'</td>';
		straux += '<td align="center" width="20"><img src="imagenes/cross.gif" style="cursor:pointer;" onClick="delRow('+"'"+id_d+"'"+', this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);"></td>';//alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);
		straux += '</tr></table>';
		straux += '<table id="'+prefijo+'-'+cuenta+'" class="closed" border="0" style="position:relative;left:0px;"><tr><td width="350px">';
		straux += '<table>';
		var p = arr_campos.length;
		for (i=1;i<p;i++) {
			if (i == Math.ceil(p/2) + 1) {
				straux += '</table></td><td widht="350px"><table>';
			}
			if (arr_valores[i] != "") {
				straux += '<tr><td><b>'+arr_campos[i][1]+':</b></td>';
				straux += '<td><input type="hidden" name="'+prefijo+'-'+arr_campos[i][0]+'[]" value="'+LC(arr_valores[i])+'">'+arr_valores[i]+'</td></tr>';
			} else {
				straux += '<input type="hidden" name="'+prefijo+'-'+arr_campos[i][0]+'[]" value="'+LC(arr_valores[i])+'">';
			}
		}
		straux += '</table></td></tr></table>';
		td.innerHTML = straux;
	}
//----->

//---AGREGAR UN VALOR EN EL ANTEÚLTIMO LUGAR DE UN SELECT--->
	function addinglist_agregar_listas (id) {
		var lista = document.getElementById(id);
		var texto = document.getElementById(id+"-add").value;
		var nueva_opcion = document.createElement('option');
		nueva_opcion.text = texto;
		nueva_opcion.value = texto;
		var vieja_opcion = lista.options[lista.length-1];  
		try {
			lista.add(nueva_opcion, vieja_opcion); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			lista.add(nueva_opcion, lista.selectedIndex); // IE only
		}
		lista.options[lista.length-2].selected = true;
	}
//----->


function CheckBoxRush_add (tabla, id) {
	var textbox = document.getElementById(tabla+"-t");
	var boton = document.getElementById(tabla+"-a");
	var div_interno = document.getElementById(tabla+"-d");
	if (textbox.value == "") {
		div_interno.className = "closed";
		boton.className="opened";
	} else {
		var table = document.getElementById(tabla);
		var filas = document.getElementById(tabla).rows.length - 1;
		var columnas = document.getElementById(tabla).rows[filas].cells.length - 1;
		var celda_actual = document.getElementById(id).parentNode.cellIndex;
		var valor = document.getElementById(tabla+"-t").value;
		//alert("Ubound(Filas): "+filas+"\nUbound(Columnas): "+columnas+"\nid_actual: "+fila_actual+" - "+celda_actual);
		boton.className="opened";
		textbox.value = "";
		div_interno.className="closed";
		var stuff = document.getElementById(id).parentNode.innerHTML;
		
		if (celda_actual == columnas) {
			var nueva_row = table.insertRow(filas+1);
			for (i=0;i<=columnas;i++) {
				nueva_row.insertCell(i).innerHTML = "&nbsp;";
			}
			table.rows[filas+1].cells[0].innerHTML = stuff;
		} else {
			table.rows[filas].cells[celda_actual+1].innerHTML = stuff;
		}
		
		var aux = "";
		aux += '<input type="checkbox" name="'+tabla.substr(4)+'[]" value="'+valor+'" checked>'+valor;
		table.rows[filas].cells[celda_actual].innerHTML = aux;
	}
}

function reconstructor_CheckBoxRush(donde, titulo, nombre, valores, bool_input, bool_identificador) {
	var codigo = "";
	var cols = 0;
	var rows = 0;
	valores = valores.split(";");
	var raiz = Math.sqrt(valores.length);
	var resto = raiz - Math.floor(raiz);
	if (resto == 0) {
		cols = raiz;
		rows = raiz;
	} else {
		cols = Math.floor(raiz);
		if (resto >= 0.5) {
			rows = Math.floor(raiz) + 2;
		} else {
			rows = Math.floor(raiz) + 1;
		}
	}
	
	codigo += '<table><tr><td colspan="'+cols+'"><b>'+titulo+'</b></td></tr>';
	
	for (n=0;n<(rows*cols);n++) {
		if (n % cols == 0) {
			codigo += '</tr><tr>';
		}
		codigo += '<td>';
		if (n < valores.length) {
			codigo += '<input type="checkbox" ';
			if (bool_identificador == 0) {
				codigo += 'id="'+nombre+'-'+n+'" ';
			} else {
				codigo += 'name="'+nombre+'[]" ';
			}
			codigo += 'value="'+valores[n]+'">'+valores[n];
		} else {
			codigo += '&nbsp;';
		}
		codigo +='</td>';
	}
	codigo += '</table>';

	document.getElementById(donde).innerHTML = codigo;
}
	
//---DEVUELVE EL NÚMERO DE DÍAS QUE TIENE UN MES EN UN DETERMINADO AÑO--->
	function pidovalormes() {
		if (arguments.length != 2) {
			alert("PidoValorMes requiere dos argumentos únicos");
		}
		if (arguments[0] == -1 || arguments[0] == 1 || arguments[0] == 3 || arguments[0] == 5 || arguments[0] == 7 || arguments[0] == 8 || arguments[0] == 10 || arguments[0] == 12) {
			return 31;
		}
		if (arguments[0] == 4 || arguments[0] == 6 || arguments[0] == 9 || arguments[0] == 11) {
			return 30;
		}
		if (arguments[0] == 2) {
			if (arguments[1] % 4 == 0) {
				return 29;
			} else {
				return 28;
			}
		}
	}
//----->
	
//---ARMA EL INTERIOR DE UN <SELECT> CON LA CANTIDAD DE DIAS DE UN DETERMINADO MES EN UN DETERMINADO AÑO--->
	function armodia(id) {
		var dia = document.getElementById(id + "-d");
		var elegido = dia.value;
		var lps = pidovalormes(document.getElementById(id + "-m").value, document.getElementById(id + "-a").value);
	
		if (elegido > 0) {
			if (elegido > lps) {
				elegido = 0
			}
		}
		
		var num_borrar = dia.options.length;
		for (i=1;i<num_borrar;i++) {	
			dia.remove(1);
		}
		
		for (i=1;i<=lps;i++) {
			agregar_listas(i, id + "-d");
		}
		
		if (elegido > 0) {
			dia.selectedIndex = elegido;
		}
		
	}
//----->


//Encuentra el valor de posición absoluto de un objeto
function findPos(obj) {
	obj = document.getElementById(obj);
	var ret = Array();
	var curleft = obj.offsetLeft;
	var curtop = obj.offsetTop;
	while (obj.offsetParent) {
		obj = obj.offsetParent;
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
	ret[0] = curleft;
	ret[1] = curtop;
	return ret;
}
//----->


//Muestra dialogos en caja de nuevo item de Select :S
function displayMensajes(objeto) {
	var pos = Array();
	pos = findPos(objeto+"-S");
	document.getElementById(objeto+"-displaySi").style.left = pos[0] + "px";
	document.getElementById(objeto+"-displaySi").style.top = (pos[1] - 46)+"px";
	document.getElementById(objeto+"-displaySi").style.visibility = "visible";
	pos = findPos(objeto+"-N");
	document.getElementById(objeto+"-displayNo").style.left = pos[0] + "px";
	document.getElementById(objeto+"-displayNo").style.top = (pos[1] + 25) + "px";
	document.getElementById(objeto+"-displayNo").style.visibility = "visible";
}

	/*
	function addRow(table) {
		var tabla = document.getElementById(table);
		var rows = tabla.rows.length;
		var arg = arguments.length;
		var i;
		var x = Array();
		var t = tabla.insertRow(rows-1);
	
		for (i=0;i<arg-1;i++) {
			x[i] = t.insertCell(i);
			x[i].innerHTML = '<input type="hidden" name="'+table+'-'+i+'['+(c_titulos_h)+']" value="'+arguments[i+1]+'">'+arguments[i+1];
		}
		x[arg-1] = t.insertCell(arg-1)
		x[arg-1].innerHTML = '<img src="imagenes/cross.gif" style="cursor:pointer;" onClick="delRow('+"'"+table+"'"+', this.parentNode.parentNode.rowIndex);">';
		
		c_titulos_h++;
	}
	*/	

	//---AGREGA UN VALOR A LA DERECHA EN UN ToRightList---//
	/*
	function addRight (id_d, campos, valores, cuenta, prefijo) {
		tabla_destino = document.getElementById(id_d);
		var rows = tabla_destino.rows.length;
		var arr_campos = campos.split(";");
		var arr_valores = valores.split(";");
		var i;
		var x;
		var t = tabla_destino.insertRow(rows);
		x = t.insertCell(0);
		x.id = "newtd-"+cuenta;
		x.innerHTML = "&nbsp;";
		var td = document.getElementById("newtd-"+cuenta);
		var straux = "";
		straux = '<table><tr><td><img id="'+prefijo+'--'+cuenta+'" src="../imagenes/show_more2.bmp" style="cursor:pointer;" onClick="if(document.getElementById('+"'"+prefijo+'-'+cuenta+"'"+').className=='+"''"+') {document.getElementById('+"'"+prefijo+'-'+cuenta+"'"+').className='+"'closed'"+';document.getElementById(this.id).src='+"'../imagenes/show_more2.bmp'"+'}else{document.getElementById('+"'"+prefijo+'-'+cuenta+"'"+').className='+"''"+';document.getElementById(this.id).src='+"'../imagenes/show_less2.bmp'"+'};">';
		straux += '</td><td>'+document.getElementById(arr_valores[0]).value+'</td></tr></table>';
		straux += '<table id="'+prefijo+'-'+cuenta+'" class="closed" border="1" style="position:relative;left:16px;">';
		for (i=1;i<arr_campos.length;i++) {
			straux += '<tr><td><b>'+arr_campos[i]+':</b></td>';
			straux += '<td>'+document.getElementById(arr_valores[i]).value+'</td></tr>';
		}
		straux += '</table>';
		
		td.innerHTML = straux;
	}
	*/
	//----->


//=-=-=-=-=-=-=-=-=-=-//
