
function externalLinks() {
	if (!document.getElementsByTagName) return;	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank") {
			anchor.target = "_blank";
		}
	}
}

function setMainMenu() {
  if( document.getElementById &&
      document.getElementsByTagName ){
    if( document.getElementById('main-menu') ){
      var submenu = document.getElementById('main-menu');
      var links = submenu.getElementsByTagName('a');
      for( var i=0; i < links.length; i++ ) {     	    
      	if (links[i].parentNode) {
			p = links[i].parentNode;
			if (links[i].nextSibling == null) {
				p.href = links[i].href;
				p.onclick = function(){
					document.location = this.href;
					return false;
				};
			}
			
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
					$("ul.tiered-menu ul").each(function(i) {
						this.style.left = this.parentNode.offsetLeft;
					});
				 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
				 if (ieversion<=6) {
					p.onmouseover=function() {
						this.className+=" over";
					}
					p.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				 }
			}
			
			
		}
      }	        
    }
   }
 }

function openNewPopup(name, url) {		
	var horizontalOffset = (screen.width - 850) / 2;
	if (horizontalOffset < 10) horizontalOffset = 0;
	var width = 850;
	var height = 540;	
	var verticalOffset	= (screen.height - height - 20) / 2;
	if (verticalOffset < 10) verticalOffset = 0;	
	
	var w = window.open(url, name, "toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=yes,screenX=" + horizontalOffset + ",screenY=" + verticalOffset + ",left=" + horizontalOffset + ",top=" + verticalOffset + ",width=" + width + ",height=" + height);
	w.focus();
}

function openGuestFormPopup(name, url) {		
	var horizontalOffset = (screen.width - 960) / 2;
	if (horizontalOffset < 10) horizontalOffset = 0;
	var width = 960;
	var height = 540;
	if (screen.height > 900) {
		height = 740;
	}	
	var verticalOffset	= (screen.height - height - 20) / 2;
	if (verticalOffset < 10) verticalOffset = 0;	
	
	var w = window.open(url, name, "toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=yes,screenX=" + horizontalOffset + ",screenY=" + verticalOffset + ",left=" + horizontalOffset + ",top=" + verticalOffset + ",width=" + width + ",height=" + height);
	w.focus();
}

function setEnquiryAndTalePopup() {		
  if( document.getElementById &&
      document.getElementsByTagName ){
     
    if( document.getElementById('container') ) {
      var submenu = document.getElementById('container');
      var links = submenu.getElementsByTagName('a');
      for( var i=0; i < links.length; i++ ) {
      	link = links[i];
      	if (link.href.indexOf('/enquiry/') != -1) {
			link.onclick = function(){
				openNewPopup("EnquiryWindow", this.href);
				return false;
			};
		}
		else
      	if (link.href.indexOf('/tales/new/') != -1) {
			link.onclick = function(){
				openNewPopup("TalesWindow", this.href);
				return false;
			};
		}
		else
      	if (link.href.indexOf('v3travel.com') != -1 || link.href.indexOf('v3booking') != -1 || link.href.indexOf('rubbertree') != -1) {
			link.onclick = function(){
				openNewPopup("V3Window", this.href);
				return false;
			};
		}
		else
      	if (link.href.indexOf('/golfbooking/') != -1) {
			link.onclick = function(){
				openNewPopup("GolfBookingWindow", this.href);
				return false;
			};
		}
		else
      	if (link.href.indexOf('/bookings/book/') != -1) {
			link.onclick = function(){
				openNewPopup("WalkBookingWindow", this.href);
				return false;
			};
		}
		else
      	if (link.href.indexOf('/resortbooking/') != -1 || link.href.indexOf('/resortbooking/') != -1) {
			link.onclick = function(){
				openNewPopup("HotelBookingWindow", this.href);
				return false;
			};
		}
		else
      	if (link.href.indexOf('popup=1') != -1) {
			link.onclick = function(){
				openNewPopup("InfoPopupWindow", this.href);
				return false;
			};
		}	
		else
      	if (link.href.indexOf('/guestform/') != -1) {
			link.onclick = function(){
				openGuestFormPopup("GuestFormWindow", this.href);
				return false;
			};
		}			
      }
    }

   }
 }

// Join the Collective signup field
function setCollectiveSidebarSignup(){
	if (document.getElementById && document.getElementsByTagName) {
		if (document.getElementById('id_sidebar_collective_email') && document.getElementById('id_sidebar_collective_submit')) {
			var HELP_TEXT = "Enter your email address";
			var email_field = document.getElementById('id_sidebar_collective_email');
			var submit_btn = document.getElementById('id_sidebar_collective_submit');
			var form = document.getElementById('sidebar-quick-signup-form');
			email_field.className = "empty";
			email_field.value = HELP_TEXT;
			email_field.onclick = function() {
				if (email_field.className == "empty") {
					email_field.className = "";
					email_field.value = "";
				}
			};
			email_field.onblur = function() {
				if (email_field.value == "") {
					email_field.className = "empty";
					email_field.value = HELP_TEXT;
				}
			};
			form.onsubmit = function() {
				if (email_field.className == "empty") {
					email_field.className = "";
					email_field.value = "";
				}
			}
		}
	}
}