jQuery.noConflict();
jQuery(function($) { 

// DROP DOWN MENU
	// http://users.tpg.com.au/j_birch/plugins/superfish/#getting-started
	// http://users.tpg.com.au/j_birch/plugins/superfish/#options
	$('.sf-menu').supersubs({ 
			minWidth:    10,   // minimum width of sub-menus in em units 
			maxWidth:    27,   // maximum width of sub-menus in em units 
			extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
							   // due to slight rounding differences and font-family 
		}).superfish({
			dropShadows:    false,
			delay:			400
			
							}); // call supersubs first, then superfish, so that subs are 
                         		// not display:none when measuring. Call before initialising 
                         		// containing tabs for same reason. 
								
								
	
	// Scroll to top animation
	$('.scroll-top').click(function(){ 
		$('html, body').animate({scrollTop:0}, 600); return false; 
	});
	
	
// mouseover effects
$('fieldset label').mouseover(function(){$(this).addClass('over');}).mouseout(function(){$(this).removeClass('over');});



/* disable sections */
  // single day fieldset
  $('#attending_single input[type="radio"]').change(function() {
	  var name = $(this).attr('name');
	  $('#attending_double input[type="radio"]:not(:checked)').prop('disabled', true);
	  $('#attending_double label').css({color:'#999'});
	  // if fee is selected, but no day
	  if ($('input:radio[name="singleday"]').is(':checked') && $('input:radio[name="attending"]:not(:checked)')) {
			  $("#attending_friday, #attending_saturday").parent().css({color:"#C00"});
			  $("#error-attending").fadeIn();
		  }
	  // else if = no work
	  // if fee is selected and day is selected	
	  if ($('input:radio[name="singleday"]').is(':checked') && $('input:radio[name="attending"]').is(':checked')) {
			  $("#attending_friday, #attending_saturday").parent().css({color:"#555"});
			  $("#error-attending").fadeOut();
		  }
  });
  // both days fieldset
  $('#attending_double input[type="radio"]').change(function() {
	  var name = $(this).attr('name');
	  $('#attending_single input[type="radio"]:not(:checked)').prop('disabled', true);
	  $('#attending_single label').css({color:'#999'});
  });

/* check 'both days' if corresponding fee selected */
  $('fieldset#attending_both_fees').change(function() {
	  if ($('input:radio[name="bothdays"]').is(':checked')) {
		  $('input#attending_both').prop('checked', true);
		  //set hidden values
			$('input#h_total_days').attr('value', '2');
			$('input#h_attending_fri').attr('value', 'Y');
			$('input#h_attending_sat').attr('value', 'Y');
	  } //else { 
	  //}
  });


/* reset fee selections */
$('#reset_fees_by_day').click(function() {
  $('#attending_single, #attending_double').find('input:radio:checked').removeProp('checked');
  $('#attending_single, #attending_double').find('input:radio:disabled').removeProp('disabled');
  $('#attending_single label, #attending_double label').css({color:'#555'}); //fix colors
  $('#totalcost_conffee').val(0); //clear conference fee listed in total cost section
  $('input#amount').val(''); //clear TOTAL
});


/* update hidden fields */
// determine day(s) attending by radio button set
  $('input:radio[name="attending"]').change(function() {
	// total # of days attending
  if ($('input:radio[value="attending_friday"]').is(':checked')) { //set hidden values
	$('input#h_attending_fri').attr('value', 'Y');
	$('input#h_attending_sat').attr('value', 'N');
  } else { //set hidden values
	$('input#h_attending_fri').attr('value', 'N');
	$('input#h_attending_sat').attr('value', 'Y');
  }
  if ($('input:radio[value="attending_both"]').is(':checked')) { //set hidden values
	$('input#h_total_days').attr('value', '2');
	$('input#h_attending_fri').attr('value', 'Y');
	$('input#h_attending_sat').attr('value', 'Y');
  } else {
	$('input#h_total_days').attr('value', '1');
  }
});


/* calculations */
//calculate cost of shirts based on quantity

$(function() { $('input.xTsizes').change(calculateSum); } );
function calculateSum() {
        var xTsizes_quantity = 0;
        //iterate through each textboxes and add the values
        $('input.xTsizes').each(function() {
            //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                //xTsizes_quantity += parseFloat(this.value);
				xTsizes_quantity += parseInt(this.value), 10;
            }
			//if there are no extra shirts
			else if(this.value.length=0) { xTsizes_quantity == parseInt(0), 10; }
        });
	
		$('input#extra_tshirt_quantity').val(xTsizes_quantity); //add em up
		
		var xTsizes_cost = xTsizes_quantity * 15; //calculate cost
	
		$('input#extra_tshirt_cost')[0].value = xTsizes_cost.toFixed(0); //disabled display
		$('input#h_extra_tshirt_cost')[0].value = xTsizes_cost.toFixed(0); //duplicate hidden field for db
		$('input#totalcost_xtshirts')[0].value = xTsizes_cost.toFixed(0); //fill in totalcost section
    }

//get value of conf. fee selection
  $('input:radio[name="singleday"]').change(function() {
  //$('input[name="singleday"]').change(function() {
	  var fee_value = parseInt(this.value);
      //val = parseInt(val, 10); //converts string to integer
	  //$('input#amount')[0].value = val.toFixed(2);
	  $('input#totalcost_conffee')[0].value = fee_value.toFixed(0); //fill in totalcost section
  });
  $('input:radio[name="bothdays"]').change(function() {
  //$('input[name="bothdays"]').change(function() {
	  var fee_value = parseInt(this.value);
	  $('input#totalcost_conffee')[0].value = fee_value.toFixed(0); //fill in totalcost section
  });


//special case for committee, vendors, etc.
// if attending day selected, fade in special case textbox
$('input#special_case, input[name="attending"]').change(function() {
//var special_case_price = parseInt(0);
  if ( $('input#special_case').val() == '2011' && $('input#attending_friday, input#attending_saturday').is(':checked') ) {
	$('input#single_special').prop('checked', true); //checks the $0 option
	$('input#h_special_case_email').attr('value', 'N'); //sets hidden field for email function
	$('input#pay_by_paypal').prop('disabled', true);
	$('input#pay_by_check').parent().addClass('highlight'); //css({backgroundColor:'#FF6'});
	$('input#totalcost_conffee').val(0); //fill in totalcost section
	$('.various').css({textDecoration:'line-through'});
  } else
  if ( $('input#special_case').val() == '2011' && $('input#attending_both').is(':checked') ) {
	//$('input:radio[id="double_special_case"]').prop('checked', true);
	$('input#double_special').prop('checked', true); //checks the $0 option
	$('input#h_special_case_email').attr('value', 'N'); //sets hidden field for email function
	$('input#pay_by_paypal').prop('disabled', true);
	$('input#pay_by_check').parent().addClass('highlight'); //.css('background', '#FF6');
	$('input#totalcost_conffee').val(0); //fill in totalcost section
	$('.various').css({textDecoration:'line-through'});
  }
});


/* update submit button by payment option */
//$('input:radio[name="payment_options"]').click(function() {
$('input#pay_by_check, input#pay_by_paypal').click(function() {
	var nofee = parseInt(0);
	var fee = parseInt(6);
//if paying by check, set submit button + action/redirect
  if ($('input#pay_by_check').is(':checked')){ // && $('input#notes').is(':empty') ) {
	$('input#submit_registration').attr('value', 'SUBMIT REGISTRATION').css({color:'#FF9', backgroundColor:'#36C'});
	$('.processing').css({textDecoration:'line-through'});
	$('input#totalcost_processing').val(nofee); //(0)
	//$('input#totalcost_processing_sum').val($('input#totalcost_processing').val(nofee));
	//$('input#amount').val(total)
	//MOVED to validation//$('form#registration').attr('action', '/surviving-trauma-conference/registration/process/'); // ACTION !!!

var total = parseInt(0);
    $('input.foo').each(function() {
        total += parseFloat($(this).val());
    });
    $('input#amount').val(total);
  //update hidden fields
  $('input#totalcost_xtshirts_sum').val($('input#totalcost_xtshirts').val());
  $('input#totalcost_conffee_sum').val($('input#totalcost_conffee').val());
  $('input#totalcost_latefee_sum').val($('input#totalcost_latefee').val());
  $('input#totalcost_processing_sum').val($('input#totalcost_processing').val());
  $('input#total_amount').val($('input#amount').val());


  } else if
//if paying by paypal, set submit button + action/redirect
   ($('input#pay_by_paypal').is(':checked')){ // && $('input#notes').is(':empty') ) {
	$('input#submit_registration').attr('value', 'CONTINUE & PAY').css({color:'#FF9', backgroundColor:'#36C'});
	$('.processing').css({textDecoration:'none'});
	$('input#totalcost_processing').val(fee); //(5)
	//$('input#amount').val(total);
	//MOVED to validation//$('form#registration').attr('action', '/surviving-trauma-conference/registration/process/'); // ACTION !!!
	
	var total = parseInt(0);
    $('input.foo').each(function() {
        total += parseFloat($(this).val());
    });
    $('input#amount').val(total);
  //update hidden fields
  $('input#totalcost_xtshirts_sum').val($('input#totalcost_xtshirts').val());
  $('input#totalcost_conffee_sum').val($('input#totalcost_conffee').val());
  $('input#totalcost_latefee_sum').val($('input#totalcost_latefee').val());
  $('input#totalcost_processing_sum').val($('input#totalcost_processing').val());
  $('input#total_amount').val($('input#amount').val());
	
	
  }
});


/* update TOTAL when new amount selected/entered */
//OLD//:radio[name="payment_options"]
$(':radio[name="singleday"], :radio[name="bothdays"], input#extra_tshirt_quantity, input#pay_by_check, input#pay_by_paypal').change(function() {
    //OLD//var total = 0;
	var total = parseInt(0);
    $('input.foo').each(function() {
        total += parseFloat($(this).val());
    });
    $('input#amount').val(total);
  //update hidden fields
  $('input#totalcost_xtshirts_sum').val($('input#totalcost_xtshirts').val());
  $('input#totalcost_conffee_sum').val($('input#totalcost_conffee').val());
  $('input#totalcost_latefee_sum').val($('input#totalcost_latefee').val());
  $('input#totalcost_processing_sum').val($('input#totalcost_processing').val());
  $('input#total_amount').val($('input#amount').val());
});

//get id of certification level to write in plain text
$('input:radio[name="singleday"], input:radio[name="bothdays"]').change(function() {
//$('input[name="singleday"], input[name="bothdays"]').change(function() {
    // get id from options
	var prof_id = $(this).attr('id');//.val();
    // and update the hidden input's value
	$('input#h_profession').val(prof_id);
});



/* temp fix for only allowing #s on specific inputs */
$('input.type_number, input[type="number"], input[type="tel"]').keyup(function () { 
    this.value = this.value.replace(/[^0-9\.]/g,'');
});


/* processing */
$('.loading').hide();
$('input#submit2paypal').click(function(){
    //$('input[name=submit2paypal]', this).attr('disabled', 'disabled');
	$('input#submit2paypal').hide();
	$('.loading').show();
});
//$('#submit_registration').click(function() { /*$('#submit_registration').hide();*/ $('.loading').show(); });


/* honeypot */
$('input#notes').change(function() {
//if ($('#notes').is(':empty')) {
if ($('input#notes').val() == '') {
	$('input#submit_registration, input#submit').prop('disabled', false);
	 } else {
	$('input#submit_registration, input#submit').prop('disabled', true);
	}
});



//////////////////////////////////////////// general.js

	
	// contact form + registration form validation
		var hasChecked = false;
		
		//$("#submit, #submit_registration").click(function () { 
		$('input#submit').submit(function () { 
			hasChecked = true;
			return checkForm();
		});

		$('input#submit_registration').click(function () {
		/* if not IE, fill in value *///if ($('#IE_ver').val() == '') {	$(this).attr('value', 'X'); };
			hasChecked = true;
			return checkForm();
			$('form#registration').attr('action', '/surviving-trauma-conference/registration/process/'); // ACTION !!!
			//$('.loading').show();
		});

		$('.standard #name, .standard #email, .standard #message, input#first_name, input#last_name, input#night_phone_c, input#email_registration, input#tshirt_size, input#address1, input#city, input#state, input#zip, input[name="attending"], input[name="singleday"], input[name="bothdays"], input#license, input[name="payment_options"], input#pay_by_check, input#pay_by_paypal').live('change click', function(){
			if(hasChecked == true)
			{
				return checkForm();
				$('form#registration').attr('action', '/surviving-trauma-conference/registration/process/'); // ACTION !!!
			}
		});
		function checkForm()
		{
			var hasError = false;
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			
			// contact form
			if($('.standard #name').val() == '') {
				$('.standard #error-name').fadeIn();
				hasError = true;
			}else{
				$('.standard #error-name').fadeOut();
			}
			if($('.standard #email').val() == '') {
				$('.standard #error-email').fadeIn();
				hasError = true;
			}else if(!emailReg.test( $('.standard #email').val() )) {
				$('.standard #error-email').fadeIn();
				hasError = true;
			}else{
				$('.standard #error-email').fadeOut();
			}
			if($('.standard #message').val() == '') {
				$('.standard #error-message').fadeIn();
				hasError = true;
			}else{
				$('.standard #error-message').fadeOut();
			}
// registration form
if($('input#first_name').val() == '') { $('span#error-first_name').fadeIn(); hasError = true; }else{ $('span#error-first_name').fadeOut(); }
if($('input#last_name').val() == '') { $('span#error-last_name').fadeIn(); hasError = true; }else{ $('span#error-last_name').fadeOut(); }
if($('input#night_phone_a').val() == '') { $('span#error-phone').fadeIn(); hasError = true; }else{ $('span#error-phone').fadeOut(); }
if($('input#night_phone_b').val() == '') { $('span#error-phone').fadeIn(); hasError = true; }else{ $('span#error-phone').fadeOut(); }
if($('input#night_phone_c').val() == '') { $('span#error-phone').fadeIn(); hasError = true; }else{ $('span#error-phone').fadeOut(); }
if($('input#email_registration').val() == '') { $('span#error-email_registration').fadeIn(); hasError = true; }else if(!emailReg.test( $('#email_registration').val() )) { $('span#error-email_registration').fadeIn(); hasError = true; }else{ $('span#error-email_registration').fadeOut(); }
/*dropdown value will always be 1 = so this validation is not correct */
if($('input#tshirt_size').val() == '' || $('input#tshirt_size').attr('selectedIndex') == 0) { $('span#error-tshirt_size').fadeIn(); hasError = true; }else{ $('span#error-tshirt_size').fadeOut(); }
//if($('input#tshirt_size').length < 1 || $('input#tshirt_size').val() == '') { $('span#error-tshirt_size').fadeIn(); hasError = true; }else{ $('span#error-tshirt_size').fadeOut(); }
//if($('input#tshirt_size').attr('selectedIndex') == 0 || $('input#tshirt_size').val() == '') { $('span#error-tshirt_size').fadeIn(); hasError = true; }else{ $('span#error-tshirt_size').fadeOut(); }

if($('input#address1').val() == '') { $('span#error-address1').fadeIn(); hasError = true; }else{ $('span#error-address1').fadeOut(); }
if($('input#city').val() == '') { $('span#error-city').fadeIn(); hasError = true; }else{ $('span#error-city').fadeOut(); }
////if($('input#state').val() == '') { $('span#error-state').fadeIn(); hasError = true; }else{ $('span#error-state').fadeOut(); }
if($('input#state').val() == '' || $('input#state').attr('selectedIndex') == 0) { $('span#error-state').fadeIn(); hasError = true; }else{ $('span#error-state').fadeOut(); }
//if(/*$('input#state').length == 1 ||*/ $('input#state').val() == '') { $('span#error-state').fadeIn(); hasError = true; preventDefault(); return false; }else{ $('span#error-state').fadeOut(); }

if($('input#zip').val() == '') { $('span#error-zip').fadeIn(); hasError = true; }else{ $('span#error-zip').fadeOut(); }
if($('input[name="attending"]:checked').length < 1) { $('span#error-attending').fadeIn(); hasError = true; }else{ $('span#error-attending').fadeOut(); }
//if( ! $("input[name='attending']").is(':checked')) { $("#error-attending").fadeIn(); hasError = true; }else{ $("#error-attending").fadeOut(); }
//if( ! $('input[name="attending"]').prop('checked')) { $('span#error-attending').fadeIn(); hasError = true; }else{ $('span#error-attending').fadeOut(); }

if( ! $('input[name="singleday"], input[name="bothdays"]').is(':checked')) { $('span#error-fee').fadeIn(); hasError = true; }else{ $('span#error-fee').fadeOut(); $('input#amount').val(total); }
if($('input#license').val() == '') { $('span#error-license').fadeIn(); hasError = true; }else{ $('span#error-license').fadeOut(); }
if($('input[name="payment_options"]:checked').length < 1 /*= 0*/) { $('span#error-payment_option').fadeIn(); hasError = true; }else{ $('span#error-payment_option').fadeOut(); }
////if($('#pay_by_check:checked, input#pay_by_paypal:checked').length < 1) { $('span#error-payment_option').fadeIn(); hasError = true; }else{ $('span#error-payment_option').fadeOut(); }
//if( ! $('input#pay_by_check, input#pay_by_paypal').is(':checked')) { $('span#error-payment_option').fadeIn(); hasError = true; }else{ $('span#error-payment_option').fadeOut(); }
//if( ! $('input#pay_by_check, input#pay_by_paypal').prop('checked')) { $('span#error-payment_option').fadeIn(); hasError = true; }else{ $('span#error-payment_option').fadeOut(); }

			if(hasError == true)
			{
				return false;
			}else{
				return true;
				$('form#registration').attr('action', '/surviving-trauma-conference/registration/process/'); // ACTION !!!
			}
		}
		// end contact form validation

<!--// EOS //-->

/*
$(function () {
if ($.browser.msie) {
$('input:radio').click(function () {
this.blur();
this.focus();
});
}
});
*/

		
}); // end jQuery
