﻿
    function openDisableControl(){
        document .getElementById ('btnSearch').style.display='inline';
    }
	

//---不允許有不合法字句
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 '';
}

	

//---小視窗位置在瀏覽器中央
function OpenPopUpWindow(theURL,winName,intWidth,intHeight,strFeatures) { 
		var intTop=(screen.availHeight - intHeight) / 2 ;
		var intLeft=(screen.availWidth - intWidth) / 2 ;
		strFeatures += ',top=' + intTop + ',left=' + intLeft + ',width=' + intWidth + ',height=' + intHeight ;
		window.open(theURL,winName,strFeatures);
}

    
    
 //---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';
      }
}



//---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;
    }
	
	
	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';	
	
}




//---去左右空白
function TrimTextBoxValue(strControlValue){
	strControlValue = strControlValue.replace(/^[\s　]+/g, "");
	strControlValue = strControlValue.replace(/[\s　]+$/g, "");
	strControlValue = strControlValue.replace(/[\s　]+/g, " ");
	return strControlValue;
}

//---TextArea計數器
function TextAreaCounter(objTextArea, strRemainLabelID, intMaxLimit) {
  if (objTextArea.value.length > intMaxLimit) {
    objTextArea.value = objTextArea.value.substring(0,intMaxLimit);
  }
  else {
    document.getElementById(strRemainLabelID).innerHTML='尚能輸入 ' + (intMaxLimit - objTextArea.value.length) + ' 個字';
  }
}



function AddFavorite(url, title, homepage){
   if( window.sidebar && window.sidebar.addPanel ) {  
      window.sidebar.addPanel( title, url+homepage, '' );
   }
   else if( window.external ) {     // IE
      window.external.AddFavorite( url, title );
   }
   else if( document.layers ) {     // NS4
      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;
            }
        }
}



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 parentCheck(parentID, parentValue){
        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('chkRegion_',0) != '-1'){
                        var arrTmp=strCheckID.split("_");
                        if (parseInt(arrTmp[1])==parseInt(parentValue)){
                            if (document.getElementById (parentID).checked==true){document.getElementById(strCheckID).checked=true;}
                            if (document.getElementById (parentID).checked==false){document.getElementById(strCheckID).checked=false;}
                        }
                    }
                }
          }
 }
 
 function childCheck(childID, parentID){
    if (document.getElementById(childID).checked==false){
        document.getElementById(parentID).checked=false;
    }
 }
 
 
 
//---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 '';
}



//---check email format
function EmailFormat(strEmailControlID, strAlertMsg){
            strEmail=document.getElementById(strEmailControlID).value ;
	        strEmail = strEmail.replace(/^[\s　]+/g, "");
            strEmail = strEmail.replace(/[\s　]+$/g, "");
	        if (strEmail != ''){
		        var intEmailLength = strEmail.length;
		        for(var intI=0;intI<intEmailLength;intI++){ 
			        var strEmailChar= strEmail.charAt(intI);
			        if(!((strEmailChar>="A"&&strEmailChar<="Z")||(strEmailChar>="a"&&strEmailChar<="z")||(strEmailChar>="0"&&strEmailChar<="9")||(strEmailChar=="-")||(strEmailChar=="_")||(strEmailChar==".")||(strEmailChar=="@")))
				        return strAlertMsg+'\n';
		        }
		        if((strEmail.indexOf("@")==-1)||(strEmail.indexOf("@")==0)||(strEmail.indexOf("@")==(intEmailLength-1)))
			        return strAlertMsg+'\n\n';
    				
		        if((strEmail.indexOf("@")!=-1)&&(strEmail.substring(strEmail.indexOf("@")+1,intEmailLength).indexOf("@")!=-1))
			        return strAlertMsg+'\n\n';
    				
		        if((strEmail.indexOf(".")==-1)||(strEmail.indexOf(".")==0)||(strEmail.lastIndexOf(".")==(intEmailLength-1)))
			        return strAlertMsg+'\n\n';
    				
		        return '';
	        }
	        else{
		        return '';
	        }
}

function slideStringSub(ul, delay, speed, lh) {
			var slideBox = (typeof ul == 'string')?document.getElementById(ul):ul;
			var delay = delay||1000, speed=speed||20, lh = lh||20;
			var tid = null, pause = false;
			var start = function() {
				tid=setInterval(slide, speed);
			}
			var slide = function() {
				if (pause) return;
				slideBox.scrollTop += 2;
				if (slideBox.scrollTop % lh == 0) {
					clearInterval(tid);
					slideBox.appendChild(slideBox.getElementsByTagName('li')[0]);
					slideBox.scrollTop = 0;
					setTimeout(start, delay);
				}
			}
			slideBox.onmouseover=function(){pause=true;}
			slideBox.onmouseout=function(){pause=false;}
			setTimeout(start, delay);
}
//---至, 以上, 以下
function FromToSub(startId, betweenId, endId){
    if (document.getElementById(startId).value=='-1'){
        document.getElementById(betweenId).style.display='none';
        document.getElementById(endId).style.display='none';
    }else{
        document.getElementById(betweenId).style.display='inline';
        if (document.getElementById(betweenId).value=='between'){
            document.getElementById(endId).style.display='inline';
        }else{document.getElementById(endId).style.display='none';}                
    }
}

function closePopUpDiv(){
    document.getElementById('divBlockBackGround').style.display='none';
    document.getElementById('divPopUpMsg').style.display='none';
    document.getElementById('divPublicPopUp').style.display='none';
    document.getElementById('divPublicPopUp').innerHTML='';
}

 //---顯示detail
function ShowPopUpDetail(path, width, height){
        document.getElementById('divBlockBackGround').style.display='block';
        document.getElementById('divPublicPopUp').style.display='block';
        document.getElementById('divPublicPopUp').style.width=width+'px';
        document.getElementById('divPublicPopUp').style.height=height+'px';
        setPopUpPosition('divPublicPopUp');
        SetBGDIVWH();
        document.getElementById('divPublicPopUp').innerHTML='';
        if(document.getElementById('ifPublicPopUp')==null){
            document.getElementById('divPublicPopUp').innerHTML="<iframe name='ifPublicPopUp' id='ifPublicPopUp' width='100%' height='92%' frameborder='0' scrolling='auto'></iframe>";
        }
        document.getElementById('divPublicPopUp').innerHTML +="<div class='butt'><input type ='button' id='btnClose' value='關閉視窗' onclick='parent.BackGroundDIVClick();' style='width:80px;'/></div>";
        document.getElementById('ifPublicPopUp').src=path;         
}

function BackGroundDIVClick(){
        document.getElementById('divBlockBackGround').style.display='none';
        document.getElementById('divPublicPopUp').style.display='none';
        document.getElementById('ifPublicPopUp').src='';
}