$(document).ready(function(){
	//standard AJAX mail form submission (requires mail2_plus.php, and captcha)
	//add form name to selector for submit event, the rest will take care of itself!
	$("input[type=submit]").removeAttr("disabled");
	$("#sem_signup").submit(function(e){
		e.preventDefault();
		var form = $(this);
		var btn = $(this).find("input[type=submit]");
		btn.attr("disabled","disabled");
		$.post("includes/mail2_plus.php",form.serialize(),function(data){
			var err = data.split("|");
			if (err[0] == "error") {
				alert(err[1]);
				btn.removeAttr("disabled");
			} else {
				//if a redirect is specified, use that. Else replace the form with a message.
				if (form.find("input[name=redirect]").length && form.find("input[name=redirect]").val() != "") {
					window.location = form.find("input[name=redirect]").val();
				} else {
					form.replaceWith("<p class='sent'>Your message has been sent.</p>");
				}
			}
		});
	});
	
	$("#sem_signup input[type=text]").focus(function(){
		val = $(this).val();
		if (val == "Name" || val == "Email" || val == "Telephone" || val == "Copy the code") {
			$(this).val("");
		}
	});
	
	$("#sem_signup input[type=text]").blur(function(){
		name = $(this).attr("name");
		val = $(this).val();
		if (name == "name" && val == "") {
			$(this).val("Name");
		} else if (name == "email" && val == "") {
			$(this).val("Email");
		} else if (name == "phone" && val == "") {
			$(this).val("Telephone");
		} else if (name == "code" && val == "") {
			$(this).val("Copy the code");
		}
	});

	//font resizer
	//anything within #mid with a font size set in em space will be affected
	// Reset Font Size
	var originalFontSize = $('#left').css('font-size');
		//if cookie is set, use that font size.
		if ($.cookie("fsize") != null && $.cookie("fsize") != "") {
		var size = parseFloat($.cookie("fsize"));
		$('#left').css('font-size', size);
		}
		$(".resetFont").click(function(){
		$('#left').css('font-size', originalFontSize);
		$.cookie("fsize", null);
		return false;
	});
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('#left').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		if (newFontSize > 24) {
		  newFontSize = 24;
		}
		$('#left').css('font-size', newFontSize);
		$.cookie("fsize", newFontSize);
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		var currentFontSize = $('#left').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		if (newFontSize < 14) {
		  newFontSize = 14;
		}
		$('#left').css('font-size', newFontSize);
		$.cookie("fsize", newFontSize);
		return false;
	});
	
	//cms bug fix:
	$("input[name=post_date]").val("");
	$("input[name=post_date]").parents("tr").hide();
});
