function doEndorsement(url) {
	var params = "";
	var form = document.getElementById('form1');
	if (form.sectionsFile != null) {
		// check if radio buttons
		if (form.sectionsFile.length != null) {
			for (i = 0; i < form.sectionsFile.length; i++) {
				if (form.sectionsFile[i].checked == true) {
					params += "sectionsFile="
							+ form.sectionsFile[i].value;
					break;
				}
			}
		} else
			params += "sectionsFile=" + form.sectionsFile.value;
	}

	if (form.personName != null)
		params += "&name=" + form.personName.value;
		
	if (form.company != null)
		params += "&company=" + form.company.value;

	if (form.itemName != null)
		params += "&item=" + form.itemName.value;

	if (form.sex != null)
		params += "&sex=" + form.sex.value;	
	
	if (form.onlyDenominator != null)
		params += "&tylkoMianownik="
				+ (form.onlyDenominator.checked ? true : false);
	
	if (form.charLimit != null)
		params += "&limit=" + form.charLimit.value;

	return getAjaxEndorsement(url, params);
}

function writeNewWindow(content) {
 top.newWindow=window.open('','debug.endorser.org',
  'width=320,height=350'
   +',menubar=0'
   +',toolbar=0'
   +',status=0'
   +',scrollbars=1'
   +',resizable=1')
 top.newWindow.document.writeln(
  '<html><head><title>debug.endorser.org</title></head>'
   +'<body bgcolor="white" onLoad="self.focus()">'
   +content
   +'</body></html>'
 )
 top.newWindow.document.close()
}	
	
function getAjaxEndorsement(url, params) {
	//TODO: improve adblock handling, disabling at the moment
	var adblock_disabled = 1;
	
	document.getElementById("endorsementFieldset").style.display = "block";

	if(adblock_disabled==null || adblock_disabled==1){
		document.getElementById("endorsement").innerHTML = "generating...";
	}
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
		return true;

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4 && (adblock_disabled==null || adblock_disabled==1)) {
			if(xmlHttp.status == 200){
				//var responseText = xmlHttp.responseText;
				
				var json_tekst = xmlHttp.responseText; // uzyskuje dane w postaci ciągu znaków 
				//alert(json_tekst);
				eval("var json_obiekt = ("+json_tekst+")");
				//alert(json_obiekt.endorsement);
				document.getElementById("endorsement").innerHTML = json_obiekt.endorsement;
				//document.getElementById("endorsement").innerHTML = json_tekst;
				if(json_obiekt.debug != null)
					writeNewWindow(json_obiekt.debug);
			}
			else
				document.getElementById("endorsement").innerHTML = "request failed (status "+xmlHttp.status+")";
		}
	}

	//var url = "/ajax/testDictionary.php";

	xmlHttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.send(params);
	return false;
}