
// this is the common file for the Freak Fitness Website

 
// check content of form, the full name, e-mail address and
// phone number and url, etc
function register_verified(da_reg_form) {
	
  var form_process = 2;
	
  var register_req_array = new Array();
  register_req_array[0] = da_reg_form.register_name.value;
  register_req_array[1] = da_reg_form.register_area_code.value;
  register_req_array[2] = da_reg_form.register_area_phone.value;
  register_req_array[3] = da_reg_form.register_local_num.value;
  register_req_array[4] = da_reg_form.register_email.value;
  register_req_array[5] = da_reg_form.register_address.value;


  for (i = 0; i < register_req_array.length; i++) {
    if (register_req_array[i] == "") {
      alert('You have not filled in all the required fields, Name, Address, Phone Number, E-Mail, have to be filled, please check and rekey.');
	  document.Freak_registration.register_name.focus();	      
	  return false;
    }
  }
  
  
    // recheck to make sure that the e-mail is correctly formated
  var this_valid_email = checkEMail(da_reg_form.register_email.value, form_process);
  if (!this_valid_email){
    return false;
  }


  // recheck the phone number to see if any error are still there
  var this_valid_area_code = checkPhone(da_reg_form.register_area_code.value, form_process);
  if (!this_valid_area_code) {
	return false;  
  }

  // recheck the phone number to see if any error are still there
  var this_valid_phone = checkPhone(da_reg_form.register_area_phone.value, form_process);
  if (!this_valid_phone) {
	return false;  
  }

  // recheck the phone number to see if any error are still there
  var this_postal_code = checkPostal(da_reg_form.register_postal_code.value, da_reg_form.register_country.value, form_process);
  if (!this_postal_code) {
	return false;  
  }

  // recheck the phone number to see if any error are still there
  var this_valid_phone_local = checkPhoneLocal(da_reg_form.register_local_num.value);
  if (!this_valid_phone_local) {
	return false;  
  }

  // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextData(da_reg_form.register_name.value.toUpperCase());
  if (!this_valid_text_entry) {
	return false;  
  }

  // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextData(da_reg_form.register_address.value.toUpperCase());
  if (!this_valid_text_entry) {
	return false;  
  }
 
 // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextData(da_reg_form.register_city.value.toUpperCase());
  if (!this_valid_text_entry) {
	return false;  
  }
  

}



// check content of form, the full name, e-mail address and
// phone number and url, etc
function search_verified(search_form) {

  // recheck to see that they have not entered specific database commands in some fields
  var this_valid_text_entry = checkTextSearchData(search_form.search_info.value.toUpperCase());
  if (!this_valid_text_entry) {
	return false;  
  }

}




// this function will check the phone number group against a regular Expression
// to see if it is valid.  
function checkPhone(phone_num, form_process) {
  var msg = "That is not a valid 3 number group/area phone number. Please re-type it.";

  // Check to see if the phone number has been entered properly
  var checked_phone = new RegExp("[0-9][0-9][0-9]");


  // checking the phone number against a regular expression
  if (phone_num.match(checked_phone) != null) {
    return true;  
  } else {
    alert(msg);
	
    if (form_process == 2) {
      document.Freak_registration.register_area_code.focus();		
	} else {
      document.Freak_registration.area_code.focus();	
	}
    return false;
  }
}

// this function will check the phone number local against a regular Expression
// to see if it is valid.  
function checkPhoneLocal(phone_num, form_process) {
  var msg = "That is not a valid 4 number local phone number. Please re-type it.";

  // Check to see if the phone number has been entered properly
  var checked_phone_Local = new RegExp("[0-9][0-9][0-9][0-9]");


  // checking the phone number against a regular expression
  if (phone_num.match(checked_phone_Local) != null) {
    return true;  
  } else {
    alert(msg);
	
    if (form_process == 2) {
	  document.Freak_registration.register_local_num.focus();		
	} else {
	  document.Freak_registration.local_phone.focus();
	}
    return false;
  }
}


// this function will check the email information for the @ sign and the 
// period.  Also the @ sign could not be at the start of the email address
// or the period be anywhere near the end of the address.
function checkEMail(email_address, form_process) {
  // set up message variables
  var msg1 = 'You have entered an e-mail address with an improper "@", please rekey.';
  var msg2 = 'You have entered an e-mail address with an improper ".", please rekey.';

  if (email_address != '') {
    // check for the @ sign in the field
    if ((email_address.indexOf('@') == -1)||
        (email_address.charAt(0) == '@')||
	    (email_address.charAt(email_address.length-1) == '@')) {
      alert(msg1);

      if (form_process == 2) {
        document.Freak_registration.register_email.focus();	  
	  } else {
        document.Freak_registration.email.focus();
	  }
      return false;
    }
    // check for the "period" in the second portion of the info
    if ((email_address.indexOf('.') == -1)||
        (email_address.charAt(0) == '.')||
	    (email_address.charAt(email_address.length-1) == '.')||
  	    (email_address.charAt(email_address.length-2) == '.')) {
      alert(msg2);

      if (form_process == 2) {
        document.Freak_registration.register_email.focus();	  
	  } else {
        document.Freak_registration.email.focus();
	  }
      return false;
    }
  }
  return true;	
}




// this function will check the postal code to make sure that they have
// entered the correct sequence of letters and numbers
function checkPostal(postal_Info, country_name, form_process) {
  // set up message variables

  var postal_mess2 = 'You have entered an incorrect postal code, please rekey.';
  var postal_us_mess2 = 'You have entered an incorrect zip code, please rekey.';
  
  var name_Canada = 'Canada';
  var name_incorrect = 'incorrect';


  // set up the regular expression
  var checked_Postal_End = new RegExp("[A-Z][0-9][A-Z] [0-9][A-Z][0-9]");
  
  var check_us_Zip = new RegExp("[0-9][0-9][0-9][0-9][0-9]");

  postal_Info = postal_Info.toUpperCase();
  
  if (country_name.match(name_Canada) != null) {

//alert ('just into canadian check postal function.');

      // checking the start postal against a regular expression
    if (postal_Info.match(checked_Postal_End) != null) {
	  return true;  
    } else {
      alert(postal_mess2);

// called from either the members_registration form, or the Freak_registration pages, 2 is members_registration
      if (form_process == 2) {
        document.Freak_registration.register_postal_code.focus();
	  } else {
        document.Freak_registration.postal_code.focus();	
	  }
	
      return false;
	} 

  } else {

//alert ('just into US check postal function.');

    if (postal_Info.match(check_us_Zip) != null) {
//alert ('just into true check of zip code');
	  return true;
	} else {
//alert ('just into false check of zip code');
      alert(postal_us_mess2);

// called from either the members_registration form, or the Freak_registration pages, 2 is members_registration
      if (form_process == 2) {
        document.Freak_registration.register_postal_code.focus();
	  } else {
        document.Freak_registration.postal_code.focus();	
	  }	  
	  return false;
	}
  }

}



// change the information to uppercase for the postal code
function changeCase(upper_Postal) {
    upper_Postal = upper_Postal.toUpperCase();
	return upper_Postal;
}


// check to make sure that the data entered in some text fields does not contain
// any commands that can be used against databases in mysql
function checkTextData(sText) {

  var msg1 = 'You may not use certain command words such as SELECT in these fields, please re-key.';   
  var msg2 = 'You may not use certain command words such as DROP in these fields, please re-key.'; 
  var msg3 = 'You may not use certain command words such as DELETE in these fields, please re-key.'; 
  var msg4 = 'You may not use certain command words such as INSERT in these fields, please re-key.'; 
  var msg5 = 'You may not use certain command words such as LOAD DATA in these fields, please re-key.'; 
  var msg6 = 'You may not use certain command words such as REPLACE in these fields, please re-key.'; 
  var msg7 = 'You may not use certain command words such as UPDATE in these fields, please re-key.'; 
  var msg8 = 'You may not use certain command words such as SHOW in these fields, please re-key.'; 
  var msg9 = 'You may not use certain command words such as DESCRIBE in these fields, please re-key.'; 
  var msg10 = 'You may not use certain command words such as EXPLAIN in these fields, please re-key.'; 
  var msg11 = 'You may not use certain command words such as CHECK in these fields, please re-key.'; 
  var msg12 = 'You may not use certain command words such as ANALYZE in these fields, please re-key.'; 
  var msg13 = 'You may not use certain command words such as REPAIR in these fields, please re-key.';
  var msg14 = 'You may not use certain command words such as OPTIMIZE in these fields, please re-key.';  

  var select_text = new RegExp("SELECT");
  var drop_text = new RegExp("DROP");
  var delete_text = new RegExp("DELETE");
  var insert_text = new RegExp("INSERT");
  var load_text = new RegExp("LOAD DATA");
  var replace_text = new RegExp("REPLACE");
  var update_text = new RegExp("UPDATE");
  var show_text = new RegExp("SHOW");
  var describe_text = new RegExp("DESCRIBE");
  var explain_text = new RegExp("EXPLAIN");
  var check_text = new RegExp("CHECK");
  var analyze_text = new RegExp("ANALYZE");
  var repair_text = new RegExp("REPAIR");
  var optimize_text = new RegExp("OPTIMIZE");


// check to make sure that there is data in the field
  if (sText != '') {

    if (select_text.test(sText)) {
        alert(msg1);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (drop_text.test(sText)) {
        alert(msg2);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (delete_text.test(sText)) {
        alert(msg3);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (insert_text.test(sText)) {
        alert(msg4);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (load_text.test(sText)) {
        alert(msg5);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (replace_text.test(sText)) {
        alert(msg6);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (update_text.test(sText)) {
        alert(msg7);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (show_text.test(sText)) {
        alert(msg8);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (describe_text.test(sText)) {
        alert(msg9);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (explain_text.test(sText)) {
        alert(msg10);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (check_text.test(sText)) {
        alert(msg11);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (analyze_text.test(sText)) {
        alert(msg12);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (repair_text.test(sText)) {
        alert(msg13);
        document.Freak_registration.register_name.focus();
        return false;
	}
    if (optimize_text.test(sText)) {
        alert(msg14);
        document.Freak_registration.register_name.focus();
        return false;
	}

  }
  return true;

  
}

// check to make sure that the data entered in some text fields does not contain
// any commands that can be used against databases in mysql
function checkTextSearchData(sText) {

  var msg1 = 'You may not use certain command words such as SELECT in these fields, please re-key.';   
  var msg2 = 'You may not use certain command words such as DROP in these fields, please re-key.'; 
  var msg3 = 'You may not use certain command words such as DELETE in these fields, please re-key.'; 
  var msg4 = 'You may not use certain command words such as INSERT in these fields, please re-key.'; 
  var msg5 = 'You may not use certain command words such as LOAD DATA in these fields, please re-key.'; 
  var msg6 = 'You may not use certain command words such as REPLACE in these fields, please re-key.'; 
  var msg7 = 'You may not use certain command words such as UPDATE in these fields, please re-key.'; 
  var msg8 = 'You may not use certain command words such as SHOW in these fields, please re-key.'; 
  var msg9 = 'You may not use certain command words such as DESCRIBE in these fields, please re-key.'; 
  var msg10 = 'You may not use certain command words such as EXPLAIN in these fields, please re-key.'; 
  var msg11 = 'You may not use certain command words such as CHECK in these fields, please re-key.'; 
  var msg12 = 'You may not use certain command words such as ANALYZE in these fields, please re-key.'; 
  var msg13 = 'You may not use certain command words such as REPAIR in these fields, please re-key.';
  var msg14 = 'You may not use certain command words such as OPTIMIZE in these fields, please re-key.';  

  var select_text = new RegExp("SELECT");
  var drop_text = new RegExp("DROP");
  var delete_text = new RegExp("DELETE");
  var insert_text = new RegExp("INSERT");
  var load_text = new RegExp("LOAD DATA");
  var replace_text = new RegExp("REPLACE");
  var update_text = new RegExp("UPDATE");
  var show_text = new RegExp("SHOW");
  var describe_text = new RegExp("DESCRIBE");
  var explain_text = new RegExp("EXPLAIN");
  var check_text = new RegExp("CHECK");
  var analyze_text = new RegExp("ANALYZE");
  var repair_text = new RegExp("REPAIR");
  var optimize_text = new RegExp("OPTIMIZE");


// check to make sure that there is data in the field
  if (sText != '') {

    if (select_text.test(sText)) {
        alert(msg1);
        document.search_site.search_info.focus();
        return false;
	}
    if (drop_text.test(sText)) {
        alert(msg2);
        document.search_site.search_info.focus();
        return false;
	}
    if (delete_text.test(sText)) {
        alert(msg3);
        document.search_site.search_info.focus();
        return false;
	}
    if (insert_text.test(sText)) {
        alert(msg4);
        document.search_site.search_info.focus();
        return false;
	}
    if (load_text.test(sText)) {
        alert(msg5);
        document.search_site.search_info.focus();
        return false;
	}
    if (replace_text.test(sText)) {
        alert(msg6);
        document.search_site.search_info.focus();
        return false;
	}
    if (update_text.test(sText)) {
        alert(msg7);
        document.search_site.search_info.focus();
        return false;
	}
    if (show_text.test(sText)) {
        alert(msg8);
        document.search_site.search_info.focus();
        return false;
	}
    if (describe_text.test(sText)) {
        alert(msg9);
        document.search_site.search_info.focus();
        return false;
	}
    if (explain_text.test(sText)) {
        alert(msg10);
        document.search_site.search_info.focus();
        return false;
	}
    if (check_text.test(sText)) {
        alert(msg11);
        document.search_site.search_info.focus();
        return false;
	}
    if (analyze_text.test(sText)) {
        alert(msg12);
        document.search_site.search_info.focus();
        return false;
	}
    if (repair_text.test(sText)) {
        alert(msg13);
        document.search_site.search_info.focus();
        return false;
	}
    if (optimize_text.test(sText)) {
        alert(msg14);
        document.search_site.search_info.focus();
        return false;
	}

  }
  return true;
  
}

// build a footer so that I only have to update this to make the footer the same on all pages
function create_footer() {

    var current_date = new Date().getFullYear();

    document.write('<p>Web site design and integration by <a href="http://www.swj.cc" target="_blank">SWJ Strategic Marketing &amp; Advertising</a><br />Copyright '+current_date+'. All rights reserved.</p>');
}