// Declare namespace
function Rivkin() { }

Rivkin.openPrintableVersion= function(objLink) {
	var s_width = parseInt(parent.document.documentElement.clientWidth);
	if (s_width == 0) s_width = parseInt(parent.document.body.clientWidth);
	var s_height = parseInt(parent.document.documentElement.clientHeight);
	if (s_height == 0) s_height = parseInt(parent.document.body.clientHeight);

	var pWin = window.open(objLink.href,'_printVer','top=100,left=100,height=' + (s_height - 200) + ',width=' + (s_width - 200) + ',resizable=yes,scrollbars=yes,menubar=yes');
	pWin.focus();
	return false;
}

Rivkin.openInvestorCentreWindow = function(strHref) {
	var s_width = parseInt(parent.document.documentElement.clientWidth);
	if (s_width == 0) s_width = parseInt(parent.document.body.clientWidth);
	var s_height = parseInt(parent.document.documentElement.clientHeight);
	if (s_height == 0) s_height = parseInt(parent.document.body.clientHeight);

	var iWin = window.open(strHref,'_riv_icParallel','top=100,left=100,height=' + (s_height - 200) + ',width=' + (s_width - 200) + ',resizable=yes,scrollbars=yes');
	iWin.focus();
	return false;
}

Rivkin.openInvestorCentreParallel = function() {
	// Pre-schedule move to investor centre in source window
	setTimeout("document.location.href='" + CMS.appRoot + "InvestorCentre.aspx';",250);
	
	// Open investor centre window
	Rivkin.openInvestorCentreWindow(CMS.appRoot + 'ui.ashx?f=riv_investor_centre');
}

// Dropdown function overrides
// Close (conditionally)
Rivkin.ddCvx = function(strIdn) {
	strId = 'dm_' + strIdn;
	$(strId).dmEnable = 0;
	setTimeout('Rivkin.cVis(\'dm_'+strIdn+'\',$(\''+strId+'\').dmEnable)',100);
}

Rivkin.cVis = function(strId, dmx) {
	if (dmx != 1) { 
		var objTgt = $(strId);
		if (objTgt._hasIframe == 1) objTgt._iframe.style.display='none';
		objTgt.style.display='none';
	}
}
// Open DD
Rivkin.ddOvx = function(strIdn) {
	strId = 'dm_'+strIdn;
	strTopId = 'ml_'+strIdn;
	var objTgt = $(strId);
	objTgt.dmEnable = 1;
	objTgt.style.top=(findPosY($(strTopId)) + $(strTopId).offsetHeight + 1) + "px";
	objTgt.style.left=findPosX($(strTopId)) + "px";
	objTgt.style.display='block';
	if (document.selection) {
		// IE IFRAME underlay trick
		if (objTgt._hasIframe != 1) {
			var iFrame = document.createElement('IFRAME');
			iFrame.className = 'dd_iframe_underlay';
			iFrame.frameBorder = 'no';
			iFrame.style.display = 'none';
			iFrame.style.top = objTgt.style.top;
			iFrame.style.left = objTgt.style.left;
			iFrame.style.width = objTgt.offsetWidth + 'px';
			iFrame.style.height = objTgt.offsetHeight + 'px';
			objTgt._iframe = iFrame;
			objTgt.parentNode.appendChild(iFrame);
			objTgt._hasIframe = 1;
		}
		objTgt._iframe.style.display='block';
	}
}
// Sustain DD
Rivkin.ddSvx = function(strIdn) {
	strId = 'dm_'+strIdn;
	$(strId).dmEnable = 1;
}


// Filter recommendations
Rivkin.filterRec = function() {
	var table_obj = $('recommendation_tbl');
	var filterObjects = new Array($('r_filt_risk'),$('r_filt_type'),$('r_filt_sector'),$('r_filt_rec'));
	var filterColumns = new Array(2,3,5,6);
	var exactMatch = new Array(true,false,false,false);
	
	Rivkin.filterRecInner(table_obj, filterObjects, filterColumns, exactMatch);
}

Rivkin.filterRecInner = function(table_obj,filterObjects,filterColumns,exactMatch) {
	for (var i=0; i < table_obj.childNodes.length; i++) {
		var this_row = table_obj.childNodes[i];

		if (this_row.tagName == 'TR') {
			// we need to set it visible to make the reading of innerHTML behave
			if (document.selection) {
				// IE
				this_row.style.display = 'block';
			} else {
				// DOM
				this_row.style.display = 'table-row';	// default; make it visible
			}

			if (this_row.className == 'selected' || this_row.className == 'listhdr') {
				// formerly set-visible code
			} else {
				var foundMatch = true;

				for (var c=0; c < filterObjects.length; c++) {
					var val = filterObjects[c].value;
					if (val != null && val != '') {
						var this_cell = this_row.childNodes[filterColumns[c]];
						var innerText = this_cell.innerHTML;
						if (exactMatch[c] == true) {
							if (innerText.toLowerCase() != val.toLowerCase()) foundMatch = false;
						} else {
							if (innerText.toLowerCase().indexOf(val.toLowerCase()) == -1) foundMatch = false;
						}
					}
				}

				if (foundMatch == false) {
					this_row.style.display = 'none';
				}
			}
		} else if (this_row.tagName == 'TBODY') {
			Rivkin.filterRecInner(this_row, filterObjects, filterColumns, exactMatch);
		}
	}
}

/*
	FlashReplace is developed by Robert Nyman, http://www.robertnyman.com, and it is released according to the
	Creative Commons Deed license (http://creativecommons.org/licenses/GPL/2.0/)
*/
// ---
var FlashReplace = {
	elmToReplace : null,
	flashIsInstalled : null,
	defaultFlashVersion : 7,
	replace : function (elmToReplace, src, id, width, height, wmode, flashvars, version, params){
		this.elmToReplace = $(elmToReplace);
		this.flashIsInstalled = this.checkForFlash(version || this.defaultFlashVersion);
		if(this.elmToReplace && this.flashIsInstalled){
			var obj = '<object' + ((window.ActiveXObject)? ' id="' + id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="' + src + '"' : '');
			obj += ' width="' + width + '"';
			obj += ' height="' + height + '"';
			obj += '>';
			param = '<param';
			param += ' name="movie"';
			param += ' value="' + src + '"';
			param += '>';
			if(wmode!=""){
				param += '<param';
				param += ' name="wmode"';
				param += ' value="' + wmode + '"';
				param += '>';
			}
			if(flashvars!=""){
				param += '<param';
				param += ' name="FlashVars"';
				param += ' value="' + flashvars + '"';
				param += '>';
			}
			param += '';
			var extraParams = '';
			var extraAttributes = '';
			for(var i in params){
				extraParams += '<param name="' + i + '" value="' + params[i] + '">';
				extraAttributes += ' ' + i + '="' + params[i] + '"';
			}
			var embed = '<embed id="' + id + '" src="' + src + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"';
			if(wmode!=""){
				embed += ' wmode="' + wmode + '"';
			}
			if(flashvars!=""){
				embed += ' flashvars="' + flashvars + '"';
			}
			embed += '"';
			var embedEnd = extraAttributes + '></embed>';
			var objEnd = '</object>';
			this.elmToReplace.innerHTML = obj + param + extraParams + embed + embedEnd + objEnd;			
		}
	},
	
	checkForFlash : function (version){
		this.flashIsInstalled = false;
		if(window.ActiveXObject){
			try{
				var flash = new ActiveXObject(("ShockwaveFlash.ShockwaveFlash." + version));
				this.flashIsInstalled = true;
			}
			catch(e){
				// Throws an error if the version isn't available			
			}
		}
		else if(navigator.plugins && navigator.mimeTypes.length > 0){
			var flash = navigator.plugins["Shockwave Flash"];
			if(flash){
				var flashVersion = navigator.plugins["Shockwave Flash"].description.replace(/.*(\d+\.\d+).*/, "$1");
				if(flashVersion >= version){
					this.flashIsInstalled = true;
				}
			}
		}
		return this.flashIsInstalled;
	}
};
// ---