/* 
 *  Title:			TRS??????????
 *  Description:	TRS IDS??????js????.
 *		
 *  Copyright: 		Copyright (c) 2004-2005 TRS????????????????
 *  Company: 		TRS Info. Ltd.??www.trs.com.cn??
 *  Author:			liushen
 *  Created:		2005-03-02
 */

/**
 * ??????????????????.
 * @param mypage ??????????URL
 * @param myname ????????
 * @param w ????	
 * @param h ????
 * @param scroll ????????????????, ??????????????.
 * @param toolbar ??????????????.
 * @compatible IE; FireFox 1.0
 */
function newWindow(mypage, myname, w, h, scroll, toolbar){
	var nLeftPos = (screen.width) ? (screen.width-w)/2 : 0;
	var nTopPos = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height='+h+',width='+w+',top='+nTopPos+',left='+nLeftPos+',status,resizable';
	if (scroll == null || scroll == "") {
		scroll = "yes";
	}
	settings += ',scrollbars' + (scroll == 'no' ? '=no' : '');
	if (toolbar) {
		settings += ',toolbar=1';
	}
	var win = window.open(mypage, myname, settings);
	win.focus();
}

function showModal(mypage, myname, w, h, scroll){
	var nLeftPos = (screen.width) ? (screen.width-w)/2 : 0;
	var nTopPos = (screen.height) ? (screen.height-h)/2 : 0;
	var settings =
		'dialogHeight='+h+',dialogWidth='+w+',dialogTop='+nTopPos+',dialogLeft='+nLeftPos+',scrollbars='+scroll+',resizable';
	window.showModalDialog(mypage, myname, settings);
}

/**
 * Submit the specified form to the specified actionPage.
 * ????????????form??, ??????????form??onsubmit()????.
 * @param frm the specified form
 * @param actionPage the specified actionPage
 * @compatible IE; FireFox 1.0
 */
function submitTo(frm, actionPage) {
	if (frm == null) {
		return;
	}
	if (actionPage) {
		frm.action = actionPage;
	}
	frm.submit();
}

/** 
 * ????????id??html??????????display????.
 * @param eleId ????html??????????id
 * @compatible IE; FireFox 1.0
 */
function switchDisplay(eleId) {
	if (eleId == null) {
		return;
	}
	if (eleId.style.display == "none") {
		eleId.style.display = "inline";
	} else {
		eleId.style.display = "none";
	}
}

/** 
 * ??????????????????????????????id??html????????(??????????html??????????display????????).
 * @param bDisplay ????????. ??true??????, false????????
 * @param eleId ????html??????????id
 * @compatible IE; FireFox 1.0
 */
function doDisplay(bDisplay, eleId) {
	if (eleId == null) {
		return;
	}
	if (bDisplay == true) {
		eleId.style.display = "inline";
	} else {
		eleId.style.display = "none";
	}
}

/**
 * ????????, ??????????????????????????.
 * ????????FireFox 1.0.
 * @compatible IE;
 */
function closeWindow() {
	if (window.top) {
		if (window.top == window) {
			window.close();
		} else {
			window.top.close();
		}
	} else {
		window.close();
	}
}

/**
 * ??????????????HREF????, ??????????????????????????.
 * @param {String} href ????????HREF
 * @compatible IE; FireFox 1.0
 */
function changeHref(sHref) {
	if (window.top) {
		window.top.location.href = sHref;
	} else {
		location.href = sHref;
	}
}

/**
 * Hide the specified element by id.
 * @param {String} ele the specified element id.
 * @compatible IE; FireFox 1.0
 */
function hideElement(ele) {
	if (ele) {
		if (ele.style.display != "none") {
			ele.style.display = "none";
		}
	}
}

function showBroswerInfo() {
	if (window.navigator) {
		alert(window.navigator.appName + window.navigator.appVersion);
	} else {
		alert("Unknown!");
	}
}

function reloadWindow() {
	if (window.opener != null) {
		try {
			window.opener.location.reload(true);
		}catch (e) {
			window.close();
		}
		window.close();
	}else {
		window.close();
	}
}

/**
  * change bg of tr
  * @param obj the tr object 
  * @param sName the value of attribute
  * by ldr 060719
  */
function mOver(obj,sName)
{
	var child;
	setClass(obj,sName);
	/*
	for(var i =0 ; i < obj.childNodes.length ;i = i + 1)
	{
		child = obj.childNodes[i];
		if(document.all)
			child.style.cssText = "border-bottom:1px solid #c0c0c0;border-top:1px solid #d0d0d0;";
		else
			obj.childNodes[2*i+1].setAttribute("style","border-bottom:1px solid #c0c0c0;border-top:1px solid #d0d0d0;");
	}
	*/
}

function mOut(obj,sName)
{
	var child;
	setClass(obj,sName);
	/*
	for(var i = 0 ; i < obj.childNodes.length ; i = i + 1)
	{
		child = obj.childNodes[i];
		if(document.all)
			child.style.cssText = "border-bottom:1px solid #fff;border-top:1px solid #fff;";
		else
			obj.childNodes[2*i+1].setAttribute("style","border-bottom:1px solid #fff;border-top:1px solid #fff;");
	}
	*/
}
function setClass(obj,sName)
{
	obj.setAttribute("class", sName);
	obj.setAttribute("className", sName);
	return;
}
/**
  * show/hide div
  * @param fromObj the object that send the event
  * @param target the id of the target div
  * @param img_src the src of the image contains in fromObj
  * by ldr 060720
  */
function changeDisplayMode(fromObj, target, img_src)
{
	var obj = document.getElementById(target);
	var img = document.getElementById(img_src);
	if(obj.style.display=="block" || obj.style.display=="")
	{
		obj.style.display="none";
		fromObj.title="Click to show the content";
		img.setAttribute("src","../images/bit_white.gif");
	}
	else
	{
		obj.style.display="block";
		fromObj.title="Click to hide the content";		
		img.setAttribute("src","../images/bit_white_down.gif");
	}
}
function changeDisplayModeHome(fromObj, target, img_src)
{
	var obj = document.getElementById(target);
	var img = document.getElementById(img_src);
	if(obj.style.display=="block" || obj.style.display=="")
	{
		obj.style.display="none";
		fromObj.title="Click to show the content";
		img.setAttribute("src","images/bit_white.gif");
	}
	else
	{
		obj.style.display="block";
		fromObj.title="Click to hide the content";		
		img.setAttribute("src","images/bit_white_down.gif");
	}
}

/**
 * È¥³ý×Ö·û´®×ó±ß¿Õ¸ñ
 */
function LTrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1){
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1){
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

/**
 * È¥³ý×Ö·û´®ÓÒ±ß¿Õ¸ñ
 */
function RTrim(str){
    var whitespace = new String(" \t\n\r");
    var s = new String(str);

    if (whitespace.indexOf(s.charAt(s.length-1)) != -1){
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1){
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;
}

/**
 * 	È¥³ýÁ½±ß¿Õ¸ñ
 */
function Trim(str){
    return RTrim(LTrim(str));
}