<!-- Begin
/*
##############################################################################
# PLEASE DO NOT REMOVE THIS HEADER!!!
#
# COPYRIGHT NOTICE
#
# Shopping Cart v1.0 Written specifically for Strike it heathly
# Copyright 2007-2008 George L. Smith III (c) All rights reserved.
# Created 09/22/2007   Last Modified 09/23/2007
# 
##############################################################################
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
##############################################################################
* A common message given if there is a problem with creating a cookie. 
* The ability to create a session cookie is tested in each method below
*/
var cookie_alert = "Cookies must be enabled to utilize this shopping cart, refer to your browsers help tab for more information.";
var add_alert = "The Additional Bonus Guidebook can only be purchased if you purchase the above package.";
var removed = " was removed from your cart.";
var added   = " was added to your cart.";

/* 
 * 
 * Each of these functions are grouped by the page that it was used for
 * are indicated by the comments, and are in order of appearance.
 * all 'common' functions are listed below that
 * 
 */
 
/*
 *
 * functions for ProductsServices.htm
 * This checks the number entered by the returning customer
 * and indicates which package they previously purchased,
 * and redirects them to other pages.
 * 
 */
function checkNumber(){
	var securityNum = document.getElementById("cust");
	if( securityNum.value == "4561"){
		location.replace("ProductsServicesSIHReturnAdult.htm");
		alert( "Welcome back, You will be redirected to a different page");
	}
	if( securityNum.value == "4562"){
		location.replace("ProductsServicesSIHReturnKids.htm");
		alert( "Welcome back, You will be redirected to a different page");
	}
}
/*
 *	functions for 
 *	ProductsServicesSIHAdult.htm
 */

var adult_flag = null; 
 
function addAdult(){
	if( testCookie() ){
		writeCookie( 'adult', 'TRUE' );
		adult_flag = 'true';
		alert( "SIH Adult package"+added );
	} else alert( cookie_alert );
}


function addAdultBonus(){
	if( adult_flag != 'true' ) alert( add_alert );
	else{
		if (testCookie()) {
			writeCookie( 'adult_bonus', 'TRUE' );
			alert( "SIH Adult Bonus Guidebook"+added );
		} else alert (cookie_alert); 
	}
}


/** 
 * functions for ProductsServicesSIHKids.htm
 * 
 * 
 */

var fa_flag     = null;
var fb_flag     = null;
var age         = null;
var family_flag = null;


function loadAge( iage ){
	age = iage;
}

function addFamily(){
	if (testCookie()) {
		writeCookie ('family', age );
		if( age == "A" ){
			alert( "SIH Family package - ages 9-13 was added to your cart" );
		}
		else{
			alert( "SIH Family package - ages 14-18 was added to your cart" );
		}
		family_flag = 'true';
	} else alert (cookie_alert); 
}
function removeFamilyBA(){
	if(testCookie()){
		writeCookie( 'familyAQty',0 );
		alert( 'Item was removed from your cart' );
	}
	else alert( cookie_alert);
}
function removeFamilyBB(){
	if(testCookie()){
		writeCookie( 'familyBQty',0 );
		alert( 'Item was removed from your cart' );
	}
	else alert( cookie_alert);
}

function setFamilyA(qty){
	if (testCookie()) {
		writeCookie( 'familyAQty', qty );
		fa_flag = 'true';
	} else alert (cookie_alert); 
}

function setFamilyB(qty){
	if (testCookie()) {
		writeCookie( 'familyBQty', qty );
		fb_flag = 'true';
	} else alert (cookie_alert); 
}

function AddKidsAdult(){
	if(testCookie()){
		writeCookie( 'kids_adult', 'TRUE' );
		alert( 'Adult Guidebook was added to your cart' );
	} else alert( cookie_alert);
}
function removeAdultKid(){
	if(testCookie()){
		writeCookie( 'kids_adult', 'FALSE' );
		alert( 'Adult Guidebook was removed from your cart' );
	} else alert( cookie_alert );
}
	
var $BonusA = null;
var $BonusB = null;
var $AdultNUT = null;

function setAdultNut( qty ){
	if( qty >= 0 && qty <=2 ){
		AdultNUT = qty;
	}
	else alert( 'Invalid Quantity\n0-2 are the only valid quantities' );
}
function changeAdultNut(){
	if( AdultNUT != null ){
		if (testCookie()) {
			writeCookie( 'returnAQty', AdultNUT );
		} else alert (cookie_alert); 
	}
}

function changeFamilyA(){
	if( BonusA != null ){
		if (testCookie()) {
			writeCookie( 'familyAQty', BonusA );
			sihfa_flag = 'true';
		} else alert (cookie_alert); 
	}
}

function changeFamilyB(){
	if( BonusB != null ){
		if (testCookie()) {
			writeCookie( 'familyBQty', BonusB );
			sihfa_flag = 'true';
		} else alert (cookie_alert); 
	}
}

var KANut = null;
var KBNut = null;

function setKANut( qty ){
	if( qty >= 0 && qty <= 3 ){
		KANut = qty;
	}
	else alert( 'Invalid Quantity\n0-3 are the only valid quantities' );
}

function setKBNut( qty ){
	if( qty >= 0 && qty <= 3 ){
		KBNut = qty;
	}
	else alert( 'Invalid Quantity\n0-3 are the only valid quantities' );
}

function changeKAReturn(){
	if( KANut != null ){
		if (testCookie()) {
			writeCookie( 'returnKAQty', KANut );
			sihfa_flag = 'true';
		} else alert (cookie_alert); 
	}
}

function changeKBReturn(){
	if( KBNut != null ){
		if (testCookie()) {
			writeCookie( 'returnKBQty', KBNut );
			sihfa_flag = 'true';
		} else alert (cookie_alert); 
	}
}

function setBonusA( qty ){
	if( qty >= 0 && qty <= 3 ){
		BonusA = qty;
	}
	else alert( 'Invalid Quantity\n0-3 are the only valid quantities' );
}

function setBonusB( qty ){
	if( qty >= 0 && qty <= 3 ){
		BonusB = qty;
	}
	else alert( 'Invalid Quantity\n0-3 are the only valid quantities' );
}

function testFamilyQtyA(){
	$test_value = getCookieValue( 'familyAQty' );
	if( $test_value == 'null' )return false;
	else if( $test_value == '0' )return false;
	else return true;
}

function testFamilyQtyB(){
	$test_value = getCookieValue( 'SIHFBQty' );
	if( $test_value == 'null' )return false;
	else if( $test_value == '0' )return false;
	else return true;
}

function addFamilyBonus(){
	if( testCookie() ){
		if( family_flag == 'false' )alert( add_alert );
		// determine if a value was chosen for either the A or B bonus packages.
		else if( !testFamilyQtyA() && !testFamilyQtyB() )alert( 'No values were chosen' );
		else{
			writeCookie( 'family_bonus', 'TRUE' );
			alert( "SIH Family Bonus Guidebook"+added );
		}
	} else alert(cookie_alert);
}

/**
 * Functions for ProductsServicesSIHReturnAdult.htm
 */

var ra_flag = false;

function setReturnAdult( qty ){
	if (testCookie()) {
		writeCookie( 'returnAQty', qty );
		ra_flag = 'true';
	} else alert (cookie_alert); 
}


function removeAdultReturn(){
	if( testCookie() ){
		writeCookie( 'returnA', 'FALSE' );
		alert( "SIH Adult Nutrition Guidebook was removed from your cart" );
	}
	else alert(cookie_alert);
}

function addReturnAdult(){
	if( testCookie() ){
		if( ra_flag != 'true' ){
			alert( "No Quantity was entered." );
			document.getElementById( "adult").focus();
		}
		// determine if a value was chosen for either the A or B bonus packages.
		else{
			writeCookie( 'returnA', 'TRUE' );
			alert( "SIH Adult Nutrition Guidebook"+added );
		}
	} else alert(cookie_alert);
}

/**
 * Functions for ProductsServicesSIHReturnKids.htm
 */

var rk_flag = false;

function setReturnKidsA( qty ){
	if (testCookie()) {
		writeCookie( 'returnKAQty', qty );
		rk_flag = 'true';
	} else alert (cookie_alert); 
}

function setReturnKidsB( qty ){
	if (testCookie()) {
		writeCookie( 'returnKBQty', qty );
		rk_flag = 'true';
	} else alert (cookie_alert); 
}

function removeKAReturn(){
	if( testCookie() ){
		writeCookie( 'returnKAQty', 0 );
		alert( 'Item was removed from your cart' );
	}
	else alert(cookie_alert);
}

function removeKBReturn(){
	if( testCookie() ){
		writeCookie( 'returnKBQty', 0 );
		alert( 'Item was removed from your cart' );
	}
	else alert(cookie_alert);
}
	
function addReturnKids(){
	if( testCookie() ){
		if( rk_flag != 'true' ){
			alert( "No Quantity was entered." );
			document.getElementById( "adult").focus();
		}
		// determine if a value was chosen for either the A or B bonus packages.
		else{
			writeCookie( 'returnK', 'TRUE' );
			alert( "SIH Kids & Young Adults Nutrition Guidebook(s) were added to your cart" );
		}
	} else alert(cookie_alert);
}

/**
 * ShoppingCart.php specific functions.
 */

function removeAdult(){ 
	if (testCookie()){
		writeCookie( 'adult', 'FALSE' );
		adult_flag = 'false';
		alert( "SIH Adult package"+removed );
	} else alert (cookie_alert); 
}

function removeAdultBonus(){
	if (testCookie()){
		writeCookie( 'adult_bonus', 'FALSE' );
		alert( "SIH Adult Bonus Guidebook"+removed );
	} else alert (cookie_alert); 
}

function removeFamily(){
  if (testCookie()) {
    writeCookie ('family', 'FALSE' );
    alert( "SIH Family package was removed from your cart" );
  } else alert (cookie_alert); 
}



/*
 * Function to create a cookie representing the 
 * number of SIH Family Bonus Booklets and Pamphlets
 * chosen by the customer. 
 * 
 * This function is specifically for the 14-18 age
 * group.
 * 
 * This function actually creates a non-persistant
 * cookie that holds the number of additional 
 * bonus packages selected by the customer.
 * 
 * Cookie Name: SIHFBQty
 * 
 * Parameters:
 * 		qty: the number of bonus packages chosen.
 */
function changeSIHFamilyB(){
	if( BonusB != null ){
		if (testCookie()) {
			writeCookie( 'SIHFBQty', BonusB );
			sihfb_flag = 'true';
		} else alert (cookie_alert); 
	}
}
function setBonusB( qty ){
	if( qty >= 0 && qty <= 3 ){
		BonusB = qty;
	}
	else alert( 'Invalid Quantity\n0-3 are the only valid quantities' );
}
/*
 *	Function to Add StrikeItHealthy Family Bonus Booklet and
 *	Pamphlets to the Shopping cart.
 *	
 *	This function actually writes a non-persistant cookie to the
 *	users computer.
 *	
 *	The cookie is named SIHFamilyBonus and will contain either 
 *	 TRUE or FALSE
 *	
 *	This function makes the content of the SIHAdultBonus Cookie
 *		either A or B
 *	
 *	Parameters:
 *		age:
 *			A = ages 9-13
 *			B = ages 14-18
 *			
 *	Return value:
 *		if successful an alert will display the success
 *		if failure an alert will notify the user.
 */


/*
 * Function tests the value of the SIH bonus quantity for ages
 * 9-13.
 * Parameters:
 * 	none
 * Returns:
 *   False if the contents of the cookie are null/undefined/0;
 *   otherwise returns true;
 */

/*
 *	Function to Remove StrikeItHealthy Family Bonus Booklet and
 *	Pamphlets from the Shopping cart.
 *	
 *	This function actually writes a non-persistant cookie to the
 *	users computer.
 *	
 *	The cookie is named SIHFamilyBonus and will contain either 
 *	 TRUE or FALSE
 *	
 *	This function makes the content of the SIHAdultBonus Cookie
 *		FALSE
 *	
 *	Parameters:
 *		none
 *			
 *	Return value:
 *		if successful an alert will display the success
 *		if failure an alert will notify the user.
 */
function removeSIHFamilyBonus(){
	if( testCookie() ){
			writeCookie( 'SIHFamilyBonusBQty', 'FALSE' );
			alert( "SIH Family Bonus Guidebook"+removed );
	} else alert(cookie_alert);
} 




 
/* family main package flag */
var SIHFamily_flag = null;
/* family bonus 9-13 flag */
var sihfa_flag = null;
var sihfb_flag = null;
/* family main package age indicator */ 
var age = null;
var BonusB = null;
var BonusA = null;
/* adult returning flag */

var sihar_flag = null;


/*
 * Function to test the customers computers ability to accept 
 * cookies.
 * 
 * Parameters
 * 		None
 * Return value
 * 		True if the customers computer can accept cookies
 * 		otherwise false.
 */
function testCookie () {
  document.cookie ="testCookie=Enabled";
  if (getCookieValue ("testCookie")=="Enabled")
    return true 
  else
    return false;
}

/*
 * Function to get the value of a specific cookie.
 * Parameter
 * 		cookieName: the name of the cookie 
 * Return
 * 		the content of the named cookie,
 * 		otherwise false.
 */
function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

/*
 * Function to write a non-persistant cookie
 * to the customers computer.
 * Parameters
 * 		cookieName: the name of the cookie to be written to.
 * 		cookieValue: the value being written into the cookie.
 * Return
 * 		True if successful, otherwise false.
 */
function writeCookie (cookieName, cookieValue) {
  if (testCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

function shippingFormValidator(theForm){
	if( theForm.shp_fname.value==""){
		alert( "Please enter a value for the \"First Name\" field. (required)" );
		theForm.shp_fname.focus();
		return (false);
	}
	if( theForm.shp_lname.value == "" ){
		alert( "Please enter a value for the \"Last Name\" field. (required)" );
		theForm.shp_lname.focus();
		return (false);
	}
	if( theForm.shp_address_one.value == "" ){
		alert( "Please enter a value for the \"Address\" field. (required)" );
		theForm.shp_address_one.focus();
		return (false);
	}
	if( theForm.shp_city.value == "" ){
		alert( "Please enter a value for the \"City\" field. (required)" );
		theForm.shp_city.focus();
		return (false);
	}
	if( theForm.shp_state.value == "0" ){
		alert( "Please select a value for the \"State\" field. (required)" );
		theForm.shp_state.focus();
		return (false);
	}
	if( theForm.shp_zip.value.length < 5 || theForm.shp_zip.value.length > 10 ){
		alert( "Please enter a value for the \"Zip Code\" field. (required)\nZip Codes must be greater than 5 digits." );
		theForm.shp_zip.focus();
		return (false);
	}
	if( theForm.shp_phone.value == ""){
		alert( "Please enter a value for the \"Phone number\" field. (required)" );
		theForm.shp_phone.focus();
		return (false);
	}
	if( theForm.shp_phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
	      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	      theForm.shp_phone.focus();
	      return (false);
	}
	return(true);
}

function billingOptionsFormValidator(theForm){
	var card_type = typeOfCard( theForm.CardNumber.value );
	var code_length = null;
	/* 
	 * First we have to determine the lenght of the security number
	 */
	if( card_type == "AMEX" )code_length = 4;
	else code_length = 3;

	if( theForm.CreditCardType.value=="0"){
		alert( "Please select a valid Credit Card Type. (required)" );
		theForm.CreditCardType.focus();
		return (false);
	}
	if( theForm.CardNumber.value == "" ){
		alert( "Please enter a value for the \"Credit Card Number\" field. (required)" );
		theForm.CardNumber.focus();
		return (false);
	}
	if( !isValidCreditCard( theForm.CardNumber.value  )){
		alert( "The number you entered doesn't appear to be a valid Credit Card Number. \nPlease try again.");
		theForm.CardNumber.focus();
		return (false);
	}
	if( theForm.SecurityNumber.value == "" ){
		alert( "Please enter a value for the \"Card Security Number\" field. (required)" );
		theForm.SecurityNumber.focus();
		return (false);
	}
	if( theForm.SecurityNumber.value.length != code_length ){
		alert( "It appears that the \"Card Security Number\" is invalid.\nPlease try again." );
		theForm.SecurityNumber.focus();
		return (false);
	}
	if( theForm.CreditCardExpireMonth.value == "NOSELECTION" ){
		alert( "Please enter a value for the \"Credit Card Expiration Date\" field. (required)" );
		theForm.CreditCardExpireMonth.focus();
		return (false);
	}
	if( theForm.CreditCardExpireYear.value == "NOSELECTION" ){
		alert( "Please select a value for the \"Credit Card Expiration Year\" field. (required)" );
		theForm.CreditCardExpireYear.focus();
		return (false);
	}
	if( theForm.FirstName.value == "" ){
		alert( "Please enter a value for the \"First Name\" field. (required)" );
		theForm.FirstName.focus();	
		return (false);
	}
	if( theForm.LastName.value == "" ){
		alert( "Please enter a value for the \"Last Name\" field. (required)" );
		theForm.LastName.focus();	
		return (false);
	}
	if( theForm.Address1.value == "" ){
		alert( "Please enter a value for the \"Address\" field. (required)" );
		theForm.Address1.focus();	
		return (false);
	}
	if( theForm.City.value == "" ){
		alert( "Please enter a value for the \"City\" field. (required)" );
		theForm.City.focus();	
		return (false);
	}
	if( theForm.State.value == "NOSELECTION" ){
		alert( "Please enter a value for the \"State\" field. (required)" );
		theForm.State.focus();	
		return (false);
	}
	if( theForm.ZipCode.value.length < 5 || theForm.ZipCode.value.length > 10 ){
		alert( "Please enter a value for the \"Zip Code\" field. (required)\nZip Codes must be greater than 5 digits." );
		theForm.ZipCode.focus();
		return (false);
	}
	if( theForm.PhoneNumber.value == ""){
		alert( "Please enter a value for the \"Phone number\" field. (required)" );
		theForm.PhoneNumber.focus();
		return (false);
	}
	if( theForm.PhoneNumber.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
	      alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
	      theForm.PhoneNumber.focus();
	      return (false);
	}
	if( theForm.ContactEmail.value == ""){
		alert( "Please enter a value for the \"Contact E-Mail\" field. (required)" );
		theForm.ContactEmail.focus();
		return (false);
	}
	if(!emailCheck( theForm.ContactEmail.value ) ){
		theForm.ContactEmail.focus();
		return(false);
	}
	if( theForm.VerifyEmail.value == ""){
		alert( "Please enter a value for the \"Verify E-Mail\" field. (required)" );
		theForm.ContactEmail.focus();
		return (false);
	}
	if( theForm.ContactEmail.value != theForm.VerifyEmail.value ){
		alert( "The \"Contact E-Mail\" and the \"Verify E-Mail\" must be the same.\nPlease try again." );
		theForm.ContactEmail.focus();
		return (false);
	}
	if( theForm.UsePhone.value == "" ){
		alert( "Please enter a value for the \"Phone Number\" field. (required)" );
		theForm.UsePhone.focus();
		return (false);
	}
	
	return(true);
}


/*
 * This Funtion returns the type of credit card based on
 * the entered numbes.
 */
function typeOfCard(number) {
	/* 
	//	Card Prefixes
	//
	//	Mastercard	51-55
	//	Visa		4
	//	AmEx		34,37
	//	Discover	6011
	*/

	var firstNumber = number.substring(0,1);
	var firstThreeNumbers = number.substring(0,3);

	if (firstNumber == 4) {
		return "VISA";
	} 

	var firstTwoNumbers = number.substring(0,2);
	if (firstTwoNumbers > 50 && firstTwoNumbers < 56) {
		return "MASTERCARD";
	}

	if (firstTwoNumbers == 34 || firstTwoNumbers == 37) {
		return "AMEX";
	}

	var firstFourNumbers = number.substring(0,4);
	if (firstFourNumbers == 6011) {
		return "DISCOVER";
	}
}

/*
 * This function checks the validity of the entered email address
 */
function emailCheck( emailStr ){
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
		}
	}

	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	if (user.match(userPat)==null) {
		// user is not valid
		alert("The username doesn't seem to be valid.");
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		// this is an IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name.  Check if it's valid.
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}

	return true;
}
/* 
 * Function that determines whether a credit card number is a valid
 * number, this doesn't mean the card is any good, only that the 
 * numbers entered fit a specific pattern.
 */
 
function isValidCreditCard(number) {
	var total = 0;
	var flag = 0;
	for (var i=(number.length - 1);i>=0; i--) {
		if (flag == 1) {
			var digits = number.charAt(i) * 2;
			if (digits > 9) digits -= 9;
			total += digits;
			flag = 0;
		} else {
			total = total + parseInt(number.charAt(i));
			flag = 1;
		}
	}
	if ((total%10) == 0) {
		return true;
	} else {
		return false;
	}
}


//  End -->