window.onload = function() {
//	setFormDefaults();
//	highlightSection();
}


// Highlight current section in main nav

function highlightSection() {
	var strDirStruct = document.location.href.toString();
	if(strDirStruct.indexOf('content') == -1) return;
	var arrDirStruct = strDirStruct.split('/');
	var intSection = arrDirStruct.length-1;
	var strSection = arrDirStruct[intSection];
	while(arrDirStruct[intSection-1] != 'content') {
		intSection += -1;
		strSection = arrDirStruct[intSection];
	}

	var nav = document.getElementById('nav_' + strSection);
	if (nav) {
		nav.className = 'current';
	}
	
}

// Highlight function used to highlight tab when hovering over dropdown menu
function highlight(id,state) {
	var nav,args=highlight.arguments;
	nav = document.getElementById('nav_' + id);
	if (nav && nav.className.indexOf('current') < 0) {
		if (args.length < 2 || state.length == 0) {
			nav.className = 'current';
		}
		else {
			nav.className = state;
		}
	}			
}

// Initialise form by checking each text field for a title element
// and using this to populate the field if no value is supplied
function setFormDefaults(id){
	if( document.getElementById && document.getElementsByTagName ){
		if( document.getElementById(id) ){
			var f = document.getElementById(id);
			var inputs = f.getElementsByTagName( 'input' );
			for( var i=0; i < inputs.length; i++ ){
				if (inputs[i].type.indexOf('text') > -1) {
					if (inputs[i].title) {
						// If field has no value then set value equal to title.	
						// Otherwise set title equal to value 
						if (inputs[i].value == '') {
							inputs[i].value = inputs[i].title;
						}
						else {
							inputs[i].title = inputs[i].value; 
						}

						inputs[i].onfocus = function() {
							return clearField(this);
						}
					}
				}
			}
			f.onsubmit = function() {
				return clearDefaults(this,inputs);
			}
		}
	}
}

function clearField(field) {
	if (field.value == field.title) field.value = '';
}

function clearDefaults(form) {
	var inputs = form.getElementsByTagName( 'input' );
    for( var i=0; i < inputs.length; i++ ){
		if (inputs[i].type.indexOf('text') > -1) {
			clearField(inputs[i]);
		}
	}
}
