var iexplore_sc = true;

Object.extend(Array.prototype, {

	implode: function(separator) {
		return (this.constructor == Array) ? this.flatten().join().replace(/,/g,separator) : this;
	},

	add: function(key,value) {
		return this[key] = value;
	}

});


Object.extend(Hash.prototype, {
	implode: function(separator) {
		return this.values().flatten().join().replace(/,/g,separator);
	},
	
	getPageName: function() { // s.pageName
		if(this.get('is_index') == 'true') {
			return this.getSiteSubSection3();
		}else if(this.get('is_error') == 'true') {
			return "404:" + document.referrer; // no way to test this in local environment since 404's are not set up the same way as staging and prod
		} else if (this.get('tour_id') != '' && typeof this.get('tour_id') != 'undefined') { // a better way to check if something is not set?
			return this.getSiteSubSection3() + ":" + this.getTourId();
		} else if (this.get('hotel_id') != '' && typeof this.get('hotel_id') != 'undefined') { // a better way to check if something is not set?
			return this.getSiteSubSection3() + ":" + this.getHotelId();
		} else {
			return this.getSiteSubSection3() + ":" + this.getContentTitle();
		}
	},
	
	getPageType: function() {
		if (typeof this.get('is_error') != 'undefined') {
			return this.get('is_error');
		} else {
			return '';	
		}
	},
	
	getSiteCountry: function(country) {
		return this.get('country').clean();
	},

	getTourId: function() {
		if (typeof this.get('tour_id') != 'undefined') {
			return this.get('tour_id');
		} else {
			return '';
		}
	},

	getSiteSection: function() { // s.channel
		return this.getSiteCountry() + ":" + this.get('site section').clean();
	},

	getSiteSubSection: function() {
		if(this.get('subsection').gsub(/\s+/, '').empty() || !this.get('subsection')) {
			return this.getSiteSection();
		} else {
			return this.getSiteSection() + ":" + this.get('subsection').clean();
		}
	},

	getSiteSubSection2: function() {
		if(this.get('subsection2').gsub(/\s+/, '').empty() || !this.get('subsection2')) {
			return this.getSiteSubSection();
		} else {
			return this.getSiteSubSection() + ":" + this.get('subsection2').clean();
		}
	},

	getSiteSubSection3: function() {
		if(this.get('subsection3').gsub(/\s+/, '').empty() || !this.get('subsection3')) {
			return this.getSiteSubSection2();
		} else {
			return this.getSiteSubSection2() + ":" + this.get('subsection3').clean();
		}
	},

	getContentTitle: function() { // s.prop2
		return this.get('content_title').clean();
	},

	getContentType: function() { // s.prop4
		return this.get('content_type').toLowerCase();
	},

	getContentId: function() { // s.prop3
		return this.get('content_id').clean();
	},

	getSiteSubSection2PlusContentType: function() {
		return this.getSiteSubSection2() + ":" + this.getContentType();
	},
	
	getContentHierarchy: function() {
		return this.getSiteSection() + this.getSiteSubSection2PlusContentType().gsub(this.getSiteSection(),'').gsub(/:/,',');
	},

	getSearchType: function() { // s.prop13
		if (typeof this.get('search_type') != 'undefined') {
			return this.get('search_type');
		} else {
			return '';	
		}
	},

	getSearchRegion: function() { // s.prop14
		if (typeof this.get('search_region') != 'undefined') {
			return this.get('search_region');
		} else {
			return '';	
		}
	},

	getSearchCountry: function() { // s.prop15
		if (typeof this.get('search_country') != 'undefined') {
			return this.get('search_country');
		} else {
			return '';	
		}
	},
	
	getSearchActivity: function() { // s.prop16
		if (typeof this.get('search_activity') != 'undefined') {
			return this.get('search_activity');
		} else {
			return '';	
		}
	},

	getSearchLength: function() { // s.prop17
		if (typeof this.get('search_length') != 'undefined') {
			return this.get('search_length');
		} else {
			return '';	
		}
	},

	getSearchPrice: function() { // s.prop18
		if (typeof this.get('search_price') != 'undefined') {
			return this.get('search_price');
		} else {
			return '';	
		}
	},

	getSearchDepartureMonthFrom: function() { // s.prop19
		if (typeof this.get('search_departure_month_from') != 'undefined') {
			return this.get('search_departure_month_from');
		} else {
			return '';	
		}
	},

	getSearchDepartureMonthTo: function() { // s.prop20
		if (typeof this.get('search_departure_month_to') != 'undefined') {
			return this.get('search_departure_month_to');
		} else {
			return '';	
		}
	},

	getSearchKeyword: function() { // s.prop22
		if (typeof this.get('search_keyword') != 'undefined') {
			return this.get('search_keyword');
		} else {
			return '';	
		}
	},

	getSearchResultCount: function() { // s.prop23
		if (typeof this.get('search_result_count') != 'undefined') {
			return this.get('search_result_count');
		} else {
			return '';	
		}
	},

	
	getEvents: function() { // s.events
		if (typeof this.get('events') != 'undefined') {
			return this.get('events');
		} else {
			return '';	
		}
	},
	
	getLeadType: function() { // e.var48
		if (typeof this.get('lead_type') != 'undefined') {
			return this.get('lead_type');
		} else {
			return '';	
		}
	},
	
	getHotelId: function() {
		return this.get('hotel_id');
	},

	getHotelNights: function() {
		return this.get('hotel_nights');
	},

	getHotelRate: function() {
		return this.get('hotel_rate');
	},


	getProducts: function(type) { // s.products
		if(type == 'tour') {
			if (this.getTourId() != '') {
				return ';' + this.getTourId();
			} else {
				return '';
			}
		} else if (type == 'hotel') {
			if (this.getHotelId() != '') {
				return ';' + this.getHotelId();
			} else {
				return '';
			}
		}
	}

	
});


Object.extend(String.prototype, {
	clean: function() {
		return this.strip().gsub(/[:\s-\+\/]+/, '-').gsub(/&amp;/,'and').gsub(/&/,'and').gsub(/['(),]+/,'').gsub(/\[-\]/,':').toLowerCase();
	},
	
	escape: function() {
		return this.gsub(/'/,'');
	}
	
	
});