$(document).ready(function() {
        $("#choice_300k .more_details").click(function(){
            $(".more_details").removeClass("selected");
            $(this).addClass("selected");

            $("#details_225k").hide();
            $("#details_150k").hide();
            $("#over_75k").hide();
            $("#limitations").hide();
            
            $(".details").show();
            $("#details_300k").show();

        });

        $("#choice_225k .more_details").click(function(){
            $(".more_details").removeClass("selected");
            $(this).addClass("selected");

            $("#details_300k").hide();
            $("#details_150k").hide();
            $("#over_75k").hide();
            $("#limitations").hide();

            $(".details").show();
            $("#details_225k").show();

        });

        $("#choice_150k .more_details").click(function(){
            $(".more_details").removeClass("selected");
            $(this).addClass("selected");

            $("#details_300k").hide();
            $("#details_225k").hide();
            $("#over_75k").hide();
            $("#limitations").hide();

            $(".details").show();
            $("#details_150k").show();

        });

        $(".close").click(function(){
            $(".more_details").removeClass("selected");
            $(".details").hide();

            $("#over_75k").show();
            $("#limitations").show();

            return false
        });

	// This function will create HTML elements to form the default grey box with rounded corners, so long as the class 'box' is placed on it. //
	$(".box").wrapInner('<div class="box2"><div class="box3"><div class="box4"><div class="box5"></div></div></div></div>');
	
	// This function, similar to the previous one, will create HTML elements to form the default blue button with rounded corners, so long as the class 'button' is placed on it. //
	$(".button").wrapInner('<div class="button2"><div class="button3"><div class="button4"><div class="button5"></div></div></div></div>');
	
	// This function, similar to the previous one, will create HTML elements to form the default SMALL blue button with rounded corners, so long as the class 'smallButton' is placed on it. //
	$(".smallButton").wrapInner('<div class="smallButton2"><div class="smallButton3"><div class="smallButton4"><div class="smallButton5"></div></div></div></div>');
	
	// This function, similar to the previous one, will create HTML elements to form the default SMALL GREY button with rounded corners, so long as the class 'smallButtonSpecial' is placed on it. //
	$(".smallButtonSpecial").wrapInner('<div class="smallButton2Special"><div class="smallButton3Special"><div class="smallButton4Special"><div class="smallButton5Special"></div></div></div></div>');
	
	// This function makes it so that any element with the class 'submit', will submit the closest parent form element. //
	$(".submit").click(function(){
		$(this).closest("form").submit();
		return false;
	});
	
	// Login variant with tracking
	$(".login_submit").click(function(){
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		var iframe_src = 'http://fls.doubleclick.net/activityi;src=1662490;type=2009g188;cat=login123;ord='+ a + '?';
		$("iframe#login_iframe").attr("src",iframe_src);
		
		$(this).closest("form").submit();
		return false;
	});
	
	// For vehicle enrollment, when the page loads and other is selected, the text boxes should show. //
	
	if($("#cc_make_id").val() == 'oth' || $("#cc_make_id").val() == 'Oth' || $("#cc_make_id").val() == 'OTH'){
		$("#div_cc_make_id").addClass('arrow');
		$("#write_in_make").show();
	};
	
	if($("#cc_model_id").val() == 'other' || $("#cc_model_id").val() == 'Other' || $("#cc_model_id").val() == 'OTHER'){
		$("#div_cc_model_id").addClass('arrow');
		$("#write_in_model").show();
	};
	
	// This is for the vehicle enrollment submit button. //
	if($("#agree_terms-option-group input:checked").val() == !null){
		$("#dummySubmit").hide();
		$("#realSubmit").show();
	}else if($("#agree_terms-option-group input:checked").val() == null){
		$("#dummySubmit").show();
		$("#realSubmit").hide();
	};
	
	$("#agree_terms-option-group input").click(function(){
		displayVal = $("#agree_terms-option-group input:checked").val();
		if (displayVal == !null){
			$("#dummySubmit").hide();
			$("#realSubmit").show();
		}else if(displayVal == null){
			$("#dummySubmit").show();
			$("#realSubmit").hide();
		};
	});
	
	// This is for the special invite submition //
	
	function showButton(){
		$("#dummyEnrollMe").hide();
		$("#enrollMe").show();
	};
	
	function hideButton(){
		$("#dummyEnrollMe").show();
		$("#enrollMe").hide();
	};
	
	function checkBoxDetermination(){
		if ($("#special_enrollment_form #termsCheckbox input:checked").val() == null){
			hideButton();
		}else{
			showButton();
		};
	};
	
	if($("#special_enrollment_form #termsCheckbox input:checked").val() == null){
		hideButton();

	}else{
		showButton();
	};
	
	$("#special_enrollment_form #termsCheckbox input").click(function(){
		checkBoxDetermination();
	});
	
	
	displayVal = $("#reminder_opt_in-option-group input:checked").val();
	displayVal2 = $("#as_sms_opt_in-option-group input:checked").val();
	displayVal3 = $("#as_email_opt_in-option-group input:checked").val();

	if(displayVal == "yes" || displayVal2 == !null || displayVal3 == !null){
		$("#as_email_opt_in").show();
		$("#as_sms_opt_in").show();
		$("#remind_language").show();
		$(".reminderQuestion").show();
	};
	
	if(displayVal2 == !null){
		$("#mobile_phone_number").show();
	};
	
	// This is for record a service, when you click on "I don't have a UPC" //
	
	$("#unspecifiedUPC").click(function(){
		unspecifiedUPC();
		return false
	});
	
	$("#specifiedUPC").click(function(){
		specifiedUPC();
		return false
	});
	
	// This hides the select boxes so that the modals in IE6 won't break //

	$(".modal_trigger").click(function (){
		if(jQuery.browser.version == "6.0"){
			$("select").addClass("hideSelectBoxes");
		};
	});
});

// This is for recording a service, and the user selects "Other" for their retailer. //
	
function changeRetailer(x){
	var xval = $(x).val()
	if(xval == "Other" || xval == "OTHER" || xval == "other"){
		$("#wi_retailer").show();
		$("#diy_wi_address").show();
		$("#diy_service_zip").show();
	}else{
		$("#wi_retailer").hide();
		$("#diy_wi_address").hide();
		$("#diy_service_zip").hide();
		
		$("#wi_retailer input").val("");
		$("#diy_wi_address input").val("");
		$("#diy_service_zip input").val("");
	}

};

// This is for record a service, when you click on "I don't have a UPC" //

function unspecifiedUPC(){
	$("#unspecifiedUPC").hide();
	$("#specifiedUPC").show();
	$(".noUpc").show();	
	$("#fs_upc input").attr("disabled","disabled");
	$(".upcGuide").hide();
	$(".oilInfo").hide();
	$("#upc1 input").val("");
	$("#upc2 input").val("");
	$("#upc3 input").val("");
	$("#upc4 input").val("");
	$("#upc5 input").val("");
	$(".upc span").removeClass("error");
	$(".upc span strong").removeClass("error");
	return false
};
	
function specifiedUPC(){
	$("#specifiedUPC").hide();
	$("#unspecifiedUPC").show();
	$(".noUpc").hide();	
	$("#fs_upc input").attr("disabled","");
	$(".upcGuide").show();
	return false
};
