 $(document).ready(function(){
	
	//set class for links to external sites and other document types
	$('#main a[href^="http://"]').addClass('external').attr('target', '_blank');
	$('#main a[href*="wmrmh"]').removeClass('external').attr('target', '_self');

	$('#main a[href$=".pdf"]').addClass('pdf').attr('target','_blank');
	$('#main a[href$=".ppt"]').addClass('powerpoint').attr('target','_blank');
	$('#main a[href$=".doc"]').addClass('word').attr('target','_blank');
	$('#main a[href$=".xls"]').addClass('excel').attr('target','_blank');
	$('#main a[href$=".csv"]').addClass('excel').attr('target','_blank');

	$('a').click(function(){$(this).blur(); });
	
	$('.social_column a[href^="http://"]').removeClass('external').attr('target', '_blank');
	$('#corporate_partners_page a[href^="http://"]').removeClass('external').attr('target', '_blank');
	$('#referral_page a[href^="http://"]').removeClass('external').attr('target', '_blank');

	$('#checkout_date').datepicker();
	$('#checkin_date').datepicker();
	$('#patient_birth_date').datepicker();
	
	$('a[rel*=facebox]').facebox();
	
	/*  Show Hide  */
	$('.view_desc').click(function(){		
		var toggleHide = 'images/templates/hide.gif';
			var toggleShow = 'images/templates/view.gif'; 
			
		var eImg = $(this).children('img'); 
			
			var eDiv = $('div.'+$(this).attr('rel'));
		
		if(eDiv.is(':hidden')){
			$(this).children('img').attr('src', toggleHide); 
				eDiv.show('fast');
			$(".view_img").not(this).children('img').hide('fast');
			
			
			}	
			
			
		else if(eDiv.is(':visible')){
				$(this).children('img').attr('src', toggleShow); 
				eDiv.hide('fast');
			
			}
		
		 $(this).blur();
			
		return false;	
	});

	// jquery odd/even table row background change
	$('table.striped > tr:odd').css('background', '#999999');


	//FAQ
	$('dl.faq').find('dd').hide().end().find('dt').click(function() {
         var answer = $(this).next();
         if (answer.is(':visible')) {
             answer.slideUp();
         } else {
             answer.slideDown();
         }
     });

	 $('#expand_all').toggle(
		function(){
			$(this).text("collapse all");
			$('.expand_section').text('collapse section');
			$('dl.faq dd').slideDown();
		},
		function(){
			$(this).text("expand all");
			$('.expand_section').text('expand section');
			$('dl.faq dd').slideUp();
		}
	 );

	$('.expand_section').toggle(
		function(){
			$(this).text("collapse section");
			$('dl.faq dd.'+$(this).attr('rel')).slideDown();
		},
		function(){
			$(this).text("expand section");
			$('dl.faq dd.'+$(this).attr('rel')).slideUp();
		}
	);

		
	/* DONATION PAGE */	
	// hide on page load
	$('#donate').hide();	
	$('#show_donate_form').click(function(){
		$('#donate').show();
		$('#donate_page_images').hide();
		$('#breakline').show();
		$('#closeform').show();
	});	
	
	$('#closeform').click(function(){
		$('#donate').hide();
		$('#donate_page_images').show();
		$('#breakline').hide();
		$('#closeform').hide();
	});	

	// check that at least one donation field has been filled in
	$('#donate').submit(function(){				
		if( $('input[name=circles_of_caring_level]:radio:checked').length==0 && $('input[name=sponsor_a_night]:radio:checked').length==0 && $('input[name=other_general_amount]').val()=='' && $('input[name=other_memorial_amount]').val()=='' && $('input[name=other_tribute_amount]').val()=='' && $('input[name=other_amount]').val()==''){
				alert('Please let us know how much you are donating.');	
				return false;
		}else if( $('input[name=company_address]').val()=='' && $('input[name=address]').val()==''){
				alert('Please fill in either the address or company address field.');
				
				return false;
		}else{
				return true;
		}

		return false;
		
	});	 
	  // remove other checks/values if circles_of_caring_level is clicked
	 
	  $('input[name=circles_of_caring_level]:radio').click(function(){	
		$('input[name=sponsor_a_night]:radio').removeAttr("checked");
		$('input[name=other_general_amount]').val('');
		$('input[name=other_memorial_amount]').val('');
		$('input[name=other_tribute_amount]').val('');
		$('input[name=other_amount]').val('');
		});

	  $('input[name=sponsor_a_night]:radio').click(function(){	
		$('input[name=circles_of_caring_level]:radio').removeAttr("checked");
		$('input[name=other_general_amount]').val('');
		$('input[name=other_memorial_amount]').val('');
		$('input[name=other_tribute_amount]').val('');
		$('input[name=other_amount]').val('');
		});
	
	  $('input[name=other_general_amount]').change(function(){	
		$('input[name=circles_of_caring_level]:radio').removeAttr("checked");
		$('input[name=sponsor_a_night]]:radio').removeAttr("checked");
		$('input[name=other_memorial_amount]').val('');
		$('input[name=other_tribute_amount]').val('');
		$('input[name=other_amount]').val('');
		});

	  $('input[name=other_memorial_amount]').change(function(){	
		$('input[name=circles_of_caring_level]:radio').removeAttr("checked");
		$('input[name=sponsor_a_night]:radio').removeAttr("checked");
		$('input[name=other_general_amount]').val('');
		$('input[name=other_tribute_amount]').val('');
		$('input[name=other_amount]').val('');
		});

		$('input[name=other_tribute_amount]').change(function(){	
		$('input[name=circles_of_caring_level]:radio').removeAttr("checked");
		$('input[name=sponsor_a_night]:radio').removeAttr("checked");
		$('input[name=other_general_amount]').val('');
		$('input[name=other_memorial_amount]').val('');
		$('input[name=other_amount]').val('');
		});

		$('input[name=other_amount]').change(function(){	
		$('input[name=circles_of_caring_level]:radio').removeAttr("checked");
		$('input[name=sponsor_a_night]:radio').removeAttr("checked");
		$('input[name=other_general_amount]').val('');
		$('input[name=other_memorial_amount]').val('');
		$('input[name=other_tribute_amount]').val('');
		});
		
		if(document.getElementById('go_to_justgive')){	
			$('#go_to_justgive input:submit').click();		
		}
			
		if(document.getElementById('showform')){
			$('form#donate').show();	
		}
			

	/* mothers day campaign form */
	
	$('input[name=mothers_day_contribution]:radio').click(function(){	
		var amount = $(this).val();
		$('input[name=other_mothers_day_amount]').val(amount);
		$('input[name=other_mothers_day_amount]').css({color : '#000'});
	});
	
	$('input[name=other_mothers_day_amount]').change(function(){
		var amount = $(this).val();
		$(this).css({color : '#000'});
		if(amount!=''){
			if (isNaN(amount)) {
				alert("the number must be an integer");
				$('input[name=other_mothers_day_amount]').css({color : '#c00'}).val('0');
				$("input[name=other_mothers_day_amount]").focus();  
				
				return false;
			}		
			amount = Math.floor(amount);
			$(this).val(amount);
			return true;
		}
	});

	$('#roomrequest_page').submit(function(){
		var $msg = 'Guests Name and Birthdate must be entered';
		if( $('#guest1_name').val()!='' && $('#guest1_birthdate').val()=='' ){
			alert($msg);
			return false;
		}else if ($('#guest1_name').val()=='' && $('#guest1_birthdate').val()!='')
		{
			alert($msg);
			return false;
		}else if ($('#guest2_name').val()!='' && $('#guest2_birthdate').val()=='' )
		{
			alert($msg);
			return false;
		}else if ($('#guest2_name').val()=='' && $('#guest2_birthdate').val()!='')
		{
			alert($msg);
			return false;
		}else if ($('#guest3_name').val()!='' && $('#guest3_birthdate').val()=='' )
		{
			alert($msg);
			return false;
		}else if ($('#guest3_name').val()=='' && $('#guest3_birthdate').val()!='')
		{
			alert($msg);
			return false;
		}else if ($('#guest4_name').val()!='' && $('#guest4_birthdate').val()=='' )
		{
			alert($msg);
			return false;
		}else if ($('#guest4_name').val()=='' && $('#guest4_birthdate').val()!='')
		{
			alert($msg);
			return false;
		}	
		else{
			return true;
		}
		
	
	});


// BIKE TOUR DONATION

 if( $('#biketourdonation input[name=submit_form]') ) {

	$('input[name=amount]').change(function() {
		var amount = $(this).val();
		$(this).css({color : '#000'});
		
		if(amount!=''){	
		
			if ( isNaN(amount) ) {
				
				alert(" the amount of donation must be an number only. Please do not add a $ sign or commas to the number. ");
				$(this).css({color : '#c00'}).val('');
				$(this).focus();  	
				return false;
				
			}
		
			if(amount < 1){
				alert(" the number entered for amount of donation must be at least one dollar. ");
				$(this).css({color : '#c00'}).val('');
				$(this).focus();  	
				return false;
					
			}
		
		}
	
	});// close on change
	
	
	// remove rider selected if team is chosen
	$('select[name=team_id]').change(function(){		
	  
		if( $('select[name=team_id]').val()!=0 ){
			$('select[name=rider_id]').val(0);

		}
			
	});// close on change

	// remove team selected if rider is chosen
	$('select[name=rider_id]').change(function(){		
	  
		if( $('select[name=rider_id]').val()!=0 ){
			$('select[name=team_id]').val(0);

		}
			
	});// close on change




}	
		




		
});


