var Austria = -0.01;
var Belgium = -0.01;
var Cyprus = -0.01;
var Czech_Republic = -0.01;
var Denmark = -0.01;
var Estonia = -0.01;
var Finland = -0.01;
var France = -0.01;
var Germany = -0.01;
var Greece = -0.01;
var Hungary = -0.01;
var Ireland = -0.01;
var Italy = -0.01;
var Latvia = -0.01;
var Lithuania = -0.01;
var Luxembourg = -0.01;
var Malta = -0.01;
var Netherlands = -0.01;
var Poland = -0.01;
var Portugal = -0.01;
var Slovakia = -0.01;
var Slovenia = -0.01;
var Spain = -0.01;
var Sweden = -0.01;
var United_Kingdom = -0.05;
    var currs = new Array(0,0,0,0,0,0,0);
    var curr_countries = new Array('GBP','USD','AUD','CAD','EUR','NZD','ZAR');
    var curr_symbols = new Array('&#163;','$','$','$','&#8364;','$','R');
    function updatePrice()
    {
        var c = document.getElementById('dest_country');
        var country = c.options[c.selectedIndex].value;
        var s = document.getElementById('service');
        var service = s.options[s.selectedIndex].value;
        var price=0;
        country = country.replace(/ /,'_'); 
       
        if (typeof(window[country]) != "undefined")
            var cVal=updateService(eval(country));
        else
            var cVal=updateService(0);

        if (document.getElementById('scan_and_save').checked==true)
            price=5;
        price=price + cVal;

        var curr = document.getElementById('currency');
        if (curr && curr.selectedIndex)
            var currency = curr.options[curr.selectedIndex].value;
        else
            var currency = 0;
        if (currency!=0)
        {
            var tprice = price * currs[ currency ];
            document.getElementById('price2').innerHTML = 'GBP: &#163;'+price.toFixed(2)+" is "+ curr_countries[ currency ] + ": "+curr_symbols[ currency ]+tprice.toFixed(2)+' (Guide only)';    
        }
        else
            document.getElementById('price2').innerHTML = '';
        document.getElementById('price').innerHTML = price.toFixed(2);    
    }
    function updateService(pricediff)
    {
        var values=new Array("standard","swift","express");
        var ucvalues=new Array("Standard","Swift","Express");
        var prices=new Array(25,40,60);
        var days=new Array(15,5,1);
        var c = document.getElementById('service');
        var current = c.options[c.selectedIndex].value;
        var selected = false;
        // wipe
        var service = document.getElementById('service');
        service.length=0;
        for (i=0;i<3;i++)
        {
            var s = (days[i]>1) ? 's' : '';
            var price=prices[i];
            if (pricediff!=0)
                price=price+pricediff;
            var newOpt = document.createElement('option');
            newOpt.text=ucvalues[i]+" Service ("+price.toFixed(2)+") - Up to "+days[i]+" Business Day"+s+" before Despatch";
            newOpt.value=values[i];


            try 
            {
                service.add(newOpt, null); // standards compliant; doesn't work in IE
            }
            catch(ex) 
            {
                service.add(newOpt); // IE only
            }
            if (current==values[i])
            {
                service.options[i].selected = true;
                var returnVal=prices[i]+pricediff;
                selected = true;
            }
            if (!selected)
            {
                service.options[0].selected = true;
                var returnVal=prices[0]+pricediff;

            }
            
        }
        return returnVal;
    }
    function checkYear(fId,mId,bId,sType)
    {
        var year = document.getElementById(fId).value;
        var m = document.getElementById(mId);
        var month = m.options[m.selectedIndex].value;
        var d = document.getElementById(bId);
        var day = d.options[d.selectedIndex].value;
        var checkYear = 2006;
        var checkMonth = 10;
        if (!isInteger(year) || year<1837)  
        {
            return "The "+sType+" must be 1837 or later\n";
        }
        if (month==0)
            month=1;
        if (day==0)
            day=1;
       
        month--;
        checkMonth--;
        var checkDate = new Date;
        checkDate.setFullYear(year,month,day);
        var currDate = new Date;
        currDate.setFullYear(checkYear,checkMonth,1);
        if (currDate < checkDate)
        {
            return "The year and month must be before Oct/2006\n";
        }
        return '';

    }
    function checkBirthYear(id)
    {
        var year = document.getElementById(id).value;
        if (year>1958)
            return addStarForBirth(true);
        else
            return addStarForBirth(false);
    }
    function checkDeathYearIsInt(id,id2)
    {
        var year = document.getElementById(id).value;
        var dyear = document.getElementById(id2).value;
        if (!isInteger(year) && dyear>=1955)
        {
            return "Age at death is required after 1955.\n";
        }
        if (year>130 && dyear>=1955)
        {
            return "Please enter an age at death.\n";
        }
        if (dyear>=1955 && !isInteger(year))
        {
            return "The Age at Death must be a number.\n";
        }
        return '';
    }
    function checkDeathYear(id)
    {
        var year = document.getElementById(id).value;
        if (!isInteger(year))
            return false; 
        if (year>=1955)
            return addStarForDeath(true);
        else
            return addStarForDeath(false);
    }
    function addStarForDeath(vBool)
    {

        var star = '';
        var msg = '';
        if (vBool)
        {
            star = '*';
            msg = '<br />Required after 1955';
        }
       document.getElementById('aatdeath').innerHTML = star;
       document.getElementById('aatdeath2').innerHTML = msg;

    }
    function addStarForBirth(vBool)
    {
        var bFields = new Array('sfathersurname','sfatherforename','smothermaidenname','smothersforename');
        var star = '';
        var msg = '';
        if (vBool)
        {
            star = '*';
            msg = 'Father\'s and Mother\'s details should be supplied, if known, if birth occured in last 50 years';
        }
        for (i=0;i<bFields.length;i++)
        {
            document.getElementById(bFields[i]).value = star;

        }
        document.getElementById('smsg').innerHTML = msg;
        return vBool;
    }
    function isInteger(s)
    {
        var i;
        if (isEmpty(s))
            if (isInteger.arguments.length == 1) 
                return 0;
            else 
                return (isInteger.arguments[1] == true);
                                   
        for (i = 0; i < s.length; i++)
        {
            var c = s.charAt(i);
            if (!isDigit(c)) return false;
        }
        return true;
    }
    function isEmpty(s)
    {
        return ((s == null) || (s.length == 0))
    }
    function isDigit (c)
    {
        return ((c >= "0") && (c <= "9"))
    }