$(document).ready(function(){
	var target = document.location.search.substring(1);
	var agreed=false;

	$("#programs, #agreement, #pay, #thankyou, #pay_now, #individual_options, #group_options, #corporate_options").hide();
	if (target !== "") {
		$("#programs, #"+target+"_options").show();
		$("#testimonials #"+target+"_testimonial").show();
		$("#tabs li a").removeClass("active");
		$("#tabs li a#"+target+"_tab").addClass("active");
	}
	if (target == ""){
		$("#programs").hide();
		$("#corporate_options").show();
		$("#testimonials #corporate_testimonial").show();
		$("#corporate_tab").addClass("active");
	}
		
	$("#program_link").click(function(){
		$("#agreement, #pay, #thankyou").hide();
		$("#programs").show();
		return false;
	})

	$("#agreement_link").click(function(){
		$("#programs, #pay, #thankyou").hide();
		$("#agreement").show();
	})
	
	$("#agreement input:submit").click(function(){
		if($("#pay_link").attr("href")){
			agreed = true;
			$("#agreement").hide();
			$("#pay").show();
			$("#agreement_link").addClass("complete");
		}
		else {
			alert("First you must choose a program");
			$("#agreement").hide();
			$("#programs").show();
			return false;
		}
	})

	$("a.item").click(function(){
		var agreementCopy = $(this).parent().parent().html();  // copies the text from the item to be used in "attachment a" of the agreement
		var choice = $(this).attr("href");  // copies the url from the item to be used in the "pay now" link
		$("#programs").hide();
		$("#agreement").show();
		$("#program_link").addClass("complete");
		$("#pay_link, #pay_link2").attr("href",choice);	 // inserts the item url into the pay link	
		$("#agreement_link, #pay_link").removeClass("complete"); agreed = false;  // this resets the check boxes and makes them accept the agreement each time they choose an item
		$("#attachment_a").html(agreementCopy);  // inserts the item description into the "attachment A" section of the agreement
		$("#attachment_a a.action").remove();  // takes the "click to choose this item" link out of the agreementCopy text
		$("#attachment_a h4 a.item").replaceWith($(this).parent().parent().children("h4").text()); // removes the link and replaces it with the link text
		return false;
	})

	$("#pay_link, #pay_link2").click(function(){
		$("#pay, #programs, #agreement").hide();

		if($(this).attr("href")){
			var url = $(this).attr("href")
			if( agreed == true){
				$("#pay_link").addClass("complete");
				$('#thankyou').show().load('get_started/thankyou.htm');
				newwindow=window.open( url, 'paypal');
				if (window.focus) {newwindow.focus()}
				return false;
			}
			else {
				$("#agreement").show();
				alert("Please review and accept the conditions.");
				return false;
			}
		}
		else {
			alert("Please choose a program");
			$("#agreement").hide();
			$("#programs").show();
			return false;
		}

	})
	$("#corporate_tab").click(function(){
		
		if($("#corporate_options").is(":hidden")){
			$("#programs div.option").hide();
		$("#corporate_options").show();
		$("#tabs li a").removeClass("active");
		$(this).addClass("active");
		return false;
		}
		else {
			return false;
		}
	})
    $("#individual_tab").click(function(){
	
		if($("#individual_options").is(":hidden")){
			$("#programs div.option").hide();
			$("#individual_options").show();
			$("#tabs li a").removeClass("active");
			$(this).addClass("active");
			return false;
		}
		else {
			return false;
		}
		
	})
    $("#group_tab").click(function(){
		if($("#group_options").is(":hidden")){
			$("#programs div.option").hide();
			$("#group_options").show();
			$("#tabs li a").removeClass("active");
			$(this).addClass("active");
			return false;
		}
		else {
			return false;
		}
		
	})
	
	var aColor = "orange";
	var cColor = "blue";
	var gColor = "burgundy";
	var iColor = "green";
	$("#agreement, #pay, #thankyou").append("<img src='images/options_" + aColor + "_bottom.gif' style='position:absolute;bottom:-3px;left:-3px;' /><img src='images/options_" + aColor + "_top.gif' style='position:absolute;top:0;left:-3px;' />");
	$("#corporate_options").append("<img src='images/options_" + cColor + "_bottom.gif' style='position:absolute;bottom:-3px;left:-3px;' /><img src='images/options_" + cColor + "_top.gif' style='position:absolute;top:0;left:-3px;' />");
	$("#individual_options").append("<img src='images/options_" + iColor + "_bottom.gif' style='position:absolute;bottom:-3px;left:-3px;' /><img src='images/options_" + iColor + "_top.gif' style='position:absolute;top:0;left:-3px;' />");
	$("#group_options").append("<img src='images/options_" + gColor + "_bottom.gif' style='position:absolute;bottom:-3px;left:-3px;' /><img src='images/options_" + gColor + "_top.gif' style='position:absolute;top:0;left:-3px;' />");
});                      


