/* 
 *  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,location){
	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=yes,resizable';
	if (scroll == null || scroll == "") {
		scroll = "yes";
	}
	if (location == null || location == "") {
		location = "no";
	}
	settings += ',location=' + location;
	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="点击此处展开本栏";
		img.setAttribute("src","../images/bit_white.gif");
	}
	else
	{
		obj.style.display="block";
		fromObj.title="点击此处收起本栏";		
		img.setAttribute("src","../images/bit_white_down.gif");
	}
}

function changeDisplayMode1(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="点击此处展开本栏";
		img.setAttribute("src","../images/bit_white.gif");
	}
	else
	{
		obj.style.display="block";
		fromObj.title="点击此处收起本栏";		
		img.setAttribute("src","../images/bit_white_down.gif");
	}
}
// 该方法用来解决模块开发中图片路径问题
function changeDisplayModeHome2(fromObj, target, path, 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="点击此处展开本栏";
		img.setAttribute("src",path+"/admin/images/bit_white.gif");
	}
	else
	{
		obj.style.display="block";
		fromObj.title="点击此处收起本栏";		
		img.setAttribute("src",path+"/admin/images/bit_white_down.gif");
	}
}
// @deprecated  废弃原因：不能灵活的解决模块开发中图片路径问题 ;  推荐使用changeDisplayModeHome(fromObj, target, path, img_src)方法。
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="点击此处展开本栏";
		img.setAttribute("src","images/bit_white.gif");
	}
	else
	{
		obj.style.display="block";
		fromObj.title="点击此处收起本栏";		
		img.setAttribute("src","images/bit_white_down.gif");
	}
}

function changeDisplayWord(fromObj, target) {
	var obj = document.getElementById(target);	
	var fromObj = $(fromObj);
		if(obj.style.display=="block" || obj.style.display=="")
		{
			obj.style.display="none";
			fromObj.innerHTML="<a href='#'>展开</a>"
			fromObj.title="点击此处展开";	
		}
		else
		{
			obj.style.display="block";
			fromObj.innerHTML="<a href='#'>隐藏</a>"
			fromObj.title="点击此处隐藏";				
		}
}

/**
 * 去除字符串左边空格
 */
function LTrim(str){
    return str.replace(/(^\s*)/g,"");
}

/**
 * 去除字符串右边空格
 */
function RTrim(str){
     return str.replace(/(\s*$)/g,"");
}

/**
 * 	去除两边空格
 */
function Trim(str){
    return str.replace(/(^\s*)|(\s*$)/g, "");
}