var EssilorFunctions = {
	monitorForms: function(){
		var failures = $('main').select('.fail .required_element');
		if (failures.length > 0) {
			failures.first().focus();
			if ($('flash')) { $('flash').scrollTo(); }
			failures.each(function(failure){
				new Form.Element.Observer(
					failure,
					0.5,
					function(el,value){
						if (!value || value == '') { el.up('.required_set').addClassName('fail'); }
						else { el.up('.required_set').removeClassName('fail'); }
					});
			});
		}
	},
	removeFailures: function(element){
		element = $(element);
		element.select('.fail .required_element').each(function(failure){
			failure.up('.required_set').removeClassName('fail');
		});
		return element;
	}
};

Element.addMethods(EssilorFunctions);

function checkCorpEntity() {
	var permission = $F('staff_staffTypeOid');
	if (permission == 'SFTP-CORPENTITY') {
		$('staff_nameLast','staff_nameMiddle').each(function(element) { element.disable().up().hide(); });
		$('staff_staffRoleOid','staff_staffTitleOid','staff_phoneNumber').each(function(element) { element.up().hide(); });
		$('staff_staffTitleOid').value = 'STTL-NA';
		$('staff_staffRoleOid').value = 'SROL-NA';
		$('staff_nameFirst').value = ($F('staff_nameFirst')+' '+$F('staff_nameMiddle')+' '+$F('staff_nameLast')).strip().gsub('\ \ ',' ').gsub('\ \ ',' ');
		$('staff_nameMiddle').value = '';
		$('staff_nameLast').value = '';
		$('staff_nameFirst').up().removeClassName('medium').addClassName('long').down('label').update('Entity Name');
	} else {
		$('staff_nameLast','staff_nameMiddle','staff_phoneNumber','staff_staffRoleOid','staff_staffTitleOid').each(function(element){ element.enable().up().show(); });
		$('staff_nameFirst').up().removeClassName('long').addClassName('medium').down('label').update('First Name');
	}
}

function change_location() {
	$('location_changer').request({
		onCreate: function() { $('location_changer').disable(); },
		onComplete: function() { document.location.reload(); }
	});
}

function to_dollars(amount) {
	amount = amount.toString();
	var dot = amount.indexOf('.');
	var amount_length = amount.length;
	if (dot >= 0) {
		if (dot == 0) amount = '0' + amount;
		if (dot+1 == amount_length) { return amount + '00'; }
		else if (dot+2 == amount_length) { return amount + '0'; }
		else if (dot+3 == amount_length) { return amount; }
		else {
			amount_front = amount.substring(0,dot+2);
			amount_back = amount.substring(dot+2,amount_length);
			return amount_front + (amount_back*1).round().toString();
		}
	} else { return amount + '.00'; }
}

function random_id() { return 'temp' + Math.random().toString(); }

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

// Rewards Forecaster

function calculateRewardsForecaster() {
	// There are two scenarios to calculate.  I'll use 'n' to get their values by id.
	$R(1,2).each(function(n){
		// Vars to retrieve from HTML
		var base_jobs, actual_jobs, base_arp, base_arv, actual_arp, actual_arv;
		// Vars to set
		var growth_arp, penetration_arp, growth_arv, penetration_arv, penetration_ar, monthly, annual;
		// Temp vars
		var payout_arp, payout_arv;
		
		// Set numbers
		
		base_jobs   = $('base_jobs'+n).innerHTML * 1;
		//actual_jobs = $('actual_jobs'+n).innerHTML * 1;
		actual_jobs = $F('actual_jobs'+n) * 1;
		base_arp    = $('base_arp'+n).innerHTML * 1;
		base_arv    = $('base_arv'+n).innerHTML * 1;
		actual_arp  = $F('actual_arp'+n) * 1;
		actual_arv  = $F('actual_arv'+n) * 1;
		
		growth_arp      = (base_arp==0)    ? 0 : (actual_arp/base_arp) - 1;
		penetration_arp = (actual_jobs==0) ? 0 : actual_arp/actual_jobs;
		growth_arv      = (base_arv==0)    ? 0 : (actual_arv/base_arv) - 1;
		penetration_arv = (actual_jobs==0) ? 0 : actual_arv/actual_jobs;
		penetration_ar  = (actual_jobs==0) ? 0 : (actual_arp+actual_arv)/actual_jobs;
		
		// the *4 and *2 here are based on core rewards programs that may change
		// ... probably shouldln't be hard-coded, so in the future we may want
		// to add hidden input fields to store these in
		payout_arp = (actual_arp<=base_arp) ? 0 : (actual_arp-base_arp) * 4;
		payout_arv = (actual_arv<=base_arv) ? 0 : (actual_arv-base_arv) * 2;
		monthly = payout_arp + payout_arv;
		annual  = monthly * 12;
		
		// Update table values
		
		if (growth_arp>0)      $('growth_arp'+n).update(Math.round(growth_arp*100)+'%');
		if (penetration_arp>0) $('penetration_arp'+n).update(Math.round(penetration_arp*100)+'%');
		if (growth_arv>0)      $('growth_arv'+n).update(Math.round(growth_arv*100)+'%');
		if (penetration_arv>0) $('penetration_arv'+n).update(Math.round(penetration_arv*100)+'%');
		if (penetration_ar>0)  $('penetration_ar'+n).update(Math.round(penetration_ar*100)+'%');
		$('monthly'+n).update('$'+addCommas(monthly.toFixed(2)));
		$('annual'+n).update('$'+addCommas(annual.toFixed(2)));		
		
		// new Effect.Highlight('monthly'+n);
		// new Effect.Highlight('annual'+n);
		
	});
	
	$$('.payout').each(function(el){
		new Effect.Highlight(el);
	});
	
}

function oldCalculateRewardsForecaster() { // D E P R E C A T E D (used for 2008 program)
	// Using class-based system to support unlimited scenarios
	$$('.payout_scenario').each(function(scenario){
		// Define variables
		var baseJobs,baseAR,actualJobs,actualAR,growthJobs,growthAR,penetrationTotal;
		var payoutGrowth = 0;
		var payoutBase = 0;
		var payoutDouble = 0;
		var payoutTotal = 0;

		// Get important values
		baseJobs = scenario.down('.payout_base_jobs').innerHTML * 1;
		baseAR = scenario.down('.payout_base_ar').innerHTML * 1;
		actualJobs = $F(scenario.down('.payout_actual_jobs')) * 1;
		actualAR = $F(scenario.down('.payout_actual_ar')) * 1;
		
		// Calculate growth percentages
		if (actualJobs>baseJobs) {
			if (baseJobs>0) { growthJobs = Math.round((actualJobs-baseJobs)/baseJobs*100); }
			else { growthJobs = "0"; }
			growthJobsNumber = actualJobs-baseJobs;
		} else {
			growthJobs = "0";
			growthJobsNumber = "0";
		}
		if (actualAR>baseAR) {
			if (baseAR>0) { growthAR = Math.round((actualAR-baseAR)/baseAR*100); }
			else { growthAR = "0"; }
			growthARNumber = actualAR-baseAR;
		} else {
			growthAR = "0";
			growthARNumber = "0";
		}

		if (actualJobs>0) { penetrationTotal = Math.round((actualAR/actualJobs)*100); }
		else { penetrationTotal = "0"; }

		// Display growth percentages
		scenario.down('.payout_growth_jobs').update(growthJobsNumber+" ("+growthJobs+"%)");
		scenario.down('.payout_growth_ar').update(growthARNumber+" ("+growthAR+"%)");
		scenario.down('.payout_penetration').update(penetrationTotal+"%");

		// Calculate payouts
		if (actualAR>baseAR) { payoutGrowth = ((actualAR-baseAR)*3.5); }
		if (actualJobs>99) { payoutBase = (actualAR>baseAR)?(baseAR*0.5):(actualAR*0.5); }
		if ((baseJobs==0 && actualJobs>29) || (baseJobs>0 && actualJobs>29 && (actualJobs/baseJobs)>1.19999) || (baseJobs>0 && actualJobs>99 && (actualJobs/baseJobs)>1.0999)) { payoutDouble = (payoutGrowth+payoutBase); }
		payoutTotal = (payoutGrowth+payoutBase+payoutDouble);

		// Display payout totals
		var element_payout_monthly = scenario.down('.payout_monthly');
		var element_payout_annual = scenario.down('.payout_annual');
		element_payout_monthly.update("$" + addCommas(payoutTotal.toFixed(2)));
		element_payout_annual.update("$" + addCommas((payoutTotal*12).toFixed(2)));
		new Effect.Highlight(element_payout_monthly);
		new Effect.Highlight(element_payout_annual);

	});

}

function trackRewardsForecaster(){
	calculateRewardsForecaster();
	$('form_rewards_forecaster').request();
}

// Profitability Predictor

function calculateProfitabilityPredictor(whichRun) {
	var inc_vsp,inc_nonvsp,inc_profit,inc_profit_increase,growth_percent,gp_temp,baseline_units,baseline_percent;
	var total_month		=	0;
	var total_quarter	=	0;
	var total_year		=	0;

	var percent_vsp		=	$F('pp_percent_vsp') / 100;
	var percent_nonvsp	=	1 - percent_vsp;
	var baseline_total	=	$('pp_baseline_total').innerHTML * 1;
	var growth_total	=	$F('pp_growth_total') * 1;
	$$('.pp_row').each(function(singleRow) {
		switch (singleRow.id) {
			case 'category0':
				inc_nonvsp	=	120;
				inc_vsp		=	25;
			break;
			case 'category1':
				inc_nonvsp	=	50;
				inc_vsp		=	26;
			break;
			case 'category2':
				inc_nonvsp	=	85;
				inc_vsp		=	23;
			break;
			case 'category3':
				inc_nonvsp	=	70;
				inc_vsp		=	23;
			break;
			case 'category4':
				inc_nonvsp	=	65;
				inc_vsp		=	20;
			break;
			case 'category5':
				inc_nonvsp	=	35;
				inc_vsp		=	15;
			break;
			case 'category6':
				inc_nonvsp	=	90;
				inc_vsp		=	50;
			break;
		}
		baseline_units		=	singleRow.down('.pp_baseline_units').innerHTML * 1;
		baseline_percent	=	(baseline_total>0)?(baseline_units / baseline_total):(0);

		if (whichRun == "initialize" && $F(singleRow.down('.pp_growth_percent')) == 0) {
			growth_percent	=	baseline_percent;
			singleRow.down('.pp_growth_percent').value = (growth_percent * 100).toFixed();
		} else {
			growth_percent	=	$F(singleRow.down('.pp_growth_percent')) / 100;
		}

		growth_units		=	Math.round((growth_total * growth_percent) - baseline_units);

		inc_profit			=	Math.round((inc_nonvsp * percent_nonvsp) + (inc_vsp * percent_vsp));
		inc_profit_increase	=	inc_profit * growth_units;

		singleRow.down('.pp_baseline_percent').update((baseline_percent * 100).toFixed() + "%");
		singleRow.down('.pp_growth_units').update(growth_units);
		singleRow.down('.pp_profit_job').update("$" + addCommas(inc_profit));
		singleRow.down('.pp_profit_increase').update("$" + addCommas(inc_profit_increase));

		total_month = total_month + inc_profit_increase;
	});

	$('pp_total_month').update("$" + addCommas(total_month));
	$('pp_total_quarter').update("$" + addCommas(total_month * 3));
	$('pp_total_year').update("$" + addCommas(total_month * 12));

	if (total_month < 0) {
		$('flash_wrapper').update("<div class=\"error\">Please note that with these sales goals, your estimated net payout is negative. Please contact your sales consultant for ways to increase your payout.</div>");
	} else { $('flash_wrapper').update(); }

	$$('.total').each(function(element){
		new Effect.Highlight(element);
	});

}

function trackProfitabilityPredictor(){
	calculateProfitabilityPredictor();
	$('form_profitability_predictor').request();
}

// Capture Rate and Staff Performance

function checkEmployeeSelected() {
	var employee = $F('employee_find');
	if (employee && employee != '') {
		$('submit').enable();
		$('calendar').select('.capture').invoke('enable');
		$('selectnote').hide();
		return true;
	}
	else {
		$('submit').disable();
		$('calendar').select('.capture').invoke('disable');
		$('selectnote').show();
		return false;
	}
}

function getStoredJobTracker(){
	$('find_job_tracker').request({
		onCreate: function() {
			$('calendar').select('.capture').invoke('clear');
			if (checkEmployeeSelected() === false) Event.stop('find_job_tracker');
			else { $('indicator_find').show(); }
		},
		onComplete: function(transport,json){
			$('indicator_find').hide();
			$('employee_track').value = $F('employee_find');
			json.each(function(job){
				var target = $('job_' + job.date);
				new Effect.Highlight(target.up(),{startcolor:'#ffff99', endcolor:'#fafafa'});
				target.value = job.rate;
			});
		}
	});
}

function changeJobTrackerDate(){
	new Ajax.Request('/actions/change_job_tracker_date.php',{
		method: 'post',
		parameters: $('calendar_wrapper').serialize(true),
		onCreate: function(){
			$('month_find').value = $F('month_track');
			$('year_find').value = $F('year_track');
		},
		onComplete: function(transport){
			$('calendar_wrapper').update(transport.responseText);
			getStoredJobTracker();
			$('month_track').observe('change',function(event){ changeJobTrackerDate(); });
			$('year_track').observe('change',function(event){ changeJobTrackerDate(); });
		}
	});
}

function storeJobTracker(){
	$('calendar_wrapper').request({
		onCreate: function(){
			if (checkEmployeeSelected() === false) Event.stop('calendar_wrapper');
			else { $('indicator_track').show(); }
		},
		onComplete: function(){
			$('indicator_track').hide();
			$('calendar_wrapper').select('.capture').each(function(target){
				if ($F(target)) new Effect.Highlight(target.up(),{startcolor:'#ffff99', endcolor:'#fafafa', duration: 1.5});
			});
		}
	});
}

function updateCaptureRateBadges(){
	var passing_rate = $('passing_rate').innerHTML;
	$('calendar').select('.rate').each(function(rate){
		var p = $F(rate.next(".capture_prescriptions"));
		var j = $F(rate.next(".capture_jobs"));
		var new_rate = calculateCaptureRate(p,j);
		
		if (new_rate>=passing_rate) rate.removeClassName('rate-low').addClassName('rate-high');
		else if (new_rate>0) rate.removeClassName('rate-high').addClassName('rate-low');
		else rate.className = 'rate';
		
		if (new_rate>999) rate.update('wow').setStyle({fontSize:'9px'});
		else if (new_rate>99) rate.update(new_rate).setStyle({fontSize:'9px'});
		else if (new_rate>0) rate.update(new_rate).setStyle({fontSize:''});
		else rate.update('&nbsp;');
	});
}

function getStoredCaptureRate(){
	$('find_capture_rate').request({
		onCreate: function() {
			$('calendar').select('.capture').invoke('clear');
			if (checkEmployeeSelected() === false) Event.stop('find_capture_rate');
			else { $('indicator_find').show(); }
		},
		onComplete: function(transport,json){
			$('indicator_find').hide();
			$('employee_track').value = $F('employee_find');
			json.each(function(single){
				var target = $(single.kind+'_'+single.date);
				target.value = single.rate;
			});
			updateCaptureRateBadges();
		}
	});
}

function changeCaptureRateDate(){
	new Ajax.Request('/actions/change_capture_rate_date.php',{
		method: 'post',
		parameters: $('calendar_wrapper').serialize(true),
		onCreate: function(){
			$('month_find').value = $F('month_track');
			$('year_find').value = $F('year_track');
		},
		onComplete: function(transport){
			$('calendar_wrapper').update(transport.responseText);
			getStoredCaptureRate();
			$('month_track').observe('change',function(event){ changeCaptureRateDate(); });
			$('year_track').observe('change',function(event){ changeCaptureRateDate(); });
		}
	});
}

function storeCaptureRate(){
	$('calendar_wrapper').request({
		onCreate: function(){
			if (checkEmployeeSelected() === false) Event.stop('calendar_wrapper');
			else { $('indicator_track').show(); }
		},
		onComplete: function(){
			updateCaptureRateBadges();
			$('indicator_track').hide();
		}
	});
}

function calculateCaptureRate(p,j){ return (!p || p<=0 || j<0) ? 0 : Math.round(j/p*100); }

// Dashboard

	// Flash Player Version Detection - Rev 1.5
	// Detect Client Browser type
	// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
	var isIE	= (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

	function ControlVersion()
	{
		var version;
		var axo;
		var e;

		// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

		try {
			// version will be set for 7.X or greater players
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			version = axo.GetVariable("$version");
		} catch (e) {
		}

		if (!version)
		{
			try {
				// version will be set for 6.X players only
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
				// installed player is some revision of 6.0
				// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
				// so we have to be careful. 
			
				// default to the first public version
				version = "WIN 6,0,21,0";

				// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
				axo.AllowScriptAccess = "always";

				// safe to call for 6.0r47 or greater
				version = axo.GetVariable("$version");

			} catch (e) {
			}
		}

		if (!version)
		{
			try {
				// version will be set for 4.X or 5.X player
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = axo.GetVariable("$version");
			} catch (e) {
			}
		}

		if (!version)
		{
			try {
				// version will be set for 3.X player
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
				version = "WIN 3,0,18,0";
			} catch (e) {
			}
		}

		if (!version)
		{
			try {
				// version will be set for 2.X player
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				version = "WIN 2,0,0,11";
			} catch (e) {
				version = -1;
			}
		}
	
		return version;
	}

	// JavaScript helper required to detect Flash Player PlugIn version information
	function GetSwfVer(){
		// NS/Opera version >= 3 check for Flash plugin in plugin array
		var flashVer = -1;
	
		if (navigator.plugins != null && navigator.plugins.length > 0) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
				var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
				var descArray = flashDescription.split(" ");
				var tempArrayMajor = descArray[2].split(".");
				var versionMajor = tempArrayMajor[0];
				var versionMinor = tempArrayMajor[1];
				if ( descArray[3] != "" ) {
					tempArrayMinor = descArray[3].split("r");
				} else {
					tempArrayMinor = descArray[4].split("r");
				}
				var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
				var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
			}
		}
		// MSN/WebTV 2.6 supports Flash 4
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
		// WebTV 2.5 supports Flash 3
		else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
		// older WebTV supports Flash 2
		else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
		else if ( isIE && isWin && !isOpera ) {
			flashVer = ControlVersion();
		}	
		return flashVer;
	}

	// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
	function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
	{
		versionStr = GetSwfVer();
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				// Given "WIN 2,0,0,11"
				tempArray				 = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
				tempString				= tempArray[1];			// "2,0,0,11"
				versionArray			= tempString.split(",");	// ['2', '0', '0', '11']
			} else {
				versionArray			= versionStr.split(".");
			}
			var versionMajor			= versionArray[0];
			var versionMinor			= versionArray[1];
			var versionRevision	 = versionArray[2];

						// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if (versionMajor > parseFloat(reqMajorVer)) {
				return true;
			} else if (versionMajor == parseFloat(reqMajorVer)) {
				if (versionMinor > parseFloat(reqMinorVer))
					return true;
				else if (versionMinor == parseFloat(reqMinorVer)) {
					if (versionRevision >= parseFloat(reqRevision))
						return true;
				}
			}
			return false;
		}
	}

	function AC_AddExtension(src, ext)
	{
		if (src.indexOf('?') != -1)
			return src.replace(/\?/, ext+'?'); 
		else
			return src + ext;
	}

	function AC_Generateobj(objAttrs, params, embedAttrs) 
	{ 
			var str = '';
			if (isIE && isWin && !isOpera)
			{
				str += '<object ';
				for (var i in objAttrs)
					str += i + '="' + objAttrs[i] + '" ';
				for (var i in params)
					str += '><param name="' + i + '" value="' + params[i] + '" /> ';
				str += '></object>';
			} else {
				str += '<embed ';
				for (var i in embedAttrs)
					str += i + '="' + embedAttrs[i] + '" ';
				str += '> </embed>';
			}

			$('flex_dashboard').update(str);
	}

	function AC_FL_RunContent(){
		var ret = 
			AC_GetArgs
			(	arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
			 , "application/x-shockwave-flash"
			);
		AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
	}

	function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
		var ret = new Object();
		ret.embedAttrs = new Object();
		ret.params = new Object();
		ret.objAttrs = new Object();
		for (var i=0; i < args.length; i=i+2){
			var currArg = args[i].toLowerCase();		

			switch (currArg){	
				case "classid":
					break;
				case "pluginspage":
					ret.embedAttrs[args[i]] = args[i+1];
					break;
				case "src":
				case "movie":	
					args[i+1] = AC_AddExtension(args[i+1], ext);
					ret.embedAttrs["src"] = args[i+1];
					ret.params[srcParamName] = args[i+1];
					break;
				case "onafterupdate":
				case "onbeforeupdate":
				case "onblur":
				case "oncellchange":
				case "onclick":
				case "ondblClick":
				case "ondrag":
				case "ondragend":
				case "ondragenter":
				case "ondragleave":
				case "ondragover":
				case "ondrop":
				case "onfinish":
				case "onfocus":
				case "onhelp":
				case "onmousedown":
				case "onmouseup":
				case "onmouseover":
				case "onmousemove":
				case "onmouseout":
				case "onkeypress":
				case "onkeydown":
				case "onkeyup":
				case "onload":
				case "onlosecapture":
				case "onpropertychange":
				case "onreadystatechange":
				case "onrowsdelete":
				case "onrowenter":
				case "onrowexit":
				case "onrowsinserted":
				case "onstart":
				case "onscroll":
				case "onbeforeeditfocus":
				case "onactivate":
				case "onbeforedeactivate":
				case "ondeactivate":
				case "type":
				case "codebase":
					ret.objAttrs[args[i]] = args[i+1];
					break;
				case "id":
				case "width":
				case "height":
				case "align":
				case "vspace": 
				case "hspace":
				case "class":
				case "title":
				case "accesskey":
				case "name":
				case "tabindex":
					ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
					break;
				default:
					ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
			}
		}
		ret.objAttrs["classid"] = classid;
		if (mimeType) ret.embedAttrs["type"] = mimeType;
		return ret;
	}

	function render_dashboard() {
		// Major version of Flash required
		var requiredMajorVersion = 9;
		// Minor version of Flash required
		var requiredMinorVersion = 0;
		// Minor version of Flash required
		var requiredRevision = 0;

		// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
		var hasProductInstall = DetectFlashVer(6, 0, 65);

		// Version check based upon the values defined in globals
		var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

		var location = $('location_selector') ? $F('location_selector') : $F('location_oid');

		// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
		if ( hasProductInstall && !hasRequestedVersion ) {
			// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
			// This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
			// DO NOT MODIFY THE FOLLOWING FOUR LINES
			// Location visited after installation is complete if installation is required
			var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
			var MMredirectURL = window.location;
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				var MMdoctitle = document.title;

			AC_FL_RunContent(
				"src", "playerProductInstall",
				"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
				"width", "100%",
				"height", "500px",
				"align", "middle",
				"id", "EssilorChart",
				"quality", "high",
				"wmode", "transparent",
				"name", "EssilorChart",
				"allowScriptAccess","sameDomain",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);
		} else if (hasRequestedVersion) {
			// if we've detected an acceptable version
			// embed the Flash Content SWF when all tests are passed
			AC_FL_RunContent(
					"src", "/dashboard/EssilorChart",
					"width", "100%",
					"height", "500px",
					"align", "middle",
					"id", "EssilorChart",
					"quality", "high",
					"wmode", "transparent",
					"name", "EssilorChart",
					"flashvars",'location=' + location,
					"allowScriptAccess","sameDomain",
					"type", "application/x-shockwave-flash",
					"pluginspage", "http://www.adobe.com/go/getflashplayer"
			);
			} else {	// flash is too old or we can't detect the plugin
				var alternateContent = 'The dashboard graph requires the Adobe Flash Player. '
			 	+ '<a href="http://www.adobe.com/go/getflash/">Get Flash</a>';
				$('flex_dashboard').update(alternateContent);	// insert non-flash content
			}
	}

  function bodyOnLoad() {
		af = document.getElementById('auto_focus');
		if (!af) af = $('user_loginName');
		if (af) {
			af.focus();
		}
	}
