/**** Hideme ****/

$(document).ready(function() {
	// Input default fx
	//$('input.hideme').addClass("idleField");
	$('input.hideme').focus(function() {
		//$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input.hideme').blur(function() {
		//$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
});


/**** Jump Menu ****/

$(document).ready(function() {
	$('select.jumpmenu').change(function() {
		var jump_url;
		jump_url = $(this).val(); 
		if (jump_url != "") {
			document.location.href = jump_url;
		}
	});
});


/**** Subscribe Now ****/

$(document).ready(function(){
	$("#emaillist_submit").click(function(){		//Submit Button ID	
		
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var emailVal = $("#emaillist_email").val(); //field ID + Validation
		if(emailVal == '') {
			$("#emaillist_msg").css('color','red');
			$("#emaillist_msg").html('Please enter a valid email address above.');
			hasError = true;
		} else if(!emailReg.test(emailVal)) {
			$("#emaillist_msg").css('color','red');
			$("#emaillist_msg").html('Please enter a valid email address above.');
			hasError = true;
		}		
		
		if(hasError == false) {
			$(this).hide();
			
			var formaction = $("#emaillist_form").attr('action');
			var regex = new RegExp("[^0-9]*");
			formaction = formaction.replace(regex,"");
			formaction = 'script/submitform.asp?formid=' + formaction;
			
			$("#emaillist_email").after('<img src="images/loading.gif" alt="" width="16" height="16" id="loading" style="margin:2px 0px 0px 3px;"/>');
			$("#emaillist_msg").css('color','#999');
			$("#emaillist_msg").html('Processing your submission ...');
			
			$.post(formaction,
				$("#emaillist_form").serialize(),
   				function(data){
					alert(data);
					alert(formaction);
					$("#emaillist_form").fadeTo('fast',0);
					$("#emaillist_form").html('<span class="emailtxt">Thanks for your submission. You have now successfully subscribed to our email list.</span>')
					$("#emaillist_form").show().fadeTo('slow',1);
				}
			 );
		}
		
		return false;
	});						   
});
