﻿//---TextBox必須有值
function TextBoxMustFill(strControlID, strErrorMsg){
	var strControlValue='';
	strControlValue=document.getElementById(strControlID).value ;
	strControlValue = strControlValue.replace(/^[\s　]+/g, "");
	strControlValue = strControlValue.replace(/[\s　]+$/g, "");
	strControlValue = strControlValue.replace(/[\s　]+/g, " ");
	if  (strControlValue.length == 0){
	    return strErrorMsg + '\n\n';
	}
    return('');
}
	

//---不允許有不合法字句
function FormStopWord(strErrorMsg, arystrStopWord){
    for (var intI = 0 ; intI < document.form1.length ; intI++) {
            if ((document.form1.elements[intI].type == 'text')||(document.form1.elements[intI].type == 'textarea')) {
                var strTextBoxValue=document.getElementById(document.form1.elements[intI].id).value;
                strTextBoxValue = strTextBoxValue.replace(/^[\s　]+/g, "");
                strTextBoxValue = strTextBoxValue.replace(/[\s　]+$/g, "");
                strTextBoxValue = strTextBoxValue.replace(/[\s　]+/g, " ");
                if (strTextBoxValue.length != 0){
                        strTextBoxValue=strTextBoxValue.toLowerCase();
                        for (var intJ = 0 ; intJ < arystrStopWord.length ; intJ++) {
                                var strStopWord=arystrStopWord[intJ].toLowerCase();
                                if (strTextBoxValue.indexOf(strStopWord,0)!=-1){
	                                return strErrorMsg + '\n\n';                    
	                                break;
                                }
                        }
                }
            }
      }
      return '';
}
	
	
	

//---dropdown必須選一項目
function DropDownListMustSelect(strddlID, strErrorMsg){
		var strControlValue='';
		strControlValue=document.getElementById(strddlID).value ;
		strControlValue = strControlValue.replace(/^[\s　]+/g, "");
		strControlValue = strControlValue.replace(/[\s　]+$/g, "");
		strControlValue = strControlValue.replace(/[\s　]+/g, " ");
		if ((strControlValue == '-1') || (strControlValue == '')){	
		    return strErrorMsg + '\n\n';
		}
        return '';
}
	

//---textbox必須是數字
function TextBoxMustBeNumeric(strTextBoxID, strErrorMsg){
		var strControlValue='';
		strControlValue=document.getElementById(strTextBoxID).value ;
		strControlValue = strControlValue.replace(/^[\s　]+/g, "");
		strControlValue = strControlValue.replace(/[\s　]+$/g, "");
		strControlValue = strControlValue.replace(/[\s　]+/g, " ");
		if  (strControlValue.length != 0){
			if  (isNaN(strControlValue) == true){	
			    return strErrorMsg + '\n\n';
			}
		}
		return '';
}
//---textbox必須是大於或大於0
function TextBoxNumericType(strTextBoxID, strErrorMsg, blnAllowLessZero, blnAllowZero, blnAllowDot){
		var strControlValue='';
		strControlValue=document.getElementById(strTextBoxID).value ;
		strControlValue = strControlValue.replace(/^[\s　]+/g, "");
		strControlValue = strControlValue.replace(/[\s　]+$/g, "");
		strControlValue = strControlValue.replace(/[\s　]+/g, " ");
		if  (strControlValue.length != 0){
		    if  (isNaN(strControlValue) == false){
		            var floControlValue=parseFloat(strControlValue);
		            if (blnAllowLessZero==false){
		                if (floControlValue<0){return strErrorMsg+'\n\n';}
		            }
		            if (blnAllowZero==false){
		                if (floControlValue==0){return strErrorMsg+'\n\n';}
		            }
		            if(blnAllowDot==false){
		                if (strControlValue.indexOf(".",0) != '-1'){return strErrorMsg+'\n\n';}
		            }
		    }
		}
		return '';	    
}
	



//---秀警告句
function ShowErrorMessage(){
    if (document.getElementById('ErrorMsgHidden').value!=''){
        alert(document.getElementById('ErrorMsgHidden').value);
        document.getElementById('ErrorMsgHidden').value=''; 
        return false;
    }
    return true;
}
    
    
 //---radio起碼要打一個勾       
function RadioMustSelectOne(strKeyWord, strMsg){
    var blnSelected=false;
    for (var intI = 0 ; intI < document.form1.length ; intI++) {
            if (document.form1.elements[intI].type == 'radio') {
                var strRadioID=document.form1.elements[intI].id ;
                if (strRadioID.indexOf(strKeyWord,0) != '-1'){
                    if (document.getElementById(strRadioID).checked==true){
                        blnSelected=true;
                        return '';
                    }
                }
            }
      }
      if (blnSelected==false){
            return strMsg+'\n\n';
      }
}

 //---checkbox起碼要打一個勾       
function CheckBoxMustSelectOne(strKeyWord, strMsg){
    var blnSelected=false;
    for (var intI = 0 ; intI < document.form1.length ; intI++) {
            if (document.form1.elements[intI].type == 'checkbox') {
                var strCheckID=document.form1.elements[intI].id ;
                if (strCheckID.indexOf(strKeyWord,0) != '-1'){
                    if (document.getElementById(strCheckID).checked==true){
                        blnSelected=true;
                        return '';
                    }
                }
            }
      }
      if (blnSelected==false){
            return strMsg+'\n\n';
      }
}
//---只允許數字
function TextBoxDigits(value, blnAllowDot){
    if(blnAllowDot==true){
        value=value.replace(/[^0123456789.]/g,'')
    }
    if(blnAllowDot==false){
        value=value.replace(/[^0123456789]/g,'')
    }
    return value;
}

//---Block background div fill full all screen
function SetBGDIVWH(){
    document.getElementById('divBlockBackGround').style.width=((document.documentElement.clientWidth>document.documentElement.scrollWidth)?document.documentElement.clientWidth:document.documentElement.scrollWidth)+'px';
    document.getElementById('divBlockBackGround').style.height=((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+'px';
}

//---set waiting progress div 
function xxxsetPopUpPosition(strPopUpDIVID){
        var intSW=((document.documentElement.clientWidth>document.documentElement.scrollWidth)?parseInt(document.documentElement.clientWidth/2):parseInt(document.documentElement.scrollWidth/2));
        var intHalfW=parseInt(parseInt(document.getElementById(strPopUpDIVID).style.width.replace('px',''))/2);             
     
        var intTop=0;
        intTop=document.documentElement.scrollTop + (document.documentElement.clientHeight)/2 -parseInt(parseInt(document.getElementById(strPopUpDIVID).style.height.replace('px',''))/2)
    
        document.getElementById(strPopUpDIVID).style.left=(intSW-intHalfW)+'px';
        document.getElementById(strPopUpDIVID).style.top=(intTop)+'px';
}


function setPopUpPosition(strPopUpDIVID) {
    var yScroll;
	if (self.innerHeight) {
		windowHeight = self.innerHeight;
	}	else {
		windowHeight = document.documentElement.clientHeight;
	}
	
	
	if (typeof document.body.style.maxHeight != "undefined") {////Mozilla, Safari,...IE7
        yScroll = 0;
    } else {//ie6
        yScroll = document.documentElement.scrollTop;
    }

	
//	alert(setY);
//	
//	if (! setY) {
//		if (self.pageYOffset) {
//		alert('111');
//			yScroll = self.pageYOffset;
//		yScroll = 0;
//		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
//		alert('222');
//			yScroll = document.documentElement.scrollTop;
////			yScroll = document.documentElement.scrollTop + (document.documentElement.clientHeight)/2 -parseInt(parseInt(document.getElementById(strPopUpDIVID).style.height.replace('px',''))/2)
//		} else if (document.body) {
////			  yScroll = document.body.scrollTop;
//			yScroll = document.documentElement.scrollTop + (document.documentElement.clientHeight)/2 -parseInt(parseInt(document.getElementById(strPopUpDIVID).style.height.replace('px',''))/2)
//		alert('333');
//		}
//	} else {
//		alert('444');
//		yScroll = 0;
//	}
	
	
	var posObj=document.getElementById(strPopUpDIVID);	
	posObj.style.left = (document.documentElement.clientWidth - parseInt(posObj.style.width))/2 + 'px';
	posObj.style.top = yScroll + (windowHeight - parseInt(posObj.style.height))/2 + 'px';	

//	posObj.style.marginLeft = - parseInt(posObj.style.width)/2 + 'px';
//	posObj.style.marginTop = - parseInt(posObj.style.height)/2 + 'px';	
	
	
}


//---按下Enter後,某個控制項自動去執行
function ControlClickByEnterKey(e,strControlClickedID){
		if (e.keyCode == 13){//Enter key
			e.returnValue=false;
			e.cancel = true;
			document.getElementById(strControlClickedID).click();
			return false;
		}
}

//---去左右空白
function TrimTextBoxValue(strControlValue){
	strControlValue = strControlValue.replace(/^[\s　]+/g, "");
	strControlValue = strControlValue.replace(/[\s　]+$/g, "");
	strControlValue = strControlValue.replace(/[\s　]+/g, " ");
	return strControlValue;
}



//---全選全不選
function SelectAllNoneSelectAllSub(strkeyWord, blnCheck){
    for (var intI = 0 ; intI < document.form1.length ; intI++) {
            if (document.form1.elements[intI].type == 'checkbox') {
                var strCheckID=document.form1.elements[intI].id ;
                if (strCheckID.indexOf(strkeyWord,0) != '-1'){
                    if (blnCheck==true){document.getElementById(strCheckID).checked=true}
                    if (blnCheck==false){document.getElementById(strCheckID).checked=false}
                }
            }
      }
}



function closePopUpDiv(){
    $get('divBlockBackGround').style.display='none';
    $get('divPopUpMsg').style.display='none';
    $get('divPublicPopUp').style.display='none';
    $get('divPublicPopUp').innerHTML='';
}



function AddFavorite(url, title){
   if( window.sidebar && window.sidebar.addPanel ) {   
      window.sidebar.addPanel( title, url+'index.aspx', '' );
   }
   else if( window.external ) {     // IE
      window.external.AddFavorite( url, title );
   }
   else if( document.layers ) {     // NS4
      alert('NS');
      alert( '請按 OK 後,再按鍵盤按鈕 Ctrl+D 建立一個新的書籤' );
   }
   else {     // Other browsers
      alert( '報歉, 無法為您的瀏覽器中加入最愛功能,自行新增一個最愛聯結' );
   }
}




function CityRegionCascade(strRegionFirstText, strCityDropID, strRegionDropID){
        var intSelectCityValue=$get(strCityDropID).value;
        var ddlRegion=$get(strRegionDropID);
        for (var intI=ddlRegion.options.length-1; intI>-1; intI--) {
            ddlRegion.remove(intI);
        }
        var objOption1=new Option(strRegionFirstText, '-1');
        ddlRegion.options[0]=objOption1;            
        for (intI=0; intI<arystrRegion.length; intI++) {
            if (parseInt(arystrRegion[intI].strCityID)==parseInt(intSelectCityValue)){
                var objOption=new Option(arystrRegion[intI].strText, arystrRegion[intI].strRegID);
                ddlRegion.options[ddlRegion.options.length]=objOption;
            }
        }
}


//---比較2值是否相同
function CompareTwoValue(strID1, strID2, strErrorMsg){
	var strValue1='';
	var strValue2='';
	strValue1=document.getElementById(strID1).value ;
	strValue1 = strValue1.replace(/^[\s　]+/g, "");
	strValue1 = strValue1.replace(/[\s　]+$/g, "");
	strValue1 = strValue1.replace(/[\s　]+/g, " ");
	strValue2=document.getElementById(strID2).value ;
	strValue2 = strValue2.replace(/^[\s　]+/g, "");
	strValue2 = strValue2.replace(/[\s　]+$/g, "");
	strValue2 = strValue2.replace(/[\s　]+/g, " ");
	if (strValue1==strValue2){
	    return '';
	}
    return strErrorMsg + '\n\n';
}

document.oncontextmenu = function(){return false;}
document.onselectstart = function(){return false;}
document.oncopy = function(){return false;}
document.oncut = function(){return false;}
document.ondrag = function(){return false;}


function moreLinkSub(){
    document.getElementById('divlnk').style.display='';
}


function  fontCol(Num){
document.getElementById(Num).style.color = "#ea625c";
}
function  fontColBack(Num){
document.getElementById(Num).style.color = "#CDCDCD";
}

function chgMenu(Mnum){
document.all['m'+Mnum].style.color="FFFF00"
}

function chgMenuout(OMnum){
document.all['m'+OMnum].style.color="#CCCCCC"
}


         function startLogin(){                
            var strAlert='';
            strAlert += TextBoxMustFill('txtAccount', '請填入帳號');
            strAlert += TextBoxMustFill('txtPassword', '請填入密碼');      
           if( strAlert != '' ){                     
			    alert(strAlert);
			    return false;
		    }      
            $get('divPopUpMsg').style.display='block';
            setPopUpPosition('divPopUpMsg');
            wsPublic.memberLogin($get('txtAccount').value, $get('txtPassword').value, onSucceeded, WSFailed);
         }
         
         
         function onSucceeded(returnObject, userContext, methodName){
                if (methodName=='memberLogin'){
                                switch(returnObject){
                                    case ("1"):{
                                        alert('登入成功，歡迎來到台灣法律教育推廣協會');
                                        break ;
                                    }
                                    case ("2"):{
                                        alert('登入失敗，請您再重新試試，謝謝');
                                        break ;
                                    }
                                    case ("3"):{
                                        alert('登入失敗，帳號或密碼有錯誤');
                                        break ;
                                    }
                                }
                }
                $get('divPopUpMsg').style.display='none';
         }
         
         function clearSub(){
            $get('txtAccount').value='';
            $get('txtPassword').value='';
         }
         
         
         
        if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
			
