
String.prototype.ltrim = function() {
  return (this.replace(/^[\s\xA0]+/, ""));
}
String.prototype.rtrim = function() {
  return (this.replace(/[\s\xA0]+$/, ""));
}
String.prototype.trim = function() {
  return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}

var tOMap = { };
function tabOpen(name,idx) {
	var elm = document.getElementsByName(name);
	for( i=0; i<elm.length; i++ ) {
		elm[i].style.display = (i!=idx)?"none":"";
	}
	try { new Function("odx,idx","tabOpen_"+name+"(odx,idx);")(tOMap[name],idx);
	} catch(e) { }
	tOMap[name] = idx;
}

var goSiteBtnStt = true;
function goSiteBtnChg(objID) {
	try {
		var obj = document.getElementById(objID);
		var pb = obj.style.backgroundPosition.replace(/px/g, "");
		if(pb == "0 -22") 
			obj.style.backgroundPosition = "0 0";
		else 
			obj.style.backgroundPosition = "0 -22";
		
		window.status = obj.style.backgroundPosition;
			
		if(goSiteBtnStt == true) {
			setTimeout("goSiteBtnChg('" + objID + "')", 500);
		}
	}catch (e) {
	}
}

function setGoSiteBtnCng(stt, objID) {
	goSiteBtnStt = stt;
	if(stt == true)
		goSiteBtnChg(objID);
}

function setDivPos(targetId, thisId, x, y) {
	var targetObj = document.getElementById(targetId);
	var thisObj = document.getElementById(thisId);
	thisObj.style.top = ( GetPosY(targetObj) + y )+ "px";
	thisObj.style.left = ( GetPosX(targetObj) + x )+ "px";
}

function popUpCheck( obj ) {
	if(obj == null) return alert('disable popup check');
}

function setWindowSize( objName ) {
	var obj = document.getElementById( objName );
	var width = parseInt(obj.offsetWidth ) + 30;
	var height = parseInt(obj.offsetHeight) + 85;
	window.resizeTo(width, height);
}
 
function copyClipboard(text) {
	window.clipboardData.setData('text', text);
	alert("copied clipboard");
}

function thisform(en) {
	if(en) return document.forms["memothis"][en];
	return document.forms["memothis"];
}

function formElem(name) {
	var elem = thisform(name);
	if( !elem ) thisform().appendChild(elem=document.createElement("<INPUT type=hidden name="+name+">"));
	return elem;
}

function replaceQuery( arg1,arg2,qry ) {
  var tq = qry?qry:(thisQuery)?thisQuery():'';
  var re = new RegExp( "(^"+arg1+"=)|(&"+arg1+"=)[^&]*","i" );
  var qr = tq.replace( re,arg2?("$1$2"+arg2):"" );
  if( arg2 && qr.indexOf(arg1+"=")==-1 ) qr += "&"+arg1+"="+arg2;
  return qr;
}

function imposeMaxLength(Object, MaxLen) {
	if( event.keyCode==8 || event.keyCode==46 ) return true;
	if( event.keyCode>=33 && event.keyCode<=40 ) return true;
	var value = Object.value,
			cc = wcslen(value);
	if( cc>MaxLen ) {
		var ix = 0,cx = cc-MaxLen, vc = value.length-1;
		while(cx>0) {
			if( value.charCodeAt(vc)>255 ) cx --;
			cx --; ix--;
		}
		value = value.substr(0,value.length+ix);
		Object.value = value;
		return false;
	}
	return (cc < MaxLen);
}

function imgSize(img,w,h) {
	if( img.width>w ) { img.removeAttribute('height'); img.width = w; }
	if( img.height>h ) { img.removeAttribute('width'); img.height = h; }
}

function absPos(elem, x, y) {
	x = x || 0; y = y || 0;
	if (!elem) return { x:x, y:y };
	x += elem.offsetLeft; y += elem.offsetTop;
	return elem.tagName != "BODY" ? absPos(elem.offsetParent, x, y) : { x:x, y:y };
}

function addLoadEvent(efn) {
try {
	if( window.attachEvent )
		window.attachEvent("onload",efn);
	else if( window.addEventListener )
		window.addEventListener("load",efn,true);
}
catch(e) { }
}
