//定义xmlhttp
var xmlhttp = false;
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
  try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlhttp = false;
  }
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  xmlhttp = new XMLHttpRequest();
}


//創建xmlhttp
function createxmlhttp(){
	var xmlhttp = false;
	try {
  	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e){
  	try {
    	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	} catch (e2) {
    	xmlhttp = false;
  	}
	}
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  	xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

/*
function $(id){
	return document.getElementById(id);	
}*/

// 检测是否为0-9数字	-------------------------------------------------------------------------------------------------------------------------
function isnumeric(s){
	var patrn=/^\d*$/;
		if (!patrn.exec(s)){
			return false;
		}
	return true;
}



// 去字符串前后空格   -------------------------------------------------------------------------------------------------------------------------
function trim(s){
	return s.replace(/(^\s*)|(\s*$)/g, "");  
}


// 检测用户名,密码
function isAccount(str,flag){

	if(flag==1){
		if(/^[a-z]\w{3,10}$/i.test(str)){	
			return true;
		}else{
			return false;	
		}
	}else if(flag==2){
		var patrn=/^(\w){6,20}$/;
		if (!patrn.exec(str)){
			return false;
		}else{
			return true;
		}
	}else if(flag==3){
		if(/^[a-z]\w{2,19}$/i.test(str)){	
			return true;
		}else{
			return false;
		}
	}else if(flag==4){
		if(/^[a-z]\w{3,15}$/i.test(str)){	
			return true;
		}else{
			return false;	
		}
	}else if(flag==5){
		var pattern = /^[a-zA-Z\s]+$/i;

		if (!pattern.test(str)){
			return false;
		}else{
			return true;	
		}
	}else if(flag==6){
		if(/^[a-zA-Z\s]\w{2,19}$/i.test(str)){	
			return true;
		}else{
			return false;
		}
	}
}


//判断是否网址
function ishttp(str){
	var pattern =/^(http:\/\/)?[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_%\?\.=&;\\]+/;

	if (pattern.test(str)){
		return true;
	}else{
		return false;	
	}
}


// 检测tag 字母,数字,中文,空格
function isChinese(str){
	var pattern = /^[0-9a-zA-Z\u4e00-\u9fa5\s]+$/i;

	if (!pattern.test(str)){
		return false;
	}else{
		return true;	
	}
}

//中文
function isChinesex(str){
	var pattern = /^[\u4e00-\u9fa5]+$/i;

	if (!pattern.test(str)){
		return false;
	}else{
		return true;	
	}
}

//英文
function isEnglish(str){
	var pattern = /^[a-zA-Z\s]+$/i;

	if (!pattern.test(str)){
		return false;
	}else{
		return true;	
	}
}

// 判断是否为空	   	-------------------------------------------------------------------------------------------------------------------------
/*
	obj 控件名
	mess 错误信息
*/
function checkempty(obj,mess){
	if(trim(obj.value)==''){
		alert(mess);
		obj.focus();		
		return false;
	}
}


//检测email
function ismail(email){
	return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(email));
}

//检测图片 			-------------------------------------------------------------------------------------------------------------------------
function checkphoto(obj){
var AllImgExt="|.jpg|.jpeg|";	//定义允许的后缀

fileext=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();	//取后缀

if(AllImgExt.indexOf("|"+fileext+"|")==-1){		//后缀不正确
	return false;
}
}

//检测图片 			-------------------------------------------------------------------------------------------------------------------------
function checkphoto1(obj){
var AllImgExt="|.jpg|.jpeg|.gif|";	//定义允许的后缀

fileext=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();	//取后缀

if(AllImgExt.indexOf("|"+fileext+"|")==-1){		//后缀不正确
	return false;
}
}

//检测zip 			-------------------------------------------------------------------------------------------------------------------------
function checkzip(obj){
var AllImgExt="|.zip|";	//定义允许的后缀

fileext=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();	//取后缀

if(AllImgExt.indexOf("|"+fileext+"|")==-1){		//后缀不正确
	return false;
}
}

//判断字符串长度
function  getLen( str) {
   var totallength=0;   for (var i=0;i<str.length;i++)
   {
    var intCode=str.charCodeAt(i);    if (intCode>=0&&intCode<=128) {
     totallength=totallength+1; //非中文单个字符长度加 1
    }
    else {
     totallength=totallength+2; //中文字符长度则加 2
    }
   } //end for  
 return totallength;
}


//页数跳转 			-------------------------------------------------------------------------------------------------------------------------
function gopage(path,para){
	var jumppage=document.getElementById("jumppage").value;
	if(jumppage!="0"){
		window.location=path+"?page="+jumppage+para;
	}
}


function gopagex(path,tname,para){
	var jumppage=document.getElementById("jumppage").value;
	if(jumppage!="0"){
		window.location=path+"?"+tname+"="+jumppage+para;
	}
}

//顶部搜索
function home_search(c){

	if(trim(document.getElementById("key").value)==''){	
		alert("請輸入要搜索的關鍵字！");	
		document.getElementById("key").focus();
		return false;
	}

	if(c==0){
		window.location="search.php?key="+encodeURI(document.getElementById("key").value);
	}else{
		window.open("search.php?key="+encodeURI(document.getElementById("key").value),"_top");
	}
}

//验证contactus
function upcontact(){

	if(checkempty(document.form1.subject,"請輸入Subject！")==false){
		return false;
	}

	if(checkempty(document.form1.content,"請輸入Message！")==false){
		return false;
	}	

	if(checkempty(document.form1.cname,"請輸入Name！")==false){
		return false;
	}

	if(checkempty(document.form1.email,"請輸入Email！")==false){
		return false;
	}

	if(ismail(document.form1.email.value)==false){;
		alert("Email地址不正確！");
		document.form1.email.focus();
		return false;
	}

	if(checkempty(document.form1.phone,"請輸入Phone！")==false){
		return false;
	}

	if(isnumeric(document.form1.phone.value)==false){
		alert("Phone必須是數字！");
		document.form1.phone.focus();
		return false;
	}

	if(checkempty(document.form1.checkcode,"請輸入Captcha！")==false){
		return false;
	}

	var stra="subject="+document.form1.subject.value;
	stra=stra+"&content="+encodeURIComponent(document.form1.content.value);
	stra=stra+"&cname="+document.form1.cname.value;
	stra=stra+"&email="+document.form1.email.value;
	stra=stra+"&phone="+document.form1.phone.value;
	stra=stra+"&checkcode="+document.form1.checkcode.value;
	stra=stra+"&ajaxid=1";

	var temptext;

	xmlhttp.open("post","ajax.php",true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;

			if(temptext=="true"){
				alert("留言信息發送成功！");
				
				//清空表单
				document.form1.subject.value="";
				document.form1.content.value="";
				document.form1.cname.value="";
				document.form1.email.value="";
				document.form1.phone.value="";
				document.form1.checkcode.value="";
			
				document.getElementById("ck").src="checkcode.php?t="+Math.random();

			}else{
				alert("Captcha不正確！");
				document.getElementById("ck").src="checkcode.php?t="+Math.random();
			}

		}
	}

	xmlhttp.setRequestHeader("content-length",stra.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(stra);

}


//snap隐显,复位
function showsnap(c,cnum){
	for(var i=0;i<=cnum;i++){
		if(i==c){
			document.getElementById("p"+i).src=snap_tp[i][0].replace("_1a.jpg","_1.jpg");
			document.getElementById("f"+i+"_1").src=snap_tp[i][0].replace("_1a.jpg","_2a.jpg");
			document.getElementById("f"+i+"_2").src=snap_tp[i][0].replace("_1a.jpg","_3a.jpg");
			document.getElementById("spantop"+i).innerHTML=snap_tit[i][0];
			document.getElementById("spancon"+i).innerHTML=snap_con[i][0];
			document.getElementById("tempj").innerTEXT=0;

			document.getElementById("big"+i).style.display="block";	
			document.getElementById("small"+i).style.display="none";
		}else{
			document.getElementById("small"+i).style.display="block";
			document.getElementById("big"+i).style.display="none";
		}
	}
}

//snap 换图
function showsnapphoto(i,j){
	document.getElementById("p"+i).src=snap_tp[i][j].replace("_1a.jpg","_1.jpg");
	document.getElementById("f"+i+"_1").src=snap_tp[i][j].replace("_1a.jpg","_2a.jpg");
	document.getElementById("f"+i+"_2").src=snap_tp[i][j].replace("_1a.jpg","_3a.jpg");
	document.getElementById("spantop"+i).innerHTML=snap_tit[i][j];
	document.getElementById("spancon"+i).innerHTML=snap_con[i][j];
	document.getElementById("spanin"+i).innerHTML=snap_in[i][j];
	document.getElementById("tempj").innerTEXT=j;
}

//snap 换图1
function showsnapphoto1(i,c){
	var j=document.getElementById("tempj").innerTEXT;
	//j未定义情况
	if(j==undefined){
		j=0;	
	}
	document.getElementById("p"+i).src=snap_tp[i][j].replace("_1a.jpg","_"+(c+1)+".jpg");
}

//snap 换图2 返回
function showsnapphoto2(i){
	var j=document.getElementById("tempj").innerTEXT;
	//j未定义情况
	if(j==undefined){
		j=0;	
	}
	document.getElementById("p"+i).src=snap_tp[i][j].replace("_1a.jpg","_1.jpg");
}


//news换图
function shownewsphoto(str){
	document.getElementById("showphoto").src=str.replace("newsphoto/s","newsphoto/");
}


//news comment -----------------------------------------------------------------
function addcomment(){
	if(trim(document.form1.content.value)=='' || trim(document.form1.content.value)=='只限會員留言，請先按「Register」進行登記！'){
		alert("請輸入Message！");
		document.form1.content.focus();
		return false;
	}

	/*
	if(getLen(document.form1.content.value)>300){
		alert("Message不能超過150個中文字符！");	
		document.form1.content.focus();
		return false;
	}*/

	if(document.form1.islogin.value==0){
		if(trim(document.form1.username.value)==''){
			alert("請輸入Name！");	
			document.form1.username.focus();
			return false;
		}

		if(trim(document.form1.password.value)==''){
			alert("請輸入Password！");	
			document.form1.password.focus();
			return false;
		}
	}

	//提交数据
	var stra="content="+encodeURIComponent(document.form1.content.value);
	stra=stra+"&username="+document.form1.username.value;
	stra=stra+"&password="+document.form1.password.value;
	stra=stra+"&newsid="+document.form1.newsid.value;
	stra=stra+"&ajaxid=2";

	var temptext;

	xmlhttp.open("post","ajax.php",true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;

			if(temptext=='e1'){
				alert("用戶名和密碼不能為空！");
			}else if(temptext=='e2'){
				alert("用戶名或密碼錯！");
				document.form1.password.value="";
				document.form1.password.focus();
			}else if(temptext=='e3'){
				alert("此用戶未啟用！");
				document.form1.password.value="";
			}else if(temptext=='true'){
				//調用統一登入
				document.getElementById("syndiscuz").src = "ucfunction.php?ucid=1&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				document.getElementById("synuchome").src = "ucfunction.php?ucid=2&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				
				alert("Comment 提交成功！");
				document.form1.reset();
				document.form1.content.value='';
				document.form1.islogin.value="1";
				document.getElementById("showlogin").style.display="none";
				document.getElementById("showreg").style.display="none";

				//调用列表函数
				showcomment(document.form1.newsid.value,1);
			}
		}
	}

	xmlhttp.setRequestHeader("content-length",stra.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(stra);
}
//---------------------------------------------------------------------------------


//news comment list ---------------------------------------------------------------
function showcomment(c,page){
	var temptext;
	var ismore = document.getElementById("ismore").value;

	xmlhttp.open("get","showcomment.php?newsid="+c+"&page="+page+"&ismore="+ismore,"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;
			document.getElementById("commentlist").innerHTML=temptext;
		}
	}
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
}
//---------------------------------------------------------------------------------



//vote comment -----------------------------------------------------------------
function addvcomment(){

	if(trim(document.form1.content.value)=='' || trim(document.form1.content.value)=='只限會員留言，請先按「Register」進行登記！'){
		alert("請輸入Message！");
		document.form1.content.focus();
		return false;
	}

	if(getLen(document.form1.content.value)>300){
		alert("Message不能超過150個中文字符！");	
		document.form1.content.focus();
		return false;
	}

	if(document.form1.islogin.value==0){
		if(trim(document.form1.username.value)==''){
			alert("請輸入Name！");	
			document.form1.username.focus();
			return false;
		}

		if(trim(document.form1.password.value)==''){
			alert("請輸入Password！");	
			document.form1.password.focus();
			return false;
		}
	}

	//提交数据
	var stra="content="+encodeURIComponent(document.form1.content.value);
	stra=stra+"&username="+document.form1.username.value;
	stra=stra+"&password="+document.form1.password.value;
	stra=stra+"&vid="+document.form1.vid.value;
	stra=stra+"&ajaxid=8";

	var temptext;

	xmlhttp.open("post","ajax.php",true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;

			if(temptext=='e1'){
				alert("用戶名和密碼不能為空！");
			}else if(temptext=='e2'){
				alert("用戶名或密碼錯！");
				document.form1.password.value="";
				document.form1.password.focus();
			}else if(temptext=='e3'){
				alert("此用戶未啟用！");
				document.form1.password.value="";
			}else if(temptext=='true'){
				//調用統一登入
				document.getElementById("syndiscuz").src = "ucfunction.php?ucid=1&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				document.getElementById("synuchome").src = "ucfunction.php?ucid=2&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				alert("Comment 提交成功！");
				document.form1.reset();
				document.form1.content.value='';
				document.form1.islogin.value="1";
				document.getElementById("showlogin").style.display="none";
				document.getElementById("showreg").style.display="none";
				//调用列表函数
				showvcomment(document.form1.vid.value,1);
			}
		}
	}

	xmlhttp.setRequestHeader("content-length",stra.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(stra);
}
//---------------------------------------------------------------------------------


//vote comment list ---------------------------------------------------------------
function showvcomment(c,page){
	var temptext;

	xmlhttp.open("get","showvcomment.php?vid="+c+"&page="+page,"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;
			document.getElementById("commentlist").innerHTML=temptext;
		}
	}
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
}
//---------------------------------------------------------------------------------



//video comment -----------------------------------------------------------------
function addvideocomment(){

	if(trim(document.form1.content.value)=='' || trim(document.form1.content.value)=='只限會員留言，請先按「Register」進行登記！'){
		alert("請輸入Message！");
		document.form1.content.focus();
		return false;
	}

	if(getLen(document.form1.content.value)>300){
		alert("Message不能超過150個中文字符！");	
		document.form1.content.focus();
		return false;
	}

	if(document.form1.islogin.value==0){
		if(trim(document.form1.username.value)==''){
			alert("請輸入Name！");	
			document.form1.username.focus();
			return false;
		}

		if(trim(document.form1.password.value)==''){
			alert("請輸入Password！");	
			document.form1.password.focus();
			return false;
		}
	}

	//提交数据
	var stra="content="+encodeURIComponent(document.form1.content.value);
	stra=stra+"&username="+document.form1.username.value;
	stra=stra+"&password="+document.form1.password.value;
	stra=stra+"&videoid="+document.form1.videoid.value;
	stra=stra+"&ajaxid=11";

	var temptext;

	xmlhttp.open("post","ajax.php",true);
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;

			if(temptext=='e1'){
				alert("用戶名和密碼不能為空！");
			}else if(temptext=='e2'){
				alert("用戶名或密碼錯！");
				document.form1.password.value="";
				document.form1.password.focus();
			}else if(temptext=='e3'){
				alert("此用戶未啟用！");
				document.form1.password.value="";
			}else if(temptext=='true'){
				//調用統一登入
				document.getElementById("syndiscuz").src = "ucfunction.php?ucid=1&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				document.getElementById("synuchome").src = "ucfunction.php?ucid=2&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				alert("Comment 提交成功！");
				document.form1.reset();
				document.form1.content.value='';
				document.form1.islogin.value="1";
				document.getElementById("showlogin").style.display="none";
				document.getElementById("showreg").style.display="none";
				//调用列表函数
				showvideocomment(document.form1.videoid.value,1);
			}
		}
	}

	xmlhttp.setRequestHeader("content-length",stra.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(stra);
}
//---------------------------------------------------------------------------------


//video comment list ---------------------------------------------------------------
function showvideocomment(c,page){
	var temptext;

	xmlhttp.open("get","showvideocomment.php?videoid="+c+"&page="+page,"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;
			document.getElementById("commentlist").innerHTML=temptext;
		}
	}
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
}
//---------------------------------------------------------------------------------

//验证用户名密码---------------------------------------------------------------
function flogin(){
	if(checkempty(document.form1.username,"請輸入Username！")==false){
		return false;
	}

	if(checkempty(document.form1.password,"請輸入Password！")==false){
		return false;
	}

	if(document.getElementById("xcookie").checked){
		document.form1.iscookie.value="1";	
	}else{
		document.form1.iscookie.value="0";
	}

	var stra="username="+document.form1.username.value;
	stra=stra+"&password="+document.form1.password.value;
	stra=stra+"&iscookie="+document.form1.iscookie.value;
	stra=stra+"&ajaxid=3";

	var temptext;

	xmlhttp.open("post","ajax.php","true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			temptext=xmlhttp.responseText;

			if(temptext=="0"){
				alert("用戶名和密碼不能為空！");
			}else if(temptext=="1"){
				alert("用戶名或密碼錯！");
				document.form1.password.value="";
				document.form1.password.focus();
			}else if(temptext=="2"){
				alert("此用戶未啟用！");
				document.form1.password.value="";
			}else if(temptext=="true"){
				//調用統一登入
				document.getElementById("syndiscuz").src = "ucfunction.php?ucid=1&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				document.getElementById("synuchome").src = "ucfunction.php?ucid=2&username=" + document.form1.username.value + "&password=" + document.form1.password.value;
				alert("登入成功！");
				setTimeout(function(){window.location = document.getElementById("tourl").value;},1000);
				//window.location = document.getElementById("tourl").value
			}
		}
	}

	xmlhttp.setRequestHeader("content-length",stra.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(stra);

}

//---------------------------------------------------------------------------------

//验证取回密码 ----------------------------------------------------------------------
function frepass(){
	if(trim(document.form2.email.value)==''){
		alert("請輸入Email！");
		document.form2.email.focus();
		return false;
	}

	if(ismail(document.form2.email.value)==false){;
		alert("Email地址不正確！");
		document.form2.email.focus();
		return false;
	}

	var stra="email="+document.form2.email.value;
	stra=stra+"&ajaxid=4";

	var temptext;

	xmlhttp.open("POST","ajax.php","true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){	
			temptext=xmlhttp.responseText;
			
			if(temptext=="0"){
				alert("Email不能為空！");
			}else if(temptext=="1"){
				alert("Email不存在！");
			}else if(temptext=="true"){
				alert("新密碼已經發送到你的Email！");
				document.form2.email.value="";
			}
		}
	}
	xmlhttp.setRequestHeader("content-length",stra.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(stra);
}

//---------------------------------------------------------------------------------

//IE触发事件-------------------------------------------------------------------------
function frepass1(){
	if(event.keyCode==13){
		frepass();
	}
}
//---------------------------------------------------------------------------------


//会员注册 ----------------------------------------------------------------------------
function reg(){

	if(checkempty(document.form1.checkcode,"請輸入Captcha！")==false){
		return false;
	}

	if(checkempty(document.form1.username,"請輸入Login Name！")==false){
		return false;
	}

	if(isAccount(document.form1.username.value,4)==false){
		alert("Login Name由字母、數字、下劃線組成，且只能以字母開頭，長度為4-15位，小寫！");
		document.form1.username.focus();
		return false;
	}

	if(checkempty(document.form1.email,"請輸入Email！")==false){
		return false;
	}

	if(ismail(document.form1.email.value)==false){;
		alert("Email地址不正確！");
		document.form1.email.focus();
		return false;
	}

	if(checkempty(document.form1.password,"請輸入Password！")==false){
		return false;
	}

	if(isAccount(document.form1.password.value,2)==false){
		alert("Password由字母、數字、下劃線組成，長度為6-20位！");
		document.form1.password.focus();
		return false;
	}

	if(checkempty(document.form1.tpassword,"請輸入Re-type Password！")==false){
		return false;
	}

	if(isAccount(document.form1.tpassword.value,2)==false){
		alert("Re-type Password由字母、數字、下劃線組成，長度為6-20位！");
		document.form1.tpassword.focus();
		return false;
	}

	if(document.form1.password.value!=document.form1.tpassword.value){
		alert("Re-type Password 與 Password不一致！");
		document.form1.password.focus();
		return false;
	}


	if(checkempty(document.form1.ename,"請輸入Full Name In English！")==false){
		return false;
	}

	if(isAccount(document.form1.ename.value,5)==false){
		alert("Full Name In English不正確！");
		document.form1.ename.focus();
		return false;
	}

	if(document.getElementById("sex1").checked==false && document.getElementById("sex2").checked==false){
		alert("請選擇 Gender！");
		document.getElementById("sex1").focus();
		return false;
	}


	if(checkempty(document.getElementById("photo"),"請輸入Change Picture！")==false){
		return false;
	}

	if(checkphoto(document.getElementById("photo"))==false){
		alert("Change Picture格式只能是JPG！");
		document.getElementById("photo").focus();
		return false;
	}	


	if(checkempty(document.form1.phone,"請輸入Phone Number")==false){
		return false;
	}

	if(isnumeric(document.form1.phone.value)==false){
		alert("Phone必須是數字！");
		document.form1.phone.focus();
		return false;
	}


	if(document.form1.mm.value!='' || document.form1.dd.value!='' || document.form1.yy.value!=''){

		if(isnumeric(document.form1.mm.value)==false){
			alert("Date Of Brith 月份不正確！");
			document.form1.mm.focus();
			return false;
		}else if(document.form1.mm.value>12 || document.form1.mm.value<1){
			alert("Date Of Brith 月份不正確！");
			document.form1.mm.focus();
			return false;;
		}


		if(isnumeric(document.form1.dd.value)==false){
			alert("Date Of Brith 日不正確！");
			document.form1.dd.focus();
			return false;
		}else if(document.form1.dd.value>31 || document.form1.dd.value<1){
			alert("Date Of Brith 日不正確！");
			document.form1.dd.focus();
			return false;;
		}


		if(isnumeric(document.form1.yy.value)==false){
			alert("Date Of Brith 年份不正確！");
			document.form1.yy.focus();
			return false;
		}else if(document.form1.yy.value>2046 || document.form1.yy.value<1900){
			alert("Date Of Brith 年份必須在1900-2046之間！");
			document.form1.yy.focus();
			return false;;
		}

	}

	if(document.getElementById("isagree").checked!=true){	
		alert("必須同意條款才能成功注冊！");
		document.getElementById("isagree").focus();
		return false;
	}

	if(document.getElementById("xmail").checked==true){
		document.form1.ismail.value="1";	
	}else{
		document.form1.ismail.value="0";
	}

	document.form1.submit();
}
//---------------------------------------------------------------------------------


//会员注册检测 ajax ------------------------------------------------------------------------
function reg_check(c){
if(c==1){
	if(trim(document.form1.username.value)==''){
		document.getElementById("ajax1").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>請輸入Login Name！</font>";
		return false;
	}

	if(isAccount(document.form1.username.value,4)==false){
		document.getElementById("ajax1").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Login Name 不正確！</font>";
		alert("Login Name由字母、數字、下劃線組成，且只能以字母開頭，長度為4-15位，小寫！");
		return false;
	}

	//判断是否被占用
	var stra="username="+document.form1.username.value;
	stra=stra+"&ajaxid=5";

	var temptext;

	xmlhttp.open("GET","ajax.php?"+stra,"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){	
			temptext=xmlhttp.responseText;
			if(temptext=="0"){
				document.getElementById("ajax1").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Login Name 已被使用！</font>";
				return false;
			}
		}
	}

	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);


	document.getElementById("ajax1").innerHTML="<img src=\"images/common/re_l_02.gif\" /> Login Name 正確！";

}else if(c==2){
	if(trim(document.form1.email.value)==false){
		document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>請輸入Email！</font>";
		return false;
	}

	if(ismail(document.form1.email.value)==false){;
		document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Email地址不正確！</font>";
		return false;
	}

	//判断是否被占用

	var stra1="email="+document.form1.email.value;
	stra1=stra1+"&ajaxid=6";

	var temptext1;

	xmlhttp.open("GET","ajax.php?"+stra1,"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){	
			temptext1=xmlhttp.responseText;
			if(temptext1=="0"){
				document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Email 已被使用！</font>";
				return false;
			}
		}
	}

	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);

	document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_02.gif\" /> Email 正確！";

}else if(c==3){
	if(trim(document.form1.password.value)==false){
		document.getElementById("ajax3").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>請輸入Password！</font>";
		return false;
	}

	if(isAccount(document.form1.password.value,2)==false){
		document.getElementById("ajax3").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Password 不正確！</font>";
		alert("Password由字母、數字、下劃線組成，長度為6-20位！");
		return false;
	}

	document.getElementById("ajax3").innerHTML="<img src=\"images/common/re_l_02.gif\" /> Password 正確！";

}else if(c==4){

	if(trim(document.form1.tpassword.value)==false){
		document.getElementById("ajax4").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>請輸入Re-type Password！</font>";
		return false;
	}

	if(isAccount(document.form1.tpassword.value,2)==false){
		document.getElementById("ajax4").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Re-type Password 不正確！</font>";
		alert("Re-type Password由字母、數字、下劃線組成，長度為6-20位！");
		return false;
	}

	if(document.form1.password.value!=document.form1.tpassword.value){
		document.getElementById("ajax4").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Re-type Password 不一致！</font>";
		return false;
	}

	document.getElementById("ajax4").innerHTML="<img src=\"images/common/re_l_02.gif\" /> Re-type Password 正確！";

}else if(c==5){
	if(trim(document.form1.email.value)==false){
		document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>請輸入Email！</font>";
		return false;
	}

	if(ismail(document.form1.email.value)==false){;
		document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Email地址不正確！</font>";
		return false;
	}

	//判断是否被占用

	var stra1="email="+document.form1.email.value;
	stra1=stra1+"&ajaxid=7";

	var temptext1;

	xmlhttp.open("GET","ajax.php?"+stra1,"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){	
			temptext1=xmlhttp.responseText;
			if(temptext1=="0"){
				document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_01.gif\" /> <font color='#FF0000'>Email 已被使用！</font>";
				return false;
			}
		}
	}

	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);

	document.getElementById("ajax2").innerHTML="<img src=\"images/common/re_l_02.gif\" /> Email 正確！";

}

}
//---------------------------------------------------------------------------------


//会员修改 -------------------------------------------------------------------------
function modmember(){

	if(checkempty(document.form1.email,"請輸入Email！")==false){
		return false;
	}

	if(ismail(document.form1.email.value)==false){;
		alert("Email地址不正確！");
		document.form1.email.focus();
		return false;
	}

	if(trim(document.form1.opassword.value)!='' || trim(document.form1.password.value)!='' || trim(document.form1.tpassword.value)!=''){ //-

	if(checkempty(document.form1.opassword,"請輸入Old Password！")==false){
		return false;
	}

	if(isAccount(document.form1.opassword.value,2)==false){
		alert("Old Password由字母、數字、下劃線組成，長度為6-20位！");
		document.form1.opassword.focus();
		return false;
	}

	if(checkempty(document.form1.password,"請輸入New Password！")==false){
		return false;
	}

	if(isAccount(document.form1.password.value,2)==false){
		alert("New Password由字母、數字、下劃線組成，長度為6-20位！");
		document.form1.password.focus();
		return false;
	}

	if(checkempty(document.form1.tpassword,"請輸入Re-type Password！")==false){
		return false;
	}

	if(isAccount(document.form1.tpassword.value,2)==false){
		alert("Re-type Password由字母、數字、下劃線組成，長度為6-20位！");
		document.form1.tpassword.focus();
		return false;
	}

	if(document.form1.password.value!=document.form1.tpassword.value){
		alert("Re-type Password 與 New Password不一致！");
		document.form1.password.focus();
		return false;
	}

	}	//-


	if(checkempty(document.form1.ename,"請輸入Full Name In English！")==false){
		return false;
	}

	if(isAccount(document.form1.ename.value,5)==false){
		alert("Full Name In English不正確！");
		document.form1.ename.focus();
		return false;
	}

	if(trim(document.getElementById("photo").value)!=''){
		if(checkphoto(document.getElementById("photo"))==false){
			alert("Change Picture格式只能是JPG！");
			document.getElementById("photo").focus();
			return false;
		}	
	}

	if(checkempty(document.form1.phone,"請輸入Phone Number")==false){
		return false;
	}

	if(isnumeric(document.form1.phone.value)==false){
		alert("Phone必須是數字！");
		document.form1.phone.focus();
		return false;
	}


	if(document.form1.mm.value!='' || document.form1.dd.value!='' || document.form1.yy.value!=''){

		if(isnumeric(document.form1.mm.value)==false){
			alert("Date Of Brith 月份不正確！");
			document.form1.mm.focus();
			return false;
		}else if(document.form1.mm.value>12 || document.form1.mm.value<1){
			alert("Date Of Brith 月份不正確！");
			document.form1.mm.focus();
			return false;;
		}


		if(isnumeric(document.form1.dd.value)==false){
			alert("Date Of Brith 日不正確！");
			document.form1.dd.focus();
			return false;
		}else if(document.form1.dd.value>31 || document.form1.dd.value<1){
			alert("Date Of Brith 日不正確！");
			document.form1.dd.focus();
			return false;;
		}


		if(isnumeric(document.form1.yy.value)==false){
			alert("Date Of Brith 年份不正確！");
			document.form1.yy.focus();
			return false;
		}else if(document.form1.yy.value>2046 || document.form1.yy.value<1900){
			alert("Date Of Brith 年份必須在1900-2046之間！");
			document.form1.yy.focus();
			return false;;
		}

	}

	document.form1.submit();
}
//---------------------------------------------------------------------------------


//搜索
function show_sresult(){
	if(trim(document.form1.key.value)==''){
		alert("請輸入搜索條件！");
		document.form1.key.focus();
		return false;
	}

	if(document.getElementById("cx1").checked==false && document.getElementById("cx2").checked==false && document.getElementById("cx3").checked==false){
		alert("至少選擇一個搜索範圍！");
		document.getElementById("cx1").focus();
		return false;
	}

	var pagesize,dateflag,key;
	pagesize=document.form1.pagesize.value;
	dateflag=document.form1.dateflag.value;
	key=encodeURI(document.form1.key.value);


	//获取搜索结果
	if(document.getElementById("cx1").checked){
		sfan1="1";
	}else{
		sfan1="2";	
	}
	if(document.getElementById("cx2").checked){
		sfan2="1";
	}else{
		sfan2="2";		
	}

	if(document.getElementById("cx3").checked){
		sfan3="1";
	}else{
		sfan3="2";	
	}

	window.location="search.php?key="+key+"&dateflag="+dateflag+"&pagesize="+pagesize+"&sfan1="+sfan1+"&sfan2="+sfan2+"&sfan3="+sfan3;
}


function showresult(){
	if(trim(document.form1.key.value)==''){
		alert("請輸入搜索條件！");
		document.form1.key.focus();
		return false;
	}

	if(document.getElementById("cx1").checked==false && document.getElementById("cx2").checked==false && document.getElementById("cx3").checked==false){
		alert("至少選擇一個搜索範圍！");
		document.getElementById("cx1").focus();
		return false;
	}

	var pagesize,dateflag,key;
	pagesize=document.form1.pagesize.value;
	dateflag=document.form1.dateflag.value;
	key=encodeURI(document.form1.key.value);

	sfan="";

	//获取搜索结果
	if(document.getElementById("cx1").checked){
		sfan="1";
	}else{
		sfan="0";	
	}
	if(document.getElementById("cx2").checked){
		sfan=sfan+"|1";
	}else{
		sfan=sfan+"|0";		
	}

	if(document.getElementById("cx3").checked){
		sfan=sfan+"|1";
	}else{
		sfan=sfan+"|0";	
	}

	getresultall(sfan,key,pagesize,dateflag,1);
}

//全体搜索
function getresultall(sfan,key,pagesize,dateflag,pageno){
	var temptext,mydiv;
	xmlhttp.open("GET","showresultall.php?sfan="+sfan+"&key="+key+"&pagesize="+pagesize+"&dateflag="+dateflag+"&page="+pageno+"&t="+Math.random(),"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){

			temptext=xmlhttp.responseText;

			if(temptext.split("|###|")[0]!="0"){
				document.getElementById("stit1").style.display="block";
				document.getElementById("sresult1").style.display="block";	
				document.getElementById("sresult1").innerHTML=temptext.split("|###|")[0];
			}else{
				document.getElementById("stit1").style.display="none";	
				document.getElementById("sresult1").innerHTML=" ";
				document.getElementById("sresult1").style.display="none";	
			}

			if(temptext.split("|###|")[1]!="0"){
				document.getElementById("stit2").style.display="block";
				document.getElementById("sresult2").style.display="block";	
				document.getElementById("sresult2").innerHTML=temptext.split("|###|")[1];
			}else{
				document.getElementById("stit2").style.display="none";				
				document.getElementById("sresult2").innerHTML=" ";
				document.getElementById("sresult2").style.display="none";	
			}

			if(temptext.split("|###|")[2]!="0"){
				document.getElementById("stit3").style.display="block";
				document.getElementById("sresult3").style.display="block";	
				document.getElementById("sresult3").innerHTML=temptext.split("|###|")[2];
			}else{
				document.getElementById("stit3").style.display="none";	
				document.getElementById("sresult3").innerHTML=" ";
				document.getElementById("sresult3").style.display="none";	
			}

			document.getElementById("showtime").innerHTML=temptext.split("|###|")[3];

		}
	}
	
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
}


//单个搜索
function getresult(sflag,key,pagesize,dateflag,pageno){
	var temptext;
	xmlhttp.open("GET","showresult.php?sflag="+sflag+"&key="+key+"&pagesize="+pagesize+"&dateflag="+dateflag+"&page="+pageno+"&t="+Math.random(),"true");
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){

			temptext=xmlhttp.responseText;

			if(sflag==1){
				document.getElementById("sresult1").innerHTML=temptext;
			}else if(sflag==2){
				document.getElementById("sresult2").innerHTML=temptext;
			}else if(sflag==3){
				document.getElementById("sresult3").innerHTML=temptext;
			}
		}
	}
	
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
}
//---------------------------------------------------------------------------------

function DrawImage(ImgD,twidth,theight){ 
 var flag=false; 
 var image=new Image(); 
 var iwidth = twidth;  //定义允许图片宽度 
 var iheight = theight;  //定义允许图片高度 
 image.src=ImgD.src; 
 if(image.width>0 && image.height>0){ 
 flag=true; 
 if(image.width/image.height>= iwidth/iheight){ 
  if(image.width>iwidth){   
  ImgD.width=iwidth; 
  ImgD.height=(image.height*iwidth)/image.width; 
  }else{ 
  ImgD.width=image.width;   
  ImgD.height=image.height; 
  } 
  //ImgD.alt=image.width+"×"+image.height; 
  } 
 else{ 
  if(image.height>iheight){   
  ImgD.height=iheight; 
  ImgD.width=(image.width*iheight)/image.height;   
  }else{ 
  ImgD.width=image.width;   
  ImgD.height=image.height; 
  } 
  //ImgD.alt=image.width+"×"+image.height; 
  } 
 } 
}  


//時間比較
function comptime(beginTime,endTime){

var beginTimes=beginTime.substring(0,10).split('-');
var endTimes=endTime.substring(0,10).split('-');

beginTime=beginTimes[1]+'/'+beginTimes[2]+'/'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime=endTimes[1]+'/'+endTimes[2]+'/'+endTimes[0]+' '+endTime.substring(10,19);

// alert(beginTime+endTime+beginTime);
// alert(Date.parse(endTime));
// alert(Date.parse(beginTime));
 
var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;

if(a<0){
return -1;
}else if (a>0){
return 1;
}else if (a==0){
return 0;
}else{
return 'exception'
}

}

//留言前檢測！
function checkarea(c){
	if(trim(c.value)=='只限會員留言，請先按「Register」進行登記！' || trim(c.value)=='只限會員評論，請先按「Register」進行登記！'){
		c.value='';
	}
}

//投票
function addvote(){

	var votenum = document.form1.votenum.value;
	var page = document.form1.page.value;
	var maxsel = document.form1.maxsel.value;
	var minsel = document.form1.minsel.value;
	var xflag = document.form1.xflag.value;
	var id = document.form1.id.value;
	var isok = 0;
	var selnum = 0;
	var selid = "";

	if(xflag==1){	//單選
		for(var i=1;i<=votenum;i++){
			if(document.getElementById("vsel"+i).checked==true){
				selid=document.getElementById("vsel"+i).value;
				isok=1;
				break;
			}
		}

		if(isok==0){
			alert("請選擇你要投票的選項！");
			return false;
		}

	}else{	//多選
	
		for(var i=1;i<=votenum;i++){
			if(document.getElementById("vsel"+i).checked==true){
				if(selid==''){
					selid=document.getElementById("vsel"+i).value;
				}else{
					selid=selid + "," + document.getElementById("vsel"+i).value;
				}
				selnum=selnum+1;
			}
		}

		if(selnum<minsel || selnum>maxsel){
			alert("最小投票數不能少於："+minsel+"個，最多投票數不能多於："+maxsel+"個！");
			return false;
		}
		isok=1;
	}

	if(isok==1){	//投票成功提交

		var stra="selid="+encodeURI(selid);
		stra=stra + "&vid="+id;
		stra=stra + "&ajaxid=9";

		xmlhttp.open("post","ajax.php",true);
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4 && xmlhttp.status==200){		
				temptext=xmlhttp.responseText;
				if(temptext=='1'){
					alert("投票成功！");
					window.location="vote_show.php?id="+id+"&page="+page;
				}else{
					alert(temptext);
				}
			}
		}
		xmlhttp.setRequestHeader("content-length",stra.length);
		xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.send(stra);
	}
}

//複製到剪切版
function copyToClipboard(txt) {        
	txt=document.getElementById(txt).value;

	if(window.clipboardData) {        
             window.clipboardData.clearData();        
             window.clipboardData.setData("Text", txt);        
     } else if(navigator.userAgent.indexOf("Opera") != -1) {        
          window.location = txt;        
     } else if (window.netscape) {        
          try {        
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");        
          } catch (e) {        
               alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");        
          }        
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);        
          if (!clip)        
               return;        
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);        
          if (!trans)        
               return;        
          trans.addDataFlavor('text/unicode');        
          var str = new Object();        
          var len = new Object();        
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);        
          var copytext = txt;        
          str.data = copytext;        
          trans.setTransferData("text/unicode",str,copytext.length*2);        
          var clipid = Components.interfaces.nsIClipboard;        
          if (!clip)        
               return false;        
          clip.setData(trans,null,clipid.kGlobalClipboard);        
          alert("复制成功！")        
     }        
}  


function copyText(objId) { 
var obj = document.getElementById(objId); 
obj.select(); 
document.execCommand("Copy"); 
alert("複製成功！");
} 


//檢測瀏覽器類型
function checkbrowser(){
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

//以下进行测试
if (Sys.ie) return "ie";			//document.write('IE: ' + Sys.ie);
if (Sys.firefox) return "ff";		//document.write('Firefox: ' + Sys.firefox);
if (Sys.chrome) return "chrome";	//document.write('Chrome: ' + Sys.chrome);
if (Sys.opera) return "opera";		//document.write('Opera: ' + Sys.opera);
if (Sys.safari) return "safari";	// document.write('Safari: ' + Sys.safari);
return "none";
}


//link 轉 videocode
function changevideocode(c,d){
	var temp = d.value.replace("http:\/\/www.youtube.com\/watch?v=","");
	document.form1.video_photo.value = document.form1.video_photo.value.replace("[#photo#]",temp);

	var str = c.value;
	str = str.replace("[#video#]",temp);
	str = str.replace("[#video#]",temp);
	return str;
}

//mouseover mouseout替換圖片
/**
* id 圖片id
* photo 圖片名稱
*/
function changephoto(id,photo){
	document.getElementById(id).src = photo;	
}


/**
* 會員浮動資料框
* param o 對象
*/
function show_userinfo(o){
	if(o.className=='top_info01'){
		o.className = 'top_info02';		
		//o.title = '隱藏資料';
		document.getElementById("top_userinfo").style.display = "";
	}else{
		o.className = 'top_info01';
		//o.title = '顯示資料';
		document.getElementById("top_userinfo").style.display = "none";
	}
}

/**
* 顯示 10位數
*/
function format_ten(c){
	if(c<10){
		c = '0' + c;
	}
	return c;
}