var DIA = {};

DIA.contactUs = {
	init: function() {
		this.bindEvents();
		
	},
	bindEvents: function() {
		
		$("#element_10_1").click(function() {
			$("#li_11").hide();
			$("#tube-benders").hide();
			$("#tube-cutting").hide();
			
			$("#li_11 select").attr("disabled", "disabled");
			$("#tube-benders select").attr("disabled", "disabled");
			$("#tube-cutting select").attr("disabled", "disabled");			
			
		});
		
		$("#element_10_2").click(function() {
			$("#li_11").hide();
			$("#tube-cutting").hide();
			$("#tube-benders").show();
			
			$("#li_11 select").attr("disabled", "disabled");
			$("#tube-cutting select").attr("disabled", "disabled");
			$("#tube-benders select").removeAttr("disabled");
			
		});
		
		$("#element_10_4").click(function() {
			$("#li_11").hide();
			$("#tube-benders").hide();
			$("#tube-cutting").show();
			
			$("#li_11 select").attr("disabled", "disabled");
			$("#tube-benders select").attr("disabled", "disabled");
			$("#tube-cutting select").removeAttr("disabled");
		});
		
		
		
		$("#element_10_3").click(function() {
			$("#li_11").show();
			$("#tube-benders").hide();
			$("#tube-cutting").hide();
			
			$("#tube-benders select").attr("disabled", "disabled");
			$("#tube-cutting select").attr("disabled", "disabled");
			$("#li_11 select").removeAttr("disabled");
		});
		
	    $("#contact-us-form").find(':input').each(function() {
	        switch(this.type) {
	            case 'password':
	            case 'select-multiple':
	            case 'select-one':
	            case 'text':
	            case 'textarea':
	                $(this).val('');
	                break;
	            case 'checkbox':
	            case 'radio':
	                this.checked = false;
	        }
	    });
	
		$("#submit-code").val(this.randomString());
		
		// Place ID's of all required fields here.
		required = ["element_1", "element_2","element_4","element_5_1","element_5_2","element_5_3"];
		// If using an ID other than #email or #error then replace it here
		email = $("#element_4");
		errornotice = $("#error");
		// The text to show up within a field when it is incorrect
		emptyerror = "";
		emailerror = "";

		
		$("#contact-us-form").submit(function(){	
			//Validate required fields
			for (i=0;i<required.length;i++) {
				var input = $('#'+required[i]);
				if ((input.val() == "") || (input.val() == emptyerror)) {
					input.addClass("needsfilled");
					input.val(emptyerror);
					errornotice.fadeIn("fast");
				} else {
					input.removeClass("needsfilled");
				}
			}
			// Validate the e-mail.
			if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
				email.addClass("needsfilled");
				email.val(emailerror);
			}

			//if any inputs on the page have the class 'needsfilled' the form will not submit
			if ($(":input").hasClass("needsfilled")) {
				return false;
			} else {
				errornotice.hide();
				return true;
			}
		});

		// Clears any fields in the form when the user clicks on them
		$(":input").focus(function(){		
		   if ($(this).hasClass("needsfilled") ) {
				$(this).val("");
				$(this).removeClass("needsfilled");
		   }
		});
		
	},
	randomString: function() {
	   var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');

	    if (! length) {
	        length = Math.floor(Math.random() * chars.length);
	    }

	    var str = '';
	    for (var i = 0; i < length; i++) {
	        str += chars[Math.floor(Math.random() * chars.length)];
	    }
	    return str;
	}
	
}


$(document).ready(function() {
   DIA.contactUs.init();
});



