
var isdrag=false;
var x,y;
var dobj;
function $( s ) { return document.getElementById( s ); }
function ce( t ) { return document.createElement( t ); }
function v(){}; // void function
function insertAfter(node, referenceNode)
{
  referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
}
function isdefined( variable)
{
    return (typeof(variable) == "undefined")?  false: true;
}
function isnumber( variable)
{
    return (typeof(variable) == "number")?  false: true;
}

function val( o )
{
	var vo = o*1;
	return vo+'' == 'NaN' ? 0 : vo;
}

function inspect( dobj )
{
	win = window.open( '', 'inspect' );
	for (var i in dobj)	
	{ 
		var j = eval( 'dobj.' + i );
		win.document.write( i + ', ' + typeof( j )+ ', ' +  j + '<br>' );
//		debug( i, typeof( j ), j );
	}
}
function addOption(selectbox,text,value )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function splittext( classname, maxwid, stext )
{
	var tmp = ce( 'div' );
	var i, j;
	tmp.className = classname;
	tmp.style.position = 'absolute';
	tmp.style.left = -10000;
	tmp.style.width = '';
	tmp.style.display = 'block';

	var txtsplit = stext.split( / |\n/ );

	document.body.appendChild( tmp );
//	tmp.style.width = '10px';
	tmp.style.width = 'auto';
	var k = 40;
	for( i = 0 ; i < txtsplit.length ; i++ )
	{
		tmp.innerHTML = txtsplit[i];
		if( tmp.clientWidth > maxwid )
		{
			var out = txtsplit[i];
			for( j = 1 ; j < out.length && j < 1000; j++ )
			{
				tmp.innerHTML = out.substring( 0, j );
				if( tmp.clientWidth > maxwid )
				{
					out = out.substring( 0, j - 5) + '<br>' + out.substring( j-5, 10000 );
				}
			}
			txtsplit[i] = out;
			tmp.innerHTML = txtsplit[i];
		}
	}
	document.body.removeChild( tmp );
	return txtsplit.join( ' ' );

	
	dim = 5;
	while( 1 && tmp.clientHeight > maxheight )
	{
		stext = stext.substring( 0, stext.length - dim );
		while( stext.charAt(stext.length-1).match( /[a-zA-Z<]/ ) )
			stext = stext.substring( 0, stext.length - 1 );
		stext += more;
		if( dim < more.length ) dim += more.length;
		tmp.innerHTML = stext;
	}
	return stext;
}


function shrinktext( classname, maxheight, stext, maximizescript, moreflag, width )
{
//	return stext;
	var tmp = ce( 'div' );
	var more = moreflag ? ' ... <a href="javascript:'+ maximizescript + '">(more)</a>' : '...';
	tmp.className = classname;
	tmp.style.position = 'absolute';
	tmp.style.left = -10000;

	//#-- If more length string will be wrap into multi line.
//	stext = stext.wordWrap(38, "\n", true);
	//#--
	if( isdefined( width ) ) tmp.style.width = width;
	
	document.body.appendChild( tmp );
	tmp.innerHTML = stext;
	dim = 5;
	while( 1 && tmp.clientHeight > maxheight )
	{
		stext = stext.substring( 0, stext.length - dim );
		while( stext.charAt(stext.length-1).match( /[a-zA-Z<]/ ) )
			stext = stext.substring( 0, stext.length - 1 );
		stext += more;
		if( dim < more.length ) dim += more.length;
		tmp.innerHTML = stext;
	}
	document.body.removeChild( tmp );
	return stext;
}

function imgmaxdimmiddle( img, max )
{
	if( !isdefined( img.tim ) ) img.tim = 0;
	if( img.tim < 10 && img.width == 0 )
	{
		img.tim++;
		setTimeout( function() { imgmaxdimmiddle( img, max ); }, 1000 );
		return;
	}
	imgmaxdim( img, max );
	img.style.position = 'relative';
	img.style.left = Math.floor( (max-img.clientWidth)/2 );
}

function imgmaxdimcenter( img, max )
{
	if( !isdefined( img.tim ) ) img.tim = 0;
	if( img.tim < 10 && img.width == 0 )
	{
		img.tim++;
		setTimeout( function() { imgmaxdimcenter( img, max ); }, 1000 );
		return;
	}
	imgmaxdim( img, max );
	img.style.position = 'relative';
	img.style.left = Math.floor( (max-img.clientWidth)/2 );
	img.style.top = Math.floor( (max-img.clientHeight)/2 );
}

function imgmaxdim(img, max)
{
	if( !isdefined( img.tim ) ) img.tim = 0;
	if( img.tim < 10 && img.width == 0 )
	{
		img.tim++;
		setTimeout( function() { imgmaxdim( img, max ); }, 1000 );
		return;
	}
	var r = 1;
	var left = parseInt( img.offsetLeft + 0 );
	var top = parseInt( img.offsetTop + 0 );
	if( !isdefined( img.nheight ) )
	{
		img.nheight = img.height;
		img.nwidth = img.width;
	}
	var w = img.nwidth;
	var h = img.nheight;
	if( w == -1 )
	{
		debug( 'reload', img.width );
		setTimeout( function() { imgmaxdim( img, max ) }, 1000 );
		return;
	}
	var m = w > h ? w : h;
	if( m > max ) r = max/m;

	img.width = Math.floor( w*r );
	img.height = Math.floor( h*r );
	var w2 = img.width;
	var h2 = img.height;
	var m2 = w2 > h2 ? w2 : h2;
	if( m2 > max )
	{
//		debug( 'force' );
		img.style.width = Math.floor( w*r );
		img.style.height = Math.floor( h*r );
	}
//	debug( img.src, w, h, r, 'x', img.width, img.height );
	if( left <= 0 ) 
	{
		img.style.left = Math.floor((max-img.height)/2);
		img.style.left = 0;
	}
	if( top < 0 )
	{
		img.style.position = 'relative';
		img.style.top = 0;
	}
	var o = img.parentNode;
	while( o != document.body && o.parentNode != null && o.onmouseover == null ) o = o.parentNode;
	if( isdefined( o.onmouseover ) ) o.title = img.title;
	img.isloaded = true;
}
//# - check for special extended characters
function checkspecialchars(e)
{
	var isIE = navigator.userAgent.indexOf("MSIE") != -1; 
	
	//# - Get keycode
	if(!isIE) 
	{
		var pNumKeyCode = e.which
	}
	else
		var pNumKeyCode = (window.event) ? event.keyCode : e.keyCode;
	//#- check for special chars
	//if(pNumKeyCode >= 33 && pNumKeyCode<48 || pNumKeyCode>=58 && pNumKeyCode<65 || pNumKeyCode >= 91 && pNumKeyCode<97 || pNumKeyCode >= 123 && pNumKeyCode<127)//
	if(pNumKeyCode >= 160 && pNumKeyCode<256)
	{
		return false;
	}
	else
			window.event.returnValue = "NULL";
	return true;
}
