var domain = 'hudson.com';
function SetHudsonSite (){
  var rbArray = document.frmMyHudson.rbMyHudson;
  var Url='';
  var rbSelected;
  for (var i=0; i < rbArray.length; i++)
    if (rbArray[i].checked) {
      rbSelected = rbArray[i];
      Url = rbArray[i].value;
    }

  if (!Url) ChangeInnerHTML ('formanswer', 'Select one of the websites');
  else {
    WriteCookie ('DefaultHudsonJobSite', Url, 8760, '/', domain); // cookie for one year
    rbSelected.checked = false;
    ChangeInnerHTML ('formanswer', 'your preferences are saved');
  }
  return false;
}

function ClearHudsonSite (){
  WriteCookie ('DefaultHudsonJobSite', '', -1, '/', domain); // delete cookie
  ChangeInnerHTML ('formanswer', 'your preferences are cleared');
}
//---------------------------------------------
// Write the cookie to the client disk
//---------------------------------------------
function WriteCookie (Name, Value, Expire, Path, Domain, Secure){
  // creating cookie contents
  if (Name=='') return;
  var Cookie = Name + '=' + escape (Value);
  if (Expire){
    // set the expire date
    var D = new Date((new Date()).getTime() + Expire*3600000);
    Cookie += '; expires=' + D.toGMTString();
  }
  if (Path) Cookie += '; path=' + Path;
  if (Domain) Cookie += '; domain=' + Domain;
  if (Secure) Cookie += '; secure';
  
  // write the cookie
  document.cookie = Cookie;
}

//------------------------------------------------------------
// Read Cookie for this webside from client disk
//------------------------------------------------------------
function ReadCookie (Name, DefValue){
  // Get all cookies for this page
  var Cookies = document.cookie;
  if (Cookies == '') // no cookie for this page
    return (DefValue);
  
  var Start = Cookies.indexOf (Name+'=');
  if (Start == -1) // No cookie of this name
    return DefValue;

  // getting cookie value
  Start += Name.length + 1;
  var End = Cookies.indexOf(';', Start);
  if (End == -1) End = Cookies.length;
  
  return (unescape (Cookies.substring(Start, End)));
}


