// JavaScript Document
// class TtipData
// code by Azer Manafov (azerman[at]hotmail[dot]com)

// cursor position trailing
var GLB_CURSOR            =  {x:-1, y:-1};
var HELPER_EVENT_HANDLERS = new Array( );
var FN_WINDOW_ONLOAD      = cursorposinit;

var HTM_RET = (HTM_RET == undefined)?0:HTM_RET;
var HTM_WRT = (HTM_WRT == undefined)?1:HTM_WRT;
var HTM_INS = (HTM_INS == undefined)?2:HTM_INS;
var HTM_CRT = (HTM_CRT == undefined)?3:HTM_CRT;

var WIN_ONLOAD_CALLED  = false;
var BODY_ONLOAD_CALLED = false;

window.onload = cursorposinit;
function cursorposinit      ()
{	//alert('cursorposinit');
	if ( WIN_ONLOAD_CALLED ) return;
    WIN_ONLOAD_CALLED    = true;
	
	if ( document.addEventListener )
	{
		document.addEventListener('mousemove',mouseEventHandler,false);
		document.addEventListener('mousedown',mouseEventHandler,false);
		document.addEventListener('mouseup',  mouseEventHandler,false);
		document.addEventListener('mouseover',mouseEventHandler,false);
		document.addEventListener('mouseout', mouseEventHandler,false);
		document.addEventListener('click',    mouseEventHandler,false);

	}
	else
	{
		
        if ( document.captureEvents )
	    {   document.captureEvents(Event.MOUSEMOVE |  Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK );
	    }
	    document.onmousemove = mouseEventHandler;
	    document.onmousedown = mouseEventHandler;
	    document.onmouseup   = mouseEventHandler;
	    document.onmouseover = mouseEventHandler;
	    document.onmouseout  = mouseEventHandler;
	    document.onclick     = mouseEventHandler;
	}

	
    FN_WINDOW_ONLOAD     = null;//prevent from repeated call
    if ( BODY_ONLOAD_CALLED == false )
    	loadComplete( );

}
//called at body.onload
function loadComplete       ( )
{   //alert('loadComplete');
	if ( BODY_ONLOAD_CALLED ) return;
    BODY_ONLOAD_CALLED = true;
	var callfirst = new Array( );
    var callafter = new Array( );
    for ( var  i = 0; i < layout.count(); i++ )
    {   if ( layout.callAfter(i)) 
		     callafter[callafter.length] = i;
		else callfirst[callfirst.length] = i;	 
	}
    for ( var  i = 0; i < callfirst.length; i++ )
    {   //alert( "F: "+layout.name(callfirst[i]));
		layout.call(callfirst[i]);
    }
    for ( var  i = 0; i < callafter.length; i++ )
    {   //alert( "A: "+layout.name(callafter[i]));
		layout.call(callafter[i]);
    }
}

function mouseEventHandler  (e)
{
	e = e || window.event;
	for( var hlp in HELPER_EVENT_HANDLERS )
	{   if ( HELPER_EVENT_HANDLERS[hlp].onMouseEvent ) 
		     GLB_CURSOR = HELPER_EVENT_HANDLERS[hlp].onMouseEvent(e);
		else HELPER_EVENT_HANDLERS[hlp](e);
	}
}
// end cursor position trailing

//start clsCallbackList -  callback stack class
function clsCallbackList    ( )
{
    var m_arCallbackFun = new Array( );

	this.addCallback    = function( fun, bAfter,name )
	{   var bAfter = (bAfter != undefined )?bAfter:false;
	    var name   = (name   != undefined )?name:getFunctionName(fun);
        for ( var i = 0; i < m_arCallbackFun.length; i++ )
		{   if ( m_arCallbackFun[i].callback == fun ) return;
		}
		var ob = new Object( );
		ob.callback = fun;
		ob.name     = name;
		ob.after    = bAfter;
		m_arCallbackFun.push( ob );
	}
	this.remCallback = function ( fun )
	{   for ( var i = 0; i < m_arCallbackFun.length; i++ )
		{   if ( m_arCallbackFun[i].callback == fun )
			{   m_arCallbackFun.splice( i,1);
				return;
			}
		}
	}
	this.call       = function( index )
	{   if ( typeof index == 'string' )
		{   for ( var i = 0; i < m_arCallbackFun.length; i++ )
			{   if ( m_arCallbackFun[i].name == index )
				     return m_arCallbackFun[i].callback();
			}
			return;
		}
	    if ( index > -1 && index < m_arCallbackFun.length )
		     return m_arCallbackFun[index].callback();
	}
	this.count      = function( ) { return m_arCallbackFun.length; }
	this.name       = function( index )
	{   if ( typeof index == 'string' )
		{   for ( var i = 0; i < m_arCallbackFun.length; i++ )
			{   if ( m_arCallbackFun[i].name == index )
				     return i;//return index
			}
			return -1;
		}
	    if ( index > -1 && index < m_arCallbackFun.length )
		     return m_arCallbackFun[index].name;
	}
	this.callAfter  = function( index )
	{   if ( index > -1 && index < m_arCallbackFun.length )
		     return m_arCallbackFun[index].after;
	}
};// end clsCallbackList
/*
* visihlp      - clsViewHelper object
* common_param - common param for all events(  { x:a, y:b} )
*/
function clsMouseEventsHandle( visihlp,common_param )
{
	var m_arEvt     = new Array( );
	var m_visihlp   = (visihlp == 'undefined')?new clsViewHelper():visihlp;
	var m_param     = (common_param == undefined )?null:common_param;

	m_visihlp.registerHelper( handleMouseEvent );
/*
* ev_name     - mousedown, mouseup, mouseover, mouseout, mousemove, click, dblclick
* eventid     - altername of event
* ev_callback - event handler function
* ev_ident    - id of container that evens while handled
* ev_param    - user defined parameters as { X:Y } values
*/
	this.evobject   = function( ev_name, eventid, ev_callback, ev_ident, ev_param )
	{
		this.name     = ev_name;
		this.eventid     = eventid;
		this.callback = ev_callback;
		this.ident    = ev_ident;
		this.param    = ev_param;
	}
	this.addEventA  = function( evp )
	{   for ( var i = 0; i < m_arEvt.length; i++ )
			if ( m_arEvt[i].name == evp.name ) return;
		var ev = new Object( );
		ev = evp;
	    m_arEvt.push( ev );
	}
	this.addEvent   = function( ev_name, eventid, ev_callback, e_ident, ev_param )
	{   var ev  = new this.evobject( ev_name, eventid, ev_callback, e_ident, ev_param );
		this.addEventA( ev );
	}
    this.btnState   = function ( e )
	{   var state = 0;
		if ( e.button )
		{   if ( browser.isIE )
		    {   switch( e.button )
				{   case 1: state = 1; break;//left
					case 2: state = 2; break;//right
					case 4: state = 3; break;//middle
				}
			}
			else
			{   switch( e.button )//Firefox
				{   case 0: state = 1; break;//left
					case 2: state = 2; break;//right
					case 1: state = 3; break;//middle
				}
			}
		}
		else
			if ( e.which )
			{   switch( e.which )
				{   case 1: state = 1; break;//left
					case 3: state = 2; break;//right
					case 2: state = 3; break;//middle
				}
			}
		return state;	
	}
    function is_ident( objchk, ident )
	{   var objret = null;
	    if ( ident == undefined || ident == "" ) return null;
		var objtmp = objchk;
		while( objtmp )
		{   if ( objtmp.id && objtmp.id.indexOf( ident ) != -1)
			{   objret = objtmp;
				break;
			}
			objtmp = objtmp.parentNode;
		}
		return objret;
	}
	function handleMouseEvent( e )
	{
        e = e || window.event;
		if ( !e ) return null;

		for ( var i = 0; i < m_arEvt.length; i++ )
		{   if ( e.type == m_arEvt[i].name )
			{    var prop    = new Object( );
			     prop.eventid   = m_arEvt[i].eventid;
			     prop.param  = m_arEvt[i].param;
				 prop.cparam = m_param;
			     prop.target = m_visihlp.getEventTarget( e );
				 prop.obj    = (prop.target)?is_ident( prop.target,m_arEvt[i].ident ):null;
				 prop.e      = e;
				 prop.bubble  = true; 
				 m_arEvt[i].callback( prop );//user callback
		 
				 if ( !prop.bubble )
				 {
					 stopropagation(e);
				 }
			     return prop;
			}
		}
	    return null;
	}
	function stopropagation ( e )
	{   if (!e) var e = window.event;
	    e.cancelBubble = true;
	    if ( e.stopPropagation) e.stopPropagation();
	}

};

function clsTtipData( id, iconWidth, iconHeight, imgW, imgH, iconOn, iconOff, tipImage )
{
	var m_id		   = id;
	var m_icon         = id+'3';
	var m_image        = id+'2';
	var m_movie	       = null;
	
	var m_iconOn       = iconOn;
	var m_iconOff      = iconOff;
	var m_tipImage     = tipImage;
	var m_link         = "#";
	var m_alttxt       = '';
	var m_bblend       = false;//true;
	var m_connectid    = "";

	var m_iconPos      = new function () { this.x = 0; this.y = 0; this.width = 0; this.height = 0; }
	m_iconPos.width    = iconWidth;
	m_iconPos.height   = iconHeight;
	var m_imafePos     = new function () { this.x = 0; this.y = 0; this.width = 0; this.height = 0; }
	m_imafePos.x       = -iconWidth/2;
	m_imafePos.y       = -iconHeight/2;
	m_imafePos.width   = imgW;
	m_imafePos.height  = imgH;

	var m_imgState     = 0;
	var m_img          = new Image( );
	
	this.isActive      = true;
	this.setconnectid  = function( connectid ) { m_connectid = connectid; }
	this.getconnectid  = function( ) { return m_connectid; }
	
	this.getId         = getId;
	this.getIconOn     = getIconOn;
	this.getIconOff    = getIconOff;
	this.getImgTtip	   = getImgTtip;

	this.getLink	   = getLink;
	this.setLink	   = setLink;
	this.getAlttxt	   = getAlttxt;
	this.setAlttxt	   = setAlttxt;
	this.setMovie      = setMovie;
	this.getMovie      = getMovie;
	this.setIconPos    = setIconPos;
	this.setImagePos   = setImagePos;
	this.enableBlend   = enableBlend;
	this.canBlend      = canBlend;
	this.correctTtipPos= correctTtipPos;

	this.isImgComplete = isImgComplete;
	this.isEqual       = isEqual;
	this.showThis      = showThis;
	this.showIcon      = showIcon;
	this.showImage     = showImage;
	this.showMovie     = showMovie;
	this.iconBlend     = iconBlend;
	this.iconSet       = iconSet;
	this.getIconRect   = getIconRect;
	this.getImageRect  = getImageRect;


	if ( clsTtipData.HELPER  ==  undefined || !clsTtipData.HELPER )
	     clsTtipData.HELPER = new clsViewHelper( );
	if ( clsTtipData.IMGS_PATH  ==  undefined || !clsTtipData.IMGS_PATH )
	     clsTtipData.IMGS_PATH   =  "images/sys";
	if ( clsTtipData.VIEW_RIGHT	==  undefined || !clsTtipData.VIEW_RIGHT )
		 clsTtipData.VIEW_RIGHT  = 800;
	if ( clsTtipData.VIEW_BOTTOM == undefined || !clsTtipData.VIEW_BOTTOM )
		 clsTtipData.VIEW_BOTTOM = 600;
	if ( clsTtipData.REF_LT_OBJ  == undefined || !clsTtipData.REF_LT_OBJ )
	     clsTtipData.REF_LT_OBJ = "mapRefPoint";

	m_img.onload  = onImgload;
	m_img.onabort = onImgAbort;
	m_img.onerror = onImgError;
	m_img.src     = getImgTtip( );

	function onImgload     ( ) { onComplete(1); }
	function onImgError    ( ) { onComplete(2); }
	function onImgAbort    ( ) { onComplete(2); }
	function onComplete    ( state ) 
	{   m_imgState = state; 
		if ( m_imgState == 1)
		{	if ( m_imafePos.width  == 0 ) m_imafePos.width  = m_img.width;
			if ( m_imafePos.height == 0 ) m_imafePos.height = m_img.height;
		}
	}
	
	function isImgComplete ( ) { return (m_imgState)?true:false; }
    function correctTtipPos( )
	{	var helper = clsTtipData.HELPER;
		var thisObj= helper.getElement( m_id );
		if ( !thisObj ) return;
		var thisPos= [parseInt(thisObj.style.left), parseInt(thisObj.style.top)];

		if ( thisPos[0] + m_imafePos.width > clsTtipData.VIEW_RIGHT )
		     m_imafePos.x = -(thisPos[0] + m_imafePos.width - clsTtipData.VIEW_RIGHT );
		if ( thisPos[1] + m_imafePos.height > clsTtipData.VIEW_BOTTOM )
		     m_imafePos.y = -(thisPos[1] +  m_imafePos.height - clsTtipData.VIEW_BOTTOM );
	}

	function getId 		( )	{ return m_id; }
	function getIconOn 	( )	{ return clsTtipData.IMGS_PATH + '/' + m_iconOn; }
	function getIconOff	( ) { return clsTtipData.IMGS_PATH + '/' + m_iconOff; }
	function getImgTtip	( ) { return clsTtipData.IMGS_PATH + '/' + m_tipImage; }
	
	function getIconRect( )	{ return m_iconPos;	}
	function getImageRect( )
	{   if ( m_imafePos.width  == 0 ) m_imafePos.width  = m_img.width; 
	    if ( m_imafePos.height == 0 ) m_imafePos.height = m_img.height; 
		return m_imafePos;	
	}
	function getLink	( ) { return m_link; }
	function setLink	( linktxt ) { m_link = linktxt; }
	function getAlttxt	( ) { return m_alttxt; }
	function setAlttxt	( alttxt ) { m_alttxt = alttxt; }
	function setMovie	( obj ) { m_movie = obj;}
	function getMovie	( ) { return m_movie;}
	
	function enableBlend( blend ) { m_bblend = blend; }
	function canBlend	( ) { return m_bblend; }
	
	function setIconPos	( x,y ) { m_iconPos.x = x; m_iconPos.y = y; }
	function setImagePos( x,y )
	{   if ( x != undefined ) m_imafePos.x = x; 
		if ( y != undefined ) m_imafePos.y = y; 
		clsTtipData.HELPER.setDivPos( m_image,{ x : m_imafePos.x, y : m_imafePos.y} );
	}
	
	function isEqual    ( behav ) { return (m_id == behav.getId());}
	function showThis   ( show ) { clsTtipData.HELPER.setVisible( m_id,    show);}
	function showIcon   ( show ) { clsTtipData.HELPER.setVisible( m_icon,  show);} 
	function showImage  ( show ) { clsTtipData.HELPER.setVisible( m_image, show);}
	function showMovie  ( show ) { clsTtipData.HELPER.setVisible( m_movie, show);}
	function iconBlend  ( val  ) { clsTtipData.HELPER.setOpacity( m_icon,  val);}
	function iconSet    ( onoff)
	{   if ( onoff == 'off' )
		     clsTtipData.HELPER.swapImages(m_icon,getIconOff());
		else clsTtipData.HELPER.swapImages(m_icon,getIconOn());
	}

};// end class clsTtipData

function clsFlashLayer( id, f_name, width, height,flashvars, params,attributes)
{

	var m_id         = id;//'movie'+id;
	var m_style      = new Object();
	var m_movie      = f_name;
	var m_width      = width;
	var m_height     = height;
	var m_sflashvars = '';
	var m_params     = 	{"movie":m_movie, "quality": "high", "loop":"true","wmode":"transparent"};

	if ( flashvars )
	{   for ( var  i in flashvars )
             m_sflashvars += (i + '=' + flashvars[i] + '&');
		if ( m_sflashvars != '' )
             m_sflashvars = m_sflashvars.substring(0,m_sflashvars.lastIndexOf('&'));
	}
	if ( params )
	{   for ( var i in params )
             m_params[i] = params[i];
	}
	if ( attributes )
	{   for ( var i in attributes)
             m_style[i] = attributes[i];
	}

	
	this.createFlashLayer	= createFlashLayer;
	this.getId				= getId;

	this.setStyle			= setStyle;
	this.resStyle			= resStyle;
	

	function getId    		 ( ) { return m_id; }
	function createFlashLayer( plaseholder, inc_type )
	{	if ( inc_type == undefined )
	         inc_type = HTM_WRT;

	    var s = getFlashContent( m_width, m_height, m_movie, m_sflashvars,m_params);
	    switch( inc_type )
		{
            case HTM_RET: return  s; 
            case HTM_WRT: document.write(s); break;
            case HTM_INS:
			var o = getElement(plaseholder);
			if ( !o ) return;
		
			o.parentNode.innerHTML = s;
			break;
			default: return s;
		}
		setStyle( );
		return s;
	}
	function resStyle( ) { m_style = new Object( ); }
	function setStyle( )
	{	var obj = getElement( m_id );
		if ( !obj ) return;
		
		for ( var i in m_style)
		      setStyleA( obj, i,m_style[i]);
	}
	function setOpacity(elm,val)
	{   elm.style.zoom     = 1;
        elm.style.filter   = "alpha(opacity=" + parseFloat(val*100) + ")";
        elm.style.opacity  = parseFloat(val); 
        return elm;
    }
	function camelize ( val )
	{
        return val.replace(/-(.)/g, function(m, l) { return l.toUpperCase()});
    }
	
	function setStyleA( elm,prop,val)
	{
        if ( prop == 'opacity') return setOpacity( elm,parseFloat(val));
        if ( prop == 'float'  ) prop = (window.attachEvent) ? 'styleFloat' : 'cssFloat';
        prop = camelize( prop );
        unit = (prop=='zIndex'||prop=='zoom' ) ? '':'px';
        elm.style[prop] = (typeof val=='string') ? val : val+unit;
        return elm;
    }
	
	function getFlashContent( width, height, movie, flashvars,params)
	{	
		var str='';	
		
		str+=' <OBJECT id="' + m_id + '" name="' + m_id + '" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"';
//		str+=' <OBJECT id="' + m_id + '" name="' + m_id + '" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		str+=' width="'+width+'" height="'+height+'">';
		for ( var i in params )
			str += '<param name="' + i + '" value="' + params[i] + '" />' + "\n";
		if ( flashvars )
		     str+=' <param name="flashvars" value="'+flashvars+'" /> \n';
		
		var str2='<embed pluginpage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high"';
	
		str2+=' width="'+width+'" height="'+height+'"';
		str2+=' src="'+movie+'"';
		str2+=' wmode="transparent"';
		str2+=' flashvars="'+flashvars+'"';
		str2+=' > </embed>' + "\n";
		
		str+=str2;
		str+='</OBJECT> ' + "\n";

		return str;
	}
	function getElement( id )
	{	if ( document.getElementById )
	         return document.getElementById( id );
		if ( document.all!=null )
      		 return document.all   [id];
    	else return document.layers[id];
	}
};
// class clsViewHelper
function clsViewHelper()
{
	var tipBkgColor         = "#f6e9cf";

	this.appendStyle        = appendStyle;
	this.disableSelection   = disableSelection;
	this.clone              = clone;
	this.createDivLayer     = createDivLayer;
	this.findPos			= findPos;
	this.getbaseurl         = function( site )
	{   var url = self.location.href;
//	    url = url.toLowerCase();
	    var u1 = url.lastIndexOf( "http://" );
		var u2 = -1;
	    if ( u1 < 0 ) u1 = 0;
		url = url.substring(u1);
		u1  = 0;
		if ( site != undefined )
		{   var p = url.lastIndexOf( site );
			if ( p >= 0 )
				u2 = url.indexOf( "/",p)
		}
		if ( u2 < 0 )
		{   u2 = url.lastIndexOf( "/");
			if ( u2 < 0 ) u2 = url.length-1;
		}
	    var base = url.substring(u1,u2+1 );
	    return base;
	}
	this.currpagename = function( )
	{   var url  = self.location.href;
		var p1   = url.lastIndexOf('/')+1;
		var p2   = url.indexOf('.',p1);
		var p3   = url.indexOf('?',p2);
		p2 = ( p3 < 0 )?url.length:p3;
		var page = url.substring( p1,p2);
		return page;
	}
	this.getElement			= getElement;
	this.getEventTarget     = getEventTarget;
    this.getCursorPos       = function( ) { return m_cursor_pos; }
	
	this.getInnerText       = getInnerText;
	this.getInstanceId      = function getInstanceId( ) { return "helper"+m_instanceid; }
	
	this.getmaxdim          = getmaxdim;
	this.getObjectRect      = getObjectRect;
	this.getStyle           = getStyle;
	this.goToUrl            = goToUrl;

	this.ltrim				= ltrim;
	this.onMouseEvent		= onMouseEvent;
	this.pointInObject		= pointInObject;
	this.registerHelper     = registerHelper;
	this.removeHelper       = removeHelper;
	this.rtrim				= rtrim;

	this.selectInpGetPos    = selectInpGetPos;
	this.selectInputText    = selectInputText;
    this.setAttributes      = setAttributes;
	this.setDivPos			= setDivPos;
	this.setOpacity 		= setOpacity;
	this.setStyleA          = setStyleA;
	this.setStyles          = setStyles;
	this.setVisible 		= setVisible;
	this.showTtip   		= showTtip;
	this.swapImages 		= swapImages;

	this.trim				= trim;
	

	var bAllSupport         = document.all!=null;
	var m_cursor_pos		= { x:-1, y:-1 };
	var m_instanceid        = 0;
	
	if ( clsViewHelper.INSTANCE == undefined )
	     clsViewHelper.INSTANCE = 0;
	else clsViewHelper.INSTANCE++;
	clsViewHelper.TTIP_DIV_ID = 'tipView';
	clsViewHelper.TTIP_ZINDEX = 40;
	
	m_instanceid = clsViewHelper.INSTANCE;
	
	registerHelper( this );

    function appendStyle    ( styleSheet )
    {   if ( !styleSheet || !styleSheet.length) return;
        var head  = document.getElementsByTagName("head")[0];
	    var style = document.createElement('style');
	    style.setAttribute("type", "text/css");
	    if ( style.styleSheet)
	    { style.styleSheet.cssText = styleSheet;
	    }
	    else
	    {  var cssText = document.createTextNode(styleSheet);
	       style.appendChild(cssText);
	    }
	    head.appendChild(style);
    }
	function camelize       ( val )
	{
        return val.replace(/-(.)/g, function(m, l) { return l.toUpperCase()});
    }
//http://keithdevens.com/weblog/archive/2007/Jun/07/javascript.clone
	function clone          ( obj )
	{   if(obj == null || typeof(obj) != 'object')
	        return obj;

	    var temp = new obj.constructor(); // changed (twice)
	    for( var key in obj)
	         temp[key] = clone(obj[key]);
	    return temp;
		
	}
	function createDivLayer ( parent, idName, divstyles, before ) //divstyles object contains <style>:<value>
    {   if ( !document.createElement ) return null;
		var ttipNode = document.createElement("div");
		ttipNode.setAttribute("id", idName );
		if ( divstyles != undefined )
		     setStyles( ttipNode, divstyles );
		parent = getElement( parent );
		if ( before != undefined )
		{    before = getElement( before );
		     parent.insertBefore( ttipNode, before );
		}
		else parent.appendChild( ttipNode );
        return ttipNode;
    }
	function dcdSpaces( src )
	{	var i;
		while( ( i = src.indexOf( "&nbsp;")) != -1 )
		{   src = src.substring( 0, i ) + ' ' + src.substring( i+6 );
		}
		return src;
	}
//http://www.dynamicdrive.com/dynamicindex9/noselect.htm	
    function disableSelection( target )
    {
        if ( typeof target.onselectstart!="undefined" ) //IE route
             target.onselectstart=function(){return false}
        else if (typeof target.style.MozUserSelect!="undefined" ) //Firefox route
             target.style.MozUserSelect="none";
        else //All other route (ie: Opera)
             target.onmousedown=function(){return false}
    }
// http://blog.firetree.net/2005/07/04/javascript-find-position/	
// from http://www.quirksmode.org/js/findpos.html#
	function findPos        ( id )
	{  	var pos  = { x : -1, y : -1 };
		var obj  = getElement( id );
	  	if ( obj == undefined || obj == null ) return pos; 
        pos.x = pos.y = 0;
        var r = obj;
		while (r)
		{   pos.x += r.offsetLeft || 0;
			pos.y += r.offsetTop  || 0;
			r  = r.offsetParent;
		}
		r = obj;
		while (r) 
		{   pos.x -= r.scrollLeft || 0;
			pos.y -= r.scrollTop  || 0;
			r  = r.parentNode;
			if ( r == document.body)
				 break;
		}
		return pos;
	}
	function getElement     ( id )
	{	if ( typeof id == 'object') return id;
	    if ( document.getElementById )
	         return document.getElementById( id );
		if ( bAllSupport )
      		 return document.all   [id];
    	else return document.layers[id];
	}
	function getEventTarget ( e )
	{   e = (e) ? e : ((window.event) ? window.event : "");
		if ( !e ) return null;
		var obj = (e.target)?e.target:e.srcElement;
		if ( obj )
		{   if ( obj.nodeType == 3)
			     obj = obj.parentNode;
		}
		return obj;
	}
	function getInnerText   ( id )
	{   var obj     = getElement( id );
		if ( !obj ) return "";
	    var s = obj.innerText;
		if ( s == undefined)
		{    s = obj.innerHTML.replace(/<[^>]+>/g,"");
	    }
	    return s;
    }
	function getmaxdim      ( ) 
	{   var w = 0, h = 0;
		if( typeof( window.innerWidth ) == 'number' )
		{   //Non-IE
		    w = window.innerWidth;
		    h = window.innerHeight;
		}
		else 
		    if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
			{   //IE 6+ in 'standards compliant mode'
                w = document.documentElement.clientWidth;
		        h = document.documentElement.clientHeight;
		    }
		else 
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{   //IE 4 compatible
		        w = document.body.clientWidth;
		        h = document.body.clientHeight;
		    }
		return {'left':0, 'top':0, 'width':w, 'height':h};
	}	
	function getObjectRect  ( id )
	{   var rc  = { left :  -1, top: 0, width : 0, height : 0 };
		var obj = getElement( id );
	  	if ( obj == undefined || obj == null )
		     return rc;
		var coord = findPos( obj );
		rc.left   = coord.x;
		rc.top    = coord.y;

        if ( browser.isIcab || browser.isMac )
		{   rc.width  = obj.offsetWidth;
		    rc.height = obj.offsetHeight;
			return rc;
		}
		rc.width  = (obj.clientWidth == 0 )?obj.offsetWidth:obj.clientWidth;
		rc.height = (obj.clientHeight== 0 )?obj.offsetHeight:obj.clientHeight;
		return rc;
	}
 // as TinyMCE 
    function getPos     ( n )
    {
	    n = getElement( n );
		if ( !n ) return {x : -1, y : -1};
		
    	var boxModel = !browser.isIE || document.compatMode == "CSS1Compat"; 
		var x = 0, y = 0, e,  r;
		// Use getBoundingClientRect on IE, Opera has it but it's not perfect
		if ( n && browser.isIE )
		{   n = n.getBoundingClientRect();
			e = boxModel ? document.documentElement : document.body;
			x = ""; // Remove border width
			x = ( x == 'medium' || boxModel && !browser.isIE6x) && 2 || x;
			n.top += window.self != window.top ? 2 : 0; // IE adds some strange extra cord if used in a frameset

			return {x : (n.left + e.scrollLeft - x), y : (n.top + e.scrollTop - x)};
		}

		r = n;
		while (r)
		{   x += r.offsetLeft || 0;
			y += r.offsetTop  || 0;
			r  = r.offsetParent;
		}
		r = n;
		while (r) 
		{   // Opera 9.25 bug fix, fixed in 9.50
			if (!/^table-row|inline.*/i.test( getStyle(r, "display", 1))) 
			{   x -= r.scrollLeft || 0;
				y -= r.scrollTop  || 0;
			}
			r = r.parentNode;
			if ( r == document.body)
				 break;
		}
		return {x : x, y : y};
	}

    function getStyle   ( elm, style, c)
    {   elm = getElement(elm);
		if (!elm)
			return false;
		// Gecko
		if ( document.defaultView && c)
		{   // Remove camelcase
			style = style.replace(/[A-Z]/g, function(a){ return '-' + a;});
			try
			{   return document.defaultView.getComputedStyle(elm, null).getPropertyValue(style);
			}
			catch (ex)
			{   // Old safari might fail
				return null;
			}
		}
		// Camelcase it, if needed
		style = style.replace(/-(\D)/g, function(a, b){ return b.toUpperCase(); });
		if ( style == 'float')
			 style = browser.isIE ? 'styleFloat' : 'cssFloat';
		// IE & Opera
		if ( elm.currentStyle && c )
			 return elm.currentStyle[style];
		return elm.style[style];
	}
	function goToUrl( strUrl)
	{	window.location.target = '_self';
		window.location=strUrl;
	//	window.location.href = strUrl;
		return true;
	}
	function isWhitespace( charToCheck, whitespaceChars )
	{   var whitespaceChars = (whitespaceChars != undefined )?whitespaceChars:" \t\n\r\f";
		return (whitespaceChars.indexOf( charToCheck ) != -1);
    }
	function ltrim( src, whitespaceChars )
	{   if ( !src.length ) return "";
		var posL = 0;
		while( isWhitespace(src.charAt(posL),whitespaceChars) && posL < src.length ) posL++;
		return src.substring( posL );
	}
	function onMouseEvent   ( e )
	{   var cursor = {x:-1, y:-1};
		e = e || window.event;
		if ( !e ) return cursor;
	
		if ( e.pageX || e.pageY )
		{   cursor.x = e.pageX;
			cursor.y = e.pageY;
		} 
		else
		{   var de = document.documentElement;
			var b  = document.body;
			cursor.x = e.clientX + 
				( de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
			cursor.y = e.clientY + 
				(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
		}
		m_cursor_pos = cursor;	 
		return cursor;
	}
	function pointInObject( id, w, h )
	{	var rc   = getObjectRect( id );
		if ( rc.left < 0 ) return false;
		var bRet = false;
		w    = (w != undefined && w > 0 )?w:(( rc.width  > 0)?rc.width :60);
		h    = (h != undefined && w > 0 )?h:(( rc.height > 0)?rc.height:60);
		if ( (rc.left  <= m_cursor_pos.x && m_cursor_pos.x <= rc.left +w) &&  
		     (rc.top   <= m_cursor_pos.y && m_cursor_pos.y <= rc.top  +h))
		      bRet = true;
//window.status = "ret: " + bRet + "; x: " + m_cursor_pos.x + "; y: " +  m_cursor_pos.y + "; left: "+ rc.left + "; top: " + rc.top + "; right: " + (rc.left+w-1) + "; bottom: " + (rc.top+h-1);
		return bRet;	  
	}
	function registerHelper( helper )
	{   for( var hlp in HELPER_EVENT_HANDLERS )
		{   if ( HELPER_EVENT_HANDLERS[hlp].getInstanceId && helper.getInstanceId )
			{   if ( HELPER_EVENT_HANDLERS[hlp].getInstanceId() == helper.getInstanceId())
	        		 return;
			}
			else
			{   if ( HELPER_EVENT_HANDLERS[hlp] == helper )
				     return;
			}
		}
		HELPER_EVENT_HANDLERS.push(helper);
	}
	function removeHelper   ( helper )
	{   for( var hlp in HELPER_EVENT_HANDLERS )
		{   if ( HELPER_EVENT_HANDLERS[hlp].getInstanceId && helper.getInstanceId )
			{   if ( HELPER_EVENT_HANDLERS[hlp].getInstanceId() == helper.getInstanceId())
			    {    HELPER_EVENT_HANDLERS.splice(hlp,1);
	        		 return;
	        	}
			}
			else
			{   if ( HELPER_EVENT_HANDLERS[hlp] == helper )
			    {    HELPER_EVENT_HANDLERS.splice(hlp,1);
	        		 return;
	        	}
			}
		}	
	}
	function rtrim( src,whitespaceChars )
	{   if ( !src.length ) return "";
		var posR = src.length - 1;
		while( isWhitespace(src.charAt(posR),whitespaceChars) && posR > 0 ) posR--;
		return src.substring( 0,posR+1);
	}
	function selectinpcheck ( id )
	{   var obj     = getElement( id );
        if ( !obj ) return false;
        if (  obj.tagName.toLowerCase() != 'input') return false;
        if ( !obj.value.length ) return false;
        obj.focus( );
        return obj;
	}
	function selectInpGetPos( id )
	{   var obj     = selectinpcheck( id );
        if ( !obj ) return -1;
		var col   = -1;
		if (document.selection)
		{   var range = document.selection.createRange();   
			if ( range.parentElement() != obj)   
				 return -1; 
			range.moveStart ('character', -obj.value.length);
			col = range.text.length;
		}
		else
		{   if ( obj.selectionStart || obj.selectionStart == '0') //&& ctrl.selectionStart == '0')
			     col = obj.selectionStart;
			else col = -1;
		}
        return col;
	}
	function selectInputText( id,p1,p2 )
	{   var obj     = selectinpcheck( id );
        if ( !obj ) return false;
		var range = null;
		var text  = obj.value;
		if ( !text.length ) return false;
		if ( p1 == undefined ) p1 = 0;
		if ( p2 == undefined ) p2 = text.length;
		if (document.selection)
		{   range = document.selection.createRange();   
			if ( range.parentElement() != obj)  return false; 
			range.moveStart ('character', -obj.value.length);
			var col = range.text.length;
		}
		else
		{   if ( obj.selectionStart ) //&& ctrl.selectionStart == '0')
			     col = obj.selectionStart;
			else col = -1;
		}
	    if ( col == -1 ) return false;
		if ( col == text.length ) return false;
	
		if ( document.selection )
	    {   range.moveStart('character',p1);
			range.moveEnd  ('character', p2-col+1);
			range.select   ( );
		}
		else
		{   if ( obj.selectionStart )
			{   obj.selectionStart = p1;
				obj.selectionEnd   = p2+1;
			}
		}
		return { 'pos1':p1,'pos2':p2 };
	}
	function setAttributes  ( id, attributes )
	{   var obj     = getElement( id );
		if ( !obj ) return;
        for ( var i in   attributes )
              obj.setAttribute( i, attributes[i]);
	}
	function setDivPos      ( id, pos )//pos.x & pos.y numeric
	{	var obj     = getElement( id );
		if ( !obj ) return;
		if ( obj.style )
		{	obj.style.left = pos.x+'px';
			obj.style.top  = pos.y+'px';
		}
	}
	function setOpacity     ( id, value )
	{	var obj = getElement(id);
		if ( obj == undefined || !obj ) return;
		obj.style.opacity      = value/10;
		if ( browser.isIE55 || browser.isIE6x )
			 obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=\''+value*10 +'\')';
		else obj.style.filter = 'alpha(opacity=' + value*10 + ')';
	}
    function setStyles       ( id, styles )
    {   var obj = getElement(id);
        if ( obj == undefined || !obj ) return;
        for ( var i in   styles )
        {   setStyleA( obj,i,styles[i]);
//          var c = i.replace(/-(\D)/g, function(a, b){ return b.toUpperCase(); });
//          obj.style[c] = styles[i];
        }
    }  
	function setStyleA( elm,prop,val)
	{   elm = getElement(elm);
        if ( prop == 'opacity') return setOpacity( elm,parseFloat(val));
        if ( prop == 'float'  ) prop = (window.attachEvent) ? 'styleFloat' : 'cssFloat';
        prop = camelize( prop );
        unit = (prop=='zIndex'||prop=='zoom' ) ? '':'px';
        elm.style[prop] = (typeof val=='string') ? val : val+unit;
        return elm;
    }
	function setVisible     ( id, enable )
	{	if ( id <=0 ) return;
		var obj     = ( typeof id == 'object')?id:getElement( id );
		if ( enable == true )
		     enable = 'visible';

	    var NNtype  ='show'; 
	    var IEtype  ='visible'; 
		var WC3type ='visible';
		
		if ( enable != 'visible' )
		{   NNtype  = 'hidden';
			IEtype  = 'hidden';
			WC3type = 'hidden';
		}
		try
		{  
		    if ( document.getElementById )
				 obj.style.visibility = WC3type;
			else
				if ( document.layers )
					obj.visibility = NNtype;
			else
				if ( document.all )
					 obj.style.visibility = IEtype;
					 
		}
		catch(err) { window.status = err.description+"; Id: "+id; }
	}
	function showTtip       ( name, enable, tipTxt,xoffset, yoffset )
	{
		var ttipNode = getElement( clsViewHelper.TTIP_DIV_ID );
		if ( ttipNode == null )
		{	if ( !document.createElement ) return;
		    var ttipNode = document.createElement("div");
		    document.body.appendChild(ttipNode);
		    ttipNode.setAttribute("id", name );
		    ttipNode.style.position   = "absolute";
		    ttipNode.style.background = tipBkgColor;
		    ttipNode.style.border     = "1pt black solid";
		    ttipNode.style.visibility = "hidden";
		    ttipNode.style.left       = "0px";
		    ttipNode.style.top        = "0px";
		    ttipNode.style.zIndex     = clsViewHelper.TTIP_ZINDEX;
		}
		var parent = getElement(name);
		var zindex = clsViewHelper.TTIP_ZINDEX;
		
		if ( parent )
		     zindex = parent.style.zIndex + 1;

		ttipNode.style.zIndex = (zindex >= clsViewHelper.TTIP_ZINDEX)?zindex:clsViewHelper.TTIP_ZINDEX;

		var ptob = findPos   ( name );
		if ( !xoffset ) xoffset=0;
		if ( !yoffset ) yoffset=40;
		if ( enable )
		{   if ( !tipTxt ) return;
			var str ='';
			str+='<B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tipTxt+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</B>';
		
			ttipNode.style.pixelLeft = ptob.x+xoffset;
			ttipNode.style.pixelTop  = ptob.y+yoffset;
			ttipNode.innerHTML = str;
			setVisible( clsViewHelper.TTIP_DIV_ID, 'visible');
		}
		else
		{
			setVisible( clsViewHelper.TTIP_DIV_ID, 'hidden');
		}
	}
	function swapImages     ( id, img )
	{	var obj = (typeof id == 'object')?id:getElement(id);
		if ( obj == undefined || !obj ) return;
		obj.src = img;
	}
	function trim( str,whitespaceChars )
	{   //str = dcdSpaces( str ); 
		return ltrim(rtrim(str,whitespaceChars),whitespaceChars);
	}
	
};// end class clsViewHelper

//class clsXmlParser
function clsXmlParser()
{   
    this.parseText = function(text, callback)
	{
		if ( typeof DOMParser != "undefined")
		{   var xml = (new DOMParser()).parseFromString(text, "application/xml");
			xml.onload = function()
            {   if ( (xml = xmlError(xml)) && callback != undefined )
                      callback( xml );
            }
			return xml;
		}
		else 
			if (typeof ActiveXObject != "undefined")
			{   var xml = new ActiveXObject("Microsoft.XMLDOM");
				xml.async="false";
				xml.loadXML(text);
				return xmlError( xml );
			}
		else
		{   // As a last resort, try loading the document from a data: URL
			// This is supposed to work in Safari. Thanks to Manos Batsis and
			// his Sarissa library (sarissa.sourceforge.net) for this technique.
			var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
			var request = new XMLHttpRequest();
			request.open ( "GET", url, false);
			request.send ( null );
			return request.responseXML;
		}
	}
    this.parseFile = function( file, callback )
	{
		if ( browser.isSafari )
		{
            var ajx = new clsAjxRequest( );
            var xml = new ajx.getSyncAjaxRq ( file,"");
            if ( (xml = xmlError(xml)) )
                      callback( xml );
            return xml;
		}
		if ( typeof DOMParser != "undefined")
		{
			var xml = document.implementation.createDocument("","",null);
            xml.load( file );
			xml.onload = function()
            {   if ( (xml = xmlError(xml)) )
                      callback( xml );
            }
			return xml;
		}
		else 
			if (typeof ActiveXObject != "undefined")
			{   var xml = new ActiveXObject("Microsoft.XMLDOM");
                xml.async="false";
				xml.load( file );

				if ( (xml = xmlError( xml )) )
				{   callback( xml );
				}
				return  xml;
			}
		return null;	
	}
	function xmlError( xml )
	{   var s = '';
	    if ( browser.isIE )
		{   if ( xml.parseError.errorCode )
			{   s += "Error Code: "   + xml.parseError.errorCode + "\n";
				s += "Error Reason: " + xml.parseError.reason    + "\n";
				s += "Error Line: "   + xml.parseError.line      + "\n";
                xml = null;
			}
		}
		else
		{   try
			{   if ( xml.documentElement && xml.documentElement.nodeName == "parsererror")
				{   s += xml.documentElement.childNodes[0].nodeValue;
					s = s.replace(/</g, "&lt;");
					xml = null;
				}
			}
			catch(e) { s = e.message; }
		}
		if ( s.length )
		     alert("xmlError: "+s);

        return xml;
	}
}; // end class clsXmlParser

function clsCalcStringWidth( id,fontStyles )
{
	var calcWDiv   = $(id);
	var bodyElm    = document.getElementsByTagName('body')[0];
	var m_maxwidth = 0;
	
	if ( calcWDiv == null)
	{   calcWDiv = document.createElement('span');
	    var styles = { 'visibility':'hidden'};
		for ( var i in fontStyles)
		      styles[i] = fontStyles[i];
		visi.setStyles( calcWDiv, styles);
		calcWDiv.setAttribute( 'id',    id  );
		bodyElm.appendChild( calcWDiv );
	}
	this.getMaxWidth     = function( ) { return m_maxwidth; }
	this.calcStringWidth = function( str )
	{
		calcWDiv.innerHTML = str;
		var rc = visi.getObjectRect( calcWDiv );
		if ( m_maxwidth < rc.width ) m_maxwidth = rc.width;
		return rc.width;
	}
};

//	    getCSSValueOf( 'table.menuline','backgroundColor');
function getCSSValueOf( selector, stylename)
{   if ( document.styleSheets )
	{   var sr    = '';
		var theRules = new Array();
		for ( var i = 0; i < document.styleSheets.length; i++ )
		{   if (document.styleSheets[i].cssRules)
				theRules = document.styleSheets[i].cssRules;
			else 
                if ( document.styleSheets[i].rules)
                     theRules = document.styleSheets[i].rules;
                else break;

			for ( var j = 0; j < theRules.length; j++ )
			{   sr = theRules[j].selectorText.toLowerCase( );
				if ( sr.indexOf(selector) != -1 )
				{   if ( theRules[j].style[stylename])
						 return theRules[j].style[stylename];
					return null;	 
				}
			}
		}
	}
    return null;
}
function disableSelection(id)
{   var target = $(id);
	if ( typeof target.onselectstart !="undefined") //IE route
		 target.onselectstart=function(){return false;}
	else if (typeof target.style.MozUserSelect !="undefined" ) //Firefox route
		 target.style.MozUserSelect="none";
	else //All other route (ie: Opera)
		 target.onmousedown=function(){return false;}
	target.style.cursor = "default";
}
function getFunctionName(theFunction)//debug stack
{   // mozilla makes it easy. I love mozilla.
	if(theFunction.name)
	{   return theFunction.name;
	}
	// try to parse the function name from the defintion
	var definition = theFunction.toString();
	var name = definition.substring(definition.indexOf('function') + 8,definition.indexOf('('));
	if ( name )
		return name;
	// sometimes there won't be a function name 
	// like for dynamic functions
	return "anonymous";
}
function $( id )
{	var bAllSupport = document.all!=null;
    if ( typeof id == 'object') return id;
	if ( document.getElementById )
		 return document.getElementById( id );
	if ( bAllSupport )
		 return document.all   [id];
	else return document.layers[id];
}


//default helper object
visi     = new clsViewHelper  ( );
xmlparse = new clsXmlParser   ( );
layout   = new clsCallbackList( );
layout.addCallback( FN_WINDOW_ONLOAD,   false );

