﻿// JavaScript Document
var loadingGraphic = '<img src="/assets/images/loading.gif">';

$(document).ready(function() {
	productSearch.clearData();
	emailSubscribe.clearData();
	emailSubscribe.processForm();
	
	$("#homepagePodWrapper div:last").css("margin-right", "0");
	$("#homepageFeatureButtonWrapper a:last").css("margin-right", "0");
	$("#layTopMenu a:last").css("margin-right", "0");
});

productSearch = {
	clearData: function() {
		$("#searchForm input").focus(function() {
			$(this).attr('value','');
		});
		$("#searchForm input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	}
},

emailSubscribe = {
	clearData: function() {
		$("#subscribeForm input").focus(function() {
			$(this).attr('value','');
		});
		$("#subscribeForm input").blur(function() {
			if ($(this).val() == "") {
				$(this).val($(this)[0].defaultValue);
			}
		});		
	},
	processForm: function() {
		$("#subscribeForm form").submit(function(){
			formLabelsAndValues=$("#subscribeForm form").serialize();
			$("#subscribeForm").html(loadingGraphic);
			$.post('/components/subscribe/process.cfm',formLabelsAndValues, function(response) {
				emailSubscribe.formResponse(response);
			});
			return false;
		});	
	},
	formResponse: function(response) {
		$("#subscribeForm").html(response);
		emailSubscribe.processForm();
	}
}