//<![CDATA[	
	$(document).ready(function(){
		var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		
		//check checkbox and show other options
		if($('#help_2').attr('checked')){
			$('#other').css('display', '');
			$('#for_other').css('display', '');
			$('#other-error').css('display', '');
		}
		else{
			$('#other').val('');
			$('#other').css('display', 'none');
			$('#for_other').css('display', 'none');
			$('#other-error').css('display', 'none');
		}
		
		if($('#hear_5').attr('checked')){
			$('#referrer').css('display', 'block');
			$('#for_referrer').css('display', 'block');
			$('#referrer-error').css('display', 'block');
		}
		else{
			$('#referrer').val('');
			$('#referrer').css('display', 'none');
			$('#for_referrer').css('display', 'none');
			$('#referrer-error').css('display', 'none');
		}
		
		$('#help_2').click(function(){
			if($(this).attr('checked')){
				$('#other').css('display', '');
				$('#for_other').css('display', '');
				$('#other-error').css('display', '');
			}
			else{
				$('#other').val('');
				$('#other').css('display', 'none');
				$('#for_other').css('display', 'none');
				$('#other-error').css('display', 'none');
			}
		});
		
		$('#hear_5').click(function(){
			if($(this).attr('checked')){
				$('#referrer').css('display', 'block');
				$('#for_referrer').css('display', 'block');
				$('#br_referrer').css('display', 'block');
				$('#referrer-error').css('display', 'block');
			}
			else{
				$('#referrer').val('');
				$('#referrer').css('display', 'none');
				$('#for_referrer').css('display', 'none');
				$('#br_referrer').css('display', 'none');
				$('#referrer-error').css('display', 'none');
			}
		});
		
		$('#submitForm').click(function(){
			var error = false;
			
			if($('#firstname').val().replace(/\s+/g,"").length == 0){
				$('#firstname-error').html('Please enter first name');
				error = true;
			}
			else{
				$('#firstname-error').html('');
			}
			
			if($('#lastname').val().replace(/\s+/g,"").length == 0){
				$('#lastname-error').html('Please enter last name');
				error = true;
			}
			else{
				$('#lastname-error').html('');
			}
			
			if($('#phone').val().replace(/\s+/g,"").length == 0){
				$('#phone-error').html('Please enter phone number');
				error = true;
			}
			else{
				$('#phone-error').html('');
			}
			
			if($('#email').val().replace(/\s+/g,"").length == 0){
				$('#email-error').html('Please enter email address');
				error = true;
			}
			else if($('#email').val().search(regexp) == -1){
				$('#email-error').html('Please enter valid email');
				error = true;
			}
			else{
				$('#email-error').html('');
			}
			
			if($('#help_2').attr('checked')){
				if($('#other').val().replace(/\s+/g,"").length == 0){
					$('#other-error').html('Please specify how can we help you');
					error = true;
				}
				else{
					$('#other-error').html('');
				}
			}
			
			if($('#hear_5').attr('checked')){
				if($('#referrer').val().replace(/\s+/g,"").length == 0){
					$('#referrer-error').html('Please neter referer name');
					error = true;
				}
				else{
					$('#referrer-error').html('');
				}
			}
			
			var help_error = true
			var hear_error = true
			
			$('#contactForm *').children().each(function(){
				if($(this)[0].tagName.toLowerCase() == 'input'){
					if($(this).attr('type').toLowerCase() == 'checkbox' && $(this).attr('checked') == true && $(this).attr('name') == 'help[]'){
						help_error = false;
					}
					if($(this).attr('type').toLowerCase() == 'checkbox' && $(this).attr('checked') == true && $(this).attr('name') == 'hear[]'){
						hear_error = false;
					}
				}
			});
			
			if(help_error){
				$('#help-error').html('Please select at least one option');
				error = true;
			}
			else{
				$('#help-error').html('');
			}
			
			if(hear_error){
				error = true;
				$('#hear-error').html('Please select at least one option');
			}
			else{
				$('#hear-error').html('');
			}
			
			if(error){
				$('#process').html('Please fill out all required fields. Form will not process unless all required fields (<span class="mandatory">*</span>) are complete.');
			}
			else{
				$('#submitForm').attr('disabled', 'true');
				$('#message').html('Processing... please wait. ');
				
				var formData = 'firstname=' + encodeURIComponent($('#firstname').val()) + '&lastname=' + encodeURIComponent($('#lastname').val()) + '&address1=' + encodeURIComponent($('#address1').val()) + '&address2=' + encodeURIComponent($('#address2').val()) + '&city=' + encodeURIComponent($('#city').val()) + '&state=' + encodeURIComponent($('#state').val()) + '&zip=' + encodeURIComponent($('#zip').val()) + '&email=' + encodeURIComponent($('#email').val()) + '&phone=' + encodeURIComponent($('#phone').val()) + '&comments=' + encodeURIComponent($('#comments').val());
				
				if($('#help_2').attr('checked')){
					formData += '&help_other=' + encodeURIComponent($('#other').val());
				}
				
				if($('#hear_5').attr('checked')){
					formData += '&referrer=' + encodeURIComponent($('#referrer').val());
				}
				
				var i = 0;
				var ii = 0;
				$('#contactForm *').children().each(function(){
					if($(this)[0].tagName.toLowerCase() == 'input'){
						if($(this).attr('type').toLowerCase() == 'checkbox' && $(this).attr('checked') == true && $(this).attr('name') == 'help[]'){
							formData += '&help[' + i + ']=' + encodeURIComponent($(this).val());
							++i;
						}
						if($(this).attr('type').toLowerCase() == 'checkbox' && $(this).attr('checked') == true && $(this).attr('name') == 'hear[]'){
							formData += '&hear[' + ii + ']=' + encodeURIComponent($(this).val());
							++ii;
						}
					}
				});
				
				$.ajax({
					type: 'POST',
					url: 'contact.php',
					cache: false,
					data: formData,
					dataType: "xml",
					timeout: 10000,
					error: function(ob, status){
						$('#submitForm').attr('disabled', '');
						$('#process').html('Error: ' + status + '. Please try again.');
					},
					success: function(xml){
						$('#submitForm').attr('disabled', '');
						var root = xml.getElementsByTagName('root')[0];
						if(root.getElementsByTagName("error")[0].firstChild.nodeValue == 'false'){
							$('#contactForm')[0].reset();
							$('#content').html('<span id="confirm">Thank you! Your message has been successfully sent.</span>');
						}
						else{
							alert('error');
							$('#process').html('Error. Please try again.');
						}
					}
				});
			}
		});
	});
//]]>
