﻿// 变换表格色彩
function changetotd(highlightcolor){
source=event.srcElement
if (source.tagName=="TR"||source.tagName=="TABLE")
return
while(source.tagName!="TD")
source=source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function changebacktd(originalcolor){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
return
if (event.toElement!=source)
source.style.backgroundColor=originalcolor
}

function changetotr(highlightcolor){
source=event.srcElement
if (source.tagName=="TR"||source.tagName=="TABLE")
return
while(source.tagName!="TR")
source=source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}

function changebacktr(originalcolor){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
return
if (event.toElement!=source)
source.style.backgroundColor=originalcolor
}


//从菜单中打开链接
function OpenUrl(CurUrl,IsPopWin){
	if (CurUrl==""){
		history.back();
	}else{
		if (IsPopWin=="1"){
			OpenMenuWindow(CurUrl);
		}else{
			if (parent.mainFrame){
				parent.mainFrame.location.href=CurUrl;
			}else{
				location.href=CurUrl;
			}
		}
	}
}


//弹出窗口
//用法 MM_openBrWindow('xxx.htm','xxx','width=300,height=200')
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//弹出用于列表对话框
function MM_openCustSelectDiag(theURL,winName,features){
	var strValue = showModalDialog(theURL,window,"status:no;help:no;dialogHeight:330px;dialogWidth:510px");
	if(strValue.length > 0){
		cust_name = strValue.substring(0,strValue.indexOf("@@"));
		cust_no = strValue.substr(strValue.indexOf("@@")+2,8);
		document.all['cust_name'].value = cust_name;
		document.all['cust_no'].value = cust_no;
	}
}


//按钮提示确认
function tmt_confirm(msg){
 document.MM_returnValue=(confirm(unescape(msg)));
}


//选取所有
function checkall(form, prefix, checkall) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.elements[checkall].checked;
		}
	}
}


// 检测字数长度
function checklength(Form,Body,LenB,LenE) {
	var showmessage = LenE != 0 ? '系统限制: ' + LenB + ' 到 ' + LenE + ' 字节' : '';
	alert('\n当前长度: ' + document.all[Body].value.length + ' 字节\n\n' + showmessage);
}


//复制代码
function copyCode(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}


//运行代码
function runCode(obj) {
var winname = window.open('', "_blank", '');
winname.document.open('text/html', 'replace');
winname.document.writeln(obj.value);
winname.document.close();
}


//另存代码
function saveCode(obj) {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.writeln(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}

