/* The Bof System JS V 1.0 */

function popDate(file, width, height, scrollbars, whenON, whenOFF) {
  whenON = new Date(whenON)
  whenOFF = new Date(whenOFF)
  date = new Date()
  if (whenOFF.getTime() > date.getTime() && whenON.getTime() < date.getTime()){
    window.open('' + file + '.html','_' + file + '','toolbar=no,location=no,scrollbars=' + scrollbars + ',width=' + width + ',height=' + height + '');
  }
}
// popDate("pop_nbrev", "350", "200", "no", "04/01/2003", "04/13/2003")

function pop(file, target, width, height, scrollbars) {
  window.open('' + file + '','_' + target + '','toolbar=no,location=no,scrollbars=' + scrollbars + ',width=' + width + ',height=' + height + '');
}

function popHelpBak(id) {
  window.open('help.php?sida=' + id + '','_help' + id + '','menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,width=270,height=200');
}

function popHelp(id) {
  window.open('help.php?sida=lathund#' + id + '','_help','menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,width=270,height=200');
}

function checkBox(form) {
id = document.form.checked;
 if (id != '') {
   id = '';
 } else {
   id = 'true';
  }
}

function del(data, grupp, id, action) {
  if (confirm('Radera ' + data + '?')) {
    document.del.grupp.value = grupp;
    document.del.id.value = id;
    document.del.action.value = action;
    document.del.submit();
  }
}

function cut(data, grupp, id) {
  document.move.grupp.value = grupp;
  document.move.id.value = id;
  document.move.action.value = "mtg";
  document.move.grupp2.value = data;
}

function copy(data, grupp, id) {
  document.move.grupp.value = grupp;
  document.move.id.value = id;
  document.move.action.value = "ctg";
  document.move.grupp2.value = data;
}

function paste(grupp) {
  temp = "";
  if (document.move.action.value != "") {
    if (document.move.action.value == "mtg") { temp = "Flytta "; }
    if (document.move.action.value == "ctg") { temp = "Kopiera "; }
    if(confirm(temp + ' ' + document.move.grupp2.value + '?')) {
      document.move.grupp2.value = grupp;
      document.move.submit();
    }
  } else { alert("Inget markerat!"); }
}

function uncheckAll() {
  for(var i=0; i < document.deladresser.elements.length; i++) {
    if (document.deladresser.elements[i].type=='checkbox') { document.deladresser.elements[i].checked = false; }
  }
}

function copyit(obj) {
  rng=obj.createTextRange();
  rng.execCommand("RemoveFormat");
  rng.execCommand("Copy");
  alert('Texten är nu sparad i urklipp.');
  this.disabled = true;
}

function random(x) {
  today = new Date();
  num = today.getTime();
  num = Math.round(Math.abs(Math.sin (num)*1000000)) % x;
  return num + 1;
}

function genPass(w1, w2, w3) {
  while (id == null) {
    vo = "aeiouAEU";

    co = "bcdfgjklmnprstvwxzBCDFGHJKMNPQRSTVWXYZ0123456789_$%#";
    s = Math.round(Math.random());
    l = 8;
    p = '';

    for (i = 0; i < l; i++) {
      if (s) {
        letter = vo.charAt(Math.round(Math.random() * (vo.length - 1)));
        s = 0;
      } else {
        letter = co.charAt(Math.round(Math.random() * (co.length - 1)));
        s = 1;
      }
      p = p + letter;
    }

    var id = prompt('Lösenord:', p);
    if (id != null) {
      //alert('Lösenord: ' + p);
      document.getElementById(w1).value = id;
    }
  }
}
