
function getAbsTop(obj) {
    var o = obj;
    var t = o.offsetTop;
    while (o = o.offsetParent) t += o.offsetTop;
    return t;
}

function getAbsLeft(obj) {
    var o = obj;
    var l = o.offsetLeft;
    while (o = o.offsetParent) l += o.offsetLeft;
    return l;
}

function selectstart() {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false;
}

String.prototype.trim = function() {
    return this.replace(/(^(\s|\u3000)*)|((\s|\u3000)*$)/g, "") ;
}

function ocheckAll(obj, prefix) {
    var formObj  = obj.form;
    if (formObj == null) formObj = document.all;

    for (x in formObj) {
    	if (x.indexOf(prefix) != 0) continue;
    	if (!eval("formObj."+x).checked) return;
    }
    obj.checked = true;
}

function ycheckAllByClickBox(prefix, parentcheckObj) {
    var eventObj = window.event.srcElement;
    var formObj  = eventObj.form;
    if (formObj == null) formObj = document.all;
    var boo = false;
    if (eventObj.checked) boo = true;
    if (boo) { parentcheckObj.checked = true; return; }

    for (x in formObj) if (x.indexOf(prefix)==0 && eval("formObj."+x).checked) {
    	parentcheckObj.checked = true;
    	return;
    }
    parentcheckObj.checked = false;
}

function xcheckAllByClickBox(checkboxsnamePrefix) {
    var eventObj = window.event.srcElement;
    var formObj  = eventObj.form;
    if (formObj == null) formObj = document.all;
    var boo = false;
    if (eventObj.checked) boo = true;

    for (x in formObj) {
    	if (x.indexOf(checkboxsnamePrefix) == 0) checkAll(eval("formObj." + x), boo);
    }
}

function checkAllByClickBox(checkboxsname) {
    var eventObj = window.event.srcElement;
    var formObj  = eventObj.form;
    if (formObj == null) formObj = document.all;
    var boo = false;
    if (eventObj.checked) boo = true;

    var checkObj = eval("formObj." + checkboxsname);
    if (typeof(checkObj) != 'undefined') checkAll(checkObj, boo);
}

function myCheckByClick(prefix) {
    var obj = window.event.srcElement;
    var boo = false;
    if (obj.checked) boo = true;

    var parentId = obj.name.substr(prefix.length);
    if (parentId != '') myCheckByClickParent(prefix, parentId, boo);

    myCheckByClickChildren(prefix, obj.id, boo);
}

function myCheckByClickParent(prefix, parentId, boo) {
    var parentObj = document.getElementById(parentId);

    var pId = parentObj.name.substr(prefix.length);

    if (boo) {
        parentObj.checked = true;
        if (pId != '') myCheckByClickParent(prefix, pId, boo);
    }
}

function myCheckByClickChildren(prefix, parentId, boo) {

    var y = eval('document.all.' + prefix + parentId);
    if (typeof(y) == 'undefined') return;

    if (typeof(y.length) != 'undefined') for (var i=0; i<y.length; i++) {
    	y[i].checked = boo;
    	myCheckByClickChildren(prefix, y[i].id, boo);
    } else {
        y.checked = boo;
    	myCheckByClickChildren(prefix, y.id, boo);
    }

}

function checkAll(checkObj, boo) {
    if (typeof(checkObj.length) != 'undefined') {
        for (var i=0; i<checkObj.length; i++) checkObj[i].checked = boo;
    } else {
        checkObj.checked = boo;
    }
}

function checkNotNull(obj) {
    if (typeof(obj) == 'undefined') return true;
    if (typeof(obj.type) == 'string') {
        if (obj.value.trim() == "") return false;
        return true;
    }
    for (var i=0; i<obj.length; i++) if (obj[i].value.trim() == "") return false;
    return true;
}

function hasChecked(checkObj) {
    if (typeof(checkObj) == 'undefined') return false;
    if (typeof(checkObj.length) != 'undefined') {
        for (var i=0; i<checkObj.length; i++) {
            if (checkObj[i].checked) return true;
        }
    } else return checkObj.checked;
    return false;
}

function isAllChecked(checkObj) {
    if (typeof(checkObj) == 'undefined') return false;
    if (typeof(checkObj.length) != 'undefined') {
        for (var i=0; i<checkObj.length; i++) {
            if (!checkObj[i].checked) return false;
        }
    } else return checkObj.checked;
    return true;
}

function openWin(url, widthPercent, heightPercent, otherPara) {
	var wp = .7;
	var hp = .8;
	if (typeof(widthPercent)!='undefined'  && widthPercent!='')  wp = widthPercent;
	if (typeof(heightPercent)!='undefined' && heightPercent!='') hp = heightPercent;

	var width  = screen.width*wp;
	var height = screen.height*hp;
	var str = "resizable,scrollbars,height="+height+",";
	str += ",width=" + width;
	var xc = (1-wp)/2 * screen.width;
	var yc = (1-hp)/2 * screen.height - 20;
	str += ",left=" + xc;
	str += ",top=" + yc;

	if (typeof(otherPara)!='undefined' && otherPara!='') str += "," + otherPara;

	window.open(url, 'xwin', str);
}

function xopenWin(url, winName, widthPercent, heightPercent, otherPara) {
	var wp = .7;
	var hp = .8;
	if (typeof(widthPercent)!='undefined'  && widthPercent!='')  wp = widthPercent;
	if (typeof(heightPercent)!='undefined' && heightPercent!='') hp = heightPercent;

	var width  = screen.width*wp;
	var height = screen.height*hp;
	var str = "resizable,scrollbars,height="+height+",";
	str += ",width=" + width;
	var xc = (1-wp)/2 * screen.width;
	var yc = (1-hp)/2 * screen.height - 20;
	str += ",left=" + xc;
	str += ",top=" + yc;

	if (typeof(otherPara)!='undefined' && otherPara!='') str += "," + otherPara;

	window.open(url, winName, str);
}

function openWin2(url, widthPercent, heightPercent, otherPara) {
	var wp = .7;
	var hp = .8;
	if (typeof(widthPercent)!='undefined'  && widthPercent!='')  wp = widthPercent;
	if (typeof(heightPercent)!='undefined' && heightPercent!='') hp = heightPercent;

	var width  = screen.width*wp;
	if (wp > 1) width = wp;
	var height = screen.height*hp;
	if (hp > 1) height = hp;
	var str = "height="+height+",";
	str += ",width=" + width;
	var xc = (screen.width - width)/2;
	var yc = (screen.height-height)/2 - 20;
	str += ",left=" + xc;
	str += ",top=" + yc;

	if (typeof(otherPara)!='undefined' && otherPara!='') str += "," + otherPara;

	window.open(url, 'xwin', str);
}

function parentOpenWin(url, winName, widthPercent, heightPercent, otherPara) {
	var wp = .7;
	var hp = .8;
	if (typeof(widthPercent)!='undefined'  && widthPercent!='')  wp = widthPercent;
	if (typeof(heightPercent)!='undefined' && heightPercent!='') hp = heightPercent;

	var width  = screen.width*wp;
	var height = screen.height*hp;
	var str = "resizable,scrollbars,height="+height+",";
	str += ",width=" + width;
	var xc = (1-wp)/2 * screen.width;
	var yc = (1-hp)/2 * screen.height;
	str += ",left=" + xc;
	str += ",top=" + yc;

	if (typeof(otherPara)!='undefined' && otherPara!='') str += "," + otherPara;

	parent.window.open(url, winName, str);
}


function openDialog(url, args, para) {
	var a = null;
    var p = "dialogWidth:500pt;dialogHeight:300pt;status:no;help:no";
    if (typeof(args)!='undefined' && args!='') a = args;
    if (typeof(para)!='undefined' && para!='') p = para;
    return showModalDialog(url, a, p);
}

function isInt(i) {
    return !isNaN(i) && (new String(i).indexOf('.') == -1);
}

// force only input int, and
// less than and equal to the (max).
// onkeypress triger
function forceInt(max) {
    var obj = document.selection;
    var obj2 = obj.createRange(); // TextRange
    var selectText = obj2.text;
    if (selectText != '') obj.clear();

    var value = window.event.srcElement.value.trim();
    if (value != "" && !isInt(value)) {
        alert("forceInt(): value '" + value + "' isn't valid integer!");
        window.event.returnValue = false;
        return;
    }

    var i = window.event.keyCode;
    if  ( i < 48 || i > 57) { // 48 is keyCode of 0, 57 is keyCode of 9
        window.event.returnValue = false;
        return;
    }

    if (typeof(max) == 'undefined') return;
    if (!isInt(max)) {
        alert("forceInt(): argument '" + max + "' isn't valid integer!");
        window.event.returnValue = false;
        return;
    }
    var num = new Number(value) * 10 + (i - 48);
    if (num > max) window.event.returnValue = false;
}

// url: request.getContextPath() + "/date/calendar.html"
function selectDate(url, control) {
    var dc="";
    if (document.all(control).value=="") dc=new Date();
    else dc=new Date(document.all(control).value);
    var dt=showModalDialog(url,dc,"dialogWidth:20; dialogHeight:16; status:no;help:no");
    if (typeof(dt) == 'undefined') return;
    if (dt == null) return;
    if (dt == '') {
        document.all(control).value = '';
        return;
    }
    var m = dt.getMonth();
    document.all(control).value=dt.getFullYear()+"/"+(m<9?"0":"") + (m+1)+"/"+dt.getDate();
}
