/*

 *****************************************************************************************
 * File name      : /javascript/gts.js   	                                               *
 * Description    : Javascript                                                   	       *
 *****************************************************************************************

*/

// --------------------------------------------------------------------------------------------


/*
	Print page function
*/


// --------------------------------------------------------------------------------------------

function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}

// --------------------------------------------------------------------------------------------


/*
	Open pop-up window function
*/


// --------------------------------------------------------------------------------------------

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// --------------------------------------------------------------------------------------------


/*
	Fading Scroller- By DynamicDrive.com
	For full source code, and usage terms, visit http://www.dynamicdrive.com
	This notice MUST stay intact for use
	Heavily modified by Flagship Information Systems Ltd http://www.theflagship.co.uk
*/


// --------------------------------------------------------------------------------------------

function _fadingContent_ChangeContent( faderName ) {

	if ( faderName.index >= faderName.fcontent.length ) {
		faderName.index = 0;
	}

	if (DOM2) {

		document.getElementById(faderName.id).style.color = faderName.startcolor;		
		document.getElementById(faderName.id).innerHTML = faderName.begintag + faderName.fcontent[faderName.index] + faderName.closetag;

		linksobj = document.getElementById(faderName.id).getElementsByTagName("A");
		
		if (faderName.fadelinks) {
			_fadingContent_LinkColorChange( linksobj, faderName );
		}
		
		_fadingContent_ColorFade( faderName );
	}
	else {

		if (ie4) {

			document.all[faderName.id].innerHTML = faderName.begintag + faderName.fcontent[faderName.index] + faderName.closetag;
		}
		else if (ns4) {

			document.fscrollerns.document.fscrollerns_sub.document.write(faderName.begintag+faderName.fcontent[faderName.index]+faderName.closetag);
			document.fscrollerns.document.fscrollerns_sub.document.close();
		}
	}

	faderName.index++;
	faderName.x = setTimeout( '_fadingContent_ChangeContent_2('+faderName.name+')', ( faderName.delay + faderName.faderdelay ) );

}

// --------------------------------------------------------------------------------------------

function _fadingContent_ChangeContent_2( faderName ) {

	// this pseudo function is used by setTimeout to enable the 'faderName' object to be passed as a parameter
	_fadingContent_ChangeContent( faderName );
	
}

// --------------------------------------------------------------------------------------------

function _fadingContent_ColorFade_2( faderName ) {

	// this pseudo function is used by setTimeout to enable the 'faderName' object to be passed as a parameter
	_fadingContent_ColorFade( faderName );
	
}

// --------------------------------------------------------------------------------------------

function _fadingContent( width, height, id, fcontent, myName ) {

	ie4 = document.all && !document.getElementById;
	ns4 = document.layers;
	DOM2 = document.getElementById;

	this.begintag = '<font face="Arial" size=1>'; //set opening tag, such as font declarations
	this.closetag = '</font>';
	this.delay = 3000; //set delay between message change (in miliseconds)
	this.endcolor = (this.fadescheme ==0 ) ? "rgb(51,51,51)" : "rgb(255,255,255)";
	this.fadelinks = 1; //should links inside scroller content also fade like text? 0 for no, 1 for yes.
	this.faderdelay = 0;
	this.fadescheme = 0; //set 0 to fade text color from (white to black), 1 for (black to white)
	this.fcontent = fcontent;
	this.fheight = height; //set scroller height
	this.frame = 20;
	this.fwidth = width; //set scroller width
	this.hex = (this.fadescheme == 0) ? 255 : 0;
	this.hex1 = 0;
	this.hex2 = 51;
	this.hex3 = 51;
	this.id = id;
	this.index = 0;
	this.name = myName;
	this.startcolor = (this.fadescheme == 0) ? "rgb(255,255,255)" : "rgb(0,0,0)";
	this.x = 0;

	if (DOM2) {
		this.faderdelay = 2000;
	}


	if ( ie4 || DOM2 ) {
		document.write('<div id="' + this.id + '" style="border:1px;width:'+this.fwidth+';height:'+this.fheight+';padding:2px"></div>');
	}

	return this;
}


// --------------------------------------------------------------------------------------------


function _fadingContent_LinkColorChange( linksobj, faderName ) {

	if (linksobj.length > 0){

		for ( i=0; i < linksobj.length; i++) {

			linksobj[i].style.color = "rgb("+faderName.hex1+","+faderName.hex2+","+faderName.hex3+")";
		}
	}
}


// --------------------------------------------------------------------------------------------


function _fadingContent_ColorFade( faderName ) {	         	

	// 20 frames fading process
	if (faderName.frame > 0) {	

		faderName.hex = (faderName.fadescheme == 0)? faderName.hex-12 : faderName.hex+12; // increase or decrease color value depd on fadescheme
		document.getElementById(faderName.id).style.color = "rgb("+faderName.hex+","+faderName.hex+","+faderName.hex+")"; // Set color value.

		if (faderName.fadelinks) {
			linksobj = document.getElementById(faderName.id).getElementsByTagName("A");
			_fadingContent_LinkColorChange( linksobj, faderName );
		}

		--faderName.frame;

		faderName.x = setTimeout( '_fadingContent_ColorFade_2('+faderName.name+')', 250 );	
	}
	else {

		document.getElementById(faderName.id).style.color = faderName.endcolor;
		faderName.frame = 20;
		faderName.hex = (faderName.fadescheme == 0) ? 255 : 0;
	}   

}


// --------------------------------------------------------------------------------------------

function _isblank( s ) {

	// check whether a text field has been left blank
	for ( var i = 0; i < s.length; i++ ) { 
		var c = s.charAt(i);
		if ( ( c != ' ' ) && ( c != '\n' ) && ( c != '\t' ) ) return false;
	}
	
	return true;	
}


// --------------------------------------------------------------------------------------------

// this is for debugging only

function _listFormElements(f) {

	// a debugging routine to list form elements

	debugWindow = window.open( '', 'debug' );
		
	var msg = '';
	
	for ( var i = 0; i < f.length; i++ ) {
		
		var e = f.elements[i];
		msg += 'Name = ' + e.name + ', Type = ' + e.type + ', Value = ' + e.value + '<br>';
				
	}

	debugWindow.document.write( msg );
}


// -------------------------------------------------------------------------------------

function _pageReload( formName ) {
	
	// this is a general routine that instructs a page to reload
	
	var f = document.forms[formName];	

	f.form_action.value = 'PageReload';
	f.submit();	
	
}

// -------------------------------------------------------------------------------------

function _toggleDivDisplay(divId) {
	// divOpen = true if the DIV is currently displayed
	var divIsOpen = document.all.item(divId).style.display == 'block';

	// toggle the DIV visible/hidden
	document.all.item(divId).style.display = divIsOpen ? 'none' : 'block';
	
	// change the display/hide IMG src
	document['toggle'+divId].src = divIsOpen ? toggleClosed.src : toggleOpened.src;
	
	// change the display/hide IMG alt text
	document.images['toggle'+divId].alt = divIsOpen ? 'click here to display this section' : 'click here to hide this section';
	
	// reposition the page to fully show the DIV
	document.location.href = '#anchor' + divId;
	
}

// --------------------------------------------------------------------------------------------

function _validText( formname, textField, showAlert ) {

	// check that text fields are completed
	
	var validText = Boolean(0);
	var f = document.forms[formname];
	var text = f.elements[textField[0]].value;

	if ( arguments.length == 2 ) {
		showAlert = Boolean(1);
	}
	
	if ( text == null || _isblank(text) || text == '' ) {
		
		// text field no completed
		validText = Boolean(0);
		if ( showAlert ) {
			alert( 'Please complete the ' + textField[1] + ' field.' );
		}
	}
	else {
		
		// text field has been completed
		validText = Boolean(1);
	}

	return validText;
}


// -------------------------------------------------------------------------------------

function articles_add( formName ) {

/*
	Called from /ccc/articles.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	

	formErrors = Boolean(0);

	formErrors = articles_validate( formName );

	// if no errors found, submit the form
	if ( ! formErrors ) {		
		f.form_action.value = 'ArticleAdd';
		f.submit();	
	}

}


// -------------------------------------------------------------------------------------

function articles_delete( formName ) {

/*
	Called from /ccc/articles.php
*/

	var f = document.forms[formName];	

	if ( confirm( 'Do you want to DELETE this Article record?' ) ) {		
		f.form_action.value = 'ArticleDelete';
		f.submit();
	}
	else {
		alert( 'Record not deleted!' );
	}
}


// -------------------------------------------------------------------------------------

function articles_find( formName ) {

/*
	Called from /ccc/articles.php
*/

	var f = document.forms[formName];	

	if ( f.find_artID.selectedIndex > 0 ) {

		f.db_artID.value = f.find_artID.value;		
		f.form_action.value = 'ArticleFind';
		f.submit();
		
	}	
}


// -------------------------------------------------------------------------------------

function articles_update( formName ) {

/*
	Called from /ccc/articles.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	
	
	formErrors = Boolean(0);

	formErrors = articles_validate( formName );
	
	if ( ! formErrors ) {

		// if no errors found, submit the form
		f.form_action.value = 'ArticleUpdate';
		f.submit();	

	}

}


// -------------------------------------------------------------------------------------

function articles_validate( formName ) {

	// called by articles_add() and articles_update() to validate the field entries

	var f = document.forms[formName];

	formErrors = Boolean(0);

	// check that a division has been selected
	if ( f.db_artDivID.selectedIndex == 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select a Division' );
	}	

	// check that a category has been selected
	if ( f.db_artCatID.selectedIndex == 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select a Category' );
	}	
	
	// Title 
	if ( ! _validText( formName, Array('db_artTitle','Article Title'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Full Text
	if ( ! _validText( formName, Array('db_artFullText','Article Text'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	return formErrors;

}


// -------------------------------------------------------------------------------------

function cart_complete( formName ) {
	
	// validate and email the contents of the payment form and the cart to Grosvenor
	
	cartErrors = '';
	
	var f = document.forms[formName];	

	// validate the payment form and cart before processing further
	if ( cart_validate( formName ) ) {	

		f.form_action.value = 'CartComplete';
		f.submit();
	}
	else {
		
		alert( 'Sorry, your payment details are incomplete.\nPlease include the following information:\n\n' + cartErrors )
	}
	
}


// -------------------------------------------------------------------------------------

function cart_display( formName ) {

	// re-call the shopping cart display page

	var f = document.forms[formName];	
	
		f.form_action.value = 'CartDisplay';
		f.submit();
	
}


// -------------------------------------------------------------------------------------

function cart_payment( formName ) {
	
	// update the cart and proceed to the payment page

	var f = document.forms[formName];	

	f.form_action.value = 'CartPayment';
	f.submit();
		
}


// -------------------------------------------------------------------------------------

function cart_update( formName ) {
	
	// update the shopping cart

	var f = document.forms[formName];	

	f.form_action.value = 'CartUpdate';
	f.submit();
	
}


// -------------------------------------------------------------------------------------

function cart_validate( formName ) {
	
	// validate the cart

	var f = document.forms[formName];		
	var cartOK = true;
	
	// check that the following fields have been completed on the payment form
	fieldList = new Array( 	
		Array( 'paytFirstName', 'First name' ),
		Array( 'paytLastName', 'Last name' ),
		Array( 'paytAddress1', 'Address' ),
		Array( 'paytZipPostCode', 'ZIP / Postcode' ),
		Array( 'paytCountry', 'Country' ),
		Array( 'paytTelephoneNo', 'Telephone No.' ),
		Array( 'paytEmail', 'Email Address' ),
		Array( 'paytCardNumber', 'Payment Card Number' )	
	)
	
	for ( inputField in fieldList ) {

		if ( ! _validText( formName, fieldList[inputField], false ) ) {

			cartErrors += fieldList[inputField][1] + '\n';
			cartOK = false;
		}
		
	}

	// validate the email address
	// thanks to http://www.javascriptkit.com/script/script2/acheck.shtml
	
	var str = f.paytEmail.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	if ( ! filter.test(str) ) {
		cartErrors += "\nYour email address is not correct";
		cartOK = false;
	}

	return cartOK;	
}


// -------------------------------------------------------------------------------------

function cats_add( formName ) {

/*
	Called from /ccc/categories.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	

	formErrors = Boolean(0);

	formErrors = cats_validate( formName );

	// if no errors found, submit the form
	if ( ! formErrors ) {		
		f.form_action.value = 'CategoryAdd';
		f.submit();	
	}

}


// -------------------------------------------------------------------------------------

function cats_delete( formName ) {

/*
	Called from /ccc/categories.php
*/

	var f = document.forms[formName];	

	if ( confirm( 'Do you want to DELETE this sub-category record?' ) ) {		

		f.form_action.value = 'CategoryDelete';
		f.submit();
	}
	else {

		alert( 'Record not deleted!' );
	}
}


// -------------------------------------------------------------------------------------

function cats_find( formName ) {

/*
	Called from /ccc/categories.php
*/

	var f = document.forms[formName];	

	if ( f.find_catID.selectedIndex > 0 ) {

		f.db_catID.value = f.find_catID.value;	
		f.form_action.value = 'CategoryFind';
		f.submit();
		
	}
		
}


// -------------------------------------------------------------------------------------

function cats_update( formName ) {

/*
	Called from /ccc/categories.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	
	
	formErrors = Boolean(0);

	formErrors = cats_validate( formName );
	
	if ( ! formErrors ) {

		// if no errors found, submit the form
		f.form_action.value = 'CategoryUpdate';
		f.submit();	

	}

}


// -------------------------------------------------------------------------------------

function cats_validate( formName ) {

	// called by cats_add() and cats_update() to validate the field entries

	var f = document.forms[formName];

	formErrors = Boolean(0);
	
	// check that a category has been selected
	if ( f.find_catID.selectedIndex == 0 ) {
		alert( 'Please select a Category from the list' );
		formErrors = Boolean(1);
	}
	
	// Category Name
	if ( ! _validText( formName, Array('db_catName','Category Name'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
		
	return formErrors;

}


// -------------------------------------------------------------------------------------

function courses_add( formName ) {

/*
	Called from /ccc/courses.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	

	formErrors = Boolean(0);

	formErrors = courses_validate( formName );

	// if no errors found, submit the form
	if ( ! formErrors ) {		
		f.form_action.value = 'CourseAdd';
		f.submit();	
	}

}


// -------------------------------------------------------------------------------------

function courses_delete( formName ) {

/*
	Called from /ccc/courses.php
*/

	var f = document.forms[formName];	

	if ( confirm( 'Do you want to DELETE this Course record?' ) ) {		
		f.form_action.value = 'CourseDelete';
		f.submit();
	}
	else {
		alert( 'Record not deleted!' );
	}
}


// -------------------------------------------------------------------------------------

function courses_find( formName ) {

/*
	Called from /ccc/courses.php
*/

	var f = document.forms[formName];	

	if ( f.find_crsID.selectedIndex > 0 ) {

		f.db_crsID.value = f.find_crsID.value;
		f.form_action.value = 'CourseFind';
		f.submit();
		
	}
	
}


// -------------------------------------------------------------------------------------

function courses_update( formName ) {

/*
	Called from /ccc/courses.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	
	
	formErrors = Boolean(0);

	formErrors = courses_validate( formName );
	
	if ( ! formErrors ) {

		// if no errors found, submit the form
		f.form_action.value = 'CourseUpdate';
		f.submit();	

	}

}


// -------------------------------------------------------------------------------------

function courses_validate( formName ) {

	// called by courses_add() and courses_update() to validate the field entries

	var f = document.forms[formName];

	formErrors = Boolean(0);

	// check that a division has been selected
	if ( f.db_crsDivID.selectedIndex == 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select a Division' );
	}	

	// check that a category has been selected
	if ( f.db_crsCatID.selectedIndex == 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select a Category' );
	}	
	
	// Title 
	if ( ! _validText( formName, Array('db_crsTitle','Course Title'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Description
	if ( ! _validText( formName, Array('db_crsDescription','Course Text'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Duration
	if ( ! _validText( formName, Array('db_crsDuration','Course Duration'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Who should attend
	if ( ! _validText( formName, Array('db_crsAttend','Course Attenders'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Objectives
	if ( ! _validText( formName, Array('db_crsObjectives','Course Objectives'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Pricing
	if ( ! _validText( formName, Array('db_crsPricing','Course Pricing'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Country
	if ( ! f.db_crsCountry[0].checked && ! f.db_crsCountry[1].checked ) {
		formErrors = Boolean(1);
		alert( 'Please indicate whether this is a UK or US course' );
	}
	
	return formErrors;

}


// -------------------------------------------------------------------------------------

function crossrefs_add( formName, crefFromType, crefFromID ) {
	
	// cross-reference the current item with the item selected
	
	var f = document.forms[formName];

	// check that an article, course or news story is on display
	
	if ( crefFromID == 0 ) { 

		switch ( crefFromType ) {
		
			case 1:
				var itemType = 'an article';
				break;
				
			case 2:
				var itemType = 'a course';
				break;
				
			case 3:
				var itemType = 'a news story';
				break;
				
		}
		
		alert( 'You have not loaded ' + itemType + ' yet!' );
	}
	else {

		// check that a Type and an Item have been selected

		if ( f.cref_itemType.selectedIndex == 0 || f.cref_itemList.selectedIndex == 0 ) {

			alert( 'Please select a Type and an Item' );
		}
		else {

			// check that the user is not trying to link the current item to itself

			if ( crefFromType == f.cref_itemType.value && crefFromID == f.cref_itemList.value ) {

				alert( 'You cannot cross-reference this item to itself!' );
			}
			else {

				// process the request
				f.form_action.value = 'CrefAdd';
				f.submit();
			}	
		}
	}

}


// -------------------------------------------------------------------------------------

function crossrefs_byCat( formName ) {
	
	// select records to display based on the chosen category
	
	var f = document.forms[formName];
	
	// reset the CREF division <select>
	f.cref_divID.selectedIndex = 0;
	
	if ( f.cref_catID.selectedIndex > 0 ) {
		f.form_action.value = 'CrefSelect';
		f.submit();
	}
	
}


// -------------------------------------------------------------------------------------

function crossrefs_byDiv( formName ) {
	
	// select records to display based on the chosen division
	
	var f = document.forms[formName];
	
	// reset the CREF category <select>
	f.cref_catID.selectedIndex = 0;
	
	if ( f.cref_divID.selectedIndex > 0 ) {
		f.form_action.value = 'CrefSelect';
		f.submit();
	}
	
}


// -------------------------------------------------------------------------------------

function crossrefs_delete( formName, crefID ) {
	
	// delete a linked cross-reference
	
	var f = document.forms[formName];	
	
	if ( confirm( 'Delete this cross-reference?' ) ) {
		
		f.form_action.value = 'CrefDelete';
		f.crefID.value = crefID;
		f.submit();	
	}
	
}


// -------------------------------------------------------------------------------------

function crossrefs_listItemTypes( formName ) {
	
	// regenerate the <select> list of item types, showing the number of items found per type	
	
	var f = document.forms[formName];

	// initialise the items select object
	f.elements['cref_itemType'].options.length = 0;	
		
	// create a default option
	var opt = new Option();
	opt.value = 0;
	opt.text = 'Item type';
	f.cref_itemType.options[0] = opt;
	
	// add each of the 3 item types
	for ( var cntr = 1; cntr < 4; ++cntr ) {
		
		var opt = new Option();
		opt.value = cntr;
		
		switch ( cntr ) {
			case 1:
				opt.value = cntr;
				opt.text =  'Articles (' + crossref_list['count'][cntr] + ')';
				break;

			case 2:
				opt.value = cntr;
				opt.text =  'Courses (' + crossref_list['count'][cntr] + ')';
				break;

			case 3:
				opt.value = cntr;
				opt.text =  'News stories (' + crossref_list['count'][cntr] + ')';
				break;

		}
			
		f.cref_itemType.options[cntr] = opt;
	
	}
	
}


// -------------------------------------------------------------------------------------

function crossrefs_listType( formName ) {
	
	// re-populate the item <select> list with the articles/courses/news items
	
	var f = document.forms[formName];

	// initialise the items select object
	f.elements['cref_itemList'].options.length = 0;	
	
	// create a default option
	var opt = new Option();
	opt.value = 0;

	var listType = f.cref_itemType.selectedIndex;
	
	switch( listType ) {
		
		case 0:
			opt.text = 'Please select an item type';
			break;
			
		case 1:
			opt.text = ( crossref_list['count'][listType] == 0 ? 'No articles' : 'Please select an article' );
			break;
			
		case 2:
			opt.text = ( crossref_list['count'][listType] == 0 ? 'No courses' : 'Please select a course' );
			break;
			
		case 3:
			opt.text = ( crossref_list['count'][listType] == 0 ? 'No news stories' : 'Please select a news story' );
			break;
			
	}
	
	f.cref_itemList[0] = opt;

	// if the item type selected > 0 then populate the itemList with the items

	if ( listType > 0 ) {
		
		var newOpts = 0;
		
		for ( var itemX in crossref_list[listType] ) {
			
			var opt = new Option();
			opt.text = crossref_list[listType][itemX].name;
			opt.text = opt.text.slice(0,25);
			opt.value = itemX;

			f.cref_itemList.options[++newOpts] = opt;

		}
	}
	
}


// -------------------------------------------------------------------------------------

function news_add( formName ) {

/*
	Called from /ccc/news.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	

	formErrors = Boolean(0);

	formErrors = news_validate( formName );

	// if no errors found, submit the form
	if ( ! formErrors ) {		
		f.form_action.value = 'NewsAdd';
		f.submit();	
	}

}


// -------------------------------------------------------------------------------------

function news_delete( formName ) {

/*
	Called from /ccc/news.php
*/

	var f = document.forms[formName];	

	if ( confirm( 'Do you want to DELETE this News record?' ) ) {		
		f.form_action.value = 'NewsDelete';
		f.submit();
	}
	else {
		alert( 'Record not deleted!' );
	}
}


// -------------------------------------------------------------------------------------

function news_find( formName ) {

/*
	Called from /ccc/news.php
*/

	var f = document.forms[formName];	

	if ( f.find_newsID.selectedIndex > 0 ) {

		f.db_newsID.value = f.find_newsID.value;	
		f.form_action.value = 'NewsFind';
		f.submit();
		
	}
		
}


// -------------------------------------------------------------------------------------

function news_update( formName ) {

/*
	Called from /ccc/news.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	
	
	formErrors = Boolean(0);

	formErrors = news_validate( formName );
	
	if ( ! formErrors ) {

		// if no errors found, submit the form
		f.form_action.value = 'NewsUpdate';
		f.submit();	

	}

}


// -------------------------------------------------------------------------------------

function news_validate( formName ) {

	// called by news_add() and news_update() to validate the field entries

	var f = document.forms[formName];

	formErrors = Boolean(0);

	// check that a division has been selected
	if ( f.db_newsDivID.selectedIndex == 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select a Division' );
	}	

	// check that a category has been selected
	if ( f.db_newsCatID.selectedIndex == 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select a Category' );
	}	
	
	// Headline
	if ( ! _validText( formName, Array('db_newsHeadline','News Headline'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Story
	if ( ! _validText( formName, Array('db_newsStory','News Story'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	return formErrors;

}


// -------------------------------------------------------------------------------------

function orders_delete( formName ) {

	// delete a sales order
	
	var f = document.forms[formName];	

	f.form_action.value = 'OrdersDelete';
	f.submit();
	
}


// -------------------------------------------------------------------------------------

function orders_find( formName ) {

	// find a sales order
	
	var f = document.forms[formName];	

	f.form_action.value = 'OrdersFind';
	f.submit();
	
}


// -------------------------------------------------------------------------------------

function pagetext_add( formName ) {

	// an ADD function is not required for page text

}

// -------------------------------------------------------------------------------------

function pagetext_delete( formName ) {

	// a DELETE function is not required for page text

}


// -------------------------------------------------------------------------------------

function pagetext_find( formName ) {

/*
	Called from /ccc/pagetext.php
*/

	var f = document.forms[formName];	

	if ( f.find_pageID.selectedIndex > 0 ) {

		f.db_pageID.value = f.find_pageID.value;	
		f.form_action.value = 'PagetextFind';
		f.submit();
		
	}
		
}


// -------------------------------------------------------------------------------------

function pagetext_update( formName ) {

/*
	Called from /ccc/pagetext.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	
	
	formErrors = Boolean(0);

	formErrors = pagetext_validate( formName );
	
	if ( ! formErrors ) {

		// if no errors found, submit the form
		f.form_action.value = 'PagetextUpdate';
		f.submit();	

	}

}


// -------------------------------------------------------------------------------------

function pagetext_validate( formName ) {

	// called by pagetext_add() and pagetext_update() to validate the field entries

	var f = document.forms[formName];

	formErrors = Boolean(0);

	// Check that either a Category xor a Division xor the Company checkbox has been selected
	if ( f.db_pageCatID.selectedIndex == 0 && f.db_pageDivID.selectedIndex == 0 && ! f.db_pageCompanyOnly.checked ) {
		formErrors = Boolean(1);
		alert( 'Please select a Category, a Division or the Company flag' );
	}

	// Check that only one of either a Category xor a Division has been selected
	if ( f.db_pageCatID.selectedIndex > 0 && f.db_pageDivID.selectedIndex > 0 ) {
		formErrors = Boolean(1);
		alert( 'Please select either a Category or a Division - not both' );
	}

	// Check that the Company flag hasn't beed selected as well as one of either a Category or a Division
	if ( ( f.db_pageCompanyOnly.checked && f.db_pageCatID.selectedIndex > 0 ) || ( f.db_pageCompanyOnly.checked &&  f.db_pageDivID.selectedIndex > 0 ) ) {
		formErrors = Boolean(1);
		alert( 'Please do not select the Company flag and a Category or a Division' );
	}

	// Page Text
	if ( ! _validText( formName, Array('db_pageFullText','Page'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Metatag Title
	if ( ! _validText( formName, Array('db_pageMetaTitle','Metatag Title'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Metatag Description
	if ( ! _validText( formName, Array('db_pageMetaDesc','Metatag Description'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Metatag Keywords
	if ( ! _validText( formName, Array('db_pageMetaKeywords','Metatag Keywords'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}

	// Optional fields pageQuoteText and pageQuoteName	
	
	return formErrors;

}


// -------------------------------------------------------------------------------------

function weblink_add( formName ) {

/*
	Called from /ccc/weblinks.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	

	formErrors = Boolean(0);

	formErrors = weblink_validate( formName );

	// if no errors found, submit the form
	if ( ! formErrors ) {		
		f.form_action.value = 'WeblinkAdd';
		f.submit();	
	}

}


// -------------------------------------------------------------------------------------

function weblink_delete( formName ) {

/*
	Called from /ccc/weblinks.php
*/

	var f = document.forms[formName];	

	if ( confirm( 'Do you want to DELETE this web link record?' ) ) {		

		f.form_action.value = 'WeblinkDelete';
		f.submit();
	}
	else {

		alert( 'Record not deleted!' );
	}
}


// -------------------------------------------------------------------------------------

function weblink_find( formName ) {

/*
	Called from /ccc/weblinks.php
*/

	var f = document.forms[formName];	

	if ( f.find_linkID.selectedIndex > 0 ) {

		f.db_linkID.value = f.find_linkID.value;	
		f.form_action.value = 'WeblinkFind';
		f.submit();
		
	}
		
}


// -------------------------------------------------------------------------------------

function weblink_update( formName ) {

/*
	Called from /ccc/weblinks.php
	Validate fields, set the form_action variable and submit the form
*/

	var f = document.forms[formName];	
	
	formErrors = Boolean(0);

	formErrors = weblink_validate( formName );
	
	if ( ! formErrors ) {

		// if no errors found, submit the form
		f.form_action.value = 'WeblinkUpdate';
		f.submit();	

	}

}


// -------------------------------------------------------------------------------------

function weblink_validate( formName ) {

	// called by weblink_add() and weblink_update() to validate the field entries

	var f = document.forms[formName];

	formErrors = Boolean(0);
	
	// URL
	if ( ! _validText( formName, Array('db_linkUrl','Weblink URL'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Description
	if ( ! _validText( formName, Array('db_linkDescription','Weblink Description'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
	
	// Title
	if ( ! _validText( formName, Array('db_linkTitle','Weblink Title'), Boolean(1) ) ) {
		formErrors = Boolean(1);
	}
		
	return formErrors;

}

