﻿
// Not all browsers allow scripted bookmarking so change the "Bookmark site" link if necessary:
// To do: Turn this around to use progressive enhancement!
if(window.jQuery){

	jQuery(function($){

		try{
			if(		( window.external && (typeof (window.external.AddFavorite) == 'unknown' || window.external.AddFavorite) )
				||	( window.sidebar && window.sidebar.addPanel ) ){
				// Do nothing. IE and FF allow add-bookmark to be scripted.
			}else{
				// For other browsers, change the link's caption and behaviour.
				downgradeBookmarkLink();
			};
		}catch(e){
			// Unhandled exception so assume the worst and downgrade the link's caption and behaviour.
			downgradeBookmarkLink();
		}

		function downgradeBookmarkLink(){
			// For non IE/FF browsers, change the link's caption and behaviour.
			$('#breadcrumbTools A')
				.attr({ href: "javascript:alert('Click OK then CTRL+D to bookmark this site');" })
				.children("SPAN").text("Press CTRL+D to bookmark this site")
		}

	});
};

function addToFavourites(theName, theUrl) {

	// Note we cannot test for (window.external && window.external.AddFavorite) because it errors in IE:
    if (window.external && (typeof (window.external.AddFavorite) == 'unknown' || window.external.AddFavorite) ){
        // IE:
        window.external.AddFavorite(theUrl, theName);
    } else if (window.sidebar && window.sidebar.addPanel) {
        // FF:
        window.sidebar.addPanel(theName, theUrl, "");
    } else {
		// Some older browsers:
		try{
			var elem = document.createElement('a');
			elem.setAttribute('href',theUrl);
			elem.setAttribute('title',theName);
			elem.setAttribute('rel','sidebar');
			elem.click();
		}catch(e){};    
    }
}


var helpWindow = null;

function closeWin() {
    if (helpWindow != null) {
        if (!helpWindow.closed)
            helpWindow.close();
    }
}

function popUpWin(url, features, width, height) {
    closeWin();

    features = features + ",width=" + width + ",height=" + height;
    helpWindow = window.open(url, 'helpText', features);
    helpWindow.focus();
}

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);
}
