// JavaScript Document
function increase(s)
{
	switch(s){
	  case 0:
	    $("body").css({'font-size':"11px"});
	  break;
	  case 1:
	    $("body").css({'font-size':"120%"});
	  break;
	  case 2:
	    $("body").css({'font-size':"140%"});
	  break;
	}
}

$(document).ready(function(){
	$("#contentContainer").corner("bottom 15px");
	$("#content").corner("bottom 10px");
	
	$("#needHelp").click(function() {
		  $("#dialog-form").dialog("open");
	});

});




	
				

	$(function() {
				
		var name = $("#dialog-form #name"),
			email = $("#dialog-form #email"),
			user_question = $("#dialog-form #user_question"),
			allFields = $([]).add(name).add(email).add(user_question),
			tips = $(".validateTips");

		function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog-form").dialog({
			autoOpen: false,
			height: 360,
			width: 420,
			modal: true,
			buttons: {
				'Submit': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"name",3,16);
					bValid = bValid && checkLength(email,"email",6,80);
					bValid = bValid && checkLength(user_question,"user_question",1,999);

										
					if (bValid) {
						/*  send to email script */						
						$.post("send_email.php", {name:name.val(), email: email.val(), user_question:user_question.val(),subject:'Devonhotels CMS Question'});
						$(this).dialog('close');
						$('#dialog-message').dialog('open');

					}
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});	

		

	});


	$(function() {
		$("#dialog-message").dialog({
			autoOpen: false,
			bgiframe: true,
			modal: true,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	});

/* button states */

$(function(){
		//all hover and click logic for buttons
		$(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
		.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
			}
		});
	});
