/*
	file:	        reader.js
	description:	extends classes from base.js
	$Header: /source/docroot/downloadcenter/js/live/reader.js,v 1.29 2011/12/01 12:01:24 skattima Exp $

*/

/*
	file:	        base.js
	description:	base JS classes for download centers. to be extended by product specific files (i.e. flashplayer.js)
	$Header: /source/docroot/downloadcenter/js/live/base.js,v 1.36 2011/10/13 23:18:10 alongnio Exp $

*/

/* ********************
 * BASE CLASSES
 ******************** */

var Request = Class.create({
	// child classes must implement these empty functions
	initialize   :   function() {
		var eventname = $F("eventname");

		//load installers once os and language is selected
		document.observe("otherVersion:getInstallers", this._getInstallers.bindAsEventListener(this));
	},
	getResultDisplay	:	function(eventname){ return displayResult; },
	getInstallerResultDisplay	:	function(eventname){ return installerDisplayResult; },
	getNoResultDisplay	: function(){return "display:noInstaller";},
	getAjaxUrl	:	function(){return url;},
	
	_getCriteriaMap   :   function(e,dlc) {
		var url = "/webservices/json/criteriamap/?downloadcenter=" + dlc + "&locale=" + locale;
		var options 	= {
			method 		: "get", 
			onSuccess 	: this._onCriteriaMapFetchSuccess.bind(this),
			onFailure 	: this._onFetchFailure
		};
	
		new Ajax.Request(url, options);
	},
	_onCriteriaMapFetchSuccess   :   function(transport) {
		var json 			= transport.responseJSON;
		var eventname		= $F("eventname");
		var displayResult	= this.getResultDisplay(eventname);
		var noDisplayResult = this.getNoResultDisplay();
		if(json) {	
			document.fire(displayResult, json);
		} else {
			document.fire(noDisplayResult);
		}
	},
		
	_getInstallers   :   function(e) {
		var url = this.getAjaxUrl();
		if (url.match(/English_UK/)){
			url = url.replace("English_UK","English%20(UK)"); 
		}
		// if the user has not made an OS selection, alert them and stop all event processing
		if ($F("select_os") == -1) {
			document.fire("display:noSelection");
			return;			
		} else {					
			var options 	= {
				method 		: "get", 
				onSuccess 	: this._onInstallerFetchSuccess.bind(this),
				onFailure 	: this._onFetchFailure
			};
	
			new Ajax.Request(url, options);
		}
	},
	
	_onInstallerFetchSuccess   :   function(transport) {
		var json 			= transport.responseJSON;
		var eventname		= $F("eventname");
		var installerDisplayResult	= this.getInstallerResultDisplay(eventname);
		var noInstallerDisplayResult = this.getNoResultDisplay();

		if(json.length) {	
			document.fire(installerDisplayResult, json);
		} else {
			document.fire(noInstallerDisplayResult);
		}
	},
	
	_onFetchFailure   :   function() {
		var noDisplayResult = this.getNoResultDisplay();
		
		document.fire(noDisplayResult);	
	},
	
	prepareQueryString	   :   function() {
		var os				= $F("select_os");
		var eventname		= $F("eventname");
		var query_as		= criteriamap.platforms[os].properties;
		var query_string 	= "?";
		
		// enumerate over query_as and load query_string with key/values
		for(key in query_as) {
			query_string += key + "=" + query_as[key] + "&";
		}
		
		query_string += "eventname=" + eventname;

		return query_string;
	}
});

var Display = Class.create({
	
	initialize	:	function() {
		showaddon = false;
		document.observe("display:otherversions", this._displayOtherVersions.bindAsEventListener(this));
		document.observe("display:noSelection", this._displayNoSelection.bindAsEventListener(this));
		document.observe("display:addons", this._displayAddons.bindAsEventListener(this));
		document.observe("display:otherversionsShowInstallers", this._onInstallerFetchSuccess.bindAsEventListener(this));
		document.observe("display:enterpriseShowInstallers", this._onInstallerFetchSuccess.bindAsEventListener(this));
		document.observe("display:noInstaller", this._displayNoInstaller.bindAsEventListener(this));
        $("buttonDownload").observe("click", this._onDownloadClick.bindAsEventListener(this)); 
	},

	curtainsUp   :   function() {
		  $('buttonDownload').setAttribute("href", "../download/");
		  if ($("eventname") && $("eventname").value=="readermoreinfo") {
		  	$('buttonDownload').setAttribute("href", "download/");
		  }
          $('buttonDownload').className = "download-button";
		  $('buttonDownload').disabled = false;
		  $('ajaxloading').hide();
		  $("downloadContent").show();
	},
				
	setEULA   :   function(enable) {
		$('eula').childElements().each(function(e) {
			$(e).hide()
		});
		
		$(enable.toString()).show();
		
	},
	setResources  :   function(enable) {
		if (!$(enable)) return;
		
		$('resources').childElements().each(function(e) {
			$(e).hide()
		});
		
		$(enable.toString()).show();
		
	},
	
	curtainsDown   :   function() {
		try {
			  //reset eula to default state
			  if ($("eventname").value != "readerenterprise" && $("eventname").value != "readerdirect") {
			  	this.setEULA("adobeEULA");
			  }
			  $('buttonDownload').disabled = true;
			  $('buttonDownload').setAttribute("href", "javascript: void(0)");
	          $('buttonDownload').className = "download-button download-button-disabled";
			  if($("downloadContent") && $("downloadContent").visible()) {
			  	 $("downloadContent").hide();
			  } 
			  if($("acrobatBundleString") && $("acrobatBundleString").visible()) {
			  	 $("acrobatBundleString").hide();
			  } 
			  $('ajaxloading').show();
		}
			catch (e) {
				errorHandler (e);
		  }
	},
    
	_onInstallerFetchSuccess   :   function(event) {
		//populate version dropdown
		readerjson 			= event.memo;
		var verObj = $("installer");
		verObj.childElements().each(function(s) {
			if (s.value!=0) {s.remove();}
		});// clear out version box
		
		if(readerjson.length) {	
			for (i = 0; i < readerjson.length; i++) {
				var offer = readerjson[i];
				var readerVersion = new Array();
				readerVersion = offer.Name.split(" "); //get the reader version number alone into readerVersion[1]
				offer.Name = offer.Name.replace(/^Reader 10 /, "Reader X "); //for Reader version 10 only
				offer.Name = offer.Name.replace(/^Reader 10(.\d\d{0,1}){1,2} /, "Reader X (" + readerVersion[1] + ") ");// for Reader version 10.?.? only
				var option = new Element("option", { "value" : offer.queryName }).update(offer.Name);
		 		verObj.insert(option);
			}
		$("installer").stopObserving("change"); //remove any previous listners
		$("installer").observe("change", this._installerChangeHanlder.bindAsEventListener(this)); //reader other version version selection
		$('ajaxloading').hide();
		$("unavailable").hide();
		if(adobe.hostEnv.ie6) {
			$('installer').setStyle({
			  'width': 'auto'
			});
		}
		
		} else {
			document.fire("display:otherVersionsNoInstaller");
		}
	},

	_installerChangeHanlder	:	function(e) {
		// update download button href
		// display file size, sys. req.
		// hide/show addon offers
		this.curtainsDown();

		if ($F("installer")!=0) {
		  for (i = 0; i < readerjson.length; i++) {
				if (readerjson[i].queryName==$F("installer")) {
					$("clientfilesize").update((otherLocale())? dotToComma(readerjson[i].file_size) : readerjson[i].file_size);  // dot to comma conversion 					
					utility.set_aih_compatible_installer(readerjson[i].aih_compatible);
					suffix = readerjson[i].aih_version_suffix ? readerjson[i].aih_version_suffix : "";
					utility.set_can_bundle_with_air(readerjson[i].Version,readerjson[i].language_type,suffix); //for otherversions AIR bundle text
				}
			}
		  if ($("eventname").value != "readerenterprise" && $("eventname").value != "readerdirect") {
		  	this.makeaddonoffer();
		  	this._termOfService();
		  }
		  if(utility.get_can_bundle_with_air()) {
				this.updateClientSize();
		 }
		  this.curtainsUp();
		} else {
			$('ajaxloading').hide();			
		}
	},		
	makeaddonoffer   :   function() {
		if(utility.aih_compatible() && showaddon) {
			if(!$("addonoffers").visible()){
				$("addonoffers").show();
                $("addon").checked = true;
			}
        } else {
			$("addonoffers").hide();
			
			// addon checkbox only gets written in when a user is dlm/addon compatible,
			// so ensure it's in the dom before we alter it
			if ($("addon")) {
				$("addon").checked = false;
			}
        }
    },		
	
	set_ContainerTextAdjust   :   function(container,limit,charplaced) {		
		if($(container))
			{			
				if ( (($(container).innerHTML).length > limit) || (locale == 'jp')) 
					{ $(container).innerHTML =  $(container).innerHTML + charplaced;}
			}
	},
	
	_displayNoInstaller   :   function() {
		try {
			$("ajaxloading").hide();
			$("unavailable").show();	
		}
			catch (e) {
				errorHandler (e);
		  }
	}
});

var SwissArmyKnife = Class.create({

	initialize   :   function() {
		this.ua				= navigator.userAgent;
		
		// properties for specific browsers
		this.isIE			= this.ua.match(/MSIE/) != null;
		this.isIE6			= this.ua.match(/MSIE 6/) != null;
		this.isIE7 			= this.ua.match(/MSIE 7/) != null;
		this.isIE8 			= this.ua.match(/MSIE 8/) != null;
		this.isIE9 			= this.ua.match(/MSIE 9/) != null;
		this.isIE10 		= this.ua.match(/MSIE 10/) != null;
		this.is64bitIE 		= this.ua.match(/Win64|x64/) != null;
		this.is32IEonVista64= this.ua.match(/WOW64/) != null && this.isIE7;
		this.isFirefox 		= this.ua.match(/Firefox/) != null;
		this.isFirefox50 	= this.ua.match(/Firefox\/5/) != null;		
		this.isFirefox40 	= this.ua.match(/Firefox\/4/) != null;
		this.isFirefox30 	= this.ua.match(/Firefox\/3/) != null;
		this.isFirefox20 	= this.ua.match(/Firefox\/2/) != null;
		this.isFirefox15 	= this.ua.match(/Firefox\/1\.5/) != null;
		this.compatibleIEVersion = this.isIE6 || this.isIE7 || this.isIE8 || this.isIE9 || this.isIE10;
		this.compatibleFFVersion = this.isFirefox;
		this.gtbinstalled	= this.ua.match(/GTB/) != null;
		this.isSafari = this.ua.match(/Safari/) != null && this.ua.match(/Chrome/) == null;
		this.isOpera = this.ua.match(/Opera/) != null;
		this.isChrome = this.ua.match(/Chrome/) != null;
				
		// properties for specific os/platforms
		this.isWinXP 		= this.ua.match(/Windows NT (5\.1)/) != null;
		this.isWinXPSP2 	= this.ua.match(/SV1/) != null && this.isWinXP;
		this.isWin2k3 		= this.ua.match(/Windows NT 5.2/) != null;
		this.isMac			= this.ua.match(/Mac/) != null;
		this.isWin2k		= this.ua.match(/Windows (NT 5\.0|NT 5\.01|2000)/) != null;
		this.isAol 			= this.ua.match(/America Online Browser|AOL/) != null;
		this.isVista 		= this.ua.match(/Windows NT 6.0/) != null;
		this.isWin7 		= this.ua.match(/Windows NT 6.1/) != null;
		this.is64bitVista 	= this.isVista && this.is64bitIE;
		
		// properties specific to funnel

		this.xpiinstalled	= window.location.href.indexOf("xpiinstalled") > -1;
		this.isDistrib		= $("eventname") ? $F("eventname") == "readerenterprise" && $F("eventname") == "readerdirect" : false;
		this.eventname		= $("eventname") ? $F("eventname") : ' ';
		this.theBho 		= null;
		this.install_method = "sai";
		this.aih_compatible_config = this.is_aih_compatible_config();
		this.aih_compatible_installer = 1;
		this.can_bundle_with_air = 0;
	},
	
	// return the value of a text node within an option element
	select_textnode   :   function(element) {
    	return element.options[element.selectedIndex].text;
    },
	
	is_aih_compatible_config   :   function() {
		// verifies DLM compatibility based off of the config
		
		if (this.isWin7 || this.isVista || this.isWinXP)
		{
			// config is compatible with AIH
			this.set_install_method("aih");
			return true;
		}
		else
		{
			// config is incompatible with AIH
			this.set_install_method("sai");
			return false;	
		}
	},
	
	set_aih_compatible_installer   :   function(compatibility) {
		this.aih_compatible_installer = compatibility == 1 || compatibility == "on" ? 1 : 0;
	},
	
	get_aih_compatible_installer   :   function() {
		return this.aih_compatible_installer;
	},
	
	aih_compatible   :   function() {
		var config = this.aih_compatible_config;
		var installer = this.get_aih_compatible_installer();
		return config && installer;
	},
	
	set_install_method   :   function(method) {
		this.install_method = method;
	},
	
	get_install_method   :   function() {
		return this.install_method;
	},
	
	set_can_bundle_with_air   :   function(version, language, suffix) {
		
		var major_version = "";
		var non_win2kFlag = true;
		this.can_bundle_with_air = 0;
		//special hack code to disable AIR for win2k from otherversions page
		if($F("eventname")== "readerotherversions" && $F("select_os") == "Windows_2000_SP4"){
			non_win2kFlag = false;
		}		
	
	    // the main flow calls this method with no arguments, so we must get version/language directly from the page
	 	version = version || $("clientversion").innerHTML;
		language = language != undefined ? language : $("language").innerHTML;
		
		// ensure we have a string so we can perform an indexOf	
		version = version.toString();
		
		major_version = version.indexOf(".") > -1 ? version.substring(0, version.indexOf(".")) : version;
		
		//to handle X in main page 
		if( major_version.match(/10/)) {
			major_version = "X";			
		}
		
		// get include text dynamically from installer version for otherversions and enterprise page
		if ($("acrobatBundleString") && $F("eventname") == "readerotherversions" || $F("eventname")== "readerenterprise" || $F("eventname")== "readerdirect") {
			$('acrobatBundleString').update();
			$("acrobatBundleString").hide();
		}
		// for bug 115933, only show acrobat bundle string for dlm compatible OR Mac
		if ($("acrobatBundleString")&& non_win2kFlag && suffix) {
			$("acrobatBundleString").innerHTML = suffix;			
			
			if ($("select_os") && $F("select_os").match("Mac") && major_version.match(/9/)) {
				$("acrobatBundleString").show();
			} 
		}
		
		//if(!this.aih_compatible() || !(language.match(/English/))) return;

		if ($F("eventname") != "readerenterprise" && $F("eventname") != "readerdirect") {
			try {
				if ((major_version.match(/9/) || major_version.match(/X/) || major_version.match(/10/)) && language.match(/English/) && addons.getInstallAir() && non_win2kFlag) {
					if (AIRBundle != undefined && AIRBundle) {
						offers.enable("AIRBundle");
					}
					if ($("acrobatBundleString")) {
						$("acrobatBundleString").show();
					}
					this.can_bundle_with_air = 1;
				}
				else {
					if (AIRBundle != undefined && AIRBundle) offers.disable("AIRBundle");
					this.can_bundle_with_air = 0;
				}
			}
			catch (e){
			}
		}
	},
	
	get_can_bundle_with_air   :   function(){
		return this.can_bundle_with_air;		
	},
	
	// Taken from http://www.netlobo.com/url_query_string_javascript.html and modified slightly
	gup   :   function(name) {
		name = name.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
		var regexS = '[\\?&]'+name+'=([^&##]*)';
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.href);
		return results == null ? false : results[1];
	},
	
	/**
	* Returns the value of the selected radio button in the radio group, null if
	* none are selected, and false if the button group doesn't exist
	*
	* @param {radio Object} or {radio id} el
	* OR
	* @param {form Object} or {form id} el
	* @param {radio group name} radioGroup
	*/
	$RF: function(el, radioGroup) {
	    if($(el).type && $(el).type.toLowerCase() == 'radio') {
	        var radioGroup = $(el).name;
	        var el = $(el).form;
	    } else if ($(el).tagName.toLowerCase() != 'form') {
	        return false;
	    }
	
	    var checked = $(el).getInputs('radio', radioGroup).find(
	        function(re) {return re.checked;}
	    );
	    return (checked) ? $F(checked) : null;
	}
});
// replaces file sizes with , instead of . for locales like french
var dotToComma = function(size) {
		size = size.toString().gsub(/\.+/,',');
		return size;
	}
// replaces file sizes with . instead of , this way we can add stuff up
var commaToDot = function(size) {
	size = size.toString().gsub(/\,+/,'.');
	return size;
}

var otherLocale = function() {
	var loc = (locale == 'fr' || locale == 'de' || locale == 'es'|| locale == 'it' || locale == 'br' || locale == 'se' || locale == 'nl' || locale == 'no' || locale == 'fi' || locale == 'dk' || locale == 'ru' || locale == 'cz' || locale == 'tr' || locale == 'pl') ? true : false;
	return loc;
	
}


var errorHandler = function (e) {
	try {
		var errorName = e.name;
		var errorMessage = e.message;
		
		var jsErrorPing = new adobe.Deeppurple.Event("PDLC", "JSError", "JSError.gif");
		jsErrorPing.run($H({
			id: "deeppurpleFailure",
			currentURL: document.location,
			errorName: errorName,
			errorMessage: escape(errorMessage)
		}));
		jsErrorPing.send();
	} 
	catch (e1) {
		url = "<img src='http://www.adobe.com/deeppurple/JSError.gif?id=deeppurpleFailure&currentURL=" + document.location + "&errorName=" + e1.name + "&errorMessage=" + escape(e1.message) + "' />"
		document.getElementById("JSError").innerHTML += url;
	}
	
}

/**
 * @projectDescription	3rd Party Offers library
 * @namespace adobe.polarbear
 * @author Kevin Favro kfavro@adobe.com
 * @author Chris Lechner clechner@adobe.com
 * 
 * $Header: /source/docroot/downloadcenter/js/live/offers.js,v 1.21 2012/01/05 19:37:33 vmadired Exp $
 */

// Create the adobe.polarbear namespaces
if (!adobe) abort();
if (!adobe.polarbear) adobe.polarbear = {};
if (!adobe.polarbear.products) adobe.polarbear.products = {};
if (!adobe.polarbear.DLM) adobe.polarbear.DLM = {};

/**
 * adobe.polarbear.offers
 */
adobe.polarbear.offers = Class.create({
	/**
	 * @constructor
	 */
	initialize : function() {
		this.utility = new adobe.polarbear.utility();
		this.container = $H();
		
		// create different category hashes within products
		this.products = $H({
			all : $H(),
			byClass: $H(),
			byType: $H({
				core : [],
				addon : [], 
				bundle: []
			}),
			byName: $H()
		});
		
		// Map class names to a regular expression
		this.classMap = $H({
			GTB: /^Google Toolbar/i, 
			MSS: /^McAfee/i,
			CHR: /^Google Chrome/i
		});
	},
	
	/**
	 * Takes a JSON structure of installer meta-data returned from
	 * the polar bear criteria table, instantiates, and prepare()s product 
	 * classes based on matching the installer name property against classMap.
	 * After the product class has been prepare()ed, instances are then stored
	 * as members in the products hash.  
	 * 
	 * @param   json  a json structure containing installer meta-data
	 * @return        void
	 */
	loadProducts : function(json) {
		var j = json;
		var map = this.classMap;
		
		j.each(function(item) {
			map.each(function(regex) {
				if (item.Name.match(regex.value)) {
					try {
						// instantiate a new product class with the same name as the classMap key
						product = new adobe.polarbear.products[regex.key](item, this.utility).prepare();						
						this.categorize(regex.key, product);						
					} catch(e) {}
				}
			}.bind(this));
		}.bind(this));
		
	},
	
	categorize: function(key, product) {
		var qName = product.properties.queryName;
		var byName = qName ? qName : key; 
		
		try {
			// begin storing instances of product classes into hashes organized by category
			this.products.get("all").set(key, product);
			
			if (this.products.get("byClass").get(key)) 
				this.products.get("byClass").get(key).push(product);
			else 
				this.products.get("byClass").set(key, new Array(product));
			
			this.products.get("byType").get(product.type).push(product);
			this.products.get("byName").set(byName, product);
		} catch(e) {}
	},
	
	/**
	 * Sets a product class' eligibility to true
	 * 
	 * @param  id  name of the product class to enable
	 * @return     void
	 */
	enable : function(id) {
		this.products.get("all").get(id).eligible = true;
	},
	
	/**
	 * Set's a product class' eligibility to false
	 * 
	 * @param  id  name of the product class to disable
	 * @return     void
	 */
	disable : function(id) {
		try {
		this.products.get("all").get(id).eligible = false;
		} catch(e) {}
	},
	
	/**
	 * Loops through Omniture relevant products in the 
	 * products.byClass hash and sets Omniture meta-data
	 * on each product.  The Omniture variable sProp_34
	 * will be set to the value this method returns.
	 * 
	 * @return  a string representing the status of all
	 *          Omniture relevant products
	 */
	toOmnitureString : function() {
		var state = $H();
		
		if (this.products.get("all").size()) {
			this.products.get("all").each(function(item) {
				var usesOmniture = item.value.usesOmniture;
				var preinstalled = item.value.preinstalled;
				var eligible = item.value.eligible;
				
				if(usesOmniture) {
					if(preinstalled) state.set(item.key, "offer-preinstalled");
					else if (eligible) state.set(item.key, "offer-eligible");
					//else state.set(item.key, "offer-ineligible");
				}
			});
			
			return state.toQueryString();
		} else {
			return "offer-ineligible";
		}
	},
	
	/**
	 * Loops through all products in the products.byClass hash
	 * and sets each product.queryName equal to a pre-determined
	 * value (p, i, a, d).  The return from this method will be
	 * appended to the thankyou page href.
	 * 
	 * @param  choice  boolean value representing the state of
	 * 				   the addon checkbox
	 * @return 		   a string representing the eligibility and
	 * 				   acceptance status of all products 
	 */
	toQueryString : function(choice) {		
		//var state = $H({ p : [], i : [], a : [], d : [] });
		var state = $H({ p : [], b : [], a : [], d : [] });
		
		this.products.get("all").each(function(item) {
			var usesOmniture = item.value.usesOmniture;
			var preinstalled = item.value.preinstalled;
			var eligible = item.value.eligible;
			var queryName = item.value.properties.queryName;
			var bundledItem = item.value.type == "bundle" ? true : false;
			
			if(usesOmniture) {
				if(preinstalled) state.get('p').push(queryName);
				else if (eligible && choice == 0) state.get('d').push(queryName);
				else if (eligible && choice == 1) state.get('a').push(queryName);
			}
				
			if(bundledItem && eligible) {
				// some bundles, like the AIR bundle, will be an array, so must be iterated
				if(queryName instanceof Array) {
					for(i=0;i<queryName.length;i++) {
						state.get('b').push(queryName[i]);
					}
				} else {
					state.get('b').push(queryName);
				}
			}
		});
		
		// since state values are arrays, we need to remove all empty
		// arrays since toQueryString() returns empty arrays as '&'
		state.each(function(item) {
			if(!item.value.length) state.unset(item.key);
		});	
		
		return state.toQueryString();		
	},
	
	/**
	 * Returns all products of a related class
	 * by searching through products.byClass hash
	 * 
	 * @param  className  name of the class
	 * @return     		  an instance of the requested product class
	 */
	getProductsByClass : function(className) {
		return this.products.get("byClass").get(className);
	},
	
	/**
	 * Returns all products of a related type
	 * by searching through the products.byType hash
	 * 
	 * @param  type  type of class (addon or core)
	 * @return       an instance of the requested product class
	 */
	getProductsByType : function(type) {
		return this.products.get("byType").get(type);		
	},
	
	/**
	 * Returns a product by searching through the 
	 * products.byName hash
	 * 
	 * @param  name  installer query name
	 * @return   	 an instance of the requested product class
	 */
	getProductByName : function(name) {
		return this.products.get("byName").get(name);
	},
	
	/**
	 * Returns a single product by searching through the
	 * products.all hash
	 * 
	 * @param  id  key stored in products.all hash
	 * @return     an instance of the requested product class
	 */
	getProduct : function(id) {		
		return this.getProducts().get(id);
	},
	
	/**
	 * Returns all products stored in the products.all hash
	 * 
	 * @return  all instances of product classes that have been instantiated
	 */
	getProducts : function() {
		return this.products.get("all");
	},
	
	/**
	 * Loops over an array of objects and determines which one will be offered
	 * 
	 * @param  secondarOffers array of offer objects
	 * @return individual offer object
	 * 
	 * @return  all instances of product classes that have been instantiated
	 */
	selectSecondaryOffer : function(secondaryOffers) {
		// Get a random number
		var sample = Math.random();
		var pointer = 0;
		var index = $H({});
		var secondaryOffer = false;
		
		// build our index
		for(i = 0; i < secondaryOffers.length; i++) {
			var o = secondaryOffers[i];
			index.set(o.obj.id, $H({ start: pointer, stop: pointer + o.percent, offer: o.obj }));
			pointer += o.percent;
		}		
		
		// loop through our index to determine which offer falls within the boundary of our sample
		for(i = 0; i < secondaryOffers.length; i++) {
			
			var offer = index.get(secondaryOffers[i].obj.id);
			
			if(sample >= offer.get('start') && sample < offer.get('stop')) {
				secondaryOffer = offer.get('offer');
			} else {
				offer.get('offer').eligible = false;
			}
		}
		
		return secondaryOffer;
	},
	
	setOfferCookie: function(dlc, type, choice)
	{
		var c = dlc + "offerchoice";	
		adobe.Cookie.set(c, [type, choice].join("="), false, '/', '.adobe.com');
	},
	
	getOfferCookie: function(dlc)
	{
		var c = dlc + "offerchoice";	
		if (adobe.Cookie.get(c) !== undefined)
		{
			var t = adobe.Cookie.get(c).split("=");
			return { type: t[0], choice: t[1] == "true" ? true : false };
		}
	},
	
	removeOfferCookie: function(dlc)
	{
		var c = dlc + "offerchoice";	
		adobe.Cookie.remove(c, '/');
	},
	
	getEligibleItem: function()
	{
		var item = false;
		this.products.get("all").each(function(i) 
		{
			if (i.value.eligible)
			{
				item = i.value;
				throw $break;
			}
		});
		
		return item;
	}
});

/**
 * adobe.polarbear.rdcOffers
 */
adobe.polarbear.rdcOffers = Class.create(adobe.polarbear.offers, {
	initialize: function($super) {
		// initialize the parent class
		$super();
	},
	
	loadProducts: function($super, json) {
		var j = json;
		var temp = "";
		var bundleAcrobat = false;
		var bundleClassName = "AIRBundle";
		var bundleDetails = {
			"file_size": 0,
			queryName: []
		};
		
		// load up shared offers using the parent class
		$super(j);
		
		this.bundleClassMap = $H({
			// removing ARH since it no longer needs to be present in the query string with AIH
			// ARH: /^ARH/i, 
			// removing acrobat.com to be offered with reader on windows
			// ACROBAT: /^Acrobat\.com/i,
			AIR: /^Air\ Installer/i	
		});
		
		j.each(function(item) {
			this.bundleClassMap.each(function(regex) {
				if (item.Name.match(regex.value)) {
					temp = bundleDetails.file_size;
					bundleDetails.file_size = Math.round((temp + item.file_size)*100)/100;
					temp = bundleDetails.queryName;
					bundleDetails.queryName.push(item.queryName);
					
					throw $break;
				}
			}.bind(this));
		}.bind(this));

		if(bundleDetails.queryName.length == this.bundleClassMap.size()) {
			try {
				// instantiate a new product class with the same name as the classMap key
				product = new adobe.polarbear.products[bundleClassName](bundleDetails, this.utility).prepare();
				// begin storing instances of product classes into hashes organized by category
				this.categorize(bundleClassName, product, true);
			} 
			catch (e) {}
		}
	}
});

/**
 * A base Class representing a generic offer
 * 
 * adobe.polarbear.products.base
 */
adobe.polarbear.products.base = Class.create({
	/**
	 * @constructor
	 * @return       void
	 */
	initialize : function(properties, utility) {
		this.properties = properties;
		this.utility = utility;
		this.type = null;
		this.usesOmniture = false;
		this.preinstalled = false;
		this.eligible = true;

	},
	
	/**
	 * More or less an abstract method.  Child classes will
	 * need to override within themselves.
	 * 
	 * @return  boolean
	 */
	userIsEligible : function() {
		this.eligible = true;
	}
});

/**
 * A Class representing a Google Toolbar offer
 * 
 * @extends adobe.polarbear.products.base
 */
adobe.polarbear.products.GTB = Class.create(adobe.polarbear.products.base, {
	/**
	 * @constructor
	 * @param  $super  	   reference to parent class
	 * @param  properties  object returned from polar bear container
	 * @param  utility     an instance of the utility class
	 * @return 			   self
	 */
	initialize : function($super, properties, utility) {		
		// initialize common properties from the base class
		$super(properties, utility);
		
		// initialize local properties
		this.type = "addon";
		this.usesOmniture = true;
		this.properties = properties;
		this.id = "gtb";
		return this;
	},
	
	/**
	 * Runs preinstallation and eligibility checks, and stores
	 * results in instance members
	 * 
	 * @return self
	 */
	prepare : function() {
		this.preinstalled = this.isVerGTE();
		this.eligible = this.preinstalled ? false : this.userIsEligible();
		return this;	
	},
	
	/**
	 * GTB eligibility test
	 * 
	 * @return  boolean
	 */
	userIsEligible : function() {
		var u = this.utility;
		return (((u.isWin2k3 || u.isWinXP || u.isWinVista || u.isWin7) && u.compatibleIEVersion) && !u.isAol);
	},
	
	/**
	 * Runs GTB preinstallation test
	 * 
	 * @return  boolean
	 */
	isVerGTE: function() {
		try {
			var theBho = this.initBho();
			if (null != theBho) {
				return true;
			} else {
				return false;
			}
		} catch (err) { return true; }
	},

	/**
	 * GTB preinstallation test 
	 * 
	 * @return  string
	 */
	initBho: function() {
		var bInitBho = false;
		var theBho = null;
		if(!bInitBho) {
			bInitBho = true;
	
			var y = document.createElement( "div" );
			var bho = document.createElement( "OBJECT" );
			bho.width = 1;
			bho.height = 1;
			bho.classid ="clsid:2318C2B1-4965-11d4-9B18-009027A5CD4F";
			bho.id ="bho";
			y.appendChild( bho );
	
			var bho2 = document.createElement( "OBJECT" );
			bho2.width = 1;
			bho2.height = 1;
			bho2.classid ="clsid:2318C2B1-4965-11d4-9B18-009027A5CD4F";
			bho2.id ="bho2";
			y.appendChild( bho2 );
	
			if (null != bho2 && "undefined" != typeof(bho2) && null != bho2.object) {
				theBho = bho2;
			} else if (null != bho && "undefined" != typeof(bho) && null != bho.object) {
				theBho = bho;
			}
		}
	
		return theBho;
	}
	
});

/**
 * A Class representing a McAfee Security Scan offer
 * 
 * @extends adobe.polarbear.products.base
 */
adobe.polarbear.products.MSS = Class.create(adobe.polarbear.products.base, {
	/**
	 * @constructor
	 * @param  $super  	   reference to parent class
	 * @param  properties  object returned from polar bear container
	 * @param  utility     an instance of the utility class
	 * @return 			   self
	 */
	initialize : function($super, properties, utility) {		
		// initialize common properties from the base class
		$super(properties, utility);
		
		// initialize local properties
		this.type = "addon";
		this.usesOmniture = true;
		this.properties = properties;
		this.id = "mss";

		return this;
	},
	
	/**
	 * Runs eligibility check and stores
	 * results in instance member
	 * 
	 * @return self
	 */
	prepare : function() {
		this.eligible = this.userIsEligible();
		return this;
	},
	
	/**
	 * MSS eligibility test
	 * 
	 * @return  boolean
	 */
	userIsEligible : function() {
		var u = this.utility;
		return (u.isWinXP || u.isWinVista || u.isWin7);
	}
});

/**
 * A Class representing a Google Chrome offer
 * 
 * @extends adobe.polarbear.products.base
 */
adobe.polarbear.products.CHR = Class.create(adobe.polarbear.products.base, {
	/**
	 * @constructor
	 * @param  $super  	   reference to parent class
	 * @param  properties  object returned from polar bear container
	 * @param  utility     an instance of the utility class
	 * @return 			   self
	 */
	initialize : function($super, properties, utility) {		
		// initialize common properties from the base class
		$super(properties, utility);
		
		// initialize local properties
		this.type = "addon";
		this.usesOmniture = true;
		this.properties = properties;
		this.id = "chr";

		return this;
	},
	
	/**
	 * Runs eligibility check and stores
	 * results in instance member
	 * 
	 * @return self
	 */
	prepare : function() {
		this.eligible = this.userIsEligible();
		return this;
	},
	
	/**
	 * CHR eligibility test
	 * 
	 * @return  boolean
	 */
	userIsEligible : function() {
		var u = this.utility;
		return ((u.isWinXP || u.isWinVista || u.isWin7) && !u.isChrome && !u.isFF);
	}
});

/**
 * A Class representing a Acrobat.com offer
 * 
 * @extends adobe.polarbear.products.base
 */
adobe.polarbear.products.AIRBundle = Class.create(adobe.polarbear.products.base, {
	/**
	 * @constructor
	 * @param  $super  	   reference to parent class
	 * @param  properties  object returned from polar bear container
	 * @param  utility     an instance of the utility class
	 * @return 			   self
	 */
	initialize : function($super, properties, utility) {		
		// initialize common properties from the base class
		$super(properties, utility);
		
		// initialize local properties
		this.type = "bundle";
		this.usesOmniture = false;
		this.properties = properties;

		return this;
	},
	
	/**
	 * Runs eligibility check and stores
	 * results in instance member
	 * 
	 * @return self
	 */
	prepare : function() {
		this.eligible = this.userIsEligible();
		return this;
	},
	
	/**
	 * Acrobat Bundle eligibility test
	 * 
	 * @return  boolean
	 */
	userIsEligible : function() {
		var u = this.utility;
		return (((u.isWin2k3 || u.isWinXP || u.isWinVista || u.isWin7) && (u.compatibleIEVersion || u.compatibleFFVersion || u.isSafari || u.isOpera || u.isChrome)) && !u.isAol);	
	}
});

/**
 * adobe.polarbear.utility
 */
adobe.polarbear.utility = Class.create({
	
	/**
	 * @constructor
	 * @return       void
	 */
	initialize: function(){
		this.ua = navigator.userAgent;
		
		// properties for specific browsers
		this.isIE6 = this.ua.match(/MSIE 6/) != null;
		this.isIE7 = this.ua.match(/MSIE 7/) != null;
		this.isIE8 = this.ua.match(/MSIE 8/) != null;
		this.isIE9 = this.ua.match(/MSIE 9/) != null;
		this.isIE10 = this.ua.match(/MSIE 10/) != null;
		this.is64bitIE = this.ua.match(/Win64|x64/) != null;
		this.is32IEonVista64 = this.ua.match(/WOW64/) != null && this.isIE7;
		this.isFF = this.ua.match(/Firefox/) != null;
		this.isFF9 = this.ua.match(/Firefox\/9/) != null;		
		this.isFF8 = this.ua.match(/Firefox\/8/) != null;		
		this.isFF7 = this.ua.match(/Firefox\/7/) != null;		
		this.isFF6 = this.ua.match(/Firefox\/6/) != null;
		this.isFF5 = this.ua.match(/Firefox\/5/) != null;		
		this.isFF4 = this.ua.match(/Firefox\/4/) != null;
		this.isFF3 = this.ua.match(/Firefox\/3/) != null;
		this.isFF2 = this.ua.match(/Firefox\/2/) != null;
		this.isFF15 = this.ua.match(/Firefox\/1\.5/) != null;
		this.compatibleIEVersion = this.isIE10 || this.isIE9 || this.isIE8 || this.isIE7 || this.isIE6;
		this.compatibleFFVersion = this.isFF9 || this.isFF8 || this.isFF7 || this.isFF6 || this.isFF5 || this.isFF4 || this.isFF3 || this.isFF2 || this.isFF15;
		this.isSafari = this.ua.match(/Safari/) != null && this.ua.match(/Chrome/) == null;
		this.isOpera = this.ua.match(/Opera/) != null;
		this.isChrome = this.ua.match(/Chrome/) != null;
		
		// properties for specific os/platforms
		this.isWin2k = this.ua.match(/Win(dows)? ?(NT 5.0)/) != null && this.ua.match(/Win(dows)? ?(NT 5.01)/) == null;
		this.isWin2k3 = this.ua.match(/Windows NT 5.2/) != null;
		this.isWinXP = this.ua.match(/Win(dows)? ?(NT 5.1)/) != null;
		this.isWinXPSP2 = this.ua.match(/SV1/) != null && this.isWinXP;
		this.isWinVista = this.ua.match(/Win(dows)? ?(NT 6.0)/) != null;
		this.is64bitVista = this.isWinVista && this.is64bitIE;
		this.isWin7 = this.ua.match(/Win(dows)? ?(NT 6.1)/) != null;
		this.isAol = this.ua.match(/America Online Browser|AOL/) != null;
		this.isMac = this.ua.match(/Mac/) != null;
	}
}); 
if(AIRBundle!='defined')
{
var AIRBundle="";
}
var RDC = Class.create({

	bootstrap   :   function(fetchReader) {

		// first create a utlity object for other classes to take advantage of
		utility = new SwissArmyKnife();

		offers = new adobe.polarbear.rdcOffers();
		
		// not all funnels need an ajax request for reader items
		if(fetchReader) new RDR_Request();

		// load Display Class
        rdrDisplay = new RDR_Display();

		// create a addons object for other classes to take advantage of
        if (window.addonsjson && window.addonsjson.length) {
			addons = new Addons();
			addons.processAddons();
		}
		
		if(!fetchReader) document.fire("display:main");
	}	
});

/* ***************************************
 * RDR_ CLASSES OVERWRITTING BASE CLASSES
 *************************************** */

var RDR_Request = Class.create(Request, {

	initialize   :   function($super) {
		$super();
		//load criteria map
		document.observe("otherVersion:loadCriteriaMap", this._getCriteriaMap.bindAsEventListener(this,"Reader"));
	},
	
	getAjaxUrl	:	function(){
		var url = "/reader/webservices/json/standalone/" + this.prepareQueryString();
		return url;
	},
	
	getResultDisplay	:	function(eventname){
		var displayResult;

		switch(eventname) {		
			case "readermoreinfo" :
				displayResult = "display:moreinfo";
			break;
			
			case "readerotherversions" :
				displayResult = "display:otherversions";
			break;
			
			case "readerenterprise" :
			case "readerdirect":
				displayResult = "display:enterprise";
			break;
		}

		return displayResult;
	},
	
	getInstallerResultDisplay	:	function(eventname){
		var installerDisplayResult;

		switch(eventname) {		
			case "readermoreinfo" :
				displayResult = "display:moreinfoShowInstallers";
			break;
			
			case "readerotherversions" :
				displayResult = "display:otherversionsShowInstallers";
			break;
			
			case "readerenterprise" :
			case "readerdirect" :
				displayResult = "display:enterpriseShowInstallers";
			break;
		}

		return displayResult;
	},
	
	prepareQueryString	   :   function($super) {
		var os				= $F("select_os");
		var eventname		= $F("eventname");
		var query_as		= criteriamap.platforms[os].properties;
		var query_string 	= "?";
		
		// enumerate over query_as and load query_string with key/values
		for(key in query_as) {
			query_string += key + "=" + query_as[key] + "&";
		}
		
		query_string += "eventname=" + eventname;
		
		var language = $F("select_language");
		
		query_string += "&language=" + language;

		return query_string;
	}
});

var RDR_Display = Class.create(Display, {
	
	initialize   :   function($super) {
		
		// base.js is setting the observe on 'otherversions' and 'noSelection'
		// it is also setting the observer on the buttonDownload
		$super();
		document.observe("display:main", this._displayMain.bindAsEventListener(this));
		
		document.observe("display:moreinfo", this._displayMoreInfo.bindAsEventListener(this));
		document.observe("display:moreinfoShowInstallers", this._onMoreInfoInstallerFetchSuccess.bindAsEventListener(this));

		document.observe("display:enterprise", this._displayEnterprise.bindAsEventListener(this));
		document.observe("reader:addonClick", this._termOfService.bindAsEventListener(this));
	},
	
	_termOfService   :   function() {
		try {
			
			if(!$('addon')) return;
			
			if ($('addon').value == '' || $('addon').value == null) {
				$('addon').checked = false;
			}
			
			if ($('addon').checked && utility.aih_compatible()) {
				if ($("gtb").visible()) { this.setEULA("gtbEULA");this.setResources("gtbResources"); }  // set gtb eula and resource links
				if ($("mss").visible()) { this.setEULA("mssEULA");this.setResources("mssResources"); } // set mss eula and resource links
				if ($("chr").visible()) { this.setEULA("chrEULA");this.setResources("chrResources"); } // set chr eula and resource links
			}
			else { // set adobe eula and resource links
				this.setEULA("adobeEULA"); 
				this.setResources("adobeResources");
			}
		} catch (e) {
				errorHandler (e);
		}
	},	
	
	_displayMain   :   function(event) {
		// we need to process the version in case we have a Reader 9 that isn't
		// actually compatible with the air bundle (ex: Win7)
		try {			
			utility.set_can_bundle_with_air();		
			this.updateClientSize();
		}
			catch (e) {
				errorHandler (e);
		  }
	},

/* -------------------- for reder more info page ------------------------- */	
	_displayMoreInfo   :   function(event) {
		try {
			this._popMoreInfoOS_select(event); //populate os select dropdown
			this.setEULA("adobeEULA");
		}
			catch (e) {
				errorHandler (e);
		  }
	},
	
	_popMoreInfoOS_select	:	function(e) {
		// populate os dropdown options
		// clears download content div
		criteriamap = e.memo;
		var osObj = $("select_os");
		this.curtainsDown();
	  	for (key in ontology) {
			if (key.match(/Mac/)) {
				var option = new Element("option", { "value" : key }).update(criteriamap.platforms[key].label);
	 			osObj.insert(option);
			}
		}
		$("select_os").observe("change", this._osMoreInfoChangeHandler.bindAsEventListener(this)); //reader more info OS selection
		$('ajaxloading').hide();
	},
	
	_osMoreInfoChangeHandler	:	function(e) {
		// ajax call to get installers available
		// populate version dropdown options from json returned
		// reset EULA
		this.curtainsDown();
		document.fire("otherVersion:getInstallers");
	},
	
	_onMoreInfoInstallerFetchSuccess   :   function(event) {
		readerjson 			= event.memo;
		var installerObj = $("installer");
		var installercontent = $("installerContent");
		if(readerjson.length) {
			var version = readerjson[0].Version.toString().replace(/^10$/, "X");
			version = readerjson[0].Version.toString().replace(/^10(.\d\d{0,1}){1,2}$/, "X (" + readerjson[0].Version.toString() + ")");
			installercontent.update("<b>Adobe Reader " + version + "</b><br>" + readerjson[0].language_type + "");
			installerObj.value = readerjson[0].queryName;
			$("clientfilesize").update((otherLocale())? dotToComma(readerjson[0].file_size) : readerjson[0].file_size);	// dot to comma conversion
			utility.set_aih_compatible_installer(readerjson[0].aih_compatible);
			suffix = readerjson[i].aih_version_suffix ? readerjson[i].aih_version_suffix : "";
			utility.set_can_bundle_with_air(readerjson[0].Version,readerjson[0].language_type, suffix); //for otherversions AIR bundle text
		  	this.makeaddonoffer();
		  	this._termOfService();
	        if(utility.get_can_bundle_with_air()) {this.updateClientSize();}
		    this.curtainsUp();
		} else {
			document.fire("display:otherVersionsNoInstaller");
		}
	},
/* -------------------- end for reder more info page ------------------------- */	

/* -------------------- for reder other versions page ------------------------- */
	_displayOtherVersions   :   function(event) {
		try {
			this._popOS_select(event); //populate os select dropdown
			if ($("error-message") != undefined)
				$("error-message").hide();
			this.setEULA("adobeEULA");
		} catch (e) {
				errorHandler (e);
		  }
	},
	
	_popOS_select	:	function(e) {
		// populate os dropdown options
		// clears download content div
		criteriamap = e.memo;
		var osObj = $("select_os");
		this.curtainsDown();
	  	for (key in ontology) {
	  		var option = new Element("option", { "value" : key }).update(criteriamap.platforms[key].label);
	 		osObj.insert(option);
		}
		$("select_os").observe("change", this._osChangeHandler.bindAsEventListener(this)); //reader other version OS selection
		$('ajaxloading').hide();
	},
	
	
	_osChangeHandler	:	function(e) {
		// clears language and version dropdown options if necessary,
		// populate language dropdown options from hard coded json, based on OS selection
		// clears download content div
		// reset EULA
		if(adobe.hostEnv.ie6) {
			$('installer').setStyle({
			  'width': ''
			});
			$('select_language').setStyle({
			  'width': ''
			});
		}
		this.curtainsDown();
		var lanObj = $("select_language");
		var os_selected = $F("select_os");
		
		lanObj.childElements().each(function(s) {
			if (s.value!=0) {s.remove();}
		});// clear out lan box
		
		$("installer").childElements().each(function(s) {
			if (s.value!=0) {s.remove();}
		});// clear out version box
		
		if (os_selected!=0) {
			ontology[os_selected].each(function(s) {
			  	var option = new Element("option", { "value" : s }).update(criteriamap.languages[s].label);
			 	lanObj.insert(option);
			});

    	if(adobe.hostEnv.ie6) {
			$('select_language').setStyle({
			  'width': 'auto'
			});
		 }

		}
		//reader other version language selection
		$("select_language").stopObserving("change"); //remove any previous listners
		$("select_language").observe("change", this._lanChangeHanlder.bindAsEventListener(this,criteriamap));
		$('ajaxloading').hide();
	},
	
	_lanChangeHanlder	:	function(e) {
		// ajax call to get installers available
		// populate version dropdown options from json returned
		// reset EULA
		this.curtainsDown();
		$("installer").childElements().each(function(s) {
			if (s.value!=0) {s.remove();}
		});// clear out version box
		
		// Bug 96560 - redirect users who are downloading mobile version
		if ($F("select_os") == "Mobile") {
			return location.href = "http://www.quickoffice.com/store/s60-3rd-edition/adobe-reader-le-v25/"
		};
		
		//fire off event to get installers
		document.fire("otherVersion:getInstallers");
	},
/* -------------------- end reder other versions page ------------------------- */
		
	_displayEnterprise   :   function(event) {
		try {
			this._popOS_select(event); //populate os select dropdown
			
			if ($("error-message") != undefined)
				$("error-message").hide();

			this.setEULA("adobeEULA");
		}
			catch (e) {
				errorHandler (e);
		  }
	},

	_onDownloadClick   :   function(event) {
		try {
			var f = document.forms["downloadForm"];
			var eventname = $("eventname").value;
			//if it is the other versions page and no installer is selected, the download button should be disabled
			if (eventname=="readerotherversions" && $F("installer")==0) {
				return false;
			}
			var radioChoice = utility.$RF('downloadForm', 'installer');
			var installer = "?installer=";
			installer += radioChoice != null ? radioChoice : $F("installer");
			var choice = $("addon") ? $("addon").checked : false;
			var addons = offers.toQueryString(choice);
			var queryString = addons ? installer + "&" + addons : installer;
			var href = $('buttonDownload').href;
			var item = false;
			
			// bug 127589 set an offer cookie 
			if (item = offers.getEligibleItem())
			{
				offers.setOfferCookie("reader", item.id, choice);
			}
			
			if (browser == "MSN" || (browser == "OEM" && utility.isIE)) {
				browser = "ie";
			} else if (browser == "OEM" && utility.isOpera) {
				browser = "opera";
			}

			if (eventname != "readerenterprise" && eventname != "readerdirect" && utility.aih_compatible()) {
				// send dlm flow to download page
				queryString += "&os=" + os + "&browser=" + browser;
				
				if (browser == "ie") {
					window.open(host + "/reader/download/msie/" + queryString, "msiedownload", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=1,width=1");
				}
				
				href += queryString;
			} else {
				// send sai flow to completion page
				href = href.replace(/download/i, "completion");
				href += installer;
			}
			$('buttonDownload').setAttribute("href", href);	
		} catch (e) {
			errorHandler (e);
		}
	},
	
	_displayNoSelection   :   function() {
		try {
			$("ajaxloading").hide();
			$("error-message").show();
		}
			catch (e) {
				errorHandler (e);
		  }
	},
	
	_displayAddons   :   function(event) {
		try {
			var div = event.memo.div;			
			var addonfilesizediv = "addonfilesize" + event.memo.div;
			var addonCheckboxDiv = "addon-checkbox-" + event.memo.div;
			var isChecked = event.memo.checked === undefined ? true : event.memo.checked;
			var checkboxAttribute = isChecked ? 'checked="checked"' : '';
			addonCheckbox = '<input id="addon" name="addon" value="true" type="checkbox" ' + checkboxAttribute + ' onclick="document.fire(' + "'reader:addonClick'" + ',{ checked: this.checked })">';$(addonCheckboxDiv).update(addonCheckbox);
			$(addonfilesizediv).update((otherLocale())? dotToComma(event.memo.size) : event.memo.size);		// dot to comma conversion				
			this.set_ContainerTextAdjust('addonsubtextmss',44,'<br//>');
			$(div).show();
			$(div).up("div").show();
			showaddon = true;
		}
			catch (e) {
				errorHandler (e);
		  }
	},

	updateClientSize   :   function() {
		var installer_name = $F("installer");
		if (installer_name.match(/Windows/) || installer_name.match(/Mac/)){
			if(AIRBundle != undefined && AIRBundle && AIRBundle.eligible){
				client = parseFloat($("clientfilesize").innerHTML);
				bundle = AIRBundle.properties.file_size;
				$("clientfilesize").update(Math.round((client + bundle)*100)/100);
			}
		}
		
		if(otherLocale()) {
			$("clientfilesize").update(dotToComma($("clientfilesize").innerHTML));
		}
	},
	
	processVersion   :   function(version) {
		// installers that can be bundled with air/acrobat have an extra descriptive string
		// in the version field from the admin.  the possibity exists that a user could request
		// an installer that is able to be bundled with air/acrobat, but their configuration
		// is dlm incompatible, so we must remove the air/acrobat information from the version #
		// this will most likely only happen on the otherversions flow
		
		// some version numbers will be considered strings (8.1.3, 9.1 with Acrobat.com....) and
		// some will be numbers.  make sure version is a string so we can perform indexOf() below.
		if(typeof version != "string") version = version.toString();
		
		var found = version.search(/<br(\s\/)?>/i);
		
		if(found != -1 && !addons.getInstallAir()) {
			return version.substring(0, found);
		} else {
			return version;
		}
	}
});

var Addons = Class.create({
		
	initialize   :   function() {
		this.addonsjson = addonsjson;
		this.installAir = 0;
		this.airInstallSize = 0;
		return this;
	},
	
	processAddons   :   function() {
		s_prop34 = "Reader: ";
		
		offers.loadProducts(addonsjson);

		if (utility.aih_compatible()) {				
			gtbobj = offers.getProduct("GTB");			
			mssobj = offers.getProduct("MSS");
			chrobj = offers.getProduct("CHR");
			AIRBundle = offers.getProduct("AIRBundle");
			
			// override primary / secondary offer tests by cookie
			if (gtbobj === undefined) gtbobj = {};
			if (mssobj === undefined) mssobj = {};
			if (chrobj === undefined) chrobj = {};
			
			try {
				if (cookie = offers.getOfferCookie("reader")) {
					if (cookie.type == "gtb") {
						if (gtbobj.properties === undefined) {
							offers.removeOfferCookie("reader");
							throw "CookieNotAvailable";
						}
						gtbobj.eligible = true;
						mssobj.eligible = false;
						chrobj.eligible = false;
						document.fire("display:addons", {
							size: gtbobj.properties.file_size,
							div: "gtb",
							checked: cookie.choice
						});
					}
					else 
						if (cookie.type == "mss") {
							if (mssobj.properties === undefined) {
								offers.removeOfferCookie("reader");
								throw "CookieNotAvailable";
							}
							mssobj.eligible = true;
							chrobj.eligible = false;
							gtbobj.eligible = false;
							document.fire("display:addons", {
								size: mssobj.properties.file_size,
								div: "mss",
								checked: cookie.choice
							});
						}
						else 
							if (cookie.type == "chr") {
								if (chrobj.properties === undefined) {
									offers.removeOfferCookie("reader");
									throw "CookieNotAvailable";
								}
								chrobj.eligible = true;
								gtbobj.eligible = false;
								mssobj.eligible = false;
								document.fire("display:addons", {
									size: chrobj.properties.file_size,
									div: "chr",
									checked: cookie.choice
								});
							}
				}
				else {
					throw "CookieNotAvailable";
				}
			} 
			catch (e) {
				// test for our primary offer
				if (gtbobj && gtbobj.eligible) {
					if (mssobj) 
						offers.disable("MSS");
					if (chrobj) 
						offers.disable("CHR");
					
					document.fire("display:addons", {
						size: gtbobj.properties.file_size,
						div: "gtb"
					});
				}
				else {
					// test for our secondary offers
					secondaryOffers = [];
					
					if (mssobj && mssobj.eligible) {
						// add mss into secondary offer structure
						secondaryOffer = {
							obj: mssobj,
							percent: .50
						};
						secondaryOffers.push(secondaryOffer);
					}
					
					if (chrobj && chrobj.eligible) {
						// add chr into secondary offer structure
						secondaryOffer = {
							obj: chrobj,
							percent: .50
						};
						secondaryOffers.push(secondaryOffer);
					}
					
					if (secondaryOffers.length > 0) {
						if (secondaryOffers.length == 1) 
							eligibleOffer = secondaryOffers[0].obj; // make offer for the only offer we're eligible for
						else 
							eligibleOffer = offers.selectSecondaryOffer(secondaryOffers); // feed secondaryOffers into decision maker
						document.fire("display:addons", {
							size: eligibleOffer.properties.file_size,
							div: eligibleOffer.id
						});
					}
				}
			}
			
			if(AIRBundle != undefined && AIRBundle && AIRBundle.eligible) {
				this.setInstallAir(1);
				this.setAirInstallSize(AIRBundle.properties.file_size);
			}		
		}
		
		rdrDisplay._termOfService(); //determind the proper eula to show
		s_prop34 += offers.toOmnitureString();
	},
	
	setInstallAir   :   function(install) {
		this.installAir = install;
	},
	
	getInstallAir   :   function() {
		return this.installAir;
	},
	
	setAirInstallSize   :   function(size) {
		this.airInstallSize += size;
	},
	
	getAirInstallSize   :   function() {
		return this.airInstallSize;
	}
});

function getReaderVersion() {
	
	/*********** IE **************/
	try { 
		// used by Adobe Reader version 7 and later 
		return getVersionForOmniture( getVersionViaActiveX('AcroPDF.PDF') );
	} catch (e) {};
	
	try { 
		// used by version 6 and earlier
		return getVersionForOmniture( getVersionViaActiveX('PDF.PdfCtrl') );
	} catch (e) {};
	
	/**** FF, Safari & Chrome *****/
	try { 
		var browserPlugins = window.navigator.plugins;
		for (var i = 0; i <= browserPlugins.length; i++) {
			if ( browserPlugins[i].name.match(/Adobe Acrobat/)) {
				var versionString = browserPlugins[i].description.split(" ").pop();
				return getVersionForOmniture(versionString);
			} 
		}
	} catch(e) {};
	
	return getNoReader()
}

function getVersionViaActiveX( PDFString ) {
	var objReader = new ActiveXObject(PDFString);
	
	var versionNumbers = [ 'x', 'x', 'x' ];
	
	// something like Accessibility=10.1.
	var firstKeyValuePair = objReader.GetVersions().split(',')[0].split('=');
	
	for (var i = 0; i <= firstKeyValuePair.length; i++) {
		if ( i == 1 ) {
			
			// get plugin version number string
			var intPluginVersion = new Number( parseFloat(firstKeyValuePair[i]) );
			var fullVersion = new String( intPluginVersion );
			
			// make string into an array
			var versionElements = fullVersion.split('.');
			
			for (var ii = 0; ii <= ( versionElements.length-1 ); ii++ ) {
				
				versionNumbers[ii] = versionElements[ii];
			}
		}
	}
	return versionNumbers.join('.');
}

function getNoReader() {
	return "No Reader";
}

function getVersionForOmniture(versionString) {
	var versionNumbers = versionString.split('.');
	
	if (versionNumbers.length >= 2) {
		return "Reader " + versionNumbers[0] + "." + versionNumbers[1];
	} 
	return getNoReader();
}

try { var s_prop5 = getReaderVersion(); } catch (e) {}
