// form related functions




function onForm_submit(form) {
        var inputFields = form.getElementsByTagName('input');
		for(i=0;i<inputFields.length;i++){
            if(inputFields[i].type == 'submit' || (inputFields[i].type == 'button' && inputFields[i].disableonsubmit=='true')){
				inputFields[i].disabled = true;
			}
		}
}

/*
* Sets the fired event on the form and submits
* form to the server
*/
function submitForm(event, form) {
	setFormEvent(event, form);
	form.submit();
}

function setFormEvent(event, form) {
	form.formEvent.value = event;
}

function enableField(field,checkBox){
	var checked = checkBox.checked;
	if(checked == true){
		document.getElementsByName('orderDealer('+ field +')')[0].disabled=false;
		document.getElementsByName('priceTaxExcluded('+ field +')')[0].disabled=false;
	}	
	else{
		document.getElementsByName('orderDealer('+ field +')')[0].disabled=true;
		document.getElementsByName('priceTaxExcluded('+ field +')')[0].disabled=true;
	}
}


function setCheckBoxes(group,value){

	var checkBoxes = 	document.getElementById(group).getElementsByTagName("input");

	for(var i= 0 ; i< checkBoxes.length;i++){
		checkBoxes[i].checked = value;
	}
}




	/**
		Set the text of the element/node to the specified value.
		The innerText/innerHtml property is not a standard property so the
		W3C standards are used in this method to be cross browser.
		
	*/
	function setNodeTextValue(nodeId, theTextValue) {
		var clientNode = document.getElementById(nodeId);
		var newTextNode = document.createTextNode(theTextValue);
		var previousTextNode = clientNode.childNodes[0];
		if( previousTextNode == null ) {
			clientNode.appendChild(newTextNode);
		} else {
			clientNode.replaceChild(newTextNode,previousTextNode);
		}
	}
	
	
	
	/**
		Set the value of the text field with the specified id.
	*/
	function setTextField(textFieldId,value) {
		var textField = document.getElementById(textFieldId);
		if( textField != null ) {
			if( value == null || value == 'null' ) {
				textField.value = '';
			} else {
				textField.value = value;
			}
		}
	}
	
	
	
	/**
		Clear the value of the text field with the specified id.
	*/
	function clearTextField(textFieldId) {
		var textField = document.getElementById(textFieldId);
		if( textField != null ) {
			textField.value = '';
		}
	}

	
	
	/**
		Clear the specified select box (set to first value in the list).
	*/
	function setSelectBox(selectBoxId, value) {
		var selectBox = document.getElementById(selectBoxId);
		if( selectBox != null ) {
			var items = selectBox.options;
			if( items != null && items.length != 0 ) {
				for( i = 0; i < items.length; ++i) {
					var option = items[i];
					if( option.value == value ) {
						selectBox.selectedIndex = i;
					}
				}
			}
		}
	}
	
	
	
	/**
		Clear the specified select box (set to first value in the list).
	*/
	function clearSelectBox(selectBoxId) {
		var selectBox = document.getElementById(selectBoxId);
		if( selectBox != null ) {
			selectBox.selectedIndex = 0;
		}
	}
	
	
	
	/**
		Set the selected radio button (by radio name, since the id is not always clear for radio buttons).
	*/
	function setRadioButton(radioButtonName, value) {
		var radioButtons = document.getElementsByName(radioButtonName);
		if( radioButtons == null || radioButtons.length == 0 ) {
			return;
		}
		
		for( i = 0; i < radioButtons.length; ++i ) {
			var radioButton = radioButtons[i];
			if( radioButton.value == value ) {
				radioButton.checked = true;
			} else {
				radioButton.checked = false;
			}
		}
	}
	
	
	
	/**
		Deselect a radio button (by radio name, since the id is not always clear for radio buttons).
	*/
	function clearRadioButton(radioButtonName) {
		var radioButtons = document.getElementsByName(radioButtonName);
		if( radioButtons == null || radioButtons.length == 0 ) {
			return;
		}
		
		for( i = 0; i < radioButtons.length; ++i ) {
			var radioButton = radioButtons[i];
			radioButton.checked = false;
		}
	}
	