function loadTextFile(kh_fName,kh_tName)
{
	new Ajax.Updater(kh_tName,kh_fName, {method: "post", evalScripts: true});
}

//登入頁面載入
function loginIndex()
{
	loadTextFile("login/login.jsp","login_area");
}

//登入最新消息載入
function news()
{
	loadTextFile("news.jsp","news");
}
function intro()
{
	loadTextFile("intro_content.jsp","news");
}

//登出功能
function logOut(cid,sess)
{
	//alert(sess);
	loadTextFile("login/logout.jsp?cid="+cid+"&sess="+sess+"","login_area");
	window.location="music.jsp";
}

function bclogOut(user,pass)
{
	//alert(sess);
	loadTextFile("login/bclogout.jsp?user="+user+"&pass="+pass+"","login_area");
}

function load_tcolumn(url,table)
{
	url = url+"?"+"table="+table;
	//alert(url);
	loadTextFile(url,"cols");
}

function showtrack(trknm,lang1)
{
	//alert(lang1);
	//document.getElementById('div1').innerHTML = 'whatever<img src="whatever.png">whatever'; 
	var showtext ='';
	if(lang1=='zh')
	{
		showtext = '目前播放的音樂 : ';
	}
	else if(lang1=='cn')
	{
		showtext= '目前播放的音乐 :';
	}
	else if(lang1=='en')
	{
		showtext = 'Current Music is : ';	
	}
	document.getElementById("trackply").innerHTML = "<font size='2'>"+showtext+"</font><br />"+"<font size='2'>"+trknm+"</font>";
}

function stoptrack()
{
	document.getElementById("trackply").innerHTML = "";
}

function back()
{
	window.location="music.jsp";
}

function home(lang)
{
	window.location="prova.jsp?lang="+lang;
}
function langzh()
{
	window.location="prova.jsp?lang=zh";
}
function langcn()
{
	window.location="prova.jsp?lang=cn";
}
function langen()
{
	window.location="prova.jsp?lang=en";
}
function check_mail()
{
	if(document.getElementById("email").value=='')
	{
		alert("Email為必填欄位");	
		document.form2.elements[3].focus();
		return false; 
	}
	
	if(document.getElementById("email").value != "" &&  ! /^[_\.\d\w\-]+@([\d\w][\d\w\-]+\.)+[\w]{2,3}$/.test(document.getElementById("email").value))
  {
    alert("請檢查您的 E-mail 是否完整!");
    document.form2.elements[3].focus();
    return false;  
    //return false;
  }   
	
}
function addMember(flag)
{
	loadTextFile("addMember.jsp?flag='"+flag+"'","contents");
}
function addMemberbefore()
{
	loadTextFile("addMemberbefore.jsp","contents");
}

function pssF()
{
	loadTextFile("passMail.jsp","contents");
}

function search1()
{
	loadTextFile("search.jsp?filetype=false&filefolder="+b+"","rightcolumn");

}

function addRec(i)
{
	var seq = document.getElementById("seq"+i).value;
	var lang1 = document.getElementById("lang").value;
	//alert(lang1);
	loadTextFile("addRec.jsp?seq="+seq+"&lang="+lang1,"recom"+i);
}

function wopen(ulink)
{
	//alert(ulink);
	window.open(ulink,"_blank","height=350, width=350, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
}

function index(ulink)
{
	//alert(ulink);
	window.location.href=ulink;
}
//function index(s)
//{
	//alert(s)
//	loadTextFile(s,"middleArea");
//}

var xmlHttp;
function createXHR(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (!xmlHttp) {
		alert('您使用的瀏覽器不支援 XMLHTTP 物件');
		return false;
	}
}

function sendRequest(url){
	createXHR();
	xmlHttp.open('GET',url,true);
	xmlHttp.onreadystatechange=catchResult;
	xmlHttp.send(null);
}

function catchResult(){
	if (xmlHttp.readyState==4){
		if (xmlHttp.status == 200) {
			//預備接收的div的id是"life_wind"
			document.getElementById('life_wind').innerHTML=xmlHttp.responseText;
    		}else{
			var msg='<strong>'+xmlHttp.status+':</strong><br/>'+xmlHttp.statusText;
			document.getElementById('life_wind').innerHTML=msg;
		}
	}
}

function loginVerify(url)
{
	//接收頁面中的表單欄位內容
	//表單的name屬性是"login"
	var wuname = encodeURIComponent(document.getElementById('accountName').value);
	var wupasswd = encodeURIComponent(document.getElementById('passwords').value);
	sendRequest(url + '?wuname=' + wuname + '&wupasswd=' + wupasswd );
	//alert(url + '?wuname=' + wuname + '&wupasswd=' + wupasswd);
	//window.location.href=url + '?wuname=' + wuname + '&wupasswd=' + wupasswd;
}

//顯示DIV Layer
function showDiv(divID,temp,i)
{
	var objDiv = document.getElementById(divID+i);
	document.getElementById(temp+i).style.display = 'none';
	document.getElementById('more').style.display = 'none';
	objDiv.style.display  = 'inline';
}

//隱藏DIV Layer
function hideDiv(divID,temp,i)
{
	//alert(i);
	document.getElementById(divID+i).style.display = 'none';;
	document.getElementById(temp+i).style.display = 'inline';
	document.getElementById('more').style.display = 'inline';
	
	
}
function clickButton(e, buttonid){
      var bt = document.getElementById(buttonid);
      //alert(bt);
      if (typeof bt == 'object'){
            if(navigator.appName.indexOf("Netscape")>(-1)){
                  if (e.keyCode == 13){
                        bt.click();
                        return false;
                  }
            }
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
                  if (event.keyCode == 13){
                        bt.click();
                        return false;
                  } 
            } 
      } 
}       

function focus(buttonid)
{
	document.getElementById(buttonid).focus();
}

function ck1(url)
{
	var acct = encodeURIComponent(document.form2.elements[0].value);
	var contact = encodeURIComponent(document.form2.elements[1].value);
	var phone = encodeURIComponent(document.form2.elements[2].value);
	var email = encodeURIComponent(document.form2.elements[3].value);
	//alert(acct);
	if(acct=='')
	{
		alert("申請單位為必填欄位");	
		document.form2.elements[2].focus();
		return false; 
	}
	
	if(contact=='')
	{
		alert("聯絡人為必填欄位");	
		document.form2.elements[2].focus();
		return false; 
	}
	
	if(phone=='')
	{
		alert("聯絡電話為必填欄位");	
		document.form2.elements[2].focus();
		return false; 
	}
	
	if(email=='')
	{
		alert("Email為必填欄位");	
		document.form2.elements[3].focus();
		return false; 
	}
	check_mail();
	//loadTextFile(url+'?acct='+acct+'&contact='+contact+'&phone='+phone+'&email='+email,'','add');
	//iBox.showURL(url+'?acct='+acct+'&contact='+contact+'&phone='+phone+'&email='+email,'','');	
	//alert("申請完成!,敬請等候通知!");
	window.location.href=url+'?acct='+acct+'&contact='+contact+'&phone='+phone+'&email='+email;
	iBox.hide();
}

function ck()
{
 	iBox.showURL("applyform.jsp","","");
}

function ck_acct()
{
 	//iBox.showURL("acct_list.jsp","","");
 	window.location.href = "acct_list.jsp";
}


function DupCheck(kh_tName)
{
  //alert(kh_tName);
  loadTextFile('check.jsp?md=1&rv='+kh_tName+'&fd='+encodeURIComponent(document.form2.elements[0].value),'add');
  //new Ajax.Updater("add","./check.jsp?md=1&rv="+kh_tName+"&fd="+encodeURIComponent(document.getElementById(kh_tName).value), {method: "get", evalScripts: true});
}
