// JavaScript Document

var AssetWindow;
var VulnWindow;
var AuthWindow;
var TopoWindow;
var SysWindow;
var DocWindow;
var WaitWindow;

function none(){return;}

function delCookie(name)
{
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var value = getCookie (name);
	document.cookie = name + "=" + value + "; expires="+ exp.toGMTString();
}

function getCookie(name)
{
	var array = document.cookie.split(";");
	for(var i=0;i<array.length;i++)
	{
		if(array[i].split("=")[0]==name)
		{
			return array[i].split("=")[1];
		}
	}
	return null;
}

function ShowWait()
{
	var oWin = window;
	while(oWin.frameElement != null)
	{
		oWin = oWin.parent;
	}

	if (WaitWindow && WaitWindow.open && !WaitWindow.closed)
		oWin.WaitWindow.focus();
	else
		oWin.WaitWindow = window.open('../wait.jsp','','resizable=no,width=300,height=160,top=' + (window.screen.height-160)/2 + ',left=' + (window.screen.width-300)/2);
}

function CloseWait()
{
	//alert('yes')
	var win = window;
	if (window.opener)
		win = window.opener;
	if (window.dialogArguments)
		win = window.dialogArguments[1];
	while (win != null)
	{
		WaitWindow = win.WaitWindow;
		if (WaitWindow && WaitWindow.open && !WaitWindow.closed)
			WaitWindow.close();
		if (win.frameElement == null)
			break;
		else
			win = win.parent;
	}
}

function openMainWindow(URL, winName)
{
	if (winName == 'AssetWindow')
	{
		if (AssetWindow && AssetWindow.open && !AssetWindow.closed)
			AssetWindow.focus();
		else
			AssetWindow = window.open(URL, '', 'status=yes,resizable=yes');
	}
	else if (winName == 'VulnWindow')
	{
		if (VulnWindow && VulnWindow.open && !VulnWindow.closed)
			VulnWindow.focus();
		else
			VulnWindow = window.open(URL, '', 'status=yes,resizable=yes');
	}
	else if (winName == 'AuthWindow')
	{
		if (AuthWindow && AuthWindow.open && !AuthWindow.closed)
			AuthWindow.focus();
		else
			AuthWindow = window.open(URL, '', 'status=yes,resizable=yes');
	}
	else if (winName == 'TopoWindow')
	{
		if (TopoWindow && TopoWindow.open && !TopoWindow.closed)
			TopoWindow.focus();
		else
			TopoWindow = window.open(URL, '', 'status=yes,resizable=yes');
	}
	else if (winName == 'SysWindow')
	{
		if (SysWindow && SysWindow.open && !SysWindow.closed)
			SysWindow.focus();
		else
			SysWindow = window.open(URL, '', 'status=yes,resizable=yes');
	}
	else if (winName == 'DocWindow')
	{
		if (DocWindow && DocWindow.open && !DocWindow.closed)
			DocWindow.focus();
		else
			DocWindow = window.open(URL, '', 'status=yes,resizable=yes');
	}
}

function openWindow(theURL,winName,features)
{
	var paramArr = features.split(",");
	var width;
	var height;
	for (var i = 0; i < paramArr.length; i++)
	{
		if (paramArr[i].indexOf("width=") > -1)
			width = paramArr[i].substr(paramArr[i].indexOf("width="));
		else if (paramArr[i].indexOf("height=") > -1)
			height = paramArr[i].substr(paramArr[i].indexOf("height="));
	}
	if (width != null && height != null)
	features += ",top=" + (window.screen.height-eval(height))/2 + ",left=" + (window.screen.width-eval(width))/2;
	window.open(theURL,winName,features);
}

//????????????
function showList(id, retItem)
{
	var features = "dialogWidth:400px;dialogHeight:320px;help=no;";
	var arg;

	arg = new Array(1);
	arg[0] = document.all.item(retItem);

	window.showModalDialog(id,arg,features);

}

function showVulnIndex(id, retItem)
{
	var features = "dialogWidth:800px;dialogHeight:600px;help=no;";
	var arg;

	arg = new Array(2);
	arg[0] = document.all.item(retItem);
	arg[1] = window;

	window.showModalDialog(id,arg,features);

}

function SelectVulnCode(E)
{
	while (E.tagName!="TR")
	{
		E=E.parentElement;
	}
	window.dialogArguments[0].value = E.children[0].innerText;
	window.close();
}

//????????????????????
function showPFList(selectURL, swapURL, retItem, toOption, dID)
{
	var features = "dialogWidth:400px;dialogHeight:320px;help=no;";
	var arg;

	arg = new Array(2);
	arg[0] = document.all.item(retItem);
	arg[1] = swapURL;

	var pfOptions = window.showModalDialog(selectURL,arg,features);

	//if (pfid == null)
		//return;

	//var pfOptions = window.showModalDialog(swapURL + '&id=' + pfid,null,features);
	if (pfOptions == null)
		return;
	var oOption = document.all.item(toOption);
	var count = 0;
	for (var i = 0; i < pfOptions.length; i++)
	{
		if (dID != null && dID == pfOptions[i].value)
		{
			count++;
			continue;
		}

		oOption.options[i] = new Option(pfOptions[i].text,pfOptions[i].value,false,false);
	}
	oOption.options.length = pfOptions.length - count;
	oOption.selectedIndex = 0;
}

function SwapOSPatch(swapURL, toOption, isSearch)
{
	var features = "dialogWidth:400px;dialogHeight:320px;help=no;";

	var osPatchOptions = window.showModalDialog(swapURL,null,features);

	if (osPatchOptions == null)
		return;

	var oOption = document.all.item(toOption);
	if (isSearch)
	{
		if (toOption == 'osPatch')
			oOption.options[0] = new Option("??????", 0, false, false);
		else
//			oOption.options[0] = new Option("????", 0, false, false);
//			oOption.options[0] = new Option("????", 0, false, false);
			oOption.options[0] = new Option("", -1, false, false);
		for (var i = 0; i < osPatchOptions.length; i++)
		{
			oOption.options[i+1] = new Option(osPatchOptions[i].text, osPatchOptions[i].value,false,false);
		}
		oOption.options.length = osPatchOptions.length + 1;
		oOption.selectedIndex = 0;
	}
	else
	{
		for (var i = 0; i < osPatchOptions.length; i++)
		{
			oOption.options[i] = new Option(osPatchOptions[i].text, osPatchOptions[i].value,false,false);
		}
		oOption.options.length = osPatchOptions.length;
		oOption.selectedIndex = -1;
	}
}

//??????????????????
function showAdjustWindow(id,form)
{
	if (eval(form).deviceID.type == 'checkbox')
	{
		if (eval(form).deviceID.checked)
		{
			var features = "dialogWidth:700px;dialogHeight:550px;help=no;";

			var args = new Array(1);
			args[0] = eval(form);

			window.showModalDialog(id,args,features);

			return;
		}
	}
	else
	{
		for (var i = 0; i < eval(form).deviceID.length; i++)
		{
			if (eval(form).deviceID[i].checked)
			{
				var features = "dialogWidth:700px;dialogHeight:550px;help=no;";

				var args = new Array(1);
				args[0] = eval(form);

				window.showModalDialog(id,args,features);

				return;
			}
		}
	}
	alert('????????????????????????!');
}

//??????????????????
function showVulnAdjust(id)
{
	var features = "dialogWidth:500px;dialogHeight:400px;help=no;";

	window.showModalDialog(id,null,features);

}

//to singly select business system
function SelectSingleBS(obj)
{
	var oSource = document.all.item(obj);
	if (oSource != null)
	{
		for (var j = 0; j < oSource.length; j++)
		{
			if (eval("oSource[" + j + "].checked") == true)
			{
				window.dialogArguments[0].value = oSource[j].parentNode.innerText;
				break;
			}
		}
	}

	window.close();
}

//????????????????
function SelectSinglePF(obj)
{
	var oSource = document.all.item(obj);
	if (oSource != null)
	{
		for (var j = 0; j < oSource.length; j++)
		{
			if (eval("oSource[" + j + "].checked") == true)
			{
				window.dialogArguments[0].value = oSource[j].id;
				//window.returnValue = oSource[j].value;
				window.open(window.dialogArguments[1] + "&id=" + oSource[j].value,"SinglePFList");
				return;
			}
		}
	}

	window.close();
}

//to multiply select business system
function SelectMultipleBS(obj)
{
	var oSelect = document.all.item(obj);
	var bsString = "";
	if ((!document.all.item('all') || !document.all.item('all').checked) && (oSelect.checked == true || oSelect.length > 0))
	{
		for (var i = 0; i < oSelect.length; i++)
		{
			if (oSelect[i].checked)
			{
				bsString = bsString + oSelect[i].parentNode.innerText + ",";
			}
		}
		if (bsString.length > 0)
			bsString = bsString.substring(0, bsString.length-1);
	}
	else
		bsString = document.all.item('all').parentNode.innerText;

	window.dialogArguments[0].value = bsString;

	window.close();
}

//Has been Deprecated
function BSystemOperation(target, form)
{
	form.submit();

	window.dialogArguments.location = target;

	window.close();
}

//????????????????????ID
function GetBranchID(form)
{
	var E = window.dialogArguments.document.all("selectedBranch");
	if (E == null)
	{
		alert("????????????????????????????????");
		window.close();
	}

	var oSource = document.all('ParentName');
	oSource.innerText += E.innerText;

	while(E.tagName != "IMG")
	{
		E = E.previousSibling;
	}
	form.id.value = E.id;
}

//Deprecated
//????????????
function adjustConfirm(type, form)
{
	//?IT????
	if (type == 'it')
	{
		window.dialogArguments[0].osType.value = form.osType.options[form.osType.selectedIndex].value;
		window.dialogArguments[0].osVersion.value = form.osVersion.value;
		window.dialogArguments[0].osPatch.value = form.osPatch.value;
		window.dialogArguments[0].func.value = form.func.value;
		window.dialogArguments[0].pos.value = form.pos.value;
		window.dialogArguments[0].org.value = form.org.value;
		window.dialogArguments[0].businessSys.value = form.businessSys.value;
		window.dialogArguments[0].proStructure.value = form.proStructure.value;
		window.dialogArguments[0].confi.value = form.confidentiality.options[form.confidentiality.selectedIndex].value;
		window.dialogArguments[0].inte.value = form.integrity.options[form.integrity.selectedIndex].value;
		window.dialogArguments[0].use.value = form.usability.options[form.usability.selectedIndex].value;
		window.dialogArguments[0].valuable.value = form.valuable.value;
	}
	//???????
	else
	{
		window.dialogArguments[0].storageMedia.value = form.storageMedia.options[form.storageMedia.selectedIndex].value;
		window.dialogArguments[0].storageType.value = form.storageType.options[form.storageType.selectedIndex].value;
		window.dialogArguments[0].backupType.value = form.backupType.options[form.backupType.selectedIndex].value;
		window.dialogArguments[0].backupCycle.value = form.backupCycle.options[form.backupCycle.selectedIndex].value;
		window.dialogArguments[0].func.value = form.func.value;
		window.dialogArguments[0].pos.value = form.pos.value;
		window.dialogArguments[0].org.value = form.org.value;
		window.dialogArguments[0].businessSys.value = form.businessSys.value;
		window.dialogArguments[0].proStructure.value = form.proStructure.value;
		for(var i = 0; i < form.checkbox.length; i++)
		{
			if (form.checkbox[i].checked)
			{
				window.dialogArguments[0].secret.value = form.checkbox[i].value;
				break;
			}
		}
		for(var i = 0; i < form.checkbox1.length; i++)
		{
			if (form.checkbox1[i].checked)
			{
				window.dialogArguments[0].integrity.value = form.checkbox1[i].value;
				break;
			}
		}
		for(var i = 0; i < form.checkbox2.length; i++)
		{
			if (form.checkbox2[i].checked)
			{
				window.dialogArguments[0].usable.value = form.checkbox2[i].value;
				break;
			}
		}
		window.dialogArguments[0].valuable.value = form.valuable.value;
	}

	window.dialogArguments[0].submit();

	window.close();
}

//replaced by the function SelectSingleBS()
function SelectSystem(id)
{
	var oSelect = document.all.item(id);
	if (oSelect.checked == true || oSelect.length > 0)
	{
		for (var i = 0; i < oSelect.length; i++)
		{
			if (oSelect[i].checked)
			{
				window.dialogArguments[0].value = window.dialogArguments[0].value + oSelect[i].value + ",";
			}
		}
		window.dialogArguments[0].value = window.dialogArguments[0].value.substring(0, window.dialogArguments[0].value.length-1);
	}

	window.close();
}

function ShowMoreInfo(id)
{
	var layername = eval(id);
	if (layername.style.display == 'none')
		layername.style.display = '';
	else
		layername.style.display = 'none';

	var oSource = window.event.srcElement;
	if (oSource == null)
		return;
	if (oSource.src.indexOf('down') > -1)
		oSource.src = oSource.src.replace('down', 'up');
	else
		oSource.src = oSource.src.replace('up', 'down');
}


//????????????
function ShowSubQuery(id,valueField)
{
	var oSource;

	oSource = window.event.srcElement;

	var layername=eval(id);

	if (oSource == null){
		if (layername.style.display=="none") {
			layername.style.display="";
		}
		else {
			layername.style.display="none";
		}
	} else {
		if (oSource.checked){
			layername.style.display="";
		} else {
			layername.style.display="none";
/*			if (valueField)
			{
				if ((typeof document.all.item(valueField).type) == "undefined")
				{
					for (var i = 0; i < document.all.item(valueField).length; i++)
					{
						if (document.all.item(valueField)[i].value == "0" || document.all.item(valueField)[i].value == "")
						{
							document.all.item(valueField)[i].checked = true;
							break;
						}
					}
				}
				else if (document.all.item(valueField).type == "select-one")
				{
					document.all.item(valueField).value = document.all.item(valueField).options[0].value;
				}
				else
					document.all.item(valueField).value = "";
			}*/
		}
	}
}

//??????????????????
function hL(E)
{
	while (E.tagName!="TR")
	{
		E=E.parentElement;
	}
	for (var i =0; i < E.children.length; i++)
		E.children[i].className="H";
}

//??????????????????????
function dL(E)
{
	while (E.tagName!="TR")
	{
		E=E.parentElement;
	}
	for (var i =0; i < E.children.length; i++)
		E.children[i].className="";
}

//????????
function resure(path,str,parent)
{
	var message = str;
	question = confirm(message)
	if (parent && question != "0")
	{
		window.open(path, 'IndexWindow');
		window.parent.close();
	}
	if (question !="0")
	{
		window.location=path
	}
}

//Deprecated
//????IP????
function AddListItem(from,to,forSelect)
{

	if (document.all.item(from).value == "" || document.all.item(from).value == null)
		return;

	for (var i = 0; i < to.options.length; i++)
	{
		if (document.all.item(from).value == to.options[i].value)
		{
			alert("already exist!");
			document.all.item(from).value = "";
			return;
		}
	}

    to.options[to.options.length]=new Option(document.all.item(from).value,document.all.item(from).value, false, false);
    forSelect.options[forSelect.options.length]=new Option(document.all.item(from).value,document.all.item(from).value, false, false);
	document.all.item(from).value="";
}

//????????????
function AddPatchInfo(from, to)
{
	var oFrom = document.all.item(from);
	var oTo = document.all.item(to);

	for (var i = 0; i < oTo.options.length; i++)
	{
		if (oTo.options[i].value == oFrom.options[oFrom.selectedIndex].value)
		{
			alert("????????????????");
			return;
		}
	}

	if (oFrom.selectedIndex != -1)
	{
		oTo.options[oTo.options.length] = new Option(oFrom.options[oFrom.selectedIndex].text, oFrom.options[oFrom.selectedIndex].value, false, false);
	}
}

//Deprecated
//????IP????
function DelListItem(to,forSelect)
{
   var oSelect = document.all.item(to);
   var oForSelect = document.all.item(forSelect);
   var index = oSelect.selectedIndex
   if (oSelect.selectedIndex != -1)
   {
	   oSelect.options[index]=null;
	   oForSelect.options[index]=null;
   }

}

//????????????
function DelPatchInfo(from)
{
	var oSource = document.all.item(from);
	if (oSource.selectedIndex != -1)
	{
		oSource.options[oSource.selectedIndex] = null;
	}
}

//??????????????????
function checkBoxValidate(cb,field) {
	var oSource = document.all.item(field);
	if (oSource != null)
	{
		for (var j = 0; j < oSource.length; j++)
		{
			if (eval("oSource[" + j + "].checked") == true)
			{
				oSource[j].checked = false;
				if (j == cb)
				{
					oSource[j].checked = true;
				}
			}
		}
	}
}

//????????????
function AddTopuLink(form, tableName)
{
	var oSource = document.all(tableName);
	if (form.upLinkDevice.options.length == 0)
		return;
	if (form.upLinkDevice.selectedIndex == -1)
	{
		alert("??????????????????");
		return;
	}
	if (form.linkType.value == 0)
	{
		alert("??????????????");
		return;
	}
	if (oSource != null)
	{
		var linkType = form.linkType.options[form.linkType.selectedIndex].text;
		var linkSpeed = form.linkSpeed.value;
		var uplinkName = form.upLinkDevice.options[form.upLinkDevice.selectedIndex].text;
		var linkSpeedType = form.linkSpeedType.options[form.linkSpeedType.selectedIndex].text;
		//var localPort = form.localPort.value;
		//var upPort = form.upLinkPort.value;
	}
	/*if (oSource.innerText.indexOf(uplinkName + linkType + linkSpeed) > -1 || oSource.innerText.indexOf(uplinkName + " " + linkType + " " + linkSpeed) > -1)
	{
		alert("????????????????????");
		return;
	}*/
	var linklist = document.all.item('deviceLink');
	if (linklist != null)
	{
		if (linklist.type == 'hidden')
		{
			if (linklist.value.indexOf(form.upLinkDevice.options[form.upLinkDevice.selectedIndex].value + ";") > -1)
			{
				alert("????????????????????");
				return;
			}
		}
		else
		{
			for (var i = 0; i < linklist.length; i ++)
			{
				if (linklist[i].value.indexOf(form.upLinkDevice.options[form.upLinkDevice.selectedIndex].value + ";") > -1)
				{
					alert("????????????????????");
					return;
				}
			}
		}
	}
	var showSpeed = (linkSpeed == "") ? "????" : linkSpeed + linkSpeedType;
	var insertHTML = "<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><tr bgcolor=\"#F0F6FF\" class=\"btn1\" width=\"100%\"><td width=\"40%\">" + uplinkName + "</td><td width=\"20%\">" + linkType + "</td><td width=\"20%\">" + showSpeed + "</td>";
	insertHTML += "<td width=\"10%\" align=\"center\"><img src=\"../images/editbutton.gif\" style=\"cursor:hand\" onClick=\"UpdateTopuLink(document.forms[0]," + form.upLinkDevice.options[form.upLinkDevice.selectedIndex].value + "," + form.linkType.options[form.linkType.selectedIndex].value + "," + linkSpeed * form.linkSpeedType.options[form.linkSpeedType.selectedIndex].value + ");DelTopuLink(this,true)\" alt=\"????????????\"></td><td width=\"10%\" align=\"center\"><img src=\"../images/delbutton.gif\" style=\"cursor:hand\" onClick=\"DelTopuLink(this)\" alt=\"????????????\"></td></tr>";
	insertHTML += "<input type=\"hidden\" name=\"deviceLink\" value=\"" + form.upLinkDevice.options[form.upLinkDevice.selectedIndex].value + ";" + form.linkType.options[form.linkType.selectedIndex].value + ";" + linkSpeed * form.linkSpeedType.options[form.linkSpeedType.selectedIndex].value + "\"></table>";
	oSource.insertAdjacentHTML("BeforeEnd", insertHTML);

	form.linkType.selectedIndex = 0;
	form.linkSpeed.value = "";
	form.linkSpeedType.selectedIndex = 0;
}

//????IP????????
function AddInterface(form, tableName)
{
	var oSource = document.all(tableName);

	if (form.inputIP.value == '')
		return;

	/*var val = form.inputIP.value;
	var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
	if (re.test(val))
	{
		val.match(re);
		if (!(RegExp.$1 >= 0 && RegExp.$1 <= 255
			  && RegExp.$2 >= 0 && RegExp.$2 <= 255
			  && RegExp.$3 >= 0 && RegExp.$3 <= 255
			  && RegExp.$4 >= 0 && RegExp.$4 <= 255))
		{
			alert("IP????????????");
			return;
		}
	}
	else
	{
		alert("IP????????????");
		return;
	}*/
	if (!checkIP(form.inputIP))
		return;

	if (form.interfaceType.value == 0)
	{
		alert("??????????????");
		return;
	}

	if (oSource != null)
	{
		var IPAddr = form.inputIP.value;
		var interfaceType = form.interfaceType.options[form.interfaceType.selectedIndex].text;
		var interfaceSpeed = form.interfaceSpeed.value;
		var interfaceSpeedType = form.interfaceSpeedType.options[form.interfaceSpeedType.selectedIndex].text;
	}
	var iplist = document.all.item('localIP');
	if (iplist != null)
	{
		if (iplist.type == "hidden")
		{
			if (iplist.value.indexOf(IPAddr + ";") > -1)
			{
				alert("??IP??????????????????");
				return;
			}
		}
		else
		{
			for (var i = 0; i < iplist.length; i++)
			{
				if (iplist[i].value.indexOf(IPAddr + ";") > -1)
				{
					alert("??IP??????????????????");
					return;
				}
			}
		}
	}
	var showSpeed = (interfaceSpeed == "") ? "????" : interfaceSpeed + interfaceSpeedType;
	var insertHTML = "<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><tr bgcolor=\"#F0F6FF\" class=\"btn1\" width=\"100%\"><td width=\"40%\">" + IPAddr + "</td><td width=\"20%\">" + interfaceType + "</td><td width=\"20%\">" + showSpeed + "</td>";
	insertHTML += "<td width=\"10%\"><img src=\"../images/editbutton.gif\" style=\"cursor:hand\" onClick=\"UpdateInterface(document.forms[0],'" + IPAddr + "'," + form.interfaceType.options[form.interfaceType.selectedIndex].value + "," + interfaceSpeed * form.interfaceSpeedType.options[form.interfaceSpeedType.selectedIndex].value + ");DelInterface(this,true)\" alt=\"????IP????????\"></td><td width=\"10%\"><img src=\"../images/delbutton.gif\" style=\"cursor:hand\" onClick=\"DelInterface(this)\" alt=\"????IP????????\"></td></tr>";
	insertHTML += "<input type=\"hidden\" name=\"localIP\" value=\"" + IPAddr + ";" + form.interfaceType.options[form.interfaceType.selectedIndex].value + ";" + interfaceSpeed * form.interfaceSpeedType.options[form.interfaceSpeedType.selectedIndex].value + "\"></table>";
	oSource.insertAdjacentHTML("BeforeEnd", insertHTML);

	form.inputIP.value = "";
	form.interfaceType.selectedIndex = 0;
	form.interfaceSpeed.value = "";
	form.interfaceSpeedType.selectedIndex = 0;
}
function checkIP(IPObj)
{
   matchStr = /^\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?$/;
   IPAddress = IPObj.value;

   if (IPAddress == "") return false;
   if (IPAddress.search(matchStr))
   {
      alert("IP??????????\n????????????????????????,/\-=+_?<>??????????????????????????");
      IPObj.select();
      IPObj.focus();
      return false;
   }
   strAry = IPAddress.split(".");
   ip1 = strAry[0]*1;
   ip2 = strAry[1]*1;
   ip3 = strAry[2]*1;
   ip4 = strAry[3]*1;
   if ((ip4 == 0) || (ip4 == 255))
   {
      alert("??????????????0??255");
      IPObj.select();
      IPObj.focus();
      return false;
   }
   if ((ip1>255)||(ip2>255)||(ip3>255)||(ip4>255))
   {
      alert("????????????????1-254");
      IPObj.select();
      IPObj.focus();
      return false;
   }
   if ((ip1==0) || (ip1 == 127) || (ip1 > 223))
   {
      alert("????????????IP??????IP");
      IPObj.select();
      IPObj.focus();
      return false;
   }
   if ((ip1 >= 1) && (ip1 <= 126))
   {
      if (((ip2==255) && (ip3==255) && (ip4==255)) || ((ip2==0) && (ip3==0) && (ip4==0)))
      {
         alert("A??????????????????????0????1??");
         IPObj.select();
         IPObj.focus();
         return false;
      }
   }
   if ((ip1 >= 128) && (ip1 <= 191))
   {
      if (((ip3==255) && (ip4==255)) || ((ip3==0) && (ip4==0)))
      {
         alert("B??????????????????????0????1??");
         IPObj.select();
         IPObj.focus();
         return false;
      }
   }
   if ((ip1 >= 192) && (ip1 <= 223))
   {
      if ((ip4==255) || (ip4==0))
      {
         alert("C??????????????????????0????1??");
         IPObj.select();
         IPObj.focus();
         return false;
      }
   }
   return true;
}

function AddOSType(form, tableName)
{
	var oSource = document.all(tableName);

	if (form.osType.selectedIndex == -1)
	{
		alert("????????????????????????");
		return;
	}

	if (oSource != null)
	{
		var osType = form.osType.options[form.osType.selectedIndex].text;
		var osDesc = form.osDesc.value;
	}
	var oslist = document.all.item('osid');
	if (oslist != null)
	{
		if (oslist.type == "hidden")
		{
			if (oslist.value.indexOf(form.osType.options[form.osType.selectedIndex].value + ";") > -1)
			{
				alert("??????????????????????");
				return;
			}
		}
		else
		{
			for (var i = 0; i < oslist.length; i++)
			{
				if (oslist[i].value.indexOf(form.osType.options[form.osType.selectedIndex].value + ";") > -1)
				{
					alert("??????????????????????");
					return;
				}
			}
		}
	}
	var insertHTML = "<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><tr bgcolor=\"#F0F6FF\" class=\"btn1\" width=\"100%\"><td width=\"30%\">" + osType + "</td><td width=\"60%\" style=\"word-wrap:break-word; word-break: break-all;\">" + osDesc + "</td>";
	insertHTML += "<td width=\"5%\"><img src=\"../images/editbutton.gif\" style=\"cursor:hand\" onClick=\"UpdateOSType(document.forms[0]," + form.osType.options[form.osType.selectedIndex].value + ",'" + osDesc + "');DelOSType(this,true)\" alt=\"????????????????\"></td><td width=\"5%\"><img src=\"../images/delbutton.gif\" style=\"cursor:hand\" onClick=\"DelOSType(this)\" alt=\"????????????????\"></td></tr>";
	insertHTML += "<input type=\"hidden\" name=\"osid\" value=\"" + form.osType.options[form.osType.selectedIndex].value + ";" + osDesc + "\"></table>";
	oSource.insertAdjacentHTML("BeforeEnd", insertHTML);

	form.osDesc.value = "";
	form.osType.selectedIndex = 0;
}

function UpdateTopuLink(form,devID,type,speed)
{
	form.upLinkDevice.value = devID;
	form.linkType.value = type;
	if (speed > 1000000)
	{
		form.linkSpeed.value = speed / 1000000;
		form.linkSpeedType.selectedIndex = 2;
	}
	else if (speed > 1000)
	{
		form.linkSpeed.value = speed /1000;
		form.linkSpeedType.selectedIndex = 1;
	}
	else if (speed != 0)
	{
		form.linkSpeed.value = speed;
		form.linkSpeedType.selectedIndex = 0;
	}
	else
	{
		form.linkSpeed.value = '';
		form.linkSpeedType.selectedIndex = 0;
	}
}

function UpdateInterface(form,ipAddr,type,speed)
{
	form.inputIP.value = ipAddr;
	form.interfaceType.value = type;
	if (speed > 1000000)
	{
		form.interfaceSpeed.value = speed / 1000000;
		form.interfaceSpeedType.selectedIndex = 2;
	}
	else if (speed > 1000)
	{
		form.interfaceSpeed.value = speed /1000;
		form.interfaceSpeedType.selectedIndex = 1;
	}
	else if (speed != 0)
	{
		form.interfaceSpeed.value = speed;
		form.interfaceSpeedType.selectedIndex = 0;
	}
	else
	{
		form.interfaceSpeed.value = '';
		form.interfaceSpeedType.selectedIndex = 0;
	}
}

function UpdateOSType(form,osID,Desc)
{
	form.osType.value = osID;
	form.osDesc.value = Desc;
}

//Deprecated
//??????????????????????
function EditTopuLink(tableName,localIP,localPort,uplinkName,upIP,upPort,uplinkID,upIPID,upPortID)
{
	var oSource = document.all(tableName);
	if (oSource == null)
		return;

	oSource.insertAdjacentHTML("BeforeEnd", "<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><tr bgcolor=\"#F0F6FF\" class=\"tablecontent\" width=\"100%\"><td width=\"20%\">" + localIP + "</td><td width=\"5%\">" + localPort + "</td><td width=\"20%\">" + uplinkName + "</td><td width=\"20%\">" + upIP + "</td><td width=\"5%\">" + upPort + "</td><td width=\"10%\" align=\"center\"><input type=\"button\" onClick=\"DelTopuLink(this)\" class=\"button\" value=\"????\"></td></tr><input type=\"hidden\" name=\"deviceLink\" value=\"" + localIP + ";" + localPort + ";" + uplinkID + ";" + upIPID + ";" + upPortID + "\"></table>");
}

//????????????
function DelTopuLink(str,quiet){
	if (!quiet)
	{
		question = confirm("????????????????????")
		if (question == "0")
		{
			return;
		}
	}

	while (str.parentNode.tagName != "TABLE")
		str = str.parentNode;
	str.removeNode(true);
}

//????IP????????
function DelInterface(str,quiet){
	if (!quiet)
	{
		question = confirm("??????????IP??????????????")
		if (question == "0")
		{
			return;
		}
	}

	while (str.parentNode.tagName != "TABLE")
		str = str.parentNode;
	str.removeNode(true);
}

function DelOSType(str,quiet){
	if (!quiet)
	{
		question = confirm("????????????????????????????")
		if (question == "0")
		{
			return;
		}
	}

	while (str.parentNode.tagName != "TABLE")
		str = str.parentNode;
	str.removeNode(true);
}

//????????????
function SwapBg1(E)
{
	if (E.tagName == "TD")
	{
	    if(E.background=="../images/button2.gif")
	  		E.style.background = "url(../images/button1.gif) no-repeat";

		if(E.background =="../images/buttonb.gif")
			E.style.background = "url(../images/buttona.gif) no-repeat";
    }
}

function SwapBg(E)
{}
function RestoreBg(E)
{}
//????????????
function RestoreBg1(E)
{
	if (E.tagName == "TD")
	{
		if( E.style.background =="url(../images/button1.gif) no-repeat")
			E.style.background = "url(../images/button2.gif) no-repeat";

		if(E.style.background =="url(../images/buttona.gif) no-repeat")
	    	E.style.background = "url(../images/buttonb.gif) no-repeat";
     }
}

function HighLightBg(E)
{
	var tds = document.getElementsByTagName("td");
	for(var j=0;j<tds.length;j++)
	{
		if(tds[j].background=="images/button2.gif"||tds[j].background=="images/button1.gif"||tds[j].background=="images/button3.gif")
	    	tds[j].style.background = "url(images/button2.gif) no-repeat";
	    if(tds[j].background=="images/buttonb.gif"||tds[j].background=="images/buttona.gif"||tds[j].background=="images/buttonc.gif")
	    	tds[j].style.background = "url(images/buttonb.gif) no-repeat";
	}
	if (E.tagName == "TD")
	{
	    if(E.background=="images/button2.gif"||E.background=="images/button1.gif")
	    	E.style.background = "url(images/button3.gif) no-repeat";

		if(E.background =="images/buttonb.gif"||E.background =="images/buttona.gif")
	    	E.style.background = "url(images/buttonc.gif) no-repeat";
    }
}

//Swap IP and Port select list when the up-link device has changed
function myOption(text,id,dID)
{
	this.text = text;
	this.id = id;
	this.dID = dID;
}
function SwapSubType(typeList,subTypeList)
{
	var oType = document.all.item(typeList);
	var oSub = document.all.item(subTypeList);
	var x = 0;

	for (var i = 0; i < oType.options.length; i++)
	{
		if (oType.options[i].value == '')
		{
			oSub.options[x++] = new Option('????', '', false, false);
			break;
		}
	}

	if (oType.options[oType.selectedIndex].value == '')
	{
		for (var i = 0; i < sTypeList.length; i++)
		{
			oSub.options[x++] = new Option(sTypeList[i].text, sTypeList[i].id, false, false);
		}
		oSub.options.length = x;
		return;
	}

	for (var i = 0; i < sTypeList.length; i++)
	{
		if (sTypeList[i].dID == oType.options[oType.selectedIndex].value)
			oSub.options[x++] = new Option(sTypeList[i].text, sTypeList[i].id, false, false);
	}
	oSub.options.length = x;
}
//Deprecated
function SwapIPPort(dID,IPfield,Portfield)
{
	var oDev = document.all.item(dID);
	var oIP = document.all.item(IPfield);
	var oPort = document.all.item(Portfield);
	var x = 0;
	for (var j = 0; j < uplinkIP.length; j++)
	{
		//alert(uplinkIP[j].value);
		if(uplinkIP[j].dID == oDev.options[oDev.selectedIndex].value)
			oIP.options[x++] = new Option(uplinkIP[j].text,uplinkIP[j].id,false,false);
	}
	oIP.options.length = x;

	x = 0;
	for (var k = 0; k < uplinkPort.length; k++)
	{
		if (uplinkPort[k].dID == oDev.options[oDev.selectedIndex].value)
			oPort.options[x++] = new Option(uplinkPort[k].text,uplinkPort[k].id,false,false);
	}
	oPort.options.length = x;

}

//????Form????????????List??????????????
function SelectSubmit(arg)
{
	var oSource = document.all.item(arg);
	if (oSource != null)
	{
		for (var i = 0; i < oSource.options.length; i++)
		{
			oSource.options[i].selected = true;
		}
		if(oSource.options.length == 0)
		{
			oSource.options[0] = new Option('', '', false, false);
			oSource.options[0].selected = true;
		}
	}

}

//??????????????
function next(form) {
	if ( eval(form.currentpage.value) >= eval(form.totalpages.value) )
	{
		form.currentpage.value = form.totalpages.value;
	}
	else
	{
		form.currentpage.value = ++form.currentpage.value;
	}
}

//??????????????
function previous(form) {
	if ( form.currentpage.value == 1 )
	{
		return false;
	}
	else if ( eval(form.currentpage.value) > eval(form.totalpages.value) )
	{
		form.currentpage.value = form.totalpages.value;
	}
	else
	{
		form.currentpage.value = --form.currentpage.value;
	}
}

//??????????????????????
function checkpage(form){
	if (form.currentpage.value == '')
		form.currentpage.value = 1;
	if (isNaN(form.currentpage.value))
		form.currentpage.value = 1;
	if ( eval(form.currentpage.value) >= eval(form.totalpages.value) )
	{
		form.currentpage.value = eval(form.totalpages.value);
	}
	if ( eval(form.currentpage.value) <= 0 )
	{
		form.currentpage.value = 1;
	}
}

//????????????
function ValidateUserForm(form, isClose)
{
	var errors = '';
	if (form.name.value == null || form.name.value == "")
		errors = errors + '\r\n??????????????????;';
	//if (form.passwd.value == null || form.passwd.value == "")
		//errors = errors + '\r\n????????????;';
	if (form.passwd.value != null && form.passwd.value != "" && form.passwd.value != form.repasswd.value)
		errors = errors + '\r\n??????????;';
	var val = form.name.value;
	var re = /\w+|\d+|_+/;
	if (!re.test(val))
		errors = errors + '\r\n????????????????????????????????';
	val = form.email.value;
	re = /\w+@\w+\.\w+/;
	if (!re.test(val))
		errors = errors + '\r\n????????????;';
	//if (val.indexOf('@') < 1 || val.indexOf('@') == (val.length-1) || val.indexOf('.') < 1 || val.indexOf('.') == (val.length-1))
	//	errors = errors + '\r\n????????????;';
	if (form.phone.value != "")
	{
		val = form.phone.value;
		re = /\d+-*\d+/;
		if (!re.test(val))
			errors = errors + '\r\n????????????;';
	}

	if (errors == '')
	{
		form.submit();
		//if (isClose == true)
		//	window.close();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

//????????????????????????????????????
function BSOperate(E)
{
	if (E.name.value == '')
	{
		alert("????????????????????");
		E.name.focus();
		return;
	}
	if (!checkUser(E.name))
		return;
	oSource = E.name.value + ',';
	if (bsname.indexOf(oSource) > -1)
	{
		alert("????????????????????????????????");
		E.name.focus();
		return;
	}
	if (E.description.value.length > 60)
	{
		alert("??????????????????????????60??????");
		E.description.focus();
		return;
	}

	E.submit();
	window.close();
}
function checkUser(UserObj){
	matchStr = /[\s\\\/\[\]:|<>+=;,\?\.*]/;
	user = UserObj.value;
	if (user.search(matchStr) != -1){
		alert("??????????????????????????????????\\ / | [ ] : + = , ? . *??????????");
		UserObj.select();
		UserObj.focus();
		return false;
	}
	return true;
}

function validateUploadForm(form,type)
{
	var head = "????????????????????????\r\n";
	var str = "";
	if(type != "update")
	{
		if(form.theFile.value == "")
		{
			str+="- ??????????????????????\r\n";
		}
		//if(form.indexSn.value == "")
		//{
		//	str+="- ????????????????\r\n";
		//}
	}
	if(form.author.value == "")
	{
		str+="- ????????????????\r\n";
	}
	if(form.publisher.value == "")
	{
		str+="- ????????????????\r\n";
	}

	if(str!="")
	{
		alert(head + str);
	}
	else
	{
		if(form.submitButton!=undefined)
		{
			form.submitButton.disabled = true;
		}
		form.submit();
	}
}

//????????????????????????????
function ReadDicTableForm(form,id,name,descrip,action,typeid)
{
	var oForm = document.all.item(form);
	oForm.id.value = id;
	oForm.name.value = name;
	if (oForm.description)
		oForm.description.value = descrip;
	oForm.action = action;
	if (typeid)
		oForm.typeid.value = typeid;
	if (oForm.RESET.disabled)
		oForm.RESET.disabled = false;
	oForm.OK.value = "????";
}

//????????????????????????????
function ReturnDicTableInsert(form,action)
{
	var oForm = document.all.item(form);
	oForm.id.value = '';
	oForm.name.value = '';
	if (oForm.description)
		oForm.description.value = '';
	oForm.action = action;
	if (oForm.typeid)
		oForm.typeid.selectedIndex = 0;
	oForm.RESET.disabled = true;
	oForm.OK.value = "????";
}

//??????????????????
function ReadSecForm(form,id,rate,critical,valuation)
{
	var oForm = document.all.item(form);
	oForm.id.value = id;
	oForm.rate.value = rate;
	oForm.bsCriticalLevel.value = critical;
	oForm.valuation.value = valuation;
	oForm.OK.disabled = false;
}

//??????????????????
function ClearValue(E,form)
{
	//oSource = document.all.item(E);
	oSource = form[E];
	if (oSource == null)
		return;

	if ((typeof oSource.type) == "undefined")
	{
		for (var i = 0; i < oSource.length; i++)
		{
			if (oSource[i].value == "0" || oSource[i].value == "")
			{
				oSource[i].checked = true;
				break;
			}
		}
	}
	else if (oSource.type == "select-one")
	{
		oSource.value = oSource.options[0].value;
	}
	else
		oSource.value = "";

}

var MOL=new Array();
function MenuObj(_A,_B,_C,_D,_E,_F,_G,_H,_I)
{
	this.name=_A;
	this.bOn=_E;
	this.bOf=_F;
	this.bA=_G;
	this.SBS=SBS;
	this.showing=false;
	this.TM=TM;
	document.onclick=MCH;
	this.Direction=_I;
	MOL[MOL.length]=this;
	this.divObj=eval('document.all.' + _B);
	this.divStyleObj=eval('document.all.' + _B + '.style');
	this.refTDObj=eval('document.all.' + _C);
	if (_D)
		this.DdTDObj=eval('document.all.' +  _D);
	this.frmObj=eval('document.all.' +  _H);
	this.strShow='visible';
	this.strHide='hidden';
}

function ROP(ObjRef)
{
	var theObj=null;
	if (ObjRef)
	{
		if (typeof ObjRef != 'object')
			theObj=eval(ObjRef);
		else
			theObj=ObjRef;
		return theObj;
	}
	else
		return false;
}

function TM()
{
	if (!this.showing)
	{
		var RelObjCords=getXY(this.refTDObj);
		if (this.Direction)
		{
			this.divStyleObj.top = this.frmObj.style.top = RelObjCords.top + -this.divObj.offsetHeight;
			this.divStyleObj.left = this.frmObj.style.left = RelObjCords.left;
		}
		else
		{
			this.divStyleObj.top = this.frmObj.style.top = RelObjCords.top + 18;
			this.divStyleObj.left = this.frmObj.style.left = RelObjCords.left;
		}
		this.frmObj.style.height=this.divObj.offsetHeight;
		if (this.divObj.offsetWidth < 91)
			this.divStyleObj.width = 91;
		this.frmObj.style.width=this.divObj.offsetWidth;
		var pCurrMenuObj=ROP(this);
		CM(this);
//		this.SBS('clicked');
		this.divStyleObj.visibility = this.frmObj.style.visibility = this.strShow;
		this.showing=true;
	}
	else
	{
		this.divStyleObj.visibility = this.frmObj.style.visibility = this.strHide;
		this.showing=false;
//		this.SBS();
	}
}

function CM(callerObj)
{
	for (aIndex=0;aIndex < MOL.length; aIndex++)
	{
		if ((callerObj) && (callerObj.name != MOL[aIndex].name))
		{
			if (MOL[aIndex].showing)
			{
				MOL[aIndex].TM();
//				MOL[aIndex].SBS();
			}
		}
		else
		{
			if (MOL[aIndex].showing)
			{
				MOL[aIndex].TM();
//				MOL[aIndex].SBS();
			}
		}
	}
}

function MCH(e, srcObj, srcIsMenuDiv)
{
	var srcElem;
	if (!e)
		var e=window.event;
	e.cancelBubble=true;
	if (srcObj)
	{
		var pCurrMenuObj=ROP(srcObj);
		if (!srcIsMenuDiv)
			pCurrMenuObj.divObj.onclick="MCH(event,"+srcObj+",true)";
		pCurrMenuObj.TM();
	}
	else
		CM();
}

function MME(e, srcObj)
{
	try
	{
		if (!e)
			var e=window.event;
		var pCurrMenuObj=ROP(srcObj);
		if (!pCurrMenuObj.showing)
		{
			if (e.type == 'mouseover')
				pCurrMenuObj.SBS('on');
			else if ((e.type == 'mouseout') || (e.type == 'blur'))
				pCurrMenuObj.SBS();
		}
	}
	catch(e){}
}

function SBS(wS)
{
	if (typeof this.refTDObj != "undefined")
	{
		if (wS == 'on')
		{
			if (this.bOn)
			{
				if (typeof this.DdTDObj != "undefined")
					this.DdTDObj.className=this.bOn;
				this.refTDObj.className=this.bOn;
			}
		}
		else if (wS == 'clicked')
		{
			if (this.bA)
			{
				if (typeof this.DdTDObj != "undefined")
					this.DdTDObj.className=this.bA;
				this.refTDObj.className=this.bA;
			}
		}
		else
		{
			if (this.bOf)
			{
				if (typeof this.DdTDObj != "undefined")
					this.DdTDObj.className=this.bOf;
				this.refTDObj.className=this.bOf;
			}
		}
	}
}

function MO_D(e)
{
	if (!e)
		var e=window.event;
	var S=e.srcElement;
	while (S.tagName!="TD")
		{S=S.parentElement;}
	S.className="X";
}

function MU_D(e)
{
	if (!e)
		var e=window.event;
	var S=e.srcElement;
	while (S.tagName!="TD")
		{S=S.parentElement;}
	S.className="W";
}

function getXY(Obj)
{
	for (var sumTop=0,sumLeft=0;Obj!=document.body;sumTop+=Obj.offsetTop,sumLeft+=Obj.offsetLeft, Obj=Obj.offsetParent);
	return {left:sumLeft,top:sumTop}
}

function showStatTime(ivalue)
{
	var tTitle = eval('timeTitle');
	var tCondition = eval('timeCondition');
	if (ivalue != 'StatDeviceChange' && ivalue != 'StatRiskChange' && ivalue != 'StatVulnChange')
	{
		tTitle.style.display = "none";
		tCondition.style.display = "none";
	}
	else
	{
		tTitle.style.display = "";
		tCondition.style.display = "";
	}

}


function ChangeToMultipleBS(ivalue)
{
	var tIncludeSubBS = eval('includeSubBS');
	var link = eval('bslink');
	if (ivalue == 'StatDeviceGrade' || ivalue == 'StatRiskAssetSeverity')
	{
		link.href = link.href.replace('single', 'multiple');
		if (ivalue == 'StatRiskAssetSeverity')
			tIncludeSubBS.style.display = "none";
		else
			tIncludeSubBS.style.display = "";
	}
	else
	{
		link.href = link.href.replace('multiple', 'single');
		tIncludeSubBS.style.display = "";
	}
}

function ChangeTree(bsorpf)
{
	var oLink = eval('bslink');
	if (bsorpf == 'pf')
	{
		oLink.href = oLink.href.replace('ReadBSTree', 'ReadPFTree');
		oLink.href = oLink.href.replace('\',','&param=adjust\',');
	}
	else
	{
		oLink.href = oLink.href.replace('ReadPFTree', 'ReadBSTree');
		oLink.href = oLink.href.replace('&param=adjust\',', '\',');
	}
}

function CheckALL(id,target)
{
	var clickObj = eval(id);
	var targetObj = document.all.item(target);
	if (targetObj.type == 'checkbox')
	{
		targetObj.checked = clickObj.checked;
	}
	else
	{
		for (var i = 0; i < targetObj.length; i++)
		{
			targetObj[i].checked = clickObj.checked;
		}
	}
}

function CheckSingle(id,target)
{
	var clickObj = eval(id);
	var targetObj = document.all.item(target);
	if (targetObj.type == 'checkbox')
	{
		clickObj.checked = targetObj.checked;
	}
	else
	{
		var status = targetObj[0].checked;
		for (var i = 1; i < targetObj.length; i++)
		{
			if (targetObj[i].checked != status)
			{
				clickObj.checked = false;
				return;
			}
		}
		clickObj.checked = status;
	}
}

function QueryArr(name, input)
{
	this.name = name;
	this.input = input;
}
function QueryCheck(itemArr,form)
{
	if (itemArr == null)
		return;

	for (var i = 0; i < itemArr.length; i++)
	{
		//alert(eval(itemArr[i].name).style.display)
		if (eval(itemArr[i].name).style.display == 'none')
			ClearValue(itemArr[i].input,form);
	}
}

function RefreshFrame()
{
 var oWin = window.parent;
 var i = 0;
 while (oWin.frames.length != 0)
 {
  i++;
  oWin = oWin.frames[oWin.frames.length-1];
 }
 	if (i == 1)
 		window.parent.location.reload(true);
 	else if (i == 2)
 		window.parent.frames[1].location.reload(true);
 	//oWin.location.reload(true);

}
/*
function goto(URI)
{
	window.location = URI;
}
*/
function newurl(URI)
{
  var random = Math.random() * 10000000000;
  URI = URI +"&"+ random.toString();
  window.location = URI;
}

//??????????
function ValidateBasicLibraryForm(form)
{
	var errors = '';
	var sn = form.sn.value;
	var parentSn = form.parentSn.value+'.';
	if(sn == null || sn.indexOf(parentSn)!=0)
			errors = errors + '\r\n????????????????????;';
	if(sn == parentSn)
			errors = errors + '\r\n????????????????????;';
	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????;';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}


//??????????
function ValidateCtrlMeasureForm(form)
{

	var errors = '';

	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????;';
	if (form.aim.value == null || form.aim.value == '')
		errors = errors + '\r\n????????????;';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

//??????????
function ValidateSecurityIndexForm(form,isInsert)
{
	var errors = '';
	var sn = form.sn.value;
	var parentSn = form.parentSn.value;
	var secType = '';
	if(isInsert)
	{
		for(var i=0;i<form.secType.length;i++)
		{
			if(form.secType[i].checked)
			{
				secType = form.secType[i].value;
				break;
			}
		}
	}
	else
	{
		secType = form.secType.value;
	}
	if(secType =='')
		errors = errors + '\r\n??????????????????;';
	else if(secType == '0')
	{
		if(sn == null || sn.indexOf(parentSn)!=0)
			errors = errors + '\r\n????????????????????????????;';

	}
	else if(secType == '1')
	{
		if(sn.indexOf('OPT-')!=0)
			errors = errors + '\r\n??????????????????\'OPT-\'????;';
		if(sn == null || sn.substring(4).indexOf(parentSn)!=0)
			errors = errors + '\r\n????????????????????;';

	}
	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????????;';
	if (form.secGroups.value == null || form.secGroups.value == '')
		errors = errors + '\r\n????????????????;';
	else
	{
		val = form.secGroups.value;
		re = /\d+/;
		if (!re.test(val))
			errors = errors + '\r\n??????????????????;';
	}
	if (form.secClass.value == null || form.secClass.value == '')
		errors = errors + '\r\n????????????????;';
	else
	{
		val = form.secClass.value;
		re = /[123]/;
		if (!re.test(val))
			errors = errors + '\r\n??????????????(1~3)??????;';
	}
	if (form.methods.value == null || form.methods.value == '')
		errors = errors + '\r\n????????????????;';
	if (form.areas.value == null || form.areas.value == '')
		errors = errors + '\r\n????????????????;';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

function ValidateCommonForm(form)
{
	var errors = '';
	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????;';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

function ValidateBuzSystemForm(form)
{
	var errors = '';
	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????;';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}


function ValidatePrtObjAnalysisForm(form)
{
	var errors = '';
	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????;';

	if (errors == '')
	{
		if(needGenObj)
		{
			var message = '????????????????????????????????????????????????';
			question = confirm(message)
			if (question != "0")
			{
				form.genObj.value=0;
				form.submit();
			}
		}
		else
		{
			form.submit();
		}
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

function ValidateExamForm(form)
{
	var errors = '';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

function ValidatePolicyLibFolderEditForm(form)
{
	var errors = '';
	if (form.name.value == null || form.name.value == '')
		errors = errors + '\r\n????????????;';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}


//???????????????? by ????
function showWindow(url,width,height,name,option)
{
	if(typeof name == "undefined")
	{
		name = null;
	}
	if(typeof width == "undefined")
	{
		width = "400";
	}
	if(typeof height == "undefined")
	{
		height = "300";
	}
	if(typeof option != "undefined")
	{
		option = "," + option;
	}
	else
	{
		option = "";
	}
	var features = "width=" + width + ",height=" + height + option;
	features += ",top=" + ((window.screen.height - height - 100)/2) + ",left=" + (window.screen.width - width)/2;
	window.open(url,name,features);
}


//????????
function resuredelete(path,str)
{
	var message = str;
	var newPath=path;
	question = confirm(message)
	if (question != "0")
	{
		window.location=path;
	}
}
//????????????
function AddCtrlMeasure(from, to)
{
	var oFrom = document.all.item(from);
	var oTo = document.all.item(to);

	if (oFrom.selectedIndex != -1)
	{
		for(var j = 0; j < oFrom.options.length; j++)
		{
			if(oFrom.options[j].selected)
			{
				var isIn = false;
				for (var i = 0; i < oTo.options.length; i++)
				{
					if (oTo.options[i].value == oFrom.options[j].value)
					{
						alert("????????:" + oFrom.options[j].text + " ??????????");
						isIn = true;
						break;
					}
				}
				if(!isIn)
				{
					oTo.options[oTo.options.length] = new Option(oFrom.options[j].text, oFrom.options[j].value, false, false);
				}
			}
		}
	}
}

function AddAllCtrlMeasure(from, to)
{
	var oFrom = document.all.item(from);
	var oTo = document.all.item(to);

	if (confirm('??????????????????') == "0")
	{
		return;
	}

	for(var j = 0; j < oFrom.options.length; j++)
	{
		var isIn = false;
		for (var i = 0; i < oTo.options.length; i++)
		{
			if (oTo.options[i].value == oFrom.options[j].value)
			{
				isIn = true;
				break;
			}
		}
		if(!isIn)
		{
			oTo.options[oTo.options.length] = new Option(oFrom.options[j].text, oFrom.options[j].value, false, false);
		}
	}

}

//????????????
function DelAllCtrlMeasure(from)
{
	var oSource = document.all.item(from);
	if (confirm('??????????????????') == "0")
	{
		return;
	}

	for(var i=oSource.options.length-1;i>=0;i--)
	{
		oSource.options[i] = null;
	}
}

function DelCtrlMeasure(from)
{
	var oSource = document.all.item(from);

	for(var i=oSource.options.length-1;i>=0;i--)
	{
		if(oSource.options[i].selected == true)
		{
			oSource.options[i] = null;
		}
	}
}

function myPrtObj(id,buzSysId,prtFrmId,prtFrmName)
{
	this.id = id;
	this.buzSysId=buzSysId;
	this.prtFrmId=prtFrmId;
	this.prtFrmName=prtFrmName;
}

function SwapPrtFrm(buzSys,prtFrm)
{
	var oType = document.all.item(buzSys);
	var oSub = document.all.item(prtFrm);
	var x = 0;

	if (oType.options[oType.selectedIndex].value == '')
	{
		for (var i = 0; i < pList.length; i++)
		{
			oSub.options[x++] = new Option(pList[i].prtFrmName, pList[i].prtFrmId, false, false);
		}
		oSub.options.length = x;
		return;
	}

	for (var i = 0; i < pList.length; i++)
	{
		if (pList[i].buzSysId == oType.options[oType.selectedIndex].value)
			oSub.options[x++] = new Option(pList[i].prtFrmName, pList[i].prtFrmId, false, false);
	}
	oSub.options.length = x;
}

function SwapSecuritySN(form)
{
	for(var i=0;i<form.secType.length;i++)
	{
		if(form.secType[i].checked)
		{
			if(form.secType[i].value=='0')
			{
				var sn = form.sn.value;
				if(sn.indexOf('OPT-')==0)
				{
					sn = sn.substring(4);
					form.sn.value=sn;
				}
			}
			else if(form.secType[i].value=='1')
			{
				var sn = form.sn.value;
				if(sn.indexOf('OPT-')!=0)
				{
					sn = 'OPT-'+sn;
					form.sn.value=sn;
				}
			}
		}
    }
}

function back()
{
	window.back();
}

function EditStandard(textArea)
{
	textArea.readonly='false';
	textArea.value='go!';
	textArea.readonly='true';
}

function ValidatePaperImportForm(form)
{
	var errors = '';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}

function ValidatePaperDbForm(form)
{
	var errors = '';

	if (errors == '')
	{
		form.submit();
	}
	else
	{
		errors = '??????????????????????:' + errors;
		alert(errors);
	}
}