////////////////
function  js_var_isdef( v )
{
  try {
    if  ( ( v == null) || (typeof(v) == "undefined") )   
     return false;
  return true;
  }
  catch(ex)
  {
    return false;
  }
  
  return true;
}


////////////map class begin /////////////

function struct(key, value){

  this.key = key;
  this.value = value;

}

function setAt(key, value){
  
  for (var i = 0; i < this.map.length; i++)
  {
    if ( this.map[i].key === key )
    {
      this.map[i].value = value;
      return;
    }
  }
  
  this.map[this.map.length] = new struct(key, value);

}

function lookUp(key)
{
  for (var i = 0; i < this.map.length; i++)
  {
    if ( this.map[i].key === key )
    {
      return this.map[i].value;
    }
  }
  
  return null;
}

function removeKey(key)
{
  var v;
  for (var i = 0; i < this.map.length; i++)
  {
    v = this.map.pop();
    if ( v.key === key )
      continue;
      
    this.map.unshift(v);
  }
}

function getCount(){
  return this.map.length;
}

function isEmpty(){
  return this.map.length <= 0;
}

function classJsMap() {

  this.map = new Array();

  this.lookUp = lookUp;
  this.setAt = setAt;
  this.removeKey = removeKey;
  this.getCount = getCount;
  this.isEmpty = isEmpty;
}

///////////map class end./////////////////


///////////////Cookie function Begin//////////////////


function js_cookie_set_i(name,value, exptime )
{   
    var exp  = new Date();
    exp.setTime(exp.getTime() + exptime*1000);
    document.cookie = name + "="+ escape (value) + ";path=/" +  ";expires=" + exp.toGMTString();   
}

function js_cookie_get_i(name)        
{  
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return null; 
}


function js_cookie_del_i(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

function  js_cookie_ready()
{
    var name = "js_cookie_test2008abc";
    var value = "hello";
    js_cookie_set_i( name , value , 3600*72 );
    if( value == js_cookie_get_i( name ) ) {
      return true;
    }
            
    return  false;
}

var  js_cookie_map = null;
if( js_cookie_ready() == false )
{
    js_cookie_map = new classJsMap();    
    alert("Warning: cookie is not supported by your browser! some function will be disabled.");
}


function js_cookie_set(name,value, exptime )
{   

  if( js_cookie_ready() ) {
     js_cookie_set_i(name,value,exptime);
   }
   else {
   js_cookie_map.setAt( name, value );
  }
      
}

function js_cookie_set_default(name,value )
{
  js_cookie_set(name,value, 30*24*3600 ); //Default: 30Days.
}

function js_cookie_get(name)        
{
  if( js_cookie_ready() ) {
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
  }
  else {
   return  js_cookie_map.lookUp( name );     
  }

}
function js_cookie_del(name)
{
if( js_cookie_ready() ) {
   js_cookie_del_i(name);
 }
 else {
  js_cookie_map.removeKey( name );
 }
    
}

///////////////////Cookie function End///////////////////



///////////////Browser control function begin ////////////////////////
////////////update the text of Status bar of the browser////////////
function   js_browser_updatestatusbar( msg )
{
  window.status = msg;
}


///////////////Browser control function End ////////////////////////



////////////////Controls & Objects function Begin //////////////////
function   js_ui_findobj( objtag, objname )
{
  var  objs = document.getElementsByTagName( objtag );
  if( objs == null ) return null;
  
  var  len = objs.length;
  var  n;
  for(n=0;n<len;n++)
  {
  
     var obj = objs[n];     
     var sname = obj.getAttribute("name");
     if( sname == null || sname.length == 0 ) continue;                
     var  idx =  sname.indexOf( objname );
     if( idx > 0 ) {
        return obj;
     }               
     
  }
  return null;
  
}


////////////////Controls & Objects function End //////////////////
