/* ********************************************************************************
 * Channel 6 Validation Code,
 * specific to goslings.com
 * ---------------------------------
 * (c) ch-6.co.uk, 2004-2005
 * ---------------------------------
 * Last modified:	2005-07-14: oops! "oError.select" -> "if (oError.select) oError.select;", etc.
 *								2005-06-28:	validateNews(): added validation for "ArticleDate_*"
 * ********************************************************************************/

/**********************************************************************************/
/* Section: Public                                                                */
/**********************************************************************************/

function validateSignup(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Email;
	if (!validateEmail(oElement,"You must enter a valid email address!") && oError == null) oError = oElement;
	
	oElement = oForm.FirstName;
	if (!validateTextMin(oElement,1,"You must enter your first-name!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateContact(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Email;
	if (!validateEmail(oElement,"You must enter a valid email address!") && oError == null) oError = oElement;
	
	oElement = oForm.Name;
	if (!validateTextMin(oElement,1,"You must enter your name!") && oError == null) oError = oElement;

	oElement = oForm.Message;
	if (!validateTextMin(oElement,1,"You must enter a message!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateRecipeForm(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Email2;
	if (!validateEmail(oElement,"You must enter a valid email address!") && oError == null) oError = oElement;
	
	oElement = oForm.Name;
	if (!validateTextMin(oElement,1,"You must enter your name!") && oError == null) oError = oElement;

	oElement = oForm.Recipe;
	if (!validateTextMin(oElement,1,"You must enter a recipe!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateCocktailForm(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Email2;
	if (!validateEmail(oElement,"You must enter a valid email address!") && oError == null) oError = oElement;
	
	oElement = oForm.Name;
	if (!validateTextMin(oElement,1,"You must enter your name!") && oError == null) oError = oElement;

	oElement = oForm.Cocktail;
	if (!validateTextMin(oElement,1,"You must enter a recipe!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateRecipeSearch(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	// Search (Submit) or List (SubmitAll)?
	oElement = oForm.ListAll;		// either "0" (search) or "1" (list)
	var iListAll = oElement.value;
	
	// Either "Product" or "Category":
	if (iListAll == 0) {	// only validate if we're doing a search; lists don't require a keyword.
		oElement = oForm.Product;
		var sType = 'Gosling\'s product';
		if (!oElement) {
			oElement = oForm.Category;
			sType = 'category';
		}
		if (!validateDropDown(oElement,"You must select a " + sType + "!") && oError == null) oError = oElement;
	}
	
// 2005-07-15, jn: Keyword validation deprecated:
	// Keyword:
//	if (iListAll == 0) {	// only validate if we're doing a search; lists don't require a keyword.
//		oElement = oForm.Keyword;
//		if (!validateTextMin(oElement,1,"You must enter a keyword to search for!") && oError == null) oError = oElement;
//	}
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

/**********************************************************************************/
/* Section: Distributors/Suppliers                                                */
/**********************************************************************************/

function validateDistributorsLoginForm(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.email;
	if (!validateTextMin(oElement,1,"You must enter your Email address") && oError == null) oError = oElement;
	
	oElement = oForm.password;
	if (!validateTextMin(oElement,1,"You must enter your Password!") && oError == null) oError = oElement;

	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		oElement = oForm.remember_me;
		if (oElement.checked) {
			rememberDetails(oForm.email.value, oForm.password.value);
		} else {
			deleteCookie('LoginDistributor');
		}
		return true;
	}
}

function validateDistributorsSupplier(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Supplier;
	if (!validateTextMin(oElement,1,"You must enter a your company's name!") && oError == null) oError = oElement;
	
	oElement = oForm.RegionID;
	if (!validateDropDown(oElement,"You must select your company's region!") && oError == null) oError = oElement;
	
	oElement = oForm.Address;
	if (!validateTextMin(oElement,1,"You must enter your company's address!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

/**********************************************************************************/
/* Section: Login                                                                 */
/**********************************************************************************/

function validateLoginForm(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.email;
	if (!validateTextMin(oElement,1,"You must enter your Email address") && oError == null) oError = oElement;
	
	oElement = oForm.password;
	if (!validateTextMin(oElement,1,"You must enter your Password!") && oError == null) oError = oElement;

	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		oElement = oForm.remember_me;
		if (oElement.checked) {
			rememberDetails(oForm.email.value, oForm.password.value);
		} else {
			deleteCookie('Login');
		}
		return true;
	}
}

function validateChef(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Name;
	if (!validateTextMin(oElement,1,"You must enter a Name for the Chef!") && oError == null) oError = oElement;
	
	oElement = oForm.CountryID;
	if (!validateDropDown(oElement,"You must select a Country for the Chef!") && oError == null) oError = oElement;
	
	oElement = oForm.ChefType;
	if (!validateDropDown(oElement,"You must select the Type of Chef!") && oError == null) oError = oElement;
	
	oElement = oForm.Profile;
	if (!validateTextMin(oElement,1,"You must enter a Profile for the Chef!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateRecipe(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Recipe;
	if (!validateTextMin(oElement,1,"You must enter a Name for the Recipe!") && oError == null) oError = oElement;

	oElement = oForm.Ingredients;
	if (!validateTextMin(oElement,1,"You must enter the Ingredients for the Recipe!") && oError == null) oError = oElement;

	oElement = oForm.Directions;
	if (!validateTextMin(oElement,1,"You must enter the Directions for the Recipe!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateCountry(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Country;
	if (!validateTextMin(oElement,1,"You must enter a Name for the Country!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateRegion(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Region;
	if (!validateTextMin(oElement,1,"You must enter a Name for the Region!") && oError == null) oError = oElement;
	
	oElement = oForm.Country;
	if (!validateDropDown(oElement,"You must select a Country for the Region!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateRegionType(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.RegionType;
	if (!validateTextMin(oElement,1,"You must enter a Name for the Region-type!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateSupplier(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Supplier;
	if (!validateTextMin(oElement,1,"You must enter a Name for the Supplier!") && oError == null) oError = oElement;
	
	oElement = oForm.RegionID;
	if (!validateDropDown(oElement,"You must select a Region for the Supplier!") && oError == null) oError = oElement;
	
	oElement = oForm.Address;
	if (!validateTextMin(oElement,1,"You must enter an Address for the Supplier!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateNews(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message

	var sType = '';
	oElement = oForm.Type;
	if (!validateDropDown(oElement, "You must select the type of News article!") && oError == null) {
		oError = oElement;	
	} else {
		sType = oElement.options[oElement.selectedIndex].value;
	}

	oElement = oForm.Headline;
	if (!validateTextMin(oElement,1,"You must enter a Headline for the News article!") && oError == null) oError = oElement;
	
	oElement = oForm.ArticleDate_day;
	if (!validateDropDown(oElement, "You must select the day that the News article is published!") && oError == null) oError = oElement;	
	oElement = oForm.ArticleDate_month;
	if (!validateDropDown(oElement, "You must select the month that the News article is published!") && oError == null) oError = oElement;	
	oElement = oForm.ArticleDate_year;
	if (!validateDropDown(oElement, "You must select the year that the News article is published!") && oError == null) oError = oElement;
	
	if (sType != 'articles') {	// we DON'T need to validate summary, article if Type := articles
		oElement = oForm.Summary;
		if (!validateTextMin(oElement,1,"You must enter a Summary for the News article!") && oError == null) oError = oElement;
		
		oElement = oForm.Article;
		if (!validateTextMin(oElement,1,"You must enter Article text for the News article!") && oError == null) oError = oElement;
	}
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateEvent(oForm) {
	var oError = null;	// location of first error
	var oElement;
	sErrorMessage = '';	// reset error message
	
	oElement = oForm.Headline;
	if (!validateTextMin(oElement,1,"You must enter a Headline for the Event!") && oError == null) oError = oElement;
	
	oElement = oForm.StartDate_day;
	if (!validateDropDown(oElement, "You must select the day that the Event starts!") && oError == null) oError = oElement;	
	oElement = oForm.StartDate_month;
	if (!validateDropDown(oElement, "You must select the month that the Event starts!") && oError == null) oError = oElement;	
	oElement = oForm.StartDate_year;
	if (!validateDropDown(oElement, "You must select the year that the Event starts!") && oError == null) oError = oElement;

	oElement = oForm.EndDate_day;
	if (!validateDropDown(oElement, "You must select the day that the Event ends!") && oError == null) oError = oElement;	
	oElement = oForm.EndDate_month;
	if (!validateDropDown(oElement, "You must select the month that the Event ends!") && oError == null) oError = oElement;	
	oElement = oForm.EndDate_year;
	if (!validateDropDown(oElement, "You must select the year that the Event ends!") && oError == null) oError = oElement;
	
	oElement = oForm.Summary;
	if (!validateTextMin(oElement,1,"You must enter a Summary for the Event!") && oError == null) oError = oElement;
	
	oElement = oForm.Event;
	if (!validateTextMin(oElement,1,"You must enter Event text for the Event!") && oError == null) oError = oElement;
	
	oElement = oForm.CountryID;
	if (!validateDropDown(oElement,"You must select the country hosting the Event!") && oError == null) oError = oElement;
	
	// place focus on first invalid form-element:
	if (oError != null) {
		alert(sErrorMessage);
		if (oError.select) oError.select;
		if (oError.focus) oError.focus;
		return false;
	} else {
		return true;
	}
}

function validateGallery(oForm) {
  var oError = null;  // location of first error
  var oElement;
  sErrorMessage = ''; // reset error message
  
  oElement = oForm.Headline;
  if (!validateTextMin(oElement,1,"You must enter a Name for the Gallery!") && oError == null) oError = oElement;
 
  oElement = oForm.Summary;
  if (!validateTextMin(oElement,1,"You must enter a Summary for the Gallery!") && oError == null) oError = oElement;
  
  // place focus on first invalid form-element:
  if (oError != null) {
    alert(sErrorMessage);
    if (oError.select) oError.select;
    if (oError.focus) oError.focus;
    return false;
  } else {
    return true;
  }
}