String.prototype.multiReplace = function ( hash ) {
	var str = this, key;
	for ( key in hash ) {
		str = str.replace( new RegExp( key, 'g' ), hash[ key ] );
	}
	return str;
};

// if (!Array.indexOf)
// {
	Array.prototype.indexOf=function(obj)
	{
		var result=-1;
		for(var i=0; i<this.length; i++)
		{
			if(this[i]==obj)
			{
				result=i;
				break;
			}
		}
		return result;
	}
// }
if (!Array.remove)
{
	Array.prototype.remove=function(from,to)
	{
		var rest = this.slice((to || from) + 1 || this.length);
		this.length = from < 0 ? this.length + from : from;
		return this.push.apply(this, rest);
	};
}

function getQueryVariable(url,variable)
{
	var query=url.substring((url.search('.php')+5));
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
			return pair[1];
		}
	}
	alert('Query Variable ' + variable + ' not found');
}

function dump(arr,level)
{
	var dumped_text="";
	if (!level) level=0;
	//The padding given at the beginning of the line.
	var level_padding="";
	for (var j=0;j<level+1;j++) level_padding+="    ";
	if (typeof(arr)=='object')
	{ //Array/Hashes/Objects
		for (var item in arr)
		{
			var value=arr[item];
			if (typeof(value)=='object')
			{ //If it is an array,
				dumped_text+=level_padding + "'" + item + "' ...\n";
				dumped_text+=dump(value,level+1);
			}
			else
			{
				dumped_text+=level_padding+"'"+item+"' => \""+value+"\"\n";
			}
		}
	}
	else
	{ //Stings/Chars/Numbers etc.
		dumped_text="===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

$.fn.alertHTML=function(text){
	this.each(function(){
		alert(text+': '+$(this).html());
	});
	return this;
};

$(document).ready(function(){
	var dateInstruct='Click here to select a date';
	$('input.date').attr('autocomplete','off').blur(function(){
		if ($(this).val()=='') $(this).val(dateInstruct);
	}).blur().datePicker({clickInput:true,startDate:'01/01/1970'});
	
	$('a.target').attr('target','_top');
});

