function callOperation(operationName, returnFormat, params, callback, callbackContainer){

	var httpRequest = getXMLHttpRequest();
    httpRequest.onreadystatechange = function(){
        receiveOperationResult(httpRequest, returnFormat, callback, callbackContainer);
    };

    var requestParameters = '__submited_action=' + escape(operationName);

	var url = 'index.php?returnFormat=' + returnFormat + '&' + params;
    httpRequest.open('POST', url, true);
    httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    httpRequest.send(requestParameters);
}

function receiveOperationResult(httpRequest, returnFormat, callback, callbackContainer){

	if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
			if (returnFormat == 'json') {
				result = JSON.parse(httpRequest.responseText);
            }
            else
                if (returnFormat == 'xml') {
                    result = httpRequest.responseXML;
				}
                else {
                    result = httpRequest.responseText;
				}
			callback(result, callbackContainer);
        }
        else {
            alert(httpRequest.responseText);
        }
    }
    else {
    }
}

function printWeatherInfo(result, callbackContainer){
	var container = document.getElementById(callbackContainer);

   	container.innerHTML = '';

	var div = container.appendChild(document.createElement('div'));
	div.className = 'title_radical';
	div.appendChild(document.createTextNode(result.name));

	container = container.appendChild(document.createElement('div'));
	container.className = 'text_radical';

	for (var date in result.tides) {

		div = container.appendChild(document.createElement('div'));
		div.style.cssText = "padding-top:10px; padding-bottom:30px; padding-left:15px;";
		div.appendChild(document.createElement('b')).appendChild(document.createTextNode('DATA: '));
		div.appendChild(document.createTextNode(result.tides[date][0].date.substr(0, 15)));

		div = container.appendChild(document.createElement('div'));
		div.style.cssText = "width:144px; float:left; text-align:center; font-size:12px;";
		div.appendChild(document.createElement('b')).appendChild(document.createTextNode('HORA LEGAL'));
		div.appendChild(document.createElement('br'));
		div.appendChild(document.createElement('b')).appendChild(document.createTextNode('DE VERÃO '));
		div.appendChild(document.createTextNode('(UTC +1)'));

		div = container.appendChild(document.createElement('div'));
		div.style.cssText = "width:80px; float:left; text-align:center; font-size:12px;";
		div.appendChild(document.createElement('b')).appendChild(document.createTextNode('ALTURA'));
		div.appendChild(document.createElement('br'));
		div.appendChild(document.createTextNode('(m)'));

		div = container.appendChild(document.createElement('div'));
		div.style.cssText = "width:96px; float:left; text-align:center; font-size:12px;";
		div.appendChild(document.createElement('b')).appendChild(document.createTextNode('MARÉ'));

		div = container.appendChild(document.createElement('div'));
		div.style.cssText = "clear:both; height:30px;";


		for (var i = 0; i != result.tides[date].length; i++) {
			tides = result.tides[date][i];
			div = container.appendChild(document.createElement('div'));
			div.style.cssText = "width:144px; float:left; text-align:center;";
			div.appendChild(document.createTextNode(tides.date.substr(16, 5)));

			div = container.appendChild(document.createElement('div'));
			div.style.cssText = "width:80px; float:left; text-align:center;";
			div.appendChild(document.createTextNode(tides.waveSize));

			div = container.appendChild(document.createElement('div'));
			div.style.cssText = "width:96px; float:left; text-align:center;";
			div.appendChild(document.createTextNode(tides.type));

			div = container.appendChild(document.createElement('div'));
			div.style.cssText = "clear:both;";

		}

		subContainer = container.appendChild(document.createElement('div'));
		subContainer.style.cssText = "margin-left:10px; margin-right:30px; margin-top:25px; margin-bottom:20px;";

		div = subContainer.appendChild(document.createElement('div'));
		div.style.cssText = "background:#558412; height:1px;";

	}


}
