$(document).ready(function(){
	initRollOvers();
});

function initRollOvers(){
	// Preload all rollovers
	$(".RollOver").each(function() {
		rollsrc = $(this).attr("src");
		var ext = rollsrc.match(/(.{3}$)/)[1];
		rollON = rollsrc.replace('.' + ext, "_over." + ext);
		$("<img>").attr("src", rollON);
	});

	// Setup javascript for rollovers
	$('.RollOver').hover(function(){
		imgsrc = $(this).attr("src");
		var ext = rollsrc.match(/(.{3}$)/)[1];
		matches = imgsrc.match(/_over/);
		if(!matches){
			imgsrcON = imgsrc.replace('.' + ext, "_over." + ext);
			$(this).attr("src", imgsrcON);
		}
	}, function(){
		$(this).attr("src", imgsrc);
	})
}

var win = null;
function popup(pagelink,myname,w,h,scroll) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable=yes';		
  win=window.open(pagelink,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function formatDate(field, base_level){

	// Set url
	if(base_level){
		var url = "content/tools/date.php";
	} else {
		var url = "../../content/tools/date.php";
	}

	// Run ajax query
	$.ajax({
		url: url,
		cache: false,
		data: { value: $('#'+field).val() },
		success: function(results){
			if(results == "invalid"){
				alert('Unknown date format, some acceptable date formats are: 01/02/2000 - Jan 1, 2007 - Today - Yesterday - Next Month - Last Year');
				$('#'+field).val('');
				$('#'+field).focus();
				$('#'+field).select();
			} else {
				$('#'+field).val(results);
			}
		},
		error: function(results){
			alert("Error: The date tool was not found.");
		}
	});
}
