/* Thanks for paying me the compliment of taking time to look at my code.
//
// I have made this code viewable to you as a priveledge, not as a right.
//
// All code below is made available under the GNU General Public License
// http://www.gnu.org/license/gpl.html
//
// This means that you are free to use and modify the code AS LONG AS YOU
// MAKE ALL DERIVATIVE CODE AVAILABLE FOR FREE TO OTHERS UNDER THE SAME LICENSE.
//
// If you use the code below, please mention http://www.tomoakley.net/
// on your script. Thanks.
*/

// break out of frames
if ( window != top ) top.location.href = location.href;


/**
 * Returns true if email had a valid form
 * 
 * @param     string    s   Email address
 */
function isEmail (s) {
  var reEmail = /^.+\@.+\..+$/ // set regular expression for email address
  return reEmail.test(s);      // test email address against regular expression
}


/**
 * Returns false if form has not been filled in properly
 * 
 * @param     string    f   name of HTML form
 */

function check_form(f) {                       // f is the form
  if(document.all || document.getElementById){ // check methods available to browser

    if(f.name.value.length < 1){               // check if user has not entered anything
      f.name.style.background = "#ffcccc";     // make name field red
      f.name.focus();                          // focus on the name field 
      alert("You must enter a name");          // alert user
      return false;                            // make sure the form is not submitted
    } else {
      f.name.style.background = "#ccffcc";     // make name field green
    }

    if(!isEmail(f.email.value)){               // check if email address is invalid
      f.email.style.background = "#ffcccc";    // make email field red
      f.email.focus();                         // focus on the email field
      alert("You must enter a valid email address of the form\njohn@company.com");
      return false;                            // make sure the form is not submitted
    } else {
      f.email.style.background = "#ccffcc";    // make the email field green
    }

    if(f.content.value.length < 1){            // check if user has not entered anything
      f.content.style.background = "#ffcccc";  // make content field red
      f.content.focus();                       // focus on the content field 
      alert("You must enter a message");       // alert user
      return false;                            // make sure the form is not submitted
    } else {
      f.content.style.background = "#ccffcc";  // make content field green
    }
	} else {
	  return true;                               // is browser can not use DOM, send it for checking at server
	}
}

/**
 * Sets href property of style element to given URL
 * 
 * @param     string    newSheet   URL of new stylesheet
 */
function changeSheet(newSheet) {
  if ( newSheet != "" ) {                                 // check that a parameter has been passed
    document.getElementById('docStyle').href = newSheet;  // change href of style element
  }
}

