// JavaScript Document


/*
Javascript function - make hidden prompt messages visible
---------------------------------------------------------------------------------------------
																								Needs to be parameterised for more general use
	Function is called by an onchange/onkeyup/onmouseup in each SlickForms form element 
	Give the prompts id="savePrompt[i]"
	Initially style prompts as #savePrompt[i] {visibility: hidden [; other elements]}
	OK to add statements to the function
	Statements can style other attributes (eg -.style.backgroundColor='#ffff00';)
*/
	function saveMsg() {
		document.getElementById('savePrompt1').style.visibility='visible';
		document.getElementById('savePrompt2').style.visibility='visible';
	}  	


/*
Javascript functions - maxlength for textareas
---------------------------------------------------------------------------------------------
from www.quirksmode.org
	setMaxLength() - called after the form - implements a maxlength equivalent for 
	textareas (which don't have maxlength in HTML). It reads the maxlength attribute in each
	textarea (which is ignored by HTML), counts characters and feeds the results to the counter 
	that appears below the textarea (all built into pSFTexta in .asp file).
*/


	function setMaxLength() {
		var x = document.getElementsByTagName('textarea');
		var counter = document.createElement('div');
		counter.className = 'counter';
		for (var i=0;i<x.length;i++) {
			if (x[i].getAttribute('maxlength')) {
				var counterClone = counter.cloneNode(true);
				counterClone.relatedElement = x[i];
				counterClone.innerHTML = '<p class="cue"><span>0</span> used of '+ x[i].getAttribute('maxlength') 
					+ ' characters allowed</p>';
				x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
				x[i].relatedElement = counterClone.getElementsByTagName('span')[0];
	
				x[i].onkeyup = x[i].onchange = checkMaxLength;
				x[i].onkeyup();
			}
		}
	}
	
	function checkMaxLength() {
		var maxLength = this.getAttribute('maxlength');
		var currentLength = this.value.length;
		if (currentLength > maxLength)
			this.relatedElement.className = 'toomuch';
		else
			this.relatedElement.className = '';
		this.relatedElement.firstChild.nodeValue = currentLength;
		// not innerHTML
	}
