function valid_js() {
   // anything that claims NS 4 or higher functionality better work
   if (navigator.userAgent.indexOf("Mozilla/") == 0) {
      return (parseInt(navigator.appVersion) >= 4);
   }
   return false;
}

function hash(form,login_url) {
    // this is Javascript enabled browser
    //document.login_form[".js"].value=1;
    // rudimentary check for a 4.x brower. should catch IE4+ and NS4.*
    var url;

    if (arguments.length > 1 && login_url != "") { // in case login_url is not passed in
      url = login_url;
    } else {
      url = "http://www.saigonmusic.net/login.cgi";
    }
    url += "?";

    if (valid_js()) {
      var passwd = form.password.value;
      var hash1 = hex_md5(form.password.value);

     for(i=0; i<form.elements.length; i++){
        if(form.elements[i].name.length <=0) {
          continue;
        }
        if(i > 0){
          url += "&";
        }
        url += form.elements[i].name;
        url += "=";
        if(form.elements[i].name == "password"){
          url += hash1;
        } else if (form.elements[i].type == "checkbox" && !form.elements[i].checked) {
          url += "";
        } else if (form.elements[i].type == "radio" && !form.elements[i].checked) {
          url += "";
        } else if (form.elements[i].name == ".save"){
          url += "1"; // "Sign in" causes problem with the space
        } else if (form.elements[i].name == ".js"){
          js = 1;
          url += "1";
        } else {
          url += escape(form.elements[i].value);
        }
      }

      // indicate the password is hashed.
      url += "&hash=1";
      url += "&md5=1";
      //alert("url=" + url);
      location.href=url;
      // prevent from running this again. Allow the server response to submit the form directly
      form.onsubmit=null;

      // abort normal form submission
      return false;
    }
    // allow normal form submission
    return true;
}
