function HandleChange(valor,valor2) {		
		url="http://www.mybuenosairesapartments.com/changefoto.php?id_f="+valor+"&num="+valor2;
		var theULU = document.getElementById("changefoto");
		theULU.innerHTML = '<div class="loading2"></div>';
		leer_doc(url);	
}
	
function leer_doc(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("changefoto").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}



function HandleTransfer(valor) {		
		switch(valor){
		case "yes":
		url="http://www.mybuenosairesapartments.com/booktransfersi.php";
		break;
		case "no":
		url="http://www.mybuenosairesapartments.com/booktransferno.php";	
		break;
		}
		leer_doc2(url);	
}
	
function leer_doc2(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv2;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv2;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv2() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("transfers").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}

var myPic = new Image(25,18);
    myPic.src = "imagenes/flecha_next_over.jpg";

var myPic = new Image(25,18);
    myPic.src = "imagenes/flecha_prev_over.jpg";

var myPic = new Image(90,25);
    myPic.src = "imagenes/book_now_over.gif";

var myPic = new Image(90,25);
    myPic.src = "imagenes/see_apartment_over.gif";

var myPic = new Image(150,56);
    myPic.src = "imagenes/paypal-btn2.png";
	
var myPic = new Image(150,27);
    myPic.src = "imagenes/btn-over.jpg";	
	
var myPic = new Image(168,26);
    myPic.src = "imagenes/paypal-booknow-mi2.png";	

var myPic = new Image(170,30);
    myPic.src = "imagenes/paypalbook-fo2.png";
	
/*var catPath = "imagenes/";
var catWidth = 25;
var catHeight = 18;

 var MyPics = new Array (
  "flecha_next_over.jpg",
  "flecha_prev_over.jpg",
  "tabby-cat.jpg" );

var myPics = preloadImages (catPath,MyPics,catWidth,catHeight);

function preloadImages(path,pics,width,height) {

   var images = new Array;

   for (var picNum=0; picNum<pics.length; picNum++) {
      images[picNum] = new Image(width,height);
      images[picNum].src = (path + pics[picNum]);
   }

   return(images);
} */


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_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_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 NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+''
win = window.open(mypage, myname, winprops)
}

function getdays(){
if(document.form1.diain.value!="" && document.form1.mesin.value!="" &&  document.form1.anioin.value!="" && document.form1.diaout.value!="" && document.form1.mesout.value!="" && document.form1.anioout.value!=""){

	var dout = eval(document.form1.diaout.value);
	var mout = eval(document.form1.mesout.value);
	var aout = eval(document.form1.anioout.value);
	var din = eval(document.form1.diain.value);
	var mesin = eval(document.form1.mesin.value);
	var ain = eval(document.form1.anioin.value);
	if(aout<ain){
		alert("Checkout Day cant be less than Checkin");
		document.form1.dias.value = 0;
		document.form1.dias2.value = 0;
		//document.form1.Submit.disabled = true;
		return false;
	}
	if(aout==ain && mout<mesin){
		alert("Checkout Day cant be less than Checkin");
		document.form1.dias.value = 0;
		document.form1.dias2.value = 0;
		//document.form1.Submit.disabled = true;
		return false;
	}
	if(aout==ain && mout==mesin && dout<=din){
		alert("Checkout Day cant be less than Checkin");
		document.form1.dias.value = 0;
		document.form1.dias2.value = 0;
		//document.form1.Submit.disabled = true;
		return false;
	}
	
	
	var gDays = [0,31,28,31,30,31,30,31,31,30,31,30,31];
	desde=document.form1.anioin.value+"-"+document.form1.mesin.value+"-"+document.form1.diain.value;	
	hasta=document.form1.anioout.value+"-"+document.form1.mesout.value+"-"+document.form1.diaout.value;	
	
	var mesin2 = mesin;
	var dias = eval(gDays[mesin2] - din);
	if(dias==0){
		dias = 0;
	}
	//alert(mesin2);
	//alert("dias1: "+dias);
	
	while(mesin2<mout-1){
		mesin3 = eval(mesin2)+1;
		//alert(gDays[mesin3]);
		dias = eval(dias) + eval(gDays[mesin3]);
		//echo $mesin2."<br>";
		mesin2++;
	}
	//alert("dias dif mes:: "+dias);
	
	if(aout > ain){
		while(mesin2+1<13){
			dias = eval(dias) + eval(gDays[mesin2+1]);
			//echo $gDays[$mesin2+1]."<br>";
			mesin2++;
		}
		var mesesmas = 1;
		while(mesesmas< mout){
			dias = eval(dias) + eval(gDays[mesesmas]);
			mesesmas++;
		}
	}
	if(mesin <3 && mout >2 && ain ==2008){
		if (( ain % 4 == 0) && ((ain % 100 != 0) || (ain % 400 == 0))){
			dias = eval(dias)+1;
		}
	}
	if(ain <2008 && mout>2 && aout >=2008){
		if ((aout % 4 == 0) && ((aout % 100 != 0) || (aout % 400 == 0))){
			dias = dias+1;
		}
	}

	if((document.form1.anioout.value-document.form1.anioin.value)>1){
		var anis = (document.form1.anioout.value-document.form1.anioin.value) - 1;
		var ji = 1;
		var anios = document.form1.anioin.value+1;
		while(ji<anis+1){
			if ((anios % 4 == 0) && ((anios % 100 != 0) || (anios % 400 == 0))){
				dias = eval(dias)+1;
			}
			anios++;
			ji++;
		}
		anis = 365 * anis;
		
		dias = eval(dias) + eval(anis); 
	}
	
	dias = eval(dias) + eval(document.form1.diaout.value);
	
	if(document.form1.mesin.value==document.form1.mesout.value && document.form1.anioin.value==document.form1.anioout.value){
		dias = eval(document.form1.diaout.value)-eval(document.form1.diain.value);
	}
	
document.form1.checkedin.value = document.form1.anioin.value+"-"+document.form1.mesin.value+"-"+document.form1.diain.value;
document.form1.checkedout.value = document.form1.anioout.value+"-"+document.form1.mesout.value+"-"+document.form1.diaout.value;

document.form1.dias.value = dias;
document.form1.dias2.value = dias;

if(document.form1.dias.value<1){
	alert("Checkout Day cant be less than Checkin");
	document.form1.dias.value = 0;
	document.form1.dias2.value = 0;
	//document.form1.Submit.disabled = true;
}
}else{
	alert("Complete all required fields of Checkin and Checkout");
	document.form1.dias.value = 0;
	document.form1.dias2.value = 0;
	//document.form1.Submit.disabled = true;
}
}


function getrent(){
if(document.form1.depto.value!="" && document.form1.dias.value!=0){
//document.form1.Submit.disabled = false;
var cdias = document.form1.dias2.value;
if(document.form1.dias2.value<8){
	var costodia = eval(document.form1.rsemana.value);
}
if(document.form1.dias2.value>7 && document.form1.dias2.value<22){
	var costodia = (document.form1.rsemana.value/7)*document.form1.dias2.value;	
}
if(document.form1.dias2.value>21 && document.form1.dias2.value<31){
	var costodia = eval(document.form1.rmes.value);	
}
if(document.form1.dias2.value>30){
	var costodia = eval(document.form1.rmes.value/30)*document.form1.dias2.value;	
}
document.form1.renta.value = costodia.toFixed(0);
document.form1.renta2.value = costodia.toFixed(0);
if(cdias<15){
	document.form1.deposito.value = document.form1.rsemana.value;
}
if(cdias>14  && cdias<31){
	document.form1.deposito.value = document.form1.rsemana.value*2;
}
if(cdias>30){
	document.form1.deposito.value = document.form1.rmes.value;
}

var myMonth = ["Sunday","January","February","March","April","May","June","July","August","September","October","November","December"];
var myDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
var getdia = document.form1.diain.value+" "+myMonth[document.form1.mesin.value]+", "+document.form1.anioin.value;
var mydiain = new Date(eval('"'+getdia+'"'));
var quedia = myDays[mydiain.getDay()];

	if(document.form1.dias2.value>7 && document.form1.dias2.value<22 && eval(document.form1.renta.value)>eval(document.form1.rmes.value)){
		var costodia = eval(document.form1.rmes.value);
		
		document.form1.renta.value = costodia.toFixed(0);
		document.form1.renta2.value = costodia.toFixed(0);
		if(cdias<15){
			document.form1.deposito.value = document.form1.rsemana.value;
		}
		if(cdias>14  && cdias<31){
			document.form1.deposito.value = document.form1.rsemana.value*2;
		}
		if(cdias>30){
			document.form1.deposito.value = document.form1.rmes.value;
		}

		var myMonth = ["Sunday","January","February","March","April","May","June","July","August","September","October","November","December"];
		var myDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
		var getdia = document.form1.diain.value+" "+myMonth[document.form1.mesin.value]+", "+document.form1.anioin.value;
		var mydiain = new Date(eval('"'+getdia+'"'));
		var quedia = myDays[mydiain.getDay()];

	//end si la renta es mayor al precio de mes	
	}
}//end validacion de campos completos
else{
//alert("Campos Obligatorios: departamento/huesped/pasajeros/idioma/checkin/checkout");
}
}//end function getrent


function vaciopayres() {		
	var theULU = document.getElementById("checkreserva");
	theULU.innerHTML = '<div class="vacio"></div>';
}

/* checkeo que no haya reservas en el periodo seleccionado para el depto */
function Handlereserva(valor,valor2,valor3) {		
	url="http://www.mybuenosairesapartments.com/reservas_check_reserva.php?checkin="+valor+"&checkout="+valor2+"&id="+valor3;
	var theULU = document.getElementById("checkreserva");
	theULU.innerHTML = '<div class="loadpaypal"></div>';
	leer_doc8(url);	
}
function leer_doc8(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv8;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv8;
req.open("GET", url, true);
req.send();
}
}
}
function targetDiv8() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("checkreserva").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}

function loadtermsclose() {		
		url="http://www.mybuenosairesapartments.com/vacio.php";
		var theULU = document.getElementById("termsandcond");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		leer_doc9(url);	
}
function loadterms() {		
		url="http://www.mybuenosairesapartments.com/termsandcond.php";
		var theULU = document.getElementById("termsandcond");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		leer_doc9(url);	
}
	
function leer_doc9(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv9;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv9;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv9() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("termsandcond").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}


function loadpaypalcon(valor) {		
		url="http://www.mybuenosairesapartments.com/paypalgo.php?id="+valor;
		var theULU = document.getElementById("paypalbook");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		leer_doc10(url);	
}
	
function leer_doc10(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv10;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv10;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv10() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("paypalbook").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}

function acepto(){
	if (document.formbook.termscond.checked){
		document.formbook.termsvalue.value = 1;
	}else{
		document.formbook.termsvalue.value = 0;
	}
}
function edif(){
		document.form1.diff.value = 40;
}


function tipoarribo2(valor) {		
	vacio = "";

	if(valor == "Plane"){
		dia = document.form1.dianum.value;
		url="http://www.mybuenosairesapartments.com/flightinfo.php?dia="+dia;
	}
	if(valor == "Ship"){
		url="http://www.mybuenosairesapartments.com/infoshipbus.php";
	}
	if(valor == "Bus"){
		url="http://www.mybuenosairesapartments.com/infoshipbus.php";
	}
	if(valor == "Other"){
		url="http://www.mybuenosairesapartments.com/otherinfo.php";
	}
	if(valor == ""){
		url="http://www.mybuenosairesapartments.com/vacio.php";
	}
		var theULU = document.getElementById("arrival");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		leer_doc11(url);	
		var theULU = document.getElementById("horaencuentro");
		theULU.innerHTML = '<div class="vacio"></div>';
}
	
function leer_doc11(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv11;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv11;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv11() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("arrival").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}


function ezetransfer(valor) {		
	if(valor == "Ezeiza"){
		url="http://www.mybuenosairesapartments.com/ezetransfer.php";
		document.form1.diff.value = 90;
	}else{
		url="http://www.mybuenosairesapartments.com/vacio.php";
		document.form1.diff.value = 40;
	}
		var theULU = document.getElementById("ezetran");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		leer_doc12(url);	
}
	
function leer_doc12(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv12;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv12;
req.open("GET", url, true);
req.send();
}
}
}

function targetDiv12() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("ezetran").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}


function ftime(valor) {		
	vacio = "";
	url2="http://www.mybuenosairesapartments.com/flighttime.php";
	document.form1.diff.value = valor;
		var theULU = document.getElementById("flighttime");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		var theULU = document.getElementById("horaencuentro");
		theULU.innerHTML = '<div class="vacio"></div>';
		leer_doc12b(url2);	
}
function leer_doc12b(url2) {
if (window.XMLHttpRequest) { // Non-IE browsers
req2 = new XMLHttpRequest();
req2.onreadystatechange = targetDiv12b;
try {
req2.open("GET", url2, true);
} catch (e) {
alert(e);
}
req2.send(null);
} else if (window.ActiveXObject) { // IE
req2 = new ActiveXObject("Microsoft.XMLHTTP");
if (req2) {
req2.onreadystatechange = targetDiv12b;
req2.open("GET", url2, true);
req2.send();
}
}
}

function targetDiv12b() {
if (req2.readyState == 4) { // Complete
if (req2.status == 200) { // OK response
document.getElementById("flighttime").innerHTML = req2.responseText;
} else {
alert("Problem: " + req2.statusText);
}
}
}


function calcuextra(){
var quedia = document.form1.quedia.value;

var horasen = eval(document.form1.horaen.value);
alert("llego"+horasen);
/*if(quedia=="Saturday"){
		document.form1.extra.value = 10;	
}else if(quedia=="Sunday"){
		document.form1.extra.value = 10;	
}else{
		document.form1.extra.value = 0;	
}*/	
if(horasen>6 && horasen<10){
document.form1.extra.value = 10;
}
if(horasen>18 && horasen<24){
document.form1.extra.value = 10;
}
if(horasen>=0 && horasen<7){
document.form1.extra.value = 15;
}
if(horasen>8 && horasen<19){
	if(quedia=="Saturday"){
		document.form1.extra.value = 10;	
	}else if(quedia=="Sunday"){
		document.form1.extra.value = 10;	
	}else{
		document.form1.extra.value = 0;	
	}	
}
document.form1.extra2.value = document.form1.extra.value;
}

function calculatime(valor, valor1) {
		ediff = document.form1.diff.value;
		dia = document.form1.dianum.value;
		url="http://www.mybuenosairesapartments.com/meetingtime.php?hora="+valor+"&minu="+valor1+"&dia="+dia+"&ediff="+ediff;

		var theULU = document.getElementById("horaencuentro");
		theULU.innerHTML = '<div class="loadpaypal"></div>';
		leer_doc13(url);	
}
	
function leer_doc13(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv13;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv13;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv13() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("horaencuentro").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}

function ADVSEARCH(valor) {		
	if(valor == "avanzada" ){
		url="http://www.mybuenosairesapartments.com/apartments-advanced-search-on-buenos-aires";
	}else if(valor == "normal" ){
		url="http://www.mybuenosairesapartments.com/apartments-normal-search";
	}
		var theULU = document.getElementById("advsearch");
		theULU.innerHTML = '<div class="loadingadvsearch"></div>';
		leer_doc14(url);	
}
	
function leer_doc14(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv14;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv14;
req.open("GET", url, true);
req.send();

}
}
}

function targetDiv14() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("advsearch").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}



