if (!window.console || !console.firebug)
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}

function SelectAllCheckboxes(spanChk){

 // Added as ASPX uses SPAN for checkbox
 var oItem = spanChk.children;
 var theBox= (spanChk.type=="checkbox") ? 
			spanChk : spanChk.children.item[0];
 xState=theBox.checked;
 elm=theBox.form.elements;

 for(i=0;i<elm.length;i++)
	 if(elm[i].type=="checkbox" && 
						elm[i].id!=theBox.id)
	 {
		 //elm[i].click();
		 if(elm[i].checked!=xState)
			 elm[i].click();
		 //elm[i].checked=xState;
	 }
}

String.prototype.trim = function () {
    return this.replace(/^s*/,'').replace(/s*$/,'').replace("\\t", "");
};

function ProtectEmail(name, address, link, subject, body, aParams) {
    document.write("<a href='ma" + "i" + "lto:" + name + "@" + address + "?subject=" + subject + "&body=" + body + "' " + aParams + ">" + link + "</a>");
}


function preloadStyleSheetBackgrounds() {
	//* only needed in IE
	if (!_b.isIE) {return;}
	
	var styleSheets = document.styleSheets;
	var ruleList;
	var i, j;
	var ImagesArr = new Array();
//	debugger

	for (i = styleSheets.length - 1; i >= 0; i--)
	{
		var styleSheet = styleSheets[i];
		var baseHref = styleSheet.href;
		baseHref = baseHref.substring(0, baseHref.lastIndexOf("/") + 1);
		
		//* this is the difference b/w IE (rules) and Firefox (cssRules)
		ruleList = (styleSheet.rules) ? styleSheet.rules : styleSheet.cssRules;
		for ( j = 0; j < ruleList.length; j++)
		{
			var rule = ruleList[j];
			var imgSrc = rule.style.backgroundImage;
			if (imgSrc != "" && imgSrc != "none")		//* "none" is when "BACKGROUND:" is used and URL is not specified
			{
				imgSrc = imgSrc.replace("url(", "");
				imgSrc = imgSrc.replace(")", "");
				var img = new Image();
				img.src = baseHref + imgSrc;
				ImagesArr[ImagesArr.length] = img;
			}
		}
	}
}
__addEventHandler("onload", preloadStyleSheetBackgrounds);

function convertCsharpGmtDateToJsDate(str)
{
	var date = str
	date = date.replace(/-/g, "/");
	date = date.replace(/Z/g, "");
	date = date.replace("(", "");
	date = date.replace(")", "");
	date = new Date(Date.parse(date));
	date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
	return date;
}
function getDateHtml(baseDate, gmtDate, className)
{
	var friendlyDate = getFriendlyDateDiff(baseDate, gmtDate);
	var str = "<span class='"
	if (isNewerThan(baseDate, gmtDate, 2))
	{
		str += "new ";
	}
	str += className + "' title='" + gmtDate.toLocaleString() + "'>" + friendlyDate + "</span>";
	console.log(str)
	return str;
}
function isNewerThan(baseDate, gmtDate, howManyDays)
{
	var nowDate = new Date((new Date()).toGMTString())
	diff = nowDate - gmtDate;
	
	diff = diff / 86400000  // 1000ms * 60s * 60m * 24h
	return (diff < howManyDays);
}
function getFriendlyDateDiff(baseDate, date)
{
	console.log("baseDate: " + baseDate + ", date: " + date)

	var diff = baseDate - date;
	console.log("diff: " + diff)

	var diffInSeconds = diff / 1000;
	var diffInSecondsR = Math.round(diffInSeconds);
	console.log("diffInSeconds: " + diffInSeconds + " / " + diffInSecondsR)

	var diffInMinutes = diffInSeconds / 60;
	var diffInMinutesR = Math.round(diffInMinutes);
	console.log("diffInMinutes: " + diffInMinutes + " / " + diffInMinutesR)

	var diffInHours = diffInMinutes / 60
	var diffInHoursR = Math.round(diffInHours);
	console.log("diffInHours: " + diffInHours + " / " + diffInHoursR)

	var diffInDays = diffInHours / 24;
	var diffInDaysR = Math.round(diffInDays);
	console.log("diffInDays: " + diffInDays + " / " + diffInDaysR)

	var diffInWeeks = diffInDays / 7
	var diffInWeeksR = Math.round(diffInWeeks);
	console.log("diffInWeeks : " + diffInWeeks + " / " + diffInWeeksR)

	var diffInMonths = diffInWeeks / 4
	var diffInMonthsR = Math.round(diffInMonths);
	console.log("diffInMonths : " + diffInMonths + " / " + diffInMonthsR)

	var diffInYears = diffInMonths / 12
	var diffInYearsR = Math.round(diffInYears);
	console.log("diffInYears : " + diffInYears + " / " + diffInYearsR)

	if (diffInMinutesR < 1)
	{
			return friendlyDateFormatHelper(diffInSeconds, "second");
	} 
	if (diffInHoursR < 1)
	{
			return friendlyDateFormatHelper(diffInMinutesR, "minute");
	} 
	if (diffInDaysR < 1)
	{
			return friendlyDateFormatHelper(diffInHoursR, "hour");
	} 

	if (diffInDaysR === 1)
	{
			return "yesterday";
	}
	if (diffInWeeksR < 2)
	{
			return friendlyDateFormatHelper(diffInDaysR, "day");
	}
	if (diffInMonthsR < 3)
	{
			return friendlyDateFormatHelper(diffInWeeksR, "week");
	}
	if (diffInYearsR < 1)
	{
			return friendlyDateFormatHelper(diffInMonthsR, "month");
	}
	return friendlyDateFormatHelper(diffInYearsR, "year");
}
function friendlyDateFormatHelper(units, unitName)
{
	var str = units + " " + unitName;
	if (units > 1) {str += "s";}
	return str + " ago";
}