function bookMark(title, url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if ( window.external ) { // IE Favorite
		window.external.AddFavorite(url, title); 
	}
}

function inputClick(id, defval) {
	val = document.getElementById(id).value;
	if (val == defval) {
		document.getElementById(id).value = '';
	}
}

function inputBlur(id, defval) {
	val = document.getElementById(id).value;
	if (val == '') {
		document.getElementById(id).value = defval;
	}
}

function changeTab(tab) {
	if (tab == 'news') {
		$('newsbox').style.display = 'block';
		$('eventsbox').style.display = 'none';
		$('news').addClass('on');
		$('events').removeClass('on');		
	} else {
		$('eventsbox').style.display = 'block';
		$('newsbox').style.display = 'none';
		$('events').addClass('on');
		$('news').removeClass('on');
	}
}

function changePage(url) {
	if (confirm('Please note: If you leave this page you will be logged out of the Customer Zone. Do you want to leave this page?'))	{
		document.location = url;
	}
}

function countryChange() {
	jQuery('#currentcountry a').mouseover(function() {
		if (jQuery('#countrylist').is(':hidden')) {
			jQuery('#countrylist').show();
			jQuery('#currentcountry a').removeClass('plus').addClass('minus');
		} else {
			jQuery('#countrylist').hide();
			jQuery('#currentcountry a').removeClass('minus').addClass('plus');
		}
	});
	jQuery('ul#countrylist').bind('mouseleave',function() {
		jQuery('ul#countrylist').hide();
		jQuery('#currentcountry a').removeClass('minus').addClass('plus');
	});
}


jQuery(document).ready(function(){
																
	countryChange();

	jQuery('#newseventstabs a').click( function () { 
	
		if(jQuery(this).attr('id') == 'news') {
		
			show_news();
		
		} else {
		
			show_events();
		}
	
	});
	
	var tabs = readCookie('fdb-tabs');
	if(tabs){
	
		if(tabs == 'news') {
			show_news();
		} else if(tabs == 'events') {
			show_events();
		} else {
		
		}
		
	}


});

function show_news() {
	jQuery('#newsbox').show();
	jQuery('#eventsbox').hide();
	jQuery('#news').addClass('on');
	jQuery('#events').removeClass('on');
	
	createCookie('fdb-tabs', 'news');
}

function show_events() {
	jQuery('#newsbox').hide();
	jQuery('#eventsbox').show();
	jQuery('#news').removeClass('on');
	jQuery('#events').addClass('on');
	
	createCookie('fdb-tabs', 'events');
}


function changePage(url) {
	/*
	
	disable this completely
	
	if (confirm('Please note: If you leave this page you will be logged out of the Customer Zone. Do you want to leave this page?'))	{
		document.location = url;
	}
	*/
}

jQuery(document).ready(function(){
    	var url = window.location.href;
    	if(url.lastIndexOf('/27/customer-zone') != -1) {
		     /* all clicks on links in the page */
		     jQuery('a').click( function () { 
		    	
		    		if(confirm_unload()) {
		    			return true;
		    		} else {
		    			return false;
		    		}
		     });
		     /* all clicks on links in the page */
		     jQuery('#sbut').click( function () { 
		    		if(confirm_unload()) {
		    			return true;
		    		} else {
		    			return false;
		    		}
		     });
	     }
  });
 
 function confirm_unload() {
 	if(confirm("PLEASE NOTE: You are about to leave the Customer Zone. If you haven't done so already you will be logged out and will have to re-enter your login details again to download your data.")){
					return true;
				} else {
					return false;
				}
 }
 
 // cookie functions http://www.quirksmode.org/js/cookies.html
 
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}