﻿function shiftAllOption( srcField, tarField ){

	for( var i=0; i<srcField.options.length; i++ ){
		
		srcField.options[i].selected = true;
	}//end of for( var i=0; i<srcField.options.length; i++ )
	
	var srcHt = getHashtableByOption( srcField );
	var tarHt = getHashtableByOption( tarField );
	
	hashtablePutAll( tarHt, srcHt );
	
	createOptionByHashtable( tarField, tarHt );
}//end of function shiftAllOption( srcField, tarField )

function removeAllOption( tarField ){
	
	var srcHt = new Hashtable();
	srcHt.put( "", "請選擇" );
	createOptionByHashtable( tarField, srcHt );
}//end of function removeAllOption( tarField )

function shiftSelectedOption( srcField, tarField ){
	
	var srcHt = getHashtableBySelectedOption( srcField );
	var tarHt = getHashtableByOption( tarField );
	
	hashtablePutAll( tarHt, srcHt );
	
	createOptionByHashtable( tarField, tarHt );
}//end of function shiftSelectedOption( srcField, tarField )

function removeSelectedOption( tarField ){

	var tarHt = getHashtableByUnSelectedOption( tarField );
	createOptionByHashtable( tarField, tarHt );
}//end of function removeSelectedOption( tarField )

function transValueToList( srcField, tarField ){
	var value="";
	try{
		for( var i=0; i<srcField.options.length; i++ ){
			if( srcField.options[i] ){
				if( value.length == 0 )
					value = srcField.options[i].value;
				else	
					value = value + ";" + srcField.options[i].value;	
			}//end of if( srcField.options[i].selected )
		}//end of for( var i=0; i<srcField.options.length; i++ )
		tarField.value = value;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function transValueToList( srcField, tarField )

function transTextToList( srcField, tarField ){
	var value="";
	try{
		for( var i=0; i<srcField.options.length; i++ ){
			if( srcField.options[i] ){
				if( value.length == 0 )
					value = srcField.options[i].text;
				else	
					value = value + ";" + srcField.options[i].text;	
			}//end of if( srcField.options[i].selected )
		}//end of for( var i=0; i<srcField.options.length; i++ )
		tarField.value = value;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function transValueToList( srcField, tarField )

function transOptionTextToTarget( srcField, tarField ){

	tarField.value = srcField.options[srcField.selectedIndex].text;
}//end of function transOptionTextToTarget( srcField, tarField )

function transOptionValueToTarget( srcField, tarField ){

	tarField.value = srcField.options[srcField.selectedIndex].value;
}//end of function transOptionValueToTarget( srcField, tarField )

function containsElement( anyArray, strElement ){
	//判斷陣列 anyArray 中是否有 strElement 這個元素
	try{
		for( var i in anyArray ){
			if( anyArray[i] == strElement )
				return true;
		}//end of for( var i in res )

		return false;

	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function containsElement( anyArray, strElement )

function removeElement( anyArray, strElement ){
	//移除陣列 anyArray 中 strElement 這個元素
	try{
		var tmpArray = new Array();
		for( var i in anyArray ){
			if( anyArray[i] != strElement )
				tmpArray[ anyArray[i] ] = anyArray[i];
		}//end of for( var i in res )	
    	
		return tmpArray;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch					
}//end of function removeElement( anyArray, strElement )

function exclusiveArray( arrayA, arrayB ){
	//陣列 arrayB 的元素不可與陣列 arrayA 的元素重複, 若有則移除 arrayB 中的元素
	try{
		for( var i in arrayA ){
			if( containsElement( arrayB, arrayA[i] ) )
				arrayB = removeElement( arrayB, arrayA[i] );
		}//end of for( var i in res )		
    	
		return arrayB;		
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch	
}//end of function exclusiveArray( arrayA, arrayB )

function getCheckedRadioButton( radioObj ){

	var specObj = null;
	
	if( !radioObj )
		return specObj;
		
	var radioLength = radioObj.length;
	if( radioLength == undefined ){
		
		if( radioObj.checked )
			specObj = radioObj;
	}//end of if( radioLength == undefined )	
			
	for( var i = 0; i < radioLength; i++ ){
		
		if( radioObj[i].checked ){
			
			specObj = radioObj[i];
			break;
		}//end of if( radioObj[i].checked )
	}//end of for( var i = 0; i < radioLength; i++ )
	
	return specObj;		
	
}//end of function getCheckedRadioButton( radioObj )

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue( radioObj ){
	
	if( !radioObj )
		return "";
		
	var radioLength = radioObj.length;
	if( radioLength == undefined ){
		
		if( radioObj.checked )
			return radioObj.value;
		else
			return "";
	}//end of if( radioLength == undefined )	
			
	for( var i = 0; i < radioLength; i++ ){
		
		if( radioObj[i].checked ){
			
			return radioObj[i].value;
		}//end of if( radioObj[i].checked )
	}//end of for( var i = 0; i < radioLength; i++ )
	return "";
}//end of function getCheckedValue( radioObj )

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue( radioObj, newValue ){
	
	if(!radioObj)
		return;
	
	var radioLength = radioObj.length;
	if( radioLength == undefined ){
		
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}//end of if( radioLength == undefined )
	
	for( var i = 0; i < radioLength; i++ ){
		
		radioObj[i].checked = false;
		if( radioObj[i].value == newValue.toString() ){
			radioObj[i].checked = true;
		}//end of if( radioObj[i].value == newValue.toString() )
	}//end of for( var i = 0; i < radioLength; i++ )
}//end of function setCheckedValue( radioObj, newValue )

function getCheckedList( checkObj, delimiter ){
	
	if( checkObj == null )
		return;

	var tmpList = "";
	if( typeof( checkObj.length ) != "undefined" ){
	
		for( var i=0; i<checkObj.length; i++ ){
	
			if( checkObj[i].checked )
				tmpList = ( tmpList.length == 0 )? checkObj[i].value:tmpList + delimiter + checkObj[i].value;
			
		}//end of for( var i=0; i<checkObj.length; i++ )
	} else {
		
		if( checkObj.checked )
			tmpList = checkObj.value;
	}//end of if( typeof( checkObj.length ) != "undefined" )
	
	return tmpList;
}//end of function getCheckedList( checkObj, delimiter )

function setCheckedList( checkObj, strList, delimiter ){
	
	if( checkObj == null )
		return;

	if( strList == null || strList.length == 0 )
		return;
	
	var tmpArray = strList.split( delimiter );
	var tmpVt = new Vector();
	for( var i=0; i<tmpArray.length; i++ )
		tmpVt.add( tmpArray[i] );
			
	if( typeof( checkObj.length ) != "undefined" ){
	
		for( var i=0; i<checkObj.length; i++ ){
	
			if( tmpVt.contains( checkObj[i].value ) )
				checkObj[i].checked = true;
		}//end of for( var i=0; i<checkObj.length; i++ )
	} else {
		
		if( tmpVt.contains( checkObj.value ) )
			checkObj.checked = true;
	}//end of if( typeof( checkObj.length ) != "undefined" )
}//end of function setCheckedList( checkObj, strList, delimiter )

function getCheckBoxFields( checkObj ){

	var tmpArray = new Array();
	
	if( checkObj == null )
		return tmpArray;
	
	if( typeof( checkObj.length ) != "undefined" ){
	
		for( var i=0; i<checkObj.length; i++ ){
	
			tmpArray[i] = checkObj[i];
		}//end of for( var i=0; i<checkObj.length; i++ )
	} else {

		tmpArray[0] = checkObj;
	}//end of if( typeof( checkObj.length ) != "undefined" )	
	
	return tmpArray;
}//end of function getCheckBoxFields( checkObj )
	
function setCheckedAll( tmpObj ){
	
	if( tmpObj == null )
		return;
	
	if( typeof( tmpObj.length ) != "undefined" ){
	
		for( var i=0; i<tmpObj.length; i++ ){
			if( !tmpObj[i].disabled )
				tmpObj[i].checked = true;
		}//end of for( var i=0; i<tmpObj.length; i++ )
	} else {
		if( !tmpObj.disabled )
			tmpObj.checked = true;
	}//end of if( typeof( tmpObj.length ) != "undefined" )
}//end of function setCheckedAll( tmpObj )

function setUnCheckedAll( tmpObj ){
	
	if( tmpObj == null )
		return;	
	
	if( typeof( tmpObj.length ) != "undefined" ){
	
		for( var i=0; i<tmpObj.length; i++ )
			tmpObj[i].checked = false;
	} else {
	
		tmpObj.checked = false;
	}//end of if( typeof( tmpObj.length ) != "undefined" )
}//end of function setUnCheckedAll( tmpObj )

function setSelectedValue( obj, value, isIgnoreCase ){
	
	for( var i=0; i<obj.options.length; i++ ){
		
		var srcValue = value;
		var tarValue = obj.options[i].value;
		
		if( isIgnoreCase ){
		
			srcValue = srcValue.toLowerCase();
			tarValue = tarValue.toLowerCase();
		}//end of if( isIgnoreCase )
			
		if( srcValue == tarValue ){
				
			obj.options[i].selected = true;
		}//end of if( prev_DistCenterID == DistCenterID_Fd.options[i].value )
	}//end of for( var i=0; i<obj.options.length; i++ )	
}//end of function setSelectedValue( obj, value, isIgnoreCase )

function alertSize(){
  	var myWidth = 0, myHeight = 0;
	try{              
  		if( typeof( window.innerWidth ) == 'number' ) {
  		  	//Non-IE
  		  	myWidth = window.innerWidth;
  		  	myHeight = window.innerHeight;
  		} else if( document.documentElement &&
  		    ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  		  	//IE 6+ in 'standards compliant mode'
  		  	myWidth = document.documentElement.clientWidth;
  		  	myHeight = document.documentElement.clientHeight;
  		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  		  	//IE 4 compatible
  		  	myWidth = document.body.clientWidth;
  		  	myHeight = document.body.clientHeight;
  		}
  		window.alert( 'Width = ' + myWidth );
  		window.alert( 'Height = ' + myHeight );

	} catch(err) {                                            
		                                                      
		alert("Exception caught, executing the catch block"); 
		alert("Error name: " + err.name);                     
		alert("Error message: " + err.message);               
	} finally {                                               
		                                                      
		//alert("Executing finally block");                   
	}//end of try-catch	                                        	
}//end of function alertSize()

function getWindowInnerWidth(){

  	var myWidth = 0;
	try{              
  		if( typeof( window.innerWidth ) == 'number' ){
  		  	//Non-IE
  		  	myWidth = window.innerWidth;
  		} else if( document.documentElement && document.documentElement.clientWidth ){
  		  	//IE 6+ in 'standards compliant mode'
  		  	myWidth = document.documentElement.clientWidth;
  		} else if( document.body && document.body.clientWidth ){
  		  	//IE 4 compatible
  		  	myWidth = document.body.clientWidth;
  		}//end of if( typeof( window.innerWidth ) == 'number' )
		return myWidth;	
	} catch(err) {                                            
		                                                      
		alert("Exception caught, executing the catch block"); 
		alert("Error name: " + err.name);                     
		alert("Error message: " + err.message);               
	} finally {                                               
		                                                      
		//alert("Executing finally block");                   
	}//end of try-catch	                                        	
}//end of function getWindowInnerWidth()

function getWindowInnerHeight(){

  	var myHeight = 0;
	try{              
  		if( typeof( window.innerHeight ) == 'number' ){
  		  	//Non-IE
  		  	myHeight = window.innerHeight;
  		} else if( document.documentElement && document.documentElement.clientHeight ){
  		  	//IE 6+ in 'standards compliant mode'
  		  	myHeight = document.documentElement.clientHeight;
  		} else if( document.body && document.body.clientHeight ){
  		  	//IE 4 compatible
  		  	myHeight = document.body.clientHeight;
  		}//end of if( typeof( window.innerHeight ) == 'number' )
		return myHeight;	
	} catch(err) {                                            
		                                                      
		alert("Exception caught, executing the catch block"); 
		alert("Error name: " + err.name);                     
		alert("Error message: " + err.message);               
	} finally {                                               
		                                                      
		//alert("Executing finally block");                   
	}//end of try-catch	                                        	
}//end of function getWindowInnerHeight()

function optionSelFieldAdd( srcField, tarField ){

	try {	

		for( var i=0; i<srcField.options.length; i++ ){
			
			if( srcField.options[i].selected ){
			
				var srcFdValue = srcField.options[i].value;
				var srcFdText = srcField.options[i].text;
				var hasFind = false;
				for( var j=0; j<tarField.options.length; j++ ){
					
					if( tarField.options[j].value == srcFdValue ){
						hasFind = true;
						break;
					}//end of if( tarField.options[j].value == srcFdValue )		
				}//end of for( var j=0; j<tarField.options.length; j++ )
				
				if( !hasFind ){
					tarField.options.add( new Option( srcFdText, srcFdValue ));
				}//end of if( !hasFind )
			}//end of if( srcField.options[i].selected )			
		}//end of for( var i=0; i<srcField.options.length; i++ )
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function optionSelFieldAdd( srcField, tarField )

function optionSelFieldDel( tarField ){

	try {	

		for( var i=tarField.options.length-1; i>=0; i-- ){

			if( tarField.options[i].selected )
				tarField.options.remove(i);
				
		}//end of for( var i=tarField.options.length-1; i>=0; i-- ){
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function optionSelFieldDel( tarField )

function winPrinting( isPrint ){
	//呼叫子視窗列印
	if( isPrint ){
		//pagesetup_null();
		self.print();
		var timerID=0;
		//var dt = new Date();
		self.status = (new Date()).getTime();
		timerID=setInterval('myWinFunc()',1000);
	}//end of if( isPrint )
}//end of function printing()

function myWinFunc(){
	//呼叫子視窗列印所用的計時器	
	var baseDt = new Date(); 
	baseDt.setTime( self.status );
	baseDt = dateAdd( "S", 10, baseDt );	//把基準時間往後延 10 秒
	
	//比對目前時間是否超過延後 10 秒的基準時間
	var dt = new Date();
	if( dt.getTime() >= baseDt.getTime() ){
		//window.close();
		self.status = "";
		self.close();
	}//end of if( self.status >= 50 )
}//end of myWinFunc()

function dateAdd(intval, numb, base){
	/* 日期時間的加算 */
	/*intval is YYYY, M, D, H, N, S, mS as in VBscript; numb is amount +/-; base is javascript date object*/
	switch(intval){
		case "M":
			base.setMonth(base.getMonth() + numb);
			break;
		case "YYYY":
			base.setFullYear(base.getFullYear() + numb);
			break;
		case "D":
			base.setDate(base.getDate() + numb);
			break;
		case "H":
			base.setHours(base.getHours() + numb);
			break;
		case "N":
			base.setMinutes(base.getMinutes() + numb);
			break;
		case "S":
			base.setSeconds(base.getSeconds() + numb);
			break;
		case "mS":
			base.setMillseconds(base.getMillseconds() + numb);
			break;
		default:
	}//end of switch(intval)
	return base;
}//end of function dateAdd(intval, numb, base)

function indexOf( message, charCode, pos ){
	
	var result = -1;
	if( message != null && message.length > 0 ){
		for( var i=pos; i<message.length; i++ ){
			if( message.charCodeAt(i) == charCode ){
				result = i;	
				break;
			}//end of if( message.charCodeAt(i) == charCode )
		}//end of for( var i=0; i<message.length; i++ )
	}//end of if( message != null && message.length > 0 )
	return result;
}//end of function indexOf( message, charCode, pos )

function getTextArea( message ){
	
	var show = null;
	if( message != null && message.length != 0 ){
		show = "";
		
		var pos = 0;
		
		while( true ){
			
			//表示 0x0D 的位置
			var idx = indexOf( message, 13, pos);
			
			//如果沒有換行，直接離開 while loop
			if( idx == -1 )
				break;
				
			/* 若有換行, 把換行之前的字串, 放到新的 message 字串上,	
				做完再加上 HTML 格式的換行 tag, <BR>
			*/
			if( idx > pos )
				show += message.substring( pos, idx );
				
			show += "<BR>";
			pos = idx + 1;
		}//end of while(true)

		if( pos >= 0 )
			show += message.substring( pos, message.length );
			 			
	} else {
		
		show = message;			
	}//end of if( message != null && message.length() != 0 )		

	return show;	
	
}//end of function getTextArea( message )

/*  Function Equivalent to java.net.URLEncoder.encode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0	*/
function encodeURL(str){

    var s0, i, s, u;
    s0 = "";                // encoded str

    for (i = 0; i < str.length; i++){   // scan the source

        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){

        	s0 += "+";	// SP should be converted to "+"
        } else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape

                s0 = s0 + s;            // don't escape
            } else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format

                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                } else if (u > 0x1fffff){     // quaternary byte format (extended)

                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                } else if (u > 0x7ff){        // triple byte format

                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                } else {                      // double byte format

                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }//end of if ((u >= 0x0) && (u <= 0x7f))
            }//end of if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a)))
        }//end of if (s == " ")
    }//end of for (i = 0; i < str.length; i++)
	alert( "s0 = " + s0 );
    return s0;
}//end of function encodeURL(str)

/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0	*/
function decodeURL(str){

    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str

    for (i = 0; i < str.length; i++){   // scan the source str

        s = str.charAt(i);
        if (s == "+"){
        	
        	s0 += " ";	// "+" should be changed to SP
        } else {

            if (s != "%"){
            	
            	s0 += s;	// add an unescaped char
            } else {               // escape sequence decoding
                
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while(true){

                    ss = "";        // local str to parse as int
                    for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                
                        sss = str.charAt(++i);
                        if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {

                            ss += sss;      // if hex, add the hex character
                        } else {
                        	--i; 
                        	break;
                        }    // not a hex char., exit the loop
                    }//end of for (j = 0; j < 2; j++ )

                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ 
                    	i++;	// test for the next shift byte
                    } else {
                    	break;	// abnormal, format error
                    }//end of if (str.charAt(i + 1) == "%")                    

                }//end of while(true)

            	s0 += String.fromCharCode(u);           // add the escaped character
            }//end of if (s != "%")
        }//end of if (s == "+")
    }//end of for (i = 0; i < str.length; i++)

    return s0;
}//end of function decodeURL(str)

function currencyToNumeric(s){
	//千分位貨幣轉為數值
	try{
		while( s.indexOf( "," )>= 0 ){
			var idx = s.indexOf( "," );
			
			if( idx == 0 ){
			
				s = s.substring(1,s.length);
			} else {
			
				s = s.substring(0,idx) + s.substring(idx+1,s.length);
			}//end of if( idx == 0 )

		}//end of while( s.indexOf( " " )>= 0 )
		return s;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch	

}//end of function currencyToNumeric(s)

//          of using arrays when the total quantity
//          is unknown
//////////////////////////////////////////////////////

// Vector Constructor -- constructs the object
function Vector(inc) {
	if ( inc == null || inc == 0) {
		inc = 100;
	}
	
	/* Properties */
	this.data = new Array(inc);
	this.increment = inc;
	this.size = 0;
	
	/* Methods */
	this.getCapacity = vector_getCapacity;
	this.getSize = vector_getSize;
	this.isEmpty = vector_isEmpty;
	this.getLastElement = vector_getLastElement;
	this.getFirstElement = vector_getFirstElement;
	this.getElementAt = vector_getElementAt;
	this.get = vector_get;
	this.addElement = vector_addElement;
	this.add = vector_add;
	this.addVector = vector_addVector;
	this.insertElementAt = vector_insertElementAt;
	this.removeElementAt = vector_removeElementAt;
    this.remove = vector_remove;
	this.removeAllElements = vector_removeAllElements;
    this.removeAll = vector_removeAll;
    this.removeObj = vector_removeObj;
	this.indexOf = vector_indexOf;
	this.contains = vector_contains
	this.resize = vector_resize;
	this.toString = vector_toString;
	this.sort = vector_sort;
	this.trimToSize = vector_trimToSize;
	this.clone = vector_clone;
	this.overwriteElementAt = vector_overwriteElementAt;
}

// getCapacity() -- returns the number of elements the vector can hold
function vector_getCapacity() {
	return this.data.length;
}

// getSize() -- returns the current size of the vector
function vector_getSize() {
	return this.size;
}

// isEmpty() -- checks to see if the Vector has any elements
function vector_isEmpty() {
	return this.getSize() == 0;
}

// getLastElement() -- returns the last element
function vector_getLastElement() {
	if (this.data[this.getSize() - 1] != null) {
		return this.data[this.getSize() - 1];
	}
}

// getFirstElement() -- returns the first element
function vector_getFirstElement() {
	if (this.data[0] != null) {
		return this.data[0];
	}
}

// getElementAt() -- returns an element at a specified index
function vector_getElementAt(i) {
	try {
		return this.data[i];
	} 
	catch (e) {
		return "Exception " + e + " occured when accessing " + i;	
	}	
}

function vector_get( i ){
	
	return this.getElementAt(i);
}//end of function get( i )

// addElement() -- adds a element at the end of the Vector
function vector_addElement(obj) {
	
	
	if(this.getSize() == this.data.length) {
		this.resize();
	}
	this.data[this.size++] = obj;
}

// add() -- adds a element at the end of the Vector
function vector_add(obj) {
	this.addElement(obj);
}

function vector_addVector( objVt ){
	
	for( var i=0; objVt != null && i<objVt.getSize(); i++ ){
		this.addElement( objVt.get(i) );		
	}//end of for( var i=0; objVt != null && i<objVt.getSize(); i++ )
}//end of function vector_addVector( objVt )

// insertElementAt() -- inserts an element at a given position
function vector_insertElementAt(obj, index) {
	try {
		if (this.size == this.capacity) {
			this.resize();
		}
		
		for (var i=this.getSize(); i > index; i--) {
			this.data[i] = this.data[i-1];
		}
		this.data[index] = obj;
		this.size++;
	}
	catch (e) {
		return "Invalid index " + i;
	}
}

// removeElementAt() -- removes an element at a specific index
function vector_removeElementAt(index) {
	try {
		var element = this.data[index];
		
		for(var i=index; i<(this.getSize()-1); i++) {
			this.data[i] = this.data[i+1];
		}
		
		this.data[getSize()-1] = null;
		this.size--;
		return element;
	}
	catch(e) {
		return "Invalid index " + index;
	}
} 

function vector_remove( index ){

	this.removeElementAt( index );
}

// removeAllElements() -- removes all elements in the Vector
function vector_removeAllElements() {
	this.size = 0;
	
	for (var i=0; i<this.data.length; i++) {
		this.data[i] = null;
	}
}

function vector_removeAll(){

	this. removeAllElements();
}

function vector_removeObj( obj ){
	for (var i=0; i<this.getSize(); i++) {
		if (this.data[i] == obj) {	
			this.data[i] = null;	
		}//end of if (this.data[i] == obj) 
	}//end of for (var i=0; i<this.getSize(); i++)
	
	var tmpArray = new Array();
	var count = 0;
	for( var i=0; i<this.data.length; i++ ){
		if( this.data[i] != null ){
			tmpArray[ count ] = this.data[i];
			count = count + 1;
		}//end of if( this.data[i] != null )
	}//end of for( var i=0; i<this.data.length; i++ )
	
	this.data = new Array();
	var cnt = 0;
	for( var i=0; i<tmpArray.length; i++ ){
		
		this.data[cnt] = tmpArray[i];
		cnt = cnt + 1;
	}//end of for( var i=0; i<tmpArray.length; i++ )
	
	this.size = this.data.length;
}//end of function vector_removeObj( obj )

// indexOf() -- returns the index of a searched element
function vector_indexOf(obj) {
	for (var i=0; i<this.getSize(); i++) {
		if (this.data[i] == obj) {
			return i;
		}
	}
	return -1;
}

// contains() -- returns true if the element is in the Vector, otherwise false
function vector_contains(obj) {
	for (var i=0; i<this.getSize(); i++) {
		if (this.data[i] == obj) {
			return true;
		}
	}
	return false;
}

// resize() -- increases the size of the Vector
function vector_resize() {
	newData = new Array(this.data.length + this.increment);
	
	for	(var i=0; i< this.data.length; i++) {
		newData[i] = this.data[i];
	}
	
	this.data = newData;
}


// trimToSize() -- trims the vector down to it's size
function vector_trimToSize() {
	var temp = new Array(this.getSize());
	
	for (var i = 0; i < this.getSize(); i++) {
		temp[i] = this.data[i];
	}
	this.size = temp.length - 1;
	this.data = temp;
} 

// sort() - sorts the collection based on a field name - f
function vector_sort(f) {
	var i, j;
	var currentValue;
	var currentObj;
	var compareObj;
	var compareValue;
	
	for(i=1; i<this.getSize();i++) {
		currentObj = this.data[i];
		currentValue = currentObj[f];
		
		j= i-1;
		compareObj = this.data[j];
		compareValue = compareObj[f];
		
		while(j >=0 && compareValue > currentValue) {
			this.data[j+1] = this.data[j];
			j--;
			if (j >=0) {
				compareObj = this.data[j];
				compareValue = compareObj[f];
			}				
		}	
		this.data[j+1] = currentObj;
	}
}

// clone() -- copies the contents of a Vector to another Vector returning the new Vector.
function vector_clone() {
	var newVector = new Vector(this.size);
	
	for (var i=0; i<this.size; i++) {
		newVector.addElement(this.data[i]);
	}
	
	return newVector;
}

// toString() -- returns a string rep. of the Vector
function vector_toString() {
	var str = "Vector Object properties:\n" +
	          "Increment: " + this.increment + "\n" +
	          "Size: " + this.size + "\n" +
	          "Elements:\n";
	
	for (var i=0; i<getSize(); i++) {
		for (var prop in this.data[i]) {
			var obj = this.data[i];
			str += "\tObject." + prop + " = " + obj[prop] + "\n";
		}
	}
	return str;	
}

// overwriteElementAt() - overwrites the element with an object at the specific index.
function vector_overwriteElementAt(obj, index){
	this.data[index] = obj;
}

function ArrayToVector( tmpArray ){

	var tmpVt = new Vector();
	
	for( var i=0; i<tmpArray.length; i++ )
		tmpVt.add( tmpArray[i] );
	
	return tmpVt;	
}//end of function ArrayToVector( tmpArray )

//////////////////////////////////////////////////////
// File: Matrix.js
//
// Author: Jason Geissler
// 
// Date: March 9, 2004
//
// Purpose: To have a multidimensional dynamic collection instead
//          of using arrays when the total quantity
//          is unknown
//////////////////////////////////////////////////////

// Matrix() - object constructor
function Matrix(h, w) {
	/*Properties */
  	this.height = h;
	this.width = w;
	this.rows = new Vector(w);
	
	// set up this.rows. 
	for (var r = 0; r < this.height; r++) {
		var theRow = new Vector(w);

		for (var c = 0; c < this.width; c++) {
		  theRow.addElement(null);
		}
		this.rows.addElement(theRow);
	}
	
	/*Methods*/
	this.elementAt = matrix_elementAt;
	this.setElementAt = matrix_setElementAt;
	this.insertRow = matrix_insertRow;
	this.insertColumn = matrix_insertColumn;
	this.removeRowAt = matrix_removeRowAt;
	this.removeColumnAt = matrix_removeColumnAt;
	this.getWidth = matrix_getWidth;
	this.getHeight = matrix_getHeight;
	this.toString = matrix_toString;
}

// getElementAt() - returns a value from the given row/column.
function matrix_elementAt(row, col) {
	try {
		var theRow = this.rows.getElementAt(row);
		return theRow.getElementAt(col);
	}
	catch(e) {
		return "Invalid index";
	}
}

// setElementAt() - sets a value at a given row/column
function matrix_setElementAt(value, row, col) {
	if (row < 0 || row >= this.height || col < 0 || col >= this.width) {
		return "Matrix object out of Bounds";
	}
	var theRow = this.rows.getElementAt(row);
	theRow.insertElementAt(value, col);
}

// insertRowAt() - Inserts a blank row at the end.
function matrix_insertRow() {
	try {
		this.height++;
		var theRow = new Vector(this.width);
		for (var r = 0; r < this.width; r++) {
			theRow.addElement(null);
		}
		this.rows.insertElementAt(theRow, this.height-1);
	}
	catch (e) {
		return "Excecption occured " + e;
	}
}

// insertColumnAt() -- Inserts a column at the end.
function matrix_insertColumn() {
	try {
		this.width++;
		
		for (var c=0; c < this.height; c++) {
			this.rows.getElementAt(c).insertElementAt(null, this.width-1);
		}		
	}
	catch (e) {
		return "Invalid column number";
	}
}

// removeRowAt() - removes a row at a given index.
function matrix_removeRowAt(row) {
	try {
		var result = this.rows.getElementAt(row);
		this.height--;
		
		for (var r=row + 1; r <= this.height; r++) {
			var theRow = this.rows.getElementAt(r);
			this.rows.insertElementAt(theRow, r-1);
			this.rows.removeElementAt(r);
		}

		return result;
	}
	catch (e) {
		return "Invalid row number";
	}
}

// removeColumnAt() - removes a given column
function matrix_removeColumnAt(col) {
	try {
		var result = new Vector(this.height);
		this.width--;
		
		for(var r = 0; r < this.height; r++) {
			var element = this.rows.getElementAt(r).removeElementAt(col);
			result.addElement(element);
		}
			
		return result;
	}
	catch (e) {
		return "Invalid column number";
	}
}

// getWidth() - returns the Matrix width
function matrix_getWidth() {
	return this.width;
}

// getHeight() - returns the Matrix height
function matrix_getHeight() {
	return this.height;
}

// toString() - returns String data about the Matrix object
function matrix_toString() {
	var s = "Height: " + this.height + " Width: " + this.width + " Rows: " + this.rows;
	return s;
}



/* Hashtable */

function Hashtable(){
    this.clear = hashtable_clear;
    this.containsKey = hashtable_containsKey;
    this.containsValue = hashtable_containsValue;
    this.get = hashtable_get;
    this.containsKeyArray = hashtable_containsKeyArray;
    this.getByKeyArray = hashtable_getByKeyArray;
    this.isEmpty = hashtable_isEmpty;
    this.keys = hashtable_keys;
    this.put = hashtable_put;
    this.remove = hashtable_remove;
    this.size = hashtable_size;
    this.toString = hashtable_toString;
    this.values = hashtable_values;
    this.hashtable = new Array();
    this.clone = hashtable_clone;
}

/*=======Private methods for internal use only========*/

function hashtable_clear(){
    this.hashtable = new Array();
}

function hashtable_containsKey(key){
    var exists = false;
    for (var i in this.hashtable) {
        if (i == key && this.hashtable[i] != null) {
            exists = true;
            break;
        }
    }
    return exists;
}

function hashtable_containsValue(value){
    var contains = false;
    if (value != null) {
        for (var i in this.hashtable) {
            if (this.hashtable[i] == value) {
                contains = true;
                break;
            }
        }
    }
    return contains;
}

function hashtable_get(key){
   var value = null;	    
   for( var i in this.hashtable ){
      
      if( key == i ){
         value = this.hashtable[key];
         return value;
      }
   }//end of for( var i in this.hashtable )
   return value;
}//end of function hashtable_get(key)

function hashtable_containsKeyArray( keyArray ){
	if( !isArray( keyArray ) )	
		throw "keyArray is not an Array object	!!";	
	
	var keyArrays = this.keys();	
	var isSame = false;
	try {		
		for( var i=0; i<keyArrays.length; i++ ){
			
			var tmpKeyArray = keyArrays[i].split("," );
			if( tmpKeyArray.length == keyArray.length ){
				
				isSame = false;
				for( var j=0; j<tmpKeyArray.length; j++ ){
					
					if( tmpKeyArray[j] == keyArray[j] ){
						
						isSame = true;
					} else {
							
						isSame = false;
						break;
					}//end of if( tmpKeyArray[j] == keyArray[j] )
				}//end of for( var j=0; j<tmpKeyArray.length; j++ )
				if( isSame )
					return isSame;
			}//end of if( keyArrays[i].length == keyArray.length )
		}//end of for( var i=0; i<keyArrays.length; i++ )	
		
		return isSame;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//document.close();
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function hashtable_containsKeyArray( keyArray )

function hashtable_getByKeyArray( keyArray ){
	//alert( "enter into getByKeyArray()" );
	
	if( !isArray( keyArray ) )	
		throw "keyArray is not an Array object	!!";
	
	var keyArrays = this.keys();
	
	try {		
		for( var i=0; i<keyArrays.length; i++ ){
			
			var tmpKeyArray = keyArrays[i].split("," );
			if( tmpKeyArray.length == keyArray.length ){
				
				var isSame = false;
				for( var j=0; j<tmpKeyArray.length; j++ ){
					
					if( tmpKeyArray[j] == keyArray[j] ){
						
						isSame = true;
					} else {	
						
						isSame = false;
						break;
					}//end of if( tmpKeyArray[j] == keyArray[j] )
				}//end of for( var j=0; j<tmpKeyArray.length; j++ )
				
				if( isSame == true ){
				
					return this.get( tmpKeyArray );
				}//end of if( isSame == true )
			}//end of if( keyArrays[i].length == keyArray.length )
		}//end of for( var i=0; i<keyArrays.length; i++ )	
		
		return null;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//document.close();
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function hashtable_getByKeyArray( keyArray )

function hashtable_isEmpty(){
    return (parseInt(this.size()) == 0) ? true : false;
}

function hashtable_keys(){
    var keys = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            keys.push(i);
    }
    return keys;
}

function hashtable_put(key, value){
	
    if (key == null || value == null) {
        throw "NullPointerException {" + key + "},{" + value + "}";
    }else{
        this.hashtable[key] = value;
    }
}

function hashtable_remove(key){

   for( var i in this.hashtable ){
      
      if( key == i ){
         this.hashtable[key] = null;
      }
   }//end of for( var i in this.hashtable )
}//end of function hashtable_remove(key)

function hashtable_size(){
    var size = 0;
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            size ++;
    }
    return size;
}

function hashtable_toString(){
    var result = "";
    for (var i in this.hashtable)
    {      
        if (this.hashtable[i] != null) 
            result += "{" + i + "},{" + this.hashtable[i] + "}\n";   
    }
    return result;
}

function hashtable_values(){
    var values = new Array();
    for (var i in this.hashtable) {
        if (this.hashtable[i] != null) 
            values.push(this.hashtable[i]);
    }
    return values;
}

function hashtable_clone(){
	
	var keyArrays = this.keys();
	var tmpHt = new Hashtable();
	
	for( var i=0; i<keyArrays.length; i++ ){
		
		tmpHt.put( keyArrays[i], this.get( keyArrays[i] ) );
	}//end of for( var i=0; i<keyArrays.length; i++ )
	return tmpHt;
}//end of function hashtable_clone()
//end of Hashtable Class

function hashtablePutAll( tarHt, srcHt ){
	
	if( srcHt != null ){
		var srcHt_KeyArray = srcHt.keys();
		for( var i=0; i<srcHt_KeyArray.length; i++ ) 
			tarHt.put( srcHt_KeyArray[i], srcHt.get( srcHt_KeyArray[i] ) );
	}//end of if( srcHt != null )	
}//end of function hashtablePutAll( srcHt, tarHt )

function checkEmail( formfield ){
	
	return isEmailValidate( formfield.value );
}//end of function checkEmail( formfield )

function isEmailValidate( email ){
	
	// test if valid email address, must have @ and .
	
	var checkEmail = "@.";
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	
	try {				
		
		for (i = 0;  i < email.length;  i++){
			ch = email.charAt(i);
		  	for (j = 0;  j < checkEmail.length;  j++){
		    	if (ch == checkEmail.charAt(j) && ch == "@")
		      		EmailAt = true;
		    	if (ch == checkEmail.charAt(j) && ch == ".")
		      		EmailPeriod = true;
		    	if (EmailAt && EmailPeriod)
		      		break;
		    	if (j == checkEmail.length)
		      		break;
		  	}//end of for (j = 0;  j < checkEmail.length;  j++)
			
			// if both the @ and . were in the string
		  	if (EmailAt && EmailPeriod){
				EmailValid = true;
				break;
		  	}//end of if (EmailAt && EmailPeriod)
		}//end of for (i = 0;  i < email.length;  i++)
		
		if( email.indexOf("..") != -1 )
		  	EmailValid = false;
		
		if( email.lastIndexOf(".") == email.length-1 )
		  	EmailValid = false;
		
		if( email.lastIndexOf(" ") != -1 )
		  	EmailValid = false;
		
		return EmailValid;
	} catch(err) {
		
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);
		alert("Error message: " + err.message);
	} finally {
		
		//alert("Executing finally block");
	}//end of try-catch		
}//end of function isEmailValidate( email )

function moneyFormat(str){   
	if(str.length<=3)   
		return str;   
    else    
    	return 	moneyFormat(str.substr(0,str.length-3))+","+(str.substr(str.length-3));   
}//end of function moneyFormat(str)   

function getCharCount( message, spcChar ){
	
	var count = 0;
	if( message != null && message.length != 0 ){
	
		var pos = 0;
		
		while( true ){
			
			//表示 spcChar 的位置
			var idx = message.indexOf( spcChar, pos);
			
			
			//如果沒有 spcChar，直接離開 while loop
			if( idx == -1 )
				break;
				
			/* 若有 spcChar ,則 count + 1	*/
			if( idx > pos )
				count = count + 1;
				
			pos = idx + 1;
		}//end of while(true)

	}//end of if( message != null && message.length != 0 )
	
	return count;
}//end of function getCharCount( message, spcChar )

function getLineCount( message ){
	
	var ASCII_CR = String.fromCharCode( 0x0D );
	var lineCount = 0;
	if( getCharCount( message, ASCII_CR ) > 0 ){
		lineCount = getCharCount( message, ASCII_CR ) + 1;
	} else {
		if( message.length > 0 )
			lineCount = 1;
	}//end of if( getCharCount( message, ASCII_CR ) > 0 )
		
	return lineCount;
}//end of function getLineCount( message )


function getByteLength( strIN ){   
	var cnt=0;   
	for (var i=0; i<strIN.length; i++){   
     	
     	if( escape( strIN.charAt(i) ).length >= 4 ) 
     		cnt+=2;   
     	else 
     		cnt++;
     		   
   	}//end of for (var i=0; i<strIN.length; i++)   
   	return cnt;   
}//end of function function getByteLength(strIN)


function checkByteCountOfEachLine( obj, byteLimit ){
	
	var message = obj.value;
	var ASCII_CR = String.fromCharCode( 0x0D );

	var alias = "";
	if( typeof( obj.alias ) != "undefined" )
		alias = obj.alias;
	else
		alias = "????";

	var count = 0;
	if( message != null && message.length != 0 ){
	
		var pos = 0;
		
		while( true ){
			
			//表示 spcChar 的位置
			var idx = message.indexOf( ASCII_CR, pos);
			
			//如果沒有 ASCII_CR，直接離開 while loop
			if( idx == -1 )
				break;
				
			// 若有 spcChar ,則 count + 1	
			if( idx > pos ){
				var tmp = message.substring( pos, idx );
				//alert( "getByteLength(" + tmp + ") = " + getByteLength( tmp ) );
				if( getByteLength( tmp ) > byteLimit ){
					
					alert( alias + "欄位的第" + eval(count + 1) + "行過長！" );
					obj.focus();
					return false;
				}//end of if( getByteLength( tmp ) > byteLimit )
				count = count + 1;
			}//end of if( idx > pos )	
			
			pos = idx + 1;
		}//end of while(true)

		if( count == 0 ){
			
			//alert( "getByteLength(" + message + ") = " + getByteLength( message ) );
			if( getByteLength( message ) > byteLimit ){
				
				alert( alias + "欄位的第" + eval(count + 1) + "行過長！" );
				obj.focus();
				return false;
			}//end of if( getByteLength( tmp ) > byteLimit )
		}//end of if( count == 0 )	
	
	}//end of if( message != null && message.length != 0 )	

	return true;

}//end of function checkByteCountOfEachLine( message, byteLimit )	  

function setCursorType( type ){
	document.body.style.cursor = type;	
}//end of function setCursorType( type )

//視窗縮放控制函數
function setWin(flag){
	if( flag=="all" ){ //以螢幕大小縮放範圍
		resizeTo(screen.availWidth,screen.availHeight);
		moveTo(0,0);
	} else { //預設大小
		resizeTo(930,720);
		moveTo(50,10);
	}//end of if( flag=="all" )
}//end of function setWin(flag)

function getDQuote(){

	var dQuote="\"";
	return dQuote;
}//end of function getDQuote()


function cutHeadZero( strVar ){
	
	if( strVar.indexOf( "0" ) == 0 ){
	
		strVar = strVar.substring( 1, strVar.length );
		strVar = cutHeadZero( strVar );
	}//end of if( strVar.indexOf( "0" ) = 0 )
	
	return strVar;
}//end of function cutHeadZero( strVar )

function createOptionWithNoDefaultByHashtable( sel, tmpHt ){

	try{
		clearOption(sel);
		if( tmpHt != null && tmpHt.size()>0 ){
	
			var keys = tmpHt.keys();
			keys.sort();
			for( var i=0; i<keys.length; i++ ){
				
				var value = keys[i];
				var text = tmpHt.get( value );
				sel.options[i] = new Option( text, value );
			}//end of for( var i=0; i<keys.length; i++ )
		}//end of if( tmpHt != null && tmpHt.size()>0 )
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch                                      
}//end of function createOptions()

function createOptionWithDefaultByHashtable( sel, tmpHt, strName ){

	try{
		
		clearOption(sel);
		sel.options[0] = new Option( strName, "" );
		if( tmpHt != null && tmpHt.size()>0 ){
	
			var keys = tmpHt.keys();
			//keys.sort();	
			for( var i=0; i<keys.length; i++ ){
				var k = i+1;
				var value = keys[i];
				var text = tmpHt.get( value );
				sel.options[k] = new Option( text, value );
			}//end of for( var i=0; i<keys.length; i++ )
		}//end of if( tmpHt != null && tmpHt.size()>0 )
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch                                      
}//end of function function createOptionWithDefaultByHashtable( sel, tmpHt, strName )

function createOptionByHashtable( sel, tmpHt ){

	try{
		
		clearOption(sel);
		if( tmpHt != null && tmpHt.size()>0 ){
	
			var keys = tmpHt.keys();
			//keys.sort();	
			for( var i=0; i<keys.length; i++ ){
				
				var value = keys[i];
				var text = tmpHt.get( value );
				sel.options[i] = new Option( text, value );
			}//end of for( var i=0; i<keys.length; i++ )
		} else {
			//alert( "tmpHt == null || tmpHt.size()==0" );
			sel.options[0] = new Option( "請選擇", "" );
		}//end of if( tmpHt != null && tmpHt.size()>0 )
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch                                      
}//end of function createOptions()

function createParentDocOptionWithNoDefaultByHashtable( sel, tmpHt ){
	try{
		clearOption(sel);
		if( tmpHt != null && tmpHt.size()>0 ){
	
			var keys = tmpHt.keys();
			keys.sort();
			for( var i=0; i<keys.length; i++ ){
				
				var value = keys[i];
				var text = tmpHt.get( value );
				var newOpt=window.opener.document.createElement("option");
   				newOpt.text= text;
    			newOpt.value= value;

				sel.options.add( newOpt );
			}//end of for( var i=0; i<keys.length; i++ )
		}//end of if( tmpHt != null && tmpHt.size()>0 )
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch          	
}//end of function createParentDocOptionWithNoDefaultByHashtable( sel, tmpHt )

function createParentDocOptionWithDefaultByHashtable( sel, tmpHt, strName ){
	try{
		
		clearOption(sel);
		sel.options[0] = new Option( strName, "" );
		if( tmpHt != null && tmpHt.size()>0 ){
	
			var keys = tmpHt.keys();
			//keys.sort();	
			for( var i=0; i<keys.length; i++ ){
				var k = i+1;
				var value = keys[i];
				var text = tmpHt.get( value );
				var newOpt=window.opener.document.createElement("option");
   				newOpt.text= text;
    			newOpt.value= value;

				sel.options.add( newOpt );			
			}//end of for( var i=0; i<keys.length; i++ )
		}//end of if( tmpHt != null && tmpHt.size()>0 )
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch 
	
}//end of function createParentDocOptionWithDefaultByHashtable( sel, tmpHt, strName )

function createParentDocOptionByHashtable( sel, tmpHt ){
	try{
		
		clearOption(sel);
		if( tmpHt != null && tmpHt.size()>0 ){
	
			var keys = tmpHt.keys();
			//keys.sort();	
			for( var i=0; i<keys.length; i++ ){
				
				var value = keys[i];
				var text = tmpHt.get( value );
				var newOpt=window.opener.document.createElement("option");
   				newOpt.text= text;
    			newOpt.value= value;

				sel.options.add( newOpt );
			}//end of for( var i=0; i<keys.length; i++ )
		} else {
			//alert( "tmpHt == null || tmpHt.size()==0" );
			var newOpt=window.opener.document.createElement("option");
			newOpt.text= "請選擇";
			newOpt.value= "";
			sel.options.add( newOpt );
		}//end of if( tmpHt != null && tmpHt.size()>0 )
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch       
}//end of function createParentDocOptionByHashtable( sel, tmpHt )

function clearOption( sel ){
	
	//for( var i=0; i<sel.options.length; i++ )
	//	sel.options[i] = null;
	sel.options.length = 0;
	
}//end of function clearOption( sel )

function getHashtableByOption( sel ){

	try{

		var tmpHt = null;
		for( var i=0; i<sel.options.length; i++ ){

			var tmpKey = sel.options[i].value;
			var tmpValue = sel.options[i].text;
			tmpHt = ( tmpHt != null )? tmpHt:new Hashtable();
			tmpHt.put( tmpKey, tmpValue );
		}//end of for( var i=0; i<sel.options.length; i++ )

		return tmpHt;
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch    
}//end of function getHashtableByOption()

function getHashtableBySelectedOption( sel ){

	try{
	
		var tmpHt = null;
		for( var i=0; i<sel.options.length; i++ ){
			
			if( sel.options[i].selected ){
				var tmpKey = sel.options[i].value;
				var tmpValue = sel.options[i].text;
				tmpHt = ( tmpHt != null )? tmpHt:new Hashtable();
				tmpHt.put( tmpKey, tmpValue );
			}//end of if( sel.options[i].selected )
		}//end of for( var i=0; i<sel.options.length; i++ )

		return tmpHt;
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch 		
}//end of function getHashtableBySelectedOption( sel )

function getHashtableByUnSelectedOption( sel ){

	try{
	
		var tmpHt = null;
		for( var i=0; i<sel.options.length; i++ ){
			
			if( !sel.options[i].selected ){
				var tmpKey = sel.options[i].value;
				var tmpValue = sel.options[i].text;
				tmpHt = ( tmpHt != null )? tmpHt:new Hashtable();
				tmpHt.put( tmpKey, tmpValue );
			}//end of if( sel.options[i].selected )
		}//end of for( var i=0; i<sel.options.length; i++ )

		return tmpHt;
	} catch(err) {                                           
		                                                     	
		alert("Exception caught, executing the catch block");
		alert("Error name: " + err.name);                    
		alert("Error message: " + err.message);              
	} finally {                                              
		                                                     
		//alert("Executing finally block");                  
	}//end of try-catch 

}//end of function getHashtableByUnSelectedOption( sel )	
	
function getZeroStringByLength( length ){

	var rtnValue = null;
	for( var i=0; i<length; i++ ){
	
		if( rtnValue == null )
			rtnValue = "0";
		else
			rtnValue = rtnValue + "0";
	}//end of for( var i=0; i<length; i++ )

	return rtnValue;
}//end of function getZeroStringByLength( length )

function absolutePath( url ){
	//相對路徑轉為絕對路徑
	
	var Loc = location.href;
	
	Loc = Loc.substring(0, Loc.lastIndexOf('/'));
	
	while( /^\.\./.test( url ) ){
				 
		Loc = Loc.substring(0, Loc.lastIndexOf('/'));
		url= url.substring(3);
	}//end of while (/^\.\./.test(url))
	return Loc + '/' + url;
}//end of function absolutePath( url )

function getObj(name){
	
  	if (document.getElementById){
  		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
  	} else if (document.all){
		this.obj = document.all[name];
		this.style = document.all[name].style;
  	} else if (document.layers){
   		this.obj = document.layers[name];
   		this.style = document.layers[name];
  	}//end of if (document.getElementById)
}//end of function getObj(name)

function removeLayerChild( obj ){
	
	while( obj.firstChild ) 
		obj.removeChild(obj.firstChild);
}//end of function removeLayerChild( obj )

function removeLayerChildById( id ){

	var obj = document.getElementById( id );
	while( obj.firstChild ) 
		obj.removeChild(obj.firstChild);
}//end of function removeLayerChildById( id )
	
function getEvent(){
	
 	if(document.all)    
 		return window.event;//如果是ie
 		
 	var func=getEvent.caller;
	while(func!=null){
		
		var arg0=func.arguments[0];
		if( arg0 ){
			if( (arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation) ){
				return arg0;
			}            
		}
		func=func.caller;
	}//end of while(func!=null)
	
	return null;
}//end of function getEvent()

function getEventKeyCode(){
	
	var event = getEvent();
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	return keyCode;
}//end of function getEventKeyCode()

function isRightMouseButtonClick(e){
	 
	//alert( "event.button = " + event.button ); 
	 
  	if (navigator.appName == 'Netscape' && e.which == 3) {
      	self.status = "right click please";
      	return true;
    } else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2){
		self.status = "right click please";
		return true;
    }//end of if (navigator.appName == 'Netscape' && e.which == 3)
    
   return false;
}//end of function isRightMouseButtonClick(e)

function addEvent(elm, evType, fn, useCapture){
	
  	if(elm.addEventListener) {   
  		elm.addEventListener(evType, fn, useCapture);   
  		return true;   
  	} else if(elm.attachEvent){   
  		var r = elm.attachEvent('on'+evType, fn);
  		return r;   
  	} else  {   
  		elm['on' + evType] = fn;   
  	}//end of if(elm.addEventListener)   
}//end of function addEvent(elm, evType, fn, useCapture)

function removeEvent(elm, evType, fn, useCapture){

	if( elm.removeEventListener ){
		elm.removeEventListener( evType, fn, useCapture );
		return true;
	} else if( elm.detachEvent ){
		var r = elm.detachEvent( 'on'+evType, fn );
		return r;
	} else {
		elm['on' + evType] = null; 
	}//end of if( elm.removeEventListener )v
}//end of function removeEvent(elm, evType, fn, useCapture) 

function createSel( id, tarId, selHt, initSelHt, tableProp, tableStyleProp, rowProp, rowStyleProp, columnProp, columnStyleProp, onSelColumnProp, onSelColumnStyleProp ){
	
	var myData = document.getElementById( id );
	var tarValue = document.getElementById( tarId ).value;
	
	var myTable = null;
	if( document.getElementById( id + "Table" ) != null ){
		myTable = document.getElementById( id + "Table" );
	} else {
		myTable = document.createElement( "table" );
		myTable.setAttribute( "id", id + "Table" );
	}//end of if( document.getElementById( id + "Table" ) != null )
	
	while (myTable.rows.length>0) 
		myTable.deleteRow(0);
		
	if( tableProp != null && tableProp.size()>0 ){
		
		var keys = tableProp.keys();
		for( var i=0; i<keys.length; i++ )
			myTable.setAttribute( keys[i], tableProp.get( keys[i] ) );
	}//end of if( tableProp != null && tableProp.size()>0 )	

	var tableStyle = "";
	if( tableStyleProp != null && tableStyleProp.size()>0 ){
		
		var keys = tableStyleProp.keys();
		for( var i=0; i<keys.length; i++ ){
			if( tableStyle.length==0 )
				tableStyle = keys[i] + ":" + tableStyleProp.get( keys[i] );
			else
				tableStyle = tableStyle + ";" + keys[i] + ":" + tableStyleProp.get( keys[i] ); 
				
			if( document.all )	
				myTable.style.setAttribute( keys[i], tableStyleProp.get( keys[i] ) );		
		}//end of for( var i=0; i<keys.length; i++ )
		if( !document.all )
			myTable.setAttribute( "style", tableStyle );
	}//end of if( tableStyleProp != null && tableStyleProp.size()>0 )
	
	var rowStyle = "";
	if( rowStyleProp != null && rowStyleProp.size()>0 ){
		
		var tmpKeys = rowStyleProp.keys();
		for( var i=0; i<tmpKeys.length; i++ ){
			if( rowStyle.length==0 )
				rowStyle = tmpKeys[i] + ":" + rowStyleProp.get( tmpKeys[i] );
			else
				rowStyle = rowStyle + ";" + tmpKeys[i] + ":" + rowStyleProp.get( tmpKeys[i] ); 
		}//end of for( var i=0; i<tmpKeys.length; i++ )
	}//end of if( rowStyleProp != null && rowStyleProp.size()>0 )	
	
	var columnStyle = "";
	if( columnStyleProp != null && columnStyleProp.size()>0 ){
		
		var tmpKeys = columnStyleProp.keys();
		for( var i=0; i<tmpKeys.length; i++ ){
			if( columnStyle.length==0 )
				columnStyle = tmpKeys[i] + ":" + columnStyleProp.get( tmpKeys[i] );
			else
				columnStyle = columnStyle + ";" + tmpKeys[i] + ":" + columnStyleProp.get( tmpKeys[i] ); 
		}//end of for( var i=0; i<tmpKeys.length; i++ )
	}//end of if( columnStyleProp != null && columnStyleProp.size()>0 )	
	
	var onSelColumnStyle = "";				
	if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 ){
		
		var tmpKeys = onSelColumnStyleProp.keys();
		for( var i=0; i<tmpKeys.length; i++ ){
			if( onSelColumnStyle.length==0 )
				onSelColumnStyle = tmpKeys[i] + ":" + onSelColumnStyleProp.get( tmpKeys[i] );
			else
				onSelColumnStyle = onSelColumnStyle + ";" + tmpKeys[i] + ":" + onSelColumnStyleProp.get( tmpKeys[i] ); 
		}//end of for( var i=0; i<tmpKeys.length; i++ )
	}//end of if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 )	
	//alert( "onSelColumnStyle = " + onSelColumnStyle );		
	
	if( initSelHt != null && initSelHt.size()>0 ){
		
		var keys = initSelHt.keys();
		for( var i=0; i<keys.length; i++ ){
			
			var tr = myTable.insertRow(-1);
			if( rowProp != null && rowProp.size()>0 ){
		
				var tmpKeys = rowProp.keys();
				for( var j=0; j<tmpKeys.length; j++ )
					tr.setAttribute( tmpKeys[j], rowProp.get( tmpKeys[j] ) );
			}//end of if( rowProp != null && rowProp.size()>0 )
			
			if( rowStyleProp != null && rowStyleProp.size()>0 ){
				if( !document.all ){
					
					tr.setAttribute( "style", rowStyle );
				} else {
					
					var tmpKeys = rowStyleProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )					
						tr.setAttribute(tmpKeys[j], rowStyleProp.get(tmpKeys[j]) );  					
				}//end of if( !document.all )
			}//end of if( rowStyleProp != null && rowStyleProp.size()>0 )			
			
			var td = tr.insertCell(-1);
			if( columnProp != null && columnProp.size()>0 ){
		
				var tmpKeys = columnProp.keys();
				for( var j=0; j<tmpKeys.length; j++ )
					td.setAttribute( tmpKeys[j], columnProp.get( tmpKeys[j] ) );
			}//end of if( columnProp != null && columnProp.size()>0 )
			
			if( columnStyleProp != null && columnStyleProp.size()>0 ){
				
				if( !document.all ){				
				
					td.setAttribute( "style", columnStyle );
				} else {
					
					var tmpKeys = columnStyleProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )					
						td.style.setAttribute( tmpKeys[j], columnStyleProp.get( tmpKeys[j] ) );
				}//end of if( !document.all )	
			}//end of if( columnStyleProp != null && columnStyleProp.size()>0 )
			
			if( tarValue==keys[i] ){
				
				if( onSelColumnProp != null && onSelColumnProp.size()>0 ){
		    	
					var tmpKeys = onSelColumnProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )
						td.setAttribute( tmpKeys[j], onSelColumnProp.get( tmpKeys[j] ) );
				}//end of if( onSelColumnProp != null && onSelColumnProp.size()>0 )
				
				if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 ){
					
					if( !document.all ){					
					
						td.setAttribute( "style", onSelColumnStyle );
					} else {
						
						var tmpKeys = onSelColumnStyleProp.keys();
						for( var j=0; j<tmpKeys.length; j++ )
							td.style.setAttribute( tmpKeys[j], onSelColumnStyleProp.get( tmpKeys[j] ) );
					}//end of if( !document.all )
				}//end of if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 )				
			}//end of if( tarValue==keys[i] )

			var link = document.createElement( "a" );
			link.setAttribute( "href", "#" );						
			link.setAttribute( "tmpValue", keys[i] );
			var currentText = document.createTextNode( initSelHt.get( keys[i] ) );
			link.appendChild( currentText );	
			/*	//此法亦可
			link.onclick = function(){
								document.getElementById( tarId ).value =  this.value;
							};
			*/			
			/*	
			link.attachEvent( "onclick", function(){
									var e = getEvent();
									document.getElementById( tarId ).value =  e.srcElement.value;
							});			
			*/
			addEvent( link, "click", function(){
									var e = getEvent();
									document.getElementById( tarId ).value =  e.srcElement.tmpValue;
							}, false);							
			
			td.appendChild( link );			
		}//end of for( var i=0; i<keys.length; i++ )
	}//end of if( initSelHt != null && initSelHt.size()>0 )
	
	if( selHt != null && selHt.size()>0 ){
		
		var keys = selHt.keys();
		for( var i=0; i<keys.length; i++ ){
			
			var tr = myTable.insertRow(-1);
			if( rowProp != null && rowProp.size()>0 ){
		
				var tmpKeys = rowProp.keys();
				for( var j=0; j<tmpKeys.length; j++ )
					tr.setAttribute( tmpKeys[j], rowProp.get( tmpKeys[j] ) );
			}//end of if( rowProp != null && rowProp.size()>0 )
			
			if( rowStyleProp != null && rowStyleProp.size()>0 ){
				if( !document.all ){
					
					tr.setAttribute( "style", rowStyle );
				} else {
					
					var tmpKeys = rowStyleProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )					
						tr.setAttribute(tmpKeys[j], rowStyleProp.get(tmpKeys[j]) );  					
				}//end of if( !document.all )
			}//end of if( rowStyleProp != null && rowStyleProp.size()>0 )			
			
			var td = tr.insertCell(-1);
			if( columnProp != null && columnProp.size()>0 ){
		
				var tmpKeys = columnProp.keys();
				for( var j=0; j<tmpKeys.length; j++ )
					td.setAttribute( tmpKeys[j], columnProp.get( tmpKeys[j] ) );
			}//end of if( columnProp != null && columnProp.size()>0 )
			
			if( columnStyleProp != null && columnStyleProp.size()>0 ){
				
				if( !document.all ){				
				
					td.setAttribute( "style", columnStyle );
				} else {
					
					var tmpKeys = columnStyleProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )					
						td.style.setAttribute( tmpKeys[j], columnStyleProp.get( tmpKeys[j] ) );
				}//end of if( !document.all )	
			}//end of if( columnStyleProp != null && columnStyleProp.size()>0 )			
			
			if( tarValue==keys[i] ){
				
				if( onSelColumnProp != null && onSelColumnProp.size()>0 ){
		    	
					var tmpKeys = onSelColumnProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )
						td.setAttribute( tmpKeys[j], onSelColumnProp.get( tmpKeys[j] ) );
				}//end of if( onSelColumnProp != null && onSelColumnProp.size()>0 )
				
				if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 ){
					
					if( !document.all ){					
					
						td.setAttribute( "style", onSelColumnStyle );
					} else {
						
						var tmpKeys = onSelColumnStyleProp.keys();
						for( var j=0; j<tmpKeys.length; j++ )
							td.style.setAttribute( tmpKeys[j], onSelColumnStyleProp.get( tmpKeys[j] ) );
					}//end of if( !document.all )
				}//end of if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 )				
			}//end of if( tarValue==keys[i] )			
			
			var link = document.createElement( "a" );
			link.setAttribute( "href", "#" );						
			link.setAttribute( "tmpValue", keys[i] );
			var currentText = document.createTextNode( selHt.get( keys[i] ) );
			link.appendChild( currentText );
			/*	//此法亦可
			link.onclick = function(){
								document.getElementById( tarId ).value =  this.value;
							};
			*/
			/*
			link.attachEvent( "onclick", function(){
									var e = getEvent();
									document.getElementById( tarId ).value =  e.srcElement.value;
							});
			*/
			addEvent( link, "click", function(){
									var e = getEvent();
									document.getElementById( tarId ).value =  e.srcElement.tmpValue;
							}, false);
			
			td.appendChild( link );			
		}//end of for( var i=0; i<keys.length; i++ )
	}//end of if( selHt != null && selHt.size()>0 )	
	
	var border = myTable.getAttribute( "border" );
	if( border.length == 0 )
		myTable.setAttribute( "border", "2" );
	myData.appendChild( myTable );
	
	//alert( myTable.getAttribute( "bordercolor" ) );
}//end of function createSel( id, tarId, selHt, initSelHt, tableProp, tableStyleProp, rowProp, rowStyleProp, columnProp, columnStyleProp, onSelColumnProp, onSelColumnStyleProp )

function createRectangleSel( id, tarId, dspId, selHt, initSelHt, columnCount, tableProp, tableStyleProp, rowProp, rowStyleProp, columnProp, columnStyleProp, onSelColumnProp, onSelColumnStyleProp ){

	var myData = document.getElementById( id );
	var tarValue = document.getElementById( tarId ).value;
	
	//建立一個<table>元素和一個<tbody>元素
	var myTable = null;
	if( document.getElementById( id + "Table" ) != null ){
		myTable = document.getElementById( id + "Table" );
		while (myTable.rows.length>0) 
			myTable.deleteRow(0);		
	} else {
		myTable = document.createElement( "table" );
		myTable.setAttribute( "id", id + "Table" );
	}//end of if( document.getElementById( id + "Table" ) != null )
	
	var myTableBody = document.createElement("tbody");
	
	if( tableProp != null && tableProp.size()>0 ){
		
		var keys = tableProp.keys();
		for( var i=0; i<keys.length; i++ )
			myTable.setAttribute( keys[i], tableProp.get( keys[i] ) );
	}//end of if( tableProp != null && tableProp.size()>0 )	

	var tableStyle = "";
	if( tableStyleProp != null && tableStyleProp.size()>0 ){
		
		var keys = tableStyleProp.keys();
		for( var i=0; i<keys.length; i++ ){
			if( tableStyle.length==0 )
				tableStyle = keys[i] + ":" + tableStyleProp.get( keys[i] );
			else
				tableStyle = tableStyle + ";" + keys[i] + ":" + tableStyleProp.get( keys[i] ); 
				
			if( document.all )	
				myTable.style.setAttribute( keys[i], tableStyleProp.get( keys[i] ) );		
		}//end of for( var i=0; i<keys.length; i++ )
		if( !document.all )
			myTable.setAttribute( "style", tableStyle );
	}//end of if( tableStyleProp != null && tableStyleProp.size()>0 )
	
	var rowStyle = "";
	if( rowStyleProp != null && rowStyleProp.size()>0 ){
		
		var tmpKeys = rowStyleProp.keys();
		for( var i=0; i<tmpKeys.length; i++ ){
			if( rowStyle.length==0 )
				rowStyle = tmpKeys[i] + ":" + rowStyleProp.get( tmpKeys[i] );
			else
				rowStyle = rowStyle + ";" + tmpKeys[i] + ":" + rowStyleProp.get( tmpKeys[i] ); 
		}//end of for( var i=0; i<tmpKeys.length; i++ )
	}//end of if( rowStyleProp != null && rowStyleProp.size()>0 )	
	
	var columnStyle = "";
	if( columnStyleProp != null && columnStyleProp.size()>0 ){
		
		var tmpKeys = columnStyleProp.keys();
		for( var i=0; i<tmpKeys.length; i++ ){
			if( columnStyle.length==0 )
				columnStyle = tmpKeys[i] + ":" + columnStyleProp.get( tmpKeys[i] );
			else
				columnStyle = columnStyle + ";" + tmpKeys[i] + ":" + columnStyleProp.get( tmpKeys[i] ); 
		}//end of for( var i=0; i<tmpKeys.length; i++ )
	}//end of if( columnStyleProp != null && columnStyleProp.size()>0 )	
	
	var onSelColumnStyle = "";				
	if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 ){
		
		var tmpKeys = onSelColumnStyleProp.keys();
		for( var i=0; i<tmpKeys.length; i++ ){
			if( onSelColumnStyle.length==0 )
				onSelColumnStyle = tmpKeys[i] + ":" + onSelColumnStyleProp.get( tmpKeys[i] );
			else
				onSelColumnStyle = onSelColumnStyle + ";" + tmpKeys[i] + ":" + onSelColumnStyleProp.get( tmpKeys[i] ); 
		}//end of for( var i=0; i<tmpKeys.length; i++ )
	}//end of if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 )	

	var tmpSelHt = new Hashtable();
	if( initSelHt != null && initSelHt.size()>0 ){
		
		var keys = initSelHt.keys();
		for( var i=0; i<keys.length; i++ )
			tmpSelHt.put( keys[i], initSelHt.get( keys[i] ) );
	}//end of if( initSelHt != null && initSelHt.size()>0 )	
	
	if( selHt != null && selHt.size()>0 ){
		
		var keys = selHt.keys();
		for( var i=0; i<keys.length; i++ )	
			tmpSelHt.put( keys[i], selHt.get( keys[i] ) );
	}//end of if( selHt != null && selHt.size()>0 )
	
	var module = tmpSelHt.size() % columnCount;
	var quot = tmpSelHt.size() / columnCount;
	var totRowCount = quot;
	if( module>0 )
		totRowCount = totRowCount + 1;
		
	//建立所有的單元格	
	var index = 0;
	if( tmpSelHt.size()>0 ){
		
		var keys = tmpSelHt.keys();
		
		for( var i=0; i<totRowCount; i++ ){
			//建立一個<tr>元素
		    myCurrentRow = document.createElement("tr");
			if( rowProp != null && rowProp.size()>0 ){
			
				var tmpKeys = rowProp.keys();
				for( var j=0; j<tmpKeys.length; j++ )
					myCurrentRow.setAttribute( tmpKeys[j], rowProp.get( tmpKeys[j] ) );
			}//end of if( rowProp != null && rowProp.size()>0 )
			
			if( rowStyleProp != null && rowStyleProp.size()>0 ){
				if( !document.all ){
					
					myCurrentRow.setAttribute( "style", rowStyle );
				} else {
					
					var tmpKeys = rowStyleProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )					
						myCurrentRow.setAttribute(tmpKeys[j], rowStyleProp.get(tmpKeys[j]) );  					
				}//end of if( !document.all )
			}//end of if( rowStyleProp != null && rowStyleProp.size()>0 )			
		
			for(var k = 0; k < columnCount; k++ ){	
				// 創建一個<td>元素
		    	myCurrentCell = document.createElement("td");
		    	
				if( columnProp != null && columnProp.size()>0 ){
		    	
					var tmpKeys = columnProp.keys();
					for( var j=0; j<tmpKeys.length; j++ )
						myCurrentCell.setAttribute( tmpKeys[j], columnProp.get( tmpKeys[j] ) );
				}//end of if( columnProp != null && columnProp.size()>0 )
				
				if( columnStyleProp != null && columnStyleProp.size()>0 ){
					
					if( !document.all ){				
					
						myCurrentCell.setAttribute( "style", columnStyle );
					} else {
						
						var tmpKeys = columnStyleProp.keys();
						for( var j=0; j<tmpKeys.length; j++ )					
							myCurrentCell.style.setAttribute( tmpKeys[j], columnStyleProp.get( tmpKeys[j] ) );
					}//end of if( !document.all )	
				}//end of if( columnStyleProp != null && columnStyleProp.size()>0 )
				
				if( index < keys.length ){
					
					if( tarValue==keys[ index ] ){
					
						if( onSelColumnProp != null && onSelColumnProp.size()>0 ){
		    			
							var tmpKeys = onSelColumnProp.keys();
							for( var j=0; j<tmpKeys.length; j++ )
								myCurrentCell.setAttribute( tmpKeys[j], onSelColumnProp.get( tmpKeys[j] ) );
						}//end of if( onSelColumnProp != null && onSelColumnProp.size()>0 )
						
						if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 ){
							
							if( !document.all ){					
							
								myCurrentCell.setAttribute( "style", onSelColumnStyle );
							} else {
								
								var tmpKeys = onSelColumnStyleProp.keys();
								for( var j=0; j<tmpKeys.length; j++ )
									myCurrentCell.style.setAttribute( tmpKeys[j], onSelColumnStyleProp.get( tmpKeys[j] ) );
							}//end of if( !document.all )
						}//end of if( onSelColumnStyleProp != null && onSelColumnStyleProp.size()>0 )
						
					}//end of if( tarValue==keys[ index ] )

					var link = document.createElement( "a" );
					link.setAttribute( "href", "#" );						
					link.setAttribute( "tmpValue", keys[ index ] );
					var currentText = document.createTextNode( tmpSelHt.get( keys[ index ] ) );
					link.appendChild( currentText );			
			    	
					addEvent( link, "click", function(){
											var e = getEvent();
											document.getElementById( tarId ).value =  e.srcElement.tmpValue;
											if( dspId != null )
												document.getElementById( dspId ).value = tmpSelHt.get( e.srcElement.tmpValue );
									}, false);							
					
					myCurrentCell.appendChild( link );										
				}//end of if( index <= keys.length && tarValue==keys[i] )
						
				myCurrentRow.appendChild( myCurrentCell );
		    	
		    	index = index + 1;
			}//end of for(var k = 0; k < columnCount; k++ )	
			myTableBody.appendChild( myCurrentRow );
		}//end of for( var i=0; i<totRowCount; i++ )
	}//end of if( tmpSelHt.size()>0 )
	
	myTable.appendChild( myTableBody );
		
	var border = myTable.getAttribute( "border" );
	if( border.length == 0 )
		myTable.setAttribute( "border", "2" );
	myData.appendChild( myTable );	
}//end of function createRectangleSel( id, tarId, selHt, initSelHt, columnCount, tableProp, tableStyleProp, rowProp, rowStyleProp, columnProp, columnStyleProp, onSelColumnProp, onSelColumnStyleProp )	

function blink( objId ){
	
	var obj = document.getElementById( objId );
	
	if( obj != null ){
	
		if( obj.style.visibility == "hidden" ){
			obj.style.visibility = "visible";
		} else if( obj.style.visibility == "visible" ){
			obj.style.visibility = "hidden";
		} else {
			obj.style.visibility = "hidden";
		}//end of if( obj.style.visibility == "hidden" )
	}//end of if( obj != null )
}//end of function blink( objId )

function disableButtonByType( strType ){
	
	var obj_array = getButtonByType( strType );
	for( var i=0; i<obj_array.length; i++ )
		obj_array[i].disabled = true;
}//end of function disableSubmitButton()

function enableButtonByType( strType ){
	
	var obj_array = getButtonByType( strType );
	for( var i=0; i<obj_array.length; i++ )
		obj_array[i].disabled = false;
}//end of function enableButtonByType( strType )

function getButtonByType( strType ){
	
	var obj_Array = new Array();
	
	var count = 0;
	var input_Array = document.getElementsByTagName( "input" );
	for( var i=0; i<input_Array.length; i++ ){
		
		if( input_Array[i].type == strType ){
			
			obj_Array[ count ] = input_Array[i];
			count = count + 1;	
		}//end of if( input_Array[i].type == strType )
	}//end of for( var i=0; i<input_Array.length; i++ )	
	
	var btn_Array = document.getElementsByTagName( "button" );
	for( var i=0; i<btn_Array.length; i++ ){
		
		if( btn_Array[i].type == strType ){
			
			obj_Array[ count ] = btn_Array[i];
			count = count + 1;
		}//end of if( btn_Array[i].type == strType )
	}//end of for( var i=0; i<btn_Array.length; i++ )	
	
	return obj_Array;
}//end of function getButtonByType( strType )

function getStringListByAllOption( srcField, delimiter ){
	
	var tarList = "";
	for( var i=0; i<srcField.options.length; i++ ){
	
		var strItem = srcField.options[i].value;
		tarList = ( tarList.length == 0 )? strItem:tarList + delimiter + strItem;
	}//end of for( var i=0; i<srcField.options.length; i++ )
	
	return tarList;
}//end of function getStringListByAllOption( srcField )

function getStringListBySelectedOption( srcField, delimiter ){
	
	var tarList = "";
	
	for( var i=0; i<srcField.options.length; i++ ){
	
		if( srcField.options[i].selected ){
			var strItem = srcField.options[i].value;
			tarList = ( tarList.length == 0 )? strItem:tarList + delimiter + strItem;
		}//end of if( srcField.options[i].selected )
	}//end of for( var i=0; i<srcField.options.length; i++ )
	
	return tarList;	
}//end of function getStringListBySelectedOption( srcField, delimiter )

function isOpenerExists(){
	//判斷母視窗是否關閉
	
	if( opener != null && !opener.closed )
		return true;
	
	return false;	
}//end of function isOpenerExists()

function change_td_bgColor( obj, color ){
	
	var td_array = obj.getElementsByTagName( "td" );
	for( var i=0; i<td_array.length; i++ ){
	
		var td_obj = td_array[i];
		td_obj.style.backgroundColor = color;
	}//end of for( var i=0; i<td_array.length; i++ )
}//end of function change_td_bgColor( obj, color )
