/*******************************************************************/
// MUESTRA UNA BARRA DE STATUS BAJO LAS GRILLAS
function statusBar()
{
	var status = 93;
	if ( arguments[0] ) {
		status = arguments[0];
	}
	var height = (window.innerHeight) ? window.innerHeight - 4 : ((document.body) ? document.body.clientHeight : 300);
	if ( document.getElementById('mensajes') ) {
		height = height - 20;
	}
	return height - status;
}

/*******************************************************************/
// GENERA LA POSICIÓN DE LAS POPUP
function positionWindows()
{
	var titlebar = (screen.height - screen.availHeight) // Alto de la barra de título
	var frameSuperior = 49; // Alto del frame superior
	var frameIzquierda = 92; // Ancho del frame de la izquierda

	// Top
	var top=function() {
		return (screen.height - screen.availHeight + frameSuperior);
	};

	// Width
	var width=function() {
		return ( window.innerWidth ) ? (window.innerWidth - frameIzquierda) : ( ( document.body ) ? (document.body.clientWidth - frameIzquierda) : 500);
	};

	// Height
	var height=function() {
		return ( window.innerHeight ) ? ( window.innerHeight - frameSuperior - titlebar ) : ( ( document.body ) ? ( document.body.clientHeight - frameSuperior - titlebar ) : 300);
	};
	SetCookie("posicion", (top()+":"+height()+":"+width()), "", "/");
	return;
}

/*******************************************************************/
// Crea una Cookie
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2 && argv[2]!="") ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = window.location.host;
	var valCookie = name + "=" + escape(value) +
	((expires==null) ? "" : "; expires=" + expires.toGMTString()) +
	((path==null) ? "" : ("; path=" + path)) + "; domain=" + domain;
	document.cookie = valCookie;
}

/*******************************************************************/
// RECUPERA LA POSICIÓN DE LA VENTANA
function windowPosition()
{
	// Posición desde la izquierda
	var izquierda = 92;

	var width = (arguments[0]) ? arguments[0] : 0;
	var height = (arguments[1]) ? arguments[1] : 300;
	var top = (arguments[2]) ? arguments[2] : 0; // Argumento + posicion de inicio según cookie
	var left = (arguments[3]) ? izquierda + parseInt(arguments[3]) : izquierda; // Argumento + izquierda

	var buscamos = "posicion=";
	if ( document.cookie.length>0 ) {
		inicio = document.cookie.indexOf(buscamos);
		if ( inicio!=-1 ) {
			inicio += buscamos.length;
			fin = document.cookie.indexOf(";", inicio);
			if ( fin==-1 )
				fin = document.cookie.length;
			var valores = unescape(document.cookie.substring(inicio, fin)); // top, height y width separados por ":"
			var valores = valores.split(":");
			height = (height<=300) ? (parseInt(valores[1]) - top) : (height - top); // Si el top es mayor que cero viene con parámetro, por lo tanto debe achicar la ventana
			top = parseInt(valores[0]) + top; // El top de la cookie + el top enviado como parámetro
			width = (width==0) ? parseInt(valores[2]) : width; // Si el width es = 0, entonces viene sin parámetros (coloca el ancho máximo), sino pone el ancho enviado como parámetro
		}
	}
	return ',width='+width+',height='+height+',top='+top+',left='+left;
}

/*******************************************************************/
// PANTALLA DE INFORMACIÓN
// arguments[2] = width
// arguments[3] = height
// arguments[4] = top
// arguments[5] = left
function verInfo(id, pagina) {
	var width = ( arguments[2] ) ? arguments[2] : '';
	var height = ( arguments[3] ) ? arguments[3] : '';
	var top = ( arguments[4] ) ? arguments[4] : '';
	var left = ( arguments[5] ) ? arguments[5] : '';
	var num = Math.round(Math.random() * id);
	if ( pagina.indexOf("?")!=-1 )
		pagina += "&";
	else
		pagina += "?";
	window.open(pagina + "accion=info&popup=1&id="+id,"info"+num,"scrollbars=yes,resizable=yes"+windowPosition(width, height, top, left));
}

/*******************************************************************/
/* POPUP DE FOTO */
function popupFoto(img, nombre) {
	window.open('propiedad.php?accion=popup_foto&img='+img+'&nombre='+nombre,'info'+img,'scrollbars=no,resizable=yes,status=0,toolbar=0,menubar=0'+windowPosition(300));
}

/*******************************************************************/
/* VENTANA DE FOTO */
function verFoto(img, nombre) {
	var popup = (arguments[2] && arguments[2]=='popup') ? 1 : 0;
	window.open('propiedad.php?accion=crea_foto&img='+img+'&nombre='+nombre+'&popup='+popup,'info'+img,'scrollbars=no,resizable=no'+windowPosition(200, 0));
}

/*******************************************************************/
/* POPUP DE BUSCAR PROPIEDAD */
function buscaPropiedad() {
	window.open('buscar.php?tipo=popup','popupBusca','scrollbars=yes,resizable=yes'+windowPosition());
	return false;
}

/*******************************************************************/
/* POPUP DE CARACTERÍSTICAS DE PROPIEDAD */
function verCar(cod,prop) {
	window.open('propiedad.php?accion=carac&tipo='+cod+'&prop='+prop,'popup'+cod,'scrollbars=yes,resizable=yes'+windowPosition(500));
	return false;
}

/*******************************************************************/
/* Calendar.setup */
function calendario(idField, idBoton) {
	var align = 'Br';
	if (arguments[2]) {
		align = arguments[2];
	}
	Calendar.setup( { button : idBoton, inputField : idField, align : align} );
}

/*******************************************************************/
/* Le da Nombre al Botón btn */
function boton(nombre) {
	if (document.getElementById('btn'))
		document.getElementById('btn').value = nombre
	else
		alert('No has creado en input btn');
}

/*******************************************************************/
/* Fija una cabecera de listado */
function fijarCabecera(layer) {
	var pos = 0;
	if (arguments[1]) {
		pos = arguments[1];
	}
	if (document.getElementById(layer)) {
		var obj = document.getElementById(layer);
		obj.style.top = document.body.scrollTop + pos;
	}
}

/*******************************************************************/
/* Muestra y Oculta un <div> */
function displayData(idDiv,idImg) {
	if (document.getElementById(idDiv).style.display == "none") {
		document.getElementById(idDiv).style.display = "";
		if (document.getElementById(idImg).src) {
			document.getElementById(idImg).src = "../imagenes/div/menos.gif";
		}
	}
	else {
		document.getElementById(idDiv).style.display = "none";
		if (document.getElementById(idImg).src) {
			document.getElementById(idImg).src = "../imagenes/div/mas.gif";
		}
	}
}

/*******************************************************************/
/* Genera el proceso para Formatear un Textarea */
function formatText(tipo,textarea) {
	var tag1;
	var tag2;
	var seleccion;

	/* TAGs HTML */
	if (tipo=='B') {
		tipo = 'negrita';
		tag1 = '<b>';
		tag2 = '</b>';
	}
	else if (tipo=='U') {
		tipo = 'subraya';
		tag1 = '<u>';
		tag2 = '</u>';
	}
	else if (tipo=='I') {
		tipo = 'cursiva';
		tag1 = '<i>';
		tag2 = '</i>';
	}
	else if (tipo=='R') {
		tipo = 'derecha';
		tag1 = '<div style=text-align:right;>';
		tag2 = '</div>';
	}
	else if (tipo=='C') {
		tipo = 'centrar';
		tag1 = '<center>';
		tag2 = '<center>';
	}
	else if (tipo=='L') {
		tipo = 'izquierda';
		tag1 = '<div style=text-align:left;>';
		tag2 = '</div>';
	}
	else if (tipo=='J') {
		tipo = 'justificar';
		tag1 = '<div style=text-align:justify;>';
		tag2 = '</div>';
	}

	/* Imagen presionada */
	var img = document.getElementById(tipo).src;
	img = img.substring(img.indexOf('area/')+5,img.length);
	if (img==tipo+'1.gif') {
		var imagen = '../imagenes/textarea/'+tipo+'2.gif';
		var add = tag1;
	}
	else {
		var imagen = '../imagenes/textarea/'+tipo+'1.gif';
		var add = tag2;
	}

	/* Navegador */
	var navegador = navigator.userAgent.toLowerCase();

	/* TextArea */
	var area = document.getElementById(textarea);

	/* Firefox */
	if (navegador.indexOf('firefox')!=-1) {
		var text = area.value;
		var inicio = area.selectionStart;
		var fin = area.selectionEnd;
		seleccion = text.substring(inicio,fin);
		if (seleccion=='') { // No seleccionado
			area.value = text.substring(0,inicio) + add + text.substring(inicio,text.length);
			document.getElementById(tipo).src = imagen;
			var pos = text.substring(0,inicio);
			area.focus(); // posicion del cursor
			if (area.setSelectionRange) {
				area.setSelectionRange(pos.length + add.length, pos.length + add.length);
			}
		}
		else { // Seleccionado
			area.value = text.substring(0,inicio) + tag1 + seleccion + tag2 + text.substring(fin,text.length);
			document.getElementById(tipo).src = "../imagenes/textarea/"+tipo+"1.gif";
			var pos = text.substring(0,inicio);
			area.focus();
			if (area.setSelectionRange) {
				area.setSelectionRange(pos.length, pos.length + tag1.length + tag2.length + seleccion.length);
			}
		}
	}
	/* Explorer */
	else if (navegador.indexOf('msie')!=-1) {
		seleccion = document.selection.createRange().text;
		if (seleccion=='' && area.createTextRange) { // No seleccionado
			area.focus();
			area.caretPos = document.selection.createRange().duplicate();
			if (area.createTextRange && area.caretPos) { // caretPos = posicion del cursor
				area.caretPos.text = add;
				document.getElementById(tipo).src = imagen;
			}
		}
		else { // Seleccionado
			document.selection.createRange().text = tag1 + seleccion + tag2;
			area.focus();
			document.getElementById(tipo).src = '../imagenes/textarea/'+tipo+'1.gif';
		}
	}
	else
		return false;
	return;
}

/*******************************************************************/
/* Cambia la imagen al pasar el Mouse */
function cambiaImagen(img, imagen) {
	var ruta = "../imagenes/";
	img.src = ruta + imagen;
}

/*******************************************************************/
/* Cambia el color de la fila al pasar el Mouse */
function cambiaFondo(src, tipo) {
	if (tipo==true) {
		src.style.cursor = 'pointer';
		src.bgColor = "#ECF2F9";
	}
	else {
		src.style.cursor = 'default';
		src.bgColor = "#FFFFFF";
	}
}

/*******************************************************************/
/* Retorna el dígito verificador a raíz del número de Rut */
function rutDigitoVerificador(rut) {
	var i, suma=0;
	for(i=0; i<rut.length; i++)
		suma+=parseInt(rut.substring(rut.length-i-1,rut.length-i))*(i%6+2);
	switch  (11-suma%11) {
		case 10:
			return 'K';
			break;
		case 11:
			return 0;
			break;
		default:
			return 11-suma%11;
	}
}

/*******************************************************************/
/* Rut no admitidos en el sistema */
function rutPermitido(rut,dig) {
	if ( rut=='9' && dig=='9' ) {
		return true;
	}
	if (rut.length < 6 || rut.length > 9) {
		alert('El Rut debe contener entre 6 y 9 Dígitos');
		return false;
	}
	var ruts = new Array(Array(0,0),Array(1,1),Array(2,2),Array(3,3),Array(4,4),Array(5,5),Array(6,6),Array(7,7),Array(8,8),Array(9,9));
	var serie = parseInt(ruts[rut.substr(0,1)][0]);
	var igual = 0;

	for(i=1; i<rut.length; i++) {
		if (ruts[rut.substr(i,1)][0]==serie)
			igual++;
	}
	if (igual==rut.length-1 && ruts[serie][1]==dig) {
		alert('No se permite este tipo de Rut\n' + rut + '-' + dig);
		return false;
	}
	return true;
}

/*******************************************************************/
/* Retorna true si el dig equivale al rut */
function rutCorrecto(rut,dig) {
	if (!rutPermitido(rut,dig)) {
		return false;
	}
	var estado = (dig.length==1 && dig.toUpperCase()==rutDigitoVerificador(rut))? true : false;
	if (!estado)
		alert('Dígito verificador incorrecto');
	return estado;
}

/*******************************************************************/
// Verifica que "ascii" sea uno de los parametros permitidos en el input
function enArreglo(event) {
	var ascii = event.which;
	if ( typeof(ascii)=="undefined" )
		ascii = event.keyCode;

	permitidos = Array(8, 0); // caracteres ascii permitidos
	for(i=0; i<permitidos.length; i++) { // busca en los caracteres permitidos por el sistema
		if ( ascii==permitidos[i] )
			return true;
	}
	for(i=1; i<arguments.length; i++) { // busca en los caracteres enviados como permitidos
		if( ascii==arguments[i] )
			return arguments[i];
	}
	return false;
}

/*******************************************************************/
/* Confirma la eliminación de un registro */
function confirmacion() {
	var texto = (sel==0 || sel==1) ? '¿ Confirma eliminación del registro ?' : '¿ Confirma eliminación de los ' + sel + ' registros ?';
	var seguro = confirm(texto);
	return (!seguro) ? false : true;
}

/*******************************************************************/
/* Cada vez que se chequea un CheckBox suma uno a Sel y si lo elimina, le resta */
/* Con esto se obtiene la cantidad de CheckBox seleccionados */
var sel=0;
function clickCheckBox(chk) {
	sel = (chk.checked) ? sel+1 : sel-1;
	return (sel < 0) ? 0 : sel;
}

/*******************************************************************/
/* Guarda la cantidad de checkbox seleccionados */
var codigos = Array();
function seleccion(check) {
	if (check.checked==true) { // Si se checkeo el checkbox entonces se crea un nuevo item de array
		codigos.push(check.value);
	}
	else { // Sino, elimina el código y reordena el array
		var aux = codigos;
		codigos = Array();
		for (pos=0; pos<aux.length; pos++)
			if (check.value!=aux[pos])
				codigos.push(aux[pos]);
	}
	return;
}

/*******************************************************************/
/* Confirma la eliminación de un registro */
function continuar() {
	if (codigos.length==0) {
		alert('Debe seleccionar un registro');
		return false;
	}
	var texto = (codigos.length==1) ? '¿ Confirma eliminación del registro ?' : '¿ Confirma eliminación de los ' + codigos.length + ' registros ?';
	var seguro = confirm(texto);
	return (!seguro) ? false : true;
}

/*******************************************************************/
/* Según el Boton presionado pide selecionar un registro */
/* Permite solo uno cuando es selección de información (Modificar, Ver, Etc.) */
/* Permite varios para el caso de Eliminar */
function botonPress(boton) {
	if(!sel) {
		alert('Debe seleccionar un Registro');
		return false;
	}
	else if (sel > 1 && boton!='btnEliminar') {
		alert('Debe seleccionar sólo un Registro');
		return false;
	}
	else if (boton=='btnEliminar') {
		return confirmacion();
	}
	return true;
}

/*******************************************************************/
/* Retorna la cadena en minusculas */
function minuscula(str) {
	form = 0;
	if (arguments[1])
		form = arguments[1];
	var valor = str.value;
	document.forms[form].elements[str.name].value = valor.toLowerCase();
}

/*******************************************************************/
/* Retorna la cadena en mayúsculas */
function mayuscula(str) {
	form = 0;
	if (arguments[1])
		form = arguments[1];
	var valor = str.value;
	document.forms[form].elements[str.name].value = valor.toUpperCase();
}

/*******************************************************************/
/* Muestra la cantidad de caracteres que quedan libres en un textarea */
/*/////// Deprecada  ///////*/
function totalCaracteres(area, mostrar, total)
{
	var largo = String(document.forms[0].elements[area].value);
	if (largo.length > Number(total)) {
		document.forms[0].elements[area].value = largo.substring(0,Number(total));
		alert(' Está pasando el límite de caracteres permitidos ');
		largo = document.forms[0].elements[area].value;
	}
	document.forms[0].elements[mostrar].value = Number(total) - Number(largo.length);
	return false;
}
/*/////// Deprecada  ///////*/

/*******************************************************************/
/* Muestra la cantidad de caracteres que quedan libres en un textarea */
function cantCaracter(area, div, total) {
	total = parseInt(total);
	var largo = String(document.forms[0].elements[area].value);
	if (largo.length > total) {
		document.forms[0].elements[area].value = largo.substring(0,total);
		alert(' Está pasando el límite de caracteres permitidos ');
		largo = document.forms[0].elements[area].value;
	}
	var suma = new String(total - parseInt(largo.length));
	document.getElementById(div).innerHTML = 'Total '+ total + ' Caracteres. Quedan ' + suma.bold();
}

/*******************************************************************/
/* Muestra un mensaje de alerta y pone el cursor en el campo enviado, retorna falso*/
function msgError(form, campo) {
	if (arguments[2]) {
		alert(arguments[2]);
	}
	document.forms[form].elements[campo].focus();
	return false;
}

/*******************************************************************/
/* Selecciona el ejecutivo que corresponde al Tipo de Propiedad */
function seleccionaEjecutivo(cod) {
	var str = new String();
	var arrRut = new Array();
	var objRut = document.forms[0].elements['rut_pers'];
	if ( cod!='' ) {
		for (pos=1; pos < parseInt(objRut.length); pos++) {
			str = objRut.options[pos].value;
			str = str.substr(str.indexOf(':')+1);
			if ( str.indexOf(cod)!=-1 )
				arrRut.push(pos);
		}
	}
	if ( arrRut.length>1 ) {
		pos = Math.random() * (arrRut.length - 1);
		pos = Math.round(pos);
		//objRut.selectedIndex = arrRut[pos];
		objRut.selectedIndex = arrRut[0];
	}
	else if ( arrRut.length==1 )
		objRut.selectedIndex = arrRut[0];
	else
		objRut.selectedIndex = 0;

	return;
}

/*******************************************************************/
/* Verifica que el valor ingresado no sea sólo espacios en blanco */
function sinEspacios(str) {
	var i,j;
	for(i=0; i<str.length && str.substring(i,i+1)==' '; i++);
	for(j=str.length; j && str.substring(j-1,j)==' '; j--);
	return (i<j)?str.substring(i,j):false;
}

/*******************************************************************/
/* Busca espacios en el texto */
function buscarEspacios(str) {
	return (str.indexOf(' ')>0) ? false : true;
}

/*******************************************************************/
/* Valida Texto */
function validaString(frm,campo) {
	var str = new String();

	/* Valida si existen el form y el campo */
	if (document.forms[frm])
		var obj = document.forms[frm];
	else {
		alert('Formulario "undefined"');
		return false;
	}
	if (!obj.elements[campo]) {
		alert('Input '+campo+' "undefined"');
		return false;
	}

	/* Valida si se ingresaron datos */
	if (obj.elements[campo].value=='') {
		return false;
	}
	str = sinEspacios(obj.elements[campo].value);
	if (!str) {
		obj.elements[campo].value='';
		return false;
	}
	else if (str!=obj.elements[campo].value) {
		obj.elements[campo].value=str;
	}
	return true;
}

/*******************************************************************/
/* VALIDA TEXTO V2, SOLO CON ID */
function isText(id) {
	var str = new String();
	if (!document.getElementById(id)) {
		alert('ID = ' + id + '"undefined"');
		return false;
	}
	if (document.getElementById(id).value=='') {
		return false;
	}
	str = sinEspacios(document.getElementById(id).value);
	if (!str) {
		document.getElementById(id).value='';
		return false;
	}
	else if (str!=document.getElementById(id).value) {
		document.getElementById(id).value = str;
	}
	return true;
}

/*******************************************************************/
/* VALIDA NUMERO V2, SOLO CON ID */
function isNumero(id) {
	if (!document.getElementById(id)) {
		alert('ID = ' + id + '"undefined"');
		return false;
	}
	var num = new Number(document.getElementById(id).value);
	return (num==0) ? false : true;
}

/*******************************************************************/
/* Muestra un mensaje de alerta y pone el cursor en el campo enviado, retorna falso*/
function returnError(id) {
	if (arguments[1]) {
		alert(arguments[1]);
	}
	if (document.getElementById(id)) {
		document.getElementById(id).focus();
	}
	return false;
}

/*******************************************************************/
/* Valida Número */
function validaNumero(frm,campo) {
	var num = new Number(document.forms[frm].elements[campo].value);
	return (num==0) ? false : true;
}

/*******************************************************************/
/* Retorna la posicion de una Pop-up, de modo que se vean los Menús principales y no sobrepase los límites de pantalla */
function windowPosicion() {
	var width = (arguments[0]) ? arguments[0] : screen.width;
	var height = (arguments[1]) ? arguments[1] : screen.height;
	var top = (arguments[2]) ? arguments[2] : 0;
	if (width==screen.width)
		width = width - 97;

	if (self.innerWidth) {
		top = self.outerHeight - self.innerHeight;
		alert(top+' =H '+self.outerHeight +' =h '+ self.innerHeight);
		if (height==screen.height) {
			height = self.innerHeight + 75;
		}
	}
	else if (document.body) {
		top = (screen.height - document.body.clientHeight) / 2;
		if (height==screen.height)
			height = document.body.clientHeight + top / 2;
	}
	return ',width='+width+',height='+height+',top='+top+',left=88';
}

/*******************************************************************/
/* Popup de Buscar Cliente */
function buscaCliente(rut) {
	if (rut!='')
		window.open('clientes.php?accion=buscar&rut='+rut,'info'+rut,'scrollbars=yes,resizable=yes,width=200,height=200,top=30,left=30');
	return false;
}

/*******************************************************************/
/* Popup de Buscar Cliente mediante filtros de Búsqueda */
function buscarCliente() {
	window.open('clientes.php?accion=buscador','popupBusca','scrollbars=yes,resizable=yes,width=770,height=570,top=20,left=20');
	return false;
}

/*******************************************************************/
/* Recarga la pagina y carga los datos del clientes, si existe */
function cliente(rut, url) {
	if (arguments[2]==false) {
		if (document.forms[0].elements['Emp']) {
			if (!document.forms[0].elements['Emp'].checked) {
				return false;
			}
		}
	}
	if (rut.length > 5) {
		document.forms[0].action = url;
		if (url.indexOf('btn') > 0) {
			var boton = url.substring(url.indexOf('btn')+4,url.length);
			if (boton.indexOf('&') > 0) {
				boton = boton.substring(0, boton.indexOf('&'));
			}
			document.forms[0].elements['btn'].value = boton;
		}
		document.forms[0].submit();
	}
}

/*******************************************************************/
/* Deshabilita un botón */
function bloquear(nombre) {
	document.getElementById(nombre).disabled = true;
	document.getElementById(nombre).value = 'Procesando...';
}

/*******************************************************************/
/* Envía la pagina actual a la url indicada */
function go(url) {
	if (url) {
		window.location = url;
	}
}

/*******************************************************************/
/* Envía la pagina actual a la url indicada */
function redirect(url) {
	if (url)
		window.location = url;
}

/*******************************************************************/
/* Envía la pagina actual a la url indicada */
function back() {
	if (window.history.length==0) {
		window.close();
	}
	else {
		window.history.back();
	}
}
/*******************************************************************/
/* Muestra un layer de Descripción */
function Layers(estado, capa, info, titulo, evento) {
	if (document.getElementById(capa)) {
		if (estado) {
			var posWidth = 1;
			var posHeight = 1;
			var widthLayer = 350;
			var pos = (window.event) ? window.event : evento;

			var width=function() {return (window.innerWidth) ? window.innerWidth : ((document.body) ? document.body.clientWidth : 0)};
			var height=function() {return (window.innerHeight) ? window.innerHeight : ((document.body) ? document.body.clientHeight : 0)};
			var left=function() {return (window.pageXOffset) ? window.pageXOffset : ((document.body.scrollLeft) ? document.body.scrollLeft:0)};
			var top=function() {return (window.pageYOffset) ? window.pageYOffset : ((document.body.scrollTop) ? document.body.scrollTop:0)};

			document.getElementById(capa).style.width = widthLayer;
			var topeWidth = width() - (widthLayer/2);
			var topeHeight = height() - 200;

			if (pos.clientX > topeWidth)
				posWidth = width() - (widthLayer + 30) + left();
			else
				posWidth = pos.clientX-(widthLayer/2) + left();

			if (pos.clientY > topeHeight)
				posHeight = pos.clientY - 200 + top();
			else
				posHeight = pos.clientY + 20 + top();

			if (posWidth < 1)
				posWidth = 1 + left();

			if (posHeight < 1)
				posHeight = 1 + top();

			document.getElementById(capa).innerHTML = "<b><center>" + titulo + "</center></b><hr>" + info + "<hr>";
			document.getElementById(capa).style.left = posWidth;
			document.getElementById(capa).style.top = posHeight;
			document.getElementById(capa).style.display = "";
			//setTimeout("Layers()", 10);
		}
		else
			document.getElementById(capa).style.display = "none";
	}
}

/*******************************************************************/
/* Formatea un numero a formato : sin puntos de miles y con punto separador decimal*/
function formatNumero(num) {
	var valorStr = new String(num);
	valorStr = valorStr.replace(/\./g, '');
	valorStr = valorStr.replace(/,/, '.');
	return Number(valorStr);
}

/*******************************************************************/
/* Formatea un numero a formato : sin puntos de miles y con punto separador decimal*/
function formatString(num) {
	var valorStr = new String(num);
	var decimal = "";

	if (valorStr.indexOf(".") != -1) {
		var division = valorStr.split(".");
		numero = division[0]; // parte modificable
		decimal = new String(division[1]) // parte decimal
		return numero + "," + decimal.substr(0, 2);
	}
	return valorStr.replace(/\./, ',');
}

/*******************************************************************/
/* Formatea un número con separadores de miles y decimales 999.999,00 */
function formatMoneda(valor, objeto) {
	var numero = String(valor);
	var newNumero = "";
	var decimal = "";
	numero = numero.replace(/\./g, '');

	// Separa la parte entera con la decimal
	if (numero.indexOf(",") != -1) {
		var division = numero.split(",");
		numero = division[0]; // parte modificable
		var decimal = new String(division[1]) // parte decimal
	}
	else
		var decimal = "";
	// Voltea el numero y le agrega el caracter 'forma'
	var pos = 0;
	var cont = 0;
	for (pos=numero.length-1; pos >= 0; pos--) {
		var num = numero.charAt(pos);
		if (cont==3) {
			newNumero += '.' + num;
			cont = 1;
		}
		else {
			newNumero += num;
			cont ++;
		}
	}
	// Vuelve a voltear el número
	var pos = '';
	var numero = '';
	for (pos=newNumero.length-1; pos >= 0; pos--) {
		var num = newNumero.charAt(pos);
		numero += num;
	}

	if (decimal.length > 0) {
		numero += "," + decimal.substr(0, 2);
	}

	if (typeof(objeto)=="object")
		objeto.value = numero;
	else
		return numero;
}

/*******************************************************************/
/* Agrega items a un campo select */
function agregarItems(desde, hasta) {
	if (document.getElementById(desde) && document.getElementById(hasta)) {
		var obj_des = document.getElementById(desde);
		var obj_has = document.getElementById(hasta);
		var option;
		for(aux=0; aux<obj_des.length; aux++) {
			if (obj_des.options[aux].selected) {
				var existe = false;
				for (pos=0; pos<obj_has.length; pos++) {
					if (obj_has.options[pos].value==obj_des.options[aux].value)
						existe = true;
				}
				if (!existe) {
					option = new Option(obj_des.options[aux].text, obj_des.options[aux].value);
					obj_has.options[obj_has.options.length] = option;
				}
			}
		}
	}
}

/*******************************************************************/
/* Quita items a un campo select */
function quitarItems(objeto) {
	if (document.getElementById(objeto)) {
		var obj = document.getElementById(objeto);
		var aux = 0;
		while (aux < obj.length) {
			if (obj.options[aux].selected)
				obj.options[aux] = null;
			else
				aux++;
		}
	}
}

/*******************************************************************/
// Obtiene el valor de un Objeto
function _value(obj, tipo) {
	if ( document.getElementById(obj) ) {
		if ( typeof(tipo)!="undefined" ) {
			if ( tipo==1 )
				return Number(document.getElementById(obj).value);
			else if ( tipo==2 )
				return String(document.getElementById(obj).value);
		}
		return document.getElementById(obj).value;
	}
	return;
}