// <![CDATA[
/*
* Copyright: 2005 - this.year() CB.Net Ltd IT Department
* Note: All functions below are to make sure that we are sticking to standards and are mainly
* for visual effects and loading events and handlers.
*
* General functions to use across the website, we're using the functionality of prototype.js through here too
* @page validate.search.js
* @version 1.0
* @author Greg Shiers, Jarratt Ingram (CB.Net Ltd)
* @copyright: CB.Net Ltd IT Department 2002 - this.year()
*/

// Lets load all functions that we need to on the load event
Event.observe(window, 'load', function ( event ) {
		/* validate the entity name */
		/* ************************ */
		Event.observe ($('nsc'), 'focus', function () {
			if ( !validation.empty ( $('nsc') ) && ( $('nsc').value.length == 6 ) ) { resetErorr ( $('nsc') );}
		})
		
		Event.observe ($('nsc'), 'blur', function () {
			if ( $('search_button').innerHTML == '<strong>Advanced search</strong>' && validation.empty ( $('nsc') ) ) {
				addError ($('nsc'), 'Please enter an NSC');
			}
			else if ( ( !validation.empty ( $('nsc') ) && !validation.numeric_no_spaces($('nsc') ) ) || ( !validation.empty ( $('nsc') ) && $('nsc').value.length < 6 ) ) {
				addError ($('nsc'), 'NSC must be 6 characters, numbers only');
			}
			else  {
				convertErorr( $('nsc') , 'NSC' )
			}
		})
		
		/* ************************ */
		/* Add a validation script onto the submit event on entity form */
		/* TODO: Investigate if this is the most effective method of validating */
		/* ************************ */
		Event.observe($('search'), "submit" , function( event ){
			var msg = 0;
			if ( $('search_button').innerHTML == '<strong>Advanced search</strong>' && validation.empty ( $('nsc') ) ) {
				addError ($('nsc'), 'Please enter an NSC');
				msg = 1;
			}
			else if ( ( !validation.empty ( $('nsc') ) && !validation.numeric_no_spaces($('nsc') ) ) || ( !validation.empty ( $('nsc') ) && $('nsc').value.length < 6 ) ) {
				addError ($('nsc'), 'NSC must be 6 characters, numbers only');
				msg = 1;
			}
			else  {
				convertErorr( $('nsc') , 'NSC' );
				msg = 0;
			}
			/* check if there are errors and it's set to 1, if set to on, then stop */
			/* the events from submitting the form */
			if ( msg == 1 ) {
				Event.stop ( event );
			}
	});
} , false);
// ]]>