function showFaq(title, description) {
    return overlib('<table class=tooltipTable ><tr><th><strong>'+title+'</strong></th></tr><tr><td>'+description+'</td></tr></table>');
}

function showInfo(description) {
    return overlib('<span class=tooltipTable><a><b>'+description+'</b></a></span>', FULLHTML);
}

function getPopup(title, description) {
    return overlib('<table class=tooltipTable><tr><th><strong>'+title+'</strong></th></tr><tr><td>'+description+'</td></tr></table>', STICKY, CAPTION, 'Sticky');
}

var popUp = null;
function closingPopup(pageURL,winName,features) {
    popUp = window.open(pageURL,winName,features);
    if (window.focus) {
        popUp.focus();
    }
    window.onfocus = function () {
        if(!popUp) {
            return;
        }
        popUp.close();
        popUp = null;
        window.onfocus = null;
    }
    return false;
}


function confirmation(text)
{
    var confirmText = text;
    if (!confirm(confirmText)) {
        return false;
    } else {
        return true;
    }
}

function redirectConfirmation(url, msg, doubleCheck)
{

    if (!confirm(msg)) {
        return false;
    } else {
        if (doubleCheck) {
            if (!confirm(doubleCheck)) {
                return false;
            }
        }
        window.location = url;
        return true;
    }
}


function MM_preloadImages() { //v3.0

    var d=document;
    if(d.images){
        if(!d.MM_p) {
            d.MM_p=new Array();
        }

        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){
            d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
        }
    }
}


/*
*   Countdown Script zB zum Anzeigen der restlichen Ausbauzeit
*/
function countdown(seconds, id, finishedText, url, countdown_text)
{
    //alert(total_secs);
    var url = url;
    var total_secs = seconds;
    var days = Math.floor(total_secs/(60*60*24));
    var hours = Math.floor((total_secs/3600)%24);
    var mins = Math.floor((total_secs/60)%60);
    var secs = Math.floor(total_secs%60);
    var id = id;
    var finished = false;
    var time;
    var doc;
    var countdown_text = countdown_text;

    if (countdown_text)
    {
        var countdown_text = countdown_text;
    } else {
        var countdown_text = "";
    }

    doc = document.getElementById(id);
    if (!doc) {
        return false;
    }

    total_secs -= 1;

    if (hours <= 9 && hours > -1) hours = "0" + hours;
    if (mins <= 9 && mins > -1) mins = "0" + mins;
    if (secs <= 9 && secs > -1) secs = "0" + secs;

    if (days < 1 && hours < 1 && mins < 1 && secs < 1) {
        time = '<span class="topMessage">'+finishedText+'</span>';
        finished = true;
    } else if (days < 1) {
        time = "<div class=\"countdownTable\">" + countdown_text + "&nbsp;" + hours +":"+ mins +":" + secs +"</div>";
    } else {
        time = "<div class=\"countdownTable\">" + countdown_text + "&nbsp;" + days +" - "+ hours +":"+ mins +":"+ secs +"</div>";
    }

    doc.innerHTML = time;

    if(finished != true)
    {
        setTimeout("countdown('"+total_secs+"','"+id+"','"+finishedText+"','"+url+"','"+countdown_text+"')", 1000);
    } else {
        if (url) {
            window.location = url;
        }
    }
}

function runden(x, n) {
if (n < 1 || n > 14) return false;
var e = Math.pow(10, n);
var k = (Math.round(x * e) / e).toString();
if (k.indexOf('.') == -1) k += '.';
k += e.toString().substring(1);
return k.substring(0, k.indexOf('.') + n+1);
}

function progressBar(total,todo,id,url)
{
    var total = total;
    var todo = todo;
    var id = id;
    var doc;

    doc = document.getElementById(id);
    if (!doc) {
        return false;
    }
    todo = todo - 1;

    var done;
    done = 200/100*(100-total/(todo/100));

    var percent;
    percent = runden((100-todo/(total/100)),2);
    if(percent > 100)
    {
        percent = '100.00';
        if (url) {
            window.location = url;
        }
    }

//     document.getElementById(id).firstChild.nodeValue = percent+'%';
//     document.getElementById("progressBarInner").style.width = Math.round(percent)+"px";
//     setTimeout("progressBar('"+total+"','"+todo+"','"+id+"','"+url+"')", 1000);
    if(percent > 0)
    {
    doc.innerHTML = "<div class='progressBar'><div class='progressBarInner' style='width:"+Math.round(percent)+"px'><span id='progressCount' class='progressCount'>"+percent+"%</span></div></div>";
    }

    setTimeout("progressBar('"+total+"','"+todo+"','"+id+"','"+url+"')", 1000);

}

function open_profil_by_id(id, oid)
{
    var id = id;
    var oid = oid;
    var profil;

    //profil = window.open('index.php?group=user&action=profil&user_id='+id+'&owner_id='+oid,'+id+','menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,width=400,height=300');
    profil = window.open('index.php?group=user&module=spy&action=popup&user_id='+id+'','','menubar=no,toolbar=no,status=no,resizable=no,width=550,height=400');
    profil.focus();
}

function popup()
{
    var window_id = window_id;
    var popmessage;

    popmessage = window.open('index.php?group=user&action=message','','menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,width=400,height=200');
    popmessage.focus();
}

function openFromPopup(url)
{
    window.opener.location = url;
}

function open_mail(id, box)
{
    var box = box;
    var id = id;
    var window_id = id;
    var popmail;

    if (box == 'alliance' && id > 0) {
        popmail = window.open('/index.php?group=user&module=mail&action=join&alliance_id='+id,window_id,'menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=400');
       popmail.focus();
    } else if (id > 0) {
        popmail = window.open('/index.php?group=user&module=mail&action=mail&'+box+'_id='+id,window_id,'menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=400');
       popmail.focus();
    } else {
       popmail = window.open('/index.php?group=user&module=mail&action=search','mail','menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=400');
       popmail.focus();
    }
}

function open_new_mail(user_name)
{
    var user_name = user_name;
    var window_id = user_name;
    var popmail;

    if (user_name) {
        popmail = window.open('index.php?group=user&module=mail&action=search&name='+user_name,user_name,'menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,width=400,height=350');
       popmail.focus();
    }
}

function myround(num)
{
    return Math.round(num * Math.pow(10, 2))/Math.pow(10, 2);
}

function runde(x, n) {
  if (n < 1 || n > 14) return false;
  var e = Math.pow(10, n);
  var k = (Math.round(x * e) / e).toString();
  if (k.indexOf('.') == -1) k += '.';
  k += e.toString().substring(1);
  return k.substring(0, k.indexOf('.') + n+1);
}

function openPopup(url, wName, wWidth, wHeight) {
    var popup;
    popup = window.open(url, wName, 'menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,width='+wWidth+',height='+wHeight);
    popup.focus();
}

function openAllianceMail(id)
{
    var id = id;
    var allianceMail;
    allianceMail = window.open('/index.php?group=user&module=alliance&action=mailpopup&mailId='+id,'allianceMail','menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,width=400,height=340');
    allianceMail.focus();
}

function calcRessources(id, amount, modifier, stocklevel)
{
    maximum = 2000 + stocklevel*1000 + Math.pow(stocklevel, 3)*15;
    if (modifier > 0 && (amount <= maximum || id == 'credits')) {

        document.getElementById(id).innerHTML = amount++;
        setTimeout("calcRessources('"+id+"', '"+amount+"', '"+modifier+"', '"+stocklevel+"')", 1000/modifier);
    }
}

function calcModifier(levelOfProduction,taxrate,gamespeed)
{
    var modifier = (100+levelOfProduction*25 + 2*(Math.pow(levelOfProduction, 2))) / (3600/gamespeed) * ((100 - taxrate)/100);
    return runde(modifier,4);
}


function padlength(what){
    var output=(what.toString().length==1)? "0"+what : what
    return output
}

function showServerTime(servertime)
{
    var serverdate=new Date(servertime);

    serverdate.setSeconds(serverdate.getSeconds()+1);
    var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
    var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds())

    document.getElementById('time').innerHTML = timestring;
     setTimeout("showServerTime('"+datestring+" "+timestring+"')", 1000);

}

function checkTime(i)
{
  if (i < 10) {
    i="0" + i
  }
    return i
}

