/******** begin calendar *********/
	//setup some default values
	var myMaxYear			= 2029;
	var myCurrentYear 		= new Date().getFullYear();
	var myYearInView		= myCurrentYear;

	//this is what loops through the array
	function navigateCalendar(direction) {
		if(direction == "back") {
			// step backward 1 year
			myYearInView--;
			if(myYearInView<myCurrentYear) myYearInView=myMaxYear;//wrap
		} else if(direction == "forward") {
			// step forward 1 year
			myYearInView++;
			if(myYearInView>myMaxYear) myYearInView=myCurrentYear;//wrap
		} else {
			// move to specified year
			myYearInView=direction;
		}
		//set the new image
		//var img = new Image();
		//img.src = '/i/SITE_051110_15412548_16FSD/calendars/' + myYearInView + '.gif';
		//img.onload=switchCal;
		document.getElementById('myCalendarImageID').src = '/i/SITE_051110_15412548_16FSD/calendars/' + myYearInView + '.gif';

	}
	function switchCal() {
		document.getElementById('myCalendarImageID').src = '/i/SITE_051110_15412548_16FSD/calendars/' + myYearInView + '.gif';
		//document.myCalendarImage.src = '/i/SITE_051110_15412548_16FSD/calendars/' + myYearInView + '.gif';
	}
/******** end calendar *********/
	function replaceChars(entry,out,add)
		{
		temp = "" + entry; // temporary holder
		//run the while loop to remove all instances of the string
		while (temp.indexOf(out)>-1) 
			{
			pos= temp.indexOf(out);
			temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
			}
		return temp;
		}

	function createAnchor(baseLink)
		{
		if (baseLink == '/how_to_exchange/exchange_grid/' && document.cookie.userType == 'GM'){
			baseLink = '/how_to_exchange_gm/exchange_grid_gm/';
		}
		var myString = document.title;
		var myLength = myString.length;
		var myPropName = "";
		var myReturnName = "";
		var myReturnURL = "";
		//loop up the string till you find the lst delim
		for(var uu = myLength; uu >= 0; uu--)
			{
			if(	myString.substr(uu, 1) == "-")
				{myPropName = (myString.substr(uu + 2, myLength)); break;}
			}
		//remove the spaces
		myPropName = replaceChars(myPropName, "'", " ");
		myPropName = replaceChars(myPropName, "'", " ");
		myPropName = replaceChars(myPropName, " ", "_");		
		//set the name to the return var
		myReturnName = myPropName;
		myReturnURL = baseLink + "#" + myReturnName;
		window.location.href=(myReturnURL);		
		}	
	function hideProtectedText()
		{
		/*vars */
		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
		var isPC = (navigator.appVersion.indexOf("Mac") != -1) ? false : true;
		/*replace this with a check of the cookie*/
		var groupType = GetCFCookie("USERTYPE");
		var myElement = "";
		var isGM = false;
		var arraylength = 0;
		var isInCMS = (window.location.href.indexOf("hands-on") != -1) ? true : false;
		var myGroupToHide = "";
		/*action code*/
			/*check to see that the cookie exists and has a value, if not send them to the homepage*/
		if(!isInCMS)	
			{
			if(!groupType.length)
				{/*window.location.href=('/')*/;}
			else
				{
				/*whatever the group is I need to hide the other*/
				if(groupType == "core")
					{myGroupToHide = "associate";}
				else if (groupType == "GM")
					{isGM = true;myGroupToHide = "core";}
				else
					{myGroupToHide = "core";}
				
				myElement = document.getElementsByName(myGroupToHide);
				arraylength = (myElement.length * 1);
				/*check to make sure the array has a length and the loop through it*/
				if(arraylength)
					{
					for(var j=0;j<arraylength;j++)
						{
						if(isIE && isPC)
							{myElement[j].innerText = "";}
						else
							{myElement[j].innerHTML = "";}
						}
					}
				}
				//check to see if we need to hide any nav elements
				if( (document.getElementById('PAGE_051117_14214974_A6MP1')) && ( (groupType == 'associate' || groupType == 'guest') ) )
					{
					document.getElementById('PAGE_051117_14214974_A6MP1').style.visibility = "hidden";
					if(isIE && isPC)
						{document.getElementById('PAGE_051117_14214974_A6MP1').innerText = "";}
					else
						{document.getElementById('PAGE_051117_14214974_A6MP1').innerHTML = "";}
					}
				//stuff to hide from GM users
				if( (document.getElementById('PAGE_080310_07522890_2IO1P')) && ( (isGM == true) ) )
					{
					//document.getElementById('PAGE_080310_07522890_2IO1P').style.visibility = "hidden";
					//document.getElementById('iPAGE_070808_11032578_VVW1P').height = 1;
					//document.getElementById('PAGE_080310_07522890_2IO1P').href = '';
					}
				
			}
		};
        function makeSelection()
		{
		//setup any needed vars
		var myValue = document.PropSwitcher.prop[document.PropSwitcher.prop.selectedIndex].value;
		//check to see if the value has a length
		if(myValue.length)
			{
				//set the cookies
				SetCFDomainCookie('USERTYPE',myValue);
				//send me to the homepage
				window.location.href = '/index.cfm?skip=once';
			}
		else
			{alert("Please Select A Property");}
		};
	function replaceLabelTxt() {
		// get label tags
		labels = document.getElementsByTagName("label");
		for(var i=0;i<labels.length;i++){
			if(labels[i].id){
				// ajax to server
				retrieveText(labels[i].id);
				//labels[i].innerText="and non-useless label";
			}
		}
	}

	function retrieveText(id) {
		// open ajax connection
		httpa.open("GET", url + id, true);
		// set method for retrieving data
		httpa.onreadystatechange = handleTextRetrieved;
		// send request
		httpa.send(null);
	}
	function handleTextRetrieved() {
	/*
		format:
		<text id="#id#">#text_to_insert#</text>
	*/
		if (httpa.readyState==4&&typeof httpa.responseXML != null) {
			// load the XML
			var xmlDoc = httpa.responseXML;
			var xmlObj = xmlDoc.documentElement;
			var labelToReplace = document.getElementById(xmlObj.id);
			if (!labelToReplace)return;
			labelToReplace.innerText=xmlObj.innerText;
		}
	}

     function getHTTPObject() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
	    try {
	      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	      try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (E) {
	        xmlhttp = false;
	      }
	    }
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	    try {
	      xmlhttp = new XMLHttpRequest();
	    } catch (e) {
	      xmlhttp = false;
	    }
	  }
	  return xmlhttp;
	}

	
	function SetCFDomainCookie (name, value)
	{
	var name = name.toUpperCase();
	var path = "/";
	var myDomain = window.location.hostname;//theregistrycollection.com
	
	document.cookie = name + "=" + escape (value) +"; path=" + path + "; domain=" + myDomain + ";";
	};

	var url = "/i/SITE_051110_15412548_16FSD/ajax.cfm?id="; // The server-side script
	var httpa = getHTTPObject(); // We create the HTTP Object
	window.onload=replaceLabelTxt; // Create onload event to fire off label finding & replacing



	$(document).ready(function(){
		$('.CollapseTitle').bind('click',function(){
			var el = $(this).next();
			if(el.is(':hidden')){
				$(this).next().slideDown(250);
				$(this).addClass('CollapseHidden');
			}else{
				$(this).next().slideUp(250);
				$(this).removeClass('CollapseHidden');
			}
		});
		$('.OneColumn li:odd').addClass('alt');
		$('.TwoColumn li:nth-child(4n-1),.TwoColumn li:nth-child(4n)').addClass('alt');
		$('.OneColumn span').each(function(){
			var ht = $(this).html();
			if (!ht.match(/(<p|<li)/i))
				$(this).html('<p>'+ht+'</p>');
		});


(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

	});




//leaving site warning dialog [RSG 10-21-2011]
	$(document).ready(function() {
		$('body').append('<div id="dialog" title="The Registry Collection ®" />');
		var txtLink = ['www.chooseacottage.co.uk/partners/rgc/index.asp','registrycollectioncruises.com','cottages-4-you.co.uk','offthebeatenpath.com','perrygolf.com','presnellsportingcollection.com','pureluxuryholidays.co.uk','thewyndhamgrandcollection.com','theregistrycollection.yachtstore.com','www.cottages-4-you.co.uk/registry','www.fairmont.com/promotions/registrycollection','www.fairmont.com','www.cottageselection.co.uk/sites/cottageselection/partners/RGC/pages/home.aspx'];
		$('a[href^="http"]').click(function(e) {
			for(var i=0; i<txtLink.length;i++){
				if($(this).attr('href').toLowerCase().indexOf(txtLink[i]) >= 0){
					$('#dialog').html("<div class='ui-corner-all' style='padding:10px; background-color:#fff; margin-top:20px;'>By clicking \"Accept\" below, you will leave<br /> <b><em>The Registry Collection</em></b> website and be directed to a third-party provider\'s website and you will be subject to such third party\'s privacy policy, terms of use, and terms and conditions.</div>");
					$("#dialog").data('link', this).dialog('open');
				        return false;
                                 }
			
			}		
			
		});
		

		$("#dialog").dialog({
			bgiframe: true,
			modal: true,
			autoOpen: false,
			height:225,
			width:375,
			show: "fold",
			position:"center",
			buttons: {"Cancel": function() {
				$(this).dialog("close");
			},
			"Accept": function() {
				$(this).dialog("close");
				var path = $(this).data('link').href;
				$(location).attr('href', path);
			}
			
			}
		});
	});


