/**
 * Functions used on contactform.jsp
 */

/**
 * Enable or disable the input called textFieldName depending on the state of the checkbox.
 */
function enableDisableTextField(checkbox, textFieldName)
{
	try {
		var aForm = checkbox.form;
		var textField = aForm[textFieldName];
		if (textField) {
    		if (checkbox.checked) {
				textField.disabled = false;
				textField.focus();
    		} else {
    			textField.value = '';
    			textField.disabled = true;
    		}
		}
	} catch (anError) {
		showError(anError, 'Toggling ' + textFieldName);
	}
}

function disableAndClear(form, inputNamesArray)
{
	var inputName = 'none';
    try {
    	for (var i = 0; i < inputNamesArray.length; i++) {
    		inputName = inputNamesArray[i];
    		var input = form[inputName];
    		if (input) {
        		if (input.type == 'checkbox' || input.type == 'radio') {
        			input.checked = false;
        		} else {
        			input.value = '';
        			input.disabled = true;
        		}
    		}
    	}
    } catch (anError) {
    	showError(anError, 'disabling ' + inputName);
    }
}

// Set the id hidden input's value to 0 when the submit button is pressed.
function clearId(button)
{
	try {
	    var aForm = button.form;
	    var idField = aForm['id'];
	    if (idField) {
	    	idField.value = '0';
	    }	
	} catch (anError) {
	    showError(anError, 'clearing id');
	}
}

// only works with 'findbroker'
function prepareForSubmit(submitbuttonid, searchRequestedId){
	$("#showonsubmit").attr("style","display:inline;");
	$(submitbuttonid).remove();
	$("form#findbroker input").attr("readonly","readonly");

	//set the searchRequested flag to true to trigger a new search.
	$(searchRequestedId).val("true");

}

// generic version of prepareForSubmit
function prepareSubmit(submitbuttonid, searchRequestedId, disableIds){
	$("#showonsubmit").attr("style","display:inline;");
	$(submitbuttonid).remove();
	$(disableIds).attr("readonly","readonly");

	//set the searchRequested flag to true to trigger a new search.
	$(searchRequestedId).val("true");

}
			