
function open_win(url,popW,popH){
var   w = screen.availWidth;
var   h = screen.availHeight;
//var popW = 400, popH = 250;
var leftPos = (w-popW)/2 ;
var topPos = (screen.availHeight-popH)/2;
window.open(url,'','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',status=yes,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
// window.open(url,"","top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+(screen.width-10)+",height="+(screen.availHeight-50)+"");
}



//跳轉頁面顯示
function ShowPage(TotalPage,PageIndex,url){
//document.write("<table  cellspacing=0 cellpadding=2 ><tr ><td bgcolor=black nowarp><font color=white size=2>頁數: "+PageIndex+"/"+TotalPage+"&nbsp;</td>");
document.write("<table  cellspacing=0 cellpadding=2><tr ><td  nowarp class='font_2_black'>頁數: </td>");
if (PageIndex<6){PageLong=11-PageIndex;}
else
if (TotalPage-PageIndex<6){PageLong=10-(TotalPage-PageIndex)}
else{PageLong=5;}
for (var i=1; i <= TotalPage; i++) {
if (i < PageIndex+PageLong && i > PageIndex-PageLong || i==1 || i==TotalPage){
if (PageIndex==i){document.write("<td class='font_2_black'>&nbsp;"+ i +"&nbsp;</td>");}else{document.write("<td  >&nbsp;<a style='TEXT-DECORATION: underline' href=?page="+i+"&"+url+"><font face=arial color=blue>"+ i +"</a>&nbsp;</td>");}
}
}
document.write("</tr></table>");
}





function fiximgwin(url){ 
//打開一個空白視窗，並初始化大小 
   w = screen.availWidth;
   h = screen.availHeight;
var popW = 200, popH = 250;
var leftPos = (w-popW)/2, topPos = (h-popH)/2-100;
 var imgwin=window.open('','img','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos,'status=no');
 var doc=imgwin.document 
  doc.write("<div id=loading><br><br><br><br><br><br><center>圖片讀取中...</div>")   
imgwin.focus() //使視窗聚焦，成為當前視窗 
//在圖片載入完後調用resizeTo()和 moveTo()方法調整視窗大小和位置 
 var HTML="<html>\r\n<head>\r\n<title>圖片瀏覽</title>\r\n</head>\r\n<body  leftmargin=\"0\" topmargin=\"0\">\r\n<img style='display:none' id=myimg src=\""+url+"\" onload=\"myimg.style.display='block';window.resizeTo(this.width+10,this.height+46);window.moveTo((screen.width-this.width)/2,(screen.height-this.height)/2-100);loading.style.display='none';\">\r\n</body>\r\n</html>" 
//var doc=imgwin.document 
 doc.write(HTML)           //向空白視窗寫入代碼 
 doc.close()                //關閉，並強制發送資料顯示。 
 } 


//只能輸入數字
function check_number(value){
　var re = /^\d+$/;
　if (!re.test(value)) {
　　return false;
　} else {
　　return true;
　}
}



function LTrim(str)
{
var whitespace = new String(" tnr");
var s = new String(str);
 
if (whitespace.indexOf(s.charAt(0)) != -1)
{
var j=0, i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
{
j++;
}
s = s.substring(j, i);
}
return s;
}
 

function RTrim(str)
{
var whitespace = new String(" tnr");
var s = new String(str);
 
if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
{
var i = s.length - 1;
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
{
i--;
}
s = s.substring(0, i+1);
}
return s;
}
 

function Trim(str)
{
return RTrim(LTrim(str));
}


function changebg(name,int){
if (int==1){
name.bgColor="red";
}else {
name.bgColor="#FFCC00";
}
}




function CreateFlash(ObjectID, bgColor, width, Height, URL, FlashVars)
{
//	alert(FlashVars);
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id='+ObjectID+' width="'+width+'" height="'+Height+'">');
document.write('<param name="movie" value='+URL+'>');
document.write('<param name="FlashVars" value="'+FlashVars+'">');
document.write('<param name="menu" value="false">');
document.write('<param name="quality" value="high">');
document.write('<param name="allowScriptAccess" value="sameDomain">');
  if (bgColor=="") {
    document.write('<param name="wmode" value="transparent">');
    document.write('<embed src="'+URL+'"  FlashVars="'+FlashVars+'" width="'+width+'" height="'+Height+'" menu="false" quality="high" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
  } else {
    document.write('<param name="bgcolor" value="'+bgColor+'">');
    document.write('<embed src="'+URL+'" FlashVars="'+FlashVars+'" width="'+width+'" height="'+Height+'" menu="false" quality="high" scale="NoScale" bgcolor="'+bgColor+'" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
  }
document.write('</object>');
}

	//用來記錄目前所勾選的checkbox
	var currentSelected = "";
	//chooseOne()函式，參數為觸發該函式的元素本身
	function chooseOne(cb) {
		//先判斷是否有點選過任何的checkbox
		//若有的話，把原先的變為未勾選
		if(currentSelected!="")	currentSelected.checked = false;
		//變更目前勾選的checkbox
		if(cb.checked)	currentSelected = cb;
		else	currentSelected="";
	}




/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 * 
 */
 var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function




function CreateFlash(ObjectID, bgColor, width, Height, URL, FlashVars)
{
//	alert(FlashVars);
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" id='+ObjectID+' width="'+width+'" height="'+Height+'">');
document.write('<param name="movie" value='+URL+'>');
document.write('<param name="FlashVars" value="'+FlashVars+'">');
document.write('<param name="menu" value="false">');
document.write('<param name="quality" value="high">');
document.write('<param name="allowScriptAccess" value="sameDomain">');
  if (bgColor=="") {
    document.write('<param name="wmode" value="transparent">');
    document.write('<embed src="'+URL+'"  FlashVars="'+FlashVars+'" width="'+width+'" height="'+Height+'" menu="false" quality="high" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
  } else {
    document.write('<param name="bgcolor" value="'+bgColor+'">');
    document.write('<embed src="'+URL+'" FlashVars="'+FlashVars+'" width="'+width+'" height="'+Height+'" menu="false" quality="high" scale="NoScale" bgcolor="'+bgColor+'" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed>');
  }
document.write('</object>');
}


function NewWindow(mypage, myname,popW, popH, scroll) {
var   w = screen.availWidth;
var   h = screen.availHeight;
//var popW = 400, popH = 250;
var leftPos = (w-popW)/2 ;
var topPos = (screen.availHeight-popH)/2;
window.open(mypage,myname,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',status=yes,location=no,toolbar=no,menubar=no,scrollbars='+scroll+',resizable=yes');

}
