//var propertyTourID = new Array(0,286,285,211,991,601,992,0);
var contactDetails = new Array(0,2,2,1,1,1,1,3);
var rentalList = false;
var rentalPage = false;
var contactRentalPage = false;
var renovationPage = false;

if(!addresses) var addresses = new Array();

//sm
addresses.push("2993 823 653 2166 2300 2713 2402 2397 2965 1474 258 1474 2166 1245 498 2300 2842 2166 255 119 2546 2166 2397 2713 1414 2842 2397 653");
//rp
addresses.push("2993 823 653 2166 2300 2713 2402 2397 2965 255 2166 2713 498 1446 2546 255 522 1474 2397 255 2402 498 2397 2300 1245 2402 522 1414 2842 2397 653");
//cr
addresses.push("2993 823 653 2166 2300 2713 2402 2397 2965 2842 2166 255 2397 2713 1414 255 2397 1474 522 2546 2842 2166 255 2397 2713 2300 1245 2166 119 522 1474 2300 2124 1245 1474 1414 2842 2397 653");
//bp
addresses.push("2993 823 653 2166 2300 2713 2402 2397 2965 2634 522 1245 498 255 1557 651 1474 2402 2166 1245 1474 2860 2300 2546 1446 2397 2402 653 2166 2300 2713 1414 2842 2397 653");

function init()
{
	page = location.href.substring(location.href.lastIndexOf("/")+1);
	if (rentalPage)
	{
		initRentalPage();
	}
	else
	{
		document.getElementById("contactDetails1").style.display = "inline";
		if (contactRentalPage)
		{
			initContactRentalPage();
		}
	}
}
window.onload = init;

function initContactRentalPage()
{
	var propertyQueryIndex = page.indexOf("?property=");
	if (propertyQueryIndex >= 0)
	{
		rentalNumber = parseInt(page.substring(propertyQueryIndex + 10));

      	var purpleHouse = (rentalNumber == 1);
        var kingHouse = (rentalNumber == 2);
        var seasTheDay = (rentalNumber == 7);

		if (purpleHouse || kingHouse || seasTheDay)
		{
			document.getElementById("rentalContactDetails" + contactDetails[rentalNumber]).style.display = "inline";
			var propertyContactSelect = document.getElementById("propertyContactSelect");
			propertyContactSelect.selectedIndex = rentalNumber;
		}	
	}
}

function initRentalPage()
{
	rentalNumber = parseInt(page.substr(0,2));
	document.getElementById("contactDetails" + contactDetails[rentalNumber]).style.display = "inline";
//	var rentalMenu = document.getElementById("rentalMenu");
//	rentalMenu.selectedIndex = rentalNumber + 1;
	var seasTheDay = (rentalNumber == 7)
	if (seasTheDay)
	{
		document.getElementById("checkAvailabilityLink").style.display = "none";
	}
}

function rentalAvailability(q)
{
	var purpleHouse = (rentalNumber == 1);
	var kingHouse = (rentalNumber == 2);
    var seasTheDay = (rentalNumber == 7);

	if (purpleHouse || kingHouse || seasTheDay)
	{
		if (q == "book")
		{
			location.href = "contactus.html?property=" + rentalNumber;
		}
		else
		{
			location.href = "#datesandrates";
		}
	}
	else
	{
		location.href = "http://book.resortpointe.com/avail.php?property=" + rentalNumber + "&" + q;
	}
	return false;
}

function virtualTour()
{
	var tourID = propertyTourID[rentalNumber];
	if (tourID == 0)
	{
		alert("No tour is currently available for this property.");
	}
	else 
	{
		window.open("http://www.shoretours.net/tours/viewer.html?id=" + tourID);
	}
	return false;
}

function mailpage()
{
	mail_str = "mailto:?subject=Take a look at the " + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at " + location.href; 
	location.href = mail_str;
}

function mailpage2()
{
	mail_str = "mailto:?subject=I'm interested in renting the" + document.title;
	mail_str += "&body=Please contact me about the" + document.title;
	mail_str += ". You can view it at " + location.href; 
	location.href = mail_str;
}

// canManipulateImages - check if the browser we're using can do
// clever stuff with document images.

function canManipulateImages() {
	if (document.images)
		return true;
	else
		return false;
}

// loadPosterImage

function loadPosterImage(imageURL) {
	if (gImageCapableBrowser) {
		document.imagePoster.src = imageURL;
		return false;
	}
	else {
		return true;
	}
}

// gImageCapableBrowser - is this browser hip to images? Set up
// a global variable so that we don't have to keep calling a function
// (useful if the function becomes costly to compute).

gImageCapableBrowser = canManipulateImages();


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 MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

var decryption_cache = new Array();

function decrypt_string(crypted_string,n,decryption_key,just_email_address)
{
	var cache_index = "'"+crypted_string+","+just_email_address+"'";

	if(decryption_cache[cache_index])					// If this string has already been decrypted, just
		return decryption_cache[cache_index];				// return the cached version.

	if(addresses[crypted_string])						// Is crypted_string an index into the addresses array
		var crypted_string = addresses[crypted_string];			// or an actual string of numbers?

	if(!crypted_string.length)						// Make sure the string is actually a string
		return "Error, not a valid index.";

	if(n == 0 || decryption_key == 0)
	{					// If the decryption key and n are not passed to the
		var numbers = crypted_string.split(' ');			// function, assume they are stored as the first two
		n = numbers[0];	decryption_key = numbers[1];			// numbers in crypted string.
		numbers[0] = ""; numbers[1] = "";				// Remove them from the crypted string and continue
		crypted_string = numbers.join(" ").substr(2);
	}

	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');

	for(var i in crypted_characters)
	{
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		if(just_email_address && i < 7)				// Skip 'mailto:' part
			continue;
		if(just_email_address && decrypted_character == 63)	// Stop at '?subject=....'
			break;
		decrypted_string += String.fromCharCode(decrypted_character);
	}
	
	decryption_cache[cache_index] = decrypted_string;			// Cache this string for any future calls

	return decrypted_string;
}

function decrypt_and_email(crypted_string,n,decryption_key)
{
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,false);
	parent.location = decrypted_string;
}

function decrypt_and_echo(crypted_string,n,decryption_key)
{
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,true);
	document.write(decrypted_string);
	return true;
}

// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y)
{
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}

function popup(url,detWidth,detHeight) {
leftPos = 40
topPos = 40
detWidth += 20
detHeight += 20
if (screen) {
	leftPos = screen.width * .1
	topPos = screen.height * .1
		}
detWindow = window.open(url,detWidth+"x"+detHeight,'width='+detWidth+',height='+detHeight+',left='+leftPos+',top='+topPos+',toolbar,location,scrollbars,resizable,status')
detWindow.focus()
}

