jQuery(document).ready(function(){  
/*
 * 		Contact Form Validation
 */

	jQuery('#contactform').submit(function() {
	
		// Disable the submit button
		jQuery('#contactform input[type=submit]')
			.attr('value', 'Sending Information')
			.attr('disabled', 'disabled');
	
		// AJAX POST request
		jQuery.post(
			jQuery(this).attr('action'),
			{
				name:jQuery('#name').val(),
				email:jQuery('#email').val(),
				message:jQuery('#message').val(),
				title:jQuery('#title').val(),
				company:jQuery('#company').val(),
				address:jQuery('#address').val(),
				city:jQuery('#city').val(),
				state:jQuery('#state').val(),
				zip:jQuery('#zip').val(),
				referred:jQuery('#referred').val(),
				phone:jQuery('#phone').val(),
				
				c_email:jQuery('#c_email').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					jQuery('#contactform')
						.hide()
						.html('<h3 style="position:relative;margin:5px 0 0 0;">Thank you</h3><p>Your message has been sent.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					jQuery('#contactform input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'Submit Information');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					jQuery('#contactform .errorbox').html('<ul></ul>').show();
					jQuery('#contactform li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							jQuery('#' + field).parent('li').addClass('alert');
							jQuery('#contactform .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return false;
	});
	
	/*
 * 		Newsletter Form Validation
 */

	jQuery('#contactformn').submit(function() {
	
		// Disable the submit button
		jQuery('#contactformn input[type=submit]')
			.attr('value', 'Submitting Address')
			.attr('disabled', 'disabled');
	
		// AJAX POST request
		jQuery.post(
			jQuery(this).attr('action'),
			{
				news_email:jQuery('#news_email').val(),
				c_email:jQuery('#c_email').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					jQuery('#contactformn')
						.hide()
						.html('<h3 style="position:relative;margin:5px 0 0 0;">Thank you</h3><p>Your subscription request has been sent.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					jQuery('#contactformn input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'Submit E-mail');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					jQuery('#contactformn .errorbox').html('<ul></ul>').show();
					jQuery('#contactformn li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							jQuery('#' + field).parent('li').addClass('alert');
							jQuery('#contactformn .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return false;
	});


	/*
 * 		Security Audit Form Validation
 */

	jQuery('#contactforms').submit(function() {
	
		// Disable the submit button
		jQuery('#contactforms input[type=submit]')
			.attr('value', 'Submitting Request')
			.attr('disabled', 'disabled');
	
		// AJAX POST request
		jQuery.post(
			jQuery(this).attr('action'),
			{
				network_name:jQuery('#network_name').val(),
				network_company:jQuery('#network_company').val(),
				network_phone:jQuery('#network_phone').val(),
				c_email:jQuery('#c_email').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					jQuery('#contactforms')
						.hide()
						.html('<h3 style="position:relative;margin:5px 0 0 0;">Thank you</h3><p>Your scheduling request has been sent.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					jQuery('#contactforms input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'Schedule Now');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					jQuery('#contactforms .errorbox').html('<ul></ul>').show();
					jQuery('#contactforms li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							jQuery('#' + field).parent('li').addClass('alert');
							jQuery('#contactforms .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return false;
	});


	/*
 * 		Help Form Validation
 */

	jQuery('#contactformh').submit(function() {
	
		// Disable the submit button
		jQuery('#contactformh input[type=submit]')
			.attr('value', 'Submitting Help Request')
			.attr('disabled', 'disabled');
	
		// AJAX POST request
		jQuery.post(
			jQuery(this).attr('action'),
			{
				help_name:jQuery('#help_name').val(),
				help_company:jQuery('#help_company').val(),
				help_phone:jQuery('#help_phone').val(),
				c_email:jQuery('#c_email').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					jQuery('#contactformh')
						.hide()
						.html('<h3 style="position:relative;margin:5px 0 0 0;">Thank you</h3><p>Your help request has been sent.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					jQuery('#contactformh input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'Get Help Now');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					jQuery('#contactformh .errorbox').html('<ul></ul>').show();
					jQuery('#contactformh li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							jQuery('#' + field).parent('li').addClass('alert');
							jQuery('#contactformh .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return false;
	});
	
/*
 * 		Virtualization Evaluation Form Validation
 */

	jQuery('#contactformvr').submit(function() {
	
		// Disable the submit button
		jQuery('#contactformvr input[type=submit]')
			.attr('value', 'Sending Information')
			.attr('disabled', 'disabled');
	
		// AJAX POST request
		jQuery.post(
			jQuery(this).attr('action'),
			{
				name:jQuery('#vr_name').val(),
				email:jQuery('#vr_email').val(),
				message:jQuery('#vr_message').val(),
				position:jQuery('#vr_position').val(),
				company:jQuery('#vr_company').val(),
				phone:jQuery('#vr_phone').val(),
				workstations:jQuery('#vr_workstations').val(),
				servers:jQuery('#vr_servers').val(),
				personnel:jQuery('#vr_personnel').val(),
				budget:jQuery('#vr_budget').val(),
				
				c_email:jQuery('#c_email').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					jQuery('#contactformvr')
						.hide()
						.html('<h3 style="position:relative;margin:5px 0 0 0;">Thank you</h3><p>Your message has been sent.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					jQuery('#contactformvr input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'Send');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					jQuery('#contactformvr .errorbox').html('<ul></ul>').show();
					jQuery('#contactformvr li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							jQuery('#' + field).parent('li').addClass('alert');
							jQuery('#contactformvr .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return false;
	});
	

	

});
