function check_tw_id(sId){
  var LegalID = "0123456789"
  var fResult=true;
  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 ;
  }
  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;
    }
  }
  if(fResult == false)
    return false;
  else
    return true;
}


function formatNumber(number,pattern){
    var str            = number.toString();
    var strInt;
    var strFloat;
    var formatInt;
    var formatFloat;
    if(/\./g.test(pattern)){
        formatInt        = pattern.split('.')[0];
        formatFloat        = pattern.split('.')[1];
    }else{
        formatInt        = pattern;
        formatFloat        = null;
    }

    if(/\./g.test(str)){
        if(formatFloat!=null){
            var tempFloat    = Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);
            strInt        = (Math.floor(number)+Math.floor(tempFloat)).toString();                
            strFloat    = /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';            
        }else{
            strInt        = Math.round(number).toString();
            strFloat    = '0';
        }
    }else{
        strInt        = str;
        strFloat    = '0';
    }
    if(formatInt!=null){
        var outputInt    = '';
        var zero        = formatInt.match(/0*$/)[0].length;
        var comma        = null;
        if(/,/g.test(formatInt)){
            comma        = formatInt.match(/,[^,]*/)[0].length-1;
        }
        var newReg        = new RegExp('(\\d{'+comma+'})','g');

        if(strInt.length<zero){
            outputInt        = new Array(zero+1).join('0')+strInt;
            outputInt        = outputInt.substr(outputInt.length-zero,zero)
        }else{
            outputInt        = strInt;
        }

        var 
        outputInt            = outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')
        outputInt            = outputInt.replace(/^,/,'');

        strInt    = outputInt;
    }

    if(formatFloat!=null){
        var outputFloat    = '';
        var zero        = formatFloat.match(/^0*/)[0].length;

        if(strFloat.length<zero){
            outputFloat        = strFloat+new Array(zero+1).join('0');
            //outputFloat        = outputFloat.substring(0,formatFloat.length);
            var outputFloat1    = outputFloat.substring(0,zero);
            var outputFloat2    = outputFloat.substring(zero,formatFloat.length);
            outputFloat        = outputFloat1+outputFloat2.replace(/0*$/,'');
        }else{
            outputFloat        = strFloat.substring(0,formatFloat.length);
        }

        strFloat    = outputFloat;
    }else{
        if(pattern!='' || (pattern=='' && strFloat=='0')){
            strFloat    = '';
        }
    }

    return strInt+(strFloat==''?'':'.'+strFloat);
}


function openwindow(E, B, C) {
    var D = B, H = C, F = (screen.width - B) / 2, A = (screen.height - C) / 2, G = "width=" + D + ",height=" + H + ",left=" + F + ",top=" + A + ",menubar=no,scrollbars=yes,resizable=yes";
	window.open(E, "", G)
    return false;
}

function Sys() {};

Sys.Failure = function(transport) {
	
	if (transport.responseText != null) {
		
		alert(transport.responseText);
	
		if (transport.status == 401) {
			var url = '/AvivaBrokerage/security.do?method=logout';
			document.location.href = url;
		}
	}

};

Sys.ExtFailure = function(transport) {
	  
	if (transport.responseText != null) {
		
		alert(transport.responseText);
	
		if (transport.responseText == '請登入系統') {
			var url = '/AvivaBrokerage/security.do?method=logout';
			document.location.href = url;
		}
	} else {
		alert("不明錯誤");
	}

};


Sys.check = function(json,callback) {
	
	if (json.login != null &&  json.login == flase) { 
		
		Ext.MessageBox.alert("Warning", json.message,
				function() {
					  if (this.top == null) {
					  	document.location = "../js/authority/login.jsp";
					  } else {
					  	this.top.location = "../js/authority/login.jsp";
					  }
			
				}
				); 
		      
		
	} else {
		
		if (callback != null) {
			try {
				callback(json.status)();
			} catch(e) {}
		}
	} 

};


function dyniframesize(controlID) {
  		
  		 var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
    //extra height in px to add to iframe in FireFox 1.0+ browsers
    var FFextraHeight=getFFVersion>=0.1? 16 : 0 
    var pTar = null;
    if (document.getElementById)
    {
        pTar = document.getElementById(controlID);
    }
    else
    {
        eval('pTar = ' + controlID + ';');
    }
    if (pTar && !window.opera)
    {
        //begin resizing iframe
        //pTar.style.display="block"
        var h1=0, h2=0, h3=0;

        if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight)//如果用戶的瀏覽器是NetScape
        {
            //ns6 syntax
            h1 = pTar.contentDocument.body.offsetHeight+FFextraHeight; 
        }
         else if(document.body)
        {
            h3=document.body.scrollHeight;
        }
        
        
        else if (pTar.Document && pTar.Document.body.scrollHeight)//如果用戶的瀏覽器是IE
        {
            //ie5+ syntax
            //alert(pTar.Document.body.scrollHeight)
            // pTar.height = pTar.Document.body.scrollHeight;
            h2=document.documentElement.scrollHeight;
            
           // pTar.height = screen.availHeight;
           // alert(pTar.height);
        }
       
        var h=Math.max(h1, h2);
        h=Math.max(h, h3);
        if(document.all) {h += 4;}
        if(window.opera) {h += 1;}
        pTar.height = h-132;
        //pTar.height = screen.availHeight-150;
        //alert(pTar.height);
    }
  		
  		
	};
