$(document).ready(function(){
	$('a.scheduleLink').click(function(){
		$('input#schedule').attr('checked','checked');
		$('.schedule').show();
		$('#subject').val('Schedule Install/Service Call');
	});
	
	$('a.contact').click(function(){
		$('#subject').val('Quick Quote');
	});
	
	$('a.external').click(function(){
		$title = $(this).attr('title');
		if(!confirm('You will be directed to ' + $title + '.')){
			return false;
		}
	});
	if( $('#schedule').is('.isset') ){
		$('#schedule').attr('checked','checked');
		$('.schedule').show();
	} else {
		$('#schedule').removeAttr('checked');
	}
	$('input#schedule').change(function(){
		if($(this).is(':checked')){
			$('.schedule').fadeIn('slow');
			$('#subject').val('Schedule Install/Service Call');
		} else {
			$('.schedule').hide();
		}
	});
	
	$('#contact').submit(function(){
		$name = $('#name');
		if($name.val().length < 2){
			return error($name);
		}
		$email = $('#email');
		if($email.val().length < 10){
			return error($email);	
		}
		if($('input#schedule').is(':checked')){
			$phone = $('#phone');
			if($phone.val().length < 10){
				return error($phone);	
			}
			$address = $('#address');
			if($address.val().length < 10){
				return error($address);	
			}
			$city = $('#city');
			if($city.val().length < 3){
				return error($city);	
			}
			$zip = $('#zip');
			if($zip.val().length < 5){
				//return error($zip);
			}
		}
	});
	
	function error($elem){
		window.location = '#contact';
		$elem.css('background','#ffcfcf');
		setTimeout(function(){ $('#contactForm input').css('background',''); }, 2000);
		return false;
	}
});