// JavaScript Document

//getTours
/*function getTours(i) {
	  	document.getElementById("images").innerHTML = details[i];
	  }*/
	  var request = false;
   		try {
     		request = new XMLHttpRequest();
   		} 
		catch (trymicrosoft) {
     	try {
       		request = new ActiveXObject("Msxml2.XMLHTTP");
     	} 
		catch (othermicrosoft) {
       try {
         	request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }
   
   if (!request)
     alert("Error initializing XMLHttpRequest!");
	 
		 

   function getZones()
   {
	   var city = document.getElementById("city").value;
	   var url = "ajax_request_zones.php?city=" + escape(city);
	   if(request)
	   request.open("GET", url, true);
	   request.onreadystatechange = updateZones;
	   request.send(null);
   }
   
   function updateZones()
   {
	   if(request.readyState == 4)
	   	if(request.status == 200)
		   {
			   	   

			   var response = "<span style='float:left'>Zone</span>"; 
			   response += "<span style='float:right'>";
			   response += "<select name='zone' id='zone'>";
			   response += "<option value = 'any' ";
			   response += "selected='selected'>Any</option>"; 
				response += request.responseText;
				response += "</select></span>";
				document.getElementById("pzone").innerHTML = response;
		   }
		   
				  
				  
		  else if (request.status == 404)
         	alert("Request URL does not exist");
       	  else
         	alert("Error: status code is " + request.status);
   }
   function getListings() {
	   if(false){
		   var message = "You are no longer authorized to view this information.";
		   
		 document.getElementById("images").innerHTML=message;
	   }
	   else {
							 
	   var city = document.getElementById('city').value;
	   var zone = document.getElementById('zone').value;
	   var priceLow = document.getElementById('priceLow').value;
	   var priceHigh = document.getElementById('priceHigh').value;
	   var project = document.getElementById('project').value;

	   var url = "ajax_request_listings.php?city=" + escape(city) + 
	   "&zone=" + escape(zone) +
	   "&priceLow=" + escape(priceLow) +
	   "&priceHigh=" + escape(priceHigh) +
	   "&project=" + escape(project);

	   request.open("GET", url, true);
	   request.onreadystatechange = showListings;
	   request.send(null);
	   }

   }
   
    function showListings() {
	 if(request.readyState == 4)
	   	if(request.status == 200)
		   {
			   document.getElementById("images").innerHTML = request.responseText;
			   document.getElementById("thumbs").innerHTML = "";
			   document.getElementById("description").innerHTML = "";
			   document.getElementById("reference").innerHTML = "";
		   }
		  else if (request.status == 404)
         	alert("Request URL does not exist");
       	  else
         	alert("Error: status code is " + request.status);  
   }
   //var description;
  function getSelectListing(selListing) {
	   var url = "ajax_request_selected_listing.php?ref_immo=" + escape(selListing);
	   request.open("GET", url, true);
	   request.onreadystatechange = showSelectListing;
	   request.send(null); 
	   
   }
   
   function showSelectListing() {
	   if(request.readyState == 4)
	   	if(request.status == 200)
		   {
			   //var output = request.responseText;
			   //alert(output);
			   var output = request.responseText.split("|");
			   //alert(output[0]);//reference
			   //alert(output[1]);//property_type
			   //alert(output[2]);//description + comment
			   //alert(output[3]);//price
			   //alert(output[4]);//location
			   //alert(output[5]);//image directory
			   //alert(output[6]);//image
			   //alert(output[7]);//thumbs, comma separated
			   var ref = output[0];
			   var property_type = output[1];
			   var description = output[2];
			   var price = output[3];
			   var location = output[4];
			   var imageDirectory = output[5];
			   var image = output[6];
			   var thumbs = output[7].split(",");
			   var selListing = "<iframe name='slide' title='Viewer' src='adminsite/galeria/" + imageDirectory + "/images/" + image + "'";
	  selListing += " width='751px' height='563px' scrolling='no' align='right'></iframe>";
	  var thumb = "";
	  var selThumbs = "<table><tr><td class='nav'>";
	  selThumbs += "<table cellpadding='4'> <tr>";
	  for(i = 0;i < thumbs.length; i++) {
	   selThumbs += "<td valign='bottom' width='80'>";
		selThumbs += "<a target='slide' href='adminsite/galeria/";
		selThumbs += imageDirectory + "/images/" + thumbs[i] + "'>";
		selThumbs += "<img class='image' src='adminsite/galeria/";
		selThumbs += imageDirectory + "/thumbnails/" + thumbs[i] + "'";
		selThumbs += " width='80' height='80' border=0><br></a></td>"
	  }
	   
	  selThumbs += "</tr></table></td></tr></table>"
	  if(image == ""){
		  selThumbs = "";
		  selListing = "Photos not available.";
	  }
	  
	  
	  var url = "contact.php?ref_info=" + ref;
	  var selDescription = "<p>" + description + "</p>";
	  selDescription += "<p align='right'>";
	  selDescription += "<a class='link1' href='" + url + "'>";//Note this line, href='   "   + url   "   '>"; url is enclosed in single quotes, Took forever to figure out
	  selDescription += "Contact this property</a><br/><a class='link1' href='javascript:printDiv()'>Print</a></p>";
	    document.getElementById("images").innerHTML = selListing;
		document.getElementById("thumbs").innerHTML = selThumbs;
		document.getElementById("description").innerHTML = selDescription;
		document.getElementById("reference").innerHTML = "Referencia: " + ref + " - " + location + " - " + price + " - " + property_type;
		
		   }
		  else if (request.status == 404)
         	alert("Request URL does not exist");
       	  else
         	alert("Error: status code is " + request.status);  
	   
	  
   }
   
   function getInfo(){
	   
	   document.getElementById("images").innerHTML = "<iframe src='about.php' height=400px width=660px scroll=no marginheight=0 marginwidth=0 frameborder=0></iframe>";
	   document.getElementById("thumbs").innerHTML = "";
	   document.getElementById("description").innerHTML = "";
	   document.getElementById("reference").innerHTML = ""; 
   }
   
function getServices() {
	/*var services = "<p class='heading'>SERVICES</p>";
	var title1 = "<p class='title1'>Visas for Retired or Pensioned Persons</p>";
	var text1 = "<p class='text'>";
	text1 += "Panama's immigration laws have created various types of visas which are easily available to foreigners receiving a pension so they can enjoy their retirement in this country.<br>";
	text1 += "They all grant Resident status as well as offering a number of tax exemption benefits. We can provide a full range of legal services to help you with your visa application.";
	text1 += "</p>";
	var title2 = "<p class='title1'>Panamanian Corporations and Private Foundations</p>";
	var text2 = "<p class='text'>";
	text2 += "Panamanian Corporations and Private Foundations are commonly used for reducing an individual's tax burden and for protecting assets, as well as helping maintain confidentiality. They may be used as holding companies, to own any kind of property such as bank or investments accounts, real estate property, etc, as well as for business activities outside your actual place of business. Private Interest Foundations are usually used to protect family assets and income, as well as for succession purposes. Its regulations may be private and do not require public registration.";
	text2 += "</p>";
	var title3 = "<p class='title1'>Offshore Bank Accounts</p>";
	var text3 = "<p class='text'>";
	text3 += "The Republic of Panama is known as an Offshore Service Center, and many local and international banks have branches here, offering both local and offshore accounts. Investment and tax planning services are readily available.";
	text3 += "</p>";
	var title4 = "<p class='title1'>Need help relocating to paradise?</p>";
	var text4 = "<p class='text'>";
	text4 += "We are experts in relocation, with more than 22 years experience moving expats to Panama from all over the world including Canada, USA and Europe. We aim to give our clients and their families a warm welcome to make sure that their first impressions of Panama are as favorable as possible. We can offer a full range of support services free of charge to relocating families, starting with the availability of apartments for rental on a short term basis, which can provide a much easier transition than staying in a hotel, particularly for families.";
	text4 += "</p>";
	var title5 = "<p class='title1'>Other Services</p>";
	var text5 = "<p class='text'>";
	text5 += "We are certified public translators from English to Spanish and Spanish to English.<br>We can provide advice and assistance in all aspects of your move to Panama including obtaining mortgages, arranging insurance cover, opening bank accounts, incorporating companies etc.";
	text5 += "</p>";*/

	//document.getElementById("images").innerHTML = services + title1 + text1 + title2 + text2 + title3 + text3 + title4 + text4 + title5 + text5;
	document.getElementById("images").innerHTML = "<iframe src='services.php' height=400px width=677px scroll=no marginheight=0 marginwidth=0 frameborder=0></iframe>";
	   document.getElementById("thumbs").innerHTML = "";
	   document.getElementById("description").innerHTML = "";
	   document.getElementById("reference").innerHTML = ""; 
}

function getRetirementServices() {
	/*var retirementServices = "<p class='heading'>RETIREMENT SERVICES</p>";
	var title1 = "<p class='title1'>Visas for Retired or Pensioned Persons</p>";
	var text1 = "<p class='text'>";
		text1 += "Panama's immigration laws have created various types of visas which are easily available to foreigners receiving a pension so they can enjoy their retirement in this country.<br>They all grant Resident status as well as offering a number of tax exemption benefits. We can provide a full range of legal services to help you with your visa application.";
		text1 += "</p>";*/
	   document.getElementById("images").innerHTML =  "<iframe src='retirement_services.php' height=400px width=660px scroll=no marginheight=0 marginwidth=0 frameborder=0></iframe>";
	   /*var title2 =  "<p class='title1'>";
	   title2 += "Requirements for Pensioner Visa</p>"; 
 
var requirements = "<p class='text'>";
requirements+= "A.  Certification of pensioner status from a foreign government, international organization or private company, confirming that the applicant is in receipt of a lifetime pension of not less than one thousand dollars (US$ 1,000.00) per month or equivalent in foreign currency.  If the applicant is receiving a pension of a minimum of US$750.00 a month, then provided he also purchases a property for cash of at least US$100,000.00, then he may for the pensioner visa.<br> If the pension or retirement relates to a private company, the following documents must be provided in addition to those set out in this article:<br>- Letter from a foreign pension provider, trust company, mutual fund, insurance company or bank, certifying that they administer funds on behalf of the company or the applicant;<br>- Current certificate of good standing of the company issuing the pension and administering the fund;<br>- Copy of payslip or bank statement.<br><br>B.  Certificate of criminal record from the country of origin or of residence. In countries where such a certificate is not issued, the applicant must provide a certificate from a diplomatic or consular mission of the country of origin duly accredited in the Republic of Panama, confirming that such a certificate does not exist, together with a notarised affidavit stating that the applicant does not have a criminal record.<br><br>C. Four passport size photographs.<br>All documentation originating in any country other than Panama must be legalized.<br>In addition to the documents listed below, we will obtain for you:<br>Health certificate issued by a recognized professional.<br>Photocopy of your passport, duly notarized in Panama.<br>Power of Attorney given to us in order to represent you in this matter.<br><br>Our fees for this type of visa are of US$1,500.00, plus expenses."
requirements += "</p>";*/
	   document.getElementById("thumbs").innerHTML = "<iframe src='requirements_pensioner_visa.php' height=150px width=677px scroll=auto marginheight=0 marginwidth=0 frameborder=0></iframe>";
	   document.getElementById("description").innerHTML = "";
	   document.getElementById("reference").innerHTML = ""; 
}
function getSelectMngProp(managed_dir) {
	   var url = "ajax_request_selected_mng_prop.php?managedDir=" + escape(		managed_dir);
	   request.open("GET", url, true);
	   request.onreadystatechange = showSelectMngProp;
	   request.send(null); 
	   
   }
function showSelectMngProp() {
	if(request.readyState == 4)
	   	if(request.status == 200)
		   {
			   var response = request.responseText.split("|");
			   var name = response[3];
			   var description = response[2];
			   var strThumbs = response[1];
			   var managedDirectory = response[0];
			   var thumbs = strThumbs.split(",");
			    var selImage = "<iframe name='slide' title='Viewer' src='Images/managed_property/";
				selImage += managedDirectory + "/images/"  + thumbs[0] + "'";
				selImage += "width='751px' height='563px' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'></iframe>";	  
	  
			   var selThumbs = "<table><tr><td class='nav'>";
	  selThumbs += "<table cellpadding='4'> <tr>";
	  for(i = 0;i < thumbs.length; i++) {
	   selThumbs += "<td valign='bottom' width=100'>";
		selThumbs += "<a target='slide' href='Images/managed_property/";
		selThumbs += managedDirectory + "/images/" + thumbs[i] + "'>";
		selThumbs += "<img class='image' src='Images/managed_property/";
		selThumbs += managedDirectory + "/thumbs/" + thumbs[i] + "'";
		selThumbs += " width='100' height='100' border=0><br></a></td>"
	  }
	   
	  selThumbs += "</tr></table></td></tr></table>"
			   document.getElementById("images").innerHTML = selImage;
			   document.getElementById("thumbs").innerHTML = selThumbs;
			   document.getElementById("description").innerHTML = description;
			   document.getElementById("reference").innerHTML = name;
		   }
		  else if (request.status == 404)
         	alert("Request URL does not exist");
       	  else
         	alert("Error: status code is " + request.status);  
	
}
function select_Mng(managed_dir) {
	//img = img + ".jpg";
	alert(managed_dir);
	//var selListing = "<iframe name='slide' title='Viewer' src='/adminsite/galeria/" + imageDirectory + "/images/" + image + "'";
	  //selListing += " width='751px' height='563px' scrolling='no' align='right'></iframe>";
	var mngImage = "<iframe name='slide' title='Viewer' src='Images/managed_property/managed_property1/images/"  + img + ".jpg'";
	  mngImage += " width='751px' height='563px' scrolling='no' align='right'></iframe>";
	var image = "Images/managed_property/managed_property1/images/" + img + ".jpg";
	var thumb = "Images/managed_property/managed_property1/thumbs/" + img + "_c.jpg";
	alert(image + ":" + thumb);
	var desc_mng = "This is a description of the managed property selected";
	/*var selThumbs = "<table><tr><td class='nav'>";
	  selThumbs += "<table cellpadding='4'> <tr>";
	  for(i = 0;i < thumbs.length; i++) {
	   selThumbs += "<td valign='bottom' width='80'>";
		selThumbs += "<a target='slide' href=/'adminsite/galeria/";
		selThumbs += imageDirectory + "/images/" + thumbs[i] + "'>";
		selThumbs += "<img class='image' src='/adminsite/galeria/";
		selThumbs += imageDirectory + "/thumbnails/" + thumbs[i] + "'";
		selThumbs += " width='80' height='80' border=0><br></a></td>"
	  }*/
	document.getElementById("images").innerHTML = mngImage;
	document.getElementById("thumbs").innerHTML = "<a target='slide' href='" + image + "'><img src='"+thumb+"'/></a>";
	document.getElementById("reference").innerHTML = "";
	document.getElementById("description").innerHTML = desc_mng;
}
   
   
	   

function contact() {
		document.getElementById("thumbs").innerHTML = "<iframe src='contact_email.php' height=150px width=660px scroll=no marginheight=0 marginwidth=0 frameborder=0></iframe>";
}

function getReference(){
	var ref_info = document.getElementById('reference');
	alert(ref_info.innerHTML);
}

function printDiv()
{
  var divToPrint1 = document.getElementById('reference'); 
  var divToPrint2 =document.getElementById('description');
  var newWin=window.open('','Print-Window','width=1px,height=1');
  newWin.document.open();
  newWin.document.write('<html><body onload="window.print()">'+
  divToPrint1.innerHTML + '<br>' + divToPrint2.innerHTML + '</body></html>');
  newWin.document.close();
  setTimeout(function(){newWin.close();},10);
}
 /*function sendMail()
 {
	//alert("this is from sendMail: " + reference);
 	   var fullname = document.getElementById('fullname').value;
	   var email = document.getElementById('email').value;
	   var phonenumber = document.getElementById('phonenumber').value;
	   var subject = document.getElementById('subject').value;
	   var description = document.getElementsByName('description').item(0).value;

	   var url = "ajax_send_mail.php?fullname=" + escape(fullname) + 
	   "&email=" + escape(email) +
	   "&phonenumber=" + escape(phonenumber) +
	   "&subject=" + escape(subject) +
	   "&description=" + escape(description);

	   request.open("GET", url, true);
	   request.onreadystatechange = emailSent;
	   request.send(null); 
 }*/
 function emailSent()
 {
	 document.getElementById("images").innerHTML = "Your message been sent."
 }
 function Authorized()
 {
	 var dateToday = new Date();
	 var authorizeDate = new Date(2011,3,26);
	 var dateDiff = (authorizeDate.getTime() - dateToday.getTime());
	 //alert(dateToday);
	 //alert(authorizeDate);
	 //alert(dateDiff);
	 if(dateDiff < 0){
		 return false;
	 }
	 else {
		 return true;
	 }
	 
	 
 }
 

