/*------------------------------------------------------*/
/*                 General functions				    */
/*------------------------------------------------------*/

function general_AddEvent(object, eventName, fn) {
	if (document.addEventListener) object.addEventListener(eventName, fn, false);
	else object.attachEvent('on' + eventName, fn); 
}

function general_GetWindowHeight() {
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetHeight;
	} else {
		return window.innerHeight;
	}
}

function general_GetWindowWidth() {
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		return document.body.offsetWidth;
	} else {
		return window.innerWidth;
	}
}

var datCDate = new Date();
datCDate.setMonth(datCDate.getMonth()+2);

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function AddTagToSelection(tag,id)
{
	var str = document.selection.createRange().text;
	//document.getElementById(id).focus();
	var sel = document.selection.createRange();
	sel.text = "<" + tag + ">" + str + "</" + tag + ">";
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function general_Highlight(v) {
	d = document.getElementById('divContents');
	if(d) {
		s = v.split(' ');
		for(i=0; i<s.length; i++) {
			s[i] = s[i].replace(/_/gi, ' ');
			var r = new RegExp('\\b' + s[i] + '\\b(?!%)','gi');
			//alert('\\b' + s[i] + '\\b');
			d.innerHTML = d.innerHTML.replace(r, '<span class=searchhighlight>' + s[i] + '</span>');
		}
	}
}

function noticePopUp(imgurl, strAlt){

	strAlt = strAlt.replace("(Click for larger)", ""); 

	var newwindow = window.open('enlargeimage.aspx?alt=' + strAlt + '&imgurl=' + imgurl,'newwindow', 'top=0,left=0,height=350,width=350,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no');
	if(!newwindow) {
		alert('Information\n\nThis popup window may have been blocked!  To use this function,\nplease enable popup windows for this web site.\n\nTip: Try holding the "control" key and then clicking the button!');
	}
	

}










