function Ajax(url,f,loading,nombre){var intentos=0;var self;var indicemodal=0;var tooltipTimeout;this.xmlDoc=null;this.url=url?url:null;this.f=f?f:null;this.nombre=nombre?nombre:null;this.loading=loading?loading:null;this.loaderror=null;this.running=false;this.post=null;this.id=Math.random();this.nocache=false;this.async=true;this.ahistory=null;this.init=function(){AjaxOn=true;if(window.XMLHttpRequest){this.xmlDoc=new XMLHttpRequest();this.xmlDoc.onreadystatechange=check}else{if(window.ActiveXObject){this.xmlDoc=new ActiveXObject("Microsoft.XMLHTTP");if(this.xmlDoc){this.xmlDoc.onreadystatechange=check}}else{alert("Tu navegador no puede soportar el script")}}};this.run=function(run_url,run_f,run_loading){this.url=run_url?run_url:this.url;this.f=run_f?run_f:this.f;this.loading=run_loading?run_loading:this.loading;try{this.init()}catch(e){this.showModal('<h3 style="color: red">Aviso importante</h3>Hemos detectado que tu navegador tiene desactivado el uso de controles ActiveX en la configuraci&oacute;n de seguridad, lo que te impedir&aacute; navegar con normalidad por este sitio. Para activarlo, debes seguir los siguiente pasos:<br><br><div style="text-align:left">1- Accede al men&uacute; <strong>Herramientas -> Opciones de Internet</strong>.<br>2- Haz click en la pesta&ntilde;a <strong>Seguridad</strong>.<br>3- Haz click en el bot&oacute;n <strong>Nivel personalizado...</strong><br>4- Dentro del men&uacute; <strong>Controles y complementos de ActiveX</strong>, en la primera opción <strong>Activar la secuencia de comandos de los controles de ActiveX marcados como seguros</strong>, seleccionar la opci&oacute;n <strong>Activar</strong>.<br>5- Pincha en <strong>Aceptar</strong> en las dos ventanas.<br>6- Cuando hayas terminado, haz click en el bot&oacute;n <strong>Actualizar</strong> para volver a cargar la p&aacute;gina.</div><br><br><input type="button" value="Actualizar" onclick="location.reload();">');return false}this.running=true;if(this.loading!=null&&this.loading!=null){if(typeof(self.loading)=="function"){self.loading()}else{eval(self.loading)}}document.body.style.cursor="wait";this.xmlDoc.open((this.post==null?"GET":"POST"),this.url+"&rd="+Math.random(),this.async);if(this.post!=null){this.xmlDoc.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}this.xmlDoc.send(this.post);this.post=null};var label;var modal2Html="";var tooltipTimeout;this.hideTimeout=2;this.errorTimeout=5;this.abortar=function(){if(this.xmlDoc!=null){if(this.xmlDoc.readyState<4){this.xmlDoc.abort()}}};this.showLabel=function(msg){crearEtiqueta();label.style.color="#000";label.style.background="#FD6";label.innerHTML=msg;label.style.display=""};this.hideLabel=function(msg){if(msg){crearEtiqueta();label.style.color="#FFF";label.style.background="#093";label.innerHTML=msg;setTimeout(function(){if($("_ajax_label")){document.body.removeChild($("_ajax_label"))}},this.hideTimeout*1000)}else{if($("_ajax_label")){document.body.removeChild($("_ajax_label"))}}};this.errorLabel=function(msg){crearEtiqueta();label.style.color="#FFF";label.style.background="#C30";label.innerHTML=msg;setTimeout(function(){if($("_ajax_label")){document.body.removeChild($("_ajax_label"))}},this.errorTimeout*1000)};this.showTooltip=function(msg){clearTimeout(tooltipTimeout);var tt;if(!$("_ajax_tooltip_"+this.id)){tt=document.createElement("DIV");tt.id="_ajax_tooltip_"+this.id;tt.style.position="absolute";tt.style.zIndex=1000*indicemodal+1;document.body.appendChild(tt);document.body.onmousemove=function(e){$("_ajax_tooltip_"+self.id).style.top=((e?e:event).clientY+document.body.scrollTop+20)+"px";$("_ajax_tooltip_"+self.id).style.left=((e?e:event).clientX+15)+"px"}}else{tt=$("_ajax_tooltip_"+this.id)}tt.style.left="-2000px";tt.style.top="-2000px";tt.className="ajax_tooltip_on";tt.innerHTML=msg;tt.style.display=""};this.hideTooltip=function(msg){clearTimeout(tooltipTimeout);if($("_ajax_tooltip_"+this.id)){if(msg){$("_ajax_tooltip_"+this.id).style.display="";$("_ajax_tooltip_"+this.id).className="ajax_tooltip_off";$("_ajax_tooltip_"+this.id).innerHTML=msg;tooltipTimeout=setTimeout(function(){$("_ajax_tooltip_"+self.id).style.display="none"},this.hideTimeout*1000)}else{$("_ajax_tooltip_"+this.id).style.display="none"}}};this.errorTooltip=function(msg){clearTimeout(tooltipTimeout);if($("_ajax_tooltip_"+this.id)){$("_ajax_tooltip_"+this.id).style.display="";$("_ajax_tooltip_"+this.id).className="ajax_tooltip_error";$("_ajax_tooltip_"+this.id).innerHTML=msg;tooltipTimeout=setTimeout(function(){$("_ajax_tooltip_"+self.id).style.display="none"},this.errorTimeout*1000)}};this.showModal=function(html,estilo){indicemodal++;bgTrans();var idventana="_ajax_modalcontent_"+this.id+"_"+indicemodal;if(!$(idventana)){var modalcontent=document.createElement("DIV");modalcontent.style.cssText="position:absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index:"+((1000*indicemodal)+1)+";";modalcontent.id=idventana;document.body.appendChild(modalcontent)}$(idventana).innerHTML='<table border="0" width="100%" height="100%" align="center"><tr><td align="center"><div class="modalstyle'+(estilo?" "+estilo:"")+'">'+html+"</div></td></tr></table>";$(idventana).style.top=getScrollY()};this.showModalFade=function(html){this.showModal(html);fadeIn($("_ajax_modalcontent_"+this.id+"_"+indicemodal),10)};this.showModalURL=function(url,ancho,alto){this.showModal('<iframe name="frame_ajax" width="'+ancho+'" height="'+alto+'" scrolling="auto" src="'+url+'" frameborder="no"></iframe>')};this.showModalPopup=function(html){modal2Html=html;indicemodal++;bgTrans();if(!$("_ajax_modal2_"+this.id+"_"+indicemodal)){var modal=document.createElement("DIV");modal.style.cssText="position: absolute; z-index:"+((1000*indicemodal)+1)+"; left: -45px; width: 15px; height: 15px; border: 1px solid #469dbe;";modal.style.top=getScrollY()+15+"px";modal.id="_ajax_modal2_"+this.id+"_"+indicemodal;document.body.appendChild(modal)}modal2mover()};this.hideModal=function(){visionCombos("visible");if($("_ajax_modal2_"+this.id+"_"+indicemodal)){document.body.removeChild($("_ajax_modal2_"+this.id+"_"+indicemodal));document.body.removeChild($("_ajax_trans_"+this.id+"_"+indicemodal));indicemodal--}else{if($("_ajax_modalcontent_"+this.id+"_"+indicemodal)){document.body.removeChild($("_ajax_modalcontent_"+this.id+"_"+indicemodal));document.body.removeChild($("_ajax_trans_"+this.id+"_"+indicemodal));indicemodal--}}if(indicemodal>0&&$("_ajax_modalcontent_"+this.id+"_"+indicemodal)){$("_ajax_modalcontent_"+this.id+"_"+indicemodal).style.top=getScrollY()}};this.hideModalFade=function(){if($("_ajax_modal2_"+this.id+"_"+indicemodal)){fadeOut($("_ajax_modal2_"+this.id+"_"+indicemodal),90)}else{if($("_ajax_modalcontent_"+this.id+"_"+indicemodal)){fadeOut($("_ajax_modalcontent_"+this.id+"_"+indicemodal),90)}}};function crearEtiqueta(){if($("_ajax_label")){label=$("_ajax_label")}else{label=document.createElement("SPAN");label.style.cssText="position: absolute; right:0px; padding: 2px 20px 2px 20px; font-family: arial; font-size: 13px; font-weight: bold; z-index: 99";label.id="_ajax_label";document.body.appendChild(label)}label.style.top=getScrollY()}function visionCombos(opcion){if(document.all){if(indicemodal<=1){var arr=document.getElementsByTagName("select")}else{if(document.getElementById("_ajax_modal2_"+self.id+"_"+(indicemodal-1))){var arr=document.getElementById("_ajax_modal2_"+self.id+"_"+(indicemodal-1)).getElementsByTagName("select")}else{if(document.getElementById("_ajax_modalcontent_"+self.id+"_"+(indicemodal-1))){var arr=document.getElementById("_ajax_modalcontent_"+self.id+"_"+(indicemodal-1)).getElementsByTagName("select")}}}for(i=0;i<arr.length;i++){arr[i].style.visibility=opcion}}var arr_obj=document.getElementsByTagName("object");for(i=0;i<arr_obj.length;i++){arr_obj[i].style.visibility=opcion}}function getScrollY(){var scrollY=0;if(document.documentElement&&document.documentElement.scrollTop){scrollY=document.documentElement.scrollTop}else{if(document.body&&document.body.scrollTop){scrollY=document.body.scrollTop}else{if(window.pageYOffset){scrollY=window.pageYOffset}else{if(window.scrollY){scrollY=window.scrollY}}}}return scrollY}function modal2mover(){var modal=$("_ajax_modal2_"+self.id+"_"+indicemodal);if(modal.style.left!="30px"){modal.style.left=parseInt(modal.style.left.replace("px",""))+5+"px";setTimeout(function(){modal2mover()},1)}else{setTimeout("document.getElementById('_ajax_modal2_"+self.id+"_"+indicemodal+'\').style.background="#FF850D"',100);setTimeout("document.getElementById('_ajax_modal2_"+self.id+"_"+indicemodal+'\').style.background="#FFF"',200);setTimeout("document.getElementById('_ajax_modal2_"+self.id+"_"+indicemodal+'\').style.background="#FF850D"',300);setTimeout("document.getElementById('_ajax_modal2_"+self.id+"_"+indicemodal+'\').style.background="#FFF"',400);setTimeout("document.getElementById('_ajax_modal2_"+self.id+"_"+indicemodal+'\').style.background="#FF850D"',500);setTimeout("document.getElementById('_ajax_modal2_"+self.id+"_"+indicemodal+'\').style.background="#FFF"',600);setTimeout(function(){modal2resize()},700)}}function modal2resize(){var modal=$("_ajax_modal2_"+self.id+"_"+indicemodal);if(modal.style.width!=415+"px"){modal.style.width=parseInt(modal.style.width.replace("px",""))+40+"px";modal.style.height=parseInt(modal.style.height.replace("px",""))+10+"px";setTimeout(function(){modal2resize()},20)}else{modal.style.background="url(http://www.facilisimo.com/mensajes/expocasa/images/logo.gif) no-repeat top center #FFF";modal.style.height="auto";modal.innerHTML='<div style="margin: 50px 0 15px 0; text-align: center;">'+modal2Html+"</p>"}}function bgTrans(){if(!$("_ajax_trans_"+self.id+"_"+indicemodal)){var modal=document.createElement("DIV");if(document.all){modal.style.filter="Alpha(Opacity=80)"}else{modal.style.MozOpacity="0.8"}modal.style.position="absolute";modal.style.height=(document.body.scrollHeight?document.body.scrollHeight:document.documentElement.scrollHeight)+"px";modal.style.top="0px";modal.style.left="0px";modal.style.zIndex=1000*indicemodal;modal.style.width="100%";modal.className="ajax_trans";modal.id="_ajax_trans_"+self.id+"_"+indicemodal;document.body.appendChild(modal);visionCombos("hidden")}}function fadeIn(ventana,opacidad){if(document.all){ventana.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+opacidad+")"}else{if(opacidad>=100){ventana.style.MozOpacity="1.00"}else{ventana.style.MozOpacity="."+opacidad}}if(opacidad<100){if(document.all){setTimeout(function(){fadeIn(ventana,opacidad+10)},1)}else{setTimeout(function(){fadeIn(ventana,opacidad+25)},1)}}}function fadeOut(ventana,opacidad){if(document.all){ventana.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+opacidad+")"}else{ventana.style.MozOpacity="."+opacidad}if(opacidad>0){if(document.all){setTimeout(function(){fadeOut(ventana,opacidad-10)},1)}else{setTimeout(function(){fadeOut(ventana,opacidad-25)},1)}}else{self.hideModal()}}function check(){if(self.xmlDoc.readyState==4){if(self.xmlDoc.status==200){self.running=false;if(typeof(self.f)=="function"){self.f()}else{eval(self.f)}intentos=0;document.body.style.cursor="auto";if(self.ahistory!=null){location.href=location.hash.split("#")[0]+"#"+self.ahistory;$_("hash").value=self.ahistory}}else{if(self.xmlDoc.status==666){RecuperarSesion()}else{if(self.xmlDoc.status<=0){EjecucionAbortada()}else{checkerror()}}}AjaxOn=false}}function checkerror(){self.running=false;if(self.loaderror!=null){if(typeof(self.loaderror)=="function"){self.loaderror()}else{eval(self.loaderror)}}else{if(self.xmlDoc.status!=0){if(intentos<3){if(confirm("Ha ocurrido un error de comunicación con el servidor. ¿Desea reintentar?")){intentos++;self.run()}else{intentos=0;self.errorLabel("ERROR: No se ha podido establecer comunicación con el servidor.")}}else{intentos=0;self.errorLabel("Error de comunicación con el servidor.\nPor favor, vuelva a intentarlo pasados unos minutos.")}}}document.body.style.cursor="auto";return}function EjecucionAbortada(){}self=this};
