$(document).ready(function(){
		///////////////////////////////////////////////////////////////////////////////////
		///////////////////////////// SEARCH FUNCTIONS ////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////
		var volunteer = '<option value="uid">uid</option><option value="email">email</option><option value="username">username</option><option value="password">password</option><option value="name">name</option><option value="fname">fname</option><option value="lname">lname</option><option value="sex">sex</option><option value="birthday_month">birthday_month</option><option value="birthday_day">birthday_day</option><option value="birthday_year">birthday_year</option><option value="dob">dob</option><option value="registered">registered</option><option value="familyMember">familyMember</option><option value="verified">verified</option><option value="personalMessage">personalMessage</option><option value="donorConfirmation">donorConfirmation</option><option value="donationNotice">donationNotice</option><option value="facebookID">facebookID</option><option value="phone">phone</option><option value="cellphone">cellphone</option><option value="country">country</option><option value="c_address">c_address</option><option value="c_city">c_city</option><option value="c_state_province">c_state_province</option><option value="c_postalcode">c_postalcode</option><option value="p_address">p_address</option><option value="p_city">p_city</option><option value="p_state_province">p_state_province</option><option value="p_postalcode">p_postalcode</option><option value="pastvolunteer">pastvolunteer</option><option value="dietaryneeds">dietaryneeds</option><option value="medicalconsiderations">medicalconsiderations</option><option value="tshirt">tshirt</option><option value="reference">reference</option><option value="educationexperience">educationexperience</option><option value="volunteerexperience">volunteerexperience</option><option value="workexperience">workexperience</option><option value="pasttrips">pasttrips</option><option value="expectations">expectations</option><option value="othernotes">othernotes</option><option value="emergencyname">emergencyname</option><option value="emergencyphone">emergencyphone</option><option value="emergencyrelationship">emergencyrelationship</option><option value="languageRating">languageRating</option><option value="lanaguageRating">lanaguageRating</option><option value="admin">admin</option><option value="date">date</option>';
		var volunteer_checkbox = '<input type="checkbox" class="selectedColumn" value="uid" checked /> UID';
		
		var trip = '<option value="trip_id">trip_id</option><option value="uid">uid</option><option value="team_id">team_id</option><option value="group_id">group_id</option><option value="startdate">startdate</option><option value="enddate">enddate</option><option value="startdateText">startdateText</option><option value="enddateText">enddateText</option><option value="weeks">weeks</option><option value="location">location</option><option value="a_airport">a_airport</option><option value="a_airline">a_airline</option><option value="a_flight">a_flight</option><option value="a_time">a_time</option><option value="a_time_ap">a_time_ap</option><option value="d_airport">d_airport</option><option value="d_airline">d_airline</option><option value="d_flight">d_flight</option><option value="d_time">d_time</option><option value="d_time_ap">d_time_ap</option><option value="deposit_duedate">deposit_duedate</option><option value="funds_duedate">funds_duedate</option><option value="flights_duedate">flights_duedate</option><option value="program_fee">program_fee</option><option value="transportation_fee">transportation_fee</option><option value="esu_scholarship">esu_scholarship</option><option value="group_scholarship">group_scholarship</option><option value="leader_scholarship">leader_scholarship</option><option value="child_scholarship">child_scholarship</option><option value="leaders">leaders</option><option value="communication_welcome">communication_welcome</option><option value="communication_funds">communication_funds</option><option value="communication_flights">communication_flights</option><option value="confirmationCall">confirmationCall</option><option value="waiver">waiver</option><option value="type">type</option><option value="focus">focus</option><option value="programCountry">programCountry</option><option value="program">program</option><option value="religiousFocus">religiousFocus</option><option value="cancelled">cancelled</option><option value="tshirt">tshirt</option><option value="shirt_sent">shirt_sent</option><option value="funds_goal">funds_goal</option><option value="responsible">responsible</option><option value="teamLeader">teamLeader</option><option value="facebookPage">facebookPage</option><option value="estrellaMessage">estrellaMessage</option><option value="donationNotice">donationNotice</option><option value="donorMessage">donorMessage</option><option value="donorConfirmation">donorConfirmation</option><option value="surveySent">surveySent</option><option value="quicklink">quicklink</option><option value="date">date</option>';
		
		var team = '<option value="teamname">teamname</option><option value="team_id">team_id</option><option value="group_id">group_id</option><option value="groupname">groupname</option><option value="participants">participants</option><option value="leaders">leaders</option><option value="startdate">startdate</option><option value="enddate">enddate</option><option value="startdateText">startdateText</option><option value="enddateText">enddateText</option><option value="weeks">weeks</option><option value="location">location</option><option value="funds_goal">funds_goal</option><option value="program_fee">program_fee</option><option value="group_fee">group_fee</option><option value="scholarships">scholarships</option><option value="group_scholarship">group_scholarship</option><option value="esu_scholarship">esu_scholarship</option><option value="leader_scholarship">leader_scholarship</option><option value="child_scholarship">child_scholarship</option><option value="minors">minors</option><option value="total_expense">total_expense</option><option value="transportation_fee">transportation_fee</option><option value="total_credit">total_credit</option><option value="total_due">total_due</option><option value="deposit">deposit</option><option value="deposit_duedate">deposit_duedate</option><option value="funds_duedate">funds_duedate</option><option value="flights_duedate">flights_duedate</option><option value="funds_raised">funds_raised</option><option value="leader_id">leader_id</option><option value="leader_name">leader_name</option><option value="a_airport">a_airport</option><option value="a_flight">a_flight</option><option value="a_time">a_time</option><option value="d_airport">d_airport</option><option value="d_flight">d_flight</option><option value="d_time">d_time</option><option value="focus">focus</option><option value="type">type</option><option value="programCountry">programCountry</option><option value="program">program</option><option value="religiousFocus">religiousFocus</option><option value="cancelled">cancelled</option><option value="cancelled_date">cancelled_date</option><option value="shirts_sent">shirts_sent</option><option value="survey_sent">survey_sent</option><option value="responsible">responsible</option><option value="date">date</option><option value="communication_welcome">communication_welcome</option><option value="communication_funds">communication_funds</option><option value="communication_flights">communication_flights</option><option value="confirmationCall">confirmationCall</option><option value="communication_posttrip">communication_posttrip</option><option value="tshirt">tshirt</option><option value="teamMessage">teamMessage</option>';
		
		var donor = '<option value="lname">lname</option><option value="donor_id">donor_id</option><option value="fname">fname</option><option value="email">email</option><option value="address">address</option><option value="street">street</option><option value="city">city</option><option value="state_province">state_province</option><option value="state">state</option><option value="postal_code">postal_code</option><option value="zip">zip</option><option value="country">country</option><option value="phone">phone</option><option value="cellphone">cellphone</option><option value="amount">amount</option><option value="volunteer_credit">volunteer_credit</option><option value="team_credit">team_credit</option><option value="team_id">team_id</option><option value="trip_id">trip_id</option><option value="herofund_id">herofund_id</option><option value="heroteam_id">heroteam_id</option><option value="rid">rid</option><option value="check_number">check_number</option><option value="type">type</option><option value="method">method</option><option value="fund">fund</option><option value="payer_id">payer_id</option><option value="order_num">order_num</option><option value="gift_greeting">gift_greeting</option><option value="gift_firstname">gift_firstname</option><option value="gift_lastname">gift_lastname</option><option value="gift_email">gift_email</option><option value="calendars">calendars</option><option value="unique_id">unique_id</option><option value="session_id">session_id</option><option value="shipping_street">shipping_street</option><option value="shipping_city">shipping_city</option><option value="shipping_state">shipping_state</option><option value="shipping_zip">shipping_zip</option><option value="shipping_country">shipping_country</option><option value="date">date</option><option value="company">company</option><option value="recurring">recurring</option><option value="recurring_id">recurring_id</option><option value="recurring_type">recurring_type</option><option value="terms">terms</option><option value="sent">sent</option><option value="annonymous">annonymous</option><option value="hero">hero</option><option value="tshirt">tshirt</option><option value="unsubcribe">unsubcribe</option><option value="REMOTE_ADDR">REMOTE_ADDR</option>';
		
		var contact = '<option value="contact_id">contact_id</option><option value="firstname">firstname</option><option value="company">company</option><option value="lastname">lastname</option><option value="email">email</option><option value="school">school</option><option value="address">address</option><option value="city">city</option><option value="state_province">state_province</option><option value="country">country</option><option value="postal_code">postal_code</option><option value="phone">phone</option><option value="comments">comments</option><option value="call">call</option><option value="groupContact">groupContact</option><option value="question">question</option><option value="refer">refer</option><option value="education">education</option><option value="spanish">spanish</option><option value="public_health">public_health</option><option value="dental">dental</option><option value="medical">medical</option><option value="literacy">literacy</option><option value="agriculture">agriculture</option><option value="long_term">long_term</option><option value="christian">christian</option><option value="college">college</option><option value="highschool">highschool</option><option value="nursing">nursing</option><option value="socialwork">socialwork</option><option value="segments">segments</option><option value="date">date</option>';
		
		$('#columnSelection').live('click', function(){
			$('#columnSelect').toggle();
		});
		
		$('#dbSearchForm .table').live('click', function () {
			$('.columns').html('');
			switch($(this).attr('array')) {
				case 'volunteer' : 
					$('.columns').append(volunteer);
					$('#columnSelect').append(volunteer_checkbox);
				break;
				case 'trip' : 
					$('.columns').append(trip);
					$('.columnSelection').append(trip);
				break;
				case 'team' : 
					$('.columns').append(team);
					$('.columnSelection').append(team);
				break;
				case 'donor' : 
					$('.columns').append(donor);
					$('.columnSelection').append(donor);
				break;
				case 'contact' : 
					$('.columns').append(contact);
					$('.columnSelection').append(contact);
				break;
			}
		});
		$('.newSearchField').live('click',function(){
			var DB_array = $('.table:checked').attr('array');
			var boolean = $(this).attr('type');
			switch(DB_array) {
				case 'volunteer' : 
					var optionFields = volunteer;
				break;
				case 'trip' : 
					var optionFields = trip;
				break;
				case 'team' : 
					var optionFields = team;
				break;
				case 'donor' : 
					var optionFields = donor;
				break;
				case 'contact' : 
					var optionFields = contact;
				break;
			}
			$('#addSearch').remove();
			$('.addToSearch').replaceWith('<div><input type="hidden" name="boolean[]" value="' + boolean + '" /><select class="columns" name="field[]">' + optionFields + '</select><select name="inequality[]"><option value="LIKE">LIKE</option><option value="=">=</option><option value=">=">>=</option><option value="<="><=</option></select><input type="text" name="search[]" id="value" alt="date-us"/> <span id="addSearch"><a class="newSearchField" type="AND" href="#">AND</a> | <a class="newSearchField" type="OR" href="#">OR</a></span></div><div class="addToSearch"></div>');
			return false;
		});
		///////////////////////////////////////////////////////////////////////////////////
		$(function() {
			var dates = $('.regstartdate, .regenddate').datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 2,
				beforeShowDay: $.datepicker.onlySaturday,
				onSelect: function(selectedDate) {
					var option = this.id == "startdate" ? "minDate" : "maxDate";
					var instance = $(this).data("datepicker");
					var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
					dates.not(this).datepicker("option", option, date);
				}
			});
		});
		////////////////////////////////////////////////////////////////////////////////////
		////////////////////////// NICARAGUA DATES /////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////////////
		$('#programCountry').live('change', function(){
			if($(this).val() == 'Nicaragua'){
				$.facebox('<h3>Nicaragua Program!</h3><p>Thank you for choosing to make a difference in Nicaragua! This message is to notify you that the program donation for our Nicaragua program is $1000/week with no scholarships. This is because it is a new program for Orphanage Outreach, and our costs/volunteer are higher than in the Dominican Republic.</p><p>We encourage you to start sending out letters to friends and family early to give yourself plenty of time to raise the necessary funds. Your efforts pre-trip and during your trip will have a significant impact in Nicaragua! Thank you!</p>');
				$(".regstartdate, .regenddate").datepicker( "destroy" );
				var nicListStart = new Array();
						nicListStart.push("20101226");
						nicListStart.push("20101229");
						nicListStart.push("20110105");
						nicListStart.push("20110227");
						nicListStart.push("20110306");
						nicListStart.push("20110313");
					var nicListEnd = new Array();
						nicListEnd.push("20110102");
						nicListEnd.push("20110105");
						nicListEnd.push("20110112");
						nicListEnd.push("20110306");
						nicListEnd.push("20110313");
						nicListEnd.push("20110320");
					
				$(function() {
					var dates = $('.regstartdate').datepicker({
					  minDate: $.datepicker.parseDate('yymmdd', nicListStart[0]), //this makes the datepicker start at the first available
					  numberOfMonths: 2, beforeShowDay: function(dateToShow){
						return [($.inArray($.datepicker.formatDate('yymmdd', dateToShow),nicListStart) >= 0), ""]; 
					  }
					});
				});
					
				$(function() {
					var dates = $('.regenddate').datepicker({
					  minDate: $.datepicker.parseDate('yymmdd', nicListEnd[0]), //this makes the datepicker start at the first available
					  numberOfMonths: 2, beforeShowDay: function(dateToShow){
						return [($.inArray($.datepicker.formatDate('yymmdd', dateToShow),nicListEnd) >= 0), ""]; 
					  }
					});
				});
			} else {
				$(".regstartdate, .regenddate").datepicker( "destroy" );
				$(function() {
					var dates = $('.regstartdate, .regenddate').datepicker({
							defaultDate: "+1w",
							changeMonth: true,
							numberOfMonths: 2,
							beforeShowDay: $.datepicker.onlySaturday,
							onSelect: function(selectedDate) {
								var option = this.id == "startdate" ? "minDate" : "maxDate";
								var instance = $(this).data("datepicker");
								var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
								dates.not(this).datepicker("option", option, date);
							}
					});
				});
			}
		});
		
		////////////////////////////////////////////////////////////////////////////////////
		////////////////////////// PROGRAM CHANGE //////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////////////
		
		$('#program').live('change', function(){
			if($(this).val() == 'Health Corps - Medical Clinic' || $(this).val() == 'Health Corps - Dental Clinic'){
				$.facebox('<h3>Health Corps Clinics!</h3><p>Thank you for choosing to make a difference through our Health Corps Clinics! Our clinics for 2011 are scheduled for <strong>February 26- March 19, 2011 </strong></p>Health Corps medical and dental clinics are open to medical and dental professionals, and students enrolled in an program resulting in a health certification - pharmacy, nursing, medical school, dental school, etc. Pre-med, pre-dental and public health students are invited to join our public health education program at any time throughout the year - you\'ll be making a long term difference by teaching nutrition, hygiene, disease prevention, dental health, and more.</p><p>Because of the significantly higher costs conducting a clinic versus a normal teaching volunteer experience, program donations for clinics will not include scholarships - there are no group scholarships, early sign up scholarships, etc.  We encourage you to start sending out letters to friends and family early to give yourself plenty of time to raise the necessary funds. Your efforts pre-trip and during your trip will have a significant impact to the program! Thank you!</p>');
				if($('#programCountry').val() != 'Nicaragua'){
					$(".regstartdate, .regenddate").datepicker( "destroy" );
					$(function() {
						var dates = $('.regstartdate').datepicker({
							minDate: new Date(2011, 2-1, 26),
							maxDate: new Date(2011, 3-1, 12),
							changeMonth: true,
							numberOfMonths: 2,
							beforeShowDay: $.datepicker.onlySaturday,
							onSelect: function(selectedDate) {
								var option = this.id == "startdate" ? "minDate" : "maxDate";
								var instance = $(this).data("datepicker");
								var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
								dates.not(this).datepicker("option", option, date);
							}
						});
					});
					$(function() {
						var dates = $('.regenddate').datepicker({
							minDate: new Date(2011, 3-1, 5),
							maxDate: new Date(2011, 3-1, 19),
							changeMonth: true,
							numberOfMonths: 2,
							beforeShowDay: $.datepicker.onlySaturday,
							onSelect: function(selectedDate) {
								var option = this.id == "startdate" ? "minDate" : "maxDate";
								var instance = $(this).data("datepicker");
								var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
								dates.not(this).datepicker("option", option, date);
							}
						});
					});
				}
			} else {
				if($('#programCountry').val() != 'Nicaragua'){
					$(".regstartdate, .regenddate").datepicker( "destroy" );
					$(function() {
						var dates = $('.regstartdate, .regenddate').datepicker({
								defaultDate: "+1w",
								changeMonth: true,
								numberOfMonths: 2,
								beforeShowDay: $.datepicker.onlySaturday,
								onSelect: function(selectedDate) {
									var option = this.id == "startdate" ? "minDate" : "maxDate";
									var instance = $(this).data("datepicker");
									var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
									dates.not(this).datepicker("option", option, date);
								}
						});
					});
				}
			}
		});
		////////////////////////////////////////////////////////////////////////////////////
		////////////////////////// END DATES  //////////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////////////	
		
		
		$(function() {
			var dates = $('.adminInsuranceStartdate, .adminInsuranceEnddate').datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 2,
				onSelect: function(selectedDate) {
					var option = this.id == "adminInsuranceStartdate" ? "minDate" : "maxDate";
					var instance = $(this).data("datepicker");
					var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
					dates.not(this).datepicker("option", option, date);
				}
			});
		});
		$(function() {
			var dates = $('.adminScheduleStartdate, .adminScheduleEnddate').datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 2,
				onSelect: function(selectedDate) {
					var option = this.id == "adminScheduleStartdate" ? "minDate" : "maxDate";
					var instance = $(this).data("datepicker");
					var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
					dates.not(this).datepicker("option", option, date);
				}
			});
		});
		$(function() {
			var dates = $('.adminDonorStartdate, .adminDonorEnddate').datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 2,
				onSelect: function(selectedDate) {
					var option = this.id == "adminDonorStartdate" ? "minDate" : "maxDate";
					var instance = $(this).data("datepicker");
					var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
					dates.not(this).datepicker("option", option, date);
				}
			});
		});
		$(function() {
			var dates = $('.adminSurveyStartdate, .adminSurveyEnddate').datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 2,
				onSelect: function(selectedDate) {
					var option = this.id == "adminSurveyStartdate" ? "minDate" : "maxDate";
					var instance = $(this).data("datepicker");
					var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
					dates.not(this).datepicker("option", option, date);
				}
			});
		});
				
		// VALIDATE REGISTRATION ON SUBMIT
		$('#regSubmit').live('click',function() {
			var error = 0;
			$('.check').each(function(){
				if($(this).val() == '' || $(this).val() == '-1'){
					error = 1;
					$(this).css('border-color', 'red');
				} else 
					$(this).css('border-color', '');
			});
			
			//Validate email fields
			if($('#email').val()!= $('#email2').val()){
				error = 2;
				$('.emailValidate').html('*match e-mails').show();
			} else $('.emailValidate').html('*match e-mails').hide();
			//Validate password fields
			if($('#passwordcheck1').val() != $('#passwordcheck2').val()){
				error = 3;
				$('.passwordValidate').html('*match passwords').show();
			} else $('.passwordValidate').html('*match passwords').hide();
			
			if(error != 0){
				alert('Please make sure that all fields are filled in correctly and email/passwords match');
				return false;
			} else{
				$('#overlay').show();
				$('#loading').show();
			}
		});
		
		//WAIVER SUBMIT
		$('#waiverSubmit').click(function() {
			var error = 0; 
			$('.waiver').each(function(){
				if($(this).attr('checked') == false) {
					error = 1;
					$(this).css('border-color', 'red');
				}else 
					$(this).css('border-color', '');
			});
			
			// Take action based on error response
			if(error != 0){
				alert('Please check that you have read and agree to all sections of the Waiver Agreement');
				return false;
			} else{
				$('#overlay').show();
				$('#loading').show();
			}
		});
		
		$('#username').live('blur',function() {
			var username = $(this).val();
			$('.checkUsername').html('<img src="/media/images/process.gif" />');
			$.get('/registration/checkUsername',{username:username},function(check){
				if(check > 0){
					$('.checkUsername').html('<span style="color:#FF0000">username taken</span>');
					$('input[type=text]').attr('disabled','true');
					$('#username').attr('disabled','');
				}else{
					$('.checkUsername').html('<span style="color:#009900">Available</span>');
					$('input[type=text]').attr('disabled','');
				}
			});
		});
		
		$('.checkEmail').live('blur',function() {
			var email = $(this).val();
			$('.checkEmail').html('<img src="/media/images/process.gif" />');
			$.get('/registration/checkEmail',{email:email},function(check){
				if(check > 0){
					$.facebox('<h3>Email on File!</h3><p class="caption">The email address that you have entered is already on file. Please login to register for a new Orphanage Outreach trip. Logging in to register is fast and easy as your previous information is on file.</p><p class="caption">If you are trying to register a family member, you will be able to do so on your family page in <a href="/connect">OO Connect</a></p><ul><li><a href="/connect">login now</a></li><li><a href="/connect/help/login">forgot username/password?</a></li></ul>');
					$('.checkEmail').html('');
					$('input[type=text]').attr('disabled','true');
				}
					$('.checkEmail').html('');
			});
		});
		
		$('.adminEditPage').live('click',function(){
			var pid = $(this).attr('pid');
			area1 = new nicEditor({fullPanel : true,onSave : function(content, id, instance){
					//confirm("Save changes to this page?");
					$.post("/process/editSite", { content: content, pid: pid });
					//alert("Content has been saved");
					area1.removeInstance('adminEditArea');											  
			}}).panelInstance('adminEditArea',{hasPanel : true});
			return false;
		});
		
		$('.editTripPersonalMessage').live('click',function(){
			var trip_id = $(this).attr('trip_id');
			area1 = new nicEditor({fullPanel : true,onSave : function(content, id, instance){
					$.post("/connect/editPersonalMessage", { content: content, trip_id: trip_id });
					area1.removeInstance('tripPersonalMessage');											  
			}}).panelInstance('tripPersonalMessage',{hasPanel : true});
			return false;
		});
		
		$('.editTeamMessage').live('click',function(){
			var team_id = $(this).attr('team_id');
			area1 = new nicEditor({fullPanel : true,onSave : function(content, id, instance){
					$.post("/connect/editTeamMessage", { content: content, team_id: team_id });
					area1.removeInstance('TeamMessage');											  
			}}).panelInstance('TeamMessage',{hasPanel : true});
			return false;
		});
		
		$('.editDonorMessage').live('click',function(){
			var trip_id = $(this).attr('trip_id');
			area1 = new nicEditor({fullPanel : true,onSave : function(content, id, instance){
					$.post("/connect/editDonorConfirmation", { content: content, trip_id: trip_id });
					area1.removeInstance('tripDonorMessage');											  
			}}).panelInstance('tripDonorMessage',{hasPanel : true});
			return false;
		});
		
		 $("#stwTemplate").live('change',function () {	
				var str = $(this).val();
				if (str > 0){
					$.get("/connect/getTemplate",{email_id: str}, function(returned_data){
						var hashes = location.href.slice(location.href.indexOf('?') + 1).split('&');
						var hash = hashes[0];
						var myNewString = returned_data.replace("[teamlink]", "http://www.orphanage-outreach.org/hero/team?" + hash);												   
						$("#stwMessage").val(myNewString);
					});
				} else
					cleartext('#message');	
		});
		 
		(function($){
			// call setMask function on the document.ready event
			$(
				function(){
					$('#phone').setMask('phone-us'); // options are explained below and are optional
					$('#cellphone').setMask('phone-us'); // options are explained below and are optional
					$('#emergencyphone').setMask('phone-us'); // options are explained below and are optional
					$('#decimal-us').setMask('decimal-us'); // options are explained below and are optional
					$('#cardNumber').setMask('all-credit');
				}
			);
		})(jQuery);
		
		 $("#cardType").live('change',function () {
			if($("#cardType").val() == 'amex'){
				$("#cardNumber").attr("maxlength","15"); 
				$("#cardNumber").val(""); 
				$("#CVV2").val(""); 
				$("#CVV2").attr("maxlength","4"); 
				$('#cardNumber').setMask('amex-credit'); // options are explained below and are optional
			}
			else{
				$("#cardNumber").attr("maxlength","16"); 
				$("#cardNumber").val(""); 
				$("#CVV2").val(""); 
				$("#CVV2").attr("maxlength","3");
				$('#cardNumber').setMask('all-credit'); // options are explained below and are optional
			}
		});
		 
		 $(".recurringToggle").live('change',function(){
			if($(this).val() == 1) {
				$('#recurring_type').removeAttr('disabled');
				$('#terms').removeAttr('disabled');
				$('#tshirt').removeAttr('disabled');
			}   
			if($(this).val() == 0) {
				$('#recurring_type').attr('disabled', true);
				$('#terms').attr('disabled', true);
				$('#tshirt').attr('disabled', true);
			}
		});
		 
		$('#donationProcess').live('click',function(){
			$('#overlay').show();
			$('#loading').show();
		});
		
		$('#submitDonation').live('click',function(){
			var error = 0;
			$('.check').each(function(){
				if($(this).val() == '' || $(this).val() == '-1'){
					error = 1;
					$(this).css('border-color', 'red');
				} else 
					$(this).css('border-color', '');
			});
			
			if(error != 0){
				alert('Please make sure that all fields are filled in.');
				return false;
			}
		});
		
		$('#commentText').live('click',function(){
			$(this).css({'height':'50px','color':'#000000','margin-bottom':'2px'});
			$(this).val('');
			$(this).removeAttr('id');
			$('#commentSubmit').show();									 
			$('#commentName').show();
		});
		$('#commentName').live('click',function(){
			$(this).val('');
			$(this).css('color','#000000');
		});
		
		$('a[rel*=facebox]').facebox();
		
		$("#submitQuickLink").live('click',function(){
			$.get('/connect/checkQuicklink?type=check',$('#updatequicklink').serialize(),function(data){
				if(data == 1)
					$('#quicklinkResponse').html('quicklink taken; try again.');
				else{
					$.get('/connect/checkQuicklink?type=update',$('#updatequicklink').serialize(),function(getit){
						$('#quicklinkResponse').html('quicklink updated!');
						$('#quickLinkChange').html(getit);
					});
				}
			});
			return false;
		 });
		
		$('.showPhotoLink').live('click', function(){
			var photoLink = $(this).attr('rel');
			alert(photoLink);
			return false;
		});
		
		$('.contentVideo').live('mouseenter',function(){
			$('.playButton').css("background-image","url(/media/images/videos/play-hover.png)");
		}).live('mouseleave', function () {
			$('.playButton').css("background-image","url(/media/images/videos/play.png)");
		});
	
		
});
