function popup(url, width, height) {
  open(url, "popup", "height="+height+",width="+width+",channelmode=no,directories=no,fullscreen=no,location=yes,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
}
function preview(url, width, height) {
  open(url, "preview", "height="+height+",width="+width+",channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no");
}
function https(url, width, height) {
  open(url, "popup", "height="+height+",width="+width+",channelmode=no,directories=no,fullscreen=no,location=yes,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no");
}
function getObject(name) {
  if (document.all) {
    return document.all(name);
  } else if(document.getElementById) {
    return document.getElementById(name);
  }
  return null;
}
function updateCharLeft(max, text, info) {
  var comment = getObject(text);
  var span = getObject(info);
  var balance = max - comment.value.length;
  if (balance >= 0) {
    span.innerHTML = balance;
  } else {
    comment.value = comment.value.substring(0, max);
  }
}
function charleft(max) {
  return updateCharLeft(max, "comment", "charleft");
}
function refresh(frm, url) {
  var f = document.forms[frm];
  f.action = url;
  f.submit();
}
function transfer(form, fr, to) {
  var f = document.forms[form];
  f.elements[to].value = f.elements[fr].value;
  f.submit();
}
function send(form, fr, to, pad, nick, pass, btn) {
  var f = document.forms[form];
  if (f.elements[fr].value.length < 6) {
    alert("Mobilephone's number is too short !");
    f.elements[fr].focus();
    return false;
  }
  var i = pad.length;
  if (f.elements[fr].value.substr(0, i) == pad) {
    var reinsert = "Please note that you DO NOT have to reinsert country code!\nPress [OK] to continue. Press [Cancel] to edit your mobile phone number.\n";
    if (confirm(reinsert) == false) {
      f.elements[fr].focus();
      return false;
    }
  }
  var v = f.elements[fr].value;
  if (v.substring(0, 1) == "0") {
    var leadzero = "Please note that for most of the country, you need to EXCLUDE leading zero in mobile phone number filed.\n" +
      "Press [Ok] to continue. Press [Cancel] to edit your mobile phone number.";
    if (confirm(leadzero) == false) {
      f.elements[fr].focus();
      return false;
    }
  }
  f.elements[to].value = pad + f.elements[fr].value;
  if (f.elements[nick].value.length < 1) {
    alert("Nickname field should not be empty !");
    f.elements[nick].focus();
    return false;
  }
  if (f.elements[pass].value.length < 1) {
    alert("Password field should not be empty !");
    f.elements[pass].focus();
    return false;
  }
  f.elements[btn].disabled = true;
  return true;
}
function sendSMS(prefix) {
  return send("download", "mobiletmp", "mobilenum", prefix, "nick", "pass", "btnsubmit");
}
function sendMZ(prefix) {
  return send("download", "mobiletmp", "mobilenum", prefix, "nick", "pass", "btnsubmit");
}
function sendMMS(prefix) {
  return send("download", "mobiletmp", "to", prefix, "nick", "pass", "btnsubmit");
}