// JavaScript Document

ContactUs = {
	
	initialize: function(){
		
		$(document).ready( function(){
									
			//preload for button hover images
			$("#contactUsHolder input[type=image]").each(function(){
				$("<img />").attr("src", $(this).attr("src").replace(".gif","_hover.gif") );
			});

			//set the hover for buttons
			$("#contactUsHolder input[type=image]").hover(
				function(){
					if ( $(this).attr("src").indexOf("_hover") == -1 )
						$(this).attr("src", $(this).attr("src").replace(".gif","_hover.gif") )
				},
				function(){
					if ( $(this).attr("src").indexOf("_hover") > -1 )
						$(this).attr("src", $(this).attr("src").replace("_hover.gif",".gif") )
				}
			);
			
			$("#contactForm").submit(function(){
				return ContactUs.validateForm();
			});

        });
		
	},
	
	validateForm: function(){
		
		var valErr = $("#validationErrors").html("");
		
		//make sure they completed all fields --> .validationFieldFalied
		var incompleteFound = 0;				
		$("#contactForm .formRow input[type=text], #contactForm .formRow textarea").each(function(){
			if (  $(this).attr("name") != "Company" ){
				if ( $.trim( $(this).val() ).length == 0 ){
					$(this).addClass("validationFieldFalied");	
					incompleteFound += 1;
				}
				else
					$(this).removeClass("validationFieldFalied");	
			}
		});
		if ( incompleteFound ){
			valErr.append("<p>There are required fields incomplete<p>");
		}
		
		return valErr.html().length == 0;
		
	}	
	
} 

ContactUs.initialize();

