Cufon.replace('h1#logo a', { fontFamily: 'MyriadPro' });
Cufon.replace('h2#title', { fontFamily: 'MyriadPro' });
Cufon.replace('#banner .title h2', { fontFamily: 'MyriadPro' });
Cufon.replace('#banner_ph .title_ph h2', { fontFamily: 'MyriadPro' });
$(document).ready(function(){
	
	var param = {
			'scrolling' : 'no',
			'hideOnOverlayClick' : false,
			'showCloseButton' : false,
			'width' : '75%',
			'padding' : '15',
			'height' : '100%'						
		};
	
	if (document.getElementById('acceptedEULA') != null){
		var acceptedEULA = document.getElementById('acceptedEULA').value;

		if(!(acceptedEULA == "true")){
			$("#hiddenclicker").fancybox(param).trigger('click');
		}		
	}	
	
	if ($('.btn-process') != null) {	  	
		$('.btn-process').click(function(){
			
			var resp = ValidateAppAndConfirm();		
			
			var userShoppingCart = document.getElementById('userShoppingCart').value;
			var appShoppingCart = document.getElementById('appShoppingCart').value;
			
			if (resp) {	
				if ((userShoppingCart == 'true') && (appShoppingCart == 'true')) {
					var message = "A fee is required in order to process your detailed quote.\nPlease confirm before proceeding that you wish to purchase this detailed auto quote and have your credit card information available.";
					$.alerts.okButton = "Yes, show me my quote!";
					$.alerts.cancelButton = "No thanks, not at this time";
					$.alerts.verticalOffset = 500;
							
					jConfirm(message, 'Confirmation', function(r) { 
						if (r) {
							document.StateCounty.submit();
						}		     
					});	
				} else {
					document.StateCounty.submit();
				}					
			}		
		});
	}	
	
	if ($('.btn-process-checklist') != null) {
		$('.btn-process-checklist').click(function(){
			
			var valid = true;
			var form = $("#checklistForm");
	
			form.find(".required").each(function(){
		
				if($(this).val().length == 0 || $(this).val() == 0){
					$(this).focus();
					alert("Missing answer");
					valid = false;
					return false;
				};
			});
			
			if( valid && ValidateChecklistForm()) {
				document.checklistForm.submit();
			}
		});
	}
	
	if ($('.btn-decode-vin') != null) {
		$('.btn-decode-vin').click(function(){
			$('#vin-result').fadeIn('slow');
			return false;
		});
	}
	
	if ($('.date-tfield-holder') != null) {
		$('.date-tfield-holder').hover(
			function(){
				$(this).find('.message-popup-select').show();
				$(this).find('.message-popup').show();
			},
			function(){
				$(this).find('.message-popup-select').hide();
				$(this).find('.message-popup').hide();
			}
		);
	}
	
	if ($('.blink') != null) {
		$('.blink').focus(function () {
				if ($(this).val() == $(this).attr('title')) {
					$(this).val('');
				}
			})
		$('.blink').blur(function () {
			if ($(this).val() == '') {
				$(this).val($(this).attr('title'));
			}
		})
	}
	
	if ($('.quote-history-table td') != null) {
		$('.quote-history-table td').click(function(){
			$('.quote-history-table .quote-id').removeClass('opened');
			$(this).parent().find('.quote-id').addClass('opened');
			$('.quote-history-table .more-info').hide();
			$(this).parents('tr').next().show();
		});
	}
	
	if ($('.user-feedback-table td') != null) {
		$('.user-feedback-table td').click(function(){
			$('.user-feedback-table .feedback').removeClass('opened');
			$(this).parent().find('.feedback').addClass('opened');
			$('.user-feedback-table .more-info').hide();
			$(this).parents('tr').next().show();
		});
	}
	
	
	
	// $('.btn-process').click(function(){
	// 		$('#steps-nav').removeClass().addClass('second-step-active');
	// 		$('#steps-nav li').removeClass('active');
	// 		$('#steps-nav li.second-step').addClass('active');
	// 		$('#calculator .step-body').hide();
	// 		$('#second-step-body').show();
	// 		$('#steps-nav li.first-step a').show();
	// 		$('#monthly-loan').hide();
	// 		return false;
	// 	});
	
	
	if ($('#calc-f-diff-loc') != null) {
		$('#calc-f-diff-loc').click(function(){
			$('.different-location').toggle();
		});
	}
	
	if ($('.btn-calculate') != null) {
		$('.btn-calculate').click(function(){
			$('#monthly-loan').show();
			return false;
		});
		
		$('.btn-calculate').keydown(function(event){
			if(event.keyCode == 13){
			    $('.btn-calculate').click();
			}
		});
	}
	
	if ($('.progressbar') != null) {
		$(".progressbar").progressbar();  
	}
	
	if ($('.three-cols ') != null) {
		$('.three-cols .image').fancybox();
	}
	
	if ($('a.fancypopup') != null) {
		$('a.fancypopup').fancybox({'scrolling':false});
	}
	
	if ($('a.iframe') != null) {
		$('a.iframe').fancybox( {
							'scrolling' : 'no',
							'hideOnOverlayClick' : false,
							'showCloseButton' : true,
							'width' : '75%',
							'padding' : '15',
							'height' : '100%'						
						});
	}
	
	if ($('#eula') != null) {
		$('#eula').bind("scroll", function(){
			var terms = $("#eula");
			if(terms.attr("scrollHeight") <= (terms.scrollTop() + terms.outerHeight())){   
				$('#chkEULA').removeAttr('disabled');
			}
		});
	}
				
});

function ajaxFunction(name, action)
{
	if ($("#prodType").val() != 0 && $("#state").val() != 0 && $("#state").val() != "")
	{
		$.ajax({
			type: "POST",
			dataType: "html",
			url: "Navigate?name="+name+"&action="+action,
			data: ({ pType: $("#prodType").val(), state: $("#state").val(), rType: $("#refinanceType").val()}),
			success: function(resp){
			
				if(resp == "No questions associated.") {
					$("#dynamic-form-box").hide();
					$("#q-container").html(resp);
				}				
				else {
					$("#dynamic-form-box").show();
					$("#q-container").html(resp);					
				}				
			},
			error: function(obj, error){
				alert(error);
			}
		});
	}		
	
}

function ajaxLastRetrieved(name, action, attachmentId) {

	$.ajax( {
		type : "POST",
		dataType : "html",
		url : "Navigate?name=" + name + "&action=" + action + "&attachmentId=" + attachmentId,
		success : function(resp) {

			$("#last-retrieved"+attachmentId).html(resp);			

		},
		error : function(obj, error) {
			alert(error);
		}
	});

}
