/* 
 * NAME:    forms.js 
 * PURPOSE: javascript used for all forms, for musictibet.com
 *      These are all functions which provide some kind of 
 *      display or checking to make things easier for the
 *      website user. They do not do anything vital to the
 *      website, as javascript is not secure, and also, can
 *      be turned off by the user.
 * STATUS:  14 apr 2007 jw - works.
 */

// changeInputClass()
//   - change the class name of an input form element
//     (example - hide submit button after submittal)
  function changeInputClass(styleChange, item) {
    item.className = styleChange;
  }


// checkEmailSyntax()
//   - checks email syntax.
// 19 jul 2003 - needs more work - it tells true for dot
//   if the dot is in the portion before the @.
  function checkEmailSyntax(checkString) {

    if (checkString) {
	    var newstr = "";
	    var at = false;
	    var dot = false;
	
	    // Do some preliminary checks on the data:
	
	    // If email address has a '@' character:
	    if (checkString.indexOf("@") != -1) {
	      at = true;
	
	    // If email address has a '.' character:
	    } else if (checkString.indexOf(".") != -1) {
	      dot = true;
	    }
	    // Parse remainder of string:
	    for (var i = 0; i < checkString.length; i++) {
	        ch = checkString.substring(i, i + 1)
	        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
	                || (ch == "@") || (ch == ".") || (ch == "_")
	                || (ch == "-") || (ch >= "0" && ch <= "9")) {
	                newstr += ch;
	                if (ch == "@") {
	                    at=true;
	                }
	                if (ch == ".") {
	                    dot=true;
	                }
	        }
	    }
	
	// alert(dot);
	// return false;
	
	    if ((at == false) || (dot == false)) {
	      // Display error message:
	      return ("* The email address you entered doesn't look like an email address.\n");
	    } else {
	        return ("");
	    }
    } else {
        return ("");
    }
  }

// checkEmailMatch()
//   - make sure that two typed emails are the same
  function checkEmailMatch(theForm) {
    email1 = theForm.email_address1.value;
    email2 = theForm.email_address2.value;
    if (email1 != email2) {
      return("These email addresses don't match!");
    }
  }


// checkFormFields()
//   - save time for the user, by checking for 
//     empty fields, email syntax, etc.
//     before form input goes to the script.
// note: The same checks *must* be made again in the
//       server-side script, as javascript is not secure.
  function checkFormFields(form, tag) {
// alert(form);
  }

// checkFormFields()
//   - save time for the user, by checking for 
//     empty fields, email syntax, etc.
//     before form input goes to the script.
// note: The same checks *must* be made again in the
//       server-side script, as javascript is not secure.
  function checkApplyFormFields(form, tag) {
// alert(form);
  }


/* e o f */

