// Ticks or clears tick boxes en-masse
function cb_set(name, value) {
	var group = document.getElementById(name);
	var boxes = group.getElementsByTagName("input");
	for (var i = 0; i < boxes.length; i++) {
		boxes[i].checked = value;
	}
}

// Displays a character limit for text boxes
function textLimit(element, limit) {
	var field = document.getElementById(element);
	var remchar = document.getElementById(element + "-remchar");
	if (limit - field.value.length >= 0) {
		remchar.innerHTML = limit - field.value.length;
	} else {
		remchar.innerHTML='<span style="color: #f00;">Text limit reached. Consider revising the text.</span>';
	}
}

// Toggles the display of default text in form fields
function toggleFieldText(field, text) {
	if (document.getElementById(field).value == text) {
		document.getElementById(field).value = '';
	} else if (document.getElementById(field).value == '') {
		document.getElementById(field).value = text;
	}
}

// Copies content from one form field to another
function copyFormTextField(from, to) {
	document.getElementById(to).value = document.getElementById(from).value;
}

function copyFormOptionField(from, to) {
	fromfield = document.getElementById(from);
	tofield = document.getElementById(to);
	for (var i = 0; i < fromfield.options.length; i++) {
		if (fromfield.options[i].selected == true) {
			fromfieldselected = fromfield.options[i].text;
		}
	}
	for (var i = 0; i < tofield.options.length; i++) {
		if (tofield.options[i].text == fromfieldselected) {
			tofield.options[i].selected = true;
		}
	}
}

function copyFormVacancy(from, to) {
	// Name
	copyFormOptionField('f' + from + 'Title', 'f' + to + 'Title');
	copyFormTextField('f' + from + 'Forename', 'f' + to + 'Forename');
	copyFormTextField('f' + from + 'Surname', 'f' + to + 'Surname');
	// Position
	copyFormTextField('f' + from + 'Position', 'f' + to + 'Position');
	// Company name
	copyFormTextField('f' + from + 'CompanyName', 'f' + to + 'CompanyName');
	// Address
	copyFormTextField('f' + from + 'Add1', 'f' + to + 'Add1');
	copyFormTextField('f' + from + 'Add2', 'f' + to + 'Add2');
	copyFormTextField('f' + from + 'Add3', 'f' + to + 'Add3');
	copyFormTextField('f' + from + 'Add4', 'f' + to + 'Add4');
	copyFormTextField('f' + from + 'Postcode', 'f' + to + 'Postcode');
	// Contact
	copyFormTextField('f' + from + 'Telno', 'f' + to + 'Telno');
	copyFormTextField('f' + from + 'Faxno', 'f' + to + 'Faxno');
	copyFormTextField('f' + from + 'Email', 'f' + to + 'Email');
}