<!--

// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  //alert(name + ' i am here');
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);


// Toggle Layer Function

function toggle( targetId){
  if (document.getElementById){
		if (document.getElementById( targetId )){
			target = document.getElementById( targetId );
					target.style.display = "block";
		}
	}
}
function toggleOff( targetId ){
  if (document.getElementById){
		if (document.getElementById( targetId )){
			target = document.getElementById( targetId );
					target.style.display = "none";
		}
	}
}

function toggleOnOff(targetId, imgId)
{
	if (document.getElementById){
		target = document.getElementById( targetId );
		targetImage = document.getElementById(imgId);
		if (target.style.display == "none") 
		{
			target.style.display = "block";
			targetImage.src="../img/aa-centre/btn-minus.gif"; 
			targetImage.alt="collapse";
		} 
		else 
		{
			target.style.display = "none";
			targetImage.src="../img/aa-centre/btn-plus.gif"; 
			targetImage.alt="expand";
		}
	}
}

function expand(thistag, tag,htmlsrc) {
   styleObj=document.getElementById(thistag).style;
   if (styleObj.display=='none')
   {
   	styleObj.display='';
	tag.innerHTML = htmlsrc;
   }
   else {
   	styleObj.display='none';
    tag.innerHTML = htmlsrc;
   }
}

// pop up Photo

function popPhoto(imgPath,title,w,h){
	display = window.open('pop-photo.php?img='+imgPath+'&title='+title,'photo','width='+w+',height='+h+',top=100,left=100,scrollbars=no,resizable=yes');
	}
	
function popPhotoURL(imgPath,title,w,h){
	display = window.open('http://www.aatravel.co.nz/101/pop-photo.php?img='+imgPath+'&title='+title,'photo','width='+w+',height='+h+',top=100,left=100,scrollbars=no,resizable=yes');
	}
	
	// used by 101 index and  gallery pages
	function checkAllCatagories(){
		var v = document.searchForm.selectAll.checked;
		var l = document.searchForm.totCat.value;
		for(var i=1;i<l;i++){
			eval("document.searchForm.category_"+i+".checked = "+v);
		}
	}
function popup101(url,x,y){
  displayWindow = window.open(url, "newWindow", "resizable=yes,status=0,scrollbars=yes,width="+x+",height="+y+",left=100,top=100");
}

function popupBudget(url,x,y){
  displayWindow = window.open(url, "newWindow", "resizable=yes,status=0,scrollbars=yes,width="+x+",height="+y+",left=100,top=100");
}

function popup_simple(url,x,y){
	var name = 'newWindow'+(new Date().getTime());
	var iT = (screen.height / 2) - (y / 2);
	var iL = (screen.width  / 2) - (x / 2);
  displayWindow = window.open(url, name, "resizable=yes,status=0,scrollbars=yes,width="+x+",height="+y+",left="+iL+",top="+iT	);
	return false;
}

function popWindow(url, x, y, form, features){
	//alert(form);
	_features = typeof features != 'undefined' ? features : 'resizable=yes,status=0,scrollbars=yes';
	var formName = 'newWindow'+(new Date().getTime());
	displayWindow_x = window.open(url, formName, "width="+x+"px,height="+y+"px,left=100,top=100" + (_features != '' ? ',' + _features : ''));
	document.getElementById(form).target = formName;
	document.getElementById(form).submit();
	return false;
}

function ShowHide(menu, btn, shortDesc)
	{
		//alert('call showhide');
	   var thismenu = document.getElementById(menu);
	   var thisbtn = document.getElementById(btn);
	   var thisshortDesc = document.getElementById(shortDesc);
	   if ( typeof(thismenu)=='object' )
		 if ( thismenu.style.display=='none' )
		 {
			 thisshortDesc.style.display='none';
			 thismenu.style.display = '';
			 thisbtn.className = "hide-details";
	
		 }
		 else
		 {
			 thisshortDesc.style.display='';
			 thismenu.style.display = 'none';
			 thisbtn.className = "show-details";
			 return false;
		 }
	}
	
function fullScreen(url){
		var width = screen.width;
		var height = screen.height;
		window.open(url,'fullScreenWin', 'height='+height+',width='+width+', left=0,top=0,toolbar=no,scrollbars=yes,resizable=yes,status=yes,location=yes');
}	
//-->
/* <![CDATA[ */
if (typeof $ != 'undefined')
{
	var shortlistFile = '/main/my-short-list.php';
	
	function unselectToggleBtn()
	{
		$('input[alt*="selectall"]').each(function (){//this will just put a uncheck value on main toggle id top and bottom
			if( $(this).attr('checked') ==true )
			{ 	$(this).removeAttr("checked");	}
		});
	}
	
	function countTotalCheckedInputs()
	{
		var totalCheckBox = $("#frmShortList :checkbox").size();
		var totalCheckedBox = $("#frmShortList :checked").size();
		
		if( totalCheckBox !== totalCheckedBox )
		{
			unselectToggleBtn();
		}
		
		
		if( totalCheckedBox > 0 )
		{
			enableDeleteBtn();//this function can be found on /js/scripts.js
		}
		else
		{
			unselectToggleBtn();//this function can be found on /js/scripts.js this will unselect the main checkbox if checkboxes under frmShortList is all uncheck	
			disableDeleteBtn();//this function can be found on /js/scripts.js
		}
	}
	
	function enableDeleteBtn()
	{
		$('.deleteselected').each(function (){
			$(this).empty().fadeIn("slow").createAppend('a', { rel: 'deleteSelected', style: 'cursor:pointer;' }, 'Delete Selected').bind("click",function(e){
				if( $("#frmShortList :checked").size() > 0 )//this will determine how many checkboxes where checked
				{
					var iIndicatorId ='';
					var iIteration = 0;
					var Title ='';
					
					$("#frmShortList :checked").each(function (e){
						var getElementId = ($(this).parents()[2].parentNode.id);
						if( e == 0 )//first loop from e
						{
							iIndicatorId += ($(this).parents()[2].parentNode.id);
							//Below Title word was first used on individual delete image X button but was replaced with checkbox delete
							//Title += $('#'+getElementId+' .box1 h3').html();//this will supposedly get the name of the listing e.g Comfort Inn in Gwendoline
						}
						else
						{	
							iIndicatorId += "_"+($(this).parents()[2].parentNode.id);
							//Below Title word was first used on individual delete image X button but was replaced with checkbox delete
							//Title += $('#'+getElementId+' .box1 h3').html() + "<br />";//this will supposedly get the name of the listing e.g Comfort Inn in Gwendoline
						}	
						iIteration++;
					});
					Title = ( iIteration > 1 ) ? 'these' : 'this';
					Title += ' saved listing';
					$.modal('<div class="flistremoveheader"><a href="#" title="Close Window" href="#" name="confirmcancel" id="confirmcancel" onclick="cancel(); return false;"><img src="/img/images3.0/flistclose.gif" width="17" height="16" align="right" class="flistpad" alt="Close Window" /></a><h3>Remove from Shortlist?</h3></div><div class="flistpad"><p>Are you sure you want to delete '+Title+' from your shortlist?</p><div class="flistbuttons"><div class="flistremove"><a style="cursor:pointer;" name="confirmdelete" id="confirmdelete" onclick="bulkconfirmDelete(\''+iIndicatorId+'\'); return false;">Yes</a></div> <div class="flistremove2"><a href="#" name="confirmcancel" id="confirmcancel" onclick="cancel(); return false;">Cancel</a></div></div></div>', {close: false});
				}
			});
		});
	}
	
	function disableDeleteBtn()
	{
		$('.deleteselected').each(function (){
			$(this).empty().fadeIn("slow").append('Delete Selected');
		});
	}
	
	function reorder()
	{
		var countItems = ($('#contentcols div[tagId=\"listing\"]').length);
		if( countItems > 0 )
		{
			var firstItem = 0;
			var searchKey = 0;
			var lastItem  = countItems -1;
			
			$('div[tagId=\"listing\"]').each(function ()
			{
				if( firstItem == 0 )
				{	$(this).find("a[rel=\"up\"]:first").hide();	}
				else
				{	$(this).find("a[rel=\"up\"]:first").show();	}
				firstItem++;
			});
			
			$('div[tagId=\"listing\"]').each(function ()
			{
				if( searchKey === lastItem )
				{	$(this).find("a[rel=\"down\"]:last").hide();}
				else
				{	$(this).find("a[rel=\"down\"]:last").show();}
				searchKey++;
			});
			
			if( countItems < 5 )//this will hide the option key at the bottom as per Richard's request limit the display options if less than 5 items. Used by my-short-list.php
			{
				if( $('.shortlistkey').length > 1 )//go here only if the option menu is displayed at top and bottom.
				{
					$('.shortlistkey').each(function (e){//this will just put a check value on main toggle id top and bottom
						if( e > 0 )//just delete the bottom option menu not the top one.
						{
							$(this).fadeIn("slow").hide();
						}
					});
				}
			}
		}
		else
		{
			$('.shortlistkey').remove();	
			$('#contentcols').append("<div id=\"noresults\"><p><strong>Your shortlist is currently empty.</strong></p>" +
									 "<p>To add a listing to your shortlist, click on the button 'Add to Shortlist' at the bottom of each listing (see example below). " +
									 "The listing will now appear in your shortlist. Please note that your browser must be able to accept cookies in order to view this shortlist. " +
									 "This shortlist can be accessed at any time by clicking on the 'View My Shortlist' button in the left-hand column.</p>" +
									 "<p>The listing will be saved until you delete it from the list. You can do this by viewing your shortlist and clicking on the " +
									 "'delete' button at the bottom of each saved listing. You can also delete your listings by deleting your cookies. " +
									 "Once you have more than one listing in your shortlist, you can arrange the order of the listings by clicking on the arrow buttons. </p>" +
									 "<p><img src='/img/content/exampleshortlist.gif' width='750' height='133' /></p></div>");
		}
	}
	
	function saveorder ()
	{
		reorder();
		countTotalCheckedInputs();
		
		$.ajax({
			cache: false  ,
			type:  "POST" ,
			url:   "process-shortlist.php" ,
			data:  $("#frmShortList :input").serializeArray(),
			dataType: "json" ,
			success: function(data)
			{
				var responseObj = eval(data);
				navigationIndicator(responseObj.response);
				return false;
			}    
		});
	}
	
	function navigationIndicator( data )
	{
		if( ( parseInt(data)!== 0) )//short list is more than 0
		{
			if( data < 2 )
			{
				$("#totalSavedListId").empty().html('<a href="'+shortlistFile+'" id="savedListLink">View My Shortlist ('+data+')</a>');
			}
			else
			{
				$("#savedListLink").html('View My Shortlist ('+data+')');
			}
			
		}
		else//shortlist is empty
		{
			$("#totalSavedListId").empty().html('<span><a href="'+shortlistFile+'" id="savedListLink">My Shortlist (0)</a></span>');
		}
	}
	
	function cancel()
	{
		$.modal.close();
	}
		
	function confirmDelete( id )
	{
		$("#contentcols #"+id).fadeOut("slow").remove();
		saveorder();
		cancel();
	}
	
	function bulkconfirmDelete( id )
	{
		var split_id = id.split("_");
		for( i = 0 ; i < split_id.length ; i++ )
		{
			$("#contentcols #"+split_id[i]).slideToggle("0000.1").fadeOut("slow");
			$("#contentcols #"+split_id[i]).remove();
		}
		saveorder();
		cancel();
	}
	
	function showRemoveWindow(iIndicatorId)
	{
		var Title = $('.addressbox h2').html();
		$.modal('<div class="flistremoveheader"><a href="#" title="Close Window" href="#" name="confirmcancel" id="confirmcancel" onclick="cancel(); return false;"><img src="/img/images3.0/flistclose.gif" width="17" height="16" align="right" class="flistpad" alt="Close Window" /></a><h3>Remove from Shortlist?</h3></div><div class="flistpad"><p>Are you sure you want to delete <strong>'+Title+'</strong> from your shortlist?</p><div class="flistbuttons"><div class="flistremove"><a href="#" name="confirmdelete" id="confirmdelete" onclick="removeToSaveList('+iIndicatorId+'); return false;">Yes</a></div> <div class="flistremove2"><a href="#" name="confirmcancel" id="confirmcancel" onclick="cancel(); return false;">Cancel</a></div></div></div>', {close: false});
	}
	
	function addToSaveList( id , option )
	{	
		var split_id = id.split("-");
		domSearch = 'savedList'+split_id[2];	
		
		if( option.toLowerCase() == 'searchresults' )
		{	
			$(".flistadd").each(function ()
			{
				var search_id = (this.id).split("-");
				if( search_id[2].toLowerCase() == domSearch.toLowerCase() )
				{
					//$("#savedList"+id).empty().removeClass().addClass("flistadd2b").html("<img src=\"/img/waiting.gif\" alt=\"Adding to short list\" style=\"display:block\" />Adding to short list").fadeIn("slow");
					$(this).empty().removeClass().addClass("flistadd2b").html("<img src=\"/img/waiting.gif\" style=\"display:block\" />Adding to short list").fadeIn("slow");
				}
			});
			
		}
		else if( option.toLowerCase() == 'infopages' )
		{
			$("#infowrapper").empty().removeClass().addClass("flistadd2b").html("<img src=\"/img/waiting.gif\" style=\"float:left; margin:0 10px;\" />Adding to short list").fadeIn("slow"); 
		}
		
		id = split_id[2];
		
		if (this.timer) clearTimeout(this.timer);
        this.timer = setTimeout(function () 
		{  
			$.ajax({
				cache: false  ,
				type:  "POST" ,
				url:   "/main/process-shortlist.php" ,
				data:  "listingId="+id+"&method=addShortList",
				dataType: "json" ,
				success: function(data)
				{
					var responseObj = eval(data);
					navigationIndicator(responseObj.response);
					if( option.toLowerCase() == 'searchresults' )
					{					
						$(".flistadd2b").each(function ()
						{
							var search_id = (this.id).split("-");
							if( search_id[2].toLowerCase() == domSearch.toLowerCase() )
							{
								$(this).empty().removeClass().addClass("flistadd2").html('Saved to <a href="'+shortlistFile+'#'+id+'">Shortlist</a>');
								//$("#savedList"+id).empty().removeClass().addClass("flistadd2b").html("<img src=\"/img/waiting.gif\" alt=\"Adding to short list\" style=\"display:block\" />Adding to short list").fadeIn("slow");
								//$(this).empty().removeClass().addClass("flistadd2b").html("<img src=\"/img/waiting.gif\" alt=\"Adding to short list\" style=\"display:block\" />Adding to short list").fadeIn("slow");
							}
						});
					}
					else if( option.toLowerCase() == 'infopages' )
					{
						$("#infowrapper").empty().removeClass().append('<div class="flistadd4"><a href="#" onClick="showRemoveWindow('+id+'); return false;">Remove from Shortlist</a></div><div class="flistadd3">Saved to <a href="'+shortlistFile+'#'+id+'">Shortlist</a></div>');
					}
					return false;
				},
				error:function (xhr, ajaxOptions, thrownError)
				{
                    //$("#savedList"+id).empty().removeClass().addClass("flistadd2").html("Error try again.").fadeIn("slow"); 
                }    
			});
		}, 200 );
	}
	
	function removeToSaveList( id )
	{
	    this.timer = setTimeout(function () 
		{  
			$.ajax({
				cache: false  ,
				type:  "POST" ,
				url:   "/main/process-shortlist.php" ,
				data:  "listingId="+id+"&method=removeShortList",
				dataType: "json" ,
				success: function(data)
				{
					var responseObj = eval(data);
					navigationIndicator(responseObj.response);
					$("#infowrapper").empty().removeClass().append("<div id=\"l-0-savedList"+id+"\" class=\"flistadd\"><a onclick=\"addToSaveList('l-0-"+id+"','infopages');return false;\" href=\"#\">Add to Shortlist</a></div>");
					cancel();
					return false;
				}  
			});
		}, 200 );
	}
	
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}
	 
	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}
	 
	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}
	
	
	$(document).ready (function()
	{
		$("#form_sitesearch").submit(function() {
		    var q = trim($("#q").val());  
			if( q.length > 0 && q.toLowerCase() !=='enter search keyword' && q !=='')
			{
				var redirect;
				redirect = '/search/?'+ $("#form_sitesearch :input").serialize();
				location.href = redirect;
			}
			else
			{
				$("#q").removeClass().addClass("ssinput red").attr('value','Enter search keyword');
				return false;
			}
		});
		
		$("#q").focus(function () {
			$(this).removeClass().addClass("ssinput").removeAttr("value");
		});
	});
}
/* ]]> */





