$(function(){
	if ($('#menu a:first').length)
	{
		var currentHash = $('#menu a:first').get(0).hash;
	
		$('#menu a,.bgswitch').click(function(){
			if (this.hash === currentHash)
				return false;
	
			var newHash = this.hash;
	
			$(currentHash).fadeOut(500, function(){
				currentHash = newHash;
				$(currentHash).fadeIn(500);
			});
	
			return false;
		});
	}

	$('#whatCvvLink').focus(function(){$('#cvv').focus();});


	$(document).bind('keypress', function(e) {
		if (e.keyCode == 13) return false;
	});

	var keyPressPixelAdded = false;

	$('input').bind('keypress', function() {
		if (keyPressPixelAdded)
			return;

		$('body').append($('<img src="https://secure.adtrgt.com/conversion.jsp?vid=563813" width="1" height="1" border="0" />'));
		keyPressPixelAdded = true;
	});

	$('#user-info').validation({
		fields:{
			'client.firstName':{required:true,label:'First Name'},
			'client.lastName':{required:true,label:'Last Name'},
			'client.street1':{required:true},
			'client.city':{required:true},
			'client.state':{required:true},
			'client.zip':{required:true,numeric:true,minLength:5,maxLength:5,label:'Zip Code'},
			'phone1':{required:true,numeric:true,minLength:3,maxLength:3},
			'phone2':{required:true,numeric:true,minLength:3,maxLength:3},
			'phone3':{required:true,numeric:true,minLength:4,maxLength:4},
			'client.email':{required:true,email:true,label:'Email Address'},
			'confirmEmail':{required:true,confirm:'client.email'},
			'card.number':{required:true,creditcard:true},
			'card.expirationMonth':{required:true},
			'card.expirationYear':{required:true},
			'card.cvv':{required:true,numeric:true,minLength:3,maxLength:4},
			'client.phone1':{required:true,phone:true,label:'Daytime Phone'},
			'client.phone2':{required:true,phone:true,label:'Evening Phone'},
			'client.residenceType':{required:true,error:'Please select Home or Apartment'}
		},
		invalidClass:'invalid',
		submit:function(){$.blockUI({message:$('#please-wait'),css:{}});}
	});

	$('#whatCvv,#whyCharge').click(function(){
		$.unblockUI();
	});

	$('#whatCvvLink').click(function(){
		$.blockUI({message:$('#whatCvv'),css:{left:'50%',marginLeft:'-141px'}});
		return false;
	});

	$('#whyChargeLink').click(function(){
		$.blockUI({message:$('#whyCharge'),css:{left:'50%',marginLeft:'-363px'}});
		return false;
	});
	
});
