function Formatter(){
	this.MONTH_NAMES=new Array('January','February','March','April','May','June',
							   	'July','August','September','October','November',
								'December','Jan','Feb','Mar','Apr','May','Jun',
								'Jul','Aug','Sep','Oct','Nov','Dec');
	
	this.DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday',
							 'Thursday','Friday','Saturday','Sun','Mon',
							 'Tue','Wed','Thu','Fri','Sat');
	
	this.LZ = function(x) {
	 	return(x<0||x>9?"":"0")+x
	 }

	this.setStyleById = function(i, p, v) {
		var n = document.getElementById(i);
		n.style[p] = v;
	}
	
	this.setClassById = function(i, v) {
		var n = document.getElementById(i);
		n.className = v;
	}
	
	this.getStyleById = function(i, p) {
		var n = document.getElementById(i);
		var result = n.style[p];
		if(result == 'undefined'){
			result = eval('n.style.'+p+';');
		}
		return result;
	}
	
	this.setStyleByElement = function(inEl, p, v) {
		inEl.style[p] = v;
	}
	
	this.getStyleByElement = function(el, p) {
		return el.style[p];
	}
	
	this.formatDate = function(date, format) {
		format=format+"";
		var result="";
		var i_format=0;
		var c="";
		var token="";
		var y=date.getYear()+"";
		var M=date.getMonth()+1;
		var d=date.getDate();
		var E=date.getDay();
		var H=date.getHours();
		var m=date.getMinutes();
		var s=date.getSeconds();
		var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
		// Convert real date parts into formatted versions
		var value=new Object();
		if (y.length < 4) {y=""+(y-0+1900);}
		value["y"]=""+y;
		value["yyyy"]=y;
		value["yy"]=y.substring(2,4);
		value["M"]=M;
		value["MM"]=this.LZ(M);
		value["MMM"]=this.MONTH_NAMES[M-1];
		value["NNN"]=this.MONTH_NAMES[M+11];
		value["d"]=d;
		value["dd"]=this.LZ(d);
		value["E"]=this.DAY_NAMES[E+7];
		value["EE"]=this.DAY_NAMES[E];
		value["H"]=H;
		value["HH"]=this.LZ(H);
		if (H==0){value["h"]=12;}
		else if (H>12){value["h"]=H-12;}
		else {value["h"]=H;}
		value["hh"]=this.LZ(value["h"]);
		if (H>11){value["K"]=H-12;} else {value["K"]=H;}
		value["k"]=H+1;
		value["KK"]=this.LZ(value["K"]);
		value["kk"]=this.LZ(value["k"]);
		if (H > 11) { value["a"]="PM"; }
		else { value["a"]="AM"; }
		value["m"]=m;
		value["mm"]=this.LZ(m);
		value["s"]=s;
		value["ss"]=this.LZ(s);
		while (i_format < format.length) {
			c=format.charAt(i_format);
			token="";
			while ((format.charAt(i_format)==c) && (i_format < format.length)) {
				token += format.charAt(i_format++);
				}
			if (value[token] != null) { result=result + value[token]; }
			else { result=result + token; }
			}
		return result;
	}

}
var hj_formatter = new Formatter();

function Utilities(){
	this.appName = 'Husker Junction';
	this.appHomepage = 'index.php';
	
	this.getConsistentDomainName = function(){
		var dName = document.domain;
		
		if(dName.indexOf('www') == -1){
			dName = 'www.' + dName;
		}
		
		return dName;
	}
	
	this.setHtmlById = function(htmlId, htmlText){
		document.getElementById(htmlId).innerHTML = htmlText;
	}
	
	this.getHtmlById = function(htmlId){
		return document.getElementById(htmlId).innerHTML;
	}
	
	this.popUpUrl = function(URL, width, height) {
		try{
			var day = new Date();
			var id = day.getTime();
			var evalString = '\"page\" + id + "\ = window.open(';
			evalString += 'URL, \'" + id + "\', \'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,';
			evalString += 'resizable=0,width=800,height=700,left = 340,top = 312\');"';											
			
			eval(evalString);
		}
		catch(e){
			
		}
	}
	
	this.escapeHtml = function(str) {
		str = str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/‘/g, '&#8216;').replace(/’/g, '&#8217;');
		str = str.replace(/…/g, '&#8230;').replace(/—/g, '&#8212;').replace(/“/g, '&quot;').replace(/”/g, '&quot;');
		return str;
	}
	
	this.isHomepage = function(){
		if(window.location.pathname == '/'){
			return true;
		}
		else {
			return false;
		}
	}
	
	this.toggleDivDisplayById = function(inDivId){
		var displayStyle = hj_formatter.getStyleById(inDivId, 'display');
		if(displayStyle == 'none'){
			hj_formatter.setStyleById(inDivId, 'display', 'none');
		}
		else{
			hj_formatter.setStyleById(inDivId, 'display', 'block');
		}
	}
	
	this.showElement = function(inElId){
		var el = document.getElementById(inElId);
		alert(el.style.display);
		el.style.display = 'block';
	}
	
	this.getRandomNum = function(maxNumbers) {
		return Math.floor(Math.random()*(maxNumbers));
	}
	
	this.changeImgSrc = function(imgId, imgSrc){
		var imgEl = document.getElementById(imgId);
		if(imgEl != null){
			imgEl.src = imgSrc;
		}
	}
	
	this.changeHrefLink = function(linkId, newlinkSrc){
		var hrefEl = document.getElementById(linkId);
		if(hrefEl != null){
			hrefEl.href = newlinkSrc;
		}
	}
	
	this.hasSwearing = function(inStr){
		var swearString = 'fuck, shit, goddamn, god damn, god dam, goddam, goddammit, god dammit';
		var swearString = swearString.toUpperCase();
		var swearPhrase = swearString.split(', ');
		
		for(i=0; i<swearPhrase.length; i++){
			var evalWord = swearPhrase[i];
			if(inStr.toUpperCase().indexOf(evalWord.toUpperCase()) > -1){
				return true;	
			}
		}
		return false;
	}
	
	this.calcDaysAgo = function(rfc822Date){
		var dt = new Date(rfc822Date);
		var milliSecsInADay = 86400000;
		var milliSecsInHour = 3600000;
		var milliSecsInMinute = 60000;
		var secsDif = new Date().getTime() - dt.getTime();
		var days = Math.floor(secsDif/milliSecsInADay);
		var hours = Math.floor(secsDif/milliSecsInHour);
		var minutes = Math.floor((secsDif%milliSecsInHour)/milliSecsInMinute);

		var output = minutes + ' minutes ago' ;
		if(hours > 0){
			output = hours + ' hours ' + output;
		}
		if(days > 0){
			output = days + ' days ' + output;
		}
		
		return output;
	}
}
var hj_utils = new Utilities();

function Cookies(){
	
	this.getCookie = function(name) {
		var start = document.cookie.indexOf(name + "=");
		var len = start + name.length + 1;
		if ((!start) && (name != document.cookie.substring(0, name.length))){
			return null;
		}
		if(start == -1) return null;
		
		var end = document.cookie.indexOf(";", len);
		if(end == -1) end = document.cookie.length;
		
		return unescape(document.cookie.substring(len, end));
	}
	
	this.hasCookie = function(name){
		if(this.getCookie(name)  != null){
			return true;
		}
		else {
			return false;
		}
	}
	
	this.setBasicCookie = function(cookieString){
		 document.cookie = cookieString;
	}
	
	this.setCookie = function(name, value){
		 var d = new Date();
		 d.setYear(d.getYear() + 1901);
		 var cd = d.toGMTString();
		 //alert(hj_utils.getConsistentDomainName());
		 var c = name + '=' + value + ';expires=' + cd + ';path=/;domainname='+hj_utils.getConsistentDomainName();
		 this.setBasicCookie(c);
	}
	
	this.appendCookie = function(name, value){
		 var d = new Date();
		 d.setYear(d.getYear() + 1901);
		 var cd = d.toGMTString();
		 var c = name + '=' + value + ';expires=' + cd + ';path=/;domainname='+hj_utils.getConsistentDomainName();
		 this.setBasicCookie(c);
	}
	
	this.setCookieWithDate = function(name, value, date){
		 var c = name + '=' + value + ';expires=' + date + ';path=/;domainname='+hj_utils.getConsistentDomainName();
		 this.setBasicCookie(c);
	}
	
	this.deleteCookie = function(cookieName){
		var cookieDate = new Date();
		cookieDate.setTime(cookieDate.getTime() - 1);
		this.setCookieWithDate(cookieName, '', cookieDate.toGMTString());
	}
}

var hj_cookies = new Cookies();

function HtmlSnips(){
	this.miscategorizedSelectBox = '<select id></select>';
	
	this.makeImgHtml = function(imgUrl, inAlt, inWidth, inHeight, href, inOnclick){
		if(inAlt == null){
			inAlt = '';
		}
		else{
			inAlt = ' alt=\"'+inAlt+'\"';
		}
		if(inWidth == null){
			inWidth = '';
		}
		else{
			inWidth = ' width=\"'+inWidth+'\"';
		}
		if(inHeight == null){
			inHeight = '';
		}
		else{
			inHeight = ' height=\"'+inHeight+'\"';
		}
		if(inOnclick == null){
			inOnclick = '';
		}
		else{
			inOnclick = ' onclick=\"'+inOnclick+'\"';
		}
		var imgCode = '<img src=\"'+imgUrl+'\"' + inAlt + inWidth + inHeight + inOnclick + ' border=\"0\" />';
		
		if(href != null){
			imgCode = '<a href=\"'+href+'\">'+imgCode+'</a>';
		}
		return imgCode;
	}
}
var hj_html = new HtmlSnips();

function Ajax(useCacheAvoidance){
	
	this.ajaxHtml;
	
	this.getAjaxHtml = function(fileToGet, methodNameCallBack, arg1, arg2, showLoading){
		
		try{
			if (window.ActiveXObject){
				ajaxHtml = new ActiveXObject("Microsoft.XMLHTTP");
			}
			else if (window.XMLHttpRequest){
				ajaxHtml = new XMLHttpRequest();
			}
			else{
				//alert("not supported");
			}
			
			if (!YAHOO.example.container.wait  && showLoading) {
				YAHOO.example.container.wait = new YuiFactory().getLoadingWidget().loadingWidget;
	
				YAHOO.example.container.wait.setHeader(loadingMessage);
				YAHOO.example.container.wait.setBody("<img src=\"/images/_loading_interstitial.gif\"/>");
				YAHOO.example.container.wait.render(document.body);
				YAHOO.example.container.wait.show();
			}

			if(useCacheAvoidance){
				fileToGet += '?'+new Date().getTime();
			}
			ajaxHtml.open("GET", fileToGet);
			ajaxHtml.setRequestHeader("Cache-Control", "no-cache");
			ajaxHtml.setRequestHeader("Pragma", "no-cache");
			ajaxHtml.onreadystatechange = function() {
				if (ajaxHtml.readyState == 4){
					if (ajaxHtml.status == 200) {
						if (ajaxHtml.responseText != null){
							if(arg1 == null){
								eval(methodNameCallBack+'(ajaxHtml.responseText)');
							}
							else if(arg2 == null){
								eval(methodNameCallBack+'(ajaxHtml.responseText, arg1)');
							}
							else{
								eval(methodNameCallBack+'(ajaxHtml.responseText, arg1, arg2)');	
							}
						}
						else{
							location.replace(errUrl+'?err='+escape('Failed to receive RSS file from the server - file not found.'));
							return false;
						}
					}
					else{
						throw('Ajax status code: ' + ajaxHtml.status);
					}
				}
			}
		
			ajaxHtml.send(null);
		}
		catch(e){
			alert('Something went wrong with the request: ' + e);
		}
	}
}
var hj_ajaxNoCache = new Ajax(true);
var hj_ajax = new Ajax(false);

function Error(){
	
	this.sendError = function(inErrDetails, methodName, exceptionDetails){
		var emailPage = '/includes/email.php';
		var alertParam = '?alert=hjerror';
		var methodParam = '&method='+methodName;
		var exceptionParam = '&exception='+exceptionDetails;
		var dataParam = '&indata='+inErrDetails;
		var urlStr = emailPage+alertParam+exceptionParam+methodParam+dataParam;
		setAlert('Logging Error...', null, false);
		hj_ajax.getAjaxHtml(urlStr, 'setAlert', '', false);
	}
}
var hj_error = new Error();