$(document).ready(function(){

	$('.req').hide();
		
	//email form
	$('#email .button').click( function() {
										
		$('#email .req').hide();
									
		var name = $('#e-name').val();
		if (name=='')
			$('#l-e-name .req').show();
		
		var email = $('#e-email').val();
		if (email=='')
			$('#l-e-email .req').show();
		
		var msg = $('#e-msg').val();
		if (msg=='')
			msg = "No Message Provided"
		//post
		
		//if either are empty
		if( ((email=='')||(name=='')) )
			return false
		
		//otherwise post!
		else {
			$.post("mailer.php", { name: name, email: email, message: msg });
			
			//hide show stuff
			$('#email').addClass('done').animate({opacity: 1.0}, 2000)
			.fadeOut(500, function() {
				$('#email').jqmHide();
			})
		}
		
		return false;
	});
	
	//get started form
	$('#started .button').click( function() {

		$('#started .req').hide();
		
		var name = $('#g-name').val();
		if (name=='')
			$('#l-g-name .req').show();
		
		var phone = $('#g-phone').val();
		if (phone=='')
			$('#l-g-phone .req').show();
			
		//set checkbox values
		$('#started :checkbox').each( function() {
			if($(this).attr('checked'))
				$(this).val("Yes")
			else
				$(this).val("No")
		});
		var sem = $('#g-sem').val();
		var custom = $('#g-custom').val();
		var yellow = $('#g-yellow').val();
		
		//if either are empty
		if( ((phone=='')||(name=='')) )
			return false
		
		
		else {
			$.post("mailer.php", { name: name, phone: phone, sem: sem, custom: custom, yellow: yellow });
			
			$('#started').addClass('done').animate({opacity: 1.0}, 2000)
			.fadeOut(1500, function() {
				$('#dialog').jqmHide();
				$('.overlay').remove();
			})
		
		}		
		return false;
	});
		
	//contact form
	$('#contact #main .button').click( function() {

		$('#contact #main .req').hide();
		
		var name = $('#c-name').val();
		if (name=='')
			$('#l-c-name .req').show();
			
		var email = $('#c-email').val();
		if (email=='')
			$('#l-c-email .req').show();
		
		var phone = $('#c-phone').val();
		if (phone=='')
			$('#l-c-phone .req').show();
		
		var msg = $('#c-msg').val();
		if (msg=='')
			msg = "No Message Provided"
			
		//set checkbox values
		$('#contact #main :checkbox').each( function() {
			if($(this).attr('checked'))
				$(this).val("Yes")
			else
				$(this).val("No")
		});
		var sem = $('#c-sem').val();
		var custom = $('#c-custom').val();
		var yellow = $('#c-yellow').val();

		//if any are empty
		if( (email=='')||(name=='')||(phone=='') ) {
			return false
		}
		
		else {
			$.post("mailer.php", { name: name, email: email, phone: phone, sem: sem, custom: custom, yellow: yellow, message: msg });
			
			$('#main fieldset').hide();
			$('#main').append('<span class="thanks">Thank You For Contacting Us! One of our Representatives Will Follow Up With You Shortly.</span>');
			$('#main .thanks').animate({opacity:1},4000);
		}
		
		return false;

	});

});
