﻿/* JavaScript 公用函数 */

/* 基础函数 */

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i>d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function reloadPage(init) {
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
  else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
reloadPage(true);

function swapImgRestore() {
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i>a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showHideLayers() {
	var i,p,v,obj,args = showHideLayers.arguments;
	for (i = 0; i < (args.length-2); i += 3) {
		if ((obj = findObj(args[i])) != null) {
			v = args[i+2];
			if (obj.style) {
				obj = obj.style;
				v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v;
			}
			obj.visibility = v;
		}
	}
}

function highlight(x,y){
	document.forms[x].elements[y].focus();
	document.forms[x].elements[y].select();
}

function jumpMenu(targ,selObj,restore){ 
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore) selObj.selectedIndex = 0;
}
	
function nbGroup(event, grpName) {
  var i,img,nbarr,args=nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = findObj(args[2])) != null && !img.init) {
      img.init = true; img.up = args[3]; img.dn = img.src;
      if ((nbarr = document[grpName]) == null) nbarr = document[grpName] = new Array();
      nbarr[nbarr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = findObj(args[i])) != null) {
        if (!img.up) img.up = img.src;
        img.src = img.dn = args[i+1];
        nbarr[nbarr.length] = img;
    } }
  } else if (event == "over") {
    document.nbOver = nbarr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = findObj(args[i])) != null) {
      if (!img.up) img.up = img.src;
      img.src = (img.dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.up);
      nbarr[nbarr.length] = img;
    }
  } else if (event == "out") {
    for (i=0; i < document.nbOver.length; i++) {
      img = document.nbOver[i]; img.src = (img.dn) ? img.dn : img.up; }
  } else if (event == "down") {
    nbarr = document[grpName];
    if (nbarr)
      for (i=0; i < nbarr.length; i++) { img=nbarr[i]; img.src = img.up; img.dn = 0; }
    document[grpName] = nbarr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = findObj(args[i])) != null) {
      if (!img.up) img.up = img.src;
      img.src = img.dn = (args[i+1])? args[i+1] : img.up;
      nbarr[nbarr.length] = img;
  } }
}

/* 公用函数 */

var eventObj; //公用事件对象
var hiddenObj; //公用隐藏对象
var formObj; //公用表单对象
var objList; //公用对象列表
var listId = -1; //公用列表编号
var labelId = 0; //公用标签编号
var winHandler; //公用window句柄
var timerHandler; //公用timer句柄

//等待time秒后执行
function wait(code, time) {
	try {
		timerHandler = setTimeout(code, time * 1000);
		return timerHandler;
	} catch (e) {}
}

//间隔time秒执行
function repeat(code, time) {
	try {
		timerHandler = setInterval(code, time * 1000);
		return timerHandler;
	} catch (e) {}
}

//停止所有timer执行
function stop() {
	try {
		clearInterval(timerHandler);
	} catch (e) {}
}

function setAlpha(obj, alpha) {
	if(navigator.appName != "Microsoft Internet Explorer") 
		return;
	try{
	  if (obj == null)
		  return;
	  if (alpha == null)
		  alpha = 90;
	  clearInterval(obj.alphaing);
	  obj.alphaing = false;
	  obj.filters.Alpha.Opacity = alpha;
	} catch(e){}
}

function alphaUp(obj, finishAlpha, acc) {
	try {
		var obj = eval(obj);
		if (obj.filters.Alpha.Opacity < finishAlpha) {
			obj.filters.Alpha.Opacity += acc;
		}
		else {	
			obj.filters.Alpha.Opacity = finishAlpha;
			clearInterval(obj.alphaing);
			obj.alphaing = false;
		}
	} catch (e) {}
}

function alphaDown(obj, finishAlpha, acc) {
	try {
		var obj = eval(obj);
		if (obj.filters.Alpha.Opacity > finishAlpha) {
			obj.filters.Alpha.Opacity -= acc;
		}
		else {	
			obj.filters.Alpha.Opacity = finishAlpha;
			clearInterval(obj.alphaing);
			obj.alphaing = false;
		}
	} catch (e) {}
}

function showAlpha(obj, finishAlpha, startAlpha, acc, time) {
	if(navigator.appName != "Microsoft Internet Explorer") 
		return;
	if (obj == null)
		return;
	if (finishAlpha == null)
		finishAlpha = 90;
	if (startAlpha == null)
		startAlpha = 0;
	if (acc == null)
		acc = 15;
	if (time == null)
		time = 1;
	obj.filters.Alpha.Opacity = startAlpha;
	obj.alphaing = setInterval("alphaUp(" + obj.id + "," + finishAlpha + "," + acc + ")", time);
}

function hideAlpha(obj, startAlpha, finishAlpha, acc, time) {
	if(navigator.appName != "Microsoft Internet Explorer") 
		return;
	if (obj == null)
		return;
	if (startAlpha == null)
		startAlpha = 100;
	if (finishAlpha == null)
		finishAlpha = 0;
	if (acc == null)
		acc = 20;
	if (time == null)
		time = 1;
	obj.filters.Alpha.Opacity = startAlpha;
	obj.alphaing = setInterval("alphaDown(" + obj.id + "," + finishAlpha + "," + acc + ")", time);
}

function stopAlpha(obj) {
	clearInterval(obj.alphaing);
}

//获取对象
function obj(id) {
	if (hasObj(id)) return document.getElementById(id);//document.all.item(id)
	else return null;
}

//是否存在对象
function hasObj(id) {
	var o = null;
	try {
		o = document.getElementById(id);//document.all.item(id)
	} catch (e) {}
	if (o != null) return true;
	else return true;
}

//获取表单对象
function form(name, objForm) {
	try {
		if (objForm == null) {
			return document.forms[0].item(name);
		}
		else {
			return objForm.item(name);
		}
	} catch (e) {}
}


function toNumber(s) {
   return Number(String(s).replace(/[^0-9\.]/g, ""));
}

function numRound(value,i) {
	var tem = toNumber(value);
	return tem = (Math.round(tem/Math.pow(10,-i))) / (Math.pow(10,i));
}


//获取对象值
function getValue(obj) {
	if (obj != null) {
		try {
			return obj.value;
		} catch (e) {}
	}
}

function get(obj) {
	return getValue(obj);
}

function getString(obj) {
	return String(getValue(obj));
}

function getStr(obj) {
	return getString(obj);
}
	
function getNumber(obj) {
	return Number(getValue(obj));
}

function getNum(obj) {
	return getNumber(obj);
}

//设置对象值
function setValue(obj, value) {
	if (obj != null && value != null) {
		try {
			obj.value = value;
		} catch (e) {}
	}
}

function set(obj, value) {
	setValue(obj, value);
}

function setString(obj, value) {
	setValue(obj, String(value));
}

function setStr(obj, value) {
	setString(obj, value);
}

function setNumber(obj, value) {
	setValue(obj, Number(value));
}

function setNum(obj, value) {
	setNumber(obj, value);
}

//设置对象样式
function setClass(obj, className) {
	try {
		if (obj == null)
			return;
		obj.className = className;
	} catch (e) {}
}

//通过Map填充对象值
function fillObj(map, filterColor, fontColor) {
	if (map == null)
		return;
	if (filterColor == null)
		filterColor = clrBgView;
	if (fontColor == null)
		fontColor = clrTextRead;
	try {
		ad = map.toArray();
		var tmp;
		for (var i = 0; i < ad.length; i++) {
			tmp = obj(ad[i][0]);
			tmp.value = ad[i][1];
			try {
				tmp.style.color = filterColor;
				tmp.filters[0].apply();
				tmp.style.color = fontColor;
				tmp.filters[0].play();
			} catch (e) {}
		}
	} catch (e) {}
}

//通过Map填充表单对象值
function fillForm(map, objForm, filterColor, fontColor) {
	if (map == null)
		return;
	if (filterColor == null)
		filterColor = clrBgView;
	if (fontColor == null)
		fontColor = clrTextRead;
	try {
		if (objForm == null)
			objForm = forms[0];
		ad = map.toArray();
		var tmp;
		for (var i = 0; i < ad.length; i++) {
			tmp = form(ad[i][0], objForm);
			tmp.value = ad[i][1];
			try {
				tmp.style.color = filterColor;
				tmp.filters[0].apply();
				tmp.style.color = fontColor;
				tmp.filters[0].play();
			} catch (e) {}
		}
	} catch (e) {}
}

//清空文字
function clearText(obj) {
	if (obj != null) {
		try {
			obj.value = "";
		} catch (e) {}
	}
}

//清空列表
function clearSelect(obj) {
	if (obj != null) {
		try {
			obj.options[0].selected = true;
		} catch (e) {}
	}
}

//清空多选列表
function clearMulti(obj) {
	if (obj != null) {
		try {
			for (var i = obj.options.length - 1; i >= 0; i--)
				obj.options.remove(i);
		} catch (e) {}
	}
}

//清空单选框
function clearRadio(obj) {
	try {
		if (obj == null) {
			return;
		}
		else if (obj.length == null) {
			if (obj.defaultChecked) {
				obj.checked = true;
			}
			else {
				obj.checked = false;
			}
		}
		else for (var i = 0; i < obj.length; i++) {
			if (obj[i].defaultChecked) {
				obj[i].checked = true;
				break;
			}
			else {
				obj[i].checked = false;
			}
		}
	} catch (e) {}
}

//清空多选框
function clearCheckbox(obj) {
	try {
		if (obj == null) {
			return;
		}
		else if (obj.length == null) {
			if (obj.defaultChecked) {
				obj.checked = true;
			}
			else {
				obj.checked = false;
			}
		}
		else for (var i = 0; i < obj.length; i++) {
			if (obj[i].defaultChecked) {
				obj[i].checked = true;
			}
			else {
				obj[i].checked = false;
			}
		}
	} catch (e) {}
}

//隐藏对象
function hideObject(obj) {
	try {
		if (obj == null)
			return;
		obj.style.display = "none";
	} catch (e) {}
}

function hideObj(id) {
	try {
		hideObject(obj(id));
	} catch (e) {}
}

function hideObjectAll(obj) {
	try {
		if (obj == null)
			return;
		else if (obj.length == null) {
			obj.style.display = "none";
		}
		else for (var i = 0; i < obj.length; i++) {
			obj[i].style.display = "none";
		}
	} catch (e) {}
}

function hideObjAll(id) {
	try {
		hideObjectAll(obj(id));
	} catch (e) {}
}

//显示对象
function showObject(obj) {
	try {
		if (obj == null)
			return;
		obj.style.display = "";
	} catch (e) {}
}

function showObj(id) {
	try {
		showObject(obj(id));
	} catch (e) {}
}

function showObjectAll(obj) {
	try {
		if (obj == null)
			return;
		else if (obj.length == null) {
			obj.style.display = "";
		}
		else for (var i = 0; i < obj.length; i++) {
			obj[i].style.display = "";
		}
	} catch (e) {}
}

function showObjAll(id) {
	try {
		showObjectAll(obj(id));
	} catch (e) {}
}

//禁用对象
function disableObject(obj) {
	try {
		if (obj == null)
			return;
		obj.disabled = true;
	} catch (e) {}
}

function disableObj(id) {
	try {
		disableObject(obj(id));
	} catch (e) {}
}

function disableObjectAll(obj) {
	try {
		if (obj == null)
			return;
		else if (obj.length == null) {
			obj.disabled = true;
		}
		else for (var i = 0; i < obj.length; i++) {
			obj[i].disabled = true;
		}
	} catch (e) {}
}

function disableObjAll(id) {
	try {
		disableObjectAll(obj(id));
	} catch (e) {}
}

//启用对象
function enableObject(obj) {
	try {
		if (obj == null)
			return;
		obj.disabled = false;
	} catch (e) {}
}

function enableObj(id) {
	try {
		enableObject(obj(id));
	} catch (e) {}
}

function enableObjectAll(obj) {
	try {
		if (obj == null)
			return;
		else if (obj.length == null) {
			obj.disabled = false;
		}
		else for (var i = 0; i < obj.length; i++) {
			obj[i].disabled = false;
		}
	} catch (e) {}
}

function enableObjAll(id) {
	try {
		enableObjectAll(obj(id));
	} catch (e) {}
}

//隐藏元素
function hideElement(elmID) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		obj.style.display = "none";
	}
	for (f = 0; f < frames.length; f++){
		for (i = 0; i < frames[f].document.all.tags(elmID).length; i++) {
			obj = frames[f].document.all.tags(elmID)[i];
			obj.style.display = "none";
		}
	}
}

//显示元素
function showElement(elmID) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		obj.style.display = "";
	}
	for (f = 0; f < frames.length; f++){
		for (i = 0; i < frames[f].document.all.tags(elmID).length; i++) {
			obj = frames[f].document.all.tags(elmID)[i];
			obj.style.display = "";
		}
	}
}

//禁用元素
function disableElement(elmID) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		obj.disabled = true;
	}
	for (f = 0; f < frames.length; f++){
		for (i = 0; i < frames[f].document.all.tags(elmID).length; i++) {
			obj = frames[f].document.all.tags(elmID)[i];
			if (obj.type != "hidden") {
				obj.disabled = true;
			}
		}
	}
}

//禁用表单元素
function disableFormElements() {
	disableElement("INPUT");
	disableElement("SELECT");
  disableElement("TEXTAREA");
}

//启用元素
function enableElement(elmID) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		obj.disabled = false;
	}
	for (f = 0; f < frames.length; f++){
		for (i = 0; i < frames[f].document.all.tags(elmID).length; i++) {
			obj = frames[f].document.all.tags(elmID)[i];
			obj.disabled = false;
		}
	}
}

//获取随机数
function getRandom(len) {
	if (len > 16)
		len = 16;
	var temp = "" + Math.random();
	return temp.substr(2,len);
}

function random(len) {
	return getRandom(len);
}

//获取随机窗口名称
function getWinName(pre) {
	return (pre==null?"":pre) + getRandom().toString().substr(2,10);
}

//获取日期字符串
function getDat(day) {
	if (day == null)
		day = new Date();
	var year = day.getYear();
	var month = day.getMonth() + 1;
	var date = day.getDate();
	return year + "年" + month + "月" + date + "日";
}

//获取星期字符串
function getWeek(day) {
	if (day == null)
		day = (new Date()).getDay();
	if (day == 0)
		return "星期日";
	else if (day == 1)
		return "星期一";
	else if (day == 2)
		return "星期二";
	else if (day == 3)
		return "星期三";
	else if (day == 4)
		return "星期四";
	else if (day == 5)
		return "星期五";
	else if (day == 6)
		return "星期六";
}

//显示日期+星期
function showDate(day) {
	document.write(getDat(day) + " " + getWeek(day));
}

//获取问候语
function getGreeting(name) {
	var greeting = "";
	var d = new Date();
	var hour = d.getHours();
	if (hour < 6)
	  greeting = "凌晨好! " + name;
	else if (hour < 9)
	  greeting = "早上好! " + name;
	else if (hour < 12)
	  greeting = "上午好! " + name;
	else if (hour < 14)
	  greeting = "中午好! " + name;
	else if (hour < 17)
	  greeting = "下午好! " + name;
	else if (hour < 19)
	  greeting = "傍晚好! " + name;
	else if (hour < 22)
	  greeting = "晚上好! " + name;
	else
	  greeting = "夜里好! " + name;
	return greeting;
}

//显示问候语
function showGreeting(name) {
	document.write(getGreeting(name));
}

//显示分割线
var imgLine = "line_blue.gif";
function showLine() {
	document.write('<table width="100%" height="1" border="0" cellspacing="0" cellpadding="0"><tr><td background="../../images/' + imgLine + '"></td></tr></table>');
}

var clrLine = "#cccccc";
function showLineSolid() {
	document.write('<table width="100%" height="1" border="0" cellspacing="0" cellpadding="0"><tr><td bgcolor="' + clrLine + '"></td></tr></table>');
}

//显示渐变进度条
function showProcessing() {
	var elt = "0123456789ABCDEF";
	var shn = 0x66;
	var	sHtmlS = "";
	var	sHtmlE = "";
	for (var i = 0; i < 0xFF-0x99; i++) {
		var	cr = "";
		var	l;
		var	sHtml = "";
		l = i + shn;
		for (var j = 0; j < 2; j++) {
			var n = l % 16;
			l = l >> 4;
			cr = elt.charAt(n) + cr;
		}
		l = i + shn;
		for (var j = 0; j < 2; j++) {
			var n = l % 16;
			l = l >> 4;
			cr = elt.charAt(n) + cr;
		}
		l = i;
		for (var j = 0; j < 2; j++) {
			var	n = l % 16;
			l = l >> 4;
			cr = elt.charAt(n) + cr;
		}
		var	w = i > (0xFF - 0xA0) ? 8 : 4;
		sHtml = "<span style='height:4;width:" + w + ";background-color:#" + cr + ";margin:0;padding:0'></span>";
		sHtmlS += sHtml;
		sHtmlE = sHtml + sHtmlE;
	}
	var	sHtml = sHtmlS + sHtmlE;
	document.write("<marquee id='loading' scrollamount='30' direction='right' scrolldelay='1' height='4' style='width:100%;height:4; font-size:6px;background-color:#003399'>");
	document.write(sHtml);
	document.write("</marquee>");
}

//显示授权
function showGrant() {
	if (mainWin.grantName == "") mainWin.grantName = "未指定用户";
	if (mainWin.grantor == "1") {
		document.write("<font color='#ff0000'>您已授权给 " + mainWin.grantName + "</font><br>");
	}
	if (mainWin.grantee == "1") {
		document.write("<font color='#009966'>您已被 " + mainWin.grantName + " 授权</font><br>");
	}
}

//设置滚动条颜色
function scrollBar(face, track, border) {
	if (border == null) border = "#999999";
	if (track == null) track = clrBgList;
	if (face == null) face = clrBgView;
	try {
	document.body.style.scrollbarFaceColor = face;
	document.body.style.scrollbarTrackColor = track;
	document.body.style.scrollbarHighlightColor = border;
	document.body.style.scrollbarShadowColor = border;
	document.body.style.scrollbar3dLightColor = track;
	document.body.style.scrollbarDarkShadowColor = track;
	document.body.style.scrollbarArrowColor = "#333333";
	}catch(e){}
}

//页面置顶
function scrollTop() {
	parent.scrollTo(0,0);
}

//调整页面大小
function resize(rc) {
	if (window.name == "main") {
		parent.mainResize();
	}
	else {
		parent.iframeResize(window.name,rc==null?true:rc);
	}
}

//调整主框架大小
function mainResize() {
try {
	var oMainFrame = document.all.main;
	var oTaskFrame = document.all.taskbar;
	nMainHeight = main.document.body.scrollHeight;
	var nActualHeight = nMainHeight;
	if (nMainHeight <= nMainFrameHeight && nTaskHeight <= nTaskBarHeight) {
		nActualHeight = nMainFrameHeight;
	}
	else if (nMainHeight < nTaskHeight - nSpanHeight) {
		nActualHeight = nTaskHeight - nSpanHeight;
	}
	else {
		nActualHeight = nMainHeight;
	}
	oMainFrame.style.height = nActualHeight;
	oTaskFrame.style.height = nActualHeight + nSpanHeight;
}catch(e){}
}

//调整任务栏大小
function taskbarResize(height) {
try {
	var oMainFrame = document.all.main;
	var oTaskFrame = document.all.taskbar;
	nTaskHeight = taskbar.document.body.scrollHeight;
	if (height != null) {
		nTaskHeight = height;
	}
	var nActualHeight = nTaskHeight;
	if (nMainHeight <= nMainFrameHeight && nTaskHeight <= nTaskBarHeight) {
		nActualHeight = nTaskBarHeight;
	}
	else if (nTaskHeight - nSpanHeight < nMainHeight) {
		nActualHeight = nMainHeight + nSpanHeight;
	}
	else {
		nActualHeight = nTaskHeight;
	}
	oMainFrame.style.height = nActualHeight - nSpanHeight;
	oTaskFrame.style.height = nActualHeight;
}catch(e){}
}

//调整iframe页面大小
function iframeResize(frameName,rc) {
var oFrame;
try {
	eval("oFrame = document.all." + frameName);
	if (oFrame) {
		if (document.frames[frameName].document.all.tableFrame) {
			oFrame.style.height = document.frames[frameName].document.all.tableFrame.scrollHeight;
		}
		else {
			if (document.frames[frameName].document.body.scroll == "auto") {
				oFrame.style.height += document.frames[frameName].document.body.scrollHeight + 20;
			}
			else {
				oFrame.style.height = document.frames[frameName].document.body.scrollHeight;
			}
		}
	}
	if (rc && parent != window) {
		resize();
		/*if (parent != mainWin) {
			resize();
		}
		else {
			resize();
		}*/
	}
}catch(e){}
}

//页面重定向
function locate(win, url) {
	win.location.href = url;
}

//切换标签
function changeLabel(i, todo) {
	if (labelId == i)
		return;
	document.all.item("label" + labelId).className = "label";
	document.all.item("label" + i).className = "labela";
	labelId = i;
	if (todo != null) {
		//try {
			eval(todo);
		//} catch (e) {}
	}
}

//换行选择改变背景色
function changeRow(i, edit) {
	if (listId >= 0)
		eval("document.all.tr" + listId + ".style.backgroundColor=''");
	if (edit == 1) {
		eval("document.all.tr" + i + ".style.backgroundColor = '" + clrListEditable + "'");
	}
	else if (edit == 0) {
		eval("document.all.tr" + i + ".style.backgroundColor = '" + clrListViewable + "'");
	}
	else if (edit == -1) {
		eval("document.all.tr" + i + ".style.backgroundColor = '" + clrListNoright + "'");
	}
	else {
		eval("document.all.tr" + i + ".style.backgroundColor = '" + clrListOver + "'");
	}
	eval("document.all.id" + i + ".checked = true");
	listId = i;
}

function changeRowSp(i) {
	if (listId >= 0) {
		eval("document.all.tr" + listId + ".style.backgroundColor = ''");
	}
	eval("document.all.tr" + i + ".style.backgroundColor = '" + clrListOver + "'");
	listId = i;
}

function changeRowBg(i, bChecked, sRowName) {
	if (sRowName != null) {
		eval("var objRow = document.all." + sRowName + i);
	}
	else {
		eval("var objRow = document.all.tr" + i);
	}
	if (bChecked) {
		objRow.style.backgroundColor = clrListOver;
	}
	else {
		objRow.style.backgroundColor = "";
	}	
}

//多行选择改变背景色
function checkRow(i) {
	eval("var tr = document.all.tr" + i);
	eval("var id = document.all.id" + i);
	if(id.checked) {
		tr.style.backgroundColor = "";
		id.checked = false;
	}
	else {
		tr.style.backgroundColor = clrListOver;
		id.checked = true;
	}
	listId = i;
}

//单选或多选行改变背景色
function selectRow(i) {
	if (listId < 0) {
		listId = new List();
	}
	var tr = document.all.item("tr" + i);
	var id = document.all.item("id" + i);
	if (event.ctrlKey) {
		if(id.checked) {
			tr.style.backgroundColor = "";
			id.checked = false;
		}
		else {
			tr.style.backgroundColor = clrListOver;
			id.checked = true;
		}
	}
	else if (event.shiftKey) {
		if (listId.size() > 0) {
			var lastId = listId.get(listId.size() - 1);
			for (var j = 0; j < listId.size() - 1; j++) {
				document.all.item("tr" + listId.get(j)).style.backgroundColor = "";
				document.all.item("id" + listId.get(j)).checked = false;
			}
			var maxId = i > lastId ? i : lastId;
			var minId = i < lastId ? i : lastId;
			listId = new List();
			listId.add(i);
			for (var j = minId + 1; j < maxId; j++) {
				document.all.item("tr" + j).style.backgroundColor = clrListOver;
				document.all.item("id" + j).checked = true;
				listId.add(j);
			}
			i = lastId;
		}
		tr.style.backgroundColor = clrListOver;
		id.checked = true;
	}
	else {
		if (listId.size() > 0) {
			for (var j = 0; j < listId.size(); j++) {
				document.all.item("tr" + listId.get(j)).style.backgroundColor = "";
				document.all.item("id" + listId.get(j)).checked = false;
			}
			listId = new List();
		}
		tr.style.backgroundColor = clrListOver;
		id.checked = true;
	}
	listId.add(i);
}

//检查列表是否被选择
function checkList(list) {
	var bCheck = false;
	if (list == null) {
		return false;
	}
	if (list.length == null) {
		if (list.checked)
			return true;
	}
	else {
		for (i = 0; i < list.length; i++) {
			if (list[i].checked) {
				return true;
			}
		}
	}
	return bCheck;
}

function clickFirst(obj) {
	try {
		if (obj == null) obj = event.srcElement;
		obj.firstChild.click();
	} catch (e) {}
}

function clickRow(obj) {
	try {
		if (obj == null) obj = event.srcElement;
		obj.firstChild.firstChild.click();
	} catch (e) {}
}

//获取单选列表键值
function getListValue(list) {
	if (list == null) {
		return;
	}
	if (list.length == null) {
		if (list.checked)
			return list.value;
	}
	else {
		for (i = 0; i < list.length; i++) {
			if (list[i].checked) {
				return list[i].value;
			}
		}
	}
	return "";
}

//获取多选列表值
function getCheckValue(list) {
	if (list == null) {
		return;
	}
	if (list.length == null) {
		if (list.checked)
			return list.value;
	}
	else {
		var aValue = new Array();
		var j = 0;
		for (i = 0; i < list.length; i++) {
			if (list[i].checked) {
				aValue[j++] = list[i].value
			}
		}
		return aValue;
	}
}

//复选框全选
function checkAll(objCheck, bChangeBg, sRowName) {
	if (objCheck == null) {
		return;
	}
	try {
		var bChecked = false;
		var objSrc = event.srcElement;
		if (objSrc.checked) {
			bChecked = true;
		}
		if (objCheck.length == null) {
			objCheck.checked = bChecked;
			if (bChangeBg) {
				changeRowBg(0, bChecked, sRowName);
			}
		}
		else {
			for (i = 0; i < objCheck.length; i++) {
				objCheck[i].checked = bChecked;
				if (bChangeBg) {
					changeRowBg(i, bChecked, sRowName);
				}
			}
		}
	} catch (e) {}
}

//复选框取消全选
function uncheckAll(objCheckAll) {
	if (objCheckAll == null) {
		return;
	}
	try {
		var objSrc = event.srcElement;
		if (!objSrc.checked) {
			objCheckAll.checked = false;
		}
	} catch (e) {}
}

//鼠标移上改变颜色
function mouseOver(obj, i) {
	if (obj == null) obj = event.srcElement;
	if (i == null) {
		obj.style.backgroundColor = clrListOver;
	}
	else if (i == 0) {
		obj.style.backgroundColor = clrListOver;
	}
	else if (i == 1) {
		obj.style.color = clrFontOver;
	}
}

//鼠标移出改变颜色
function mouseOut(obj, i) {
	if (obj == null) obj = event.srcElement;
	if (i == null) {
		obj.style.backgroundColor = clrListOut;
	}
	else if (i == 0) {
		obj.style.backgroundColor = clrListOut;
	}
	else if (i == 1) {
		obj.style.color = clrFontOut;
	}
}

//鼠标移上改变风格
function mouseOverEx(obj) {
	if (obj == null) obj = event.srcElement;
	obj.style.backgroundColor = "#666666";
	obj.firstChild.firstChild.firstChild.style.backgroundColor = "#efef99";
}

//鼠标移出改变风格
function mouseOutEx(obj) {
	if (obj == null) obj = event.srcElement;
	obj.style.backgroundColor = "";
	obj.firstChild.firstChild.firstChild.style.backgroundColor = "";
}

//鼠标选中改变风格
var selectTable;
function mouseSelect(obj) {
	if (obj == null) obj = event.srcElement;
	if (selectTable != null) {
		selectTable.bgColor = "";
		selectTable.firstChild.firstChild.firstChild.bgColor = "";
	}
	obj.bgColor = "#666666";
	obj.firstChild.firstChild.firstChild.bgColor = "#eeeeee";
	selectTable = obj;
}

//转换成货币格式
function toMoney(money) {
	if (money == 0)
		return "0.00";
	money = String(money);
	var i = money.indexOf('.');
	if (i == -1) {
		money += ".00";
		return money;
	}
	if (money.length >= i+3)
		money = money.substring(0,i+3);
	else {
		money = money.substring(0,money.length);
		money += "0";		
	}
	return money;
}

//获取字符串字节长度
function getStrLen(str){
	var len = 0;
	if (str + "" == "undefined" || str == null) {
		len = 0;
	}
	else if (str.length == 0) {
		len = 0;
	}
	var i;
	for (i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) > 128) {
			len = len + 2;
		}
		else {
			len = len + 1;
		}
	}
	return len;
}

//去除字符串前后空格
function trim(str){
	if (str + "" == "undefined" || str == null) {
		return "";
	}
	else if (str.length == 0) {
		return "";
	}
    var i = 0;
    while(str.charAt(i) == ' ') {
    	i++;
        if (i >= str.length) {
        	break;
        }
    }
	var j = str.length - 1;
    while(str.charAt(j) == ' ') {
    	j--;
        if (j < 0) {
        	break;
        }
   	}
    return str.substring(i, j + 1);
}

//Sql语句过滤
function filtSql(str) {
	str = str.replace(/'/g, "''");
	return str;
}

//在表格末尾添加一行
function addRow(objTable, cells, className, idName, colspan, width) {
	if (objTable == null || cells == null)
		return;
	var objTr;
	var objTd;
	try {
		objTr = objTable.insertRow();
		if (className != null)
			objTr.className = className;
		if (idName != null)
			objTr.id = idName;
		for (var i = 0; i < cells.length; i++) {
			objTd = objTr.insertCell();
			objTd.innerHTML = String(cells[i]);
			if (colspan != null)
				objTd.colSpan = colspan;
			if (width != null && width.length > i)
				objTd.style.width = width[i];
		}
		if (opener == null) resize();
	} catch (e) {}
}

//在表格中间添加一行
function insertRow(srcTr, cells, sWhere, className, idName, colspan, width) {
	if (srcTr == null || cells == null)
		return;
	var objTr;
	var objTd;
	try {
		if (sWhere == null)
			sWhere = "AfterEnd";
		objTr = document.createElement("TR");
		objTr = srcTr.insertAdjacentElement(sWhere, objTr);
		if (className != null)
			objTr.className = className;
		if (idName != null)
			objTr.id = idName;
		for (var i = 0; i < cells.length; i++) {
			objTd = objTr.insertCell();
			objTd.innerHTML = String(cells[i]);
			if (colspan != null)
				objTd.colSpan = colspan;
			if (width != null && width.length > i)
				objTd.style.width = width[i];
		}
		if (opener == null) resize();
	} catch (e) {}
}

//在某行前添加一行
function insertRowBefore(srcTr, cells, className, idName, colspan, width) {
	insertRow(srcTr, cells , "BeforeBegin", className, idName, colspan, width);
}

//在某行后添加一行
function insertRowAfter(srcTr, cells, className, idName, colspan, width) {
	insertRow(srcTr, cells , "AfterEnd", className, idName, colspan, width);
}

//删除表格中的一行
/*function deleteRow(srcTr, msg) {
	if (msg != null)
		if(!confirmWin(msg))
			return;
	try {
		srcTr.removeNode(true);
		if (opener == null) resize();
	} catch (e) {}
}*/
function deleteRow(srcTr, msg, rs) {
	if (srcTr == null)
		return;
	if (msg != null)
		if(!confirmWin(msg))
			return;
	if (rs == null)
		rs = false;
	try {
		if (srcTr.length == null) {
			srcTr.removeNode(true);
		}
		else {			
			for (var i = srcTr.length - 1; i >= 0; i--) {
				srcTr[i].removeNode(true);
			}
		}
		if (rs && opener == null) resize();
	} catch (e) {
 	 	processException(e);
	}
}

function deleteRowByChild(obj, msg, rs) {
	try {
		deleteRow(obj.parentElement.parentElement, msg, rs);
	} catch (e) {
 	 	processException(e);
	}
}

//打开新窗口
function openWin(url,target,width,height,prop) {
	if (url == null || url == "")
		url = portalPrefix + "/default.jsp";
	if (target == null || target == "")
		target = "_blank";
	if (width == null)
		width = 780;
	if (height == null)
		height = 480;
	if (prop == null)
		prop = ",scrollbars=no,resizable=yes";
	var top = 10;
	var left = (screen.availWidth - width - 20);
	var newWin = window.open(url,target,"width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",statusbar=no,toolbar=no" + prop);
	newWin.focus();
	//return newWin;
}

//打开新完整窗口
function openFullWin(url,target,width,height,prop) {
	if (url == null || url == "")
		url = portalPrefix + "/default.jsp";
	if (target == null || target == "")
		target = "_blank";
	if (width == null)
		width = 780;
	if (height == null)
		height = 480;
	if (prop == null)
		prop = ",scrollbars=yes,resizable=yes";
	var newWin = window.open(url,target,"width=" + width + ",height=" + height + ",left=" + (screen.width-width)/2 + ",top=" + (screen.height-height)/2 + ",statusbar=yes,toolbar=yes" + prop);
	newWin.focus();
	//return newWin;
}

//打开新小窗口
function openLiteWin(url,target) {
	return openWin(url,target,300,150,",scrollbars=yes,resizable=no");
}

//打开新模式对话框
function openModalWin(url,arg,width,height) {
	if (url == null || url == "")
		url = portalPrefix + "/default.jsp";
	if (arg == null || arg == "")
		arg = window;
	if (width == null)
		width = 400;
	if (height == null)
		height = 300;
	var rt = window.showModalDialog(url,arg,"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;edge:raised;resizable:no;scroll:no;status:no;");
	return rt;
}

//打开新无模式对话框
function openModelessWin(url,arg,width,height) {
	if (url == null || url == "")
		url = portalPrefix + "/default.jsp";
	if (arg == null || arg == "")
		arg = window;
	if (width == null)
		width = 400;
	if (height == null)
		height = 300;
	var rt = window.showModelessDialog(url,arg,"dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;help:no;edge:raised;resizable:no;scroll:no;status:no;");
	return rt;
}

//打开密码对话框
function openWinPassword() {
	return openModalWin(pagePrefix + "common/password.jsp","",300,150);
}

//打开文件传输对话框
function openWinTransmission() {
	return openModelessWin(pagePrefix + "common/transmission.jsp","",300,150);
}

//打开警告对话框
function alertWin(s) {
	openModalWin(pagePrefix + "common/alert.htm", s, 300, 150);
}

//打开确认对话框
function confirmWin(s) {
	if (!openModalWin(pagePrefix + "common/confirm.htm", s, 300, 150)) return false;
	return true;
}

//关闭弹出窗口
function closeWin() {
	try {
		if (!winHandler.closed)
			winHandler.close();
	} catch (e) {}
}

//使页面能编辑
function enEdit() {
	mainWin.bEditable = true;
}

//使页面不能编辑
function unEdit() {
	mainWin.bEditable = false;
}

//窗口打印
function doPrint() {
	window.print();
}

//打印之前动作
function doBeforePrint(obj) {
	if (obj == null) {
		return;
	}
	else if (obj.length == null) {
		obj.style.display = "none";
	}
	else {
		for (i = 0; i < obj.length; i++) {
			obj[i].style.display = "none";
		}
	}
}

//打印之后动作
function doAfterPrint(obj) {
	if (obj == null) {
		return;
	}
	else if (obj.length == null) {
		obj.style.display = "";
	}
	else {
		for (i = 0; i < obj.length; i++) {
			obj[i].style.display = "";
		}
	}
}

//聚焦对象
function doFocus(obj) {
	obj.focus();
}

//选中对象
function doSelect(obj) {
	obj.select();
}

//失焦对象
function doBlur(obj) {
	obj.blur();
}

//关闭窗口
function doClose() {
	window.close();
}

function addFavorite(title, url) {
	if (title == null)
		title = "";
	if (url == null) {
		url = "http://" + window.location.host + window.location.pathname + window.location.search;
	}
	window.external.addFavorite(url, title);
}

//获取列表文字
function selectText(selectObj) {
	return selectObj.options[selectObj.selectedIndex].text;
}

//获取列表值
function selectValue(selectObj) {
	return selectObj.options[selectObj.selectedIndex].value;
}

//获取多个列表值
function selectValueMulti(selectObjs) {
	var aValue = new Array(selectObjs.length);
	for (var i = 0; i < selectObjs.length; i++) {
		aValue[i] = selectObjs[i].options[selectObjs[i].selectedIndex].value;
	}
	return aValue;
}

//获取多选列表值
function getMultiValue(multiObj, bSelected) {
	if (multiObj == null)
		return;
	if (bSelected == null)
		bSelected = false;
	var sValue = "";
	if (multiObj.options.length == 1) {
		return multiObj.options[0].value;
	}
	else if (multiObj.options.length > 1) {
		for (var i = 0; i < multiObj.options.length - 1; i++) {
			if (!bSelected || (bSelected && multiObj.options[i].selected)) {
				sValue += multiObj.options[i].value + ",";
			}
		}
		if (!bSelected || (bSelected && multiObj.options[multiObj.options.length - 1].selected)) {
			sValue += multiObj.options[multiObj.options.length - 1].value;
		}
	}
	return sValue;
}

function getMultiValueSelected(multiObj, bSelected) {
	return getMultiValue(multiObj, true);
}

//添加多选列表项
function multiAdd(multiObj, text, value, defaultValue, exceptValue, exceptMsg) {
	if (multiObj == null)
		return;
	if (value == null)
		value = text;
	if (defaultValue == null)
		defaultValue = "";
	if (value == defaultValue)
		return;
	for (var i = 0; i < multiObj.options.length; i++) {
		if (multiObj.options[i].value == value)
			return;
		if (exceptValue != null) {
			if (exceptValue.length == null) {
				if (multiObj.options[i].value == exceptValue) {
					if (exceptMsg != null) alert(exceptMsg);
					return;
				}
			}
			else {
				for (var j = 0; j < exceptValue.length; j++) {
					if (multiObj.options[i].value == exceptValue[j]) {
						if (exceptMsg != null) alert(exceptMsg);
						return;
					}
				}
			}
		}
	}
	multiObj.options.add(new Option(text, value));
}

//复制列表项
function multiCopy(multiObj, multiObjSrc) {
	if (multiObj == null || multiObjSrc == null)
		return;
	var bMatch = false;
	for (var i = 0; i < multiObjSrc.options.length; i++) {
		if (multiObjSrc.options[i].selected) {
			bMatch = false;
			for (var j = 0; j < multiObj.options.length; j++) {
				if (multiObj.options[j].value == multiObjSrc.options[i].value) {
					bMatch = true;
					break;
				}
			}
			if (!bMatch)
				multiObj.options.add(new Option(multiObjSrc.options[i].text, multiObjSrc.options[i].value));
		}
	}
}

//删除多选列表项
function multiRemove(multiObj, index) {
	if (multiObj == null)
		return;
	if (index == null) {
		for (var i = multiObj.options.length - 1; i >= 0; i--)
			if (multiObj.options[i].selected)
				multiObj.options.remove(i);
	}
	else if (index.length == null) {
		multiObj.options.remove(index);
	}
	else if (index.length > 0) {
		for (var i = index.length - 1; i >= 0; i++)
			if (multiObj.options[index[i]].selected)
				multiObj.options.remove(index[i]);
	}
}

//选中多选框所有项
function multiSelect(multiObj) {
	for (var i = 0; i < multiObj.options.length; i++)
		multiObj.options[i].selected = true;
}

//取消多选框所有项
function multiDeselect(multiObj) {
	for (var i = 0; i < multiObj.options.length; i++)
		multiObj.options[i].selected = false;
}

//在客户端写Cookie
function writeCookie(cookieName, cookieValue) {
	if (!chksave.checked) {
		return;
	}
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + 8640000000);
	document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString() + ";path=/";
}

function doKeyDown() {
	//快捷栏快捷键
	if (((event.ctrlKey) && (event.keyCode==192)) || (event.keyCode == 123)){ 
		mainWin.taskbar.document.all.taskbutton.click();
	}
	//屏蔽F5刷新键和Ctrl+R
	if ((event.keyCode==116) || (event.ctrlKey && event.keyCode==82)) {
		event.keyCode = 0;
		event.returnValue = false;
	}
	//屏蔽Ctrl+N
	if ((event.ctrlKey) && (event.keyCode==78)) {
		event.returnValue = false;
	}
	//屏蔽Shift+F10
	if ((event.shiftKey) && (event.keyCode==121)) {
		event.returnValue = false;
	}
	//event.returnvalue = false;
}

function doMouseDown() {
	if (event.button == 2 || event.button == 3) {
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

//屏蔽右键菜单
function doContextMenu() {
 	window.event.cancelBubble = true;
 	window.event.returnValue = false;
	return false;
}


/* 业务相关方法 */

userAgent = navigator.userAgent.toLowerCase();
n4 = document.layers;
ie = (document.all && userAgent.indexOf("mac")<0);
w3c = document.documentElement;
dhtml = ((n4 || ie || w3c) &&  userAgent.indexOf("aol")<0);

function hideElementByClass(elmID, className) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		if (obj.className == className) {
			obj.style.display = "none";
			break;
		}
	}
}

function hideElementById(elmID, idName) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		if (obj.id == idName) {
			obj.style.display = "none";
			break;
		}
	}
}

function showElementBySrc(elmID, srcName) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		if (obj.src.substring(obj.src.lastIndexOf("/") + 1) == srcName) {
			obj.style.display = "";
		}
	}
}

function showElementById(elmID, idName) {
	for (i = 0; i < document.all.tags(elmID).length; i++) {
		obj = document.all.tags(elmID)[i];
		if (obj.id == idName) {
			obj.style.display = "";
		}
	}
}

function forPrint() {
	hideElementByClass("TD", "related");
	hideElementById("DIV", "noprint");
	//hideElement("OBJECT");
	//hideElement("IMG");
	//document.all.logo.style.display = "";
	//showElementBySrc("IMG", "spacer.gif");
	//showElementBySrc("IMG", "dark.gif");
	//showElementBySrc("IMG", "gray.gif");
	//showElementBySrc("IMG", "white.gif");
	//showElementById("IMG", "reserve");
}

function loadImg(style) {
	if (document.images.item("pointb") == null)
		return;
	if (document.images.item("pointb").length == null) {
		
	}
	else for (var i = 0; i < document.images.item("pointb").length; i++) {
			document.images.item("pointb")[i].src = "../../images/point_" + style + "_b.gif";
	}
}

function Fahrer(name, id, x, y, w, h, delay) {
	this.name = name;
	this.x = x;
	this.y = y;
	this.w = w;
	this.h = h;
	this.posx = x;
	this.posy = y;
	if (this.w > this.x) {
		this.factorx = true;
	}
	else {
		this.factorx = false;
	}
	if (this.h > this.y) {
		this.factory = true;
	}
	else {
		this.factory = false;
	}
	this.stepx = (w - x) / 200;
	this.stepy = (h - y) / 200;
	this.el = n4? document.layers[id] : ie? document.all[id] : document.getElementById(id);
	this.css = n4? this.el : this.el.style;
	this.delay = delay;
	this.fahrt = Fahren;
	this.css.left = this.x;
	this.css.top = this.y;
}

function Fahren() {
	this.timer = setTimeout(this.name+".fahrt()", this.delay);
	if (((this.posx <= this.w) && this.factorx) || (!(this.posx <= this.w) && !this.factorx)){
		this.posx += this.stepx;
	}
	else {
		this.posx = this.x;
		if (this.x != this.w) {
			this.posy = this.y;
		}
	}

	if (((this.posy <= this.h) && this.factory) || (!(this.posy <= this.h) && !this.factory)) {
		this.posy += this.stepy;
	}
	else {
		this.posy = this.y;
		if (this.y != this.h) {
			this.posx = this.x;
		}
	}

	this.css.left = this.posx;
	this.css.top = this.posy;
}

function init() {
	if (!dhtml) return;
	fahrer1 = new Fahrer("fahrer1", "test1", 538, -50, 538, 500, 60);
	fahrer2 = new Fahrer("fahrer2", "test2", -27, 283, 950, 283, 55);
	fahrer3 = new Fahrer("fahrer3", "test3", 1030, 92, 0, 341, 70);
	fahrer4 = new Fahrer("fahrer4", "test4", 0, 340, 1030, 91, 75);

	setTimeout("fahrer1.fahrt()", 2000);
	setTimeout("fahrer2.fahrt()", 5000);
	setTimeout("fahrer3.fahrt()", 10000);
	setTimeout("fahrer4.fahrt()", 500);
}

//纯业务功能
function fade(id, clr) {
	var obj = document.all.item(id);
	obj.filters[0].apply();
	obj.style.color = clr;
	obj.filters[0].play();
}
