var iState;
	function toggleBox(szDivID, iState) // 1 visible, 0 hidden
	{
	  if(document.layers)  // NN4
	  {
	    document.layers[szDivID].visibility = iState ? "show" : "hide";
	  }
	  else if(document.getElementById) // gecko(NN6) + IE5+
	  {
	    var obj = document.getElementById(szDivID);
	    obj.style.visibility = iState ? "visible" : "hidden";
	  }
	  else if(document.all) //IE 4
	  {
	    document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
	  }

	}
	

		
function contact(user) {
	var domain = "frontporchforum.com";
	var email = window.location = "mailto:"+user+"@"+domain;
	return false;
}

function intro_message(user, fname) {
	var domain = "frontporchforum.com";
	var body = "Hi everyone, I'm "+fname+". This is my first message, and I'm very excited about our neighborhood forum.";
	var email = window.location = "mailto:"+user+"@"+domain+"?subject=Forum Introduction&&Body="+body;
	return false;
}



function toggle(id) {
	if ($(id).style.display == "block") {
		$(id).style.display = "none";
	} else {
		$(id).style.display = "block";
	}
}


function checkAll(field) {
	for (var i = 0; i < field.length; i++) {
		field[i].checked = true ;
	}
}

function uncheckAll(field) {
	for (var i = 0; i < field.length; i++) {
		field[i].checked = false ;
	}
}



function geoLocate() {
	// gets values of the address, city, and state fields
	// passes them to geoLocater (geocoder.us for now)
	
	// yahoo
//	var url="http://api.local.yahoo.com/MapsService/V1/geocode?appid=frontporchforum&";
	
	// geocoder.us
//	var alturl = "http://geocoder.us/service/csv/?";
	
	var aAlert = new Array();
	
	if ($F("lookup_street") == "") {
		aAlert.push("your street address");
		$("lookup_street").style.background = "url('/images/txt_input_bkgd-err.gif')";
		
	} else {
		$("lookup_street").style.background = "url('/images/txt_input_bkgd-req.gif')";		
	}
	if ($F("lookup_city") == "") {
		aAlert.push("your city");
		$("lookup_city").style.background = "url('/images/txt_input_bkgd-err.gif')";
	} else {
		$("lookup_city").style.background = "url('/images/txt_input_bkgd-req.gif')";
		
	}
	if ($F("lookup_state") == "") {
		aAlert.push("your state");
	}
	
	if (aAlert.length != 0) {
		
		var alertString = "Whoops. Please enter ";
		if (aAlert.length > 1) {
			last = aAlert.pop();
			alertString += aAlert.join(", ") + ", and "+last+".";
		} else {
			alertString += aAlert[0]+".";
		}
		
		$("status").style.display = "block";
		$("status").innerHTML = alertString;
	} else {
		
		var alertString = "Searching...";
		
		$("status").style.display = "block";
		$("status").innerHTML = "<img src=\"images/spinner.gif\" style=\"float: right;\"><i>"+alertString+"</i>";
		
		$("lookup_street").style.background = "url('/images/txt_input_bkgd-req.gif')";
		$("lookup_city").style.background = "url('/images/txt_input_bkgd-req.gif')";
	
		if ($F("lookup_street").indexOf("#") != -1) {
			var street = $F("lookup_street").substr(0, $F("lookup_street").indexOf("#"));
		} else {
			var street = $F("lookup_street");
		}

		street = encode(street);
		var city = encode($F("lookup_city"));
		var state = $F("lookup_state");
		
		if (window.location.search != "") {
			var url = window.location.href.substr(0, window.location.href.indexOf("?"));
		} else {
			var url = window.location.href;
		}
		
		if (url.indexOf("/join/") != -1) {
			url += "?street="+street+"&city="+city+"&state="+state;
		} else {
			if (url.indexOf("/userlogin.php") != -1) {
				url = url.substr(0, url.lastIndexOf("/"))+"/";
			}
			url += "join/?street="+street+"&city="+city+"&state="+state;			
		}
		
		window.location.href= url;
	}
	
}







function showHeadlines() {
	
	var t = recentMessages.length;
	if ((t%interval) != 0) {
		t = Math.floor(t/interval);
		t *= interval;
	}
	
	if (t < (start+interval)) {
		var end = t-interval;
	} else {
		var end = start+interval;
	}
	
	document.getElementById("recent").innerHTML = "";
	for (var i = start; i < end; i++) {
		var output = "<div class=\"headline\">"+recentMessages[i][0]+"</div>";
		output += "<div class=\"byline\"> &mdash; "+recentMessages[i][1]+"</div>";
		document.getElementById("recent").innerHTML += output;
	}
	if (end == t) {
		start = 0;
	} else {
		start += interval;
	}
	
	setTimeout("Effect.Fade('recent', {from:1.0, to:0.01, duration: 1.0})", 9000);

}

function makeHeadlineBox() {
	Effect.Appear('recent', {from:0.01, to:1.0, duration: 1.0});
	showHeadlines();
}

function rollHeadlines() {
	setInterval("makeHeadlineBox()", 10000);	
}



function encode(string) {

	var output = string.replace(/ /g, "+");

/*	var output = "";
	for (var i = 0; i < string.length; i++) {
		if (string[i] == " ") {
			output += "+";
		} else {
			output += string[i];
		}
	}
*/	return output;
}


function makeMap(clat, clon, lat, lon, divid, poly, zoom, sat) {
	// centerLat, centerLon, addrLat, addrLon, div ID, poly name, zoom level, bool satellite
	
	if (!sat) {
		sat = 0;
	}

	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(divid));
		map.setCenter(new GLatLng(clat,clon), zoom);
		
		var polyline = new GPolyline(poly, "#FF0000", 2);
		map.addOverlay(polyline);
		
		if ((lat != 0) && (lon != 0)) {
			var marker = new GMarker(new GLatLng(lat, lon));
			map.addOverlay(marker);
		}

		if (polyline.drawElement) {
			polyline.drawElement.className="";
		}


		
		if (zoom < 14) {
			map.addControl(new GSmallMapControl());			
		} else {
			map.addControl(new GLargeMapControl());			
		}
		
		if (sat == 1) {
			map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(2, 2)));
		}
		
	}
}

function smallPop(url) {
	var win = window.open(url, 'smallPop', 'width=450, height=300, location=0, resizable=0, directories=0, menubar=0');

}



function validate(f) {
	
	var aAlert = new Array();
	
	switch(f) {
	
		case "signup":

			if (($F("email") == "") || ($F("email").indexOf("@") === -1) || ($F("email").indexOf(" ") !== -1) || ($F("email").indexOf(".") === -1)){
				aAlert.push("a valid email address");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
			if ( $F("email_confirm") == "" ) {
				aAlert.push("an email verification");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
				$("email_confirm").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";		
				$("email_confirm").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if ($F("password") == "") {
				aAlert.push("a password");
				$("password").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("password").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if ($F("password2") == "") {
				aAlert.push("password verification");
				$("password2").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("password2").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if ($F("firstName") == "") {
				aAlert.push("your first name");
				$("firstName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("firstName").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if (($F("lastName") == "") || ($F("lastName").length < 2)) {
				aAlert.push("your last name");
				$("lastName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("lastName").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
			if ( ($F("email") !== $F("email_confirm")) ) {
				aAlert.push("make sure you entered matching email addresses in the email and verification fields");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
				$("email_confirm").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";		
				$("email_confirm").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
			if (($F("password") == "") || ($F("password2") == "") || ($F("password") !== $F("password2"))) {
				aAlert.push("check that your passwords match and are not blank");
				$("password").style.background = "url('/images/txt_input_bkgd-err.gif')";
				$("password2").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("password").style.background = "url('/images/txt_input_bkgd-req.gif')";		
				$("password2").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
			
	
		break;
		case "waitlist":

			if ($F("firstName") == "") {
				aAlert.push("your first name");
				$("firstName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("firstName").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}

			if (($F("lastName") == "") || ($F("lastName").length < 2)) {
				aAlert.push("your last name");
				$("lastName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("lastName").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}

			if (($F("email") == "") || ($F("email").indexOf("@") === -1) || ($F("email").indexOf(" ") !== -1) || ($F("email").indexOf(".") === -1)){
				aAlert.push("a valid email address");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
		break;
		case "edituser":
		
			if ($F("firstName") == "") {
				aAlert.push("your first name");
				$("firstName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("firstName").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

			if (($F("lastName") == "") || ($F("lastName").length < 2)) {
				aAlert.push("your last name");
				$("lastName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("lastName").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

		break;
		case "editemail":
		
			if (($F("email") == "") || ($F("email").indexOf("@") === -1) || ($F("email").indexOf(" ") !== -1) || ($F("email").indexOf(".") === -1)){
				aAlert.push("a valid email address");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

		break;
		case "change_pass":
			if (($F("current") == "") || ($F("new1") == "") || ($F("new2") == "") || ($F("new1") !== $F("new2"))) {
				aAlert.push("your current password, and a new password in both boxes");
				$("current").style.background = "url('/images/txt_input_bkgd-err.gif')";
				$("new1").style.background = "url('/images/txt_input_bkgd-err.gif')";
				$("new2").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("current").style.background = "url('/images/txt_input_bkgd.gif')";
				$("new1").style.background = "url('/images/txt_input_bkgd.gif')";
				$("new2").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

		break;
		case "addofficial":
			if ($F("title") == "") {
				aAlert.push("your title");
				$("title").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("title").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

			if ($F("jurisdiction") == "") {
				aAlert.push("your jurisdiction");
				$("jurisdiction").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("jurisdiction").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

			if ($F("city") == "") {
				aAlert.push("your city");
				$("city").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("city").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

		break;
		case "addaltemail":
			if (($F("new_alt") == "") || ($F("new_alt").indexOf("@") === -1) || ($F("email").indexOf(" ") !== -1) || ($F("new_alt").indexOf(".") === -1)){
				aAlert.push("a valid email address");
				$("new_alt").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("new_alt").style.background = "url('/images/txt_input_bkgd.gif')";		
			}

		break;
		
		case "adminsignup":
			if (($F("email") == "") || ($F("email").indexOf("@") === -1) || ($F("email").indexOf(" ") !== -1) || ($F("email").indexOf(".") === -1)){
				aAlert.push("a valid email address");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if ($F("password") == "") {
				aAlert.push("a password");
				$("password").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("password").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if ($F("password2") == "") {
				aAlert.push("password verification");
				$("password2").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("password2").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if ($F("firstName") == "") {
				aAlert.push("your first name");
				$("firstName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("firstName").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
	
			if (($F("lastName") == "") || ($F("lastName").length < 2)) {
				aAlert.push("your last name");
				$("lastName").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("lastName").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
			if ($F("address") == "") {
				aAlert.push("your address");
				$("address").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("address").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			

			if ($F("city") == "") {
				aAlert.push("your city");
				$("city").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("city").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}

			if ($F("zip") == "") {
				aAlert.push("your zip");
				$("zip").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("zip").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}

			

			if (($F("password") == "") || ($F("password2") == "") || ($F("password") !== $F("password2"))) {
				aAlert.push("your passwords must match and/or can not be blank");
				$("password").style.background = "url('/images/txt_input_bkgd-err.gif')";
				$("password2").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("password").style.background = "url('/images/txt_input_bkgd-req.gif')";		
				$("password2").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}
			
	
		break;
		
		case "reset_pass":
			if ($F("email") == "") {
				aAlert.push("the email address you use to log into Front Porch Forum");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";				
			}
		break;
		
		case "postMsg":
			
			if ($F("title") == "") {
				aAlert.push("a subject for your messsage");
				$("title").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("title").style.background = "url('/images/txt_input_bkgd-req.gif')";				
			}
			
			if ($F("multiple") == "1") {
				
				var cb = "forum_ids[]";
				var form = "postMsg";
				
				var e = 1;
				
				for (var c = 0; c < document[form][cb].length; c++) {
					if (document[form][cb][c].checked == true) {
						e = 0;
						break;
					} else {
						e = 1;
					}
				}
				
				if (e == 1) {
					// nothing was checked
					aAlert.push("at least one forum to publish your message to");
					$("multi_error").innerHTML = "Error: You must select at least one forum.";
					$("multi_error").style.display = "block";
				} else {
					$("multi_error").style.display = "none";
				}
				
			}
		break;
		
		case "contact":
			if ($F("name") == "") {
				aAlert.push("your name");
				$("name").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("name").style.background = "url('/images/txt_input_bkgd-req.gif')";
			}

			if (($F("email") == "") || ($F("email").indexOf("@") === -1) || ($F("email").indexOf(".") === -1)){
				aAlert.push("a valid email address");
				$("email").style.background = "url('/images/txt_input_bkgd-err.gif')";
			} else {
				$("email").style.background = "url('/images/txt_input_bkgd-req.gif')";		
			}

			if ($F("comments") == "") {
				aAlert.push("a comment");
			}
			
		break;

	}


	if (aAlert.length != 0) {
	
		var alertString = "Whoops. Please enter ";
		if (aAlert.length > 1) {
			last = aAlert.pop();
			alertString += aAlert.join(", ") + ", and "+last+".";
		} else {
			alertString += aAlert[0]+".";
		}
	
		$("f_status").style.display = "block";
		$("f_status").innerHTML = alertString;
		return false;
	} else {
		return true;
	}
	
	
}


function select(form, field, type) {
	// selects all/none of a checkbox set
	
	switch (type) {
		case "none":
			for (var i = 0; i < document[form][field].length; i++) {
				if (document[form][field][i].checked == true) {
					document[form][field][i].checked = false;
				}
			}
		break;
		
		case "all":
			for (var i = 0; i < document[form][field].length; i++) {
					if (document[form][field][i].checked == false) {
						document[form][field][i].checked = true;
					}
				}
		break;

	}
	
}











