/*
*  Autofill Function
*/
var comdir_yourInfo_autofill = "For us to contact you...";
var comdir_description_autofill = "Please enter a brief (800 characters or less) description of the organisation (text only, no HTML, line breaks, or formatting)...";
var comdir_keywords_autofill = "Words for the organisation to be found by...";
var comdir_organisationInfo_autofill = "To be displayed with your listing...";
var comdir_geoInfo_autofill = "For geographical searching...";

function comdir_clearAutofill(id,type) {
	if(id == null || id == "" || type == null || type == "")
		return;
	var input = document.getElementById(id);
	if(input != null && type != null)
		switch(type) {
			case "YourInfo": if(input.value == comdir_yourInfo_autofill) input.value = ""; input.style.color = "#000000"; break;
			case "Description": if(input.value == comdir_description_autofill) input.value = ""; input.style.color = "#000000"; break;
			case "Keywords": if(input.value == comdir_keywords_autofill) input.value = ""; input.style.color = "#000000"; break;
			case "OrganisationInfo": if(input.value == comdir_organisationInfo_autofill) input.value = ""; input.style.color = "#000000"; break;
			case "GeoInfo": if(input.value == comdir_geoInfo_autofill) input.value = ""; input.style.color = "#000000"; break;
		}
}

function comdir_populateAutofill() {
	var override = arguments[0] == true;
	var all_inputs = document.getElementsByTagName('input');
	for(var i=0;i<all_inputs.length;i++) {
		var input = all_inputs[i];
		switch(input.getAttribute('comdir_autofill')) {
			case 'YourInfo': 
				if(override || input.value == comdir_yourInfo_autofill || input.value == "" || input.value == null) {
					input.value = comdir_yourInfo_autofill;
					input.style.color = "#999999"; 
				}
			break;
			case 'Keywords': 
				if(override || input.value == comdir_keywords_autofill || input.value == "" || input.value == null) {
					input.value = comdir_keywords_autofill;
					input.style.color = "#999999"; 
				}
			break;
			case 'OrganisationInfo':
				if(override || input.value == comdir_organisationInfo_autofill || input.value == "" || input.value == null) {
					input.value = comdir_organisationInfo_autofill;
					input.style.color = "#999999";
				}
			break;
			case 'GeoInfo':
				if(override || input.value == comdir_geoInfo_autofill || input.value == "" || input.value == null) {
					input.value = comdir_geoInfo_autofill;
					input.style.color = "#999999";
				}
			break
		}
	}
	var all_textareas = document.getElementsByTagName('textarea');
	for(var i=0;i<all_textareas.length;i++) {
		var input = all_textareas[i];
		if(
		   	input.getAttribute('comdir_autofill') == 'Description' && 
			(input.value == "" || input.value == null || input.value == comdir_description_autofill || override)
		) {
			input.style.color = '#999999';
			input.value = comdir_description_autofill;
		}
	}
}
/*
* ON LOAD
*/
function comdir_onload() {
	comdir_populateAutofill();
	var comdir_submit = document.getElementById("comdir_submit")
	if(comdir_submit != null)
		comdir_submit.disabled = false;
}

window.onload = comdir_onload;
/*
*  HELPER FUNCTIONS
*/
function clearMessage() {
	var messages = document.getElementById('comdir_messages');
	if(messages != null) {
		messages.className = '';
		messages.innerHTML = '';
	}
}