  function makePOSTRequest(url, parameters,metoda) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      if(metoda=='save_map')
      	http_request.onreadystatechange = implementSave;
      	else if(metoda=='move_here')
      	http_request.onreadystatechange = implementMove;
      	else if(metoda=='build_city')
      	http_request.onreadystatechange = implementBuild;
      	else if(metoda=='show_production' || metoda == 'show_information')
      	http_request.onreadystatechange = implementShowProduction;
      	else if(metoda=='production_queve')
      	http_request.onreadystatechange = implementQueve;
      	else if(metoda=='purchase_something')
      	http_request.onreadystatechange = implementPurchase;
      	else if(metoda=='built')
      	http_request.onreadystatechange = implementConstruction;
      	else if(metoda=='show_city')
      	http_request.onreadystatechange = implementShowCity;
      	else if(metoda=='attack_here')
      	http_request.onreadystatechange = implementAttackHere;
      	else if(metoda=='purchase_tile')
      	http_request.onreadystatechange = implementPurchasedTile;
      	else if(metoda=='save_work')
      	http_request.onreadystatechange = implementSaveWork;
      	else if(metoda=='show_menu' || metoda == 'save_resolution')
      	http_request.onreadystatechange = implementShowMenu;
      	else if(metoda=='save_science' )
      	http_request.onreadystatechange = implementSaveScience;
      	else if(metoda=='save_scienceCDP' )
      	http_request.onreadystatechange = implementSaveScienceCDP;
      	else if(metoda=='show_science')
      	http_request.onreadystatechange = implementShowScience;
      	else if(metoda=='putInDiv')
      	http_request.onreadystatechange = implementShowDiv;
      	else
      	http_request.onreadystatechange = implementTeams;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

current_pos='rau';

function changeResolution()
{
	var xs = document.getElementById('opt_xs').value;
	var ys = document.getElementById('opt_ys').value;
	var parameters = '&xs='+xs+'&ys='+ys;
	loadingAjax('menuInfo');
	makePOSTRequest('action.php?m=save_resolution',parameters,"save_resolution");
}

function researchThis(what,CDP)
{
	document.getElementById('researchme').innerHTML = '';
	var parameters = '&id='+what;
	loadingAjax('currentDiscovery'+CDP);	makePOSTRequest('action.php?m=save_science&cdp='+CDP,parameters,"save_science"+CDP);
}
function showPage(method)
{	document.getElementById("map").style.display = "none";
	loadingAjax("map");
	giveHref(method);
	makePOSTRequest('action.php?m='+method,'',"show_science");
}

function show_empire(id)
{	showPage('empire:'+id);
}

var putInWhichDiv = 'something';
function putInDiv(inDiv, link, andHref)
{
	loadingAjax(inDiv);
	putInWhichDiv = inDiv;
	giveHref(andHref);
	makePOSTRequest('action.php?m='+link,'',"putInDiv");
}

function implementShowDiv()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
         	document.getElementById(putInWhichDiv).innerHTML = result;
         	javascriptEval(putInWhichDiv);
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function showScience()
{
	giveHref("science");	document.getElementById("map").style.display = "none";
	makePOSTRequest('action.php?m=science','',"show_science");
}

function showInbox()
{	giveHref("inbox");
	document.getElementById("map").style.display = "none";
	makePOSTRequest('action.php?m=inbox','',"show_science");
}

function showForum()
{	giveHref("forum");


	document.getElementById("map").style.display = "none";
	makePOSTRequest('action.php?m=forum','',"show_science");
}

function showCyberpoints()
{
	giveHref("cyberpoints");
	document.getElementById("map").style.display = "none";
	makePOSTRequest('action.php?m=cyberpoints','',"show_science");
}

function showTrade(tip)
{
	giveHref("trade");
	document.getElementById("map").style.display = "none";
	makePOSTRequest('action.php?m=trade','',"show_science");
}

function makeTrade(message, id_sale, buy_with)
{	if(confirm(message))
	{
		loadingAjax('sale_'+id_sale);
		putInDiv('sale_'+id_sale, 'trade_sale&id='+id_sale+'&with='+buy_with, '');
	}
}

function showAttackLog()
{	document.getElementById("map").style.display = "none";
	makePOSTRequest('action.php?m=attack_log','',"show_science");
}

function getMenu(method)
{
	giveHref(method);
	loadingAjax('menuInfo');

	if(method == 'world_map')
	{		document.getElementById('map').style.display = "block";
		document.getElementById('menuInfo').innerHTML = "";
	}
	else
	{
		var parameters = '&s='+method;		makePOSTRequest('action.php?m=getMenu',parameters,'show_menu');
	}
}

function saveSchedule(currentCity)
{	loadingAjax('work_tile');
	var num = 0;	var parameters = '&id='+currentCity;
	for(var xy in worked)
		if(worked[xy] == 1)
		{			num = num + 1;
			parameters = parameters + '&work_'+num+'='+xy;
		}

	makePOSTRequest('action.php?m=save_work',parameters,'save_work');
}

function implementSaveScience()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
         	document.getElementById('currentDiscovery').innerHTML = result;
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementSaveScienceCDP()
{		if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
         	document.getElementById('currentDiscoveryCDP').innerHTML = result;
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementShowScience()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
         	document.getElementById('city_div').innerHTML = result;
         	javascriptEval( 'city_div' );

            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementSaveWork()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById('work_tile').innerHTML = result;

            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementShowMenu()
{
	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById('menuInfo').innerHTML = result;

            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function purchaseTile(xy, id, currency)
{	var parameters = '&xy='+xy+'&city='+id+'&with='+currency;
	makePOSTRequest('action.php?m=purchaseTile',parameters,"purchase_tile");
}

function implementPurchasedTile()
{ 	if (http_request.readyState == 4) {
         if (http_request.status == 200) {         	result = http_request.responseText;
              document.getElementById("implementTileDiv").innerHTML = result;
            javascriptEval("implementTileDiv");
          } else {
            alert('There was a problem with the request.');
         }
 	}

}

function implementPurchase()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById(current_pos).innerHTML = result;
            javascriptEval(current_pos);
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
 	}
}

function javascriptEval(diver)
{
	window.jsCode = new Array();	var scriptTags = document.getElementById(diver).getElementsByTagName('SCRIPT');
            for(var no=0;no<scriptTags.length;no++){
                if (scriptTags[no].src){
                    var head = document.getElementsByTagName("head")[0];
                    var scriptObj = document.createElement("script");
                    scriptObj.setAttribute("type", "text/javascript");
                    scriptObj.setAttribute("src", scriptTags[no].src);
                    head.appendChild(scriptObj);

                }else{
                        var code = scriptTags[no].innerHTML;
                        window.jsCode[no] = code;
                        setTimeout('eval(window.jsCode[' + no + '])',100);      // Has to wait because we want to make all objects part of the window object(global variables) instead of locale
                }
            }
}

function implementAttackHere()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            window.jsCode = new Array();
            document.body.style.cursor="default";
            document.getElementById("map").style.display = "none";
            document.getElementById("city_div").style.display = "none";
            document.getElementById("attack_div").innerHTML = result;
            var scriptTags = document.getElementById("attack_div").getElementsByTagName('SCRIPT');
            for(var no=0;no<scriptTags.length;no++){
                if (scriptTags[no].src){
                    var head = document.getElementsByTagName("head")[0];
                    var scriptObj = document.createElement("script");
                    scriptObj.setAttribute("type", "text/javascript");
                    scriptObj.setAttribute("src", scriptTags[no].src);
                    head.appendChild(scriptObj);

                }else{
                        var code = scriptTags[no].innerHTML;
                        window.jsCode[no] = code;
                        setTimeout('eval(window.jsCode[' + no + '])',100);      // Has to wait because we want to make all objects part of the window object(global variables) instead of locale
                }
            }
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
 	}
}

function implementShowCity()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById('city_div').innerHTML = result;
            javascriptEval('city_div');
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementConstruction()
{if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById('map').innerHTML = result;

            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function back_to_world(message)
{
	document.getElementById('map').style.display = "block";	document.getElementById('city_div').style.display = "none";
	document.getElementById('attack_div').style.display = "none";
	if(message.length >=2)
		document.getElementById(message).style.display = "none";
}

function implementShowProduction()
{
	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            window.jsCode = new Array();
            document.getElementById('cityBlock').innerHTML = result;
            var scriptTags = document.getElementById('cityBlock').getElementsByTagName('SCRIPT');
            for(var no=0;no<scriptTags.length;no++){
                if (scriptTags[no].src){
                    var head = document.getElementsByTagName("head")[0];
                    var scriptObj = document.createElement("script");
                    scriptObj.setAttribute("type", "text/javascript");
                    scriptObj.setAttribute("src", scriptTags[no].src);
                    head.appendChild(scriptObj);

                }else{
                        var code = scriptTags[no].innerHTML;
                        window.jsCode[no] = code;
                        setTimeout('eval(window.jsCode[' + no + '])',100);      // Has to wait because we want to make all objects part of the window object(global variables) instead of locale
                }
            }
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementQueve()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById('production_queve').innerHTML = result;

            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}
function clearRoads()
{
	var obj;	for(var realstep2 in road)
	{
		obj = document.getElementById('road_'+realstep2);
		if(obj != null)
			rEs(obj);
		}
}


function implementMove()
{	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            var returner = new Array();
             /*alert(result);
           javascriptEval("implementTileDiv");*/
            returner = result.split(":.:.:");

            if(typeof returner[1] == "undefined")
            {
            	document.getElementById('log_contents').innerHTML = returner[0];
            	alert(returner[0]);
            }
            else
            {
            	document.getElementById('superLoader').style.display="none";            	unit_moves_left[returner[3]] = returner[0];
            	document.getElementById("unMovesLeft").innerHTML = unit_moves_left[returner[3]];
            	unitLocation[returner[3]] = returner[1];

            	var obj = document.getElementById(returner[1]);
            	document.getElementById('unit_'+returner[3]).innerHTML='';

             	document.getElementById('unit_'+returner[3]).parentNode.removeChild(document.getElementById('unit_'+returner[3]));
                rEs(document.getElementById('unit_'+returner[3]));
                /*document.getElementById(returner[2]).removeChild(document.getElementById('unit_'+returner[3]));   */


				var newDiv = document.createElement("DIV");
	    		newDiv.id = "unit_"+returner[3];
				newDiv.innerHTML = getPlayerHtml(returner[3]);

				obj.appendChild(newDiv);
				clearRoads();
				var retFrom = new Array();
				if(curUnit == parseInt(returner[3]))
				{
					retFrom = returner[1].split(",");					from["x"] = retFrom[0];
					from["y"] = retFrom[1];
				}

				var saveReturner = '';
				for(var i = 4; i <= returner.length ; i++)
				{                	saveReturner = saveReturner + returner[i];
				}
				document.getElementById("city_div").innerHTML = saveReturner;
                javascriptEval("city_div");

                for(var x=30;x<=40;x++)
                	for(var y=1;y<=25;y++)
                	{
                		obj = document.getElementById(x+","+y);
		                if(typeof obj != "undefined")
						{

							obj.innerHTML = document.getElementById("new"+x+","+y).innerHTML;
							obj.style.backgroundImage = document.getElementById("new"+x+","+y).style.backgroundImage;
							rEs(document.getElementById("new"+x+","+y));
									 }
					}
            }

            /*document.getElementById('map').innerHTML = result; */



         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementBuild()
{
	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

			document.getElementById('map').style.display = "none";
            document.getElementById('city_div').innerHTML = result;

            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function implementSave()
{
	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;

            document.getElementById('map').innerHTML = result;
            window.jsCode = new Array();
            var scriptTags = document.getElementById('map').getElementsByTagName('SCRIPT');
            var head = document.getElementsByTagName('HEAD')[0];
            for(var no=0;no<scriptTags.length;no++){
                if (scriptTags[no].src){
                    var head = document.getElementsByTagName("head")[0];
                    var scriptObj = document.createElement("script");
                    scriptObj.setAttribute("type", "text/javascript");
                    scriptObj.setAttribute("src", scriptTags[no].src);
                    head.appendChild(scriptObj);

                }else{
                        var code = scriptTags[no].innerHTML;
                        window.jsCode[no] = code;
                        setTimeout('eval(window.jsCode[' + no + '])',100);      // Has to wait because we want to make all objects part of the window object(global variables) instead of locale
                }
            }
            /*alert((typeof saved_ids[current_condition_id])+" << "+raspuns[2]+" >>"+current_condition_id);     */

         } else {
            alert('There was a problem with the request.');
         }
      }
}

function loadingAjax(objId)
{
	current_pos = objId;	var obj = document.getElementById(objId);
	obj.innerHTML = '<table cellpadding="5px" cellspacing="0px" style="background-color:#FFFCD3;border:1px Solid #E3DC7B;"><tr><td><img src="images/ajaxloader.gif"></td><td><font class=arial_grey_12>LOADING</td><td><img src="images/ajaxloader2.gif"></td></tr></table>';
}


function rEs(tO) { var i, n; if (!tO) { return false; }
				  if (!tO.nodeName) { if (tO.length) for (n=tO.length; n--;) rEs(tO[n]); }
				  else tO.parentNode.removeChild(tO);
				}


function giveHref(what)
{	document.location.href = '#'+what;
}


function goToUnit(id)
{
	alert("goToUnit();");

	alert(typeof document.getElementById('map'));
	if(typeof document.getElementById('map') == 'undefined')
	{
		alert("getMapAndSelUnit();");
		getMapAndSelUnit(id);
		}
		else
		{
           	selExistingUnit(id);
   		}
}

function changeHall(method){
	var arrayu = method.split(":");
    putInDiv("hall_of_fame_box", 'action.php?crap=1&m=gethall&limit=5&s='+method, method);
}


