/*	
	EDUCATION FOR CHANGE FORM JAVASCRIPT
	CREATED: 12.09.06
	MODIFIED: 21.09.06
	AUTHOR: ANDY FIELD
*/

/* CONTACT FORM VALIDATION */

function ContactForm(frm) 
{
	if(frm.txtFirstName.value == "") return setFocus(frm.txtFirstName, "Please enter your first name");
	if(frm.txtSurname.value == "") return setFocus(frm.txtSurname, "Please enter your surname");
	if(frm.txtEmail.value == "") return setFocus(frm.txtEmail, "Please enter your email address");
	if(frm.txtEmail.value.indexOf("@") == -1) return setFocus(frm.txtEmail, "Please enter a valid email address which contains an @");
	if(frm.txtEmail.value.indexOf(".") == -1) return setFocus(frm.txtEmail, "Please enter a valid email address with a valid domain name");
	if(frm.ddlHear.selectedIndex == "") return setFocus(frm.ddlHear, "Please tell us how you heard about us");
		
	return true;
}

function Email(frm) 
{
	if(frm.txtTo.value == "") return setFocus(frm.txtTo, "Please enter a valid 'To' email address");
	if(frm.txtTo.value.indexOf("@") == -1) return setFocus(frm.txtTo, "Please enter a valid email address which contains an @");
	if(frm.txtTo.value.indexOf(".") == -1) return setFocus(frm.txtTo, "Please enter a valid email address with a valid domain name");
	if(frm.txtFrom.value == "") return setFocus(frm.txtFrom, "Please enter a valid 'From' email address");
	if(frm.txtFrom.value.indexOf("@") == -1) return setFocus(frm.txtFrom, "Please enter a valid email address which contains an @");
	if(frm.txtFrom.value.indexOf(".") == -1) return setFocus(frm.txtFrom, "Please enter a valid email address with a valid domain name");
		
	return true;
}

function setFocus(f, message)
{
	if( message != "")
	{
		alert(message);
	}
	f.focus();
	return false;
}

/* TEXT AREA TOOGLE */

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		oldonload();
		func();
		}
	}
}

addLoadEvent(toggleComment);

function toggleComment(){
	
	// if browser doesn't support this method, return false
	if(!document.getElementById) return false;
	
	// create the anchor content and element
	var linkText = document.createTextNode('Make text area larger');
	var toggleLink = document.createElement('a');
	toggleLink.href = 'javascript:void(null)';
	toggleLink.appendChild(linkText);
	
	//create a paragraph element for the anchor to live in
	var linkPara = document.createElement('p');
	linkPara.setAttribute('id','toggle');
	linkPara.appendChild(toggleLink);
	
	// Get a reference to the comment input and it's parent fieldset
	var commentArea = document.getElementById('txtMessage');
	var commentFieldset = commentArea.parentNode.parentNode;
	
	//place the paragraph element at the end of the comment fieldset
	commentFieldset.appendChild(linkPara);
	
	// set the callback function
	toggleLink.onclick = function(){
		var theText = this.firstChild;
		var newText;
		var commentField = document.getElementById('txtMessage');
		
		if(theText.nodeValue == 'Make text area larger'){
			// make the height of the comment input bigger
			//commentField.setAttribute('class','bigComment');
			commentField.style.height = '20em';
			
			// I was origionally setting the nodevalue of the anchor text.
			// however the size of the node wasn't changing, so I figured I'd have to
			// use the replace child method instead
			newText = document.createTextNode('Make text area smaller');
			this.replaceChild(newText,theText);
			
		} else {
			// return the comment input to it's default html size
			// rather than directly changing the size, it would probably be better
			//to change the class. Thus seporating the display from the logic
			//commentField.setAttribute('class','smallComment');
			commentField.style.height = '10em';
			newText = document.createTextNode('Make text area larger');
			this.replaceChild(newText,theText);
			
		}

	}
		
}