jQuery.noConflict();
	jQuery(document).ready(function($){
		
		//Global variables
		
		if ( DOMAIN_TRACKING ) {
		var trackDomains = DOMAIN_TRACKING.split(',');
		for (var i=trackDomains.length-1;i>=0;i--) {
			$('a[href*="'+trackDomains[i]+'"], form[action*="'+trackDomains[i]+'"]').addClass('track-crossdomain');
		}
	}
	
	$('.track, .track-crossdomain').each(function() {
		var tag = '';
		if ( this.name ) {
			tag = '/'+this.name.replace(/:/g,'/');
		}
		if($(this).is('form')) {
			var a = $(this).attr('action');
			$(this).submit(function() {
				if (tag) { pageTracker._trackEvent('form', 'submit', tag); }
				if ( $(this).hasClass('track-crossdomain') ) {
					$(this).attr({action:a+'?'+$(this).serialize(), method:'post'});
					pageTracker._linkByPost(this);
				}
			});
		} else {
			$(this).click(function(e) {
				if (tag) { pageTracker._trackEvent('link','click', tag); }
				if ( $(this).hasClass('track-crossdomain') ) {
					e.preventDefault();
					var l = pageTracker._getLinkerUrl(this.href);
					$(this).attr('target')=='_blank'?window.open(l,''):window.location=l;
				}
			});
		}
	});


	// Pacakges Details Ajax
	$('.getawayWrapper').each(function(){
		var x = $(this);
		$(".getawayDetails",x).hide();
		$(".linkExpand",x).toggle(function(){
			$(this).html('Hide Details');
			$.get('/package-details.php', { package_id: this.id.substr(3), channel: this.rel },function(data) { 
				$(".getawayDetails",x).html('').html(data).slideDown('slow');
			});
		}, function(){
			$(this).html('View Details');
			$(".getawayDetails",x).slideUp('slow').html('');
		});
	});

	// PPC pages details (no include)
	$('.ppcGetawayWrapper').each(function(){
		var x = $(this);
		$(".getawayDetails",x).hide();
		$(".linkExpand",x).toggle(function(){
			$(this).html('Hide Details');
			$(".getawayDetails",x).slideToggle('slow');
		}, function(){
			$(this).html('View Details');
			$(".getawayDetails",x).slideToggle('slow');
		});
	});

			
			IE6 = ($.browser.msie&&$.browser.version=='6.0')?true:false;
			IE7 = ($.browser.msie&&$.browser.version=='7.0')?true:false;
			SAFARI = ($.browser.safari)?true:false;
			
			$('form').initializeForm();
			
			$('div#promo-codes').hide();
			$('a#promo-link').click(function() { 
				$('div#promo-codes').show();
				if (IE6)
					$('form.booking-form select').hide();	
				return false;
			});
			
			if ( ($('input#promo').val() != '') || ($('input#group_code').val() != '') || ($('input#iata_code').val() != '') ) {
				$('div#promo-code-wrapper').css('background',' url("../images/check-bg.gif") no-repeat 68px 21px');
			} 
			
			$('a#done-link').click(function() { 
				$('div#promo-codes').hide();		
				if ( ($('input#promo').val() != '') || ($('input#group_code').val() != '') || ($('input#iata_code').val() != '') ) {
					$('div#promo-code-wrapper').css('background',' url("../images/check-bg.gif") no-repeat 68px 21px');
				} else {
					$('div#promo-code-wrapper').css('background','none');	
				}
				if (IE6) {
					$('form.booking-form select').show();						
				}
				return false;
			});
	});
	
	
(function($) {		  
	$.fn.initializeForm = function() {
		return this.each(function() {
			var form = $(this);
			
			if(IE6) {
				$(".textfield")
					.focus(function() { $(this).css({backgroundColor: "#fdfcfa"}); })
					.blur(function() { $(this).css({backgroundColor: "#ffffff"}); });			
			}
			
			$(".date-picker", form).each(function() {
				$(this).datepicker({ 
					duration: "", 
					showOn: "both",
					beforeShow: setDatePicker,
					hideIfNoPrevNext: true,
					buttonImage: "/images/icon-cal-new.gif", 
					buttonImageOnly: true 
				});
				
				if($(this).val()=='mm/dd/yyyy')
					$(this).val('');
				else {
					if($(this).hasClass('date-end')&&$(this).hasClass('update-blocks'))
						getRange();
				}
			}).attr("readonly", "readonly");
			
			function setDatePicker(input) {
				if(($(input).hasClass('date-begin')||$(input).hasClass('date-end'))&&$(input).hasClass('update-blocks')){
					return {
						minDate: ($(input).hasClass('date-end') ? ($(".date-begin", $(input).parent().prev()).datepicker("getDate") ? $(".date-begin", $(input).parent().prev()).datepicker("getDate") : new Date()) : new Date()), 
						maxDate: ($(input).hasClass('date-begin') ? $(".date-end", $(input).parent().next()).datepicker("getDate") : null),
						onClose: getRange
					}; 
				} else  {
					return {
						minDate: ($(input).hasClass('date-end') ? ($(".date-begin", $(input).parent().prev()).datepicker("getDate") ? $(".date-begin", $(input).parent().prev()).datepicker("getDate") : new Date()) : new Date()), 
						maxDate: ($(input).hasClass('date-begin') ? $(".date-end", $(input).parent().next()).datepicker("getDate") : null)
					};				
				} 
			} 
			
			function getRange() {
				var start = $(".date-begin", form).datepicker("getDate");
				var end = $(".date-end", form).datepicker("getDate");
				
				if(start&&end) {
					var one_day=1000*60*60*24;
					var days = Math.ceil((end.getTime()-start.getTime())/(one_day))					
					createBlock(start, days, form);
					createMeeting(start, days, form);
				}
			}

			// hide all "other" fields
			$("ul.checkboxgroup input.other", form).not(':radio, :checkbox').hide();
			$("ul.checkboxgroup input:not(:text)", form).click(function() {
				if($(this).hasClass('other')) {
					$(this).siblings().addClass('required').show();
					if(!$(this).is(':checked')) {
						$('.validation-error', $(this).parents('ul')).removeError(form);
						$(this).siblings().removeClass('required').filter(':text').hide();
					}
				} else if($(this).is(':radio')) {
					$('.validation-error', $(this).parents('ul')).removeError(form);
					$('.other', $(this).parents('ul')).siblings().removeClass('required').filter(':text').hide();
				}
			});
			
			$("div.select-other", form).hide();
			// if "Other" is selected, then show it's "other" field
			$("select.select-other", form).change( function () {
				var el = $(this).parent().next()
				if($(this).val() == "--") {
					el.show().children('label, input').addClass("required");
				} else {
					el.hide().children().removeClass("required").find("input").val("");
					$('.validation-error', el).removeError(form);
				}
			});

		});
	};
	
	/*$.fn.formValidate = function() {
		return this.each(function() {
			var form = $(this);
			$('.submit', form).click(function() {
				var _errors = '';
				//Removes validation errors from previous submit
				$('.validation-error', form).removeError(form);	
				
				$('.required:not(label)', form).each(function() {
					var valid = true;
					
					if($(this).is(':input')) {
						var o = $.trim($(this).val());
						
						if($(this).hasClass('email')) {
							// if it's an email address make sure the email is valid using both regular expressions
							valid = /^[a-z0-9_+.-]+\@(?:[a-z0-9-]+\.)+[a-z0-9]{2,4}$/i.test(o);
							if($(this).hasClass('confirm-email')&&valid) {
								var prev = $.trim($(this).parents('.field').prev().children('.email').val());
								if(o!=prev)
									valid=!valid;
							}
						} else if (o.replace(/(?:^\s+)|(?:\s+$)/g,'').length < 1) {
							// if not an email address take out funky characters and see if its still blank
							valid = !valid;
						}
					} else if($(this).is('ul')) {
						valid = false;
						
						$(':radio, :checkbox', this).each(function() {
							if($(this).is(':checked'))
								valid = true;
						});
					}
					
					if(!valid) {
						if(form.hasClass('inline')) {
							$(this).parents('.field').children('label').addClass('validation-error');
						} else {
							var warn = $('<img />').attr('src', 'images/icon-warning.gif').addClass('validation-error');
							
							if( $(this).is('ul') )
								$('li:first', this).append(warn);
							else 
								$(this).parent().append(warn);
						}
													
						if(_errors == '')
							_errors = $(this).attr("id");
					}
				});
				if(_errors.length) {
					var lbl = $('#'+_errors).parents('.field').children('label');
					if(lbl[0].title.length)
						alert(lbl[0].title);
					else 
						alert( "A valid " + lbl.html().replace(/[*:]/g, '') + " is required." );
					$('#'+_errors, form).focus();
					return false;			
				}	
			});
		});
	};*/
	
	
	$.fn.removeError = function(form) {
		return this.each(function() {
			if(form.hasClass('inline'))
				$(this).removeClass('validation-error');
			else
				$(this).remove();
		});
	};
	
})(jQuery);	
