String.prototype.equalsIgnoreCase = function(other) {return (this.toUpperCase() == other.toUpperCase());}
String.prototype.startsWith = function(text) {return (this.indexOf(text) == 0);}
String.prototype.contains = function(text) {return (this.indexOf(text) >= 0);}

$(document).ready(function() {
	// change all external #content links to open in new windows
	$("#content").find("a").each(function() {
		var href = $(this).attr("href");
		if(href.startsWith("http://") && !href.contains("pmalu"))
			$(this).attr("target","_blank");
	});
	
	$("a.email").each(function() {
		var thelink = $(this);
		var email = thelink.text().replace(/\[at\]/g,'@').replace(/\[dot\]/g,'.');
		thelink.attr('href','mailto:'+email);
		thelink.text(email);
	});
	
	// enable all date inputs and set them to MYSQL dates
	if($("script[src*='datePicker']").attr("language") == "javascript") {
		Date.firstDayOfWeek = 7;
		Date.format = 'yyyy-mm-dd';
		$("input.date").datePicker({startDate:'2005-01-01'}); //01/01/2005
	}
	
	// hide hidden class elements
	$('.hidden').hide();
	
	// hide the error/success messages after a few seconds
	$('div.goodnews,div.badnews').each(function() {
		var div = $(this);
		if(div) window.setTimeout(function(){div.fadeOut('slow').slideUp('slow');},5000);
	});
});

function askFirst(question,func) {
	if(confirm(question)) {
		return func();
	} return false;
}

function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) +
	((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end == -1) c_end = document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		} 
	} return "";
}