//
// verification code for the mailing list subscribe box
//

function trim(sString) {
  while (sString.substring(0,1) == ' ') {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ') {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function echeck(str) {

  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("That's not a real email address.")
     return false
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    alert("That's not a real email address.")
    return false
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    alert("That's not a real email address.")
    return false
  }

  if (str.indexOf(at,(lat+1))!=-1){
    alert("That's not a real email address.")
    return false
  }

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    alert("That's not a real email address.")
    return false
  }

  if (str.indexOf(dot,(lat+2))==-1){
    alert("That's not a real email address.")
    return false
  }

  if (str.indexOf(" ")!=-1){
    alert("That's not a real email address.")
    return false
  }

  return true
}

function ValidateForm(){
  var emailID=document.subscribe.email.value

  if ((emailID==null)||(emailID=="")||(emailID=='My Email')){
    alert("Please Enter your email address")
    document.subscribe.email.focus()
    return false
  }
  if (echeck(emailID)==false){
    document.subscribe.email.value=""
    document.subscribe.email.focus()
    return false
  }
  if (document.subscribe.fname.value.length > 40) {
    alert("Your name's not really that long.")
    document.subscribe.fname.value=''
    document.subscribe.fname.focus()
    return false
  }
  if (document.subscribe.age.value > 70) {
    alert("Aren't you a little old to be listing to this music?")
    document.subscribe.age.value=''
    document.subscribe.age.focus()
    return false
  }
  if ((trim(document.subscribe.age.value)!='') && (document.subscribe.age.value < 10)) {
    alert("Aren't you a little young to be looking at this website?")
    document.subscribe.age.value=''
    document.subscribe.age.focus()
    return false
  }

  if((trim(document.subscribe.age.value)!='')&&(document.subscribe.age.value!='Age')) {
    var checkOK = "0123456789";
    var checkStr = document.subscribe.age.value;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
        if (ch == checkOK.charAt(j))
          break;
      if (j == checkOK.length)
      {
        allValid = false;
        break;
      }
      allNum += ch;
    }
    if (!allValid)
    {
      alert("Your age is nothin' but a number!!");
      document.subscribe.age.focus();
      return (false);
    }
  }

	if (document.subscribe.age.value=='Age'){
		document.subscribe.age.value='';
	}
    if (document.subscribe.fname.value=='First Name'){
        document.subscribe.fname.value='';
    }
    if (document.subscribe.lname.value=='Last Name'){
        document.subscribe.lname.value='';
    }

  return true;
}

