var COOKIE_QL = 'SunnyBrook_QuickLinks';
function quicklink() {
	var ql = $('quicklink');
	if (ql) {
		var t = ql.parentNode.innerHTML.replace(/<(.|\n)+?>/g,'').replace('<','&lt;').replace('>','&gt;');
		var l = document.location.href.replace(/#.*$/,'');
		var c = Cookie.get(COOKIE_QL);
		if (!c) { c = ''; }
		if (c.indexOf(l) > -1) {
			alert('You have already quicklinked this page.');
			return;
		}
		var p = prompt('Would you like to quick link this page?',t);
		if (p) {
			Cookie.set(COOKIE_QL,c + '¦' + l + '#' + p,30);
		}
	}
}

function deleteQuicklink() {
	Cookie.erase(COOKIE_QL);
}

function textSize() {
	var COOKIE_TS = 'SunnyBrook_TextSize';
	/* 62.5% (10px), 75% (12px), 87.5% (14px), 100% (16px) */
	var b = document.body;
	var fs = b.style.fontSize;
	if (fs == '70.5%') {
		fs = '75';
	} else {
		fs = '70.5';
	}
	Cookie.set(COOKIE_TS,fs,30);
	b.style.fontSize = fs + '%';
}

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire + '; path=/');
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') { return navigator.cookieEnabled; }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

