
function Check_FormValue (this_value,msg)	//檢查form的欄位是否有輸入
{
    if( this_value =='' )
        return(msg);
    return "";
}

function Check_IsNumber (this_value,msg)	//檢查form的欄位是否輸入的是數字
{
	if( this_value =='' ){
		return(msg);
	}
	if (isNaN(this_value)){
		return(msg);
	}
	return "";
}

function Check_identity (identity)	//檢查身份證
{
	if (identity==''){
		return('請輸入--身分證號碼\n');
	}
	else{
		if(idCheck(identity)==false){
			return('您的身份證字號有誤\n');
		}
		else{
			return "";
		}
	}

}

function Check_identity2 (ident,radio)	//檢查身份證第二版有加RadioBox
{
	if(radio[0].checked){
		if (ident==''){
			return('請輸入--身分證號碼\n');
		}
		else{
			if(idCheck(ident)==false){
				return('您的身份證字號有誤\n');
			}
			else{
				return "";
			}
		}
	}
	if(radio[1].checked){
		if (ident==''){
			return('請輸入--護照號碼\n');
		}
		else{
			return "";
		}
	}
}

var LegalID = "0123456789"
function idCheck(id)		//檢查身份證用的函數
{   
   var fResult=true;
   var value = 0;
   var sId=id;
   if(sId.length<10) fResult=false;
   else
   {
     if((sId.charAt(0)=='A') || (sId.charAt(0)=='a')) value=10
     else if((sId.charAt(0)=='B') || (sId.charAt(0)=='b')) value=11
     else if((sId.charAt(0)=='C') || (sId.charAt(0)=='c')) value=12
     else if((sId.charAt(0)=='D') || (sId.charAt(0)=='d')) value=13
     else if((sId.charAt(0)=='E') || (sId.charAt(0)=='e')) value=14
     else if((sId.charAt(0)=='F') || (sId.charAt(0)=='f')) value=15
     else if((sId.charAt(0)=='G') || (sId.charAt(0)=='g')) value=16
     else if((sId.charAt(0)=='H') || (sId.charAt(0)=='h')) value=17
     else if((sId.charAt(0)=='J') || (sId.charAt(0)=='j')) value=18
     else if((sId.charAt(0)=='K') || (sId.charAt(0)=='k')) value=19
     else if((sId.charAt(0)=='L') || (sId.charAt(0)=='l')) value=20
     else if((sId.charAt(0)=='M') || (sId.charAt(0)=='m')) value=21
     else if((sId.charAt(0)=='N') || (sId.charAt(0)=='n')) value=22
     else if((sId.charAt(0)=='P') || (sId.charAt(0)=='p')) value=23
     else if((sId.charAt(0)=='Q') || (sId.charAt(0)=='q')) value=24
     else if((sId.charAt(0)=='R') || (sId.charAt(0)=='r')) value=25
     else if((sId.charAt(0)=='S') || (sId.charAt(0)=='s')) value=26
     else if((sId.charAt(0)=='T') || (sId.charAt(0)=='t')) value=27
     else if((sId.charAt(0)=='U') || (sId.charAt(0)=='u')) value=28
     else if((sId.charAt(0)=='V') || (sId.charAt(0)=='v')) value=29
     else if((sId.charAt(0)=='X') || (sId.charAt(0)=='x')) value=30
     else if((sId.charAt(0)=='Y') || (sId.charAt(0)=='y')) value=31
     else if((sId.charAt(0)=='W') || (sId.charAt(0)=='w')) value=32
     else if((sId.charAt(0)=='Z') || (sId.charAt(0)=='z')) value=33
     else if((sId.charAt(0)=='I') || (sId.charAt(0)=='i')) value=34
     else if((sId.charAt(0)=='O') || (sId.charAt(0)=='o')) value=35
     else fResult = false ;
     //alert('Value='+value) ;
   }
   if(fResult==true)
   {
     value = Math.floor(value/10) + (value%10)*9 +
             parseInt(sId.charAt(1))*8+
             parseInt(sId.charAt(2))*7+
             parseInt(sId.charAt(3))*6+
             parseInt(sId.charAt(4))*5+
             parseInt(sId.charAt(5))*4+
             parseInt(sId.charAt(6))*3+
             parseInt(sId.charAt(7))*2+
             parseInt(sId.charAt(8))+
             parseInt(sId.charAt(9)) ;

     value = value % 10 ;
     if(value!=0) fResult = false ;

     var i;
     var c;
     for (i = 1; i < sId.length; i++)
     {
      c = sId.charAt(i);
      if (LegalID.indexOf(c) == -1) fResult = false;
     }
    }
    return fResult ;
}

function check_email1 ( email )	//檢查email信箱的正確信
{
   var len = email.length;
   if(len==0)
      return "請輸入--電子郵件地址\n";
   for(var i=0;i<len;i++)
   {  var c= email.charAt(i);
      if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
         return "您的電子郵件地址只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用 !\n";
   }
   if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
      return "您的電子郵件地址不合法 !\n";
   if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
      return "您的電子郵件地址不合法 !\n";
   if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
      return "您的電子郵件地址不完全 !\n";
   return "";
}

function check_mobilephone (TelNumber){	//判斷行動電話
	var error = false;
	for( idx = 0 ; idx < TelNumber.length ; idx++ ) {
		if( !( ( TelNumber.charAt(idx) >= '0' && TelNumber.charAt(idx) <= '9' ) || ( TelNumber.charAt(idx) == '-' ) ) ) {
			error = true;
			break;
		}
	}
	if( error == true ){
		return "您的行動電話只能是數字及'-'等符號, 其他的符號都不能使用 !\n";
	}
	else{
		return "";
	}
}

function check_Tel (TelNumber){	//判斷電話
	var error = false;
	for( idx = 0 ; idx < TelNumber.length ; idx++ ) {
		if( !( ( TelNumber.charAt(idx) >= '0' && TelNumber.charAt(idx) <= '9' ) || ( TelNumber.charAt(idx) == '-' ) ) ) {
			error = true;
			break;
		}
	}
	if( error == true ){
		return "您的電話只能是數字及'-'等符號, 其他的符號都不能使用 !\n";
	}
	else{
		return "";
	}
}

function check_uid ( uid )	//判斷帳號用的函數
{
    if( uid.length <= 0 )
        return( "請輸入--帳號\n" );
    if( uid.length < 3 || uid.length > 16 )
        return( "您的帳號長度只能 3 至 16 個字元 !\n" );
    if ( !(uid.charAt(0) >= 'a' && uid.charAt(0) <= 'z') ) {
        return( "您的帳號第一字元只能為小寫字母 !\n" );
    }
    for( idx = 0 ; idx < uid.length ; idx++ )
    {
        if( uid.charAt(idx) >= 'A' && uid.charAt(idx) <= 'Z' )
            return( "帳號不可以含有大寫字元 !\n" );
        if( !( ( uid.charAt(idx) >= 'a' && uid.charAt(idx) <= 'z' ) || ( uid.charAt(idx) >= '0' && uid.charAt(idx) <= '9' ) || ( uid.charAt(idx) == '_' ) )  )
            return( "您的帳號只能是數字,英文字母及「_」等符號,其他的符號都不能使用 !\n" );
        if( uid.charAt(idx) == '_' && uid.charAt(idx-1) == '_' )
            return( "「_」符號不可相連 !\n" );
    }
    if( uid.charAt( uid.length - 1 ) == '_' )
        return( "「_」符號不可在最後 !\n" );
    return "";
}

function check_passwd ( pw1, pw2 )	//判斷兩個密碼是否有填,資料是否一樣
{
    if( pw1 == '' )  {
        return ("請輸入--密碼\n");
    }
    for( var idx = 0 ; idx < pw1.length ; idx++ )
        if( pw1.charAt(idx) == ' ' || pw1.charAt(idx) == '\"' )
            return ("密碼不可以含有空白或雙引號 !\n");
    if( pw1.length < 4 || pw1.length > 32 )
        return( "密碼長度只能 4 到 32 個字母 !\n" );
    if( pw1 != pw2 )
        return("密碼二次輸入不一樣,請重新輸入 !\n");
    return "";
}

function check_passwd2 (pw1)	//判斷密碼是否有填
{
    if( pw1 == '' )  {
        return ("請輸入--密碼\n");
    }
    for( var idx = 0 ; idx < pw1.length ; idx++ )
        if( pw1.charAt(idx) == ' ' || pw1.charAt(idx) == '\"' )
            return ("密碼不可以含有空白或雙引號 !\n");
    if( pw1.length < 4 || pw1.length > 32 )
        return( "密碼長度只能 4 到 32 個字母 !\n" );
    return "";
}

function CheckAll(form_name,element_name,ck){	//全選(t),全不選(f)
	len = form_name.elements.length;
	var i=0;
	for(i=0; i<len; i++){
		if (ck=='t'){
			if (form_name.elements[i].name==element_name){
				form_name.elements[i].checked=true;
			}
		}
		else {
			if (form_name.elements[i].name==element_name){
				form_name.elements[i].checked=false;
			}
		}
	}
}

function del_chk(form_name,element_name){	//檢查是否有勾選要刪除的資料,若有詢問是否要刪除
  var j=0
  var prtlen = form_name.elements.length
  var del_flag = 0
  	for(j=0;j < prtlen;j++){
  		if (form_name.elements[j].name==element_name){
			if(form_name.elements[j].checked==true){
				del_flag = 1
				break;
			}
		}
	}
	if(del_flag=='0'){
		alert("請您先勾選欲刪除的資料，再嘗試點選刪除按鈕。")
	}
	else{
		if(confirm('確定要刪除這些資料？')==true){
			form_name.submit()
		}
	}	

}

function CheckBoxValue(form_name,element_name){	//檢查是否有勾選
  var j=0
  var prtlen = form_name.elements.length
  var del_flag = 0
  	for(j=0;j < prtlen;j++){
  		if (form_name.elements[j].name==element_name){
			if(form_name.elements[j].checked==true){
				del_flag = 1
				break;
			}
		}
	}
	if(del_flag=='0'){
		return( "請您先勾選，再嘗試點選按鈕。\n" );
	}
	return "";
}

function CheckDate(CYMD){//檢查日期
	CYMD1=CYMD.split(",",5)
		for (i=1;i<7;i++){	
			//if ((CYMD1[i].length == 1)){
			//	CYMD1[i]="0"+CYMD1[i]
			//}
			sCYMD=CYMD1[0]+CYMD1[1]+CYMD1[2]
			eCYMD=CYMD1[3]+CYMD1[4]+CYMD1[5]
		}
		
		if ( sCYMD > eCYMD){
			return("日期迄不可小於日期起!\n" );
		}
	return "";

}

function AddItem(ListBox,ListBox2){	//用來將ListBox的資料移到ListBox2中
	var ListBoxLen =  ListBox.length	//ListBox的下拉選項數目
	var ListBox2Len =  ListBox2.length	//ListBox2的下拉選項數目
	var NewListBox2Len =  ListBox2.length	//要新增ListBox2下拉選項的數目
	
	
	for(i = 0 ; i < ListBoxLen ; i++ ){
		if(ListBox.options[i].selected){
			//alert(ListBox.options[ListBox.selectedIndex].text)
			ListBox2.options[NewListBox2Len] = new Option(ListBox.options[i].text);
			ListBox2.options[NewListBox2Len].value = ListBox.options[i].value;
			NewListBox2Len = NewListBox2Len + 1;
		}
	}

}

function DelItem(ListBox){	//刪除ListBox中的項目

	var ListBoxLen = ListBox.length;
	//var min=0;
	for(i = ListBoxLen-1 ; i >= 0 ; i-- ){
		if(ListBox.options[i].selected){
			//if(min==0 || i<min){
			//	min=i;
				ListBox.options[i] = null;
			//}
		}
	}
}

function AddItem2(ListBox,ListBox2){	//用來將ListBox的資料移到ListBox2中
	var ListBoxLen =  ListBox.length	//ListBox的下拉選項數目
	var ListBox2Len =  ListBox2.length	//ListBox2的下拉選項數目
	var NewListBox2Len =  ListBox2.length	//要新增ListBox2下拉選項的數目
	
	
	for(i = 0 ; i < ListBoxLen ; i++ ){
		if(ListBox.options[i].selected){
			//alert(ListBox.options[ListBox.selectedIndex].text)
			ListBox2.options[NewListBox2Len] = new Option(ListBox.options[i].text);
			ListBox2.options[NewListBox2Len].value = ListBox.options[i].value;
			NewListBox2Len = NewListBox2Len + 1;
		}
	}
	
	for(i = ListBoxLen-1 ; i >= 0 ; i-- ){	//刪除ListBox中的項目
		if(ListBox.options[i].selected){
			ListBox.options[i] = null;
		}
	}

}


function del_chkCal(form_name,ID){	//是否要刪除資料,若有詢問是否要刪除
	var sID
	sID=ID
		if(confirm('確定要刪除這些資料？')==true){
			window.navigate ("Calendar_deleng.asp?sID="+sID)	
		}
}

function Keydown_EnterToTab(){	//當按下enter鍵時會變成tab鍵
	if (window.event.keyCode==13){
		window.event.keyCode=9;
	}
}

function OnLoadObjectFocus(element_name){	//將游標移到此物件上
	element_name.focus();//設為焦點
}

function OpenNewWin (UrlPath,WinName,Ww,Wh,Wx,Wy){	//開新視窗
	//UrlPath : 要開啟的視窗程式
	//WinName : 視窗程式的名字
	//Ww : 視窗程式的寬
	//Wh : 視窗程式的高
	//Wx : 視窗程式的Top位置
	//Wy : 視窗程式的Left位置
	var Set = ''
	Set += 'toolbar=no,'
	Set += 'location=no,'
	Set += 'directories=no,'
	Set += 'status=no,'
	Set += 'menubar=no,'
	Set += 'scrollbars=yes,'
	Set += 'resizable=yes,'
	Set += 'width=' + Ww + ','
	Set += 'height=' + Wh + ','
	Set += 'copyhistory=no'
	
	//alert(Set)
	window.open(UrlPath,WinName,Set).moveTo(Wx,Wy); 	
}

function Check_YMDT (sStart,sEnd)	//檢查form的欄位日期資料是否有輸入
{var msg1,msg2;
	if ((sStart == "") || (sEnd == "")) {
			if (sStart == ""){
				msg1="請輸入--廣告顯示時間起!\n"
			}
			else{
				msg1=""
			}
			
			if (sEnd == ""){
				msg2="請輸入--廣告顯示時間迄!\n"
			}
			else{
				msg2=""
			}
		return(msg1+msg2);
	}
	else{
		return"";
	}
}

function Check_Time (sStart,sEnd){					//檢查form的日期個數及是否為數字
	var a,msg1,msg2,msg3,strmsg,strStart,strEnd,sMonth;
	strStart=sStart
	strEnd=sEnd
	sMonth=strStart.substr(3,2)
		if ((sStart == "") || (isNaN(sStart) == true)||(strStart.length < 7)||(strStart.length > 7)) {
			msg1="顯示時間起請輸入7位，且為數字!\n"
		}
		else{
			msg1=""
		}

		if ( (sEnd == "") || (isNaN(sEnd) == true)||(strEnd.length < 7)||(strEnd.length > 7)) {
			msg2="顯示時間迄請輸滿7位，且為數字!\n"
		}
		else{
			msg2=""
		}
		
		if ((isNaN(sStart) == false) && (isNaN(sEnd) == false)){
			if( sStart > sEnd ){
				msg3="顯示時間迄不得小於顯示時間起!\n"
			}
			else{
				msg3=""
			}
		}	
		else {
			msg3=""
				
		}
		
		strmsg=msg1+msg2+msg3
	return (strmsg);
}

function Check_Time1 (sStart,sEnd){					//檢查form的日期個數及是否為數字(年、月、日、時、分)
	var a,msg1,msg2,msg3,strmsg,strStart,strEnd,sMonth;
	strStart=sStart
	strEnd=sEnd
	sMonth=strStart.substr(3,2)
		if ((sStart == "") || (isNaN(sStart) == true)||(strStart.length < 11)||(strStart.length > 11)) {
			msg1="顯示時間起請輸入11位，且為數字!\n"
		}
		else{
			msg1=""
		}

		if ( (sEnd == "") || (isNaN(sEnd) == true)||(strEnd.length < 11)||(strEnd.length > 11)) {
			msg2="顯示時間迄請輸滿11位，且為數字!\n"
		}
		else{
			msg2=""
		}
		
		if ((isNaN(sStart) == false) && (isNaN(sEnd) == false)){
			if( sStart > sEnd ){
				msg3="顯示時間迄不得小於顯示時間起!\n"
			}
			else{
				msg3=""
			}
		}	
		else {
			msg3=""
				
		}
		
		strmsg=msg1+msg2+msg3
	return (strmsg);
}


function Check_Time2 (sStart,sEnd){	//檢查form的時間起
var msg1,msg2,strStart,strEnd;
strStart=sStart
strEnd=sEnd

	if (( strStart.substr(7,2) != "")||( strStart.substr(9,2) != "")){
		if ( strStart.substr(7,2) >= 24 ) {
			msg1="時間起不得超過24小時!\n"
		}
		else{
			msg1=""
		}
		if (strStart.substr(9,2) > 59){
			msg2="時間起不得超過59分!\n"
		}
		else{
			msg2=""
		}
		return (msg1+msg2)	;
	}
	else{
		return "";
	}
}

function Check_Time3 (sStart,sEnd){	//檢查form的時間迄
var msg1,msg2,strStart,strEnd;
strStart=sStart
strEnd=sEnd	
	if (( strEnd.substr(7,2) != "")||( strEnd.substr(9,2) != "")){
		if ( strEnd.substr(7,2) >= 24 ) {
			msg1="時間迄不得超過24小時!\n"
		}
		else{
			msg1=""
		}
		if (strEnd.substr(9,2) > 59){
			msg2="時間迄不得超過59分!\n"
		}
		else{
			msg2=""
		}

		return (msg1+msg2);
		
	}
	else{
		return "";
	}	
}


function check_sMonth (sStart){
	var msg,msg1,msg2,msg3,strmsg,strStart,strEnd,sMonth;
	strStart=sStart
	sMonth=strStart.substr(3,2)
		if (strStart.substr(3,2) > 12){
			msg="顯示日期起--月不可大於12\n"
		}
		else{
			msg=""
		}

  		if (sMonth==1|| sMonth==3 || sMonth==5 || sMonth==7 || sMonth==8 || sMonth==10 || sMonth==12 ){
			if (strStart.substr(5,2) > 31){
				msg1="顯示日期起--大月日期至31號\n"
			}
			else{
				msg1=""
			}
		}
		else{
			msg1=""
		}

		if(sMonth==2){
			if (strStart.substr(5,2) > 29){
				msg2="顯示日期起--2月日期只至28號或29\n"
			}
			else{
				msg2=""
			}
		}
		else{
			msg2=""
		}		
		
		
		if(sMonth==4|| sMonth==6 || sMonth==9 || sMonth==11){
			if (strStart.substr(5,2) > 30){
				msg3="顯示日期起--小月日期只至30號\n"
			}
			else{
				msg3=""
			}
		}
		else{
			msg3=""
		}
		
	strmsg=msg1+msg2+msg3+msg
	return (strmsg);		

}

function check_eMonth (sEnd){
	var msg,msg1,msg2,msg3,strmsg,strStart,strEnd,eMonth,sEnd;
	strEnd=sEnd
	eMonth=strEnd.substr(3,2)
		if (strEnd.substr(3,2) > 12){
			msg="顯示日期迄--月不可大於12!\n"
		}
		else{
			msg=""
		}

  		if (eMonth==1|| eMonth==3 || eMonth==5 || eMonth==7 || eMonth==8 || eMonth==10 || eMonth==12 ){
			if (strEnd.substr(5,2) > 31){
				msg1="顯示日期迄--大月日期至31號!\n"
			}
			else{
				msg1=""
			}
		}
		else{
			msg1=""
		}

		if(eMonth==2){
			if (strEnd.substr(5,2) > 29){
				msg2="顯示日期迄--2月日期只至28號或29!\n"
			}
			else{
				msg2=""
			}
		}
		else{
			msg2=""
		}		
		
		
		if(eMonth==4|| eMonth==6 || eMonth==9 || eMonth==11){
			if (strEnd.substr(5,2) > 30){
				msg3="顯示日期迄--小月日期只至30號!\n"
			}
			else{
				msg3=""
			}
		}
		else{
			msg3=""
		}
		
	strmsg=msg1+msg2+msg3+msg
	return (strmsg);		

}



function Check_Money (this_value)	//檢查form的費用欄位是否輸入的是數字
{

	if (this_value == "") {
		return("請輸入--廣告費用!\n");
	}
	else{
		if ((this_value != "") && isNaN(this_value)){
			return("費用請輸入數字!\n");
		} 
	return "";
    }
   
}


function ReverseDemo()
{
  var a, l;
  a = new Array(0,1,2,3,4);
  MSS = a.reverse();
  return(MSS);
}
