$(function(){
	$("#submit").click(function(){
		var err = "";
		if ($("#name").val() == "")
			err += "A name is required!\n";
//		if ($("#lname").val() == "")
//			err += "A last name is required!\n";
//		if ($("#email").val() == "")
//			err += "An email address is required!\n";
		if ($("#ph_1").val() == "" || $("#ph_2").val() == "" || $("#ph_3").val() == "")
			err += "A 10-digit phone number is required!\n";
		if ($("#subject").val() == "")
			err += "A subject is required!\n";
		if ($("#purchased").val() == 0)
			err += "Have you purchased the system already?\n";
		if (err == "") {
			var data = {};
			$("#frm_contact :input").each(function() {
				data[this.id] = this.value;
				this.setAttribute("disabled", "disabled");
			});
			$.post("/contact/submit",{data: JSON.stringify(data)}, function(retData){
				$('#frm_contact').html(retData);
			});
		}
		else {
			alert(err);
		}
	});
	
/*	$("#date").datepicker({
		minDate: 0,
		speed: "",
//		showAnim: "fadeIn",
		changeMonth: false,
		changeYear: false,
		dateFormat: "D, M d, yy",
//		dateFormat: "yy-m-d",
	    beforeShowDay: $.datepicker.noWeekends,
	    showOn: "both",
	    buttonImage: "images/calendar.gif",
	    buttonImageOnly: true,
		closeAtTop: false,
		mandatory: true,
		showCurrent: false,
		hideControls: true,
		inlinePrevNext: true
	});*/
	
//	$('#ph_1').autotab({ target: 'ph_2', format: 'numeric' });
//	$('#ph_2').autotab({ target: 'ph_3', format: 'numeric', previous: 'ph_1' });
//	$('#ph_3').autotab({ target: 'ph_x', format: 'numeric', previous: 'ph_2' });
//	$('#ph_x').autotab({ format: 'numeric', previous: 'ph_3' });
//	$("#date").date_input();
	
	$("#date").each(function(){
		this.DateChooser = new DateChooser();
		$(this).click(function(e) {
			this.DateChooser.display(e);
		})
	});

/*
	Date.firstDayOfWeek = 7;
	Date.format = 'mm-dd-yyyy';
	$('#date').datePicker({
		createButton: false,
		renderCallback: function($td, thisDate, month, year) {
			if (thisDate.isWeekend()) {
				$td.addClass('weekend');
				$td.addClass('disabled');
			}
		}
	}).bind('focus', function() {
		$(this).dpDisplay();
//		this.blur();
		return false;
	});/*.blur(function() {
		$(this).dpClose();
	})/*.bind('dpClosed', function() {
//		this.focus();
//		return false;
	});/*.bind('dateSelected', function(e, selectedDate, $td) {
		console.log('You selected ' + selectedDate);
	});*/
/*
	$("#time_from, #time_to").clockpick({
		starthour: 8,
		endhour: 18,
		showminutes: true,
		minutedivisions: 4,
		military: false,
		event: 	'click focus',
		layout:	'vertical',
		valuefield: null,
		useBgiframe: false,
		hoursopacity: 1,
		minutesopacity: 1
	}, null);
*/
});