function trim( val )
{
	if( !val )
		val = "";
	var re = /^\s*/;
	val = val.replace( re, "" );
	
	re = /\s*$/;
	val = val.replace( re, "" );
	return val;
}
function isIe()
{
	if( window.ActiveXObject )
		return true;
	else
		return false;
}
function getValue( id )
{
	var obj = document.getElementById( id );
	if( obj )
		return obj.value;
}
function getRadioValue( objs )
{
	if( !objs )
		return;
	if( !objs.length )
	{
		if( objs.checked )
			return objs.value;
		else
			return;
	}
	for( var i=0; i<objs.length; i++ )
	{
		if( objs[i].checked )
			return objs[i].value
	}
	return;
}

function setValue( name, value )
{
	var obj = document.getElementById( name );
	if( obj.tagName.toLowerCase() == "select" )
	{
		for( var i=0; i<obj.options.length; i++ )
		{
			if( obj.options[i].value == value )
				obj.options[i].selected = true;
		}
	}
	else if( obj.tagName.toLowerCase() != "span" && obj.tagName.toLowerCase() != "div" )
		obj.value = value;
	else
		obj.innerHTML = value;
}
function showObj( id, val )
{
	var obj = document.getElementById( id );
	if( obj )
	{
		if( val )
		{
			if( document.all )
				obj.style.display = "block";
			else
				obj.style.display = "table-row";
		}
		else
		{
			if( document.all )
				obj.style.display = "none";
			else
				obj.style.display = "none";
		}
	}
}
function isInt( val )
{
	var re = /^\d+$/;
	var result = re.test( val );
	return result;
}
function isDouble( val )
{
	var re = /^(\d+\.)?\d+$/;
	var result = re.test( val );
	return result;
}
function showDiv(id,divWidth,top)
{
	var obj = document.getElementById( id );
	if( obj )
	{
		var avaiableWidth = document.body.clientWidth;
		var left = avaiableWidth/2 - divWidth/2;
		obj.style.left = left;
		obj.style.top = top;
		obj.style.display = "block";
	}
}
function focusObj( id )
{
	var obj = document.getElementById( id );
	if( obj )
	{
		obj.focus();
	}
}

function selectObj( id )
{
	var obj = document.getElementById( id );
	if( obj )
	{
		obj.select();
	}
}

function setPrecsion2( val )
{
	var a = val * 100;
	a=Math.round(a);
	a = a/100;
	var b = a + "";
	var index = b.indexOf( "." );
	if( index == -1 )
	{
		b += ".00";
	}
  else
	{
		//precision current has
		var c = b.length - 1 - index;
		for( var i=0; i<(2-c); i++ )
		{
			b += "0";
		}
	}
	return b;
}

function getPosition(obj, pos) {
	var t = eval("obj." + pos);
	while (obj = obj.offsetParent) {
		t += eval("obj." + pos);
	}
	return t;
}

function setCenter(id,topOffset,objWidth)
{
	var swidth = window.screen.availWidth;
	var sheight = window.screen.availHeight;
	var scrollTop = document.body.scrollTop;
	document.getElementById(id).style.left = (swidth - objWidth)/2;
	document.getElementById(id).style.top = scrollTop + topOffset;;
}

function cm2inch(cmvalue)
{
	var inchvalue = "" + cmvalue / 2.54;
	var index = inchvalue.indexOf( "." );
	if( index != -1 )
	{
		var lastIndex = index + 2;
		if( lastIndex >= inchvalue.length )
			lastIndex = inchvalue.length;
		inchvalue = inchvalue.substring(0, lastIndex);
	}
	return inchvalue;
}
function preLoadImg(url) {
  var img = new Image();
  img.src = url;
}
function preLoadImgs(urls) {
	for( var i=0; i<urls.length; i++ )
	{
	  preLoadImg(urls[i]);
	}
}
function popupFrontDiv(id)
{
	var obj = document.getElementById( id );
	if( obj )
	{
		obj.style.left = 0;
		obj.style.top = 0;
		obj.style.width = window.screen.availWidth;;
		obj.style.height = document.body.scrollHeight;
		obj.className = "opacity";

		$("#selectTieDiv").click = function(e){
     //showObj(id,false);
    };
		showObj(id,true);
	}
}
function confirmUrl(msg,url)
{
	if( confirm(msg) )
		location.href = url;
}