//--change page
function ChangePage(page){
	document.frm.to_page.value = page;
	document.frm.submit();
}

//--Sort Field
function ChangeSort(SortField,SortType) {
   document.frm.SortField.value = SortField;
   document.frm.SortType.value  = SortType;
   document.frm.submit();
}

function ChangeCondition(Field,value) {
   switch(Field){
	    case "exist_time":
	    case "login_time":
	    case "_DB_DATETIME":
		case "_TIMESTAMP":
		   document.frm.QUERY_START_DATETIME.value = value;
		   document.frm.QUERY_END_DATETIME.value = value;
		   break; 
		case "_DATETIME":
		   document.frm.QUERY_START_DATETIME.value = value;
		   document.frm.QUERY_END_DATETIME.value = value;
		   break;
		case "_DATE":
		   document.frm.QUERY_START_DATETIME.value = value;
		   document.frm.QUERY_END_DATETIME.value = value;
		   break;
		case "_OWNER":
		   document.frm.QUERY_OWNER.value = value;
		   break;
		case "_MODE":
		   document.frm.QUERY_MODE.value = value;
		   break;
		case "_INFORM":
		   document.frm.QUERY_INFORM.value = value;
		   break;
		case "_FORWARD":
		   document.frm.QUERY_FORWARD.value = value;
		   break;
	    case "_WHOM":
		   document.frm.QUERY_WHOM.value = value;
		   break;
		case "_IP":
		   document.frm.QUERY_IP.value = value;
		   document.frm.QUERY_IP_1.value = "1";
		   break;	
		case "_FROM":
		   document.frm.QUERY_FROM.value = value;
		   break;
		case "_TO":
		   document.frm.QUERY_TO.value = value;
		   break;
		case "_CC":
		   document.frm.QUERY_CC.value = value;
		   break;
		case "_BCC":
		   document.frm.QUERY_BCC.value = value;
		   break;
		case "ip":
		case "login_ip":
		   document.frm.QUERY_IP.value = value;
	   break;
		case "_MAC":
		   document.frm.QUERY_MAC.value = value;
		   break;
		case "_NAME":
		   document.frm.QUERY_NAME.value = value;
		   break;
		case "username":
		case "loginid":
		case "_USER":
		   document.frm.QUERY_USER.value = value;
		   break;
		case "_DIR":
		   document.frm.QUERY_DIR.value = value;
		   break;
		case "_SITE":
		   document.frm.QUERY_SITE.value = value;
		   break;
		case "_SENDER":
		   document.frm.QUERY_SENDER.value = value;
		   break;
		case "_HOST":
		   document.frm.QUERY_HOST.value = value;
		   break;
		case "_TAG":
		   document.frm.QUERY_TAG.value = value;
		   break;
		case "groupno":
		   document.frm.QUERY_GROUP.value = value;
		   break;
		case "remark":
		   document.frm.QUERY_REMARK.value = value;
		   break;
	    case "_SERVER":
		   document.frm.QUERY_SERVER.value = value;
		   break;
		case "status":
			document.frm.QUERY_STATUS.value = value;
			break;
		case "_ACCOUNT":
			document.frm.QUERY_ACCOUNT.value = value;
			break;
		case "_ISP":
			document.frm.QUERY_ISP.value = value;
			break;
		case "_MAC":
			document.frm.QUERY_MAC.value = value;
		break;
		case "_PMAC":
			document.frm.QUERY_PMAC.value = value;
		break;
		case "_SMAC":
			document.frm.QUERY_SMAC.value = value;
		break;
		case "_DMAC":
			document.frm.QUERY_DMAC.value = value;
		break;
		case "_DIP":
			document.frm.QUERY_DIP.value = value;
		break;
		case "_PIP":
			document.frm.QUERY_PIP.value = value;
		break;
		case "_PORT":
			document.frm.QUERY_PORT.value = value;
		break;
		case "_PPORT":
			document.frm.QUERY_PPORT.value = value;
		break;
		case "_SPORT":
			document.frm.QUERY_SPORT.value = value;
		break;
		case "_DPORT":
			document.frm.QUERY_DPORT.value = value;
		break;
		case "_TYPE":
			document.frm.QUERY_TYPE.value = value;
		break;
		case "_START":
			document.frm.QUERY_START_DATETIME.value = value;
		break;
		case "_STOP":
			document.frm.QUERY_END_DATETIME.value = value;
		break;
		case "_BYTE":
			document.frm.QUERY_BYTE.value = value;
		break;
		case "_TOOL":
			document.frm.QUERY_TOOL.value = value;
		break;
		case "_FILENAME'":
			document.frm.QUERY_FILENAME.value = value;
		break;
   }
   document.frm.submit();
}


//--new windows
function fn_OpenWin(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//--chkMail
function emailCheck (inText) {
	var emailStr = inText.value;
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|idv)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i) == 42) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)==42) {
			return false;
		}
	}

	if (user.match(userPat)==null) {
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				return false;
			}
		}
		 return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		return false;
	}

	if (len<2) {
		return false;
	}
	return true;
}


//--Check pagesize num
function CheckNum(fobj){
	var ErrorMsg = "";
	Chkstring='0123456789'
	Telstring = fobj.value;

	if (Telstring == ""){
		ErrorMsg = "1";
	}
	else if(Telstring == 0){
		ErrorMsg = "2";
	}
	else if (Telstring > 100){
		ErrorMsg = "3";
	}
	else{
		for (var i=0;i<Telstring.length;i++){
			if (Chkstring.indexOf(Telstring.charAt(i)) == -1){
				ErrorMsg = "4";
			}
		}
	}
	return ErrorMsg;
}


//--Select All
function OnOffAll(value){
	if(value == 1){
		var chkbox = document.frm.elements['chkbox_1[]'];
		var CheckBox = document.frm.OnOffCheckBox1.checked;
	}else{
		var chkbox = document.frm.elements['chkbox[]'];
		var CheckBox = document.frm.OnOffCheckBox.checked;
	}
	var i = 0;
	if ("length" in chkbox){
		for (i=0;i < chkbox.length; i++){ 
			  chkbox[i].checked = CheckBox; 
		}
	}
	else{
		chkbox.checked = CheckBox; 
	}
}

//--MainOnOffAll
function MainCheck(value){
	if(value == 'DelDataBase' || value == '' || value == undefined)
		var chkbox = document.frm.elements['chkbox[]'];
	else
		var chkbox = document.frm.elements['chkbox_1[]'];

	if ("length" in chkbox){
		for (i=0;i < chkbox.length; i++){
			if (chkbox[i].checked) return true;
		}
	}
	else{
		if (chkbox.checked) return true;
	}
	return false;
}


function fn_DateTime_New(value){
	var start_date,end_date;
	var n = 0;
	//--Start Date
	if (document.frm.QUERY_STARTDATE.value != ''){
		var DateString = document.frm.QUERY_STARTDATE.value;
		var y,m,d;
		var idx=DateString.indexOf("-");
		y=DateString.substring(0,idx);
		DateString=DateString.substring(idx+1,DateString.length);
		var idx=DateString.indexOf("-");
		m=DateString.substring(0,idx); 
		d=DateString.substring(idx+1,DateString.length); 
		if (m.length==1) m = '0' + m;
		if (d.length==1) d = '0' + d;
		if (value == "deldata"){
			start_date = y + m + d;
		}else{
			document.frm.QUERY_STARTDATE.value = y + m + d;
		}
	}
	else{
		if (value == "deldata"){
			start_date = "19000101";
		}else{
			document.frm.QUERY_STARTDATE.value = "19000101";
		}
	}
	
	//--End Date
	if (document.frm.QUERY_ENDDATE.value != ''){
		var DateString = document.frm.QUERY_ENDDATE.value;
		var y,m,d;
		var idx=DateString.indexOf("-");
		y=DateString.substring(0,idx); 
		DateString=DateString.substring(idx+1,DateString.length);
		var idx=DateString.indexOf("-");
		m=DateString.substring(0,idx); 
		d=DateString.substring(idx+1,DateString.length); 
		if (m.length==1) m = '0' + m;
		if (d.length==1) d = '0' + d;
		if (value == "deldata"){
			end_date = y + m + d;
		}else{
			document.frm.QUERY_ENDDATE.value = y + m + d;
		}
	}
	else{
		if (value == "deldata"){
			end_date = "20371231";
		}else{
			document.frm.QUERY_ENDDATE.value = "20371231";
		}
	}

	//--Start Time
	var start_time,end_time;
	if ((document.frm.QUERY_STARTHOUR.value != '') && (document.frm.QUERY_STARTMINUTE.value != '')){ 
		start_time = document.frm.QUERY_STARTHOUR.value + document.frm.QUERY_STARTMINUTE.value + "00";
	}
	else if ((document.frm.QUERY_STARTHOUR.value != '') && (document.frm.QUERY_STARTMINUTE.value == '')){
		start_time = document.frm.QUERY_STARTHOUR.value + "0000";
	}
	else if ((document.frm.QUERY_STARTHOUR.value == '') && (document.frm.QUERY_STARTMINUTE.value != '')){
		start_time = " 00" + document.frm.QUERY_STARTMINUTE.value + "00";
	}
	else if ((document.frm.QUERY_STARTHOUR.value == '') && (document.frm.QUERY_STARTMINUTE.value == '')){
		start_time = "000000";
	}
	
	//--End Date
	if ((document.frm.QUERY_ENDHOUR.value != '')&&(document.frm.QUERY_ENDMINUTE.value != '')){ 
		end_time = document.frm.QUERY_ENDHOUR.value + document.frm.QUERY_ENDMINUTE.value + "59";
	}
	else if ((document.frm.QUERY_ENDHOUR.value != '')&&(document.frm.QUERY_ENDMINUTE.value == '')){
		end_time = document.frm.QUERY_ENDHOUR.value + "5959";
	}
	else if ((document.frm.QUERY_ENDHOUR.value == '')&&(document.frm.QUERY_ENDMINUTE.value != '')){
		end_time = " 23" + document.frm.QUERY_ENDMINUTE.value + "59";
	}
	else if ((document.frm.QUERY_ENDHOUR.value == '')&&(document.frm.QUERY_ENDMINUTE.value == '')){
		end_time = "235959";
	}
	
	if (value == "deldata") {
		document.frm.QUERY_START_DATETIME.value = start_date + start_time;
		document.frm.QUERY_END_DATETIME.value = end_date + end_time;
	}else{
		document.frm.QUERY_START_DATETIME.value = document.frm.QUERY_STARTDATE.value + start_time;
		document.frm.QUERY_END_DATETIME.value = document.frm.QUERY_ENDDATE.value + end_time;
	}
}

function fn_DateTime(value){
	var start_date,end_date;
	var n = 0;
	//--Start Date
	if (document.frm.QUERY_STARTDATE.value != ''){
		var DateString = document.frm.QUERY_STARTDATE.value;
		var y,m,d;
		var idx=DateString.indexOf("-");
		y=DateString.substring(0,idx);
		DateString=DateString.substring(idx+1,DateString.length);
		var idx=DateString.indexOf("-");
		m=DateString.substring(0,idx); 
		d=DateString.substring(idx+1,DateString.length); 
		if (m.length==1) m = '0' + m;
		if (d.length==1) d = '0' + d;
		if (value == "deldata"){
			start_date = y + m + d;
		}else{
			document.frm.QUERY_STARTDATE.value = y + '-' + m + '-' + d;
		}
	}
	else{
		if (value == "deldata"){
			start_date = "19000101";
		}else{
			document.frm.QUERY_STARTDATE.value = "1900-01-01";
		}
	}
	
	//--End Date
	if (document.frm.QUERY_ENDDATE.value != ''){
		var DateString = document.frm.QUERY_ENDDATE.value;
		var y,m,d;
		var idx=DateString.indexOf("-");
		y=DateString.substring(0,idx); 
		DateString=DateString.substring(idx+1,DateString.length);
		var idx=DateString.indexOf("-");
		m=DateString.substring(0,idx); 
		d=DateString.substring(idx+1,DateString.length); 
		if (m.length==1) m = '0' + m;
		if (d.length==1) d = '0' + d;
		if (value == "deldata"){
			end_date = y + m + d;
		}else{
			document.frm.QUERY_ENDDATE.value = y + '-' + m + '-' + d;
		}
	}
	else{
		if (value == "deldata"){
			end_date = "20371231";
		}else{
			document.frm.QUERY_ENDDATE.value = "2037-12-31";
		}
	}

	//--Start Time
	var start_time,end_time;
	if ((document.frm.QUERY_STARTHOUR.value != '') && (document.frm.QUERY_STARTMINUTE.value != '')){ 
		if (value == "deldata"){
			start_time = document.frm.QUERY_STARTHOUR.value + document.frm.QUERY_STARTMINUTE.value + "00";
		}else{
			start_time = document.frm.QUERY_STARTHOUR.value + ":" + document.frm.QUERY_STARTMINUTE.value + ":00";
		}
	}
	else if ((document.frm.QUERY_STARTHOUR.value != '') && (document.frm.QUERY_STARTMINUTE.value == '')){
		if (value == "deldata"){
			start_time = document.frm.QUERY_STARTHOUR.value + "0000";
		}else{
			start_time = document.frm.QUERY_STARTHOUR.value + ":00:00";
		}
	}
	else if ((document.frm.QUERY_STARTHOUR.value == '') && (document.frm.QUERY_STARTMINUTE.value != '')){
		if (value == "deldata"){
			start_time = " 00" + document.frm.QUERY_STARTMINUTE.value + "00";
		}else{
			start_time = " 00:" + document.frm.QUERY_STARTMINUTE.value + ":00";
		}
	}
	else if ((document.frm.QUERY_STARTHOUR.value == '') && (document.frm.QUERY_STARTMINUTE.value == '')){
		if (value == "deldata") start_time = "000000"; else start_time = "00:00:00";
	}
	
	//--End Date
	if ((document.frm.QUERY_ENDHOUR.value != '')&&(document.frm.QUERY_ENDMINUTE.value != '')){ 
		if (value == "deldata") {
			end_time = document.frm.QUERY_ENDHOUR.value + document.frm.QUERY_ENDMINUTE.value + "59";
		}else{
			end_time = document.frm.QUERY_ENDHOUR.value + ":" + document.frm.QUERY_ENDMINUTE.value + ":59";
		}
	}
	else if ((document.frm.QUERY_ENDHOUR.value != '')&&(document.frm.QUERY_ENDMINUTE.value == '')){
		if (value == "deldata") {
			end_time = document.frm.QUERY_ENDHOUR.value + "5959";
		}else{
			end_time = document.frm.QUERY_ENDHOUR.value + ":59:59";
		}
	}
	else if ((document.frm.QUERY_ENDHOUR.value == '')&&(document.frm.QUERY_ENDMINUTE.value != '')){
		if (value == "deldata") {
			end_time = " 23" + document.frm.QUERY_ENDMINUTE.value + "59";
		}else{
			end_time = " 23:" + document.frm.QUERY_ENDMINUTE.value + ":59";
		}
	}
	else if ((document.frm.QUERY_ENDHOUR.value == '')&&(document.frm.QUERY_ENDMINUTE.value == '')){
		if (value == "deldata") end_time = "235959"; else end_time = "23:59:59";
	}
	
	if (value == "deldata") {
		document.frm.QUERY_START_DATETIME.value = start_date + start_time;
		document.frm.QUERY_END_DATETIME.value = end_date + end_time;
	}else{
		document.frm.QUERY_START_DATETIME.value = document.frm.QUERY_STARTDATE.value + " " + start_time;
		document.frm.QUERY_END_DATETIME.value = document.frm.QUERY_ENDDATE.value + " " + end_time;
	}
}

//--check IP style
function fn_chkeckIP(value){
	var ErrorMsg = "";
	if (value == 1){
		var Pat = /(\d*)\.(\d*)\.(\d*)\.(\d*)/;
		Ip = document.frm.txtIP.value;
	}else if (value == 2){
		var Pat = /(\d*)\.(\d*)\.(\d*)\.(\d*),(\d*)\.(\d*)\.(\d*)\.(\d*)/;
		Ip = document.frm.txtDomain.value;
	}

	var chk = Ip.match(Pat);
	
	if (chk == null){
		if (Ip != ""){
			ErrorMsg = "2";
		}else{
			ErrorMsg = "1";
		}
	}
	return ErrorMsg;
}

//--alert error msg
function fn_ErrorMsg(value){
	alert(value);
}

//--check Number value
function CheckNumValue(fobj){
	Chkstring='0123456789';
	Telstring = fobj.value;
	for (var i=0;i<Telstring.length;i++){
		if (Chkstring.indexOf(Telstring.charAt(i)) == -1){
			return false;
		}
	}		
	return true;
}

function fn_Button(msg,value){
	var Obj=document.all;
	var strOver = "_Over"+msg;
	var strOut = "_Out"+msg;
	
	if(value == 1){
		Obj.item(strOver).style.display="inline";
		Obj.item(strOut).style.display="none";
	}else if(value == 2){
		Obj.item(strOver).style.display="none";
		Obj.item(strOut).style.display="inline";
	}
}

function window_onload_language(){
		var objnav=window.navigator;
		var objSelection=document.frm.selLanguage;
		var chars=new Array("GB18030","GB3212","BIG5","HZ","ISO-8859-1");
		var nav=new Array("zh-ch","zh-sg","zh-tw","zh-hk","en");

		for(var i=0;i< chars.length;i++){
		  if (objnav.browserLanguage == nav[i]){
			  document.frm.language.value = chars[i];
		      break;
		  }
		}
}

//--forward
function resend(table,auto){
     var url = 'forward.php?TABLE='+table+'&_AUTO='+auto;
	fn_OpenWin(url,'NewWin','width=440,height=140,left=280,top=300,menubar=no,toolbar=no,location=no,directories=no,scrollbars=no,status=yes,resizable=yes,fullscreen=no');
		return;

}

//--Dynamic Module Menu
function stat(){
	var a = pageYOffset+window.innerHeight-document.bar.document.height-15;
	document.bar.top = a;
	setTimeout('stat()',2);
}
function fix(){
	nome=navigator.appName;
	if(nome=='Netscape'){
		stat();
	}
	else{
		var a=document.body.scrollTop+document.body.clientHeight-document.all.bar.offsetHeight;
		bar.style.top = a;
	}
}