function trim(theString){
	while(theString.substr(0,1)==" ")
		theString=theString.substr(1);

	while(theString.substr(theString.length-1,1)==" ")
		theString=theString.substr(0,theString.length-1);

	return theString;
}

function isIDCardNo(theIDCardNumber){

	var IDCardNumber=theIDCardNumber.toUpperCase();

	if(IDCardNumber.length!=10) return false;

	var aryAlphabet=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
	var aryCorrespondingNumeric=["10","11","12","13","14","15","16","17","34","18","19","20","21","22","35","23","24","25","26","27","28","29","32","30","31","33"];

	var FirstCharacter=IDCardNumber.charAt(0);
	var SecondCharacter=IDCardNumber.charAt(1);
	var VerifyCode=IDCardNumber.charAt(IDCardNumber.length-1);
	if(SecondCharacter!="1"&&SecondCharacter!="2") return false;
	if(isNaN(VerifyCode)) return false;

	var IsAlphabet=false;

	for(i=0;i<aryAlphabet.length;i++){
		if(FirstCharacter==aryAlphabet[i]){
			AlphaNum=aryCorrespondingNumeric[i];
			IsAlphabet=true;
			break;
		}
	}

	if(IsAlphabet){

		var SumForAlphabetChar=parseInt(AlphaNum.charAt(0))+(9*parseInt(AlphaNum.charAt(AlphaNum.length-1)));
		var strRestChar=IDCardNumber.substr(2);

		if(!isNaN(strRestChar)){

			for(i=1;i<IDCardNumber.length-1;i++)
				SumForAlphabetChar+=parseInt(IDCardNumber.charAt(i))*(9-i);

			var Remainder=SumForAlphabetChar%10;
			var CalculatedVerifyCode=Remainder==0?0:10-(SumForAlphabetChar%10);
			return CalculatedVerifyCode==parseInt(VerifyCode);
		}

		else return false;
	}

	else return false;
}



function chkLogin(theForm){

	var msg="";
	var j=0;
	alert(theForm.Account.value);
		return false;
	var memaccount=trim(theForm.Account.value);
	var mempwd=trim(theForm.MPassword.value);

	msg+=memaccount==""?(++j)+". 請輸入帳號\n":"";
	msg+=mempwd==""?(++j)+". 請輸入密碼\n":"";

	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
		return false;
	}

}

function goLogin(theForm){

	var msg="";
	var j=0;

	var memaccount=trim(theForm.Account.value);
	var mempwd=trim(theForm.MPassword.value);

	msg+=memaccount==""?(++j)+". 請輸入帳號\n":"";
	msg+=mempwd==""?(++j)+". 請輸入密碼\n":"";
	
	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
	}else{
		theForm.submit();
	}

}

function indexLogin(theForm){

	var msg="";
	var j=0;

	var memaccount=trim(theForm.Account.value);
	var mempwd=trim(theForm.MPassword.value);

	msg+=memaccount==""?(++j)+". 請輸入帳號\n":"";
	msg+=mempwd==""?(++j)+". 請輸入密碼\n":"";
	
	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
	}else{
		theForm.submit();
	}

}

function needLogin(theForm){

	var msg="";
	var j=0;

	var memaccount=trim(theForm.Account.value);

	if (memaccount == 0)
	{
	msg="請先登入會員";
	}	
	if(msg!=""){
		alert(msg);
		document.location.href = "../../member/login.asp?MenuId=2&CatId=7";

	}else{
		theForm.submit();
	}

}

function voteLogin(theForm){

	var msg="";
	var j=0;

	var memaccount=trim(theForm.Account.value);
	var blnVoteOptionChecked = true;
	var vo=theForm.VoteOption;
	var vid=theForm.VoteId;

	if (memaccount == 0)
	{
	msg="抱歉，非會員不得投票喔～請先登入或加入會員！";
	}	
	if(msg!=""){
		alert(msg);
		document.location.href = "../../index.asp";

	}else{
		theForm.submit();
		//document.location.href = "../../index/saveVote.asp";
		//document.form.action=""
	}

}


function chkBlogin(theForm){

	var msg="";
	var j=0;
	var intregexp=/\d+/;

	var vipno=trim(theForm.VIP_NO.value);
	var idno=trim(theForm.ID_NO.value);
	var vipnotest = (vipno.length >= 10) && (vipno.length <= 10) 

	var y = theForm.year.value;
	var m = theForm.month.value;
	var ey = theForm.EYear.value;
	var em = theForm.EMonth.value;
	var newd = new Date();
	var blnNotValidDate = (y<newd.getYear()&&parseInt(m)<parseInt(em))||(y==newd.getYear()&&parseInt(m)>newd.getMonth()+1);

	msg+=(idno==""&&vipno=="")?(++j)+". 請輸入您的身份證字號或\門市會員卡-卡號n":"";
	//msg+=idno==""?(++j)+". 請輸入您的身份證字號\n":"";
	//msg+=vipno==""?(++j)+". 請輸入您的門市會員卡-卡號\n":isNaN(vipno)?(++j)+". 門市會員卡號請輸入數字\n":"";
	if (vipno!= "")
	{
		msg+=vipnotest?"":(++j)+". 請輸入10碼數字的門市會員卡-卡號\n";
	}


	msg+=blnNotValidDate?(++j)+". 請選擇正確的日期區間\n":"";

	if(msg!=""){
		alert("請檢查以下項目\n\n"+msg);
		return false;
	}

	showProgress();

}

window.onload=init();

function init(){
	//define universal dsoc left point
	var dsocleft=document.all? document.body.scrollLeft : pageXOffset;
	//define universal dsoc top point
	var dsoctop=document.all? document.body.scrollTop : pageYOffset;
	var topoffset=document.all? 250 : 0;
	//define universal browser window width
	var window_width=document.all? document.body.clientWidth : window.innerWidth;
	var window_height=document.all? document.body.clientHeight : window.innerHeight;
	var pgs=document.getElementById("_pgs");

	//if the user is using IE 4+ or NS6+
	if (document.all||document.getElementById){
		pgs.style.left=parseInt(dsocleft)+(parseInt(window_width)-350)/2+"px";
		pgs.style.top=dsoctop+100+parseInt(window_height)/2+topoffset+"px";
	}
	//else if the user is using NS 4
	else if (document.layers){
		pgs.left=dsocleft+(parseInt(window_width)-350)/2+"px";
		pgs.top=dsoctop+100+parseInt(window_height)/2+topoffset+"px";
	}
}

function showProgress(){
	var pgs=document.getElementById("_pgs");
	pgs.innerHTML="<br /><br /><span style=\"font: normal bold 13px tahoma,verdana; color: #0000ff; text-align: right; padding: 150px 0 0 100px;;\">資料搜尋中，請稍候...</span>";
	pgs.style.display="";
}

