var iActiveTabCard = 1;
var oOpenPopup = null;
var tPopupTimer = null;
var iCurrentStep = 0;
var sPreHighlightClass = '';
var jFundSelected = '';
var jPrevBgColor = '';
var jPrevColor = '';

var j_cur_language = "EN";
var j_nr_of_dwnlds = 1;
var j_tab_choosen = 'overview';

function showMetadataOnly(j_fileFormat, j_section, j_title, j_abstract, j_creation_date)
{ var j_section_found = false;
 if (j_fileFormat.indexOf('idcmeta/html') == 0)
 { document.getElementById('article').style.display = 'none';
   
   if (j_section == 'FAQ')
   { document.write('</div>');
     document.write('<div id="local" class="showhideBlock"> ');
     document.write('  <div id="local" class="item"> ');
   	 document.write('    <a name="question" href="#" onclick="showCategory(this,111);return false;">'+j_title+'</a>');
     document.write('  </div>');
     document.write('  <div id=111 class="showhideText" ><p>'+j_abstract+'</p>');
     document.write('  </div>');
     var divobj = document.getElementById(111);
     if (getCurrentStyle(divobj, 'display') == 'none')
	   { divobj.style.display = 'block';
	   }
     document.write('</div>');
     document.write('<div>');
     j_section_found = true;
   }
   if (j_section == 'Movers')
   { document.write('</div>');
     document.write('<span class="moverdate">'+j_creation_date+'</span>');
     document.write('<ul class="overview">');
     document.write('<li class="clearfix">');
     document.write('<h4>'+j_title+'</h4>');
     document.write('<p>'+j_abstract+'</p>');
     document.write('</li>');
     document.write('</ul>');

     document.write('<div>');    
     j_section_found = true;
   }
   if (j_section_found)
   {
   } else
   { document.write('</div><div class=articlecontent>');
   	 document.write('<p>'+j_title+'</p>');
     document.write('<p>'+j_abstract+'</p>');
   }
 }
}
function printlist(){
top.overviewframe.focus();
  oObject = overviewframe.document.getElementById('masterlisttable');
	if (oObject != null)
	{ oObject.style.height = 'auto';
	  oObject.style.width = '600px';
	  oObject.style.overflowY = 'hidden';
	var oOverviewFrame = top.document.getElementById('overviewframe');
	var oOverviewTable = oOverviewFrame.contentWindow.document.getElementsByTagName('table')[0];
	//IE only: Show/hide the cells
	if (document.all) //IE only
	{			for (var r = 0; r < oOverviewTable.rows.length; r++)
				{
					oOverviewTable.rows[r].cells[1].style.display = 'block';
					oOverviewTable.rows[r].cells[2].style.display = 'block';
					oOverviewTable.rows[r].cells[3].style.display = 'block';
				}
		}
	}
top.overviewframe.print();
	if (oObject != null)
	{ oObject.style.height = '323px';
	  oObject.style.width = '470px';
	  oObject.style.overflowY = 'scroll';
	}
ShowOverview(j_tab_choosen);	
	
}
  
function show_dwnld(j_language)
{ j_object = document.getElementById('li_'+j_cur_language);
  if (j_object != null)
  {   j_object.style.color = '999'; 
  }
  j_object = document.getElementById('li_'+j_language);
    if (j_object != null)
  { j_object.style.color = 'f60'; 
  }
  for (i=0;i<j_nr_of_dwnlds;i++)
  { Hide('dwnld_'+j_cur_language+'_'+i);
    Show('dwnld_'+j_language+'_'+i);
  }
  j_cur_language = j_language;
}

function changeText(j_div,j_text) {
        if(document.layers) {
            document[j_div].document.open();
            document[j_div].document.write(j_text);
            document[j_div].document.close();
        } else {
            document.all[j_div].innerHTML = j_text;
        }
}  
function Show(oObject)
{
	if (typeof(oObject) == 'string')
	{
		oObject = document.getElementById(oObject);
	}
	if (oObject != null)
	{
		oObject.style.display = 'block';
	}
}

function Hide(oObject)
{
	if (typeof(oObject) == 'string')
	{
		oObject = document.getElementById(oObject);
	}
	if (oObject != null)
	{ oObject.style.display = 'none';
	}
}

function SetTabBackground(element)
{
	var parentElements = element.parentNode.parentNode.getElementsByTagName('LI');
	for(var i = 0; i < parentElements.length; i++)
	{
		parentElements[i].className = '';
	}
	element.parentNode.className = 'active';
}

function ActivateTabCard(oInactiveLayer) {
	var oActiveTabCard = document.getElementById('tabcard_' + iActiveTabCard);
	if (oActiveTabCard != null)
	{
		oActiveTabCard.className = 'tabcard';
		var oTabCard = oInactiveLayer.parentNode.parentNode;
		oTabCard.className = 'tabcard_active';
		iActiveTabCard = parseInt(oTabCard.id.split('_')[1], 10);
	}
}

function ShowPopup(e, sPopupId)
{
	//var iList = oFundLink.id.split('_')[1];
	//var iFund = oFundLink.id.split('_')[2];
	var oPopup = document.getElementById(sPopupId);
	if (oPopup != null)
	{
		//Close the current popup (if available)
		if (oOpenPopup != null)
		{
			oOpenPopup.style.display = 'none';
		}
		
		//Clear the 'closepopup' timer
		if(tPopupTimer != null)
		{
			clearTimeout(tPopupTimer);
		}
		
		//Set the this popup as the current popup
		oOpenPopup = oPopup;
		oPopup.style.display = 'block';
		
		//Get the mouse position
		xMousePos = 0;
		yMousePos = 0;
		if (document.all)
		{
			xMousePos = window.event.clientX + document.documentElement.scrollLeft + 30;
			yMousePos = window.event.clientY + document.documentElement.scrollTop;
		}
		else
		{
			xMousePos = e.pageX + 30;
			yMousePos = e.clientY;
		}
		//Set the popup position
		oPopup.style.top = yMousePos + 'px';
	//	switch (sSide)
	//	{
	//		case 'l': //Left
	//			oPopup.style.left = xMousePos - 356 - 60 + 'px';
	//			break;
	//		default: //Right
				oPopup.style.left = xMousePos + 'px';
	//			break;
	//	}
		
	}
}

function ShopPopupLeft(e, sPopupId)
{
	//var iList = oFundLink.id.split('_')[1];
	//var iFund = oFundLink.id.split('_')[2];
	var oPopup = document.getElementById(sPopupId);
	if (oPopup != null)
	{
		//Close the current popup (if available)
		if (oOpenPopup != null)
		{
			oOpenPopup.style.display = 'none';
		}
		
		//Clear the 'closepopup' timer
		if(tPopupTimer != null)
		{
			clearTimeout(tPopupTimer);
		}
		
		//Set the this popup as the current popup
		oOpenPopup = oPopup;
		oPopup.style.display = 'block';
		
		//Get the mouse position
		xMousePos = 0;
		yMousePos = 0;
		if (document.all)
		{
			xMousePos = window.event.clientX + document.documentElement.scrollLeft - 200;
			yMousePos = window.event.clientY + document.documentElement.scrollTop - 30;
		}
		else
		{
			xMousePos = e.pageX - 200;
			yMousePos = e.clientY - 30;
		}
		//Set the popup position
		oPopup.style.top = yMousePos + 'px';
		oPopup.style.left = xMousePos + 'px';
	}
}

function ClosePopup(sPopupId)
{
	//Start closing of popup
	oPopup = document.getElementById(sPopupId);
	oOpenPopup = oPopup;
	tPopupTimer = setTimeout('ClosePop()',500);
}

function ClosePop()
{
	if(oOpenPopup != null)
	{
		oOpenPopup.style.display = 'none';
		oOpenPopup = null;
	}
}

function CloseMoviePopup()
{
	//Close popup
	document.getElementById('moviepopup').style.display = 'none';
}

function HighlightFund(oFundRow)
{
	//Save the current class
	sPreHighlightClass = oFundRow.className;
	//Set the 'selected' class
	//oFundRow.className = 'selectedfund';
  // ARKO: Do not change the class but only the style settings
  // otherwise the headers will disappear
	jPrevBgColor = oFundRow.style.backgroundColor;
	jPrevColor = oFundRow.style.color;
	oFundRow.style.backgroundColor = '#EBEFF7';
	oFundRow.style.color = '#FF6600';
	
}

function UnHighlightFund(oFundRow)
{
	//Restore to the previous class
	//oFundRow.className = sPreHighlightClass;
	oFundRow.style.backgroundColor = jPrevBgColor;
	oFundRow.style.color = jPrevColor;
  if (jFundSelected)
  { jFundSelected.style.backgroundColor = '#EBEFF7';
	  jFundSelected.style.color = '#FF6600';
  }
}

function OpenMoviePopup(sMovieUrl, bUseExpressInstall)
{
	//Show the popup
	Show('moviepopup');
	//Set the height of the layer
	//document.getElementById('moviepopup').style.height = document.body.offsetHeight + 'px';
	//Position the movieplayer
	var oMovieBack = document.getElementById('movieback');
	oMovieBack.style.marginTop = (190 + document.documentElement.scrollTop) + 'px';
	
	//Load the movie in the player
	var so = new SWFObject(g_HttpRelativeWebRoot+'iml_mediaplayer_swf.swf', 'largemovie', 394, 260, '7.0.0', '#FFFFFF');
	so.addParam('scale', 'noScale');
	so.addParam('wmode', 'Transparent');
	so.addVariable('fvVideoUrl', escape(sMovieUrl));
	so.addVariable('fvCloseScript', 'CloseMoviePopup()');
	if (bUseExpressInstall)
	{
		so.useExpressInstall('swf/expressinstall.swf');
	}
	so.write('player');
}

function ShowOverview(sType)
{  var jLoopcounter = 0;
	//Get the frame
	var oOverviewFrame = top.document.getElementById('overviewframe');
	//Get the table
	var oOverviewTable = oOverviewFrame.contentWindow.document.getElementsByTagName('table')[0];
	var elements = oOverviewTable.getElementsByTagName('TD');
	var testClass = new RegExp("(^|\\s)"  + sType + "(\\s|$)");
	for(var i = 0; i < elements.length; i++)
	{ 	
    	elements[i].style.display  = (testClass.test(elements[i].className)) ? 'none' : '';
  		elements[i].style.display  = (testClass.test(elements[i].className)) ? 'block' : 'block';
	}
	var elements = oOverviewTable.getElementsByTagName('TD');
	for(var i = 0; i < elements.length; i++)
	{
		elements[i].style.display  = (testClass.test(elements[i].className)) ? 'none' : '';
  	elements[i].style.display  = (testClass.test(elements[i].className)) ? 'block' : '';
	}

	//Change the classname of the table
	oOverviewTable.className = oOverviewTable.className.split(' ')[0] + ' ' + sType;

}

function ShowFundDetails(oFundRow)
{ jFundSelected = oFundRow;
	//Get the fundId
	var sFundId = oFundRow.id.split('_')[1];
	
	//Load the details of the selected item in the detail frame
	jURL = top.document.getElementById('detailframe').contentWindow.location.href;
  jURLs = jURL.split('?');
  jNewURL = jURLs[0] + '?fundid=' + sFundId;
	top.document.getElementById('detailframe').contentWindow.location.href = jNewURL;
	
	//Clear the classname of the items
	var oTbody = oFundRow.parentNode;

	for (var i=0; i < oTbody.childNodes.length; i++)
	{
		//oTbody.childNodes[i].className = '';
		if (oTbody.childNodes[i].style)
    { oTbody.childNodes[i].style.backgroundColor = '#FFFFFF';
	    oTbody.childNodes[i].style.color = '#000066'; 
	  }  
	}
	//Set the classname of the selected item
	//oFundRow.className = 'selectedfund';	
		jFundSelected 	= oFundRow;
	oFundRow.style.backgroundColor = '#EBEFF7';
	oFundRow.style.color = '#FF6600';

	//Set the 'pre' highlightclass (for onmouseout after onclick)
	sPreHighlightClass = oFundRow.className;


}

function showCategory(obj, divid) {
    var divobj = document.getElementById(divid);
    if (getCurrentStyle(divobj, 'display') == 'none')
	{
	    divobj.style.display = 'block';
        obj.className = 'active';
    }
    else {
        divobj.style.display = 'none';
        obj.className = '';
    }
}

function validateForm()
{
	//Handle to the form
	var form = document.msgform;
	//Alert string
	var sAlert = "";
	
	//Check first name
	if (form.firstname.value == ""){
		sAlert += "The field 'First name' is required.\n";
	}
	
	//Check the last name
	if (form.lastname.value == ""){
		sAlert += "The field 'Last name' is required.\n";
	}
	
	//Check the email
	if (form.email.value == ""){
		sAlert += "The field 'Email' is required.\n";
	}
	
	//Check the message
	if (form.message.value == ""){
		sAlert += "The field 'Message' is required.\n";
	}
	
	if (sAlert.length > 0)
	{
		sAlert += "\nCorrect the field(s) and try again.";
		alert(sAlert);
		event.returnValue = false;
	}
	else
	{
		event.returnValue = true;
	}
}

function isDescendantOf(oNode, oParent)
{
	var oNodeParent = oNode.parentNode
	while(oNodeParent != null)
	{
		if (oNode.parentNode == oParent)
		{
			return true;
		}
		else
		{
			oNodeParent = oNodeParent.parentNode;
		}
	}
	return false;
}

function getCurrentStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		var computedStyle = document.defaultView.getComputedStyle(oElm, '');
		if (computedStyle != null)
		{
			strValue = computedStyle.getPropertyValue(strCssRule);
		}
		else
		{
			if (strCssRule == 'display')
			{
				return 'none';
			}
			else
			{
				return '';
			}
		}
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/-(w)/g, 
			function (strMatch, p1)
			{
				return p1.toUpperCase();
			}
		);
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}


Function.prototype.bind = function(obj)
{
	var method = this,

	temp = function()
	{
		return method.apply(obj, arguments);
	};

	return temp;
}

function activClassName(elementId, activeClass)
{
	var element = document.getElementById(elementId);
	var momentClass = element.className;

	if(!activeClass)
	{
		activeClass = 'active';
	}

	if(momentClass.search(activeClass) != -1)
	{
		element.className = element.className.replace(activeClass, '');
	}
	else
	{
		element.className += ' ' + activeClass;
	}
}

var writeInput = [];
function setWriteInput(elements, changeCLass, submitReturn)
{
	var element = '';

	for(i in elements)
	{
		element = document.getElementById(i);

		if(element)
		{
			writeInput[i] = elements[i];
			element.onfocus = function()
			{
				if(this.value == writeInput[this.id])
				{
					this.value = '';
					if(changeCLass) this.className = this.className.replace('unwrite', 'write');;
					if(submitReturn) this.form.onsubmit = function() {return true;}
				}
			};

			element.onblur = function()
			{
				if(this.value == writeInput[this.id] || !this.value)
				{
					this.value = writeInput[this.id];
					if(changeCLass) this.className = this.className.replace('write', 'unwrite');
					if(submitReturn) this.form.onsubmit = function() {return false;}
				}
			};

			if(element.value == elements[i] || !element.value)
			{
				element.value = elements[i];
				if(changeCLass) element.className += ' unwrite';
				if(submitReturn) element.form.onsubmit = function() {return false;}
			}
		}
	}
}


function $C(className)
{
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var elements = document.getElementsByTagName('*');

	for(var i = 0; i < elements.length; i++)
	{
		if(testClass.test(elements[i].className))
		{
			return elements[i];
		}
	}
}

function $CAll(className)
{
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var elements = document.getElementsByTagName('*');
	var result = new Array();
	
	for(var i = 0; i < elements.length; i++)
	{
		if(testClass.test(elements[i].className))
		{
			result.push(elements[i]);
		}
	}
	
	return result;
}

function popupVideo(title, url, videourl)
{
	destroyVideo();

	var source = '<div id="shadow"></div>';
	source += '<div class="video_box" id="video_box">';
	source += '<div class="video_container">';
	source += '<h2 id="video_title">' + title + '</h2>';
	source += '<a class="close" onclick="destroyVideo()">Close</a>';
	source += '<iframe src="' + url + '?video=' + videourl + '" scrolling="no" frameborder="0"></iframe>';
	source += '</div>';
	source += '</div>';
	$C('popup').innerHTML = source;
	
	if (document.documentElement && document.documentElement.scrollTop && document.documentElement.clientHeight){
		theTop = document.documentElement.scrollTop + (document.documentElement.clientHeight/2);
	}
	else if (document.body){
		theTop = document.body.scrollTop + (document.documentElement.clientHeight/2);
	}
	else {
		theTop = 0;
	}
	theTop = theTop - (document.getElementById('video_box').offsetHeight/2);
	document.getElementById("video_box").style.top = theTop + 'px';
	
	var element = document.getElementById('shadow');
	element.style.width = '100%';
	element.style.height = $C('wrapper').offsetHeight + 'px';
	element.style.position = 'absolute';
	element.style.zIndex = '100';
	element.style.left = '0px';
	element.style.top = '0px';

	var oTitle = document.getElementById("video_box");
	oTitle.style.cursor = "pointer";
	oTitle.onmousedown = pickIt;
	oTitle.onmouseup = dropIt;

	// BG
	var opacity = 0;
	element.style.background = '#000000';
	element.style['opacity'] = opacity / 100;
	element.style['-moz-opacity'] = opacity / 100;
	if(element.filters) element.style.filter = 'alpha(opacity=' + opacity + ')';
}

function destroyVideo()
{
	if(document.getElementById('shadow'))
	{
		$C('popup').removeChild(document.getElementById('shadow'));
	}
	if(document.getElementById('video_box'))
	{
		$C('popup').removeChild(document.getElementById('video_box'));
	}
}

function showLargeMovie(title, videourl)
{ //iPopupURL is raised in the video fragment
	popupVideo(title, jPopupURL, videourl)
}
