// 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,param )
	{   var bAfter = (bAfter != undefined )?bAfter:false;
	    var name   = (name)?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;
		ob.param    = (param == undefined )?null:param;
		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].param == null)?m_arCallbackFun[i].callback():m_arCallbackFun[i].callback(m_arCallbackFun[i].param);
			}
			return;
		}
	    if ( index > -1 && index < m_arCallbackFun.length )
		     return ( m_arCallbackFun[index].param == null)?m_arCallbackFun[index].callback():m_arCallbackFun[index].callback(m_arCallbackFun[index].param);	 
	}
	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 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 = o.parentNode;
			o.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)
	{   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 getFlashContent( width, height, movie, flashvars,params)
	{	
		var str='';	
		
		if ( !browser.isOpera )
		{
			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=10,0,0,0"';
			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+'"';
			
			if ( params )
			{   for ( var i in params )
					str2 += i+"=" + '"' + params[i]+ '" ';
			}
			
			
			
			if ( flashvars )
				 str2+=' flashvars="'+flashvars+'"';
			str2+=' > </embed>' + "\n";

			str+=str2;
			str+='</OBJECT> ' + "\n";
		}
		else// Opera Bug
		{   var str = '<embed id="' + m_id + '" name="' + m_id + '" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" type="application/x-shockwave-flash" ';
			str+=' width="'+width+'" height="'+height+'"';
			str+=' src="'+movie+'"';
			if ( params )
			{   for ( var i in params )
				      str+= i+"="+params[i]+ " ";
			}
			if ( flashvars )
				 str+=' flashvars="'+flashvars+'"';
			str+=' > </embed>' + "\n";
		}
		
		return str;
	}
	function getElement     ( id )
	{	if ( typeof id != 'string') return 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.copyStyle          = copyStyle;
	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.getPos             = getPos;
	this.getStyle           = getStyle;
	this.goToUrl            = goToUrl;

	this.inputGetCaret      = inputGetCaret;
	this.inputSubStr        = inputSubStr;

	this.ltrim				= ltrim;
	this.onMouseEvent		= onMouseEvent;
	this.pointInObject		= pointInObject;
	this.pointInRect        = pointInRect;
	this.registerHelper     = registerHelper;
	this.removeHelper       = removeHelper;
	this.rtrim				= rtrim;

    this.selectGetValue     = selectGetValue;
	this.selectFind         = selectFind;
	this.selectIndexOf      = selectIndexOf;
	this.selectSetSelected  = selectSetSelected;
	this.selectSetSelAdd    = selectSetSelAdd;

	
    this.setAttributes      = setAttributes;
	this.setDivPos			= setDivPos;
	this.setInnerText       = setInnerText;
	this.setOpacity 		= setOpacity;
	this.setStyleA          = setStyleA;
	this.setStyles          = setStyles;
	this.setVisible 		= setVisible;
	this.showTtip   		= showTtip;
	this.str2hex            = str2hex;
	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 = {};	
        try
		{   temp = new obj.constructor(); // changed (twice)
	        for( var key in obj)
	             temp[key] = clone(obj[key]);
		}
		catch(e) { temp = obj; }
		return temp;
	}
	function copyStyle(base, targ)
	{   var baseStyle = document.getElementById(base).style;
		var targStyle = document.getElementById(targ).style;
		
		for(var prop in baseStyle)
		{   var str = "targStyle." + prop + " = baseStyle." + prop + ";";
			try { eval(str); }
			catch( e ) {}
		}
	}
	
	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 != 'string') 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 = '';
        if ( document.all )
             s = obj.innerText;
        else s = obj.textContent;

		if ( s == undefined)
		{    s = obj.innerHTML.replace(/<[^>]+>/g,"");
	    }
	    return s;
    }
	
	function getmaxdim      ( ) 
	{   // copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
	    var x = (typeof window.pageXOffset != 'undefined') ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
		var y = (typeof window.pageYOffset != 'undefined') ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop  ? document.documentElement.scrollTop  : document.body.scrollTop  ? document.body.scrollTop  : 0; 
        var w = (window.innerWidth  != null )? window.innerWidth  : document.documentElement && document.documentElement.clientWidth  ? document.documentElement.clientWidth  : document.body != null ? document.body.clientWidth  : null;
		var h = (window.innerHeight != null )? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
		return {'left':x, 'top':y, '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;
		}
		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 inputGetCaret( id )
	{   var obj     = inputCtrlFocus( 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 inputCtrlFocus ( 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 inputSubStr( id,p1,p2 )
	{   var obj     = inputCtrlFocus( 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 { 'text':text.substr(p1,p2),'pos1':p1,'pos2':p2 };
	}
	
	function isWhitespace( charToCheck, whitespaceChars )
	{   var whitespaceChars = (whitespaceChars != undefined )?whitespaceChars:(" \t\n\r\f\x0C" + String.fromCharCode(8207) + String.fromCharCode(8206));
		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 );
		rc.width    = (w != undefined && w > 0 )?w:(( rc.width  > 0)?rc.width :60);
		rc.height   = (h != undefined && w > 0 )?h:(( rc.height > 0)?rc.height:60);
		return pointInRect(rc);
	}
	function pointInRect    ( rc )
	{   var bRet = false;
		if ( (rc.left  <= m_cursor_pos.x && m_cursor_pos.x <= rc.left +rc.width ) &&  
		     (rc.top   <= m_cursor_pos.y && m_cursor_pos.y <= rc.top  +rc.height))
		      bRet = true;
		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 selectGetValue     ( id, defaultval )
    {   var sel = getElement( id );
        if (!sel) return (defaultval)?defaultval:null;
        return ( sel.selectedIndex >= 0 )?({'text':sel.options[sel.selectedIndex].text,'index':sel.selectedIndex}):((defaultval)?defaultval:null);
    }
	function selectFind  ( id, findstr )
	{   var o = getElement(id);
		for ( var i = 0; i < o.options.length; i++)
		{   if ( o.options[i].text == findstr )
				 return {'text':o.options[i].text,'index':i};
		}
		return null;
	}
	function selectIndexOf    ( id, findstr,ind )
	{   var o = getElement(id);
		if ( ind )
		{   if ( ind >= o.options.length || ind < 0 )
				return null;
		}
		else ind = 0;
		for ( var i = ind; i < o.options.length; i++)
		{   if ( o.options[i].text.indexOf( findstr ) >= 0 )
				 return {'text':o.options[i].text,'index':i};
		}
		return null;
	}
	function selectSetSelected  ( id, selectid )
	{   var o = getElement(id);
	    if ( typeof selectid == 'string')
	    {   var s = selectFind( id, visi.trim(selectid) );
			if ( s )
				 o.selectedIndex = s.index;
		}
		else
		{   if ( typeof selectid == 'number')
			{   if ( selectid >= 0 || selectid < o.options.length )
				     o.selectedIndex = selectid;
			}
		}
	}
	function selectSetSelAdd  ( id, strselect )
	{   var o = getElement(id);
		var s = selectFind( id, trim(strselect));
		if ( s )
		{   o.selectedIndex = s.index;
		}
		else
		{   //alert(strselect + "; " + o.options.length);
	        strselect = trim(strselect);
			o.options[o.options.length] = new Option(strselect,strselect);
			//alert(strselect + "; " + o.options.length);
			o.selectedIndex = o. options.length-1;
		}
	}
	
	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 setInnerText   ( id,text )
	{   var obj     = getElement( id );
		if ( obj )
		{   if ( document.all )
				 obj.innerText   = text;
			else obj.textContent = text;
		}
    }
	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 setOpacityA   ( id, value )
	{	var obj = getElement(id);
		if ( obj == undefined || !obj ) return;
        var fi = (value == 1 || value === '') ? '' : (value < 0.0001) ? 0 : value/10;
		obj.style.opacity      = fi;
		
		if ( browser.isIE )
		{   fi = Math.round(value*10+0.5);
            obj.style.zoom = 1;
		    if ( browser.isIE55 || browser.isIE6x || browser.versionMajor >= 8)
		         obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=\'' + fi +'\')';
				 //filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
	        else obj.style.filter = 'alpha(opacity=' +fi + ')';
		}
	}
    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 ( !obj ) return;
		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 str2hex   ( str )
	{   var h = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
		var t = new Array( );
		var d,a1,a2;
	
		for (var i = 0,j=0; i < str.length; i++, j += 4)
		{   d  = str.charCodeAt(i);
			b1 = d>>>8;
			b2 = (d&0x00ff)
			a1 = b1>>>4;
			a2 = b1&0x0f
			a3 = b2>>>4
			a4 = b2 &0x0f
			t[j+0] = h[a1];
			t[j+1] = h[a2];
			t[j+2] = h[a3];
			t[j+3] = h[a4];
		}
		var s = t.join('');
	
		return s;
	}
	
	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: load/parse XML synchronous
function clsXmlParser( param )
{   
    var m_param = (param == undefined )?null:param;
    var MSXML   = [
					 "Msxml2.DOMDocument.6.0",
					 "Msxml2.DOMDocument.5.0",
					 "Msxml2.DOMDocument.4.0",
					 "Msxml2.DOMDocument.3.0",
					 "MSXML2.DOMDocument",
					 "Microsoft.XMLDOM"
                  ];
	function createDocument() 
	{
		var doc = null;
		if ( window.ActiveXObject ) 
		{   for ( var i = 0; i < MSXML.length; i++) 
			{   try 
				{   doc = new ActiveXObject(MSXML[i]);
				} catch (e) { }
			}
			if ( !doc )
			{   //alert("Cannot create XMLDocument object");
				return null;
			}
		}
		return doc;
	}
	
	this.setparams = function( param ) { m_param = (param == undefined )?null:param; }
    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,m_param );
            }
			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 )
	{
        var xmlDoc = createDocument();	
/*		
		if ( browser.isSafari )
		{
            var ajx = new clsAjxRequest( );
            xmlDoc     = new ajx.getSyncAjaxRq ( file,"");
            if ( (xmlDoc = xmlError(xmlDoc,file)) )
                      callback( xmlDoc,m_param );
            return xmlDoc;
		}
*/		
		if ( xmlDoc && typeof xmlDoc.load != 'undefined') 
		{   xmlDoc.async = false;
		    xmlDoc.load( file );
			if ( (xmlDoc = xmlError(xmlDoc,file)) )
                      callback( xmlDoc,m_param );
		} 
		else 
		{   var request = new XMLHttpRequest();
		    request.open("GET", file, false);
		    request.send("");
			if ( (request.responseXML = xmlError(request.responseXML,file)) )
                      callback( request.responseXML,m_param );
			return 	request.responseXML;
		}
		return xmlDoc;
		
	}
	function xmlError( xml,file )
	{   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 )
		{
			if ( file == undefined )
		         alert("xmlError: "+s);
			else alert(file + "\n" + "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.clear           = function( ) { m_maxwidth = 0; }
	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;
	}
};
function clsCalcObjectDim( id,instyles )
{
	var calcWDiv = $(id);
	var bodyElm  = document.getElementsByTagName('body')[0];
	var m_maxdim = {width:0,height:0};
	
	if ( calcWDiv == null)
	{   calcWDiv = document.createElement('div');
	    var styles = {'display':'inline-block','visibility':'hidden','overflow':'hidden', 'text-align':'left', 'padding':'0px 10px'};
		if ( instyles != undefined )
		{   for ( var i in instyles)
		          if ( typeof styles[i] == 'undefined')
		               styles[i] = instyles[i];
		}
		visi.setStyles( calcWDiv, styles);
		calcWDiv.setAttribute( 'id',    id  );
		bodyElm.appendChild( calcWDiv );
	}
	this.clear           = function( ) { m_maxdim.width = 0; m_maxdim.height = 0; }
	this.getMaxDim       = function( ) { return m_maxwidth; }
	this.calcObjectDim   = function( content )
	{
		calcWDiv.innerHTML = content;
		var rc = visi.getObjectRect( calcWDiv );
		if ( m_maxdim.width  < rc.width  ) m_maxdim.width  = rc.width;
		if ( m_maxdim.height < rc.height ) m_maxdim.height = rc.height;
		return { width: rc.width, height: rc.height };
	}
};

//	    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
{   if ( !theFunction ) return "anonymous";
    // mozilla makes it easy. I love mozilla.
	if ( typeof theFunction.name != 'undefined' && 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 != 'string') return id;
	if ( document.getElementById )
		 return document.getElementById( id );
	if ( bAllSupport )
		 return document.all   [id];
	else return document.layers[id];
}
function getScrollXY() 
{
    var scrOfX = 0, scrOfY = 0;
    if ( typeof( window.pageYOffset ) == 'number' ) 
	{   //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    }
	else 
	    if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
		{   //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } 
	else 
	    if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
		{   //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
    return { 'x':scrOfX, 'y':scrOfY };
}

function scalerect( rc1,rc_scalecoeff)
{
	return { left:rc1.width * rc_scalecoeff.left,top:rc1.height*rc_scalecoeff.top, width:rc1.width*rc_scalecoeff.width, height:rc1.height*rc_scalecoeff.height};
}
function setobjdim( obj,rc )
{   if (obj)
	{   visi.setStyles(obj,{'left':rc.left+'px','top':rc.top    + 'px','width':rc.width  + 'px','height':rc.height + 'px'});
	}
}

//default helper object
visi     = new clsViewHelper  ( );
function urlbase() { return visi.getbaseurl() };
xmlparse = new clsXmlParser   ( );
layout   = new clsCallbackList( );
layout.addCallback( FN_WINDOW_ONLOAD,   false );

