$j = jQuery.noConflict();
var original_values = new Array();
$j(document).ready(function() {
	$j.each($j('div#contactform :input'), function() {original_values[$j(this).attr('id')] = $j(this).val();});
	$j('div#contactform :input')
		.focus(function() {
			if($j(this).val() == original_values[$j(this).attr('id')] && $j(this).attr('type') != "hidden") $j(this).attr('value','');
		})
		.blur(function() {
			if($j(this).val() == '') $j(this).attr('value', original_values[$j(this).attr('id')]);
		});
	
	$j('div#contactform').hide().css({"cursor":"pointer"});
	$j('span.togglecontact').click(function() {
		$j('div#contactform').slideToggle();
	});
	
	$j('#contactform form').ajaxForm({ 
		target: '#ContactForm_FooterContactForm_error',
		beforeSubmit : function() {
			var errors = "";
			$j.each($j('div#contactform :input'), function() { 
				if($j(this).val() == original_values[$j(this).attr('id')] && $j(this).attr('type') != "hidden") 
					$j(this).attr('value',''); 
			});
			$j.each($j('div#contactform :input'), function() { 
				n = $j(this).attr('name');
				if(n == 'MessageSubject' || n == 'Message' || n == 'Email') {
					if($j(this).val() == '') {
						errors += 'Please enter a value for "'+ original_values[$j(this).attr('id')]+'"<br />';
					}
					else if($j(this).attr('name') == 'Email') {
						str = $j(this).val();
						if(str.indexOf(".") < 2 && str.indexOf("@") < 0) {
							errors += "Please enter a valid email address.<br />";
						}
					}
				}
			});
			
			if(errors != "")  {
				$j('#ContactForm_FooterContactForm_error').html(errors).removeClass('success').hide().slideDown();
					$j.each($j('div#contactform :input'), function() {
						if($j(this).val() == '') $j(this).attr('value', original_values[$j(this).attr('id')]);
					});
					return false;
			}
			
			$j('#ContactForm_FooterContactForm_error').html('');
			
		},
		success : function() {
			$j('#ContactForm_FooterContactForm_error').hide().addClass('success').slideDown();
		}
	});
	
	
	
});


