/* ********************************************************************************
 * Channel 6 Validation Code,
 * specific to ch-change.com
 * ---------------------------------
 * (c) ch-6.co.uk, 2004-2005
 * ---------------------------------
 * Last modified:	2005-05-31: validateSearchForm() added.	
 *								2005-05-31: validateContactForm() added.
 * ********************************************************************************/

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

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

function validateContactForm(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 && oError.select && oError.select()) oError.select();
		if (oError && oError.focus && 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 && oError.select && oError.select()) oError.select();
		if (oError && oError.focus && 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;
	}
}

