/*
'_______________________________________________________________________________
' File     : form_validate.js
' Created  : 7 Sep 2001
' Author   : Suzy Toop
' Purpose  : Form validation javascript
'
' SourceSafe Info:
' $Revision: 1.74 $
' $NoKeywords: $
'
' Modifications:
' Date        Person		Description
' 7  Sep 2001 Suzy Toop		Created ( Dev Release 8 )
' 27 Sep 2001 Suzy Toop		Added special case for Web User front end -
'				used by register.xsl for validating the Terms &
'				conditions checkbox
' 01 Oct 2001 Suzy Toop		Added ValidateImageChecked - used in imageadmin
'				to check that a user has selected an image to
'				link or unlink. Can be used for other checkbox
'				groups. Test carefully !
' 02 Oct 2001 Suzy Toop		Added some more registration functions -
'				ClearPasswords and ValidateRegistrationInfo
'				Added ValidateMaxIntValue
' 03 Oct 2001 Suzy Toop		Fixed the registration validation parameters
' 				Added ValidateAdminRegistrationInfo
'				Focus after number validation
' 05 Oct 2001 Suzy Toop		AFW_SHOW_ONLY_MINE added on reg admin
' 11 Oct 2001 Suzy Toop		Added ValidateHHRegistrationInfo: In theory this
'				should go into a HH js, but it uses some common
'				functions which aren't included by default on the
'				Horse and Hound front end.
' 25 Oct 2001 Suzy Toop		Trade validation for web user added
' 26 Oct 2001 Suzy Toop		Trade validation for horse and hound added
' 29 Oct 2001 Suzy Toop		Doing the checkbox js on frontend reg now.
'  8 Nov 2001 Suzy Toop		Added Package maxword validation
' 16 Nov 2001 Suzy Toop	 	Changed HH registration validation as we don't
'				know how many personalisable categories will appear
' 19 Nov 2001 Suzy Toop		Added mod_reg_data_protect_2 into HHReg checkbox update
' 27 Nov 2001 Suzy Toop		HH Reg checkboxes no longer check themselves - now update
'				a hidden field instead as this looked a tad confusing.
' 13 Dec 2001 Petra Selmer      Add a new function for a new trade company
' 16 Jan 2002 Suzy Toop		Added ValidateHHTradeRegistrationInfo
' 23 Jan 2002 Suzy Toop		Fixed shared machine stuff on HH frontend registration
'  6 Feb 2002 Suzy Toop		Added ValidateAdminUser
' 11 Feb 2002 Suzy Toop		Added some machine shared validation
' 12 Feb 2002 Suzy Toop		Fixed up machine shared
'				Added session validation
'  3 Mar 2002 Suzy Toop		WU reg opt-outs don't check themselves
' 16 Apr 2002 Suzy Toop		GLG Fund checkbox validation
' 22 Apr 2002 Suzy Toop		GLG reg validation
'				Email validation
'				String length function ( feel free to embellish ! )
' 29 Apr 2002 Suzy Toop		GLG reg validation no longer has waiver agreement
' 30 Apr 2002 P. Selmer		Boots reg validation
' 16 May 2002 Suzy Toop		Booking Calendar time check
' 24 May 2002 Suzy Toop		GLG Funds have extra validation
' 17 May 2002 Suzy Toop		GLG Funds have nullable fields... sigh.
' 27 Jun 2002 Suzy Toop		Changed CheckSessionMandatoryFieldsFilled as per rewrite
' 16 Aug 2002 Petra Selmer	Added function to ensure a checkbox is ticked before submitting
'_______________________________________________________________________________
*/

/************************************************************
*************************************************************

Function: CheckMandatoryFieldsFilled(form)
========

Description: This function alerts if mandatory fields are not filled in.
===========

Example of use:
==============
<script language="JavaScript1.2" type="text/javascript" src="/js/form_validate.js"></script>

<form name="frmUser" ....
onsubmit="return CheckMandatoryFieldsFilled( this, 0, 'user\'s first name', 2, 'user\'s salary');">
	<input type="text" name="user-fname" value="" />
	<input type="text" name="user-sname" value="" />
	<input type="text" name="user-salary" value="" />
	<input type="submit" name="submit" value="submit" />
</form>

Parameters:
==========

this - always call CheckMandatoryFieldsFilled with the first parameter = this

The rest of the parameters are in pairs.
In the first pair,
	0 stands for the index of the form element that is mandatory ( user-fname )
	'user\'s first name' is the field name that is shown to the user, ie the alert
	will say "Please enter the user's first name"

So the above will only submit the form if user-fname and user-salary are filled in.
*************************************************************
*************************************************************/

<!--
function CheckMandatoryFieldsFilled(form) {
	var okSoFar=true;

	for (var i=1; i<CheckMandatoryFieldsFilled.arguments.length; i=i+2) {
		var form_element_index = CheckMandatoryFieldsFilled.arguments[i];
		var form_element = form.elements[form_element_index];
		var alert_field_name = CheckMandatoryFieldsFilled.arguments[i+1];

// alert(i + " " + alert_field_name + " - " + form_element.value);
		if (form_element.value=='') {
		   okSoFar=false;
		   alert('Please enter the ' + alert_field_name );
		   form_element.focus();
		   return okSoFar;
		} else if ( form_element.checked!=true && form_element.name=='mod_reg_t_and_c') {
		   okSoFar=false;
		   alert('Please enter the ' + alert_field_name );
		   form_element.focus();
		   return okSoFar;
		}
	}

	return okSoFar;
}
//-->

/************************************************************
*************************************************************

Function: ValidateImageChecked(form)
========

Description: This function alerts if an image is not checked when the user clicks 'Link'
===========

Example of use:
==============
<script language="JavaScript1.2" type="text/javascript" src="/js/form_validate.js"></script>

<form name="frmUser" ....
onsubmit="return ValidateImageChecked( this );">
	<input type="submit" name="submit" value="submit" />
</form>
*************************************************************
*************************************************************/

<!--
function ValidateImageChecked(form) {
	var checked = false;

	for (var e = 0; e < form.elements.length; e++) {
		var el = form.elements[e];

		if (el.type == 'checkbox') {
			var group = form[el.name];

			if (group.length) {
				for (var r = 0; r < group.length; r++) {
					if ((checked = group[r].checked)) {
						checked = true;
						break;
					}
				}
			} else {
				// We do this check because if there is only one checkbox
				// in the group, then group.length is undefined for some
				// reason. You will need to add a special condition of your
				// own if you want to use this js for your own sordid purposes...

				if ((checked = form.MOD_IMG_IMAGEID.checked)) {
					checked = true;
				}
			}
			if (!checked) {
				alert('Please select an image');
				el.focus();
				return false;
			}
		}
	}
	return true;
}
//-->

/************************************************************
*************************************************************

Function: ValidateUploadChecked(form)
========

Description: This function alerts if an upload is not checked when the user clicks 'Link'
===========
		Sigh. Fleeced this from Images. Don't get me started on the Upload saga.

Example of use:
==============
<script language="JavaScript1.2" type="text/javascript" src="/js/form_validate.js"></script>

<form name="frmUpload" ....
onsubmit="return ValidateUploadChecked( this );">
	<input type="submit" name="submit" value="submit" />
</form>
*************************************************************
*************************************************************/

<!--
function ValidateUploadChecked(form) {
	var checked = false;

	for (var e = 0; e < form.elements.length; e++) {
		var el = form.elements[e];

		if (el.type == 'checkbox') {
			var group = form[el.name];

			if (group.length) {
				for (var r = 0; r < group.length; r++) {
					if ((checked = group[r].checked)) {
						checked = true;
						break;
					}
				}
			} else {
				// We do this check because if there is only one checkbox
				// in the group, then group.length is undefined for some
				// reason. You will need to add a special condition of your
				// own if you want to use this js for your own sordid purposes...

				if ((checked = form.MOD_UPLOAD_ITEMID.checked)) {
					checked = true;
				}
			}
			if (!checked) {
				alert('Please select an upload');
				el.focus();
				return false;
			}
		}
	}
	return true;
}
//-->


/************************************************************
*************************************************************

Function: ClearPasswords(form)
========

Description: Clears the default passwords on the update reg form
===========

Example of use:
==============
<script language="JavaScript1.2" type="text/javascript" src="/js/form_validate.js"></script>

<form name="frmUser" ....
onsubmit="ClearPasswords( this );">
	<input type="submit" name="submit" value="submit" />
</form>
*************************************************************
*************************************************************/

<!--
function ClearPasswords(form) {
	if (form.mod_reg_password.value=="__STARS__" && form.mod_reg_password_confirm.value=="__STARS__") {
		form.mod_reg_password.value = '';
		form.mod_reg_password_confirm.value = '';
	}

}
//-->

/************************************************************
*************************************************************

Function: ValidateRegistrationInfo(form)
========

Description: Calls clear password and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateRegistrationInfo(form) {
	if ( CheckMandatoryFieldsFilled( form, 1, '\'First Name\' field', 2, '\'Last Name\' field', 3, '\'Email\' field', 4, '\'House Name/Number\' field', 5, '\'Street Name\' field', 7, '\'Town/City\' field', 9, '\'Post/Zip Code\' field', 22, '\'User Name\' field', 23, '\'Password\' field', 24, '\'Confirm Password\' field', 25, '\'Terms and Conditions\' checkbox. \nYou need to check this to become a registered user.') ) {
		ClearPasswords(form);
		SetCheckboxValuesWU(form);
		return true;
	} else {
		return false;
	}
}
//-->


/************************************************************
*************************************************************

Function: ValidateDemoRegistrationInfo(form)
========

Description: Calls clear password and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateDemoRegistrationInfo(form) {
	if ( CheckMandatoryFieldsFilled( form, 1, '\'First Name\' field', 2, '\'Last Name\' field', 3, '\'Email\' field', 4, '\'Country\' field', 5, '\'User Name\' field', 6, '\'Password\' field', 7, '\'Confirm Password\' field') ) {
		ClearPasswords(form);
		return true;
	} else {
		return false;
	}
}
//-->



/************************************************************
*************************************************************

Function: ValidateHHRegistrationInfo(form)
========

Description: Calls clear password and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateHHRegistrationInfo(form) {

	if ( CheckMandatoryFieldsFilled( form, 1, '\'User Name\' field', 2, '\'Password\' field', 3, '\'Confirm Password\' field', 5, '\'First Name\' field', 6, '\'Last Name\' field', 7, '\'Email\' field' ) ) {
		if (form.mod_reg_t_and_c_checkbox.checked!=true) {
			alert('Please fill in the \'Terms and Conditions\' checkbox. \nYou need to check this to become a registered user.');
			form.mod_reg_t_and_c_checkbox.focus();
			return(false);
		}

		ClearPasswords(form);
		SetCheckboxValuesHH(form);
		return true;
	} else {
		return false;
	}
}
//-->


/************************************************************
*************************************************************

Function: ValidateHHTradeRegistrationInfo(form)
========

Description: Calls clear password and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateHHTradeRegistrationInfo(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, '\'User Name\' field', 4, '\'Password\' field', 5, '\'Confirm Password\' field' ) ) {
		if (form.mod_reg_t_and_c_checkbox.checked!=true) {
			alert('Please fill in the \'Terms and Conditions\' checkbox. \nYou need to check this to become a registered user.');
			form.mod_reg_t_and_c_checkbox.focus();
			return(false);
		}

		ClearPasswords(form);
		SetCheckboxValuesHH(form);
		return true;
	} else {
		return false;
	}
}
//-->



/************************************************************
*************************************************************

Function: ValidateAdminRegistrationInfo(form)
========

Description: Calls clear password and mandatory field validator on admin
===========

*************************************************************
*************************************************************/

<!--
function ValidateAdminRegistrationInfo(form) {

	if ( CheckMandatoryFieldsFilled( form, 1, '\'User Name\' field', 2, '\'First Name\' field', 3, '\'Last Name\' field', 4, '\'Email\' field' ) ) {
		ClearPasswords(form);

		//Hack the show only mine checkbox first

		// Jon: Commented out until checkbox put back in
		// if (form.AFW_SHOW_ONLY_MINE.checked) {
		//	form.AFW_SHOW_ONLY_MINE.value = 1;
		// } else {
		//	form.AFW_SHOW_ONLY_MINE.value = 0;
		//	form.AFW_SHOW_ONLY_MINE.checked = true;
		// }

		return true;
	} else {
		return false;
	}
}
//-->

/************************************************************
*************************************************************

Function: ValidateAdminUser(form)
========

Description: Checks everything filled in, passwords match
===========

*************************************************************
*************************************************************/

<!--
function ValidateAdminUser(form) {

	if ( CheckMandatoryFieldsFilled( form, 1, 'username', 2, 'password', 3, 'confirm password') ) {
		if (form.mod_user_password.value != form.mod_user_password_confirm.value ) {
			alert('Your passwords do not match');
			form.mod_user_password.focus();
		} else {
			return true;
		}
	}

	return false;
}
//-->


/************************************************************
*************************************************************

Function: SetCheckboxValuesWU(form)
========

Description:
===========
	Sets the values of the checkboxes and checks them,
	otherwise the reg module thinks they haven't been changed

*************************************************************
*************************************************************/

<!--
function SetCheckboxValuesWU(form) {

	if (form.mod_reg_subscriber.checked) {
		form.mod_reg_subscriber.value = 1;
	} else {
		form.mod_reg_subscriber.value = 0;
		form.mod_reg_subscriber.checked = true;
	}

	if (form.mod_reg_t_and_c.checked) {
		form.mod_reg_t_and_c.value = 1;
	} else {
		form.mod_reg_t_and_c.value = 0;
		form.mod_reg_t_and_c.checked = true;
	}

	// Added machine shared - SMT 11/2/2002
	if (form.MOD_REG_MACHINE_SHARED_checkbox.checked) {
		form.MOD_REG_MACHINE_SHARED.value = 1;
	} else {
		form.MOD_REG_MACHINE_SHARED.value = 2;
	}

	// This bit dies if the fields do not exist
	// Need to put in the existence if for the update reg page
	if (form.mod_reg_nobulkemail_checkbox.checked) {
		form.mod_reg_nobulkemail.value = 1;
	} else {
		if (form.mod_reg_nobulkemail) {
			form.mod_reg_nobulkemail.value = 0;
		}
	}

	if (form.mod_reg_data_protect_2_checkbox.checked) {
		form.mod_reg_data_protect_2.value = 1;
	} else {
		if (form.mod_reg_nobulkemail) {
			form.mod_reg_data_protect_2.value = 0;
		}
	}


}
//-->


/************************************************************
*************************************************************

Function: SetCheckboxValuesHH(form)
========

Description:
===========
	Sets the values of the checkboxes and checks them,
	otherwise the reg module thinks they haven't been changed

*************************************************************
*************************************************************/

<!--
function SetCheckboxValuesHH(form) {

	if (form.mod_reg_nobulkemail_checkbox.checked) {
		form.mod_reg_nobulkemail.value = 1;
	} else {
		form.mod_reg_nobulkemail.value = 0;
	}

	if (form.mod_reg_t_and_c_checkbox.checked) {
		form.mod_reg_t_and_c.value = 1;
	} else {
		form.mod_reg_t_and_c.value = 0;
	}

	if (form.mod_reg_data_protect_2_checkbox.checked) {
		form.mod_reg_data_protect_2.value = 1;
	} else {
		form.mod_reg_data_protect_2.value = 0;
	}

	// If shared, have maximum security (1) on login, else have medium (0)

	if (form.mod_reg_machine_shared_checkbox.checked) {
		form.mod_reg_machine_shared.value = 1;
	} else {
		form.mod_reg_machine_shared.value = 2;
	}

}
//-->


/************************************************************
*************************************************************

Function: ValidateMaxIntValue(form, index, name, max)
========

Description:
===========
Checks that the number entered in the indexed field isn't
greater than max

*************************************************************
*************************************************************/

<!--
function ValidateMaxIntValue(form, index, name, max) {

	var iValue = parseInt(form.elements[index].value, 10);

	if (isNaN(iValue)) {
		alert('The \'' + name + '\' must be a number less than ' + max );
		form.elements[index].select();
		form.elements[index].focus();
		return false;
	}

	if ( form.elements[index].value >= max ) {
		alert('The value for \'' + name + '\' must be less than ' + max );
		form.elements[index].focus();
		return false;
	}

	return true;

}
//-->

/************************************************************
*************************************************************

Function: ValidateCrosswordAdmin(form)
========

Description:
===========
Check mandatory fields are filled and that numbers aren't too big.

*************************************************************
*************************************************************/

<!--
function ValidateCrosswordAdmin(form) {

	if ( CheckMandatoryFieldsFilled(form, 1, 'title', 2, 'width', 3, 'height', 4, 'config file', 5, 'foreground', 6, 'background', 7, 'destination url', 8, 'destination target') ) {
		if (ValidateMaxIntValue(form, 2, 'width', 10000) && ValidateMaxIntValue(form, 3, 'height', 10000)) {
			return true;
		}
	}

	return false;

}
//-->


/************************************************************
*************************************************************

Function: ValidateTradeNewCompany(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateTradeNewCompany(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, '\'Company Name\' field', 4, '\'Address\' field', 9, '\'Postcode\' field', 10, '\'Admin email\' field', 11, '\'Admin phone\' field', 15, '\'Business Category\' field') && CheckTradeDescriptionMaxWords(form)) {
		return true;
	} else {
		return false;
	}
}
//-->

/************************************************************
*************************************************************

Function: ValidateTradeNewWUCompany(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateTradeNewWUCompany(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, '\'Company Name\' field', 4, '\'Address\' field', 9, '\'Postcode\' field', 10, '\'Admin email\' field', 11, '\'Admin phone\' field', 15, '\'Business Category\' field') && CheckTradeDescriptionMaxWords(form)) {
		if (!form.tradedir_opt_in.checked) {
			alert("You must accept our terms and conditions before you proceed.");
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}
//-->




/************************************************************
*************************************************************

Function: ValidateTradeNewHHCompany(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateTradeNewHHCompany(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, '\'Company Name\' field', 4, '\'Address\' field', 9, '\'Postcode\' field', 10, '\'Admin email\' field', 11, '\'Admin phone\' field', 15, '\'Business Category\' field') && CheckTradeDescriptionMaxWords(form)) {
		if (!form.tradedir_opt_in.checked) {
			alert("You must accept our terms and conditions before you proceed.");
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}
//-->


/************************************************************
*************************************************************

Function: ValidateTradeCompanyUpdate(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateTradeCompanyUpdate(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, '\'Company Name\' field', 5, '\'Address\' field', 10, '\'Postcode\' field', 15, '\'Admin email\' field', 16, '\'Admin phone\' field', 17, '\'Business Category\' field') && CheckTradeDescriptionMaxWords(form) ) {
		return true;
	} else {
		return false;
	}
}
//-->

/************************************************************
*************************************************************

Function: ValidateHHTradeCompanyUpdate(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateHHTradeCompanyUpdate(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, '\'Company Name\' field', 4, '\'Admin email\' field', 5, '\'Admin phone\' field', 7, '\'Address\' field', 12, '\'Postcode\' field', 17, '\'Business Category\' field') && CheckTradeDescriptionMaxWords(form) ) {
		return true;
	} else {
		return false;
	}
}
//-->


/************************************************************
*************************************************************

Function: CheckTradeDescriptionMaxWords(form)
========

Description: Checks max words of trade description
===========

*************************************************************
*************************************************************/

<!--
function CheckTradeDescriptionMaxWords(form) {

	if (form.mod_tradedir_description.value!='') {
		var stringToSplit = form.mod_tradedir_description.value
		var separator = " "
		arrayOfStrings = stringToSplit.split(separator)
		var numberOfWords = arrayOfStrings.length

		if (numberOfWords > form.mod_tradedir_package_maxwords.value) {
			var numdiff = numberOfWords - form.mod_tradedir_package_maxwords.value;
			alert("The maximum number of words for the description is " + form.mod_tradedir_package_maxwords.value + "\n Try to cut out " + numdiff + " words.");
			form.mod_tradedir_description.focus();
			return false;
		}
	}

	return true;
}
//-->


/************************************************************
*************************************************************

Function: ValidatePackageAdminEdit(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidatePackageAdminEdit(form) {

	if ( CheckMandatoryFieldsFilled( form, 3, 'name', 6, 'logo', 8, 'url', 9, 'email') ) {
		if (form.mod_tradedir_admin_package_maxwords.value > 32000) {
			alert('The maximum number of words is 32000');
			form.mod_tradedir_admin_package_maxwords.value = '';
			form.mod_tradedir_admin_package_maxwords.focus();
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}
//-->


/************************************************************
*************************************************************

Function: ValidatePackageAdminAdd(form)
========

Description: Calls max words check and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidatePackageAdminAdd(form) {

	if ( CheckMandatoryFieldsFilled( form, 2, 'name', 5, 'logo', 7, 'url', 8, 'email') ) {
		if (form.mod_tradedir_admin_package_maxwords.value > 32000) {
			alert('The maximum number of words is 32000');
			form.mod_tradedir_admin_package_maxwords.value = '';
			form.mod_tradedir_admin_package_maxwords.focus();
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}
//-->

/************************************************************
*************************************************************

Function: ValidateLogin(form)
========

Description: Updates the value in afw_machine_shared
===========

*************************************************************
*************************************************************/

<!--
function ValidateLogin(form) {
	// First check if this login form actually has the checkbox before we try to use it.
	if (form.afw_shared_machine_checkbox != null) {
		if (form.afw_shared_machine_checkbox.checked) {
			form.afw_shared_machine.value = 1;
		} else {
			form.afw_shared_machine.value = 2;
		}
	}
	form.submit();
}
//-->

/************************************************************
*************************************************************

Function: ValidateBathroomLogin(form)
========

Description: Updates the value in afw_machine_shared for bathrooms
===========

*************************************************************
*************************************************************/

<!--
function ValidateBathroomLogin(form) {
	// First check if this login form actually has the checkbox before we try to use it.
	if (form.afw_shared_machine_checkbox != null) {
		if (form.afw_shared_machine_checkbox.checked) {
			form.afw_shared_machine.value = 2;
		} else {
			form.afw_shared_machine.value = 1;
		}
	}
	form.submit();
}
//-->

/************************************************************
*************************************************************

Function: CheckSessionMandatoryFieldsFilled(form)
========

Description:
===========
		Checks fields filled for Sessions. Only want
		advertising text if the advertising checkbox
		is checked.

*************************************************************
*************************************************************/

<!--
function CheckSessionMandatoryFieldsFilled(form) {
	if (CheckMandatoryFieldsFilled(form, 0, 'course title', 1, 'start day', 2, 'start month', 3, 'start year', 4, 'end day', 5, 'end month', 6, 'end year', 7, 'start time', 8, 'end time')) {
		if (form.MOD_SEMINAR_SESS_ADVERTISE.checked && form.MOD_SEMINAR_SESS_ADVERTISEMENT_TEXT.value == '') {
			alert('Please fill in the advertising text');
			form.MOD_SEMINAR_SESS_ADVERTISEMENT_TEXT.focus();
			return false;
		} else {
			return true;
		}
	}

	return false;
}
//-->


/************************************************************
*************************************************************

Function: ValidateFundFields(form)
========

Description: Validates GLG admin fund forms
===========

*************************************************************
*************************************************************/

<!--
function ValidateFundFields(form) {

	//if ( CheckMandatoryFieldsFilled( form, 2, 'fund name', 4, 'inception day', 5, 'inception month', 6, 'inception year', 7, 'ITD %', 8, 'benchmark %', 9, 'outperformance', 10, 'sort order' ) ) {
	if ( CheckMandatoryFieldsFilled( form, 2, 'fund name', 10, 'sort order' ) ) {
		if (form.mod_fundadmin_fund_is_ucits.checked) {
			form.mod_fundadmin_fund_is_ucits.value = 1;
		} else {
			form.mod_fundadmin_fund_is_ucits.value = 0;
		}

		return true;
	} else {
		return false;
	}
}
//-->


/************************************************************
*************************************************************

Function: ValidateGLGRegistration(form)
========

Description:
===========
	Validates GLG registration forms - password
	validation slightly slicker than normal, passwords
	should be at least 6 characters long

*************************************************************
*************************************************************/

<!--
function ValidateGLGRegistration(form) {

		if (form.mod_reg_firstname.value == "") {
			alert("Please enter your first name");
			form.mod_reg_firstname.focus();
			return false;
		}

		if (form.mod_reg_lastname.value == "") {
			alert("Please enter your last name");
			form.mod_reg_lastname.focus();
			return false;
		}

		if (form.mod_reg_email.value == "") {
			alert("Please enter your email address");
			form.mod_reg_email.focus();
			return false;
		}

		if (form.mod_reg_tel_number.value == "") {
			alert("Please enter your telephone number");
			form.mod_reg_tel_number.focus();
			return false;
		}

		if (form.mod_reg_username.value == "") {
			alert("Please enter your user name");
			form.mod_reg_username.focus();
			return false;
		}

			if (form.mod_reg_password.value == form.mod_reg_password_confirm.value) {
			if (IsCorrectLengthString(form.mod_reg_password.value, 4, -1 ) ) {

				if (IsValidEmail(form.mod_reg_email.value)) {
					ClearPasswords(form);
					return true;

				} else {

					alert('Your email address does not look correct. Please check it and try again');
					form.mod_reg_email.focus();

				}

			} else {
				alert('Your password must be at least 6 characters long.');
				form.mod_reg_password.focus();
			}

		} else {

			alert('Passwords do not match.');
			form.mod_reg_password.focus();

		}

	return false;

}
//-->


/************************************************************
*************************************************************

Function: IsCorrectLengthString(sString, iMin, iMax)
========

Description: Checks if string is between certain lengths
===========

*************************************************************
*************************************************************/

<!--
function IsCorrectLengthString(sString, iMin , iMax ) {

	if ( sString.length >= iMin ) {

		if ( (sString.length <= iMax && iMax != -1) || ( iMax = -1 ) ) {

			return true;

		}

	}

	return false;

}
//-->

/************************************************************
*************************************************************

Function: IsValidEmail(sEmail)
========

Description: Checks if email is valid
===========

*************************************************************
*************************************************************/

<!--
function IsValidEmail(sEmail) {

	if ( sEmail.indexOf('@') > -1 && sEmail.indexOf('.') > -1 && sEmail.length > 4 ) {

		return true;

	}

	return false;

}
//-->

/************************************************************
*************************************************************

Function: ValidateBootsRegistrationInfo(form)
========

Description: Calls clear password and mandatory field validator
===========

*************************************************************
*************************************************************/

<!--
function ValidateBootsRegistrationInfo(form) {
	if ( CheckMandatoryFieldsFilled( form, 1, '\'First Name\' field', 2, '\'Last Name\' field', 3, '\'Title\' field', 4, '\'Email\' field',5, '\'Home Phone\' field',6, '\'Mobile Phone\' field',7, '\'Work Phone\' field', 14, '\'User Name\' field', 15, '\'Password\' field', 16, '\'Confirm Password\' field') ) {
		ClearPasswords(form);
		return true;
	} else {
		return false;
	}
}
//-->

/************************************************************
*************************************************************

Function: ValidateBootsPatientInfo(form)
========

Description: Validates patient admin forms
===========

*************************************************************
*************************************************************/


<!--
function ValidateBootsPatientInfo(form) {


	if ( CheckMandatoryFieldsFilled(form, 0, 'forename', 1, 'surname', 2, 'title', 5, 'email address', 6, 'telephone number', 7, 'mobile phone number', 8, 'work phone number') ) {
		if (form.MOD_BOOTS_PATIENT_APPROVED_CHECKBOX.checked) {
			form.MOD_BOOTS_PATIENT_APPROVED.value = 1;
		} else {
			form.MOD_BOOTS_PATIENT_APPROVED.value = 0;
		}

		return true;
	} else {
		return false;
	}
}
//-->

/************************************************************
*************************************************************

Function: CheckDateTimes(form)
========

Description: Checks start datetime is less than end datetime
===========

*************************************************************
*************************************************************/


<!--
function CheckDateTimes(form) {
	var startdate = new Date(form.MOD_BOOKING_CALENDAR_ENTRY_YEAR.value, form.MOD_BOOKING_CALENDAR_ENTRY_MONTH.value, form.MOD_BOOKING_CALENDAR_ENTRY_DAY.value, form.MOD_BOOKING_CALENDAR_ENTRY_START_HOUR.value, form.MOD_BOOKING_CALENDAR_ENTRY_START_MINUTE.value, 0);
	var enddate = new Date(form.MOD_BOOKING_CALENDAR_ENTRY_YEAR.value, form.MOD_BOOKING_CALENDAR_ENTRY_MONTH.value, form.MOD_BOOKING_CALENDAR_ENTRY_DAY.value, form.MOD_BOOKING_CALENDAR_ENTRY_END_HOUR.value, form.MOD_BOOKING_CALENDAR_ENTRY_END_MINUTE.value, 0);

	if ( startdate < enddate ) {
		form.MOD_BOOKING_CALENDAR_ENTRY_START_HOUR.focus();
		return true;
	}

	alert('The start time must be earlier than the end time.');
	return false;

}
//-->


/************************************************************
*************************************************************

Function: ValidateModuleCollectionParameters(form)
========

Description: Updates the manual values if necessary
===========

*************************************************************
*************************************************************/


<!--
function ValidateModuleCollectionParameters(form) {

	if (form.mod_par_type_id.value != '') {
		if (form.mod_par_name_drop.value != '') {
			form.mod_par_name.value = form.mod_par_name_drop.value;
			//alert(form.mod_par_name.value);
			//return false;
			return true;
		} else {
			if (form.mod_par_name_name.value == '' || form.mod_par_name_type.value == '') {
				alert('You must fill in the parameter name');
				form.mod_par_name_drop.focus();
				return false;
			} else {
				form.mod_par_name.value = form.mod_par_name_name.value + '#!' + form.mod_par_name_type.value;
				//alert(form.mod_par_name.value);
				//return false;
				return true;
			}
		}
	} else {
		alert('Please select the parameter type');
		form.mod_par_type_id.focus();
		return false;
	}

	return false;

}
//-->


/************************************************************
*************************************************************

Function: CheckOpenTypeTicked(form)
========

Description: Ensures the Open type box has been ticked
===========

*************************************************************
*************************************************************/

<!--
function CheckOpenTypeTicked(form) {

	if (CheckFontSelected(form) == true){
		if (form.include_open_type.value == "yes") {
			if (!form.open_type_ticked.checked) {
				alert("You must check that your application supports OpenType.");
				return false;
			} else {
				return true;
			}
		}
	}
	else{
		alert("You must select a font to continue")
		return false;
	}

	return true;
}

function CheckFontSelected(form){

	var iNumChecked;

	iNumChecked = 0;
	//alert("Here")
	//alert("Num Fam Lang " + form.number_family_language.value)
	//alert("Num Fam " + form.number_family.value)
	if (form.number_family_language.value != "0" || form.number_family.value != "0"){
		if (form.number_family_language.value > 0){
			for (var i = 0; i<= form.MOD_TYPOGRAPHY_FAMILY_LANGUAGE_ID.length - 1; i++){
					if (form.MOD_TYPOGRAPHY_FAMILY_LANGUAGE_ID[i].checked){
						iNumChecked = iNumChecked + 1
						}
				}
			if (iNumChecked == 0){
				return false;
				}
			else{
				return true;
			}
		}
		else{
			for (var i = 0; i<= form.MOD_TYPOGRAPHY_TYPEFACE_FAMILY_ID.length - 1; i++){
					if (form.MOD_TYPOGRAPHY_TYPEFACE_FAMILY_ID[i].checked){
						iNumChecked = iNumChecked + 1
						}
				}
			if (iNumChecked == 0){
				return false;
				}
			else{
				return true;
			}
		}
	}
	else{
		return true;
	}
return false;
}

function ValidateTypeface(form) {
	var elements = document.getElementsByTagName("input");

	if (form.MOD_TYPOGRAPHY_TYPEFACE_IS_PREPAY.checked) {
		form.MOD_TYPOGRAPHY_TYPEFACE_IS_PREPAY.value = 1;
	} else {
		form.MOD_TYPOGRAPHY_TYPEFACE_IS_PREPAY.value = 0;
	}

	if (form.MOD_TYPOGRAPHY_TYPEFACE_IS_CORPORATE.checked && form.MOD_TYPOGRAPHY_TYPEFACE_CUSTOMER_ACCESS_CODE.value == '') {
		alert('Please fill in the customer access code');
		form.MOD_TYPOGRAPHY_TYPEFACE_CUSTOMER_ACCESS_CODE.focus();
		return false;
	} else {
		if (form.MOD_TYPOGRAPHY_TYPEFACE_IS_PREPAY.value == 1) {
			for(var i = 0; i < elements.length; i++) {
				if (elements.item(i).name == 'MOD_TYPOGRAPHY_FORMAT_ID' && elements.item(i).checked) {
					if (elements.item(i+3).value == '') {
						elements.item(i+3).value = 0;
					}
					if(elements.item(i+2).value=='') {
						alert('Please fill in the download number');
						elements.item(i+2).focus();
						return false;
					}
				}
			}
		} else {
			for(var i = 0; i < elements.length; i++) {
				if (elements.item(i).name == 'MOD_TYPOGRAPHY_FORMAT_ID' && elements.item(i).checked) {
					elements.item(i+3).value = 0;
					elements.item(i+2).value = 0;
				}
			}
		}
	}
	return true;
}

//-->
