// clear arrest search default values
CheckArrestSearchValues = function()
{
	if($("#ArrestSearchFormLastName").val() == "Inmate Last Name")
	{
		$("#ArrestSearchFormLastName").val("");
	}
	
	if($("#ArrestSearchFormFirstName").val() == "Inmate First Name")
	{
		$("#ArrestSearchFormFirstName").val("");
	}
}

// clear update form default values
CheckUpdateValues = function()
{
	if($("#UpdatesEmailAddress").val() == "Email Address")
	{
		$("#UpdatesEmailAddress").val("");
	}
}

PrintNewsPacket = function(pk, type){
	document.write("<p><a href=\"newspacket.cfm?PK=" + pk + "&amp;sType=" + type + "&amp;printer=1\" rel=\"external\">Print News Packet</a></p>");
}

$(function(){
	
	$("a.removefile").bind("click", function(){
		$(this).parents("div:first").hide().prev("input:hidden").val("");
		return false;
	});
	
	// arrest search form check
	$("#ArrestSearchFormLastName").click(function(){
		$(this).val('');
	});
	
	$("#ArrestSearchFormFirstName").click(function(){
		$(this).val('');
	});	
	
	$("#ArrestSearchForm").submit(function(){
		CheckArrestSearchValues();
		if($("#ArrestSearchFormLastName").val() == "" && $("#ArrestSearchFormFirstName").val() == "")
		{
			alert("Enter an last name and / or first name to search by.");
			$("#ArrestSearchFormLastName").get(0).focus();
			return false;
		}
	});
	
	// update form check
	$("#UpdatesEmailAddress").click(function(){
		$(this).val('');
	});
	
	$("#getupdatesform").submit(function(){
		CheckUpdateValues();
		if($("#UpdatesEmailAddress").val() == "")
		{
			alert("Enter you email address.");
			$("#UpdatesEmailAddress").get(0).focus();
			return false;
		}
	});
	
	// replace flash video on homepage
	$(".sectionheader").corners();
	$(".firerescueshout").corners();
	
	profiles = {

		FireStations: {
			height:550,
			width:550
		},

		MapToPSB: {
			height:450,
			width:450		
		},
		
		Jurisdictions: {
			height:300,
			width:450
		},
		
		JailAddresses: {
			height:450,
			width:400
		},
		
		DistrictMap: {
			height:620,
			width:580	
		},
		
		LocalFireDepartments: {
			height:550,
			width:450,
			scrollbars:1
		}
				
	};	
	
	$("a.popupwindow").popupwindow(profiles);

	$("dl.pcnl dt a").click(function(){
		var a = $(this).parent().parent();
		var b = $(this).children("span");
		a.children("dd").toggle();
		if((a.children("dd:visible")).length != 0)
		{
			b.text("Hide");
		}else
		{
			b.text("View");
		}
		return false;
	});
	
	$("#footer2").append('<p><a href="javascript:PrintThisPage();" title="Print this page"><img src="/_files/layout/printer.gif" alt="Printer friendly page" /> Printer friendly page</a></p>');

});

// popup window
function popup(address, width, height){
	var newwindow;
	var parameters = "toolbar=false,width=" + width + ",height=" + height;

	if(arguments.length == 4){
		//alert(arguments[3]);
		parameters += ", " + arguments[3];
	}

	//alert(parameters);
	//newwindow = window.open(address, "ThisWindow", parameters).focus();
	//newwindow.focus();
	//return false;
	return !window.open(address, "ThisWindow", parameters).focus();
}

function PrintThisPage(){
	var a = document.location.toString();
	//alert(document.location.search.length);
	if(document.location.search.length == 0){
		a += "?printerfriendlypage";
	}else{
		a += "&printerfriendlypage";
	}
	
	window.location.href = a;
	
	return;
}

$(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
});