function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//預載滑鼠變換圖片之用
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Function to change page from option list
function linkURL(URL) {
	
	if (URL.options[URL.selectedIndex].value != "") self.location.href = URL.options[URL.selectedIndex].value;	
	return true;
}

//Function to open pop up window
function winOpener(theURL, winName, scrollbars, resizable, width, height) {
	
	winFeatures = 'left=' + (screen.availWidth-10-width)/2 + ',top=' + (screen.availHeight-30-height)/2 + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',width=' + width + ',height=' + height + ',toolbar=0,location=0,status=1,menubar=0'
  	window.open(theURL, winName, winFeatures);
}

//2006.08.14補充用於HTML靜態頁面插入Java Script之用
function chkdiv(divid){
	var chkid=document.getElementById(divid);
	if(chkid != null){return true; }
	else {return false; }
}

//2006.12.24補充用於新版FLASH播放。flashWrite(,,,,,, )
function flashWrite(url,w,h,id,bg,vars,win){

	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='FlashVars' value='"+vars+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='menu' value='false' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";

	document.write(flashStr);
}

//2007.02.07補充用於主選項下轄細部選項內容
function FuncList(id) {

  var listNews = '私人訊息‧個人控制台‧我的文章‧記事本‧好友名單‧文章收藏匣';
  var listClear = '';
  
  funcContent = document.getElementById('myMainMenuList');
  
  if (id==4){
    funcContent.innerHTML = listNews;
  } else {
    funcContent.innerHTML = listClear;
  }
}















//2007.05.02補充用於加入會員時的資料判斷
//身份證檢查
//-------------------------------
//檢查身份證是否正確
//return value:true or false
//-------------------------------
function isNID(num){

	num=num.toUpperCase();

	patten=/^[A-Z][12][0-9]{8}$/;
	if(patten.test(num)){
		h="ABCDEFGHJKLMNPQRSTUVXYWZIO";
		x=10+h.indexOf(num.substring(0,1));
		chksum=(x-(x%10))/10+(x%10)*9;
		
		for(i=1;i<9;i++){
			chksum+=num.substring(i,i+1)*(9-i);
			} 
		chksum=(10-chksum%10)%10 ;
      
		if(chksum==num.substring(9,10))return true;
		}
	return false;
	}

//E-mail檢查
//-------------------------------
//檢查E-mail是否正確有.@等
//return value:true or false
//-------------------------------
function isEmail(mail) {
	mail = mail.toLowerCase();
	
	patten=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	if(!patten.test(mail)){
		return false;
		}
	return true;
	}
	
//文數字檢查1
//-------------------------------
//檢查字串是否含任一 [a-zA-Z0-9_] 
//return value:true or false
//-------------------------------
function isanyEstr(Qstr) {
	patten=/\w/;
	if(!patten.test(Qstr)){
		return false;
		}
	return true;
	}

//文數字檢查2
//-------------------------------
//檢查字串是否每一個皆為 [a-zA-Z0-9_] 
//return value:true or false
//-------------------------------
function isEstr(Qstr) {
	patten=/\w/;
	for (i = 0;i < Qstr.length; i++ ){
		if(!patten.test(Qstr.charAt(i))){
			return false;
			break;
			}
		}
	return true;
	}

//數字檢查
//-------------------------------
//檢查字串是否每一個皆為 [0-9] 
//return value:true or false
//-------------------------------
function isNstr(Qstr) {
	patten=/\d/;
	for (i = 0;i < Qstr.length; i++ ){
		if(!patten.test(Qstr.charAt(i))){
			return false;
			break;
			}
		}
	return true;
	}

//去除頭尾空白
//-------------------------------
//去除頭尾空白
//return value:除去空白後的字串
//-------------------------------
function trim(unCstr){
	var Cstr;
	var charTemp;
	var i;

	Cstr = '';

	for ( i = 0; i < unCstr.length; i++ ){
		charTemp = unCstr.charAt(i);
		if ( charTemp != ' ' ){
			Cstr = unCstr.substring(i);
			break;
			}
		}

	for ( i = Cstr.length-1; i >= 0; i-- ){
		charTemp = Cstr.charAt(i);
		if ( charTemp != " " ){
			Cstr = Cstr.substring(0,i+1);
			break;
			}
		}
		return (Cstr);
	}
	
//查詢是否14歲以上
//-------------------------------
//與今天比較，是否是十四歲以上
//return value:boolean
//-------------------------------
function isLegalAge(yy,mm,dd){
	if ( !isNstr(yy) || !isNstr(mm) || !isNstr(dd) ) {
		return false;
		}
	today = new Date();
	tyy = today.getYear();
	year = (tyy < 1000) ? tyy + 1900 : tyy;
	month = today.getMonth() + 1;
	month = String(month);
	month = (month.length <2 ) ? "0"+month : month;
	date  = today.getDate();
	date = String(date);
	date = (month.length < 2 ) ? "0"+date : date;
	Lage = String((year-14) + "/" + month + "/" + date);
	Sage = String((yy + "/" + mm + "/" + dd));

	if ( Sage > Lage ){
		return false;
		}
	return true;
	}
	
//算出合法的日期
//-------------------------------
//每月顯示日數不同，僅顯示出合法的日期。
//return value:option values of 日期欄位
//-------------------------------
function changeDays(fm) {
	mth = fm.DOBmonth.selectedIndex-1;
	sel = fm.DOByear.selectedIndex;
	yr = fm.DOByear.options[sel].text;
	numDays = numDaysIn(mth,yr)+1;
	
	fm.DOBday.options.length = numDays;
	for (i=27;i<numDays;i++){
		fm.DOBday.options[i].text = i;
		fm.DOBday.options[i].value = i;
		}
	}
	
function changeDaysSlotDate(fm) {
	mth = fm.SlotDateMonth.selectedIndex-1;
	sel = fm.SlotDateYear.selectedIndex;
	yr = fm.SlotDateYear.options[sel].text;
	numDays = numDaysIn(mth,yr)+1;
	
	fm.SlotDateDay.options.length = numDays;
	for (i=27;i<numDays;i++){
		fm.SlotDateDay.options[i].text = i;
		fm.SlotDateDay.options[i].value = i;
		}
	}
	
function changeDaysStopDate(fm) {
	mth = fm.StopDateMonth.selectedIndex-1;
	sel = fm.StopDateYear.selectedIndex;
	yr = fm.StopDateYear.options[sel].text;
	numDays = numDaysIn(mth,yr)+1;
	
	fm.StopDateDay.options.length = numDays;
	for (i=27;i<numDays;i++){
		fm.StopDateDay.options[i].text = i;
		fm.StopDateDay.options[i].value = i;
		}
	}
	
function changeDaysSellDate(fm) {
	mth = fm.SellDateMonth.selectedIndex-1;
	sel = fm.SellDateYear.selectedIndex;
	yr = fm.SellDateYear.options[sel].text;
	numDays = numDaysIn(mth,yr)+1;
	
	fm.SellDateDay.options.length = numDays;
	for (i=27;i<numDays;i++){
		fm.SellDateDay.options[i].text = i;
		fm.SellDateDay.options[i].value = i;
		}
	}

function numDaysIn(mth,yr){
	if (mth==3 || mth==5 || mth==8 || mth==10) return 30;
	else if ((mth==1) && leapYear(yr)) return 29;
	else if (mth==1) return 28;
	else return 31;
	}
	
function leapYear(yr){
	if (((yr % 4 == 0) && yr % 100 != 0) || yr % 400 == 0) return true;
	else return false;
	}





















//開啟跳出視窗
//-------------------------------
//開啟忘記帳號、密碼查詢視窗
//-------------------------------
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
	}


//Function to open preview post window
function OpenPreviewWindow(targetPage, formName){
	
	now = new Date  
	
	//Open the window first 	
   	openWin('','preview','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=no,width=680,height=400')
   		
   	//Now submit form to the new window
   	formName.action = targetPage + "?ID=" + now.getTime();	
	formName.target = "preview";
	formName.submit();
	}


//Function to open preview post window
function OpenPreviewPage(targetPage, formName){

   	formName.action = targetPage;	
	formName.target = "frontAdminPage";
	formName.submit();
        return;
	}


function OpenSelfPage(targetPage, formName){

   	formName.action = targetPage;	
	formName.target = "_self";
	formName.submit();
        return;
	}

//開啟一個新視窗
function popwin(targetPage, formName, W, H){
	var dowin = targetPage != "" ? true : false;
	if (dowin)
	{
		if ((window.screen.width < W) || (window.screen.height < H)){
			var windowW = 800;
			var windowH = 600;						
		}
		else
		{
			var windowW = W;
			var windowH = H;
		}
		
		if (window.screen.width < 800)
		{
			windowW = Math.ceil(window.screen.width * 0.9) ;
			windowH = Math.ceil(window.screen.height * 0.9) ;
		}
                
		var windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
		var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
    	        
		if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4)
			isie=true
		else
			isie=false

		if (isie)
		{
			windowH=windowH+20+2; windowW=windowW+2;
		}
                
		s = ",width="+windowW+",height="+windowH;
                
		if (isie && (navigator.userAgent.toLowerCase().indexOf("win")!=-1) )
		{
		
			splashWin = window.open("", "gwpay", "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0"+s);
			splashWin.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
			splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) );
                
		   	//傳送表單值至新視窗
		   	formName.action = targetPage;	
			formName.target = "gwpay";
			formName.submit();
		}
		else
		{
			var splashWin = window.open("", "gwpay", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);

		   	//傳送表單值至新視窗
		   	formName.action = targetPage;	
			formName.target = "gwpay";
			formName.submit();
		}
	}
	else
	{
		alert ("連結網址出錯，請檢查！");
	}

}

//開啟一個自動拉霸的新視窗
function popwin_auto(targetPage, formName, W, H){
	var dowin = targetPage != "" ? true : false;
	if (dowin)
	{
		if ((window.screen.width < W) || (window.screen.height < H)){
			var windowW = 800;
			var windowH = 600;						
		}
		else
		{
			var windowW = W;
			var windowH = H;
		}
		
		if (window.screen.width < 800)
		{
			windowW = Math.ceil(window.screen.width * 0.9) ;
			windowH = Math.ceil(window.screen.height * 0.9) ;
		}
                
		var windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
		var windowY = Math.ceil( (window.screen.height - windowH) / 2 );
    	        
		if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4)
			isie=true
		else
			isie=false

		if (isie)
		{
			windowH=windowH+20+2; windowW=windowW+2;
		}
                
		s = ",width="+windowW+",height="+windowH;
                
		if (isie && (navigator.userAgent.toLowerCase().indexOf("win")!=-1) )
		{
		
			splashWin = window.open("", "gwpay", "fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0"+s);
			splashWin.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
			splashWin.moveTo  ( Math.ceil( windowX ) , Math.ceil( windowY ) );
                
		   	//傳送表單值至新視窗
		   	formName.action = targetPage;	
			formName.target = "gwpay";
			formName.submit();
		}
		else
		{
			var splashWin = window.open("", "gwpay", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0"+s, true);

		   	//傳送表單值至新視窗
		   	formName.action = targetPage;	
			formName.target = "gwpay";
			formName.submit();
		}
	}
	else
	{
		alert ("連結網址出錯，請檢查！");
	}

}

