﻿// JScript 檔
var progressWindow;
var saveBgColor="";
var saveColor;
var bgColorList=new Array("thistle","#c8e9ff","#996699","#690034","#ffccff","#fafad2","#3cff3c");
var colorList=new Array("white","#3C3CFF","white","white","#FF50A7","#FFBF00");
function ColorTROver(tdbg,index)
{
	saveBgColor=tdbg.style.backgroundColor;
	saveColor=tdbg.style.color;
	tdbg.style.backgroundColor=bgColorList[eval(index)];
	saveColor=new Array();
	for(i=0;i<tdbg.cells.length;i++)
	{
	    spanNodes=tdbg.cells[i].getElementsByTagName("span");
	    if(spanNodes.length >0)
	    {
	        saveColor[i]=spanNodes[0].style.color;
	        spanNodes[0].style.color=colorList[eval(index)];
	    }
	    else
	        saveColor[i]="null";
	}
}
function ColorTROut(tdbg)
{
	tdbg.style.backgroundColor = saveBgColor;
	for(i=0;i<tdbg.cells.length;i++)
	{
	    spanNodes=tdbg.cells[i].getElementsByTagName("span");
	    if(saveColor[i] !="null")
	        spanNodes[0].style.color=saveColor[i];
	}
	  
}
function ToSafeString(strings)
{
  var rv=strings.replace(/\,/g,"，").replace(/\'/g,"’").replace(/\;/g,"；").replace(/\//g,"／").replace(/\</g,"＜").replace(/\>/g,"＞");
  return rv;
}

function OverMaxFileSize(ctrl,maxSizeKB)
{
    var doc = document.getElementById(ctrl).value.replace(/\\/g, "\\\\");
    if(doc.length==0)
    return false;
    try{
        fso = new ActiveXObject( 'Scripting.FileSystemObject' );
        var fi = fso.getFile(doc);
        var fileSize = fi.size;
        var allowSize=maxSizeKB*1024;
         alert("檔案大小：" + fileSize + "Byte ,允許的檔案大小："+ allowSize +"Byte");
        if (fileSize > allowSize) {
            alert("檔案大小：" + fileSize + "Byte ,允許的檔案大小："+ allowSize +"Byte");
            return true;
        }
        else {
            return false;
        }
    }
    catch(error){alert(error.description);return false;}
}
function FileExtensionIsReject(ctrl,allowedExtentions)
{
    
}
function ShowProgressBar()
{
    var sFeatures = "dialogWidth=400px;dialogHeight=78px;scrollbars=no;resizable=no;help=no;status=no;";
	var aInfo=Array("");
	progressWindow = window.showModalessDialog('../Tools/ProgressBar.aspx',aInfo,sFeatures);
}

function beginrefresh()
{
    var id="showTimeDiv";
    var ctrl=document.getElementById(id);
    //ctrl.style.backgroundColor="#0080ff";
    //ctrl.style.color="#ffffff";
    ctrl.style.verticalAlign="middle";
    ctrl.innerHTML="現在是："+showtime();
    setTimeout("beginrefresh()",1000);
}

function showtime()
{
var now = new Date()
var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()
var timeValue = (now.getFullYear()-1911)+" 年 "+(now.getMonth()+1) +" 月 "+now.getDate()+" 日 ( "+GetCultureWeekName(now.getDay())+" ) ";
if(hours>=1 && hours <4)
{timeValue += ("凌晨")}
if(hours>=4 && hours<6)
{timeValue += ("清晨")}
if(hours>=6 && hours<9)
{timeValue += ("早上")}
if(hours>=9 && hours<12)
{timeValue += ("上午")}
if(hours>=12 && hours<13)
{timeValue += ("中午")}
if(hours>=13 && hours<18)
{timeValue += ("下午")}
if(hours>=18 && hours <19)
{timeValue += ("傍晚")}
if(hours>=19 && hours <24)
{timeValue += ("晚上")}
if(hours<1)
{timeValue += ("午夜")}
timeValue  += ((hours > 12) ? hours - 12 : hours)
timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
return timeValue
}
function GetCultureWeekName(weekIindex)
{
    var weekName=Array('日','一','二','三','四','五','六');
    return weekName[weekIindex];
}
function GetSelectedIndex(oo,textValue)
{
            for(i=0;i<oo.options.length;i++)
            {
                if(oo.options[i].text==textValue)
                {
                    oo.options[i].selected=true;
                    return;
                }
            }
}

function hidNews(ctrl)
{
   if(ctrl.innerText.indexOf("隱藏公告內容") >-1)
    return;
   var bChar="title=";
   var bIndex=ctrl.innerHTML.toLowerCase().indexOf(bChar);
   var eIndex=ctrl.innerHTML.toLowerCase().indexOf(" ",bIndex);
   var id=ctrl.innerHTML.substr(bIndex,eIndex-bIndex).replace(bChar,"");
   NewsWebService.HidPsotData(id,OnComplete,OnError); 
}

function OnComplete(result)
{
    window.status="您是這份公告第 "+result+" 位閱讀者。祝，網路閱讀順利！";
}
function OnError(result)
{
}
function doClick(linkId){
 
  var o = document.getElementById(linkId);   
  if(document.all && typeof(document.all) == "object")   //IE   
  {   
        o.fireEvent("onclick");   
  }   
  else   
  {   
        var   e   =   document.createEvent('MouseEvent');   
        e.initEvent('click',false,false);   
        o.dispatchEvent(e);   
    }
}
function GetCurrentFormatDate(separate)
{
    var date=new Date();
    var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	return y+separate+LZ(M)+separate+LZ(d);
}
function LZ(n) {
return (n > 9 ? n : '0' + n);
}
