/************************************************************************
  Javascript RARSFest Ticket Database Functions
  by K4HM - Hank Montgomery       k4hm@arrl.net
************************************************************************/

//   <!-- Original:  Eric King (eric_andrew_king@hotmail.com) -->       
//    <!-- Web Site:  http:\\redrival.com\eak -->                       
//    <!-- This script and many more are available free online at -->   
//    <!-- The JavaScript Source!! http:\\javascript.internet.com -->   

      function NewWindow(mypage, myname, w, h, scroll) {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
      }




function Instructions() {
  alert('This is the Instructions popup');
window.open( 'profilehelp.html', 'Instructions', 
'status = 1, height = 550, width = 700, scrollbars=1, resizable=1' )
}

function trim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
  return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
  return stringToTrim.replace(/\s+$/,"");
}

function checkemail(checkEmail) {
//  alert ("checking email");
  if (checkEmail.length > 0) {
    CharAt  =checkEmail.indexOf('@');
    var userName=checkEmail.substring(0,CharAt);
    var serverName = checkEmail.substring(CharAt+1);
    CharDot =serverName.indexOf('.');
    if ( (CharAt < 1) || (CharDot < 2) || (checkEmail.length < (CharAt + CharDot + 4)) ) {
      var msg='\tThe email address in not in a valid format.\n \n• A valid email address starts with a username (preferrably your callsign).\n\n• The username is followed by an \"@\" character.\n\n •The \"@\" character is followed by a mail server name (like \"arrl.net\").\n\n• For example my email username is \"hank\" on the mail server at \"k4hm.net\"\n\twhich resolves to \"hank@k4hm.net\".\n\nNote: Case is ignored in email addresses.\n\n\nYour input indicates:\n username = \"'+userName +'\"\ \n servername = \"'+serverName+'\"';
      alert(msg);
      s.Email.select();
      return false;
      } else {return true;} 
    }
    else {
      if (confirm('Warning - You have not provided an email address.\n\nClick OK to save this profile without an email address.')) {
//        alert("reply was OK");
        return true;
        } else {
//       alert ("reply was Cancel");
          return false;
        }
    }
  }

  


function xnewwindow() 
{ 
window.open('help.html','jav','width=300,height=200,resizable=yes'); 
} 


/**********************************************************
** valSearch()  Verifies user provided some search criteria                                                                        
**********************************************************/
function valSearch(s) {
  var txtTest = s.txtSearch.value;
  // alert('This is vasSearch with txtTest = [' + txtTest + ']');
  if (txtTest.length == 0) {
      alert("You must enter something in the search field.");
      s.txtSearch.focus();
      return false;
      }
  return true;
  }
    


/********************************************************
** vallogin()  Verifies user provided userid and password                                                                        
********************************************************/
function vallogin(s)
  {
    /* alert("Checking for blank Passwword or UseerID"); */
    var txtPass = s.tryPassword.value;
    var txtUser = s.tryUserid.value;
    if (txtPass == '' || txtUser == '') {
      alert("A blank Userid or Password is not allowed.");
      s.screen.value = "";
      s.tryUserid.focus();
      return false;
    } else {
      return true;
    }
  }


/********************************************************
** valGetPwd()  Verifies user gave userid to get password                                                                        
********************************************************/
    function valGetPwd(s)
    {
      var txtUser = s.tryUserid.value;
      if (txtUser.length == 0)
        {
        alert("Please enter your Userid");
        s.tryUserid.focus();
        return false;
        }
      s.screen.value = "GetPwd";
      return true;
    }   
  

/**********************************************************
** valForm()  Verifies user filled all required fields                                                                        
**********************************************************/
function valForm(s)
  {
//    var txtCall = s.txtCallSign.value;
//    if (txtCall.length == 0) {
//      alert("Please enter a CallSign");
//      s.txtCallSign.focus();
//      return false;
//    }

//        s.txtCall.value = txtCallSign.toUpperCase(); //  Convert Callsign to upper case

    var txt_Name = s.txtName.value;
    if (txt_Name.length == 0) {
      alert("Please enter a name");
      s.txtName.focus();
      return false;
    }

    var txtAddr1 = s.txtAddr1.value;
    if (txtAddr1.length == 0) {
      alert("Please enter an address");
      s.txtAddr1.focus();
      return false;
    }
    var txtCity = s.txtCity.value;
    if (txtCity.length == 0) {
      alert("Please enter a city");
      s.txtCity.focus();
      return false;
    }
    var txtState = s.txtState.value;
    if (txtState.length != 2) {
      alert("Please enter a valid 2-character state code");
      s.txtState.focus();
      return false;
    }
    s.txtState.value = txtState.toUpperCase(); //  Convert State to upper case

    var txtZip = s.txtZip.value;
    if (txtZip.length != 5 && txtZip.length != 10) {
      alert("Please enter a 5-digit or 10-digit zip code");
      s.txtZip.focus();
      return false;
    }
    return true;
  }

