		//=====================================================================
		//
		//
		function maintainSession() {

//			document.getElementById('ldReload').style.visibility = 'visible';

			cadena_envio = 'sys_reload.asp';

//			alert(cadena_envio);

			CreateXmlHttpObj();
			
			if(XmlHttpObj) {	
				XmlHttpObj.onreadystatechange = function () {
					if (XmlHttpObj.readyState == 1) {				
						document.getElementById('ldReload').style.visibility = 'visible';
					}

					if(XmlHttpObj.readyState == 4) {

						if(XmlHttpObj.status == 200) {			
							valorRetorno = XmlHttpObj.responseText;
							
//							alert('Resultado: ' + valorRetorno);

							document.getElementById('reload').innerHTML = valorRetorno;

							var t=setTimeout("maintainSession()", 60000);

/*							if (valorRetorno == 'KO') {
								alert('El código de facility ya existe\nPor favor, modifícalo para seguir');
								var facCodeInput = document.getElementById('facility_code');
								facCodeInput.focus();
								facCodeInput.select();
							} */
						}
						else {
							alert("Código de error: "  + XmlHttpObj.status);
						}

						document.getElementById('ldReload').style.visibility = 'hidden';

					}
				}
				XmlHttpObj.open("POST", cadena_envio, true );
				XmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				XmlHttpObj.send('');		
			}			
		}
		//
		//
		//=====================================================================

		
		//=====================================================================
		//	Sustitución de la coma decimal por un punto en los input numéricos
		//····································································
		function check_numeric(inputID) {
			var iField = document.getElementById(inputID);
			var nValue = iField.value;
			
			iField.value = nValue.replace(',','.');

			if (isNaN(iField.value)) {
				alert('ATENCION: No es un valor numerico');
				iField.select();
				iField.focus();
			}
		}
		
		
		//=====================================================================
		//	Cerrar la barra de mensajes una vez leídos
		//············································

		function closeMsgBar () {
			var msgBar = document.getElementById('messageBar');
				
			msgBar.style.visibility = 'hidden';
			msgBar.style.position = 'absolute';
			msgBar.style.left = '-4000px';
			clearTimeout(t);
		}


		//=====================================================================
		// Limpiar valores en campos que tienen valores hidden asociados,
		// como los de tipo FILE
		//·······························································

		function clearFormField (nomField) {
			var obj = document.getElementById('d_' + nomField);
			obj.innerHTML = '';

			obj = document.getElementById(nomField);
			obj.value = '';

			obj = document.getElementById('h_' + nomField);
			obj.value = '';
		}
		
		//=====================================================================
		// Confirmación del cierre de sesión
		//··········································
		function closeConfirm() {
			if (confirm('¿Quieres abandonar la sesión?')) {
				goTo('sys_logout.asp');
			}
		}
		

		//=====================================================================
		//Validación alidacion de un facility_code por AJAX
		//·················································
		function check_fac_code(asc_code, fac_code) {

			document.getElementById('loading').style.visibility = 'visible';

			cadena_envio = 'fac_code_check.asp?asc=' + asc_code + '&fac=' + fac_code;

			//alert(cadena_envio);

			CreateXmlHttpObj();
			
			if(XmlHttpObj) {	
				XmlHttpObj.onreadystatechange = function () {
					if (XmlHttpObj.readyState == 1) {				
//						document.getElementById('loading').style.visibility = 'visible';
					}

					if(XmlHttpObj.readyState == 4) {

						if(XmlHttpObj.status == 200) {			
							valorRetorno = XmlHttpObj.responseText;
							
							//alert('Resultado: ' + valorRetorno);

							if (valorRetorno == 'KO') {
								alert('El código de facility ya existe\nPor favor, modifícalo para seguir');
								var facCodeInput = document.getElementById('facility_code');
								facCodeInput.focus();
								facCodeInput.select();

							}
						}
						else {
							alert("Código de error: "  + XmlHttpObj.status);
						}

						document.getElementById('loading').style.visibility = 'hidden';

					}
				}
				XmlHttpObj.open("POST", cadena_envio, true );
				XmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				XmlHttpObj.send('');		
			}			
		}
		

		//=====================================================================
		//Validación de los datos del login
		//·································
		function check_login() {
			if ((document.login.usr.value == '') || (document.login.pwd.value == '') || (document.login.cmp.value == '')) {
				alert('Debes introducir valores en todos los campos');
			} else {
				var capa = document.getElementById('progress');
				capa.style.visibility = 'visible';	
			
				document.login.submit();
			}
		}

		//=====================================================================
		//Calculo del tamaño de la capa de progreso para que cubra 
		//todo el contenido
		//························································
		function calc_progress() {
			//Calculo de la capa de progreso para que cubra toda la ventana 
			if (parseInt(navigator.appVersion)>3) {
				if (navigator.appName=="Netscape") {
				  winW = window.innerWidth-20;
				  winH = window.innerHeight-16;
				}
			
				if (navigator.appName.indexOf("Microsoft")!=-1) {
					winW = document.body.offsetWidth-20;
					winH = document.body.offsetHeight-20;
				}
			}

			var capa = document.getElementById('progress');
			capa.style.height = winH + 'px';
		}

		//=====================================================================
		//Funcion para poder poner la capa translucida cuando se 
		//selecciona una opcion
		//······················································
		function goTo (url) {
			var capa = document.getElementById('progress');
			capa.style.visibility = 'visible';	

			window.location.href = url;
		}

		//=====================================================================
		//Funcion para mostrar u ocultar la capa del filtro
		//·················································
		function toggle_filter() {
			var laCapa = document.getElementById('filter');
			var elBoton = document.getElementById('filter_li');
			var elAnchor = document.getElementById('filter_a');

			if (laCapa.style.visibility == 'visible') {
				laCapa.style.visibility = 'hidden';
				laCapa.style.position = 'absolute';
				laCapa.style.right = '-4000px';
				elBoton.style.backgroundImage = 'url(/img/button_88.png)';
				elAnchor.style.backgroundImage = 'url(/img/button_l_white_right.png)';
			} else {
				laCapa.style.visibility = 'visible';
				laCapa.style.position = 'relative';
				laCapa.style.right = '0';
				elBoton.style.backgroundImage = 'url(/img/button_88_on.png)';
				elAnchor.style.backgroundImage = 'none';
			}
		}


		//=====================================================================
		//FUNCIONES RELACIONADAS CON LOS BOTONES
		//······································

		function bttnToday(fieldName, valDate) {
			document.getElementById(fieldName).value = valDate;
		}

		//-----------------------------------------------------------------

		function bttnBack(urlBack) {
			if (urlBack != '') {
				goTo(urlBack);
			} else {
				
				history.back();
			}
		}

		//-----------------------------------------------------------------

		function bttnActualiza(){
			var capa = document.getElementById('progress');
			capa.style.visibility = 'visible';	

			document.f_filter.submit();
		}

		//-----------------------------------------------------------------

		function bttnPersonaliza(facility_code){
			window.open("/fac_personalize.asp?fac=" + facility_code, "Personalizar","left=130, top=130, width=500, height=550, titlebar=no, status=no, resizable=no, scrollbars=auto");
		}

		//------------------------------------------------------------------

		function bttnImprime(facility_code, facility_type){
			if (facility_type == 'LIST'){
				window.open('/fac_print.asp?fac='+facility_code, 'impreso','left=10,top=10,width=1450,height=900,titlebar=no,status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no');
			} else {
				window.open('/fac_print.asp?op=' + id + '&rot=' + document.vista.rot.value + '&c=' + document.vista.c.value + '&v=' + document.vista.v.value, 'impreso','left=10,top=10,width=725,height=450,titlebar=no,status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no');
			}
		}

		//------------------------------------------------------------------

		function bttnNuevo(facility_code) {
			var capa = document.getElementById('progress');
			capa.style.visibility = 'visible';	

			window.location.href='default.asp?op=fac&fac='+facility_code;
		}

		//------------------------------------------------------------------

		function bttnDelete(facility_code, idString) {
			if (confirm('¿Desea eliminar el registro?')) {
				var capa = document.getElementById('progress');
				capa.style.visibility = 'visible';	

				window.location.href='fac_del_line.asp?fac=' + facility_code + idString;
			}
		}

		//------------------------------------------------------------------

		function bttnSelector(facility_code, objReturn1) {
			window.open("fac_selector.asp?fac=" + facility_code + "&retObj=" + objReturn1, "Selector","left=130, top=130, width=795, height=350, titlebar=no, status=no, resizable=no, scrollbars=yes");

		}

		//------------------------------------------------------------------

		function bttnSelectorClean(fieldName) {
			var field = document.getElementById(fieldName);

			field.value = '';
		}

		//------------------------------------------------------------------

		function bttnSave(objForm) {
			if (confirm('¿Seguro que desea guardar el registro?'))
			{
				var capa = document.getElementById('progress');
				capa.style.visibility = 'visible';	
				
				var x = document.getElementById(objForm);

				//Colocamos los checkbox a checked para que pase el valor
				//-------------------------------------------------------
				for (var i=0; i<x.length; i++) {
				if (x.elements[i].type == 'checkbox') {
						x.elements[i].checked = true;
					}
				}  

				x.submit();
			}
		}

		//=====================================================================
		// BOTONES siguiente DE ASISTENTE FACILITIES
		//··········································

		function bttnPaso1()
		{
		 var x = document.getElementById("sys_facilities");

		 // Primero chequeamos que esta todo relleno
		 if ((x.facility_code.value == '') || (x.origin_name.value == '')) {
			 alert('Debes rellenar todos los campos obligatorios');
		 } else {
			if (confirm('¿Es todo correcto?')) {
				x.submit();
			}
		 }
		}

		//---------------------------------------------------------------------

		function bttnPaso2()
		{
		 var x = document.getElementById("fac_columns");

		// aqui habra que comprobar que los campos obligatorios estan rellenos
		 if (confirm('¿Es todo correcto?')) {
			 x.submit();
		 }
		}

		//---------------------------------------------------------------------

		function bttnPaso3()
		{
		 var x = document.getElementById("fac_filters");

		// aqui habra que comprobar que los campos obligatorios estan rellenos
		 if (confirm('¿Es todo correcto?')) {
			 x.submit();
		 }
		}
		
		//---------------------------------------------------------------------

		function bttnPaso4()
		{
		 var x = document.getElementById("sys_security");

		// aqui habra que comprobar que los campos obligatorios estan rellenos
		 if (confirm('¿Es todo correcto?')) {
			 x.submit();
		 }
		}
		
		//---------------------------------------------------------------------

		function bttnPaso5()
		{
		 var x = document.getElementById("sys_menu");

		// aqui habra que comprobar que los campos obligatorios estan rellenos
		 if (confirm('¿Es todo correcto?')) {
			 x.submit();
		 }
		}


		//=====================================================================
		// Envío de formulario
		//····················
		function sendForm () {

			var formulario = document.getElementById('formulario');
			var cadenaEnvio = 'sys_procform.asp?';
			var isOk = true;


			//Comprobacion de campos obligatorios
			//-----------------------------------
			var obligados = 'Nombre,Telefono';
			var noRellenados = '';

			for (var i=0; i<formulario.length; i++) {
				var elemento = formulario.elements[i].name;
				var esObligado = obligados.indexOf(elemento);
				var valor = formulario.elements[i].value;

				if (valor.replace(' ', '') != '') {
					cadenaEnvio += elemento + '=' + formulario.elements[i].value + '&';
				} 
				else {
					if (esObligado >= 0) {
						isOk = false;
						noRellenados += elemento + ', ';
					}
				}
				
			}

			//Comprobacion final y envio por AJAX
			//-----------------------------------
			if (isOk) {
				if (confirm ('¿Desea enviar el formulario?')) {
					//alert('Enviando\n' + cadenaEnvio);

					CreateXmlHttpObj();
					
					if(XmlHttpObj) {	
						XmlHttpObj.onreadystatechange = function () {
							if (XmlHttpObj.readyState == 1) {				
								document.getElementById('theForm').innerHTML='<h1>Contactar</h1><p><br /><img src=\"img/loading_mini.gif\" border=\"0\" align=\"absmiddle\">&nbsp;&nbsp;Enviando datos...</p>';									
							}

							if(XmlHttpObj.readyState == 4) {

								if(XmlHttpObj.status == 200) {			
									document.getElementById('theForm').innerHTML=XmlHttpObj.responseText;
								}
								else {
									alert("Código de error: "  + XmlHttpObj.status);
								}
							}
						}
						XmlHttpObj.open("POST", cadenaEnvio, true );
						XmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
						XmlHttpObj.send('');		
					}

				}
			} else {
				alert('Debes rellenar los campos obligatorios: ' + noRellenados);
			}

		}

		//=====================================================================
		//funciones AJAX
		//····················································

		function CreateXmlHttpObj() {
			try {
				XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				try	{
					XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch(oc) {
					XmlHttpObj = null;
				}
			}
				
			if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") {
				XmlHttpObj = new XMLHttpRequest();
			}
		}


	
		//=====================================================================
		//GESTION DE PETICIONES HTTTP --> AJAX
		//····································
		var xmlhttp;

		function loadXMLDoc(url)
		{
		xmlhttp=null;
		if (window.XMLHttpRequest)
		  {// code for Firefox, Opera, IE7, etc.
		  xmlhttp=new XMLHttpRequest();
		  }
		else if (window.ActiveXObject)
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		if (xmlhttp!=null)
		  {
		  xmlhttp.onreadystatechange=state_Change;
		  xmlhttp.open("GET",url,true);
		  xmlhttp.send(null);
		  }
		else
		  {
		  alert("Tu navegador no soporta XMLHTTP.");
		  }
		}


		function state_Change()
		{
		if (xmlhttp.readyState==4)
		  {// 4 = "loaded"
		  if (xmlhttp.status==200)
			{// 200 = "OK"

			 //Sentencia cambiada para que interprete javascript. Ver la funcion mas abajo
			 //···········································································
			 //document.getElementById('containerUrl').innerHTML=xmlhttp.responseText;
			 SetContainerHTML('containerUrl', xmlhttp.responseText, true);
			}
		  else
			{
			 alert("Problema cargando datos: " + xmlhttp.statusText);
			}
		  }
		}

		//---------------------------------------------------------------------
	
		//Esta funcion hace que, si existe codigo javascript en la respuesta AJAX, se interprete como
		//tal. Para el resto de codigo HTML no afecta, o no debe afectar ;-)
		//····························································································
		function SetContainerHTML(id,html,processScripts) {
			mydiv = document.getElementById(id);
			mydiv.innerHTML = html;
			if(processScripts!=false){
				var elementos = mydiv.getElementsByTagName('script');
				for(i=0;i<elementos.length;i++) {
					var elemento = elementos[i];
					nuevoScript = document.createElement('script');
					nuevoScript.text = elemento.innerHTML;
					nuevoScript.type = 'text/javascript';
					if(elemento.src!=null && elemento.src.length>0)	nuevoScript.src = elemento.src;
					elemento.parentNode.replaceChild(nuevoScript,elemento);
				}
			}
		}

	
	
	//============= END AJAX =======================

