


function switchDisplay(id){
	
	var obj=document.getElementById(id);
	if(obj!=null){
		var divstyle=obj.style.display	
		if(divstyle=="none"){
			obj.style.display="block";
		}else{
			obj.style.display="none";
		}
	}
}
function openWin(url, width, height){
	if(width==null){
		width="600";
	}
	if(height==null){
		height="450";
	}
	var Win = window.open(url,'','width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
}
function openModal(url,width,height,parmenter){
	if (url.indexOf('?')<0){
    	url=url +"?nowtime="+ new Date().getTime();
   	}else{ 
		url=url+'&nowtime='+new Date().getTime();
	}
	if(width==null){
		width="550";
	}
	if(height==null){
		height="500";
	}
	if(parmenter==null){
		parmenter=window;
	}	
	window.showModalDialog(url,parmenter,'dialogWidth='+width+'px;dialogHeight='+height+'px;top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no,status=no');
}	    
function openFeeTryCompute(url){
	openModal(url,550,450,'');
}
/**
 * 寫入指定要求的cookie
 * name : cookie名字
 * value: cookie值
 * seconds:cookie過期時間,單位:秒
 */
function writeCookie(name, value, seconds){
	var expire = "";
	if(seconds){
		expire = new Date((new Date()).getTime() + seconds * 1000);
		expire = "; expires=" + expire.toGMTString()+"; path=/";
	}
	document.cookie = name + "=" + escape(value) + expire;
}


// Example:
// alert( readCookie("myCookie") );
/**
 *	讀取指定名字的cookie值
 * name : 要讀取的cookie名字
 */
function readCookie(name){
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if (offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1){end = document.cookie.length;}
			cookieValue = unescape(document.cookie.substring(offset, end));
		}
	}
	return cookieValue;
}
String.prototype.trim=function(){
   return   this.replace(/(^\s*)|(\s*$)/g,"");
}



//圖片寬度自動調整
var flag=false; 
function DrawImage(ImgD,intWidth,intHeight){
  var image=new Image(); 
  var iwidth = intWidth;  // 
  var iheight = intHeight;  //
  image.src=ImgD.src; 
  if(image.width>0 && image.height>0){ 
   flag=true; 
   if(image.width/image.height>= iwidth/iheight){ 
    if(image.width>iwidth){   
    ImgD.width=iwidth; 
    ImgD.height=(image.height*iwidth)/image.width; 
    }else{ 
    ImgD.width=image.width;   
    ImgD.height=image.height; 
    }
    } 
   else{ 
    if(image.height>iheight){   
    ImgD.height=iheight; 
    ImgD.width=(image.width*iheight)/image.height;      
    }else{ 
    ImgD.width=image.width;   
    ImgD.height=image.height; 
    } 

    }
   } 
} 



//cary add
//按照比例自動調整圖片大小函數
function DrawImage2(ImgD,intWidth,intHeight){ 
// imagefit:function (fitw,fith){
  var image=new Image();
 // var iwidth = intWidth;  // 
 // var iheight = intHeight;  //
 
image.src=ImgD.src; 
fitw=image.width;
fith=image.height;
//alert(fitw+","+fith);
  var maxwidth=intWidth;//預先設置的所期望的寬的值
  var maxheight=intHeight;//預先設置的所期望的高的值 
  if(fitw>maxwidth||fith>maxheight){//現有圖片只有寬或高超了預設值就進行js控制
     var w=fitw/maxwidth; 
     var h=fith/maxheight;
		  if(w>h){//比值比較大==>寬比高大
				   //定下寬度為width的寬度
			   fitw=maxwidth; 
				   //以下為計算高度
			   fith=parseInt(fith/w); 
			  }else{//高比寬大 
			   //定下寬度為height高度 
			  fith=maxheight; 
			  //以下為計算高度 
			  fitw=parseInt(fitw/h); 
					} 
		//alert(fitw>maxwidth);
		//alert(fith>maxheight);
		
	ImgD.width=fitw;   
    ImgD.height=fith; 
   } 

}


//div切換
function showDiv(obj,num,len){
 for(var id = 1;id<=len;id++){
  var ss=obj+id;
  if(id==num){
		try{			
			document.getElementById(ss).style.display="block";
		}
		catch(e){};
  }else{
		  try{
			   document.getElementById(ss).style.display="none";
			  }catch(e){};
  		}
 }  
}

//輸入長度限制 中文占2位元
function textLimitCheck(thisArea, messageCount,maxLength){//根據onkeyup事件計算文字方塊中的字元個數，限制在500以內
	 if (countCharacters(thisArea.value) > maxLength){
	   alert('已超出' + maxLength + ' 個字元限制. ');
	   thisArea.value = thisArea.value.substring(0, maxLength);
	   thisArea.focus();
	 }
	 /*回寫span的值，當前填寫文字的數量*/
	  $("#"+messageCount).html(countCharacters(thisArea.value));
}
  
//輸入長度限制 中文占2字元
function textLimitCheck2(thisArea, messageCount,maxLength){//根據onkeyup事件計算文字方塊中的字元個數，限制在500以內
	 if (countCharacters(thisArea.value) > maxLength){
	   alert(maxLength + ' 個字限制. ');
	   thisArea.value = thisArea.value.substring(0, maxLength);
	   thisArea.focus();
	 }
	 /*回寫span的值，當前填寫文字的數量*/
	//  document.getElementById(messageCount).innerHTML=countCharacters(thisArea.value);
	 $("#"+messageCount).html(countCharacters(thisArea.value));
}
//截取字串的特定長度
function LimitsTring(str,ll){
    var totalCount = 0;
    var nw=str.substr(0,500);

    return nw;
}

//計算字元長度
function countCharacters(str){
    var totalCount = 0;  
    for (var i=0; i<str.length; i++) {  
        var c = str.charCodeAt(i);  
    if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {  
           totalCount++;  
        }else {     
            totalCount+=2;  //中文雙位元
        }  
    }
    return totalCount;
}

//全形數字
function isNumber(val) 
{
   var reg = /[\d]+/;
    return reg.test(val);
}

//>0
function isNumberandOverzero(val) {	
   var reg = /[\d]+/;
  // var reg = /^[1-6][\d]/;
   
   //alert(reg.test(val));
    if(reg.test(val)){
		if(val*1>0){
			return true;	
		}	
	}
	
	return false;
}


function isIdNumber(val) {	
   var reg = /[A-Z]\d{9,9}/;	
	return reg.test(val);
}





//===============================================