var iMaxChars = 50;
var sHelpTotalLength = 'Enter total length in metres and cm\'s (for example 2.4) for up to 3 distinct runs. For more than 3 runs please calculate the first three and then repeat the exercise. The Ready Reckoner will round part panels up to the nearest full panel for estimating purposes, but the confirmed price will be adjusted for unused materials if you invite us to prepare a written quotation.';
var sHelpPanelType = 'Choose your total height including lattice if applicable. Panels can be cut to any height on site but select your nearest greater height to calculate material costs.';
var sHelpColour = 'Black and other special order colours are subject to a 35% materials surcharge, and have an 8 week minimum lead time.';
var sHelpSquarePosts = 'Square posts are an optional extra sometimes used at the start and end of a run, or for major changes in direction. If in doubt leave blank or contact us for further advice.';
var sHelpGatesSingle = 'Up to 90cm wide, price includes posts, lock and standard fitting.';
var sHelpGatesDouble = 'Up to 160 cm wide, price includes posts, lock and standard fitting.';
var sHelpGatesDriveway = 'Double gate up to 360cm opening, price includes posts, lock and standard fitting.';
var sHelpApproxFitting = 'Labour charges can be an approximation only. The labour element can only be confirmed subject to survey. Clearing and disposal if required are chargeable extras.';
var sHelpSubmit = 'If you wish to us to contact you to a arrange a convenient time for a no obligation site survey and written estimate, please submit.';			

function numeric_action_controller(sFieldName, bIncrement)
{
	var oTargetField = document.forms['rr_form'].elements[sFieldName];
	if (oTargetField == null) return;
	if (oTargetField.value == 'NaN') { oTargetField.value = 0; return; }
	var value = parseInt(oTargetField.value);
	if (typeof value != 'number') { oTargetField.value = 0; return; }
	if (value < 0) { oTargetField.value = 0; return; };
	if ( bIncrement && (value >= 999) ) return;
	if ( (bIncrement == false) && (value == 0) ) return;
	value += (bIncrement) ? 1 : -1;
	oTargetField.value = value;
}

function length_force_numeric(oTextField)
{
	var validChars = '0123456789.';
	for(var i=0; i < oTextField.value.length; i++)
	{
		if ( validChars.indexOf(oTextField.value.charAt(i)) == -1) {
			alert("Please enter a numeric number only.");
			oTextField.focus();
			return;
		}
	}
}

String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, '');
}

String.prototype.ltrim = function() {
	return this.replace(/^\s*/g, '');
}

String.prototype.rtrim = function() {
	return this.replace(/\s*$/g, '');
}

function newlinealize(sText, iMaxCharsOnLine)
{
	var aShortStrings = sText.split(' ');
	var iCharCount = 0;
	var sNewText = '';
	for (var i=0; i < aShortStrings.length; i++)
	{
		iCharCount += aShortStrings[i].length;
		if (iCharCount > iMaxCharsOnLine) {
			sNewText = sNewText.rtrim();
			sNewText += '\n';
			iCharCount = aShortStrings[i].length;
		}
		sNewText += aShortStrings[i] + ' ';
	}
	return sNewText;
}

function numerics_only(oEvent)
{
	if ( ( (oEvent.keyCode == 8) || ( (oEvent.keyCode >= 48) && (oEvent.keyCode <= 57) ) ) == false)
	{
		oEvent.returnValue = false;
	}
}