
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){
	
if(TotalPage!=1){
//document.write("<table  cellspacing=0 cellpadding=2 ><tr ><td bgcolor=black nowarp><font color=white size=2>Page: "+PageIndex+"/"+TotalPage+"&nbsp;</td>");
document.write("<table  cellspacing=0 cellpadding=2><tr >");
if (PageIndex>1)
	document.write("<td  nowarp><a target='_self' class='font_2_white bold' style='TEXT-DECORATION: underline' href=?page="+(PageIndex-1)+"&"+url+">"+Previous+"</a></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_red' valign='bottom'>&nbsp;"+ i +"&nbsp;</td>");}else{document.write("<td  >&nbsp;<a  target='_self' class='font_2_white bold' style='TEXT-DECORATION: underline' href=?page="+i+"&"+url+">"+ i +"</a>&nbsp;</td>");}
}
}
if (PageIndex<TotalPage)
document.write("<td><a  target='_self' class='font_2_white bold' style='TEXT-DECORATION: underline' href=?page="+(PageIndex+1)+"&"+url+">"+Next+"</a>&nbsp;</td>");
document.write("</tr></table>");
}
}

function ShowPageYellow(TotalPage,PageIndex,url){
	
if(TotalPage!=1){
//document.write("<table  cellspacing=0 cellpadding=2 ><tr ><td bgcolor=black nowarp><font color=white size=2>Page: "+PageIndex+"/"+TotalPage+"&nbsp;</td>");
document.write("<table  cellspacing=0 cellpadding=2><tr >");
if (PageIndex>1)
	document.write("<td  nowarp><a target='_self' class='topyellow' href=?page="+(PageIndex-1)+"&"+url+">"+Previous+"</a></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='topblue' valign='bottom'>&nbsp;"+ i +"&nbsp;</td>");}else{document.write("<td  >&nbsp;<a  target='_self' class='topyellow' href=?page="+i+"&"+url+">"+ i +"</a>&nbsp;</td>");}
}
}
if (PageIndex<TotalPage)
document.write("<td><a  target='_self' class='topyellow' href=?page="+(PageIndex+1)+"&"+url+">"+Next+"</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)
{
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">');
  if (bgColor=="") {
    document.write('<param name="wmode" value="transparent">');
    document.write('<embed src='+URL+' width='+width+' height='+Height+' menu="false" quality="high" wmode="transparent" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" 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" bgcolor='+bgColor+' pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" 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




//<script language="javascript">CreateFlash("media","","435","350","<? echo $movie; ?>")</script>   
function CreateFlash(ObjectID, bgColor, width, Height, URL)
{
document.write('<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="https://fpdownload.macromedia.com/get/shockwave/cabs/flash/swflash.cab#version=8,0,22,0" id='+ObjectID+' width='+width+' height='+Height+'>');
document.write('<param name="movie" value='+URL+'>');
document.write('<param name="menu" value="false">');
document.write('<param name="quality" value="high">');
  if (bgColor=="") {
    document.write('<param name="wmode" value="transparent">');
    document.write('<embed src='+URL+' width='+width+' height='+Height+' menu="false" quality="high" wmode="transparent" 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+' width='+width+' height='+Height+' menu="false" quality="high" bgcolor='+bgColor+' pluginspage="https://www.macromedia.com/go/getflashplayer" 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');

}




function del_guid(tableID, rowIndex, db, guid){
//檢查郵件是否已經註冊過
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
      try {
        // 新版的 IE
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          // 舊版的 IE
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
      }
			
    }
	http_request.open('GET', 'del_guid.php?guid='+guid+'&db='+db , false);
	http_request.send(null);
	var content_text = http_request.responseText;
	//content_text = content_text.replace(/\r/g,"");
	//alert (content_text);
//	window.top.location.reload();
	var   table   =document.all[tableID]   
	table.deleteRow(rowIndex);   
}




//影片播放
 function change(id, flashURL){
 	//CreateFlash('abc', '', 400, 350, flash, '')
	var flashvars = {  
		autostart: "true",
		file: flashURL
		//color1: "0x2b405b",  
		//color2: "0x6b8ab6",
		//border: "1"		
		};
	var params = {  
		menu: "false",
		wmode: "transparent",
		allowfullscreen : "true"
	};
	swfobject.embedSWF('player.swf', id, "229", "198", "9.0.0","expressInstall.swf", flashvars, params);
	
 }

function play_flv_embed(id,noneid,flashURL){
 	//CreateFlash('abc', '', 400, 350, flash, '')
	document.cookie='';
	var flashvars = {  
		autostart: "true",
		file: flashURL
		//color1: "0x2b405b",  
		//color2: "0x6b8ab6",
		//border: "1"		
		};
	var params = {  
		menu: "false",
		wmode: "transparent",
		allowfullscreen : "true"
	};
	swfobject.embedSWF('player.swf', id, "229", "198", "9.0.0","expressInstall.swf", flashvars, params);
	
	//Start Hide DIV
	if ((document.getElementById(noneid).style.display=='none')||(document.getElementById(noneid).style.display=='block')||(document.getElementById(noneid).style.display=='')){
		document.getElementById(noneid).style.display='none';
	}
	
}

function play_wmv(id,noneid,WMVUrl){
contenttxt = "<object id='MediaPlayer' width='229px' height='198px' classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' standby='Loading Windows Media Player components...' type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'> 		<param name='filename' value='"+WMVUrl+"'>			<param name='Showcontrols' value='True'>			<param name='autoStart' value='True'>			<param name='AutoSize' value='False'>			<param name='showstatusbar' value='True'>			<param name='StretchToFit' value='true'>			<embed type='application/x-mplayer2' src='"+WMVUrl+"' name='MediaPlayer' width='229' height='198' Showcontrols=1 StretchToFit='1' AutoSize='0'  showstatusbar='1' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/'></embed>			</object>";

	//Start display movie DIV
	if (document.getElementById(id).style.display=='none'){
		document.getElementById(id).style.display='block';
	}
	//Start Hide DIV
	if ((document.getElementById(noneid).style.display=='block')||(document.getElementById('videos_detail').style.display=='')){
		document.getElementById(noneid).style.display='none';
	}
	//Put the Object and value
	document.getElementById(id).innerHTML = "";
	document.getElementById(id).innerTEXT = "";
	document.getElementById(id).innerHTML = contenttxt ;
}

//清除輸入框，移走後還原，並且把屬性改成密碼框
function clickclear(thisfield, defaulttext) {
		
	if (thisfield.value == defaulttext) 
		thisfield.value = '';

	if(navigator.userAgent.indexOf("MSIE")>0) { 
		//alert(thisfield.name);
		if(thisfield.name=='password'){ //如果是密碼欄位才需要改成密碼框
			
			var newobj = changeInputType(thisfield,'password');
		}else{	
			var newobj = changeInputType(thisfield,'text');
			
		}
		setTimeout('document.getElementById("'+newobj.name+'").focus();',10); 
	}else{
		if(thisfield.getAttribute('name') == 'password'){
			thisfield.setAttribute('type','password');
		}	
	}
}

//清除輸入框，移走後還原
function clickrecall(thisfield, defaulttext) {
	//if(thisfield.getAttribute('type')!='password'){
	if (thisfield.value == ''){
		thisfield.value = defaulttext;
		//alert(defaulttext);
		if(navigator.userAgent.indexOf("MSIE")>0) { 
			changeInputType(thisfield,'text');
		}else{
			thisfield.setAttribute('type','text');
		}	
	}
}


function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
	if(oldObject.onclick) newObject.onclick = oldObject.onclick;
	if(oldObject.onblur) newObject.onblur = oldObject.onblur;
	//alert(oldObject.onclick);
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}




