
function EventUtil() {}
var eventUtil=new EventUtil();

// Event Response class definition
//================================================
function EventResponse() {}
var eventResponse = new EventResponse();


// Timer class definition
//================================================
function TimerUtil(command, timeInMs, repeat) {
    this.command  = command;
    this.timeInMs = timeInMs;
    this.timer    = 0;
    this.repeat   = repeat;
}

TimerUtil.prototype.start = function() {
    if (this.timer > 0)
        { this.reset(); }
    this.timer = window.setTimeout(this.run, this.timeInMs);
}

TimerUtil.prototype.run   = function() {
    if (this.repeat) 
        { this.start(); }
    this.command();
}

TimerUtil.prototype.reset = function() {
    if (this.timer > 0)
        { window.clearTimeout(this.timer); }
    this.timer = 0;
}


// Form
//================================================
  function deleteOptions(selectObj) { 
  	while (selectObj.options.length>0) { 
  		deleteIndex = selectObj.options.length-1; 
  		selectObj.options[deleteIndex] = null; 
  	}
  } 
  
  function setOptions(selectObj, text, value, selected, number) {
  	var select;
  
  	deleteOptions(selectObj);
  
  	if (!number)
  		number = text.length;
  
  	for (var i=0; i < number; i++) {
  		myOption       = new Option(); 
  		myOption.text  = text[i];
  		myOption.value = value[i];
  	
  		if (selectObj.selectedIndex>0) {
  			     insertIndex = selectObj.selectedIndex; 
  		} else { insertIndex = selectObj.options.length; }
  
  		if (value[i] == selected) {
  			select = insertIndex;
  		}
  		
  		selectObj.options[insertIndex]=myOption;	
  	}
  	if (select)
  		selectObj.selectedIndex = select;
  }


// Cookie
//================================================
var Cookies = {}
Cookies.ckGet = function( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
        { return null; }
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

Cookies.ckSet = function( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

Cookies.ckDelete = function( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

