jQuery.noConflict();
jQuery(document).ready(function() {
	var the_value = "";
	var aboutme = "";
	var jersey = "";
	var brace = "";
	var profileHTML = "";
	var teamHTML = "";
	var optionHTML = "";
	
	teamHTML = jQuery("#signup_team_hidden").html();
	profileHTML = jQuery("#signup_profile_hidden").html();
	optionHTML = jQuery("#signup_regoption_hidden").html();
	
	jQuery("#signup_regoption_hidden").html('');
	//jQuery("#team-details-section").html(''); //remove all team content
	
	the_value = jQuery('#signup_form input:radio:checked').attr('id');
  	the_value = the_value.replace('option_', '');
    	
	show_hide(the_value);
	show_desc(the_value); //show/hide description of each option button
	//moreRider = jQuery('#team-details-section input:radio:checked').val();
	//more_rider(moreRider);
	
	jQuery("#regoptions input:radio").click(function(){
		the_value = jQuery('#regoptions input:radio:checked').attr('id');
		the_value = the_value.replace('option_', '');
		
		show_hide();
		show_desc(the_value);
	 });
	 
	
	 
	 jQuery("#field_105").change(function() { //if corporate sponsor selecting different rider
        var val = jQuery("option:selected", this).val();
		
		corporate_show_hide(val);

	});
	
	jQuery("#team-details-section input:radio").click(function() {
		//riderValue = jQuery('#team-details-section input:radio:checked').val();
		riderValue = jQuery('#team-details-section input:radio:checked').val();		
		more_rider(riderValue);		
		
		
	});	
	
	function show_desc(val){		
		var desc = { 128:'<p>A hero page will be created for you so that you can begin to raise funds and promote your cause&mdash;this will give you full access to all of our <a href="http://www.entoure.com.au/activity/">community features</a> and perks.</p>', 
					129:'<p>A hero page will be created for you so that you can begin to raise funds and promote your cause&mdash;this will give you full access to all of our <a href="http://www.entoure.com.au/activity/">community features</a>  and perks.</p>', 
					130:'<p>A hero page will be created for you so that you can begin to raise funds and promote your cause&mdash;this will give you full access to all of our <a href="http://www.entoure.com.au/activity/">community features</a>  and perks.</p>', 
					131:'<p>Register your details with us without making any payment. Remember to head to our <a href="http://www.entoure.com.au/teams/">team directory</a> and join or create your team after registration.</p>', 
					132:'<p>Register as a corporate sponsor to request a quote for your team before submitting any payment. We\'ll send you an activation link so that you can manage your team.</p>',
					133:'<p>Register as a member of the road crew for an event. You will also be given access to our community if you wish to participate.</p>',
					134:'<p>Join our community to receive our newsletter. This will also allow you to setup a hero page, <a href="http://www.entoure.com.au/team/">create or join a team</a> and communicate with other riders.</p>' };
		
		jQuery.each(desc, function(key, value) { 
			if( val == key )
				jQuery("#regdescription").html(value);
		});    	
	}
	
	function more_rider(riderValue){
		
		if( riderValue == "Yes" ){
			jQuery("#field_105").val('+ 1 Rider');
			jQuery("#field_117").val('$11,000');
			jQuery("#rider_105").css('display', 'block');
			jQuery("#rider_117").css('display', 'block');
		}
		else{
			jQuery("#field_105").val('');
			jQuery("#field_117").val('');
			jQuery("#rider_105").css('display', 'none');
			jQuery("#rider_117").css('display', 'none');
		}
	}
	function corporate_show_hide(val){
		
		val = val.replace(' ', '');;
		val = val.replace('+', '');
		val = val.replace('Rider', '');
		var dollar = 10000;
		dollar = val * 1000 + parseInt(dollar);
		dollar = dollar + "";
		dollar = "$" + dollar.replace('000', ',000');

		jQuery("#field_117").val(dollar);
	}

 //  jQuery("#field_70").text("For this type jQuery found ");
	function show_hide(){
		if( the_value == '133'){ //if it is road crew - no right column, all values in right are set to null
			jQuery('input[name=field_40[]]').attr('checked', false);
			jersey = jQuery("#field_26").val();
			jQuery("#field_26").val('');
			brace = jQuery("#field_33").val();
			jQuery("#field_33").val('');
			aboutme = jQuery("textarea").val();
			jQuery("textarea").val('');
			jQuery("#profile-details-section").css("display", "none");
			jQuery("#team-details-section").css("display", "none");
			jQuery("#signup_regoption_hidden").html(optionHTML);
			jQuery("#signup_profile_hidden").html('');
			jQuery("#signup_team_hidden").html('');
		}
		else if( the_value == '134' ){ //join community for free
			jQuery("#profile-details-section").css("display", "none");
			jQuery("#team-details-section").css("display", "none");
			jQuery("#signup_regoption_hidden").html(optionHTML);
			jQuery("#signup_profile_hidden").html('');
			jQuery("#signup_team_hidden").html('');
			jQuery("#signup_submit").removeClass("payment");
		}
		else if( the_value == '132' ){ //if corporate sponsor registering
			jQuery("#profile-details-section").css("display", "none");
			if( profileHTML == "" ){
				profileHTML = jQuery("#signup_profile_hidden").html();
			}
			jQuery("#signup_profile_hidden").html('');
			if( teamHTML != "" )
				jQuery("#signup_team_hidden").html(teamHTML);
			jQuery("#signup_regoption_hidden").html('');
			jQuery("#team-details-section").css("display", "block");
			jQuery("#signup_submit").removeClass("payment");

		}
	  else{
			if( jersey != "") 
			  jQuery("#field_26").val(jersey);
			if( brace != "" )
			  jQuery("#field_33").val(brace);
			if( aboutme != "" )		  
				jQuery("textarea").val(aboutme);
			if( profileHTML != "" ){
				jQuery("#signup_profile_hidden").html(profileHTML);
			}
			//button control
			if( the_value == '128' || the_value == '129' || the_value == '130' ){
				jQuery("#signup_submit").addClass("payment");
			}else{
				jQuery("#signup_submit").removeClass("payment");
			}
			jQuery('input[name=field_40[]]').attr('checked', true);
	  		jQuery("#profile-details-section").css("display", "block");
			jQuery("#signup_profile_hidden").html(profileHTML);
			jQuery("#signup_team_hidden").html(''); //remove all team content
			jQuery("#signup_regoption_hidden").html('');
			jQuery("#team-details-section").css("display", "none");
	  }
 } //end show_hide
});
