// File: 			contact.js
// Description: 	Add functionality to the contact overlay (contact.html)

function contactFormSubmit(form) {
  form.emailfrom.value=form.email.value;
}
function complete() {
	alert("form submitted");
}

// Setup variables for capcha
var borderColor = ""; /* border color hex or left it null if you don't want to change border color*/
var captchaDir = "/captcha" /* path to captcha files */
var url = captchaDir + "/captcha.php" /* this is name of form action */
var formId = "contactUs" /* id of your form */
var items = Array("pencil", "scissors", "clock", "heart", "note");

// Setup Validate to ignore default value;
// Assumes an astrick in the default
function notDefaultValue(value) {
	return value.search(/\*/) == -1;
}
jQuery.validator.methods.oldRequired = jQuery.validator.methods.required;

jQuery.validator.addMethod("required", function(value, element, param) {
		if (!notDefaultValue(value)) {
				return false;
		}
		return jQuery.validator.methods.oldRequired.call(this, value, element, param);
	},
	jQuery.validator.messages.required // use default message
);

function initContact() {

	// Setup captcha
	$(".ajax-fc-container").captcha();
/*
	$.getScript("/js/jquery.defaultvalue.js", function() {
		$("#firstname, #lastname, #company, #jobtitle, #address, #city, #state, #zip, #country, #phone, #fax, #email, #comments").defaultvalue(
				"* First Name",
				"* Last Name",
				"* Company",
				"Job Title",
				"Address",
				"City",
				"State",
				"ZIP",
				"Country",
				"* Phone",
				"Fax",
				"* Email",
				"Please provide any details that will help us process your inquiry"
			);
	});
*/
	$("fieldset.default select").click(function() {
		$(this).addClass("entered")
	});
	// Setup form validation
	$("#contactUs").validate({
		invalidHandler: function(form, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted.'
					: 'You missed ' + errors + ' fields. They have been highlighted.';
				$("div#contact-error span").html(message);
				$("div#contact-error").show();
			} else {
				$("div#contact-error").hide();
			}
		},
		errorElement: "span"
	});
	
	// Add functionality to the buttons
	$('#content0 .next').click(function() {
		$('#content0').hide();
		$('#content1').show();
		return false;
	});
	$('#content1 .next').click(function() {
		$('#content1').hide();
		$('#content2').show();
		return false;
	});
	$('#content1 .back').click(function() {
		$('#content1').hide();
		$('#content0').show();
		return false;
	});
	$('#content2 .back').click(function() {
		$('#content2').hide();
		$('#content1').show();
		return false;
	});
	$('#content2 .next').click(function() {
		if ($("#contactUs").valid()) {
			$('#content2').hide();
			$('#content3').show();
			$('#content3').queue(function() {
				$(this).show();
				$('#content3 #contact-error').hide();
			});
			return false;
		}
	});
	$('#content3 .back').click(function() {
		$('#content3').hide();
		$('#content2').show();
		return false;
	});
	$('#content3 .next').click(function() {
		return false;
	});
	$('#attach-link > a').click(function() {
		$(this).parent().hide();
		$('#attach-input').queue(function() {
			$(this).show();
			Cufon.replace('#attach-input label');
			$(this).dequeue();
		});
		return false;
	});
	$('#attach-remove').click(function() {
		$(this).parent().hide();
		$('#attach-link').show();
		return false;
	});	
}    


