﻿// parsing country code from maxmind api
try {
    var country = geoip_country_code();
}
catch (e) { 
    var country = "UK"
}

// array of farsi speaking countries
var farsiSpk = ['IR', 'TJ', 'AF'];
// array of arabic speaking countries
var arabicSpk = ['DZ', 'EG', 'IQ', 'JO', 'KW', 'LY', 'MA', 'QA', 'SA', 'SY', 'AE', 'BH'];

// returns true if a matching farsi speaking country code is found
function isFarsi() {
    for (i = 0, i; farsiSpk.length; i++) {
        if (country === farsiSpk[i]) {
            return true;
        }
        else {
            return false;
        }
    }
}

// returns true if a matching arabic speaking country code is found
function isArabic() {
    for (i = 0, i; arabicSpk.length; i++) {
        if (country === arabicSpk[i]) {
            return true;
        }
        else {
            return false;
        }
    }
}

if (isFarsi()) {
    document.location = 'fa/index.htm';
}
else if (isArabic()) {
    document.location = 'ar/index.htm';
}

else if (!isArabic() && !isFarsi()) {
    document.location = 'en/index.htm';
}

else {
    document.location = 'en/index.htm';
}
