/*-------------------------------------------------------
util.js
depends on prototype.js(http://prototype.conio.net/)
@version  V1.0
@author   youngjin.shin (2007/04/20)

Copyright (c) 2007 Rakuten Travel, Inc. All Rights Reserved.
--------------------------------------------------------*/

if (!Util) {
  var Util={
    instances : null,
    getInstance:function (id){ 
  	   for (var i = 0; i < this.instances.length ; i++) {
  		    if( this.instances[i].id == id ){
  				return this.instances[i];
  			}
  		}
  		return null;
    },
    
    escapeHTML:function (str){
    	return str.replace(/\&/g, '&amp;').replace( /</g, '&lt;').replace(/>/g, '&gt;').replace(/\"/g, '&quot;').replace(/\'/g, '&#39;');
    },
    
    createOptionList:function ( optionId, valueList, nameList){
     	var index = 0;
 	 	var optionList = $(optionId);
     	for( ; index < valueList.length ; index++ ) {
        	optionList[index] = new Option( nameList[index],valueList[index] );
     	}  
     	while( optionList[index] ){
       		optionList[index] = null;
     	}  
	},
  
    createOptionList:function ( optionId, opList){
     	var index = 0;
 	 	var optionList = $(optionId);
 	 	var optGroup = null;
 	 	var option   = null;
 	 	this.clearChildNodes(optionList);
     	for( ; index < opList.length/2 ; index++ ) {
     		if(opList[index*2] == "GROUP-START"){
     			optGroup = document.createElement("optgroup");
     			optGroup.label = opList[index*2+1];
     			optionList.appendChild(optGroup);
     			index++;
     			for( ; index < opList.length/2 ; index++ ) {
     				if(opList[index*2] == "GROUP-END"){
     				   	break;
     				}
     				option = document.createElement("option");
     				option.innerHTML=opList[index*2+1];
     				option.value=opList[index*2];
     				optGroup.appendChild(option);
     				//optGroup.appendChild(new Option( opList[index*2+1],opList[index*2] ));
     			}
     			continue;
     		} 
        	optionList.options[index] = new Option( opList[index*2+1],opList[index*2] );
     	}
     	while( optionList[index] ){
       		optionList.options[index] = null;
     	}  
  	},
  	
  	clearChildNodes:function (obj){
  	    while( obj.childNodes[0] ){
       		obj.removeChild(obj.childNodes[0]);
     	}  
  	},
  	
 	appendList:function (trgList, srcList){
		if(trgList){
			if(srcList){
				for(i=0;i<srcList.length;i++){
					trgList.push(srcList[i]);
				}
			}
			return trgList;
		}	
	}

  };
}

Util.Suggest    = Class.create();
Util.TreeObject = Class.create();
Util.Date       = Class.create();
Util.LimitNumber= Class.create();