// cooklib Last updated 2007.4.9

function setCookie( nvalue, path, domain, expire ){
  var expstr = (expire)?expire.toGMTString():"";
  document.cookie = (( nvalue )?nvalue + ";":"" ) + (( path )?"path=" + path + ";":"" ) + 
         (( domain )?"domain=" + domain + ";":"" ) + ((expstr)?"expires=" + expstr:""); 
}

function getCookie( item ){
  var i, index, arr;
  arr = document.cookie.split( ";" );
  for( i = 0; i < arr.length; i++ ) {
    index = arr[i].indexOf( "=" );
    if( trim( arr[i].substring( 0, index ) ) == item )
      return arr[i].substring( index + 1 );
  }
  return "";
}

function deleteCookie(name, path, domain){
  if(getCookie(name)){
    setCookie( name + "=", path, domain, new Date(1971, 0, 1, 0, 0, 1) );
  }
}


function extendExpires(){
  if( getCookie( "sid" ) ){
    var nvalue = document.cookie;
    var exp = new Date();
    exp = new Date( exp.getTime() + 3 * 3600 * 1000 );
    setCookie( nvalue, "/", ".atengineer.com", exp );
  }
}

function extendExpire( expflg ){
  if( getCookie( "sid" ) ){
    var nvalue = document.cookie;
    var exp = new Date();
    if( expflg=="1" ){
      exp = new Date( exp.getTime() + 365 * 24 * 3600 * 1000 );
    }else{
      exp = new Date( exp.getTime() + 3 * 3600 * 1000 );
    }
    setCookie( nvalue, "/", ".atengineer.com", exp );
  }
}

function setsidToCookie( sid, expflg ){
  var exp;
  exp = new Date();
  if( expflg=="1" ){
    exp = new Date( exp.getTime() + 365 * 24 * 3600 * 1000 );
  }else{
    exp = new Date( exp.getTime() + 3 * 3600 * 1000 );
  }
  setCookie( "sid=" + sid, "/", ".atengineer.com", exp );
}

function createsid(){
  var i;
  var id = "";
  for( i=0; i<20; i++ ){
    id += GetRandomChar();
  }
  return id;
}

function GetRandomChar(){
  var c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  var r = Math.floor( Math.random() * 62 );
  return c.charAt(r);
}

function logoff(url){
  deleteCookie( "sid", "/", ".atengineer.com" );
  top.location = url;
}

function trim(item){
 return item.replace(/^\s+|\s+$/g,"");
}

