//////////////////////////////////////////////////////////
//  公用JS函數庫										//
//  @Unknowner 2003.08.07								//
//  Init Version:										//
//////////////////////////////////////////////////////////

//按回車，發送TAB鍵
function SetReturn()
{
    if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = true;
    }
}

//只能輸入數值
function NumericOnly()
{
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57)
      || (window.event.keyCode == 8) || (window.event.keyCode == 9)
      || (window.event.keyCode == 190)
      || (window.event.keyCode >= 96) && (window.event.keyCode <= 105)
      || (window.event.keyCode == 110)
      || (window.event.keyCode >= 37) && (window.event.keyCode <= 40)
      || (window.event.keyCode == 46)
     )
		window.event.returnValue = true;
    else if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = true;
    }
	else
		window.event.returnValue = false;
}

//僅能輸入數字(不包括小數點)
function NumOnly(){
	if((window.event.keyCode >= 48) && (window.event.keyCode <= 57)
      || (window.event.keyCode >= 96) && (window.event.keyCode <= 105)
      || (window.event.keyCode == 8)
      || (window.event.keyCode >= 37) && (window.event.keyCode <= 40)
      || (window.event.keyCode == 46)
     )
		window.event.returnValue = true;
    else if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = true;
    }
	else
		window.event.returnValue = false;
}

//新建窗口
//當傳入的參數為0時，大小取默認值
function openWin(theURL,width,height) {
    try {
		if(width==0) width=530;
		if(height==0) height=327;

        var top = (screen.height - height)/3;
        var left = (screen.width - width)/2;

        var newWin = window.open(theURL,"","width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars");
        newWin.focus();
    }
    catch(e) {}
}

//截斷字符串的空格
String.prototype.Trim=function() {return this.replace(/(^\s*)|(\s*$)/g,"");}
String.prototype.Ltrim = function(){return this.replace(/(^\s*)/g, "");}
String.prototype.Rtrim = function(){return this.replace(/(\s*$)/g, "");}

//截斷字符串前后的空格
function trim(param) {
    return param.Trim();
}

//頁面僅能提交一次
function submitOnce(theform)
{
	//if IE 4+ or NS 6+
	if (document.all||document.getElementById)
	{
		//screen thru every element in the form, and hunt down "submit" and "reset"
		for (i=0;i<theform.length;i++)
		{
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
			//disable em
			tempobj.disabled=true;
		}
	}

	theform.submit();
}

//全選CHECKBOX
function CheckAll(form){
  for (var i=0;i<form.elements.length;i++){
      var e = form.elements[i];
      if (e.type.toLowerCase()=="checkbox" && e.name != 'chkall')
          e.checked = form.chkall.checked;
  }
}
//是否至少一個CHECKBOX被選中
function atLeastOneChecked(form){
  for (var i=0;i<form.elements.length;i++){
      var e = form.elements[i];
	  //alert("a:" + e.name != 'chkall');
      if (e.name != 'chkall' && e.checked==true)
          return true;
  }
  return false;
}

//格式化字符串
function formatStr(str,len) {
	str = trim(str);
	var chinese = countChinese(str);
	for(var i=str.length; i<len-chinese; i++) {
		str += " ";
	}
	return str;
}

//用戶是否按下Enter
function isPressEnter() {
    var charCode = (navigator.appName=="Netscape")? event.which:event.keyCode;
    if (charCode==13) return true;
    return false;
}



//********************* 以下為顯示提示代碼 *******************

tPopWait=50;//停留tWait豪秒后顯示提示。
tPopShow=5000;//顯示tShow豪秒后關閉提示
showPopStep=20;
popOpacity=99;

sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;

document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText {  background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");


function showPopupText(){
var o=event.srcElement;
	MouseX=event.x;
	MouseY=event.y;
	if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
        if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
	if(o.dypop!=sPop) {
			sPop=o.dypop;
			clearTimeout(curShow);
			clearTimeout(tFadeOut);
			clearTimeout(tFadeIn);
			clearTimeout(tFadeWaiting);	
			if(sPop==null || sPop=="") {
				dypopLayer.innerHTML="";
				dypopLayer.style.filter="Alpha()";
				dypopLayer.filters.Alpha.opacity=0;	
				}
			else {
				if(o.dyclass!=null) popStyle=o.dyclass 
					else popStyle="cPopText";
				curShow=setTimeout("showIt()",tPopWait);
			}
			
	}
}

function showIt(){
		dypopLayer.className=popStyle;
		dypopLayer.innerHTML=sPop;
		popWidth=dypopLayer.clientWidth;
		popHeight=dypopLayer.clientHeight;
		if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
			else popLeftAdjust=0;
		if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
			else popTopAdjust=0;
		dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
		dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
		dypopLayer.style.filter="Alpha(Opacity=0)";
		fadeOut();
}

function fadeOut(){
	if(dypopLayer.filters.Alpha.opacity<popOpacity) {
		dypopLayer.filters.Alpha.opacity+=showPopStep;
		tFadeOut=setTimeout("fadeOut()",1);
		}
		else {
			dypopLayer.filters.Alpha.opacity=popOpacity;
			tFadeWaiting=setTimeout("fadeIn()",tPopShow);
			}
}

function fadeIn(){
	if(dypopLayer.filters.Alpha.opacity>0) {
		dypopLayer.filters.Alpha.opacity-=1;
		tFadeIn=setTimeout("fadeIn()",1);
		}
}
document.onmouseover=showPopupText;

//************************* 結束提示顯示 ****************************

//******** 以下為按ctrl+enter時作提交處理 *****************
ie = (document.all)? true:false
if (ie)
{
	function ctlent(eventobject)
	{
		if(event.ctrlKey && window.event.keyCode==13)
		{	
			//當通過檢測數据后，提交頁面
			if(valid1())
				this.document.forms[0].submit();
		}
	}
}

// ############### 以下代碼為做LOG站時新增 #################

//檢測時顯示錯誤提示并得到焦點
function show_err(err_item,text)
{
	window.alert (text);
	err_item.select();
	err_item.focus();
}

//檢測某個列表是否為沒有選定選項，
//如果沒有選定任何項，測返回false，否則返回true
function ListSelected(Obj)
{ 
	var retVal;
	retVal=false;

		for (i=0; i<Obj.length; i++)
		{
			if(Obj.options[i].selected == true)
			{
				retVal=true;
				break;
			}
		}

	return retVal;
}

//新建窗口,在左則
//當傳入的參數為0時，大小取默認值
function openWinOnLeft(theURL,width,height) {
    try {
		if(width==0) width=530;
		if(height==0) height=327;

        var top = (screen.height - height)/3;
        //var left = (screen.width - width)/2;
		var left = 0;

        var newWin = window.open(theURL,"","width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars");
        newWin.focus();
    }
    catch(e) {}
}

//2005.2.28 added
//新建Modal窗口
//當傳入的參數為0時，大小取默認值
function openDialog(theURL,theID,width,height,left,top) {
    try {
		if(width==0) width=530;
		if(height==0) height=327;

		if(left==0) left = 0;
        if(top==0) top = (screen.height - height)/3;
        //var left = (screen.width - width)/2;

        //var newWin = window.open(theURL,"","width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars");
        //newWin.focus();
        
		var style="dialogWidth:" + width + "px;dialogHeight:" + height + "px;dialogLeft:" + left + "px;dialogTop:" + top + "px;center:yes;help:no;resizable:no;status:no";
		window.showModalDialog(theURL,theID, style);        
    }
    catch(e) {}
}


// ############### 以下代碼為做WISUS站時新增 #################

//檢測txtObj是否為空，如果為空則給出txtTips提示
function CheckText(txtObj,txtTips){

    //alert(txtObj.value);
    //if(txtObj.value=="") {
    if(txtObj.value==""||txtObj.value.length==0) {
        if(txtTips=="") {
            txtTips="請填寫完整數据﹗";
        }
        alert(txtTips);
        txtObj.focus();
        return false;
    }
    else
    	return true;
}




//以下未被使用到

function hasChineseChar(param) {
	return (/[^\x00-\xff]/g.test(param));
}

function countChineseChar(param) {
	var count = 0;
	for(var i=0; i<param.length; i++) {
		var tmp = param.substring(i,i+1);
		if(hasChinese(tmp)) count++;
	}
	return count;
}