var pages = {
  'first':['','index.html'],
  'realestatenews':['realestate-news.html'],
  'realestateagents':['about.html'],
  'portdouglasinformation':['port-douglas.html'],
  'contactandenquiries':['enquiry.html','thanks.html'],
	'portdouglasholidayaccom':['hol-accom-info.html','hol-accom-port-douglas.html']
};

var formArray = new Array();
formArray["BuyRes"]="search.html?proptype=buy&url_category=Residential&searchbtn=1";
formArray["RentRes"]="search.html?proptype=rent&url_category=Residential&searchbtn=1";
formArray["BuyCom"]="search.html?proptype=buy&url_category=Commercial&searchbtn=1";
formArray["RentCom"]="search.html?proptype=rent&url_category=Commercial&searchbtn=1";
formArray["BuyRur"]="search.html?proptype=buy&url_category=Rural&searchbtn=1";
formArray["RentRur"]="search.html?proptype=rent&url_category=Rural&searchbtn=1";
formArray["RentHol"]="Holiday";
formArray["BuyHol"]="Holiday";
formArray["BuyLan"]="search.html?proptype=buy&url_category=Land&searchbtn=1";
formArray["ResRecent"]="Recent?url_category=Residential";
formArray["ResForms"]="forms.html?url_category=Residential";
formArray["ResSell"]="selling.html?url_category=Residential";
formArray["ResBuy"]="buying.html?url_category=Residential";
formArray["ResRecent"]="Recent?url_category=Residential";
formArray["ComForms"]="forms.html?url_category=Commercial";
formArray["ComSell"]="selling.html?url_category=Commercial";
formArray["ComBuy"]="buying.html?url_category=Commercial";
formArray["ComRecent"]="Recent?url_category=Commercial";
formArray["RurBuy"]="buying.html?url_category=Rural";
formArray["RurForms"]="forms.html?url_category=Rural";
formArray["RurSell"]="selling.html?url_category=Rural";
formArray["RurRecent"]="Recent?url_category=Rural";
formArray["HolBuy"]="buying.html?url_category=Holiday";
formArray["HolForms"]="forms.html?url_category=Holiday";
formArray["HolSell"]="selling.html?url_category=Holiday";
formArray["HolRecent"]="Recent?url_category=Holiday";
formArray["InvBuy"]="buying.html?url_category=Investment";
formArray["InvForms"]="forms.html?url_category=Investment";
formArray["InvSell"]="selling.html?url_category=Investment";
formArray["InvRecent"]="Recent?url_category=Investment";
formArray["LanBuy"]="buying.html?url_category=Land";
formArray["LanForms"]="forms.html?url_category=Land";
formArray["LanSell"]="selling.html?url_category=Land";
formArray["LanRecent"]="Recent?url_category=Land";
formArray["AgentsProfile"]="about.html?url_category=Agents";
formArray["AgentsContact"]="about.html?url_category=Agents";
formArray["InfoLocation"]="location.html?url_category=Information";
formArray["InfoResort"]="resorts.html?url_category=Information";
formArray["InfoLifestyle"]="lifestyle.html?url_category=Information";
formArray["InfoAccomm"]="accommodation.html?url_category=Information";
formArray["InfoTours"]="tours.html?url_category=Information";
formArray["InfoRestaurants"]="dining.html?url_category=Information";
formArray["InfoServices"]="services.html?url_category=Information";
formArray["InfoResources"]="resources.html?url_category=Information";
formArray["InfoPhotos"]="port-douglas-photos.html?url_category=Information";
formArray["NewsReal"]= "realestate-news.html?url_category=News";
formArray["HolAccom"]= "Holiday";
formArray["HolAccomInfo"]= "hol-accom-info.html?url_category=HolidayAccom";
formArray["HolAccomPortDouglas"]= "hol-accom-port-douglas.html?url_category=HolidayAccom";
formArray["PortDouglasBlog"]= "portdouglas/";

function getElementsByClass(searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function changeMenu(menuID) {
	
	var foundItems = new Array();
	foundItems = getElementsByClass("menuItem");

	for (var i=0; i<foundItems.length;i++) {
    var found_item = foundItems[i];
		found_item.style.display = 'none';
		
		if (document.getElementById(found_item.id + '_parent')){
  	  if(found_item.id != original_nav_item){
    		document.getElementById(found_item.id + '_parent').className = '';
  		}
		}
	}
	
	var change = document.getElementById(menuID);
	change.style.display = 'block';
	
	if (document.getElementById(menuID + '_parent'))
  	document.getElementById(menuID + '_parent').className = 'active';
}

function makeMenuItemActive(menuID){
  if (document.getElementById(menuID + '_parent'))
  	document.getElementById(menuID + '_parent').className = 'active';
	
}

function changeMenulevel2(menuID) {
	
	var foundItems = new Array();
	foundItems = getElementsByClass("menuItemLevel2");
	
	for (var i=0; i<foundItems.length;i++) {
		foundItems[i].style.display = 'none';
		if (document.getElementById(foundItems[i].id + '_parent'))
  		document.getElementById(foundItems[i].id + '_parent').className = '';
	}
	
  //Make third level menu visible
	var change = document.getElementById(menuID);
		change.style.display = 'block';
		
  if (document.getElementById(menuID + '_parent'))
   document.getElementById(menuID + '_parent').className = 'active';
		
}

function subform(target)
{
  newloc=formArray[target];
//    alert('target = ' + target);
   
  if (newloc)
  {
//    alert('newloc = ' + newloc);
    location.href = '/' + newloc;
  }  else {
    location.href = '/' + target;
  }  
}

function Pop_image(imgID) {
 	var scr_width = 452;   // Initial size; will be resized
	var scr_height = 410;  // Initial size; will be resized
	var img_page = "image.php?id=";
	var newWin = null;
	newWin = window.open(img_page+imgID,"","width=" + scr_width + ",height=" + scr_height + ",scrollbars=no,resizable=yes");
}

function Resort_Pop_image(imgID) {
  var scr_width = 452;   // Initial size; will be resized
	var scr_height = 410;  // Initial size; will be resized
	var img_page = "image.php?do=resort&id=";
	var newWin = null;
	newWin = window.open(img_page+imgID,"","width=" + scr_width + ",height=" + scr_height + ",scrollbars=no,resizable=yes");
}

function Link_Pop_image(imgID) {
  var scr_width = 452;   // Initial size; will be resized
  var scr_height = 410;  // Initial size; will be resized
  var img_page = "image.php?do=link&id=";
  var newWin = null;
  newWin = window.open(img_page+imgID,"","width=" + scr_width + ",height=" + scr_height + ",scrollbars=no,resizable=yes");
}

function Pop_page (selectName,baseUrl)
{
   page = document.getElementById(selectName).value;
   self.location.href = baseUrl + page;
} 


function ID(id) {
  return document.getElementById(id);
}


// If User has visited a statcic page, choose the correct nav item..
function changeMenuForStaticPage(){
  for(var i in pages) {
    if(in_array(page(document.location.href), pages[i])){
      ID(i + '_parent').className = 'active';
      original_nav_item = i; // keep a record of what the original selected tab is.
      ID(i).style.display = 'block';
      
    }
    else{
      ID(i + '_parent').className = '';
      ID(i).style.display = 'none';
    }
  } 
  
}

function in_array(needle,haystack) {
  for(var i in haystack)
    if(haystack[i] == needle)
      return true;
  return false;
}        

function page(url) {
  apage = url.substring(url.lastIndexOf('/')+1);
  if(apage.indexOf('#') > 0)
    apage = apage.substring(0, apage.indexOf('#'));
  return apage;
}

