function industry_change(select)
{
    if (select.options[select.selectedIndex].value > 7)
    {
        document.getElementById('row_res_cost').style.display = 'none';
    }
    else
    {
        document.getElementById('row_res_cost').style.display = 'table-row';
    }
}

function roundNumber(num, dec)
{
	return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
}

function IsNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function erepFetchCitizenForFight()
{
    $.ajax({
        type: "POST",
        url: "index.php",
        data: "page=erep_fetch_citizen&citizen_name="+ encodeURIComponent($("#fightname").val()),
        success: function(msg){
            ranks = new Object();
            ranks['Private'] = 1;
            ranks['Corporal'] = 2;
            ranks['Sergeant'] = 3;
            ranks['Lieutenant'] = 4;
            ranks['Captain'] = 5;
            ranks['Colonel'] = 6;
            ranks['General'] = 7;
            ranks['Field Marshal'] = 8;
            $("#strength").val($("strength", msg).text());
            $("#wellness").val($("wellness", msg).text());
            $("#rank").val(ranks[$("military-rank", msg).text()]);
        }
    });
}

function erepExportCalc()
{
    var start = $("#erep_start").val();
    var x1 = $("#erep_x1").val();
    var x2 = $("#erep_x2").val();
    if (IsNumeric(start) && IsNumeric(x1) && IsNumeric(x2))
    {
        $("#erep_end").html(roundNumber((start / x1) / x2, 3));
    }
}

function erepExchangeCalc()
{
    var start = $("#erep_start").val();
    var x1 = $("#erep_x1").val();
    var x2 = $("#erep_x2").val();
    var x1buysell = $("#x1buysell").val();
    var x2buysell = $("#x2buysell").val();;
    if (!IsNumeric(x2) || x2 == 0) {
        x2 = 1;
    }
    if (IsNumeric(start) && IsNumeric(x1) && start > 0 && x1 > 0) {
        end = start;
        if (x1buysell == "sell") {
            end = end * x1;
        } else {
            end = end / x1;
        }
        if (x2buysell == "sell") {
            end = end * x2;
        } else {
            end = end / x2;
        }
        if (x2 == 1) {
            profit = '-';
            percent = '-';
        } else {
            profit = roundNumber(end - start,3);
            percent = roundNumber((profit / start) * 100,3);
        }
        $("#erep_end").html(roundNumber(end,3));
        $("#erep_profit").html(profit);
        $("#erep_percent").html(percent);
        $("#result").html('');
    } else {
        $("#result").html('All values must be numeric');
    }
}

erep_market_offers = function (industry, quality)
{
    $.ajax({
        type: "POST",
        url: "index.php",
        data: "page=erep_partial_offers&quality="+encodeURIComponent(quality)+"&industry="+encodeURIComponent(industry)+"&country="+encodeURIComponent($("#country_select").val()),
        success: function(msg){
            $("#market_offers").html(msg);
        }
    });
}

find_citizen = function() {
    $.ajax({
        type: "POST",
        url: "index.php",
        data: "page=erep_fetch_citizen_local&citizen_name="+encodeURIComponent(quality),
        success: function(msg){
            $("#market_offers").html(msg);
        }
    });
}

$(document).ready(function () {
    $('#find_citizen_trigger').click(function () {

       if ($('#find_citizen_container').is(':visible')) {
           $('#find_citizen_container').hide('fast');
       } else {
           $('#find_citizen_container').show('fast');
       }
    });
});