﻿
	

//---不允許有不合法字句
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){//FF
   if( window.sidebar && window.sidebar.addPanel ) {  
      window.sidebar.addPanel( title, url+homepage, '' );
   }
   else if( window.external ) {// IE
      window.external.AddFavorite( url, title );
   }
   else { // Other browsers
      alert('抱歉,無法為您的瀏覽器中加入最愛功能,自行新增一個最愛聯結');
   }
}






function CityRegionCascade(strRegionFirstText, strCityDropID, strRegionDropID){
        var intSelectCityValue=document.getElementById(strCityDropID).value;
        var ddlRegion=document.getElementById(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;
            }
        }
}




function showClientMap(src, a, b) {
	var show1=document.getElementById("divClientMap");
	show1.innerHTML = "<iframe src="+src+" id='showVideo' name='showVideo' width='"+a+"' height='"+b+"' marginheight='0' marginheight='0' frameborder='0' scrolling='no'></iframe>";
}


function WSFailed(error){
    if (document.getElementById('divBlockBackGround')!=null){document.getElementById('divBlockBackGround').style.display='none';}
    if (document.getElementById('divPopUpMsg')!=null){document.getElementById('divPopUpMsg').style.display='none';}
    if(error !== null) {
        var strStackTrace='';
        var strMessage='';
        var strStatusCode='';
        var strExceptionType='';
        var strTimedOut='';
        strStackTrace=error.get_stackTrace()+"<br/>";
        strMessage=error.get_message()+"<br/>";
        strStatusCode=error.get_statusCode()+"<br/>";
        strExceptionType=error.get_exceptionType()+"<br/>";
        strTimedOut=error.get_timedOut()+"<br/>";
        wsNormal.errChiaMengAjax(strStackTrace, strMessage, strStatusCode, strExceptionType, strTimedOut);
//        alert('strStackTrace=' + strStackTrace + '\n\n' + 'strMessage=' + strMessage  + '\n\n' + 'strStatusCode=' + strStatusCode  + '\n\n' + 'strExceptionType=' + strExceptionType  + '\n\n' + 'strTimedOut=' + strTimedOut  + '\n\n');
        alert('錯誤：程式目前發生了一個未知錯誤，請您再重新試試'+'\n\n'+'造成您的使用不便之處，House-Info房屋資訊網深感報歉。');
    }         
}



//---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 '';
	        }
}


var strVCLabel='';
var strVCHidden='';
function reVCode(){
        document.getElementById('divPopUpMsg').style.display='block';
        setPopUpPosition('divPopUpMsg');
        SetBGDIVWH();
        wsNormal.reGetValidateCode(31, 1, onreVCodeSucceeded, WSFailed);
}
function onreVCodeSucceeded(returnObject, userContext, methodName){
            document.getElementById('divBlockBackGround').style.display='none';
            document.getElementById('divPopUpMsg').style.display='none';
            document.getElementById(strVCLabel).innerHTML=returnObject[0];
            document.getElementById(strVCHidden).value=returnObject[1];
}


 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;
    }
 }
 
//---至, 以上, 以下
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';}                
    }
}


 //---顯示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='';
}