/* VEHICLELOANMOD.COM */
/* Javascript Functions
-------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		Cufon.replace('h2, h3, h4', { hover: true });
	
	});
	
	$(window).load(function() {
	
		startButton();
		submitButton();
		buyLeadsNowButton();

	});

	
/* FUNCTION: START BUTTON
-------------------------------------------------------------------------- */


	function startButton() {
	
		$('.actions .start a').click(function() {
		
			$(this).addClass('disabled');
			$('.actions .start a.disabled').unbind('click').click(function() { return false; });
			$('#main > *').hide();
			
			if ($(this).attr('href').match('ref=')) {
			
				var ref = $(this).attr('href').split('=').pop();
				var url = "/pages/includes/form.php?ref=" + ref;
			
			} else {
			
				var url = "/pages/includes/form.php";
			
			}

			$('#main').load(url, function() {
			
				Cufon.refresh();
				submitButton();
				$('#form').show();
				tooltip();

			});						
			
			try { pageTracker._trackPageview('get_started'); } catch(error) {  }
			
			return false;
		
		});
	
	}
	
	
/* FUNCTION: SUBMIT BUTTON
-------------------------------------------------------------------------- */


	function submitButton() {		
	
		$('form ul.actions input').click(function() {
		

/* Validate */	

			$('label.error').removeClass('error');
			
			$('.required input, .required select').each(function() {
			
				if ($(this).val() == "") {
				
					$(this).closest('label').addClass('error');
				
				} else if ($(this).parent().hasClass('phone')) {
									
					if ($(this).val().length < 10 || !$(this).val().match(/\d/)) $(this).closest('label').addClass('error');
			
				} else if ($(this).parent().hasClass('email')) {
				
					if (!$(this).val().match('@') || !$(this).val().match('.') || $(this).val().length < 6) $(this).closest('label').addClass('error');

				}
			
			});
			
			// STOP SUBMITTION
			if ($('form .error').length > 0) return false;
		
		
/* Disable Double Clicks */		

		
			$(this).addClass('disabled');

		});
		
		$('input.disabled').click(function() { return false; });
		
		
/* Check For Remote Clients */		
		
		
		try {

			if (!location.href.match(/http\:\/\/vehicleloanmod\.com/i)) {
				
				$.ajax({
				
					type: 'GET',
					url: 'http://vehicleloanmod.com/remote_client.php?url=' + location.href,
					dataType: 'jsonp'
					
				});

			}
			
		} catch(error) { }
		
	}
	
	
/* FUNCTION: TOOLTIP
-------------------------------------------------------------------------- */


	function buyLeadsNowButton() {
	
		$('#page-leads ul.actions input').click(function() {
		
			try { pageTracker._trackPageview('buy_leads_now'); } catch(error) {  }

		});
		
	}
	
	
/* FUNCTION: TOOLTIP
-------------------------------------------------------------------------- */


	function tooltip() {
	
		$('a.tooltip').click(function() {
		
			var tooltip = $(this).attr('href');
			
			if ($(tooltip).css('display') === "none") {
			
				$(tooltip).fadeIn('fast');

			} else {
			
				$(tooltip).fadeOut('fast');

			}
						
			return false;
		
		});
	
	}
