function getParameter(name) {
	var url = window.location.href;
	var paramsStart = url.indexOf("?");

	if(paramsStart != -1){

		var paramString = url.substr(paramsStart + 1);
		var tokenStart = paramString.indexOf(name);

		if(tokenStart != -1){

			paramToEnd = paramString.substr(tokenStart + name.length + 1);
			var delimiterPos = paramToEnd.indexOf("&");

			if(delimiterPos == -1){
				return unescape(paramToEnd);
			}
			else {
				return unescape(paramToEnd.substr(0, delimiterPos));
			}
		}
	}
}

function showPage(name, url, height, width) {
	if(height == undefined || height <= 0)
		height = 200;
	if(width == undefined || width <= 0)
		width = 300;
	tb_show(name, url + "?height=" + height + "&width=" + width);
	return;
}

function closePage() {
	self.parent.tb_remove();
	return;
}

function showMap(name, address)
{
	tb_show(name, "map.html?name=" + escape(name) + "&address=" + escape(address) + "&TB_iframe&height=475&width=375", false);
	return;
}

$(function() {
	/*if($("div#program_listing").length > 0)
	{
		$("div#program_listing").cycle({
			fx : "fade",
			timeout : 5000,
			speed : 650,
			pause : 1,
			random : 1
		});
	}*/

	if($("p#subscribe").length > 0) {
		$("p#subscribe").html("<input type=\"button\" value=\"Subscribe\" />");
		$("p#subscribe input").click(function(){
//			window.location = "./subscribe_newsletter.html";
			window.location = 'mailto:info@teenfamilycounseling.org?subject=Newsletter Subscription&body=First Name: %0d%0aLast Name: %0d%0aAddress: %0d%0aCity: %0d%0aState: %0d%0aZip Code: %0d%0aHome Phone: %0d%0aCellular Phone: %0d%0aSpecial Interest(s): %0d%0aWork Affiliation: ';
		});
	}

	if($("input#email").length > 0) {
		$("input#email").focus();
	}
	
	if($("h3#donate_button").length > 0)
	{
		$("h3#donate_button").html("<input type=\"button\" id=\"donate_button\" value=\"DONATE NOW!\" onclick=\"window.location='donate.html'\" />");
	}

	/*if($("div#map").length > 0)
	{
		$("div#map").jmap({
			mapEnableDoubleClickZoom: true,
			mapEnableScrollZoom: true,
			mapCenter: [37.28708,-121.943564],
			mapZoom: 17,
			mapType: "hybrid"
		}).addMarker({
			pointLat: 37.28708,
			pointLng: -121.943564
		});
		$("div#map").createMarkerManager();
		$("div#map").createGeoCache();
	}
	
	if($("input#findDirections").length > 0)
	{
		$("input#findDirections").click(function(){
			if($("input#fromAddress").val() != "")
				$("div#map").searchAddress({
					fromAddress: $("input#fromAddress").val(),
					toAddress: "307 Orchard City Dr, Campbell, CA 95008",
					cache: $.jmap.GGeoCache
				});
			return;
		});
	}*/
	
	if($("div#location").length > 0)
		$("div#location").html(getParameter("name") + "<br/>" + getParameter("address"));

	if($("div#map").length > 0)
	{
		$("div#map").jmap({
			mapEnableDoubleClickZoom: true,
			mapEnableScrollZoom: true,
			mapZoom: 17,
			mapType: "hybrid",
			mapShowOverview : false,
			mapEnableGoogleBar : false,
			mapCenter: [37.287336,-121.943114]
		}).searchAddress({
			address : getParameter("address")
		});
		
		//$("div#map").createMarkerManager();
		//$("div#map").createGeoCache();
		
		if($("input#findDirections").length > 0)
		{
			$("input#findDirections").click(function(){
				if($("input#fromAddress").val() != "") {
					try {
						$("div#map").searchDirections({
							fromAddress: $("input#fromAddress").val(),
							/*toAddress: "307 Orchard City Dr, Campbell, CA 95008",*/
							toAddress: getParameter("address"),
							cache: $.jmap.GGeoCache
						});
					} catch(error) {
						alert(error);
					}
				}
				return;
			});
		}
	}
	
	return;
});

