//--------------------------------------------------------------------
	// filename: main.js
	//--------------------------------------------------------------------
	
	var show_debug = false;

	//====================================================================
	// Shortcuts
	
	function debug(text) {

		if(show_debug)
	 		$("debug").innerHTML += text + "<br />";
	
	} // function debug


	function go(url) {

		document.location.href = url;

	} // function go

	
	function addHiddenField(form, name, value) {
		
		var myValue = document.createElement('input');
		myValue.setAttribute('type', "hidden");
		myValue.setAttribute('id', name);
		myValue.setAttribute('name', name);
		myValue.setAttribute('value', value);

		$(form).appendChild(myValue);
		
		debug("adding hidden field " + name + " to " + form + " with value " + value);
	} // function addHiddenField
	

	function validateAndSubmit(form_name, validator_name) {
		data = $(form_name).serialize();
		
		var options = {

			method: 'post',
			postBody: data,
			onComplete: function(response) {
				debug("parameters are: " + data);
				debug("this is the response: " + response.responseText);

				if(response.responseText.length > 1) {
					$('warning').style.display = 'block';
					//$('td_mensagem').style.display = 'table-row';
					debug('showing response');
					//23-06-2008 update from paulo campos
					//$("warning").innerHTML = response.responseText;
					$("warning").innerHTML = response.responseText;
	
				} // if
				else {
					debug("i'll submit " + form_name);

					// add check to prevent unvalidated submissions (against a script who wants
					// to override this check, for istance)
					addHiddenField(form_name, "validatorStamp", "1");
					//alert("SUBMIT FORM");
					$(form_name).submit();
				}
			} // function anonymous
		};
		
		debug("calling " + validator_name);
		new Ajax.Request(validator_name, options);
	
	}