﻿
//取得網址參數
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
 // alert('Query Variable ' + variable + ' not found');
}

function trim (s)
{
   //   /            open search
   //     ^            beginning of string
   //     \s           find White Space, space, TAB and Carriage Returns
   //     +            one or more
   //   |            logical OR
   //     \s           find White Space, space, TAB and Carriage Returns
   //     $            at end of string
   //   /            close search
   //   g            global search

   return s.replace(/^\s+|\s+$/g, "");
}

function LeftTrim(s){
    return s.replace(/(^\s*)/g, "");
}

function RightTrim(s){
    return s.replace(/(\s*$)/g, "");
}

function string_match(sPattern,sValue) {
	var regexp = new RegExp(sPattern, "g");
	var matched = sValue.match(regexp);
	if (matched) {
		return (true);
	}
	else {
		return (false);
	}
}

function  Runner(sDivName,FirstTD,SecondTD)
{
	//變數Speed為設定捲軸的速度用 越小越快
		var Speed=50;
		//接受setInterval所回傳的值
		var timer;
		//取得myDiv的參考用的變數
		var myDiv = document.getElementById(sDivName);
		//取得pic2的參考用的變數
		var pic2= document.getElementById(SecondTD);
		//var pic1= document.getElementById(FirstTD);
		//讓pic2的innerHTML等於pic1的innerHTML
		pic2.innerHTML=document.getElementById(FirstTD).innerHTML;
		//用來捲動myDiv捲軸用的主程式
	
		//alert(pic2.style.height);//=pic1.offsetHeight;
		//var iCount=0;
		function picMarquee(){
			//若pic2的高小於myDiv的scrollTop，表示捲軸已經過了第一行
			//所以讓Div的scrollTop再回到原來的位置；反之 則繼續往下跑
			
			//if(iCount!=4){alert(pic1.offsetHeight);}
			
			if(pic2.offsetHeight - myDiv.scrollTop <= 0){
				myDiv.scrollTop = 0;
			}else{
				myDiv.scrollTop++;
			}
			//iCount++;
		}
		//每Speed毫秒就執行一次pciMarquee()
		timer=setInterval(picMarquee,Speed);
		//當滑鼠在myDiv上時 就停止捲動
		myDiv.onmouseover=function() {
			clearInterval(timer);
		}
		//當滑鼠離開myDiv上時 就繼續往下捲動
		myDiv.onmouseout=function() {
			timer=setInterval(picMarquee,Speed);
		}
		
			
}

function subShowDiv(sDivID,sHidDivID){
    var oDiv = document.getElementById (sDivID);
    var oHid = document.getElementById (sHidDivID);
    //alert(oDiv);
    //alert(oHid.value);
    if(trim(oHid.value).length>0){
        if(trim(oHid.value)==0){
            oDiv.style.display="";
            oHid.value="1";
        }else{
            oDiv.style.display="none";
            oHid.value="0";
        }
    }

}

function subShowDiv(sDivID,sHidDivID,sImgID){
    var oDiv = document.getElementById (sDivID);
    var oHid = document.getElementById (sHidDivID);
    var oImg = document.getElementById (sImgID);
    //alert(oDiv);
    //alert(oHid.value);
    if(trim(oHid.value).length>0){
        if(trim(oHid.value)==0){
            oDiv.style.display="";
            oHid.value="1";
            oImg.src=JS_SYS_IndexUrl+"App_Themes/Common/images/doc_5.jpg";
        }else{
            oDiv.style.display="none";
            oHid.value="0";
            oImg.src=JS_SYS_IndexUrl+"App_Themes/Common/images/doc_4.jpg";
        }
    }

}

function subShowByID(sDivID){
    var sID = "ctl00_" + sDivID;   
    var oDiv = document.getElementById(sID);
    if(oDiv){
        //alert(oDiv.style.display);
        if (oDiv.style.display=="none"){
            $("#"+sID).slideDown("fast");
            //$("#"+sID).show();
            //oDiv.style.display="";
        }else{
            $("#"+sID).hide();
        }        
    }
}

function subShowByClass(sDivID,sClassID){
    var sID = "ctl00_" + sDivID;   
    var oDiv = document.getElementById(sID);
    if(oDiv){
        //alert(oDiv.style.display);
        if (oDiv.style.display=="none"){
            $("."+sClassID).slideDown("fast");
            //$("#"+sID).show();
            //oDiv.style.display="";
        }else{
            $("."+sClassID).hide();
        }        
    }
}



//收合選單切換
function Floating_sw(sDivID,sIconID,sLang){
    //sDivID:Floating_div,sIconID:Floating_icon_img,iWidth:180
    var Content = document.getElementById(sDivID);
    if (Content.style.display != ''){
        Content.style.display='';
        document.getElementById(sIconID).src= JS_SYS_IndexUrl + 'App_Themes/Theme_Base/images/' + sLang + '/close.jpg';
    }else{
        Content.style.display='none';
        document.getElementById(sIconID).src= JS_SYS_IndexUrl + 'App_Themes/Theme_Base/images/' + sLang + '/open.jpg';
    }
}

//設定現在時間
var ttimer;
function Refresh(sID)
{
//alert(sID)
 var newDateObj = new Date();
 var oTxt =  document.getElementById (sID);
 if (oTxt){
 var sStr=newDateObj.getFullYear() + '/' + (newDateObj.getMonth() + 1) + '/' + newDateObj.getDate() + '  ' +  newDateObj.getHours() + ':' + newDateObj.getMinutes() ;
 //+ ':' + newDateObj.getSeconds()
 oTxt.innerHTML= sStr;
 ttimer= setTimeout("Refresh('lblNow')",5000);
 }
}

//顯示Flash
function OpenWin(iWidth,iHeight,sLang,sType,sTitle,sVars)
{
    var sUrl;
    if(!sLang)
    {
        sLang="en-us";
    }
    
    sUrl = JS_SYS_IndexUrl + "Flash.aspx?Lang=" + sLang + "&Type=" + sType + "&Width=" + iWidth + "&Height=" + iHeight + "&Title=" + sTitle ;
    if(sVars){sUrl=sUrl+"&Vars=" + sVars;}
     
    window.open(sUrl,'','location=no,status=no,menubar=no,scrollbars=no,resizable=yes,left=100,width='+iWidth+',height='+iHeight);
}

function OpenWinForVR(iWidth,iHeight,sID,sTitle)
{
    var sUrl;
    
    sUrl = JS_SYS_IndexUrl + "VR.aspx?ID=" + sID + "&Width=" + iWidth + "&Height=" + iHeight + "&Title=" + sTitle ;
     
    window.open(sUrl,'','location=no,status=no,menubar=no,scrollbars=no,resizable=yes,left=100,width='+iWidth+',height='+iHeight);
}

function OpenWinForeBook(sID,sUrl){
    window.open (sUrl, 'eBookViewer_'+sID , 'height=600, width=768, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');
}


//CheckBoXList 全選
function Select_all(CheckBox_ID,CheckBoxList_ID) {
    var oAllCheck = document.getElementById(CheckBox_ID);
       
    if(oAllCheck.checked){
        var table = document.getElementById(CheckBoxList_ID);
        //alert(table.rows[0].cells.length)
        for(r=0;r<table.rows.length;r++){
            for(c=0;c<table.rows[r].cells.length;c++){
                var oChk =table.rows[r].cells[c].childNodes[0];
                if(oChk){
                    oChk.checked = true;
                }   
            }
        }
    }else{
        var table = document.getElementById(CheckBoxList_ID);
        for(r=0;r<table.rows.length;r++){
            for(c=0;c<table.rows[r].cells.length;c++){
                var oChk =table.rows[r].cells[c].childNodes[0];
                if(oChk){
                    oChk.checked = false;
                }                    
            }
        }
    }

}

//PURPLE ADD  START

//連絡我們後端表單驗證
function Check_Email(RadioButton2_ID,RadioButton3_ID,sEmail)
{
var oRdo2 = document.getElementById(RadioButton2_ID);
var oRdo3 = document.getElementById(RadioButton3_ID);
//var oEmail = document.getElementById(Label_ID);
//alert(oRdo.value);
//alert(trim(sEmail).length);
  
    if(trim(sEmail).length < 1)
    {
             //alert("終於進來了");
         alert("沒有電子郵件網址可以回覆");
         oRdo2.checked = true;
         oRdo3.checked = false;        
    }
     
}
//連絡我們後前端意件 內容字數<500
function validateLength(oSrc,args)
{
     args.IsValid = (args.Value.length < 500);
}



//PURPLE ADD  END


/*問題諮詢*/
function OpenWin_Question(sPID){
    window.open('Question.aspx?PID=' + sPID, 'popupwindow', 'width=520,height=580,scrollbars,resizable');
}
/*轉寄好友*/
function OpenWin_SendFriend(sPID){
    var sNowurl=location.href;
    window.open('email.aspx?url=' + escape(sNowurl) +'&PID=' + sPID, 'popupwindow', 'width=420,height=520,scrollbars,resizable');
}
/*公開說明書下載*/
function OpenWin_LoadExFile(sPID){
    window.open('../../System/GetFile.aspx?sPID=' + sPID, 'popupwindow', 'width=520,height=580,scrollbars,resizable');
}