﻿var SCReporting = {
	'metacontent': '',
	'metaroot': 'acs::web::',
	'pagepath': (location.pathname) ? location.pathname : '',
	'pagetitle': (document.title) ? document.title : '',
	'subdir': '',
	'title': '',
	'map': {},
	
	'init': function() {
		this.setSubdir();
		this.normalizeTitle();
		this.mapPage();
		this.insertMetaTag();
	},
	'insertMetaTag': function() {
		var head = document.getElementsByTagName('head').item(0);
		var meta = document.createElement('meta');
		meta.setAttribute('name', 'omni_page');
		meta.setAttribute('content', this.metaroot + this.metacontent);
		head.appendChild(meta);
	},
	'mapPage': function() {
		if (this.subdir == '') {
			this.metacontent = 'homepage';
		}
		else if (this.map.psp[this.subdir]) {
			this.metacontent = 'psp::' + this.map.psp[this.subdir] + '::' + this.title;
		}
		else if (this.map.ta[this.subdir]) {
			this.metacontent = 'ta::' + this.map.ta[this.subdir] + '::' + this.title;
		}
		else if (this.map.faq[this.subdir]) {
			this.metacontent = 'faq::' + this.map.faq[this.subdir] + '::' + this.title;
		}
		else if (this.map.qp[this.subdir]) {
			this.metacontent = 'qp::' + this.map.qp[this.subdir] + '::' + this.title;
		}
		else if (this.map.price[this.subdir]) {
			this.metacontent = 'price::' + this.map.price[this.subdir] + '::' + this.title;
		}
		else {
			this.metacontent = this.title;
		}
	},
	'normalizeTitle': function() {
		this.title = this.pagetitle;
		this.title = this.title.replace(/\&mdash;/g, '-');
		this.title = this.title.replace(/\&ndash;/g, '-');
		this.title = this.title.replace(/\—/g, '-');
		this.title = this.title.replace(/\&nbsp;/g, ' ');
		this.title = this.title.replace(/\s+/g, ' ');
		this.title = this.title.replace(/\"/g, '\'');
		this.title = this.title.split(' - ');
		if (this.title.length > 2) {
			this.title.shift();  /* Remove 'Apple' */
			this.title.shift();  /* Remove 'Support' */
			this.title = this.title.join(' - ');
		}
		else {
			this.title = this.title.toString();
		}
		this.title = this.title.replace(/^\s+(.+)/, '$1');
		this.title = this.title.replace(/(.+)\s+$/, '$1');
	},
	'setSubdir': function() {
		if (this.pagepath.indexOf('/support/') != -1) {
			this.subdir = this.pagepath.match(/\/support\/(.*)$/)[1];
			this.subdir = this.subdir.replace(/(.+)(\/|\/index\.html)$/, '$1');
			this.subdir = this.subdir.replace(/^index\.html$/, '');
		}
		else {
			this.subdir = 'undefined';
		}
	},
	'trackClick': function(subtitle, url) {
		if (typeof(s_gi) != 'undefined' && subtitle != undefined) {
			var s = s_gi(s_account);
			var orig_pagename = s.pageName;
			var lastparens = orig_pagename.match(/\([^\(\)]+\)$/);
			var country = (lastparens != null && lastparens.length > 0) ? ' ' + lastparens[0] : '';
			s.pageName = this.metaroot + this.metacontent + ' - ' + subtitle + country;
			s.prop4 = (url != undefined) ? url : document.URL;
			s.prop6 = s.getQueryParam('cp') + ": " + this.metaroot + this.metacontent + subtitle + country;
			void(s.t());
		}
	}
};

SCReporting.map = {

	/* product support pages */
	'psp': {
		'airport': 'airport',
		'aperture': 'aperture',
		'appletv': 'appletv',
		'bluetooth': 'bluetooth',
		'bonjour': 'bonjour',
		'bootcamp': 'boot camp',
		'color': 'color',
		'compressor': 'compressor',
		'displays': 'displays',
		'dvdstudiopro': 'dvd studio pro',
		'emac': 'emac',
		'finalcutexpress': 'final cut express',
		'finalcutpro': 'final cut pro',
		'finalcutserver': 'final cut server',
		'finalcutstudio': 'final cut studio',
		'garageband': 'garageband',
		'hardware': 'hardware',
		'headset': 'headset',
		'ibook': 'ibook',
		'ical': 'ical',
		'ichat': 'ichat',
		'idvd': 'idvd',
		'ilife': 'ilife',
		'imac/g3': 'imac g3',
		'imac/g4': 'imac g4',
		'imac/g5': 'imac g5',
		'imac/intel': 'intel-based imac',
		'iphone': 'iphone',
		'iphone/enterprise': 'iphone::iphone enterprise',
		'iphone/internet': 'iphone::iphone internet',
		'iphone/ipod': 'iphone::iphone ipod',
		'iphone/mail': 'iphone::iphone mail',
		'iphone/phone': 'iphone::iphone phone',
		'iphoto': 'iphoto',
		'ipod/earlier': 'ipod::ipod earlier',
		'ipodclassic': 'ipod::ipod classic',
		'ipodhifi': 'ipod accessories::ipod hi-fi',
		'ipodmini': 'ipod::ipod mini',
		'ipodnano/earlier': 'ipod::ipod nano earlier',
		'ipodnano': 'ipod::ipod nano',
		'ipodnano/3rd_generation': 'ipod::ipod nano 3rd gen',
		'ipodshuffle/earlier': 'ipod::ipod shuffle earlier',
		'ipodshuffle': 'ipod::ipod shuffle',
		'ipodtouch': 'ipod::ipod touch',
		'isight': 'isight',
		'isync': 'isync',
		'itunes': 'itunes',
		'itunes/store': 'itunes::itunes store',
		'iweb': 'iweb',
		'iwork': 'iwork',
		'jaguar': 'jaguar',
		'keyboard': 'keyboard',
		'keynote': 'keynote',
		'leopard/accounts': 'mac os x 10.5::accounts',
		'leopard/addressbook': 'mac os x 10.5::address book',
		'leopard': 'mac os x 10.5',
		'leopard/install': 'mac os x 10.5::install',
		'leopard/internet': 'mac os x 10.5::internet',
		'leopard/mail': 'mac os x 10.5::mail',
		'leopard/printing': 'mac os x 10.5::printing',
		'leopard/sharing': 'mac os x 10.5::sharing',
		'leopard/thirdparty': 'mac os x 10.5::thirdparty',
		'leopard/timemachine': 'mac os x 10.5::time machine',
		'latino/itunes/store': 'itunes::latino itunes store',
		'livetype': 'livetype',
		'logicexpress': 'logic express 8',
		'logicpro': 'logic pro 8',
		'logicstudio': 'logic studio',
		'macbook': 'macbook',
		'macbookair': 'macbook air',
		'macbookpro': 'macbook pro',
		'macmini': 'mac mini',
		'macos9': 'mac os 9',
		'macosx/mailassistant': 'mac os x::mail setup assistant',
		'macosxleopardserver/advancetopics': 'mac os x server 10.5::advanced topics',
		'macosxleopardserver/filesharing': 'mac os x server 10.5::file sharing',
		'macosxleopardserver/icalserver': 'mac os x server 10.5::ical server',
		'macosxleopardserver/ichatserver': 'mac os x server 10.5::ichat server',
		'macosxleopardserver': 'mac os x server 10.5',
		'macosxleopardserver/install': 'mac os x server 10.5::install',
		'macosxleopardserver/mailservices': 'mac os x server 10.5::mail services',
		'macosxleopardserver/networkingvpn': 'mac os x server 10.5::networking vpn',
		'macosxleopardserver/opendirectory': 'mac os x server 10.5::open directory',
		'macosxleopardserver/podcastproducer': 'mac os x server 10.5::podcast producer',
		'macosxleopardserver/webservices': 'mac os x server 10.5::web services',
		'macosxtigerserver/additionaltopics': 'mac os x server 10.4::additional topics',
		'macosxtigerserver/fileservices': 'mac os x server 10.4::file services',
		'macosxtigerserver': 'mac os x server 10.4',
		'macosxtigerserver/mailservice': 'mac os x server 10.4::mail service',
		'macosxtigerserver/networkservices': 'mac os x server 10.4::network service',
		'macosxtigerserver/opendirectory': 'mac os x server 10.4::open directory',
		'macosxtigerserver/printservice': 'mac os x server 10.4::print service',
		'macosxtigerserver/softwareupdate': 'mac os x server 10.4::software update',
		'macosxtigerserver/webtechnologies': 'mac os x server 10.4::web technologies',
		'macosxtigerserver/windowsservices': 'mac os x server 10.4::windows services',
		'macpro': 'mac pro',
		'mainstage': 'mainstage',
		'mobileme': 'mobileme',
		'mobileme/trial': 'mobileme::trial',
		'motion': 'motion',
		'nikeplus': 'ipod accessories::nikeplus',
		'numbers': 'numbers',
		'pages': 'pages',
		'panther': 'mac os x 10.3',
		'photoservices/account': 'photo services::account',
		'photoservices/cancel': 'photo services::cancel',
		'photoservices/discounts': 'photo services::discounts',
		'photoservices/gifts': 'photo services::gifts',
		'photoservices': 'photo services',
		'photoservices/orderstatus': 'photo services::order status',
		'photoservices/returns': 'photo services::returns',
		'photoservices/shipping': 'photo services::shipping',
		'photoservices/terms': 'photo services::terms',
		'photoservices/preparation_tips': 'photo services::preparation tips',
		'photoservices/ordering_options': 'photo services::ordering options',
		'photoservices/product_specs': 'photo services::product line details',
		'photoservices/product_troubleshooting': 'photo services::product troubleshooting',
		'photoservices/account_troubleshooting': 'photo services::account troubleshooting',
		'photoservices/shipping_prices': 'photo services::shipping prices',
		'photoservices/billing_inquiries': 'photo services::billing inquiries',
		'photoservices/payment_options': 'photo services::payment options',
		'photoservices/contact_us': 'photo services::contact us',
		'powerbook': 'powerbook g4',
		'powerbookg3': 'powerbook g3',
		'powermac/g3': 'power mac g3',
		'powermac/g4': 'power mac g4',
		'powermac': 'power mac g5',
		'proapps/serialnumbers': 'pro apps::serial numbers',
		'quicktime': 'quicktime',
		'remotedesktop': 'remote desktop',
		'safari': 'safari',
		'shake': 'shake',
		'snowleopard': 'mac os x 10.6',
		'snowleopardserver': 'mac os x server 10.6',
		'software': 'software',
		'soundtrack': 'soundtrack',
		'soundtrackpro': 'soundtrack pro',
		'tiger/3rdparty': 'mac os x 10.4::third-party',
		'tiger/accounts': 'mac os x 10.4::accounts',
		'tiger/addressbook': 'mac os x 10.4::address book',
		'tiger/classic': 'mac os x 10.4::classic',
		'tiger/features': 'mac os x 10.4::features',
		'tiger': 'mac os x 10.4',
		'tiger/install': 'mac os x 10.4::installing',
		'tiger/internet': 'mac os x 10.4::internet',
		'tiger/mail': 'mac os x 10.4::mail',
		'tiger/network': 'mac os x 10.4::network',
		'tiger/printing': 'mac os x 10.4::printing',
		'waveburner': 'waveburner',
		'webobjects': 'webobjects',
		'xsan': 'xsan',
		'xserve': 'xserve',
		'xserveraid': 'xserve raid'
	},
	
	/* troubleshooting assistant */
	'ta': {
		'iphone/assistant/itunes': 'iphone::itunes',
		'iphone/assistant/notrecognized': 'iphone::itunes',
		'iphone/troublehsooting': 'iphone::iphone',
		'iphone/troubleshooting/calls': 'iphone::calls',
		'iphone/troubleshooting/mail': 'iphone::mail',
		'iphone/troubleshooting/phone': 'iphone::phone',
		'ipodtouch/troubleshooting': 'ipod::ipod touch',
		'ipodtouch/troubleshooting/ipodtouch': 'ipod::ipod touch',
		'ipodtouch/troubleshooting/itunes': 'ipod::ipod touch::itunes',
		'ipodtouch/troubleshooting/mail': 'ipod::ipod touch::mail',
		'ipod/five_rs': 'ipod',
		'ipod/five_rs/classic': 'ipod::ipod classic',
		'ipod/five_rs/ipod': 'ipod::ipod family',
		'ipod/five_rs/ipod5gen': 'ipod::ipod 5th gen',
		'ipod/five_rs/mini': 'ipod::ipod mini',
		'ipod/five_rs/nano': 'ipod::ipod nano',
		'ipod/five_rs/nano2gen': 'ipod::ipod nano 2nd gen',
		'ipod/five_rs/nano3gen': 'ipod::ipod nano 3rd gen',
		'ipod/five_rs/nano4gen': 'ipod::ipod nano 4th gen',
		'ipod/five_rs/photo': 'ipod::ipod photo',
		'ipod/five_rs/shuffle': 'ipod::ipod shuffle',
		'ipod/five_rs/shuffle2gen': 'ipod::ipod shuffle 2nd gen',
		'ipod/five_rs/shuffle3gen': 'ipod::ipod shuffle 3rd gen',
		'ipod/five_rs/wheel': 'ipod::ipod w/click wheel'
	},
	
	/* frequently asked questions */
	'faq': {
		'airport/service': 'airport::service',
		'emac/service': 'emac::service',
		'ibook/service': 'ibook::service',
		'imac/service': 'imac::service',
		'iphone/service/battery': 'iphone::battery replacement',
		'iphone/service/exchange': 'iphone::replacement service',
		'iphone/service/faq': 'iphone::service',
		'ipod/service/faq': 'ipod::service',
		'ipod/service/battery': 'ipod::battery replacement',
		'ipodhifi/service/faq': 'ipod::ipod hi-fi::service',
		'macbook/service': 'macbook::service',
		'macbookair/service': 'macbook air::service',
		'macbookair/service/battery': 'macbook air::battery replacement',
		'macbookpro/service': 'macbook pro::service',
		'macbookpro/service/battery': 'macbook pro::battery replacement',
		'macmini/service': 'mac mini::service',
		'nikeplus/service/faq': 'ipod::nike plus::service',
		'powerbook/service': 'powerbook g4::service',
		'powerbookg3/service': 'powerbook g3::service',
		'powermac/service': 'power mac::service',
		'xserve/service': 'xserve::service'
	},
	
	/* quality programs */
	'qp': {
		'batteryexchange/2006/faq': 'battery exchange::ibook + powerbook 2006',
		'batteryexchange/faq': 'battery exchange::ibook + powerbook 2005',
		'ibook/faq': 'repair extension::ibook logic board',
		'macbookpro/batteryexchange': 'battery exchange::macbook pro 15-inch',
		'powermac/powersupply/repairextension': 'repair extension::power mac g5 power supply',
		'usbadapter/exchangeprogram': 'adapter exchange::iphone usb adapter'
	},
	
	/* pricing */
	'price': {
		'ipod/service/price': 'ipod::repair + battery replacement'
	}
};

SCReporting.init();
