var info_box="";

/* --- */

function set_info_box_left(title,info,xpos,ypos)
{
	if(title=="")
		title="<i>" + lang_planet_uninhabited + "<\/i>";
	info_box='<table cellpadding="0" cellspacing="0" class="infobox"><tr><td class="infobox">'+title+'<\/td><td class="infoarrow right"><img src=".\/pictures\/gui\/ecke-rechts.gif" height="10" width="10" alt="" \/><\/td><\/tr><tr><td colspan="2" class="font10">'+info+'<\/td><\/tr><tr><td colspan="2" class="right font10"><a href="javascript:clear_info_box()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	document.getElementById("infobox").innerHTML=info_box;
	document.getElementById("infobox").style.top=xpos+"px";
	document.getElementById("infobox").style.left=ypos+"px";
	document.getElementById("infobox").style.visibility="visible";
	document.getElementById("infobox").style.position="absolute";
	dynamicmove=false;
}

function set_info_box_right(title,info,xpos,ypos)
{
	if(title=="")
		title="<i>" + lang_planet_uninhabited + "<\/i>";
	info_box='<table cellpadding="0" cellspacing="0" class="infobox"><tr><td class="infoarrow left"><img src=".\/pictures\/gui\/ecke.gif" height="10" width="10" alt="" \/><\/td><td class="infobox">'+title+'<\/td><\/tr><tr><td colspan="2" class="font10">'+info+'<\/td><\/tr><tr><td colspan="2" class="right font10"><a href="javascript:clear_info_box()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	document.getElementById("infobox").innerHTML=info_box;
	document.getElementById("infobox").style.top=xpos+"px";
	document.getElementById("infobox").style.left=ypos+"px";
	document.getElementById("infobox").style.visibility="visible";
	document.getElementById("infobox").style.position="absolute";
	dynamicmove=false;
}

function set_info_box(title,info,xpos,ypos)
{
	info_box='<table cellpadding="0" cellspacing="0" class="ib normalborder dialogbg"><tr><td width="10" class="infoarray left"><img src=".\/pictures\/gui\/ecke.gif" height="10" width="10" alt="" \/><\/td><td class="infobox">'+title+'<\/td><\/tr><tr><td colspan="2" class="font10">'+info+'<\/td><\/tr><tr><td colspan="2" class="right font10"><a href="javascript:clear_info_box()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	document.getElementById("infobox").innerHTML=info_box;
	document.getElementById("infobox").style.top=xpos+"px";
	document.getElementById("infobox").style.left=ypos+"px";
	document.getElementById("infobox").style.visibility="visible";
	document.getElementById("infobox").style.position="absolute";
	dynamicmove=false;
}

function set_info_box_right_small(title,info)
{
	info_box='<table cellpadding="0" cellspacing="0" class="ib3 normalborder dialogbg"><tr><td class="infobox left">'+title+'<\/td><\/tr><tr><td class="font10">'+info+'<\/td><\/tr><\/table>';
	document.getElementById("infobox").innerHTML=info_box;
	document.getElementById("infobox").style.visibility="visible";
	document.getElementById("infobox").style.position="absolute";
	document.getElementById("infobox").style.top="185px";
	document.getElementById("infobox").style.right="20px";
	document.getElementById("infobox").style.left="auto";
	dynamicmove=true;
}

function set_info_box_right_small2(title,info)
{
	info_box='<table cellpadding="0" cellspacing="0" class="ib2 normalborder dialogbg"><tr><td class="infobox left">'+title+'<\/td><\/tr><tr><td class="font10">'+info+'<\/td><\/tr><\/table>';
	document.getElementById("infobox").innerHTML=info_box;
	document.getElementById("infobox").style.visibility="visible";
	document.getElementById("infobox").style.position="absolute";
}

function clear_info_box()
{
	info_box="";
	document.getElementById("infobox").innerHTML="";
	document.getElementById("infobox").style.visibility="hidden";
}
function show_info_box(title,info,callId)
{
	if(title=="")
		title="<i>" + lang_planet_uninhabited + "<\/i>";
	document.getElementById("infobox").style.visibility="visible";
	document.getElementById("infobox").style.position="absolute";

	document.getElementById("infobox").style.top=(parseInt(document.getElementById(callId).style.top)+parseInt(document.getElementById(callId).height))+"px";
	if((parseInt(document.getElementById(callId).style.left)+parseInt(document.getElementById(callId).width)) > 320)
	{
		document.getElementById("infobox").style.left=(parseInt(document.getElementById(callId).style.left)-200)+"px";
		info_box='<table cellpadding="0" cellspacing="0" class="infobox"><tr><td class="infobox">'+title+'<\/td><td class="infoarrow right"><img src=".\/pictures\/gui\/ecke-rechts.gif" height="10" width="10" alt="" \/><\/td><\/tr><tr><td colspan="2" class="font10">'+info+'<\/td><\/tr><tr><td colspan="2" class="right font10"><a href="javascript:clear_info_box()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	}
	else
	{
		document.getElementById("infobox").style.left=(parseInt(document.getElementById(callId).style.left)+parseInt(document.getElementById(callId).width))+"px";
		info_box='<table cellpadding="0" cellspacing="0" class="infobox"><tr><td class="infobox left"><img src=".\/pictures\/gui\/ecke.gif" height="10" width="10" alt="" \/><\/td><td class="infobox">'+title+'<\/td><\/tr><tr><td colspan="2" class="font10">'+info+'<\/td><\/tr><tr><td colspan="2" class="right font10"><a href="javascript:clear_info_box()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	}
	document.getElementById("infobox").innerHTML=info_box;
	dynamicmove=false;
}

/* --- */

function set_target(coords)
{
	if(window.opener!=null)
	{
		window.opener.document.fleetform.target_coords.value=coords;
	}
}

/* --- */

function testinput()
{
	if(document.colonizeform.planet_name.value=="")
		show_error_box("ERROR",lang_name_planet);
	else
	{
		document.colonizeform.submit();
	}
}

function show_error_box(title,info)
{
	info_box='<table cellpadding="0" cellspacing="0" class="errwin"><tr><td class="bold tableheading errcolor center">'+title+'<\/td><\/tr><tr><td class="font10 middle center">'+info+'<\/td><\/tr><tr><td class="right font10"><a href="javascript:clear_error_box()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	document.getElementById("errorbox").innerHTML=info_box;
	document.getElementById("errorbox").style.visibility="visible";
	document.getElementById("errorbox").style.position="absolute";
	document.getElementById("subcolonize").disabled="disabled";
	document.getElementById("planet_name").disabled="disabled";
}

function clear_error_box()
{
	info_box="";
	document.getElementById("errorbox").innerHTML="";
	document.getElementById("errorbox").style.visibility="hidden";
	document.getElementById("subcolonize").disabled="";
	document.getElementById("planet_name").disabled="";
}

/* --- */

function show_confirmbox_box(title,info,target)
{
	info_box  = '<table cellpadding="0" cellspacing="2" class="errwin"><tr><td class="bold tableheading center" colspan="2">'+title+'<\/td><\/tr>';
	info_box += '<tr><td class="font10 middle center" colspan="2">'+info+'<\/td><\/tr>';
	info_box += '<tr><td style="width:50%" class="center handcur normalborder innerspace dialogbg" onmouseover="this.className=\'center handcur normalborder innerspace infobg\'" onmouseout="this.className=\'center handcur normalborder innerspace dialogbg\'" onclick="clear_confirmbox_box()">' + lang_close + '<\/td>';
	info_box += '<td style="width:50%" class="center handcur normalborder innerspace dialogbg" onmouseover="this.className=\'center handcur normalborder innerspace infobg\'" onmouseout="this.className=\'center handcur normalborder innerspace dialogbg\'" onclick="document.location.href=\''+target+'\'">' + lang_continue + '<\/td><\/tr><\/table>';
	document.getElementById("confirmbox").innerHTML=info_box;
	document.getElementById("confirmbox").style.visibility="visible";
	document.getElementById("confirmbox").style.position="absolute";
	if(navigator.appName=="Microsoft Internet Explorer")
		document.getElementById("confirmbox").style.top=(document.body.scrollTop/1)+150+"px";
	else
		document.getElementById("confirmbox").style.top=(window.pageYOffset/1)+150+"px";
}

function clear_confirmbox_box()
{
	info_box="";
	document.getElementById("confirmbox").innerHTML="";
	document.getElementById("confirmbox").style.visibility="hidden";
}

/* --- */

function layerWrite(mylayer, text)
{
	var ie=document.all;
	var dom=document.getElementById;
	if (ie||dom)
	{
		// targetlayer= dom ? mylayer : document.getElementById(mylayer);
		if(document.getElementById(mylayer))
			document.getElementById(mylayer).innerHTML=text;
	}
	else
	{
	// alert("Benutze einen anderen Browser!");
	}
}

function countdown()
{
	var percent;
    var now = new Date();
    var tst = now.getTime() / 1000;
    var display="";
    var std;
    var min;
    var delta;

    for (i=0; i<max; i++)
    {
        min=0;
		std=0;
        delta=Math.round(tval[i] - tst + offset);
		if(tval[i]-durval[i] < tst)
			percent=Math.round(delta*100/durval[i]);
		else
			percent=100;

		if (delta <= 0)
		{
			var next_queue = tval[i]%60;
			var delta3 = 60 - next_queue;
			
			
			delta   = Math.round(tval[i] - tst + offset + delta3);
			percent = Math.round(delta*100/delta3);
			if(percent < 0)
				percent = 0;
			
			display = lang_completed;
			if(document.getElementById("fieldempty"+i))
			{
				document.getElementById("fieldempty"+i).style.width='0px';
				document.getElementById("fieldfull"+i).style.width=percent+'px';
				document.getElementById("fieldempty"+i).style.maxWidth='0px';
				document.getElementById("fieldfull"+i).style.maxWidth=percent+'px';
				document.getElementById("fieldfull"+i).style.overflow='hidden';
			}
		}
		else
		{
			var restwidth;
			if(percent<0)
				percent=0;
			if(percent>100)
				percent=100;
			restwidth=100-percent;
			document.getElementById("fieldfull"+i).style.width=restwidth+'px';
			document.getElementById("fieldempty"+i).style.width=percent+'px';
			document.getElementById("fieldfull"+i).style.maxWidth=restwidth+'px';
			document.getElementById("fieldempty"+i).style.maxWidth=percent+'px';
		   std = Math.floor(delta / 3600);
		   delta -= std * 3600;
		   min = Math.floor(delta / 60);
		   delta -= min * 60;
		   if (delta < 10)
			   delta = "0" + delta;
		   if (min < 10)
			   min = "0" + min;
		   display= std + ":" + min + ":" + delta;
		}
		layerWrite("field" + i, display);
    }
    window.setTimeout("countdown();",990);
}

/* --- */

function clear_standard_error_window()
{
	document.getElementById("defaultErrorWindow").innerHTML="";
	document.getElementById("defaultErrorWindow").style.visibility="hidden";
}
function show_default_error_window(errorTXT)
{
	info_box='<table cellpadding="0" cellspacing="0" class="errwin"><tr><td class="tableheading errcolor bold center">ERROR<\/td><\/tr><tr><td class="font10 middle center">'+errorTXT+'<\/td><\/tr><tr><td class="right font10"><a href="javascript:clear_standard_error_window()">' + lang_close + '<\/a><\/td><\/tr><\/table>';
	document.getElementById("defaultErrorWindow").innerHTML=info_box;
	document.getElementById("defaultErrorWindow").style.visibility="visible";
	if(navigator.appName=="Microsoft Internet Explorer")
		document.getElementById("defaultErrorWindow").style.top=(document.body.scrollTop/1)+150+"px";
	else
		document.getElementById("defaultErrorWindow").style.top=(window.pageYOffset/1)+150+"px";
}
function openhelpwin(doc)
{
	info_box='<div class="right picwidth rightmargin"><a href="javascript:clear_help_win()"><img src="' + gp_path + './pictures/gui/close.gif" alt="' + lang_close + '" border="0" class="inactivetab picwidth" /><\/a><\/div><iframe src="'+doc+'" name="help" id="help" class="pageresolution' + resolution + ' helpresolution' + resolution + ' unhide normalborder" frameborder="0"><\/iframe>';
	document.getElementById("helpwin").innerHTML=info_box;
	document.getElementById("helpwin").style.visibility="visible";
	if(navigator.appName=="Microsoft Internet Explorer")
		document.getElementById("helpwin").style.top=(document.body.scrollTop/1)+"px";
	else
		document.getElementById("helpwin").style.top=(window.pageYOffset/1)+"px";
}
function clear_help_win()
{
	info_box="";
	document.getElementById("helpwin").innerHTML="";
	document.getElementById("helpwin").style.visibility="hidden";
}
function set_fleet_target(coords)
{
	document.getElementById('target_coords').value=coords;
	document.getElementById('target_coords_html').innerHTML=coords;
	updateData();
}

/* --- */

function set_message(status)
{
	if(status==0)
	{
		document.getElementById("newmessage").src = gp_path + "./pictures/gui/mail_0.gif";
		document.getElementById("newmessage").title = lang_no_new_privmessage;
		document.getElementById("newmessage").alt = lang_no_new_privmessage;
	}
	else
	{
		document.getElementById("newmessage").src = gp_path + "./pictures/gui/mail_1.gif";
		document.getElementById("newmessage").title = lang_new_privmessage.replace(/{NBR}/,status);
		document.getElementById("newmessage").alt = lang_new_privmessage.replace(/{NBR}/,status);
	}
}

function set_quest(status)
{
	if(status==0)
	{
		document.getElementById("newquest").src = gp_path + "./pictures/gui/quest_0.gif";
		document.getElementById("newquest").title = lang_no_new_quest_message;
		document.getElementById("newquest").alt = lang_no_new_quest_message;
	}
	else
	{
		document.getElementById("newquest").src = gp_path + "./pictures/gui/quest_1.gif";
		document.getElementById("newquest").title = lang_new_quest_messages.replace(/{NBR}/,status);
		document.getElementById("newquest").alt = lang_new_quest_messages.replace(/{NBR}/,status);
	}
}

