/*
 * (c) 2009 Mellowtown, All Rights Reserved
 * $Id: common.js,v 1.4 2009/07/09 02:24:04 tredman Exp $
 */

function validateStoryForm()
{
	var subname = $("subname");
	var email = $("email");
	var zip = $("zip");
	var resolution = $("resolution");
	if (subname.value == "first name" || subname.value == "") {
		alert("You must fill in a first name in order to submit this form.");
		subname.focus();
		return false;
	}
	if (email.value == "email" || email.value == "") {
		alert("You must fill in your E-mail address.  Please refer to our privacy policy to see how we use this information.");
		email.focus();
		return false;
	}
	if (zip.value == "zip code" || zip.value == "") {
		alert("You must fill in your ZIP or postal code.  Please refer to our privacy policy to see how we use this information.");
		zip.focus();
		return false;
	}
	if (resolution.value == "your resolution..." || resolution.value == "") {
		alert("Please let us know what your Motion Resolution is for 2009.");
		resolution.focus();
		return false;
	}
	return true;
}

function resetResolution(mode)
{
	var resolution = $("resolution");
	if (resolution.value == "" && !mode) {
		resolution.update("your resolution...");
	} else if (mode) {
		if (resolution.value == "your resolution...") resolution.update("");
	}
}

function validateChgPwd()
{
	var pwd1 = $("password1");
	var pwd2 = $("password2");
	if (pwd1.value == "" || pwd2.value == "") {
		alert("Please complete both fields to confirm password.");
		return false;
	}
	if (pwd1.value != pwd2.value) {
		alert("Both entries must match to change password.");
		return false;
	}
	return true;
}

function validateAddUser()
{
	var adminName = $("admin-name");
	var adminEmail = $("admin-email");
	if (adminName.value == "") {
		alert("Please provide the administrator's name in the box provided.");
		return false;
	} else if (adminEmail.value == "") {
		alert("Please provide the administrator's E-mail address in the box provided.");
		return false;
	} else if (!validateChgPwd()) {
		return false;
	} else {
		return true;
	}
}

function showMore(sid)
{
	$("story-"+sid).className = "story-byline-waiting";
	new Ajax.Updater($("story-"+sid), "ajax/ss_showmore.php", { parameters: { id: sid }, asynchronous: false });
	$("story-"+sid).className = "story-byline";
}

function showLess(sid)
{
	$("story-"+sid).className = "story-byline-waiting";
	new Ajax.Updater($("story-"+sid), "ajax/ss_showless.php", { parameters: { id: sid }, asynchronous: false });
	$("story-"+sid).className = "story-byline";
}

function deleteStory(sid)
{
	if (confirm("This will permanently delete the resolution story.  Are you sure you want to do this?")) {
		document.location = "stories.php?d="+parseInt(sid);
	}
}
