// Steve, Nov 7th 2008
// 11th feb 2009, add function findPos
// 25th Feb 2009, add cookie functions for bscal and cddoc
// 10 March 2009, change setcookie expiry to default 14 days unless specified
//                add path ('\') to set cookie
function trim(s1) { return s1.replace(/^\s+|\s+$/g,""); }
function isEmpty(s1) { return (s1 == null || trim(s1) == ""); }
function findPos(obj) {
	var x = 0;
	var y = 0;
	if (obj.offsetParent) {
		do {
			x += obj.offsetLeft;
			y += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [x, y];
}

function getCookie(pfx, name, def) {
	// always prefix the cookie names otherwise the joomla jrequest getvar might pick them up in preference to post / get vars
	var dc = document.cookie;
  	var pfx = pfx + 'cook' + name + "=";
  	var begin = dc.indexOf("; " + pfx);
  	if (begin == -1) {
    	begin = dc.indexOf(pfx);
    	if (begin != 0) return def;
 	} else
    	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
    	end = dc.length;
	return unescape(dc.substring(begin + pfx.length, end));
}

function setCookie(pfx, name, val,exp) {
   if (exp == null)
      exp = (1000*60*60*24) * 14;
	var d1 = new Date();
	var n1 = d1.getTime() + (exp);
	d1.setTime(n1);
	// always prefix the cookie names otherwise the joomla jrequest getvar might pick them up in preference to post / get vars
	var s1 = pfx + 'cook' + name + "=" + escape(val) +
	   '; expires=' + d1.toGMTString() + '; path=/';
	document.cookie = s1;
}


// end of file
