﻿//Home Page Funcion 

//取得網址參數
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  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);
		}
		
			
}

//20061213
function NewWin(sUrl,iWidth,iHeight)
{
    window.open(sUrl,'','location=no,status=no,menubar=no,scrollbars=no,resizable=no,left=100,width='+iWidth+',height='+iHeight);
}

function HiddenStatus()
{
window.status=' ';
return true
}

//send to friend
function func_send_friend(sindexurl,slang)
{
    
    var sNowurl=location.href;
    var sUrl=sindexurl+"Forward.aspx?url="+escape(sNowurl)+"&Lang="+slang;
    
    window.open(sUrl,'','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=100,width=450,height=430');
}

//FriendPrint友善列印func
//2006.12.2 六 13:17 Fion
function func_friend_print()
{
    var sNowUrl=location.href;
    var sQueryStr=sNowUrl.split("?")[1];
    
    if (sNowUrl)
    {
        if(sQueryStr)//有參數
        {
            sNowUrl+="&";
        }
        else
        {
            sNowUrl+="?";
        }
        
        sNowUrl+="shwtyp=FP"
        
        
       window.open(sNowUrl,'','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=100,width=640,height=480');
    }

}

//首頁Flash連絡到各搖尾羊做的Flash子層中
function goflash(sLang,ID,sType)
{
    //Type:Trans=交通,Hall展館
    var sUrl;
    if(sType=="Trans")
    {
        sType="Transportation";
    }
    sUrl="/DB/Flash/Flash.aspx?Lang="+sLang+"&Type="+sType+"&ID="+ID;
    window.open(sUrl,'','location=no,status=no,menubar=no,scrollbars=no,resizable=no,left=100,width=800,height=600');
}



//會議室洽訂Form Onsubmit (Conference.aspx)
//2006.11.28 二 18:27 Fion
function Conference_Form_onSubmit(oForm)
{
    var aTemp=Array();
    var aConference;
    aConference = Array("401","402","402a","402b","402c","403","501","502","503","504","504a","504b","504c");

    var aMsg_zh= new Array();
    var aMsg_en= new Array();
    var aMsg_ja= new Array();
    
	aMsg_zh[0]="請選擇會議室編號";				//TemplateID
    aMsg_zh[1]="請填寫欲申請時間之起始時間";
    aMsg_zh[2]="請填寫欲申請時間之結束時間";
    aMsg_zh[3]="起始時間必需大於今天";
    aMsg_zh[4]="結束時間必需大於等於起始時間";
    aMsg_zh[5]="請填寫姓名";
    aMsg_zh[6]="請填寫電話國碼";
    aMsg_zh[7]="請填寫電話區碼";
    aMsg_zh[8]="請填寫電話號碼";
    aMsg_zh[9]="請填寫您的E-Mail";
    aMsg_zh[10]="您的E-Mail格式不正確";
    aMsg_zh[11]="請選擇申請用途";
    aMsg_zh[12]="請輸入用途說明";
    aMsg_zh[13]="用途說明不可超過250字";
    aMsg_zh[14]="請填寫設備數量";
    aMsg_zh[15]="設備數量格式不正確";
    
    
    aMsg_en[0]="Please select the conference room";				//TemplateID
    aMsg_en[1]="Please select start of date for using";
    aMsg_en[2]="Please select end of date for using";
    aMsg_en[3]="Start of date have to greater than Today";
    aMsg_en[4]="End of date have to greater than start of date";
    aMsg_en[5]="Please input your name";
    aMsg_en[6]="Please inupt country code of TEL";
    aMsg_en[7]="Please input area code of TEL";
    aMsg_en[8]="Please input telephone number";
    aMsg_en[9]="Please input E-Mail address";
    aMsg_en[10]="The E-Mail address you type with wrong format";
    aMsg_en[11]="Please input type of purpose you apply conference";
    aMsg_en[12]="Please input description of your purpose";
    aMsg_en[13]="Description have to less than 250 words";
    aMsg_en[14]="Please input amount of equipment you want to rent.";
    aMsg_en[15]="Amount of equipment with wrong format";
    
    
    aMsg_ja[0]="Please select the conference room";				//TemplateID
    aMsg_ja[1]="Please select start of date for using";
    aMsg_ja[2]="Please select end of date for using";
    aMsg_ja[3]="Start of date have to greater than Today";
    aMsg_ja[4]="End of date have to greater than start of date";
    aMsg_ja[5]="Please input your name";
    aMsg_ja[6]="Please inupt country code of TEL";
    aMsg_ja[7]="Please input area code of TEL";
    aMsg_ja[8]="Please input telephone number";
    aMsg_ja[9]="Please input E-Mail address";
    aMsg_ja[10]="The E-Mail address you type with wrong format";
    aMsg_ja[11]="Please input type of purpose you apply conference";
    aMsg_ja[12]="Please input description of your purpose";
    aMsg_ja[13]="Description have to less than 250 words";
    aMsg_ja[14]="Please input amount of equipment you want to rent.";
    aMsg_ja[15]="Amount of equipment with wrong format";
    
	//alert(sLanguage);
	if (sLanguage=="zh-TW")	{
	    aTemp=aMsg_zh;
	}
	else if (sLanguage=="ja-JP")	{
	     aTemp=aMsg_ja;
	}
	else{
	    aTemp=aMsg_en;
	}
	
    var Today=new Date();
    var dtNowDate=Today.getYear()+"/"+(Today.getMonth()+1)+"/"+Today.getDate();
    var iCount=0;
    var oCheckbox;
    var aDate=Array();
    
    for(var i=0; i<aConference.length; i++)
    {
        oCheckbox=eval("document.aspnetForm.chk"+aConference[i]);
        if(oCheckbox.checked==true)
       {
            iCount++;
            break;
       }
    }
    if (iCount==0)
    {
        oCheckbox=eval("document.aspnetForm.chk401");
        oCheckbox.focus();
        alert(aTemp[0]);
        return false;
    }

    //會議室設備
    //alert(document.aspnetForm.chkEquipment.length);
    var oChkEpt=document.aspnetForm.chkEquipment;
    var oTxt;
    if(oChkEpt)
    {
        for(var i=0; i <oChkEpt.length; i++)
        {
            oTxt=eval("document.aspnetForm.txtRequire_"+oChkEpt[i].value);
            if(oChkEpt[i].checked==true )
            {
                if(oTxt)
                {
                    if(trim(oTxt.value).length==0)
                    {
                        alert(aTemp[14]);
                        oTxt.focus();
                        return false;
                    }
                    
                    if(string_match("^[0-9]{1,2}$",oTxt.value)==false)
                    {
                        alert(aTemp[15]);
                        oTxt.focus();
                        return false;
                         
                    }
                    
                }
             
            }
            
        }

    }
    
    if(trim(document.aspnetForm.dtUseStartDate.value).length==0)
    {
        alert(aTemp[1]);
       document.aspnetForm.dtUseStartDate.focus();
        return false;
    }
    if(trim(document.aspnetForm.dtUseEndDate.value).length==0)
    {
        alert(aTemp[2]);//請填寫欲申請時間之結束時間
        document.aspnetForm.dtUseEndDate.focus();
        return false;
    }


       
   if(Date.parse(document.aspnetForm.dtUseStartDate.value)<=Date.parse(dtNowDate))
    {
       alert(aTemp[3]);
     //  document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_dtUseStartDate.focus();
       return false;
    }
    
    if(Date.parse(document.aspnetForm.dtUseEndDate.value)<Date.parse(document.aspnetForm.dtUseStartDate.value))
    {
       alert(aTemp[4]);//結束時間必需大於起始時間
       //document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_dtUseEndDate.focus();
       return false;
    }
    
    if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtName.value).length==0)
    {
        alert(aTemp[5]);
       document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtName.focus();
        return false;
    }
    
    if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtTelCountry.value).length==0)
    {
        alert(aTemp[6]);//請填寫電話國碼
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtTelCountry.focus();
        return false;
    }
        if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtTelArea.value).length==0)
    {
        alert(aTemp[7]);//請填寫電話區碼
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtTelArea.focus();
        return false;
    }
    if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtTelLocal.value).length==0)
    {
        alert(aTemp[8]);//請填寫電話號碼
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtTelLocal.focus();
        return false;
    }
     
     if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtEmail.value).length==0)
    {
        alert(aTemp[9]);//請填寫您的E-Mail
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtEmail.focus();
        return false;
    }
    
    if(string_match("[0-9a-zA-Z\-]+[@][0-9a-zA-Z\-]+[.][0-9a-zA-Z]",document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtEmail.value)==false)
    {
        alert(aTemp[10]);//您的E-Mail格式不正確
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtEmail.focus();
        return false;
    }
    
     if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_selForWhat.value).length==0)
    {
        alert(aTemp[11]);//請選擇申請用途
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_selForWhat.focus();
        return false;
    }
    
     if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtForWhatDescription.value).length==0)
    {
        alert(aTemp[12]);//請輸入用途說明
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtForWhatDescription.focus();
        return false;
    }
    
    if(trim(document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtForWhatDescription.value).length>250)
    {
        alert(aTemp[13]);//用途說明不可超過250字
        document.aspnetForm.ctl00_ctl00_ContentPlaceHolder1_ContentPage_conPlh_txtForWhatDescription.focus();
        return false;
    }
    
    
}
    

	
//會議室洽訂_會議室選擇JS
//20061128 一 Fion
function funcCheck(oChk)
{
	
	var aConference= new Array();
	aConference[0]=new Array(1);
	aConference[0][0]="401"				//TemplateID
	aConference[0][1]=""		            //SortID
	aConference[0][2]="401會議室"		            //SortID
	aConference[1]=new Array(1);
	aConference[1][0]="402"
	aConference[1][1]=""
	aConference[1][2]="402會議室"
	aConference[2]=new Array(1);
	aConference[2][0]="402a"
	aConference[2][1]="402"
	aConference[2][2]="402a"
	aConference[3]=new Array(1);
	aConference[3][0]="402b"
	aConference[3][1]="402"
	aConference[3][2]="402b"
	aConference[4]=new Array(1);
	aConference[4][0]="402c"
	aConference[4][1]="402"
	aConference[4][2]="402c"
	aConference[5]=new Array(1);
	aConference[5][0]="501"
	aConference[5][1]=""
	aConference[5][2]="501會議室"
	aConference[6]=new Array(1);
	aConference[6][0]="502"
	aConference[6][1]=""
	aConference[6][2]="502會議室"
	aConference[7]=new Array(1);
	aConference[7][0]="503"
	aConference[7][1]=""
	aConference[7][2]="503會議室"
	aConference[8]=new Array(1);
	aConference[8][0]="504"
	aConference[8][1]=""
	aConference[8][2]="504會議室"
	aConference[9]=new Array(1);
	aConference[9][0]="504a"
	aConference[9][1]="504"
	aConference[9][2]="504a"
	aConference[10]=new Array(1);
	aConference[10][0]="504b"
	aConference[10][1]="504"
	aConference[10][2]="504b"
	aConference[11]=new Array(1);
	aConference[11][0]="504c"
	aConference[11][1]="504"
	aConference[11][2]="504c"
	
	//TRUE---父---勾選子選單全部
	//    ---子---尚未所有子項都勾--->無作用
	//         ---所有子項都已勾選--->勾取父項
	
	//False--父--->將該父項子下的所有子項，改為未選取
	//     --子---->將其父項改為未勾選

    var sSelectTopID ;
    var oCheckbox;
	var boolAllCheck;
	
	for(var i=0; i <aConference.length ; i++)
	{
		if(aConference[i][0]==oChk.value)
		{
			sSelectTopID=aConference[i][1];
			break;
		}
	}
	
	if (oChk.checked==true) //勾選
	{
	   
	    if(sSelectTopID)//子項目
	    {
	        boolAllCheck=true;
		    for(var i=0; i <aConference.length ; i++)
		    {
			    if(aConference[i][1]==sSelectTopID)
			    {
				    oCheckbox=eval("document.aspnetForm.chk"+aConference[i][0]);
				    if(oCheckbox.checked==false){boolAllCheck=false;}
			    }
		    }
		    
		    
		    if(boolAllCheck==true )
            {
	            if(sSelectTopID)
	            {
	                oCheckbox=eval("document.aspnetForm.chk"+sSelectTopID);
	                oCheckbox.checked=true;
                }
            }          
	    }
	    else//父項目
	    {
	         for(var i=0; i <aConference.length ; i++)
		    {
			    if(aConference[i][1]==oChk.value)
			    {
				    oCheckbox=eval("document.aspnetForm.chk"+aConference[i][0]);
				    oCheckbox.checked=true;
			    }
		    }
	    }
	}
	else//取消核取
	{
	    if(sSelectTopID)//子項目
	    {
	        oCheckbox=eval("document.aspnetForm.chk"+sSelectTopID);
	        oCheckbox.checked=false;
	    }
	    else//父項目
	    {
	         for(var i=0; i <aConference.length ; i++)
		    {
			    if(aConference[i][1]==oChk.value)
			    {
				    oCheckbox=eval("document.aspnetForm.chk"+aConference[i][0]);
				    oCheckbox.checked=false;
			    }
		    }
	    }
	}
		
}
	
	
function showCalendar(sFormName,sCtrlName,iCalendarType,path,sLang) {
   //var sCalendarUrl="Calendar.asp"
   var sCalendarUrl="tool/CalendarSelector.aspx";
   var sLanguage="en-US";
   //var w = 400; 
   var w = 280; 
   var h = 225; 
   var left = (screen.width - w) / 2; 
   var top = (screen.height - h) / 2; 
   var Name=sFormName + "EINSTAND" + sCtrlName;
   var sURL="";
   
   if(sLang)sLanguage=sLang;
   if (path)sURL=path; 
    
   sURL+=sCalendarUrl
   sURL+="?Lang="+sLang;
   
   var remote=open(sURL+"&CalendarType="+iCalendarType,Name,'width='+w+',height='+h+',top=' + top + ',left=' + left);
   remote.opener=self;
}



function OpenWin(iWidth,iHeight,sLang,sType,sTitle)
{
    //sType:0=Hall,1=Transportation
    if(sTitle==null){sTitle=sType;}
    
    var sUrl;
    if(!sLang)
    {
        sLang="en-us";
    }
    sUrl="/DB/Flash/Flash.aspx?Lang="+sLang+"&Type="+sType+"&width="+iWidth+"&height="+iHeight+"&title="+escape(sTitle);
    //alert(sUrl);
    window.open(sUrl,sType,'location=no,status=no,menubar=no,scrollbars=no,resizable=yes,left=100,width='+iWidth+',height='+iHeight);
}


function ChangeNewsDiv(sShowDiv)
{
    var oLayerNews,oLayerActive;
    var oNewNow,oActiveNow;
    
    if (document.getElementById) { //Netscape 6.x
         oLayerNews = eval("document.getElementById('divNews')");
         oLayerActive= eval("document.getElementById('divTodayActive')");
         oNewNow = eval("document.getElementById('NewNow')");
         oActiveNow = eval("document.getElementById('ActiveNow')");
    }
    else { // IE 5.x
         oLayerNews = eval("document.all.divNews");
         oLayerActive = eval("document.all.divTodayActive");
         oNewNow = eval("document.all.NewNow");
         oActiveNow = eval("document.all.ActiveNow");
    }

    if(sShowDiv=='News')
    {
        if(oLayerNews){oLayerNews.style.display='';} 
        if(oNewNow){oNewNow.style.display='';}
        
        if(oLayerActive){oLayerActive.style.display='none';}
        if(oActiveNow){oActiveNow.style.display='none';}
    }
    else
    {
        if(oLayerNews){oLayerNews.style.display='none';} 
        if(oNewNow){oNewNow.style.display='none';}
        
        if(oLayerActive){oLayerActive.style.display='';}
        if(oActiveNow){oActiveNow.style.display='';}
    }
}





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
   //       /^+$/g

   return s.replace(/^\s+|\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);
	}
}
