// JavaScript Document
var displayForm = false;

jQuery(function() {

	jQuery("a[rel]").overlay();

});

jQuery(document).ready(function(){
	var options = { 
    	target: '#message', // target identifies the element(s) to update with the server response 
		clearForm: false,		 // clear all form fields after successful submit
		url: 'process.php',		 // override for form's 'action' attribute  
		success: showResponse	 // post-submit callback 
	}; 

	// show a simple loading indicator
	var loader = jQuery('<div id="loader" style="background-color:#000000;color:#ffffff;padding:10;border: 1px solid #000;z-index: 99;">&nbsp;&nbsp;Processing...<br/><img src="/jquery/images/loader.gif" alt="loading..." /></div>')
		.css({position: "absolute", top: "25em", left: "35em"})
		.appendTo("body")
		.hide();
	jQuery().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});

	jQuery("#txtPhone").mask("(999) 999-9999");

	// add * to required field labels
//	$('label.required').append('&nbsp;<font color="#990000"><b>*</b></font>&nbsp;');

//	jQuery.validator.addMethod("pageRequired", function(value, element) {
//		var $element = jQuery(element)
//		return !this.optional(element);
//	}, jQuery.validator.messages.required)

	var v = jQuery("#contactForm").validate({
		errorClass: "error",
		onkeyup: false,
		onblur: false,
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit(options);
		},
		rules: {
			txtFName: {
				required: true,
				minlength: 2
			},
			txtLName: {
				required: true,
				minlength: 2
			},
			txtPhone: {
				required: true,
				minlength: 10
			},
			txtEmail: {
				required: true,
				email: true
			},
			cboReason: "required",
			txtCaptcha: "required"
		},
		messages: {
			txtFName: {
				required: "** Required<br />",
				minlength: "<br />** Minimum 2 characters"
			},
			txtLName: {
				required: "** Required<br />",
				minlength: "<br />** Minimum 2 characters"
			},
			txtPhone: {
				required: "** Required",
				minlength: "<br />** Invalid Phone Number"
			},
			txtEmail: {
				required: "** Required",
				email: "** Invalid E-Mail"
			},
			cboReason: "** Required",
			txtCaptcha: "** Required"
		}
	});

});

// post-submit callback 
function showResponse(responseText, statusText)  { 
	if (!displayForm) {
		jQuery('#htmlForm').hide();
	}

	jQuery('html,body').animate({scrollTop: 0},'slow');
	document.getElementById('siimage').src = '/captcha/securimage_show.php?sid=' + Math.random();
	jQuery('#message').fadeIn('slow'); 
}
