/*****************************************************************************************/
/*********  COOKIES  *********************************************************************/
/*****************************************************************************************/

function setCookie(name, value, expire) {
  strCookie = name + "=" + escape(value);
  if (expire)
    strCookie += "; expires=" + expire.toGMTString();
  document.cookie = strCookie;
}

function getCookie(Name) {
  var search = Name + "=";
  if (document.cookie.length > 0) {
    // if there are any cookies
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
      // if cookie exists
      offset += search.length;

      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);

      // set index of end of cookie value
      if (end == -1)
        end = document.cookie.length

      return unescape(document.cookie.substring(offset, end));
    }
  }
}

function cookiesEnabled() {
  setCookie("TEST","Hello","");
  if (getCookie("TEST") == "Hello") {
    return true;
  } else {
    return false;
  }
}



/*****************************************************************************************/
/*********  VELG FYLKE  *****************************************************************/
/*****************************************************************************************/
function VisFylke(Fylke) {
//  PopupVindu = window.open("hvor.asp?fylke="+Fylke, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"+justering);
//  PopupVindu.focus();
  document.url = "hvor.asp?fylke="+Fylke;
}

/*****************************************************************************************/
/*********  POPUP-WINDOW  ****************************************************************/
/*****************************************************************************************/
function getJustering(the_width, the_height) {
  var xMax,yMax;
  if (document.all) {
    xMax = screen.width;
    yMax = screen.height; }
  else {
    if (document.layers) {
      xMax = window.outerWidth;
      yMax = window.outerHeight; }
    else {
      xMax = 800;
      yMax = 600; }
  }

  var w_left;
  var w_top;
  w_left = (xMax - the_width)/2;
  w_top  = (yMax - the_height)/2;

  var justering = "";
  justering = justering + ",width="   +the_width;
  justering = justering + ",height="  +the_height;
  justering = justering + ",left="    +w_left;
  justering = justering + ",top="     +w_top;
  justering = justering + ",screenX=" +w_left;
  justering = justering + ",screenY=" +w_top;

  return justering;
}

/*-------------------------------------------------------------------------------------------*/
               
function openSos(the_nr) {
  var the_width  = 640;
  var the_height = 480;

  justering = getJustering(the_width, the_height);

  PopupVindu = window.open("popup/ViseSos.asp?nr="+the_nr, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"+justering);
  PopupVindu.focus();
}

function openOou(the_nr) {
  var the_width  = 640;
  var the_height = 480;

  justering = getJustering(the_width, the_height);

  PopupVindu = window.open("popup/ViseOou.asp?nr="+the_nr, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no"+justering);
  PopupVindu.focus();
}

function openNyhet(the_nr) {
  var the_width  = 640;
  var the_height = 480;

  justering = getJustering(the_width, the_height);

  PopupVindu = window.open("popup/ViseNyhet.asp?nr="+the_nr, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"+justering);
  PopupVindu.focus();
}

function openProdukterVer(the_nr) {
  var the_width  = 640;
  var the_height = 480;

  justering = getJustering(the_width, the_height);

  PopupVindu = window.open("db/produkter_ver/"+the_nr+".html", "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no"+justering);
  PopupVindu.focus();
}

function openProdukterSos(the_nr) {
  var the_width  = 640;
  var the_height = 480;

  justering = getJustering(the_width, the_height);

  PopupVindu = window.open("popup/ViseSos.asp?nr="+the_nr, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"+justering);
  PopupVindu.focus();
}

function openHvor(Navn, Adresse, PostNr, PostSted, Tlf, Epost) {
  var the_width  = 550;
  var the_height = 290;

  justering = getJustering(the_width, the_height);

  PopupVindu = window.open("popup/ViseHvor.asp?Navn="      + Navn      +
                                             "&Adresse="   + Adresse   +
                                             "&PostNr="    + PostNr    +
                                             "&PostSted="  + PostSted  +
                                             "&Tlf="       + Tlf       +
                                             "&Epost="     + Epost,
                                             "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"+justering);
  PopupVindu.focus();
}

function openBest(Info_Beskrivelse,Info_Sted,Info_Dato,Info_Tid,Info_Pris,Info_Rabatt) {
  var the_width  = 640;
  var the_height = 550;

  justering = getJustering(the_width, the_height);

  paramString = "";
  paramString = paramString+ "?Info_Beskrivelse=" + Info_Beskrivelse;
  paramString = paramString+ "&Info_Sted="        + Info_Sted;
  paramString = paramString+ "&Info_Dato="        + Info_Dato;
  paramString = paramString+ "&Info_Tid="         + Info_Tid;
  paramString = paramString+ "&Info_Pris="        + Info_Pris;
  paramString = paramString+ "&Info_Rabatt="      + Info_Rabatt;

  PopupVindu = window.open("popup/ViseBest.asp"+paramString, "Popup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no"+justering);
  PopupVindu.focus();
}



/*****************************************************************************************/
/*********  LOGG INN og REGISTRERING  ****************************************************/
/*****************************************************************************************/

function loggInn() {
  if (cookiesEnabled() == true) {
    var tmp = prompt("Skriv inn din epostadresse","");

    if (tmp != null) {
      if (tmp != "") {      //Legge inn en skikkelig sjekk
        setCookie("email", tmp, "");
        window.location.reload();
      } else {
        alert("Skriv inn en gyldig epostadresse");
      }
    }
  } else {
    alert("Nettleseren må støtte cookies.");
  }
}

function loggOut() {
  setCookie("email", "", "");
  window.location = "hoved.asp";
//  window.location.reload();
}


function avbrytRegistrering() {
  window.opener.setCookie("email", "", "");
  window.opener.location.reload();
  window.close();
}

function sjekkRegistrering() {
  tmp = true;
  formObj = document.registreringsSkjema;

  //TRIM DISSE VED SJEKK, Grundigere epost sjekk...
  if (formObj.navn.value == "") {
    alert("Du må fylle inn et navn.");
    formObj.navn.focus();
    tmp = false;
  }
  else if (formObj.epost.value == "") {
    alert("Du må fylle inn en epostadresse.");
    formObj.epost.focus();
    tmp = false;
  }

 if (tmp) {
    formObj.submit();
  }
}


function sendInn_epostListe() {
  tmp = true;
  formObj = document.registreringsSkjema;

  if (formObj.epost.value == "") {
    alert("Du må fylle inn en epostadresse.");
    formObj.epost.focus();
    tmp = false;
  }

 if (tmp) {
    formObj.submit();
  }
}



/*****************************************************************************************/
/*********  STATUS  **********************************************************************/
/*****************************************************************************************/

Status_email	     = "Klikk her for å logge deg inn med en annen emailadresse";
Status_hoved       = "Hovedside, med informasjon om eierskifte.no";
Status_nyheter     = "Hva er siste nytt innen eierskifte?";
Status_planleggern = "Les mer om Planleggern";
Status_sos         = "Spørsmål og svar om eierskifte";
Status_oou         = "En oversikt over ord og uttrykk";
Status_lenker      = "Diverse nyttige lenker";
Status_hvor        = "Oversikt over eierskifte-rådgivere";


Status_Produkter_Informasjon = "Informasjon om Planleggern";
Status_Produkter_Nyheter     = "Hva er nytt i siste versjon";
Status_Produkter_Nedlasting  = "Her kan du laste ned Planleggern";
Status_Produkter_Lisens      = "Klikk her for å bestille Planleggern, eller for å fornye din lisens";
Status_Produkter_SOS         = "Spørsmål og svar om Planleggern";
Status_Produkter_DISK        = "Lukket diskusjonsgruppe for Planleggernbrukere";

function MouseOver(adr) {
  if (adr != null && adr != "") {
    txt = adr.substring(adr.lastIndexOf('(')+2,adr.lastIndexOf(')')-1);
    txt = adr;
    window.status = eval("Status_" + txt);
  }
}

function VisStatus(txt) {
  window.status = txt;
}

window.defaultStatus='';

