﻿function checkValidDate(dtfld) {
var error = "";
var err = 0;
var dtstr = dtfld.value;
var valid = "0123456789-";
var temp;
var currentTime = new Date();
var day = currentTime.getDate();
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();

for (var i=0; i< dtstr.length; i++) {
	temp = "" + dtstr.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
		err = 1;
	}
}
if (dtstr.length != 10){
	err=1;
}

// example yyyy-mm-dd
b = dtstr.substring(0, 4); // year
c = dtstr.substring(4, 5); // '-'

d = dtstr.substring(5, 7); // month
e = dtstr.substring(7, 8);// '-'
f = dtstr.substring(8, 10); // day
if (f<1 || f>31){
err = 1;
}
if (c != '-'){
err = 1;
}
if (d<1 || d>12){
err = 1;
}
if (e != '-'){
err = 1;
}

if (err==1) {
error = 'The date must be entered in yyyy-mm-dd format.\n';
dtfld.style.backgroundColor='#D8BFD8';
return error;
}

if (b<year){
 err = 2;
}

if (b==year){
if (d<month){
  err = 2;
 }
}

if (b==year){
 if (d==month){
  if (f<day){
  err = 2;
  }
 }
}

if (d==4 || d==6 || d==9 || d==11){
if (f==31) err=3;
}
if (d==2){
var g=parseInt(b/4);
if (isNaN(g)) {
err=3;
}
if (f>29) err=3;
if (f==29 && ((b/4)!=parseInt(b/4))) err=3;
}

/*
if (err==2) {
error = 'The date must be on or after today (' + year + '-' + month + '-' + day + ').\n' + dtstr + ' is in the past.';
dtfld.style.backgroundColor='#D8BFD8';
return error;
}
*/

if (err==3) {
error = 'There is an incorrect number of days for that month.\n';
dtfld.style.backgroundColor='#D8BFD8';
return error;
}

dtfld.style.backgroundColor='#FFFFFF';
return error;
}

// email

function checkEmail (str) {
var error="";
strng = str.value;
if (strng == "") {
   error = "You didn't enter an email address.\n";
   str.style.backgroundColor='#D8BFD8';

}

  //  var emailFilter=/^.+@.+\..{2,7}$/;
  //	var emailFilter=/^[\w-]+(\.[w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
  var emailFilter=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
         str.style.backgroundColor='#D8BFD8';

    }
    else {

//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
            str.style.backgroundColor='#D8BFD8';
       }
    }
if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
}
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (first, second, third) {
var error = "";
strng = first.value.toString() + second.value.toString() + third.value.toString();
if (strng == "") {
   error = "You didn't enter a phone number.\n";
   first.style.backgroundColor='#D8BFD8';
   second.style.backgroundColor='#D8BFD8';
   third.style.backgroundColor='#D8BFD8';
}

//strip out acceptable non-numeric characters
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); 

    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.\n";
       first.style.backgroundColor='#D8BFD8';
   second.style.backgroundColor='#D8BFD8';
   third.style.backgroundColor='#D8BFD8';
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length.\n";
	first.style.backgroundColor='#D8BFD8';
   second.style.backgroundColor='#D8BFD8';
   third.style.backgroundColor='#D8BFD8';
    }
if (error == "")
{
   first.style.backgroundColor='#F5F5F5';
   second.style.backgroundColor='#F5F5F5';
  third.style.backgroundColor='#F5F5F5';
}     
return error;
}


// password - between 6-16 chars, uppercase, lowercase, and numeral

function checkPassword (str) {
var error = "";
strng = str.value;
if (strng == "") {
   error = "You didn't enter a password.\n";
   str.style.backgroundColor='#D8BFD8';
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 16)) {
       error = "The password must be between 6 and 16 characters.\n";
	str.style.backgroundColor='#D8BFD8';
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
	str.style.backgroundColor='#D8BFD8';
    } 
if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
}      
return error;    
}    

function checkNumber (strl) {
var error = "";
strng = strl.value;
if (strng == "") {
   error = "You didn't enter a number.\n";
	strl.style.backgroundColor='#D8BFD8';
	}

	var re = /^[-]?\d*\.?\d*$/;
	str = strng.toString();
	if (!str.match(re))   
    {
    error = "The number contains illegal characters.\n";
    	strl.style.backgroundColor='#D8BFD8';
    }
    
if (error == "")
{
   strl.style.backgroundColor='#F5F5F5';
} 
return error;
}

function checkIngredients (strl) {
var error = "";
strng = strl.value;
if (strng == "0") {
   error = "You didn't add any ingredients.\n";
	}

return error;
}


function checkValidNumber (strl) {
var error = "";
strng = strl.value;

	var re = /^[-]?\d*\.?\d*$/;
	str = strng.toString();
	if (!str.match(re))   
    {
    error = "The number contains illegal characters.\n";
    	strl.style.backgroundColor='#D8BFD8';
    }
    
if (error == "")
{
   strl.style.backgroundColor='#F5F5F5';
} 
return error;
}

// zip code - 5 numbers only

function checkZip (strl) {
var error = "";
strng = strl.value;
if (strng == "") {
   error = "You didn't enter a zip code.\n";
	strl.style.backgroundColor='#D8BFD8';
	}

	var re = /^[-]?\d*\.?\d*$/;
	str = strng.toString();
	if (!str.match(re))   
    {
    error = "The zip code contains illegal characters.\n";
    	strl.style.backgroundColor='#D8BFD8';
    }
    if ((strng.length < 5) || (strng.length > 5)) {
       error = "The zip code is the wrong length.\n";
    strl.style.backgroundColor='#D8BFD8';
    } 
if (error == "")
{
   strl.style.backgroundColor='#F5F5F5';
} 
return error;
}

// username - 4-16 chars, uc, lc, and underscore only.

function checkUsername (str) {
var error = "";
strng = str.value;
if (strng == "") {
   error = "You didn't enter a username.\n";
   	str.style.backgroundColor='#D8BFD8';
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 16)) {
       error = "The username must be between 4 and 16 characters.\n";
       	str.style.backgroundColor='#D8BFD8';
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    	str.style.backgroundColor='#D8BFD8';
    }
    if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
}  
return error;
}       

function checkWebsite(str) {
var error = "";
strng = str.value;
  if (strng == "http://") {
     error = "The website is invalid, enter in a valid URL or clear the box.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
} 
return error;	  
}

// non-empty textbox

function isEmpty(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#FFFFFF';
} 
return error;	  
}

function checkValidColor(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "No color selected for recipe.\n";
  }
return error;	  
}

function checkEventTitle(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "You have not entered a title for the event.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#FFFFFF';
} 
return error;	  
}

// is email confirmed

function isEmailDifferent(var1, var2) {
var error = "";
num1 = var1.value;
num2 = var2.value;
  if (num1 != num2) {
     error = "Your confirmed email does not match.\n";
     	var2.style.backgroundColor='#D8BFD8';
  }
return error;
}

// is email confirmed

function isPayPalDifferent(var1, var2) {
var error = "";
num1 = var1.value;
num2 = var2.value;
  if (num1 != num2) {
     error = "Your PayPal confirmed email does not match.\n";
     	var2.style.backgroundColor='#D8BFD8';
     	return error;
  }
var2.style.backgroundColor='#F5F5F5';  
return error;
}

// is password confirmed

function isPasswordDifferent(var1, var2) {
var error = ""; 
num1 = var1.value;
num2 = var2.value;
  if (num1 != num2) {
     error = "The passwords do not match.\n";
     	var2.style.backgroundColor='#D8BFD8';
  }

return error;
}

// was textbox altered

function isDifferent(var1, var2) {
var error = ""; 
  if (var1 != var2) {
     error = "The text does not match.\n";
  }
return error;
}

// was a checkbox checked
function checkSelectBox(slct) {
var error = "";
	if (slct.checked) 
		{
		  return error;
		}
error = "Sorry, we require that you accept the Submission Terms.\n";
return error;
}

// exactly one radio button is chosen

function checkUserAgreement(uradio) {
var error = "";
	for (var i = 0; i < uradio.length; i++) 
	{
	if (uradio[i].checked) 
		{
		  ans = uradio[i].value;
		  if (ans == 'yes')
		  {
		  return error;
		  }
		}
	}
error = "Sorry, we require that you accept the User Agreement and Privacy Policy to start an account.\n";
return error;
}

/*
function checkRecipeSelection(uradio) {
var error = "";
	for (var i=uradio.length-1; i > -1; i--) 
	{
	alert(uradio[i].value);
	if (uradio[i].checked)
		{
		  return error;
		}
	}
error = "You must select a recipe before proceding.\n";
return error;
}
*/

// exactly one radio button is chosen

function checkAge(aradio) {

var error = "";
	for (var i = 0; i < aradio.length; i++) 
	{
	if (aradio[i].checked) 
		{
		  ans = aradio[i].value;
		  if (ans == 'yes')
		  {
		  return error;
		  }
		}
	}
error = "Sorry, you can not start an account if you are under 21.\n";
return error;
}

// exactly one radio button is chosen

function checkMailingList(lradio) {
var error = "";
	for (var i = 0; i < lradio.length; i++) 
	{
	if (lradio[i].checked) 
		{
		  return error;
		}
	}
error = "Please choose on option for the Brew Letter.\n";
return error;
}

function checkState(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a state.\n";
    }    
return error;
}   

function checkArticleType(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a type.\n";
    }    
return error;
}   

function checkCountry(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a country.\n";
    }    
return error;
}

function checkShippingMethod(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a shipping method.\n";
    }    
return error;
}

function checkCCtype(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a credit card type.\n";
    }    
return error;
}

function checkCCexpmonth(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a credit card month.\n";
    }    
return error;
}

function checkCCexpyear(choice) {
var error = "";
    if (choice.value == "") {
    error = "You didn't choose a credit card year.\n";
    }    
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
	    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
} 

function checklastname(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The last name box has not been filled in.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
} 
return error;	  
}

function checkcity(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The city box has not been filled in.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
} 
return error;	  
}

function checkaddress(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The address box has not been filled in.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
} 
return error;	  
}

function checkProjectTitle(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The project title is empty.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#FFFFFF';
} 
return error;	  

}

function checkRecipeName(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The recipe name is empty.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#FFFFFF';
} 
return error;	  

}

function checkRecipeDescription(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The recipe description is empty.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#FFFFFF';
} 
return error;	  

}

function checkRecipeInstructions(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The recipe instruction block is empty.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#FFFFFF';
} 
return error;	  

}

function checkfirstname(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The first name box has not been filled in.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
} 
return error;	  
}

function checkbusinessname(str) {
var error = "";
strng = str.value;
  if (strng.length == 0) {
     error = "The Business name box has not been filled in.\n";
     	str.style.backgroundColor='#D8BFD8';
  }
  if (error == "")
{
   str.style.backgroundColor='#F5F5F5';
} 
return error;	  
}

function checkCCnumber (number, type) {
	var error = "";
	var err = 0;
	var thestr = number.value;
	var type = type.value;
	var valid = "0123456789";
	var temp;
	var ccone = thestr.substring(0, 1);
	var cctwo = thestr.substring(0, 2);
	var ccfour = thestr.substring(0, 4);
		
	for (var i=0; i< thestr.length; i++) {
	temp = "" + thestr.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
	err = 1;
	}
	}
	
	if (type == "Visa") {
		if (thestr.length != 13 && thestr.length != 16){
		err = 2;
		}
		if (ccone != "4"){
		err = 2;
		}
	}
	
	if (type == "Discover") {
		if (thestr.length != 16){
		err = 2;
		}
		if (ccfour != "6011"){
		err = 2;
		}
	}
	
	if (type == "Amex") {
		if (thestr.length != 15){
		err = 2;
		}
		if (cctwo != "34" && cctwo != "37"){
		err = 2;
		}
	}
	
	if (type == "MasterCard") {
		if (thestr.length != 16){
		err = 2;
		}
		
		if (cctwo < 51 || cctwo > 55){
		err = 2;
		}
	}
	
	var digitsOnly = "";
	var theChar = "";
	for (i = 0; i < thestr.length; i++)
		{
		theChar = thestr.substring(i,i+1);
		if (theChar >= "0" && theChar <= "9")
			{
			digitsOnly = "" + digitsOnly + theChar;
			}
		}
		
	var length = digitsOnly.length;
	sum = 0; 
	mul = 1; 
	for (i = 0; i < length; i++) 
	{
			digit = digitsOnly.substring(length-i-1,length-i);
			tproduct = parseInt(digit ,10)*mul;
			if (tproduct >= 10)
				sum += (tproduct % 10) + 1;
			else
				sum += tproduct;
			if (mul == 1)
				mul++;
			else
				mul--;
	}
	if ((sum % 10) != 0)
	{
		err = 2;	
	}	
	
	if (err== 1){
	error = "Only numbers are allowed in the credit card number. \n";
	number.style.backgroundColor='#D8BFD8';
	}
	if (err== 2){
	error = "You entered an invalid credit card number. \n";
	number.style.backgroundColor='#D8BFD8';
	}
	
	if (error == "")
	{
   	number.style.backgroundColor='#F5F5F5';
	} 
	return error;
}

function checkCVV2 (str, type) {
var error = "";
var err = 0;
var thestr = str.value;
var type = type.value;
var valid = "0123456789";
var temp;

for (var i=0; i< thestr.length; i++) {
	temp = "" + thestr.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") {
	err = 1;
	}
}

if (thestr.length != 3 && type != "Amex"){
	err=2;
}
if (thestr.length != 4 && type == "Amex"){
	err=2;
}

if (err== 1){
	error = "Only numbers are allowed in the CVV2 field. \n";
	str.style.backgroundColor='#D8BFD8';
}
if (err== 2){
	error = "The CVV2 number is not the correct length. \n";
	str.style.backgroundColor='#D8BFD8';
}

	if (error == "")
	{
   	str.style.backgroundColor='#F5F5F5';
	} 	
	return error;
}

function checkCCexpdate(theForm){
	var error = "";
	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var year = currentTime.getFullYear();
	
	if (theForm.ExpYear.value < year){
		error = "Your credit card has expired. \n";
	}
	if (theForm.ExpYear.value == year && theForm.ExpMonth.value < month){
		error = "Your credit card has expired. \n";
	}
	return error;
}

function SetBillingAddress(theForm){
	theForm.b_firstname.value = theForm.s_firstname.value;
	theForm.b_lastname.value = theForm.s_lastname.value;
	theForm.b_address1.value = theForm.s_address1.value;
	theForm.b_address2.value = theForm.s_address2.value;
	theForm.b_city.value = theForm.s_city.value;
	theForm.b_state.value = theForm.s_state.value;
	theForm.b_zip.value = theForm.s_zip.value;
	theForm.b_country.value = theForm.s_country.value;
}

function checkUseShippingAddress(theForm){
	if (theForm.chkUseShippingAddress.checked == true)	{
		SetBillingAddress(theForm);
		theForm.b_firstname.readOnly = true;
		theForm.b_firstname.className='readonly';
		theForm.b_lastname.readOnly = true;
		theForm.b_lastname.className='readonly';
		theForm.b_address1.readOnly = true;
		theForm.b_address1.className='readonly';
		theForm.b_address2.readOnly = true;
		theForm.b_address2.className='readonly';
		theForm.b_city.readOnly = true;
		theForm.b_city.className='readonly';
		theForm.b_state.disabled = true;
		theForm.b_zip.readOnly = true;
		theForm.b_zip.className='readonly';
		theForm.b_country.disabled = true;
	}else{
		theForm.b_firstname.readOnly = false;
		theForm.b_firstname.className='text';
		theForm.b_lastname.readOnly = false;
		theForm.b_lastname.className='text';
		theForm.b_address1.readOnly = false;
		theForm.b_address1.className='text';
		theForm.b_address2.readOnly = false;
		theForm.b_address2.className='text';
		theForm.b_city.readOnly = false;
		theForm.b_city.className='text';
		theForm.b_state.disabled = false;
		theForm.b_zip.readOnly = false;
		theForm.b_zip.className='text';
		theForm.b_country.disabled = false;
	}
}

function checkCartZip(theForm){
	var why = "";
	
	why += checkZip(theForm.zip);
	
	if (why != "") {
       alert(why);
       return false;
    }
    
    return true;
}

function checkCheckoutForm(theForm) {
    var why = "";
    if (theForm.noshipping.value != 'true'){
	why += checkfirstname(theForm.s_firstname);
	why += checklastname(theForm.s_lastname);
	why += checkaddress(theForm.s_address1);
	why += checkcity(theForm.s_city);
	why += checkState(theForm.s_state);
    why += checkZip(theForm.s_zip);
    why += checkCountry(theForm.s_country);
	
    why += checkShippingMethod(theForm.shippingmethod);
	}
    why += checkfirstname(theForm.b_firstname);
	why += checklastname(theForm.b_lastname);
	why += checkaddress(theForm.b_address1);
	why += checkcity(theForm.b_city);
	why += checkState(theForm.b_state);
    why += checkZip(theForm.b_zip);
    why += checkCountry(theForm.b_country);
    
    why += checkCCtype(theForm.CreditCardType);
    why += checkCCnumber(theForm.CreditCardNumber, theForm.CreditCardType);
    why += checkCVV2(theForm.CVV2, theForm.CreditCardType);
    why += checkCCexpmonth(theForm.ExpMonth);
	why += checkCCexpyear(theForm.ExpYear);
	why += checkCCexpdate(theForm);
	    
    if (why != "") {
       alert(why);
       return false;
    }

theForm.b_state.disabled = false;
theForm.b_country.disabled = false;
return true;
}

function checkNewProduct(theForm) {
    var why = "";
    why += checkDropdown(theForm.subcategory);
    why += checkDropdown(theForm.category);
    why += checkDropdown(theForm.unit);
    why += isEmpty(theForm.description);
    why += isEmpty(theForm.name);
    why += isEmpty(theForm.manufacturer);
    why += checkNumber(theForm.weight);
    why += checkNumber(theForm.qty);
    
    if (theForm.manufacturer.value == 'Various' || theForm.manufacturer.value == 'various'){
    	theForm.sku.style.backgroundColor='#FFFFFF';
    }else{
    	why += isEmpty(theForm.sku);
    }
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkMemberForm(theForm) {
    var why = "";
    why += isEmailDifferent(theForm.member_email, theForm.member_confirm_email);
    why += checkEmail(theForm.member_email);
    why += checkEmail(theForm.member_confirm_email);
    why += checkUsername(theForm.member_username);
    why += isPasswordDifferent(theForm.member_password, theForm.member_confirm_password);
    why += checkPassword(theForm.member_password);
    why += checkPassword(theForm.member_confirm_password);
    why += checkUserAgreement(theForm.terms);
    why += checkAge(theForm.is21);
    why += checkMailingList(theForm.member_list);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkAdminForm(theForm) {
    var why = "";
    why += isEmailDifferent(theForm.admin_email, theForm.admin_confirm_email);
    why += checkEmail(theForm.admin_email);
    why += checkEmail(theForm.admin_confirm_email);
    why += checkUsername(theForm.admin_username);
    why += isPasswordDifferent(theForm.admin_password, theForm.admin_confirm_password);
    why += checkPassword(theForm.admin_password);
    why += checkPassword(theForm.admin_confirm_password);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkMerchantForm(theForm) {
    var why = "";
    why += checkbusinessname(theForm.merchant_business_name);
    why += checkWebsite(theForm.merchant_website);
    why += checkaddress(theForm.merchant_address1);
    why += checkcity(theForm.merchant_city);
    why += checkState(theForm.merchant_state.selectedIndex);
    why += checkZip(theForm.merchant_zip);
    // no country validation yet
    why += checkPhone(theForm.merchant_phone_1, theForm.merchant_phone_2, theForm.merchant_phone_3);
    why += isEmailDifferent(theForm.merchant_email, theForm.merchant_confirm_email);
    why += checkEmail(theForm.merchant_email);
    why += checkEmail(theForm.merchant_confirm_email);
    why += checkUsername(theForm.merchant_username);
    why += isPasswordDifferent(theForm.merchant_password, theForm.merchant_confirm_password);
    why += checkPassword(theForm.merchant_password);
    why += checkPassword(theForm.merchant_confirm_password);
    why += isPayPalDifferent(theForm.merchant_paypal, theForm.merchant_confirm_paypal);
    why += checkUserAgreement(theForm.terms);
    why += checkMailingList(theForm.merchant_list);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
} 

function checkAddRecipe1(theForm) {
	var why = "";
	//why += checkRecipeSelection(theForm.recipe);
	why += checkRecipeName(theForm.name);
	why += checkRecipeDescription(theForm.description);
	why += checkNumber(theForm.yield);
	why += checkValidNumber(theForm.OG);
	why += checkValidNumber(theForm.FG);
	why += checkValidNumber(theForm.ABV);
	why += checkValidNumber(theForm.IBU);
	why += checkValidColor(theForm.Color);
	
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkAddRecipe3(theForm) {
	var why = "";
	//why += checkRecipeSelection(theForm.recipe);
	why += checkRecipeInstructions(theForm.instructions);
	
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkAddRecipe2(theForm) {
	var why = "";
	why += checkIngredients(theForm.numIngredients);
	
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkAddRecipe2a(theForm) {
	var why = "";
	why += checkNumber(theForm.ingqty);
	why += isEmpty(theForm.ingname);
	
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkAddProject1(theForm) {
	var why = "";
	//why += checkRecipeSelection(theForm.recipe);
	why += checkProjectTitle(theForm.projecttitle);
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkAddProject3(theForm) {
	var why = "";
	why += checkEventTitle(theForm.eventtitle);
    why += checkValidDate(theForm.date);
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkEmailFriend(theForm) {
	var why = "";
	why += checkEmail(theForm.receiver);
	why += isEmpty(theForm.message);
	why += isEmpty(theForm.sender);
	why += isEmpty(theForm.receivername);	
	if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkChangePassword(theForm) {
    var why = "";
    why += isPasswordDifferent(theForm.password, theForm.confirm_password);
    why += checkPassword(theForm.password);
    why += checkPassword(theForm.confirm_password);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkChangeEmail(theForm) {
    var why = "";
    why += isEmailDifferent(theForm.email, theForm.confirm_email);
    why += checkEmail(theForm.email);
    why += checkEmail(theForm.confirm_email);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkChangePayPal(theForm) {
    var why = "";
    why += isPayPalDifferent(theForm.paypal, theForm.confirm_paypal);
    why += checkEmail(theForm.paypal);
    why += checkEmail(theForm.confirm_paypal);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function checkFriendsEmail(theForm) {
    var why = "";
    why += checkEmail(theForm.friendsemail);
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function RaiseFlag(choice)
{
choice.style.backgroundColor='#FFC0CB';
}

function GoBack(theform)
{
theform.stage.value = 1;
}

function GoBackArticle(theform)
{
theform.action.disabled = true;
}

function DuplicateMember(theForm) {
    var why = "";
    why += isEmailDifferent(theForm.member_email, theForm.member_confirm_email);
    why += checkEmail(theForm.member_email);
    why += checkEmail(theForm.member_confirm_email);
    why += checkUsername(theForm.member_username);
 
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function DuplicateAdmin(theForm) {
    var why = "";
    why += isEmailDifferent(theForm.admin_email, theForm.admin_confirm_email);
    why += checkEmail(theForm.admin_email);
    why += checkEmail(theForm.admin_confirm_email);
    why += checkUsername(theForm.admin_username);
 
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function DuplicateMerchant(theForm) {
    var why = "";
    why += isEmailDifferent(theForm.merchant_email, theForm.merchant_confirm_email);
    why += checkEmail(theForm.merchant_email);
    why += checkEmail(theForm.merchant_confirm_email);
    why += checkUsername(theForm.merchant_username);
 
    if (why != "") {
       alert(why);
       return false;
    }

return true;
}

function chkArticleForm(theForm){
	var why = "";
	why += isEmpty(theForm.name);
	why += isEmpty(theForm.description);
	why += isEmpty(theForm.title);
	why += isEmpty(theForm.body);
	why += checkSelectBox(theForm.rules);
	why += checkArticleType(theForm.type);
	
	if (why != "") {
       alert(why);
       return false;
    }
	return true;
}