	




	/////////////////////////////////////////////////////////////////////////////////////////////////////
	////                                                                                             ////
	////    THIS IS A CLIENT-SIDE OFFER-BASED SITELET CUSTOMIZATION SCRIPT.                          ////
	////                                                                                             ////
	/////////////////////////////////////////////////////////////////////////////////////////////////////



			// FIRST, WE MUST DETERMINE IF THERE IS AN OFFER IN PLACE, AND IF SO WHICH ONE.
				var offer = {
				// set offer enabledment by request data, checking cookie enablement.
					enabled : (
						(
							cookie.enabled
						) && (
							(
								typeof(document.url.querystring.pairs.custoffer) != 'undefined'
							) || (
								typeof(cookie.pairs.custoffer) != 'undefined' &&
								document.location.href.indexOf('referrer=') == -1
							)
						)
					)
				}



				if (offer.enabled) {
					var offerName = (typeof(document.url.querystring.pairs.custoffer) != 'undefined') ? document.url.querystring.pairs.custoffer : cookie.pairs.custoffer;
				// write object properties in
					offer.dir   = './custom/' + offerName +'/';
					offer.specs = offer.dir   + 'offerSpecs.js';
					offer.css   = offer.dir   + 'offerStyle.css';
				// add support elements
					document.writeln('<style type="text/css"> #site-wrapper { visibility : hidden; } </style>');
					document.writeln('<link rel="stylesheet" href="'+offer.css+'" />');
					document.writeln('<script type="text/javascript" src="'+offer.specs+'"></script>');
				// gotta write that cookiehandler now.
					cookie.set({name:'custoffer', value:offerName, expires: 30});
				} 



			// DEFINE CUSTOM HANDLER FUNCTION THAT WILL HANDLE ALL XOS TRANSFORMATIONS.
			// FUNCTION WORKS BY LOOPING THROUGH ALL XOS ATTRIBUTES AND THEN EXTRACTING
			// A JSON OBJECT FROM THE 'CONTENTS' PROPERTY. THIS JSON OBJECT CONTAINS KEYS
			// THAT REPRESENT ELEMENT ATTRIBUTES, THEIR VALUES BEING THE NEW VALUE FOR THE
			// ELEMENT ATTRIBUTE. 



				var cosProc = function() {
					if (offer.enabled && typeof(offerSpecs) != 'undefined') {
					// utlity function
						var setInnerHTML = function(content, element) { element.innerHTML = content; element.style.visibility = 'visible'; element.normalize(); images.setImgMethods(); swf.setAll(8, deepLinking); }
					// handle each element in the offerSpecs individually.
						for (var i in offerSpecs) {
							var elementName    = i;
							var transformation = offerSpecs[i];
						// determine if the current transformation is applied in the current page.
							var appliedInPage  = (
								(
									typeof(transformation.applyToPages) == 'string' &&
									(transformation.applyToPages == 'all' || transformation.applyToPages == document.url.file)
								) || (
									function() { 
										for (var ii in transformation.applyToPages) {
											if (transformation.applyToPages[ii] == document.url.file) {
												return true;
											}
										} return false
									}()
								)
							);
						// if this is a transformattion designated for the current page, apply its settings.
							if (appliedInPage) {
							// try to determine what element to target.
								try {
									var elementRef = null;
									if (offerSpecs[i].applyToObj) {
										elementRef = offerSpecs[i].applyToObj;
										switch(typeof(offerSpecs[i].applyToObj)) {
											case 'function' :
												elementRef = elementRef();
											break;
											case 'string' :
												elementRef = (typeof(elementMap[offerSpecs[i].applyToObj]) == 'function') ?  elementMap[elementRef]() : document.getElementById(elementRef) ;
											break;
										}
									} else {
										var elementRef = elementMap[i]();
									}
								} catch (e) {
									throw('cos-preprocessor: element for customization "offerSpecs.' + i + '" could not be found, please make sure the dom reference or keyword is accurate');
								}
							// if element ref is valid, apply changes to it
								if (elementRef) {
								// handle innerHTML transformations
									if (typeof(transformation.htmlContents) != 'undefined') { 
										var htmlMods  = transformation.htmlContents;
										if (!(/\.html$/.test(htmlMods))) {                                                      // <-- test to see if string is an html document
											elementRef.innerHTML = htmlMods;                                                    // <-- if string is not an html document, insert it into the element directly
										} else {
											ajax.get({url: offer.dir + htmlMods , call: setInnerHTML, args: [elementRef]});     // <-- if string is an html file, get the contents of the html file and insert them into the element as a string.
										}
									}
								// handle element attribute transformations
									if (typeof(transformation.customAttbrs) != 'undefined') { 
										var attbrMods = transformation.customAttbrs;
										for (var iii in attbrMods) {
											var propName  = iii;
											var propValue = attbrMods[iii];
											try { elementRef[propName] = propValue;             } catch(e) { }
											try { elementRef.setAttribute(propName, propValue); } catch(e) { }
										}
									// special warning for hrefs set in absence of linkey set
										var badHrefSet = (typeof(transformation.customAttbrs.href) != 'undefined' && typeof(transformation.customAttbrs.linkey) == 'undefined' && elementRef.getAttribute('linkey'));
										if (badHrefSet) { try { console.log('customization problem: setting href without removing linkey - Will have no effect on actual linkage!') } catch (e) {} }
									}
								// handle inline-styling transformations
									if (typeof(transformation.customStyles) != 'undefined') {
										var customStyles = transformation.customStyles;
										var styleStr = '';
										for (var iii in customStyles) {
										// get property and process js-style props to css-style props
											var propName  = iii;
											var prefix = propName.match(/^[a-z]+(?=[A-Z])/);     // left-side
											var suffix = propName.match(/[A-Z][a-z]+/);          // right-side
											var propName = (prefix && suffix) ? prefix[0] + '-' + suffix[0].toLowerCase() : propName;
										// get value and write property into string.
											var propValue = customStyles[iii];
											styleStr += propName +': ' + propValue + '; ';
										}
									// apply all styles
										elementRef.setAttribute('style', styleStr); // <-- setting this way prevents multiple redraws/is faster.
									}
								}
							}
						}
					} else {
					// if there is something wrong with the offer code, kill the cookie and try to warn.
						if (offer.enabled && typeof(offerSpecs) == 'undefined') {
							try { console.log(' COS preprocessor: killed custoffer cookie due to bad or missing customization data.'); } catch (e) {}
						}
					// expire custoffer cookie if it looks like we are dealing with a standard offer banner click or search.
						if (cookie.pairs.custoffer) { cookie.expire('custoffer'); }
					// set offer enablement to false.
						offer.enabled = false;
					}
					document.getElementById('site-wrapper').style.visibility = 'visible';
				}



			// OBJECT MAPS NAMES TO DOM REFRENCES IN THE HTML FOR EASY ACCESS TO IMPORTANT ELEMENTS.
			// PROPERTIES ARE SET AS FUNCTIONS BECAUSE THIS LOADS BEFORE THE DOM.
			// FOR A REFERENCE OF WHICH KEYS TARGET WHICH ELEMENTS, PLEASE SEE DOCUMENTATION.



				var elementMap = {
				// elements in header
			 		clientLogin          : function() { return document.getElementById('head-clientLogin'); },
					getStarted           : function() { return document.getElementById('head-getStarted'); },
					txtLink              : function() { return document.getElementById('head-mainSite'); },
					tdLogo               : function() { return document.getElementById('head-logo'); },
				// main nav
					navParent            : function() { return document.getElementById('head-mainNav'); },
					navElement1          : function() { return document.getElementById('head-mainNav').getElementsByTagName('li')[0]; },
					navElement2          : function() { return document.getElementById('head-mainNav').getElementsByTagName('li')[1]; },
					navElement3          : function() { return document.getElementById('head-mainNav').getElementsByTagName('li')[2]; },
					navElement4          : function() { return document.getElementById('head-mainNav').getElementsByTagName('li')[3]; },
					navElement5          : function() { return document.getElementById('head-mainNav').getElementsByTagName('li')[4]; },
					navElement6          : function() { return document.getElementById('head-mainNav').getElementsByTagName('li')[5]; },
				// main content area
					contentBody          : function() { return document.getElementById('body'); },
				// top sub-content area
					mainSwf              : function() { return document.getElementById('swf-content'); },
					mainReg              : function() { return document.getElementById('body-content'); },
				// sub-elements of html content
					contentLeft          : function() { return document.getElementById('content-left'); },
					contentRight         : function() { return document.getElementById('body-contBox'); },
				// tab click areas
					contentTab1Clk       : function() { return document.getElementById('subnav-tabs').getElementsByTagName('li')[0]; },
					contentTab2Clk       : function() { return document.getElementById('subnav-tabs').getElementsByTagName('li')[1]; },
					contentTab3Clk       : function() { return document.getElementById('subnav-tabs').getElementsByTagName('li')[2]; },
					contentTab4Clk       : function() { return document.getElementById('subnav-tabs').getElementsByTagName('li')[3]; },
					contentTab5Clk       : function() { return document.getElementById('subnav-tabs').getElementsByTagName('li')[4]; },
				// tab content areas
					contentTab1Dat       : function() { return document.getElementById('body-contBox').getElementsByTagName('div')[0].getElementsByTagName('div')[0]; },
					contentTab2Dat       : function() { return document.getElementById('body-contBox').getElementsByTagName('div')[0].getElementsByTagName('div')[1]; },
					contentTab3Dat       : function() { return document.getElementById('body-contBox').getElementsByTagName('div')[0].getElementsByTagName('div')[2]; },
					contentTab4Dat       : function() { return document.getElementById('body-contBox').getElementsByTagName('div')[0].getElementsByTagName('div')[3]; },
					contentTab5Dat       : function() { return document.getElementById('body-contBox').getElementsByTagName('div')[0].getElementsByTagName('div')[4]; },
				// tab content area button(s)
					contentTabBtn        : function() { return getElementsByClassName('body-subFoot')[0].getElementsByTagName('a')[0]; },
				// special offer table
					specialOfferParent   : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0]; },
					specialOfferHeadline : function() { return document.getElementById('body-subCont').getElementsByTagName('h2')[0]; },
					specialOfferRow1Cel1 : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[0]; },
					specialOfferRow1Cel2 : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[1]; },
					specialOfferRow2Cel1 : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0].getElementsByTagName('tr')[1].getElementsByTagName('td')[0]; },
					specialOfferRow2Cel2 : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0].getElementsByTagName('tr')[1].getElementsByTagName('td')[1]; },
					specialOfferRow3Cel1 : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0].getElementsByTagName('tr')[2].getElementsByTagName('td')[0]; },
					specialOfferRow3Cel2 : function() { return document.getElementById('body-subCont').getElementsByTagName('table')[0].getElementsByTagName('tr')[2].getElementsByTagName('td')[1]; },
					specialOfferBtn      : function() { return document.getElementById('body-subCont').getElementsByTagName('div')[3].getElementsByTagName('a')[0]; },
				// banner sub-content area
					bannerParent         : function() { return document.getElementById('body-banner'); },
					bannerSwf            : function() { return document.getElementById('swf-banner'); },
					bannerReg            : function() { return document.getElementById('body-banner'); },
				// elements in footer
					legalTxt             : function() { return document.getElementById('legalContent'); }
				}



			// handy for the above dom refs
				var getElementsByClassName = function(objClass) {
					var allElements = document.getElementsByTagName('*');
					var ourElements = [];
					for (var i = 0; i < allElements.length; i++) {
						var thisElement = allElements[i];
						if (thisElement.className == objClass) { ourElements.push(thisElement); }
					}
					return ourElements;
				}



