window.onload = chain_event_handler(window.onload, fixLinks);

function chain_event_handler(code1, code2) {
	var tempfunction = 0;
	var func1;
	var func2;
	var body = '';
	var rexpFunctionName = /function\s*(\w*)/;
	var rexpExpression = /function\s*[(]\s*[)]\s*[{]((.|\n)*)[}]/;
	
	if(code1) 
	{
		//alert(code1);
		var results = rexpFunctionName.exec(code1);
		if(results)
		{			
			func1 = results[1];	
			//alert("func1: " + func1);		
		}
	} 
	else
		return code2;

	if(code2) 
	{
		//alert(code2);
		var results = rexpFunctionName.exec(code2);
		if(results) 
		{
			func2 = results[1];
			//alert("func2: " + func2 );	
		}	
	} 
	else
		return code1;	

	
   if(document.all) 
   {
   		if(func1) 
  		{
  			//alert("func1 is a function");
  			//code1 is a function, so call it.
			body = 'this.call_' + String(tempfunction) + '=' + code1 + "\n";                   
			body += 'this.call_' + String(tempfunction) + "(event);";			
			tempfunction++;
		} 
		else 
		{
			//alert("func1 is a expression");
			var results = rexpExpression.exec(code1);

  			//code1 is an expression, so evaluate it.
			body = results[1] + ";\n";
		}
	
		if(func2) 
		{
			//alert("func2 is a function");
  			body += 'this.call_' + String(tempfunction) + '=' + code2 + "\n";
			body += 'this.call_' + String(tempfunction) + "(event);";
			tempfunction++;
		}  
		else 
		{
			//alert("func2 is a expression");
  			var results = rexpExpression.exec(code2);
			body = results[1] + ";\n";
		}
		
  } 
  else 
  {
		if(func1) 
		{
			//alert("func1 is a function");
  			//code1 is a function, so call it.
			body = 'this.' + func1 + '=' + func1 + "\n";
			body += 'this.' + func1 + "();";
		} 
		else 
		{
			//alert("func1 is a expression");
  			//code1 is an expression, so evaluate it.
			var results = rexpExpression.exec(code1);

  			//code1 is an expression, so evaluate it.
			body = results[1] + ";\n";
		}
		
		if(func2) 
		{
			//alert("func2 is a function");
  			body += 'this.' + func2 + '=' + func2 + "\n";
			body += 'this.' + func2 + "();";
		}  
		else 
		{
			//alert("func2 is a expression");
  			var results = rexpExpression.exec(code2);
			body = results[1] + ";\n";
		}
		
		/*
		if(func1) 
		{
			body += code1 + "\n";
			body += func1 + '.call(this,event)';
		}
		
		if(func2) {
			body += code2 + ";\n";
			body += func2 + '.call(this,event)';
		}
		
		*/	
	}
	
	//alert(body);
	return new Function("event", body);
}


function fixLinks() {
	var docFile  = getFilename(document.location + '');
	//alert(docFile);
	var lnks = document.links;
	var len = lnks.length;
	for (var i=0; i<len; i++) 
	{
		//alert(getFilename(lnks[i].href))
		if ( getFilename(lnks[i].href) == docFile)
		{
			//lnks[i].className = 'leftNavLinksSelected ';
			lnks[i].style.color = '#055217';
			lnks[i].style.backgroundColor = 'white';
			//lnks[i].onmouseover = emptyFn;
			//lnks[i].onmouseout  = emptyFn;
		}
	}
}

function getFilename(x) {

 	var y=x.indexOf("http://");
	 if (y == 0)
	 {
		 y=7;
	 }
	 else if (x.indexOf("https://") == 0)
	 {
		 y=8;
	 }
	 else 
	 	y=0;
	 	
   var cutFrom  = x.indexOf('/', y);
   return x.substring(cutFrom,x.length);
}

function emptyFn() {}

