function radioCheck(ss) {
  for(var i = 0; i < ss.length; i++) {
	  if(ss[i].checked) { return ss[i].value; }
	  }
  return false;
}

function checkbox_empty(ss) {
  if (ss.attr('checked')){
  	return false;
  }
  return true;
}

function dropdown_empty(ss){
// Note: ss will need to be fetched via document.getElementById('ss-id-name') for multi-select menus
  for(var i = 0; i < ss.length; i++) {
    if(ss[i].selected) {
      if(ss[i].value.length) { return false; }
    }
  }
  return true;
}

function stripChars(pstrSource){ 
  var m_strOut = new String(pstrSource); 
		// Non-alpha characters
  //m_strOut = m_strOut.replace(/[^0-9]/g, '');
		
		// remove spaces, ( ), -, and .
		m_strOut = m_strOut.replace(/[\-|(|)|\.| ]/g, ''); 

  return m_strOut; 
}
	
function disableForm(formID){
  var element = document.getElementById(formID);
  element.style.display = "none;";
}

// ----------- validation functions ------------------------------------------

function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
 
  //check to see if in correct format
  if(!objRegExp.test(strValue)){
    return false; //doesn't match pattern, bad date
	}
  else{
    var strSeparator = strValue.substring(2,3);
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31};
    var intDay = parseInt(arrayDate[1],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] !== null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay !== 0){
        return true; //found in lookup table, good date
			}
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 === 0) && (intYear % 100 !== 0) || 
             (intYear % 400 === 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}	

function  validateNumeric( strValue ) {
/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
  True if valid, otherwise false.
******************************************************************/
var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

	
function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
//var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
var objRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function validateUSPhone( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern.
  Ex. (999) 999-9999 or (999)999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

  //check for valid us phone with or without space between
  //area code
  return objRegExp.test(strValue);
}

function validateZip( strValue ) {
/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format or zip+4
  format. 99999 or 99999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

// function to see if date 1 occurs before date 2
function validFromDate(fromDate,toDate){

	// Assuming that the date was in the correct format, this is our separator
 var separator1 = fromDate.charAt(2);
	var arrDate1 = fromDate.split(separator1);

	var checkFromDate = new Date();
	checkFromDate.setFullYear(arrDate1[2],arrDate1[0]-1,arrDate1[1]);
	
 var separator2 = toDate.charAt(2);
	var arrDate2 = toDate.split(separator2);
	
	var checkToDate = new Date();
	checkToDate.setFullYear(arrDate2[2],arrDate2[0]-1,arrDate2[1]);
	
	if (checkToDate > checkFromDate){
	  return true;
	}
	else {
	  return false;
	}
}

function check_my_account(password_length){
	error = false;
	var error_msg = "";
	
	// required fields
	var first_name = document.my_account.first_name.value;
	var last_name = document.my_account.last_name.value;
	var phone = document.my_account.phone.value;
	var company_name = document.my_account.company_name.value;
	var country = document.my_account.country;
	
	// only required if user is changing password
	var reset_pw = document.my_account.password.value;
	var confirm_pw = document.my_account.confirm_pw.value;

	if(first_name === "" || last_name === "" || company_name === ""){ 
		error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
		error = true;
	}
	
	phone = stripChars(phone);
	if ((phone.length < 10)||(!validateNumeric(phone))){
		error_msg = error_msg + "<li>Please enter a valid numerical <b>Phone Number</b>.</li>";
		error = true;
	}
	
	if (reset_pw !== ""){
		if (reset_pw.length < password_length){
			error_msg = error_msg + "<li><b>Reset Password</b> needs to be <b>"+password_length+" characters or greater</b>.</li>";
			error = true;
		}
		else if (confirm_pw === ""){
			error_msg = error_msg + "<li>Please <b>Confirm your New Password</b>.</li>";
			error = true;
		}
		else if(reset_pw !== confirm_pw){
			error_msg = error_msg + "<li><b>Reset Password</b> and <b>Confirm Password</b> do not match.</li>";
			error = true;
		}
	}
	
	if (dropdown_empty(country)){
		error_msg = error_msg + "<li>Please select your <b>Country</b>.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_registration(password_length){
	error = false;
	var error_msg = "";
	
	// required fields
	var first_name = document.registration.first_name.value;
	var last_name = document.registration.last_name.value;
	var email = document.registration.email.value;
	var phone = document.registration.phone.value;
	var password = document.registration.password.value;
	var confirm_pw = document.registration.confirm_pw.value;
	var company_name = document.registration.company_name.value;
	var country = document.registration.country;
	var security_code = document.registration.security_code.value;
	var agreement = $('#agreement');

	if(first_name === "" || last_name === "" || company_name === ""){ 
		error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
		error = true;
	}
	
	if ((email === "")||(!validateEmail(email))){
		error_msg = error_msg + "<li>Please enter a valid <b>Email Address</b>.</li>";
		error = true;
	}
	
	phone = stripChars(phone);
	if ((phone.length < 10)||(!validateNumeric(phone))){
		error_msg = error_msg + "<li>Please enter a valid numerical <b>Phone Number</b>.</li>";
		error = true;
	}
	
	if ((password === "")||(password.length < password_length)){
		error_msg = error_msg + "<li><b>Password</b> needs to be <b>"+password_length+" characters or greater</b>.</li>";
		error = true;
	}
	
	if (confirm_pw === ""){
		error_msg = error_msg + "<li>Please <b>Confirm your Password</b>.</li>";
		error = true;
	}
	else if(password !== confirm_pw){
		error_msg = error_msg + "<li><b>Password</b> and <b>Confirm Password</b> do not match.</li>";
		error = true;
	}
	
	if (dropdown_empty(country)){
		error_msg = error_msg + "<li>Please select your <b>Country</b>.</li>";
		error = true;
	}
	
	if (security_code === ""){
		error_msg = error_msg + "<li>Please enter the <b>Security Code</b> you see in the image below.</li>";
		error = true;
	}
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_sample_request(){
	error = false;
	var error_msg = "";
	
	// required fields
	var selected_product_id = $('#selected-product').val();
	var product_ids = $('#products-multiple'); // multi-select enabled drop-down
	
	if (!selected_product_id){
		if(!product_ids.val()){
			error_msg = error_msg + "<li>Please select a <b>Product</b>.</li>";
			error = true;
		}
	}
	
	// optional shipping address validation
	var attention_to = document.sample_request.attention_to.value;
	var email = document.sample_request.email.value;
	var company = document.sample_request.company.value;
	var phone = document.sample_request.phone.value;
	var address1 = document.sample_request.address1.value;
	var city = document.sample_request.city.value;
	var state = document.sample_request.state.value;
	var zip = document.sample_request.zip.value;
	var country_name = document.sample_request.country_name;
	
	if (attention_to !== "" || email !== "" || company !== "" || phone !== "" || address1 !== "" || city !== "" || state !== "" || zip !== "" || (!dropdown_empty(country_name))){
		if (attention_to === ""){
			error_msg = error_msg + "<li>Please name the shipping contact for receiving the sample in <b>Attention To</b>.</li>";
			error = true;
		}
		if ((email === "")||(!validateEmail(email))){
			error_msg = error_msg + "<li>Please enter a valid <b>Email</b> Address for your shipping contact.</li>";
			error = true;
		}
		if (company === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>Company</b>.</li>";
			error = true;
		}
		phone = stripChars(phone);
		if ((phone.length < 10)||(!validateNumeric(phone))){
			error_msg = error_msg + "<li>Please enter a valid numerical shipping <b>Phone Number</b>.</li>";
			error = true;
		}
		if (address1 === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>Address</b>.</li>";
			error = true;
		}
		if (city === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>City</b>.</li>";
			error = true;
		}
		if (zip === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>Zip or Postal Code</b>.</li>";
			error = true;
		}
		if (dropdown_empty(country_name)){
			error_msg = error_msg + "<li>Please choose your shipping <b>Country</b>.</li>";
			error = true;
		}
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_sample_request_step2(){
	error = false;
	var error_msg = "";
	
	// required fields
	var sample_sizes = $('.textfields'); // multi-select enabled drop-down
	var agreement = $('#agreement');
	
	//alert($(sample_sizes[0]).val());
	
	var sample_sizes_empty = 1;
  for(var i = 0; i < sample_sizes.length; i++) {
		if($(sample_sizes[i]).val() !== "") { 
			sample_sizes_empty = 0; 
			if (!validateNumeric($(sample_sizes[i]).val())){
				error_msg = error_msg + "<li>Please enter only numerical values for <b>Sample Size Quantity</b>.</li>";
		  	error = true;
			}
		}
	}
  
	if (sample_sizes_empty == 1){
		error_msg = error_msg + "<li>You must specify the quantities you wish to obtain for your <b>Sample Sizes</b>.</li>";
		error = true;
	}
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_request_a_quote(){
	error = false;
	var error_msg = "";
	
	// required fields
	var selected_product_id = $('#selected-product').val();
	var product_id = document.request_a_quote.product_id;
	var packaging_option = document.request_a_quote.packaging_option;
	//var budget_estimate = document.request_a_quote.budget_estimate.value;
	var annual_usage = document.request_a_quote.annual_usage.value;
	var order_quantity = document.request_a_quote.order_quantity.value;
	var manufacturer_or_distributor = document.request_a_quote.manufacturer_or_distributor;
	var agreement = $('#agreement');
	
	if (selected_product_id === ""){
		if(dropdown_empty(product_id)){
			error_msg = error_msg + "<li>Please select a <b>Product</b>.</li>";
			error = true;
		}
	}

	if(dropdown_empty(packaging_option) || ((packaging_option[0].selected) && (packaging_option[0].value === "0"))){
		error_msg = error_msg + "<li>Please select a <b>Packaging Option</b>.</li>";
		error = true;
	}
	
	/*
	if(budget_estimate === ""){ 
		error_msg = error_msg + "<li>Please provide your <b>Budget Estimate</b>.</li>";
		error = true;
	}
	*/
	
	if(annual_usage === ""){ 
		error_msg = error_msg + "<li>Please provide your <b>Estimated Annual Usage</b>.</li>";
		error = true;
	}
	
	if(order_quantity === ""){ 
		error_msg = error_msg + "<li>Please provide your <b>Quantity Per Order</b>.</li>";
		error = true;
	}
	
	// optional shipping address validation
	var address1 = document.request_a_quote.address1.value;
	var city = document.request_a_quote.city.value;
	var zip = document.request_a_quote.zip.value;
	var country_name = document.request_a_quote.country_name;
	
	if (address1 !== "" || city !== "" || zip !== "" || (!dropdown_empty(country_name))){
		if (address1 === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>Address</b>.</li>";
			error = true;
		}
		if (city === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>City</b>.</li>";
			error = true;
		}
		if (zip === ""){
			error_msg = error_msg + "<li>Please enter your shipping <b>Zip or Postal Code</b>.</li>";
			error = true;
		}
		if (dropdown_empty(country_name)){
			error_msg = error_msg + "<li>Please enter your shipping <b>Country</b>.</li>";
			error = true;
		}
	}
	
	if(!radioCheck(manufacturer_or_distributor)){ 
		error_msg = error_msg + "<li>Please tell us if you are a <b>Manufacturer or Distributor</b>.</li>";
		error = true;
	}
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_contact_us(user_loggedin){
	error = false;
	var error_msg = "";
	
	// required fields
	var subject = document.contact_us.subject;
	var comments = document.contact_us.comments.value;
	var agreement = $('#agreement');

	if (user_loggedin !== "1"){
		var first_name = document.contact_us.first_name.value;
		var last_name = document.contact_us.last_name.value;
		var email = document.contact_us.email.value;
		var phone = document.contact_us.phone.value;
		var company = document.contact_us.company.value;
		
		if(first_name === "" || last_name === "" || company === ""){ 
			error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
			error = true;
		}

		if ((email === "")||(!validateEmail(email))){
			error_msg = error_msg + "<li>Please enter a valid <b>Email Address</b>.</li>";
			error = true;
		}
	
		phone = stripChars(phone);
		if ((phone.length < 10)||(!validateNumeric(phone))){
			error_msg = error_msg + "<li>Please enter a valid numerical <b>Phone Number</b>.</li>";
			error = true;
		}
	}
	
	if (dropdown_empty(subject)){
		error_msg = error_msg + "<li>Please select a <b>Subject</b>.</li>";
		error = true;
	}
	
	if (comments === ""){
		error_msg = error_msg + "<li>Please include your <b>Comments</b>.</li>";
		error = true;
	}
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_mailing_list(user_loggedin){
	error = false;
	var error_msg = "";
	
	// required fields
	if (user_loggedin !== "1"){
		var first_name = document.mailing_list.first_name.value;
		var last_name = document.mailing_list.last_name.value;
		var email = document.mailing_list.email.value;
		var company_name = document.mailing_list.company_name.value;

		if(first_name === "" || last_name === "" || company_name === ""){ 
			error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
			error = true;
		}

		if ((email === "")||(!validateEmail(email))){
			error_msg = error_msg + "<li>Please enter a valid <b>Email Address</b>.</li>";
			error = true;
		}
	}
	var agreement = $('#agreement');
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_request_more_info(user_loggedin){
	error = false;
	var error_msg = "";
	
	// required fields
	if (user_loggedin !== "1"){
		var first_name = document.request_more_info.first_name.value;
		var last_name = document.request_more_info.last_name.value;
		var email = document.request_more_info.email.value;
		var company_name = document.request_more_info.company_name.value;
		
		if (first_name === "" | last_name === "" | company_name === ""){
			error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
			error = true;
		}
		if ((email === "")||(!validateEmail(email))){
			error_msg = error_msg + "<li>Please enter a valid Email Address for <b>Email</b>.</li>";
			error = true;
		}
	}
	var agreement = $('#agreement');
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_email_a_friend(user_loggedin){
	error = false;
	var error_msg = "";
	
	// required fields
	if (user_loggedin !== "1"){
		var name = document.email_a_friend.name.value;
		var email = document.email_a_friend.email.value;
	}
	var friend_email = document.email_a_friend.friend_email.value;
	var comments = document.email_a_friend.comments.value;
	var agreement = $('#agreement');
	
	if (user_loggedin !== "1"){
		if (name === ""){
			error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
			error = true;
		}
		if ((email === "")||(!validateEmail(email))){
			error_msg = error_msg + "<li>Please enter a valid Email Address for <b>Your email</b>.</li>";
			error = true;
		}
	}
	
	if ((friend_email === "")||(!validateEmail(friend_email))){
		error_msg = error_msg + "<li>Please enter a valid Email Address for <b>Your friend's email</b>.</li>";
		error = true;
	}
	
	if(comments === ""){ 
		error_msg = error_msg + "<li>Please include a brief message or <b>Comment</b> to your friend.</li>";
		error = true;
	}
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_forgotten_password(){
	error = false;
	var error_msg = "";
	
	// required fields
	var email = document.forgotten_password.email.value;
	var request_option = document.forgotten_password.request_option;
	
	if ((email === "")||(!validateEmail(email))){
		error_msg = error_msg + "<li>Please enter a valid <b>Email</b> Address you used to register with us.</li>";
		error = true;
	}
	
	if(!radioCheck(request_option)){ 
		error_msg = error_msg + "<li>Please choose the type of <b>Your Request</b>.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_login(password_length){
	error = false;
	var error_msg = "";
	
	// required fields
	var username = document.login.username.value;
	var password = document.login.password.value;
	//var agreement = $('#agreement');

	if ((username === "")||(!validateEmail(username))){
		error_msg = error_msg + "<li>Please enter a valid <b>Username</b>.</li>";
		error = true;
	}
	
	if ((password === "")||(password.length < password_length)){
		error_msg = error_msg + "<li><b>Password</b> needs to be <b>"+password_length+" characters or greater</b>.</li>";
		error = true;
	}
	
	/*
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}
	*/

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}

function check_career_application(){
  error = false;
  var error_msg = "<ul>";
  
  //required fields
  var FirstName = document.careers.FirstName.value;
  var LastName = document.careers.LastName.value;
  var Email = document.careers.Email.value;
  var Phone = document.careers.Phone.value;
  var FileResume = document.careers.Resume.value;
  var TextResume = document.careers.TextResume.value;
  var CAPTCHA = document.careers.Captcha.value;
  var agreement = $('#agreement');
  
  if(!FirstName){
    error_msg = error_msg + "<li><b>First Name</b> is required.</li>";
    error = true;
  }
  
  if(!LastName){
    error_msg = error_msg + "<li><b>Last Name</b> is required.</li>";
    error = true;
  }
  
  if(!Email){
    error_msg = error_msg + "<li><b>Email</b> is required.</li>";
    error = true;
  } else {
    if(!validateEmail(Email)){
      error_msg = error_msg + "<li>Please check your <b>Email</b> address.</li>";
      error = true;
    }
  }
  
  if(!Phone){
    error_msg = error_msg + "<li><b>Phone</b> number is required.</li>";
    error = true;
  } else {
    if(!validateNumeric(stripChars(Phone))){
      error_msg = error_msg + "<li>Please check your <b>Phone</b> number.</li>";
      error = true;
    }
  }
  
  if(!TextResume){
    if(!FileResume){
      error_msg = error_msg + "<li>A <b>Resume</b> must either be uploaded or pasted.</li>";
      error = true;
    }
  }
  
  if(!CAPTCHA){
    error_msg = error_msg + "<li>Please enter the <b>CAPTCHA</b> value.</li>";
    error = true;
  }
  
  if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}
  
  error_msg = error_msg + "</ul>";
  
  if(!error){
    jQuery("#form_errors").hide("fast");
    return true;
  } else {
    jQuery("#form_errors").show("slow");
    jQuery("#form_error_msg").html(error_msg);
    return false;
  }
}

function check_cal_rise(user_loggedin){
	error = false;
	var error_msg = "";
	
	// required fields
	var agreement = $('#agreement');

	if (user_loggedin !== "1"){
		var first_name = document.cal_rise_questionnaire.first_name.value;
		var last_name = document.cal_rise_questionnaire.last_name.value;
		var email = document.cal_rise_questionnaire.email.value;
		var phone = document.cal_rise_questionnaire.phone.value;
		var company = document.cal_rise_questionnaire.company.value;
		
		if(first_name === "" || last_name === "" || company === ""){ 
			error_msg = error_msg + "<li>Please make sure all required fields are filled in.</li>";
			error = true;
		}

		if ((email === "")||(!validateEmail(email))){
			error_msg = error_msg + "<li>Please enter a valid <b>Email Address</b>.</li>";
			error = true;
		}
	
		phone = stripChars(phone);
		if ((phone.length < 10)||(!validateNumeric(phone))){
			error_msg = error_msg + "<li>Please enter a valid numerical <b>Phone Number</b>.</li>";
			error = true;
		}
	}
	
	if (checkbox_empty(agreement)){
		error_msg = error_msg + "<li>You must agree to our <b>Terms of Service</b> and <b>Privacy Policy</b> before submitting.</li>";
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,70);
		return false;
	}
}