/*
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
clientLib Core Module

Author:			manfred.schneiderbauer@world-direct.at
*/
var clib_core_version = 1.162;
var clib_core_filesizeK = 16;
/*

Last Changed	2004-02-25

!!! ALL CONFIGURATION SETTINGS ARE IN clib_globalconf.js	!!!
!!! DON'T ALTER ANYTHING IN THIS CODE!						!!!

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/

/*_______________________________________________________________________
PAGE INITIALIZATION FUNCTIONS
_______________________________________________________________________*/

// Return browser identity values
// Used by almost all functions in this library
function b(whichValue) {
var isDOM=document.getElementById ? true:false;
var isNN4=document.layers ? true:false;
var isIE4=document.all ? true:false;
var isOpr=false;
var isOpr7up=false;
var isLinux=false;
var isIE55up=false;
var isMac=false;
var isGecko=false;
var GeckoVersion='';
var isSafari=false;
var isKhtml=false;
if (isDOM&&isIE4) {var isIE5up=true; isIE4=false; isDOM=false;} else {var isIE5up=false;}
if ((isIE5up)&&(navigator.appVersion.indexOf('MSIE 5.0')==-1)) {isIE55up=true;}
if (navigator.userAgent.indexOf('Opera')!=-1) {isOpr=true;isDOM=false;isNN4=false;isIE4=false;isIE5up=false;isIE55up=false;}
if (navigator.userAgent.indexOf('Linux')!=-1) {isLinux=true;}
if (isOpr&&(navigator.userAgent.indexOf('Opera 0')==-1&&navigator.userAgent.indexOf('Opera 1')==-1&&navigator.userAgent.indexOf('Opera 2')==-1&&navigator.userAgent.indexOf('Opera 3')==-1&&navigator.userAgent.indexOf('Opera 4')==-1&&navigator.userAgent.indexOf('Opera 5')==-1&&navigator.userAgent.indexOf('Opera 6')==-1)){isOpr7up=true;}
if(isOpr&&(navigator.userAgent.indexOf('Opera/0')!=-1||navigator.userAgent.indexOf('Opera/1')!=-1||navigator.userAgent.indexOf('Opera/2')!=-1||navigator.userAgent.indexOf('Opera/3')!=-1||navigator.userAgent.indexOf('Opera/4')!=-1||navigator.userAgent.indexOf('Opera/5')!=-1||navigator.userAgent.indexOf('Opera/6')!=-1)){isOpr7up=false;}
if (navigator.userAgent.indexOf('Mac')!=-1){isMac=true;}
if (navigator.userAgent.indexOf('Gecko')!=-1){isGecko=true;}
if(navigator.userAgent.indexOf('Safari')!=-1){isSafari=true;isGecko=false;}
if(navigator.userAgent.indexOf('KHTML')!=-1||navigator.userAgent.indexOf('khtml')!=-1){isKhtml=true;isGecko=false;}
if (isGecko){GeckoVersion=navigator.userAgent.substring(navigator.userAgent.indexOf('rv:')+3,navigator.userAgent.indexOf('rv:')+6);}
var whichValueValue=eval(whichValue);
return(whichValueValue);
}

// Detect the browser
// Used in each and every page and by almost every function
var isDOM=b('isDOM');var isNN4=b('isNN4');var isIE4=b('isIE4');var isOpr=b('isOpr');var isLinux=b('isLinux');var isIE5up=b('isIE5up');var isIE55up=b('isIE55up');var isOpr7up=b('isOpr7up');var isMac=b('isMac');var isGecko=b('isGecko');var isIE6=b('isIE6');var GeckoVersion=b('GeckoVersion');var isSafari=b('isSafari');var isKhtml=b('isKhtml');
if(isIE5up&&!isIE55up){var undefined='undefined';} // define undefined on IE5.0

// Init the debug console
var cL_Debug=window.cL_Debug;
try{if(top.location.href.indexOf('clib_debug=1')!=-1||document.referrer.indexOf('clib_debug=1')!=-1){cL_Debug=true;}}catch(error){}
if(cL_Debug&&(!isIE5up&&!isSafari))
	{
	cL_Debug=false;
	window.cL_Debug=false;
	alert('clib Error:\n cL_Debug has been set to 1.\n However, the Debug console can only be used on Internet Explorer (Windows) or Safari (MacOS).');
	}
	
var invalidBrowser=false; // init
// set redir flag on unwanted browsers
if(!isIE5up&&!isIE55up&&!isOpr7up&&!isGecko&&!isSafari){invalidBrowser=true;}
if(cL_DenyOpera&&isOpr){invalidBrowser=true;}
if(cL_DenyGecko&&isGecko){invalidBrowser=true;}
if(cL_DenyGeckoBefore1&&Number(GeckoVersion)<1){invalidBrowser=true;}
if(cL_DenyIE&&(isIE4||isIE5up||isIE55up)){invalidBrowser=true;}
if(cL_DenyIE50&&(isIE5up||isIE55up)){invalidBrowser=true;}
if(cL_DenyIE55&&isIE55up){invalidBrowser=true;}
if(cL_DenyIEMac&&isMac&&(isIE4||isIE5up||isIE55up)){invalidBrowser=true;}
if(cL_DenySafari&&isSafari){invalidBrowser=true;}
// execute redirection
if(invalidBrowser&&location.href.indexOf(window.cL_DenyURL)==-1){location.replace(window.cL_DenyURL);}

// Debug window
if(cL_Debug&&(isIE55up||isSafari))
	{
	openDebugWindow();
	}

// Prepare the debug window
function openDebugWindow(){
debug_assignErrorConsole();
try {
	window.dW=window.open('','debug','width=640,height=320,toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
	window.dW.moveTo(0,0);
	var dwHTML='';
	dwHTML+='<html><head><title>clientLib Debug Window</title><style type=text/css>a{color:ButtonText;}td{font-family:smallfonts,arial narrow,arial,sans-serif;font-size:8pt;}input{background-color:InfoBackground;font-family:smallfonts,arial narrow,arial,sans-serif;font-size:8pt;height:16px;line-height:10px;}.var{color:ButtonShadow;}.val{color:ButtonText;}.valb{color:ButtonText;border:1px solid ButtonHighlight;}</style><script language=javascript src=clib/clib_core_debug.js></script></head><body topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0 border=0 marginheight=0 marginwidth=0 style="background-color:Menu;font-family:terminal,courier new,courier;font-size:6pt;color:ButtonText;">';

	dwHTML+='<p><table width=99% height=100% border=0 cellspacing=1 cellpadding=0 style="font-family:courier new,courier;font-size:8pt;color:ButtonText;">';

	dwHTML+='<tr><td colspan=2><span align=right>[<a href="javascript:debug_savePos();">Save Debug Window Size & Pos</a>]</span> [<a href="javascript:debug_showHiddenFrames();">Doc Iframes @ </a> <input type=text style=width:20px; id=ifrWidth value=200>x<input type=text style=width:20px; id=ifrHeight value=200>]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>Calling Document </nobr></td><td class=val valign=top>[<span id=document_href></span>]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>Calling Document URL Params</nobr></td><td class=val valign=top>[<span id=document_search></span>]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>File Sizes (rounded)</nobr></td><td class=val valign=top>[HTML:<span id=page_filesize></span>K] [Images:<span id=img_filesize></span>K] [clientLib:<span id=clib_filesize></span>K] <strong>[Total:<span id=all_filesize></span>K]</strong></td></tr>';
	
	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_core </nobr></td><td class=val valign=top>[Version:<span id=co_version></span>] [Filesize:<span id=co_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td></td><td valign=top>[Module Image Path:<span id=co_imgpath></span>] [Current CPU Speed:~<span id=co_cpuspeed></span>MHz]</td></tr>';
	
	dwHTML+='<tr><td></td><td valign=top>[Allowed Browsers:<span id=co_browsers></span>] [Denied Browsers Redir URL:<span id=co_denyurl></span>]</td></tr>';
	
	dwHTML+='<tr><td></td><td valign=top>[Global CSS:<span id=co_globalcss></span>] [IE CSS:<span id=co_iecss></span>] [Gecko CSS:<span id=co_geckocss></span>] [Opera 7 CSS:<span id=co_op7css></span>] [Gecko Mac CSS:<span id=co_geckomaccss></span>] [Safari CSS:<span id=co_safaricss></span>] [IE Mac CSS:<span id=co_iemaccss></span>] [Other CSS:<span id=co_othercss></span>]</td></tr>';
	
	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_edit </nobr></td><td class=valb valign=top>[Status:<span id=ed_status></span>] [Version:<span id=ed_version></span>] [Filesize:<span id=ed_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_form </nobr></td><td class=valb valign=top>[Status:<span id=fo_status></span>] [Version:<span id=fo_version></span>] [Filesize:<span id=fo_filesize></span>K]<br></td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_back </nobr></td><td class=valb valign=top>[Status:<span id=ba_status></span>] [Version:<span id=ba_version></span>] [Filesize:<span id=ba_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_keys </nobr></td><td class=valb valign=top>[Status:<span id=ke_status></span>] [Version:<span id=ke_version></span>] [Filesize:<span id=ke_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_time </nobr></td><td class=valb valign=top>[Status:<span id=ti_status></span>] [Version:<span id=ti_version></span>] [Filesize:<span id=ti_filesize></span>K]<br>[Timer:<span id=ti_time></span>] [Timeout Redir URL:<span id=ti_timeouturl></span>]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_bbar </nobr></td><td class=valb valign=top>[Status:<span id=bb_status></span>] [Version:<span id=bb_version></span>] [Filesize:<span id=bb_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_date </nobr></td><td class=valb valign=top>[Status:<span id=da_status></span>] [Version:<span id=da_version></span>] [Filesize:<span id=da_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_http </nobr></td><td class=valb valign=top>[Status:<span id=ht_status></span>] [Version:<span id=ht_version></span>] [Filesize:<span id=ht_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_stre </nobr></td><td class=valb valign=top>[Status:<span id=st_status></span>] [Version:<span id=st_version></span>] [Filesize:<span id=st_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td align=right valign=top class=var><nobr>clib_loff </nobr></td><td class=valb valign=top>[Status:<span id=lo_status></span>] [Version:<span id=lo_version></span>] [Filesize:<span id=lo_filesize></span>K]</td></tr>';

	dwHTML+='<tr><td colspan=2 valign=bottom><nobr>Error and Messages Log Console: [<a href=# onclick="document.getElementById(\'error_console\').innerHTML=\'\';">Clear</a>] [<a href=# onclick="document.getElementById(\'error_console\').innerHTML+=\'<strong>clib Message:</strong> Javascript error console is stopped<br>\';opener.debug_clearErrorConsole();debug_flashErrorConsole();">Deactivate JS Errors</a>] [<a href=# onclick="document.getElementById(\'error_console\').innerHTML+=\'<strong>clib Message:</strong> Javascript error console is active<br>\';opener.debug_assignErrorConsole();debug_flashErrorConsole();">Activate JS Errors</a>] [<a href=# onclick="opener.eval(document.getElementById(\'evalField\').value);">Evaluate in Doc:</a><input style="font-family:courier new,courier;" type=text size=15 id=evalField onkeypress=debug_fitEvalfieldSize(); onblur=debug_fitEvalfieldSize();>]<br><span id=error_console style="background-color:InfoBackground;color:InfoText;border:1px solid InactiveCaption;width:100%;"><strong>clib Message:</strong> Javascript error console is active<br></span></nobr></td></tr>';

	dwHTML+='</table></p>';
	
	dwHTML+='</body></html>';
	
	window.dW.document.body.innerHTML='';
	window.dW.document.write(dwHTML);

	window.dW.debugDisplayUpdate();
	
	} catch (error) {
	window.setTimeout("openDebugWindow();",500);
	} 
}

if(window.cL_IncludeStylesheets)
	{
	// output the inclusion link for the correct css file
	var cssIncCode="<link rel=\"stylesheet\" type=\"text/css\" href=\"";
	document.write(cssIncCode+cL_CssFileName+"\">")
	if (isIE4||isIE5up) document.write(cssIncCode+cL_IECssFileName+"\">\n"); 
	else if (isGecko) document.write(cssIncCode+cL_GeckoCssFileName+"\">\n");
	else if (isOpr) document.write(cssIncCode+cL_OperaCssFileName+"\">\n");
	else document.write(cssIncCode+cL_OtherCssFileName+"\">\n");
	}
	
// generate a class named 'clib_link' mainly for clib-internal usage (pointer cursor)
var linkProp='';
if(isIE4||isIE5up){linkProp='hand';}else{linkProp='pointer';}
document.write('<style type="text/css">.clib_link{cursor:'+linkProp+';}</style>\n');

// Modules inclusion; to be expanded for inclusion of new modules
var modIncCode='';
var modIncCodeStart='<script language="javascript" src="clib/clib_';
var modIncCodeEnd='.js"></script>';
if(window.cL_ModulesToLoad.indexOf('fo')!=-1||window.cL_GlobalModulesToLoad.indexOf('fo')!=-1)
	{
	modIncCode+=modIncCodeStart+'form'+modIncCodeEnd;
	modIncCode+=modIncCodeStart+'form_textelements_'+window.cL_language+modIncCodeEnd;
	}
if(window.cL_ModulesToLoad.indexOf('ed')!=-1||window.cL_GlobalModulesToLoad.indexOf('ed')!=-1){modIncCode+=modIncCodeStart+'edit'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('ba')!=-1||window.cL_GlobalModulesToLoad.indexOf('ba')!=-1){modIncCode+=modIncCodeStart+'back'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('ke')!=-1||window.cL_GlobalModulesToLoad.indexOf('ke')!=-1){modIncCode+=modIncCodeStart+'keys'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('ti')!=-1||window.cL_GlobalModulesToLoad.indexOf('ti')!=-1){modIncCode+=modIncCodeStart+'time'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('bb')!=-1||window.cL_GlobalModulesToLoad.indexOf('bb')!=-1){modIncCode+=modIncCodeStart+'bbar'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('da')!=-1||window.cL_GlobalModulesToLoad.indexOf('da')!=-1){modIncCode+=modIncCodeStart+'date'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('ht')!=-1||window.cL_GlobalModulesToLoad.indexOf('ht')!=-1){modIncCode+=modIncCodeStart+'http'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('st')!=-1||window.cL_GlobalModulesToLoad.indexOf('st')!=-1){modIncCode+=modIncCodeStart+'stre'+modIncCodeEnd;}
if(window.cL_ModulesToLoad.indexOf('lo')!=-1||window.cL_GlobalModulesToLoad.indexOf('lo')!=-1){modIncCode+=modIncCodeStart+'loff'+modIncCodeEnd;}
document.write(modIncCode);

// Create an OPTION element
// selectId = id of the SELECT element where the OPTION element is to be attached to
// value = value for the element
// text = text for the element
// selected = when true, this option will be created with selected=true
function createOption(selectId,value,text,selected,classname){
var newOption=document.createElement("option");
var thisSelect=document.getElementById(selectId);
// append the child before setting the attributes in order to have Opera 7 taking the attributes
thisSelect.appendChild(newOption);
// don't make usage of element.setAttribute since this doesn't yet work everywhere
newOption.value=value;
if(!isOpr)
	{
	newOption.text=text;
	}else{
	var newText=document.createTextNode(text);
	newOption.appendChild(newText);
	}
if(classname!=''&&classname!=undefined){newOption.className=classname;}
// select this new option if it is to be selected
if(selected)
	{
	if(isIE5up)
		{
		// ie can set the selected attribute here
		newOption.selected=true;
		} else {
		// for opera 7, selectedIndex must be set for this to work; moz could make use of both methods
		thisSelect.selectedIndex=thisSelect.length-1;
		}
	}
}

// Delete all OPTION alements
// selectId = id of the SELECT element where all OPTION elements are to be deleted from
function deleteOptions(selectId){
var selectElement=document.getElementById(selectId);
while(selectElement.hasChildNodes())
	{
	selectElement.removeChild(selectElement.firstChild);
	}
}
					  
// Transfer a SELECT element's selectedIndex and its value into window variables
// id = id of the SELECT element
// Will define and fill the window variables 'window.[id]_value' and 'window.[id]_selectedIndex'
// Necessary to enable storing of selections also on Opera who can't make use of select elements' selectedIndex when their display=none
function selInd2WinVar(id){
var evalStrVal="window."+id+"_value='"+document.getElementById(id).options[document.getElementById(id).selectedIndex].value+"'";
var evalStrInd="window."+id+"_selectedIndex='"+document.getElementById(id).selectedIndex+"'";
eval(evalStrVal);
eval(evalStrInd);
}

// Scrolls to the top of the document after a defined delay time
// Used when page loads containing anchor jumps must be overridden
// delayTime = delay time value in milliseconds
function jumpToTop(delayTime,DOMPath,executeNow){
if(!executeNow||!executeNow) // see if delay time has been passed; if not, call the delayer
	{
	window.setTimeout("jumpTopToTop(0,'"+DOMPath+"',true);",delayTime);
	} else { // but if, jump to top
	eval(DOMPath).scrollTo(0,0);
	}
}

// Set a cookie
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// Get a cookie  
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// Measures the approximate CPU speed, writes it into a one-session cookie and returns the app. speed value in MHz
// The value is used within CPU time intensive functions to determine whether to use the time-consuming code version or a slim version of it
// Speed is measured three times per session and the average value is then set as global document variable 'CPUSpeed' and as domain-wide cookie 'CPUSpeed'; measurement precision is around +-150MHz for IE5, IE5.5, IE6 and Gecko; no measuring possible on Opera
function getCPUSpeed(){
var CPUSpeedMeasureCount=getCookie('CPUSpeedMeasureCount');
if(CPUSpeedMeasureCount!=3)
	{
	var CPUSpeed=getCookie('CPUSpeed'); // set local value
	var count=1000000;
	var date1=new Date();
	var start=date1.getTime();
	for (var i=1;i<=count;i++) {} // the measurement loop
	date1=new Date();
	var finish=date1.getTime();
	top.CPUSpeedSeconds=(finish-start)/1000;
	top.CPUSpeedLoopsPerMs=Math.round(count/top.CPUSpeedSeconds/1000);
	top.CPUSpeed=Math.round(top.CPUSpeedLoopsPerMs*0.341);
	if(CPUSpeedMeasureCount==2) // third run
		{
		top.CPUSpeed=Math.floor((Number(CPUSpeed)+Number(top.CPUSpeed))/2);
		CPUSpeedMeasureCount=3;
		}
	if(CPUSpeedMeasureCount==1) // second run
		{
		top.CPUSpeed=Math.floor((Number(CPUSpeed)+Number(top.CPUSpeed))/2);
		CPUSpeedMeasureCount=2;
		}
	if(!CPUSpeedMeasureCount||CPUSpeedMeasureCount=='') // first run
		{
		top.CPUSpeed=Math.floor((Number(CPUSpeed)+Number(top.CPUSpeed))/2);
		CPUSpeedMeasureCount=1;
		}
	setCookie('CPUSpeed',top.CPUSpeed,'','/');
	setCookie('CPUSpeedMeasureCount',CPUSpeedMeasureCount,'','/');
	} else {
	CPUSpeed=getCookie('CPUSpeed');
	}
top.CPUSpeed=CPUSpeed;
if(isMac&&CPUSpeedMeasureCount==3){top.CPUSpeed=top.CPUSpeed*2;} // Multipy measurement result by 2 @ PPC
//setCookie('CPUSpeedMeasureCount','','','/'); // delete counter for debugging
return top.CPUSpeed;
}
window.cL_CPUSpeed=getCPUSpeed();

// Debug routine private function: assign the error console to the window's error handler
function debug_assignErrorConsole(){
try
	{
	window.onerror=debug_callWriteToErrorConsole;
	} catch (error) {
	window.setTimeout("debug_assignErrorConsole();",15);
	}
}

// Debug routine private function: clear the error console (can't be called from the console window!)
function debug_clearErrorConsole(){
window.onerror='';
}

// Debug routine private function: call the error output in the console window
function debug_callWriteToErrorConsole(error_message,error_url,error_line){
dW.debug_writeToErrorConsole(error_message,error_url,error_line);
return true;
}