// Определение объектов локализации

// Социальный статус
var social_status = new Array();
social_status[0]=['0','Student/Post graduate'];
social_status[1]=['1','Director'];
social_status[2]=['2','Specialist/manager'];
social_status[3]=['3','Private entrepreneur'];
social_status[4]=['4','Servant'];
social_status[5]=['5','Worker'];
social_status[6]=['6','Unemployed'];
social_status[7]=['7','Housewife'];
social_status[8]=['8','Retired'];

// Образование 
var education = new Array();
education[0]=['4','academic degree'];
education[1]=['3','higher education'];
education[2]=['2','incomplete higher education'];
education[3]=['1','college'];
education[4]=['0','school'];

// Материалы
var materials = new Array();
materials[0]=['Новостная лента','Streaming news'];
materials[1]=['Ежедневный технический анализ','Daily technical analysis'];
materials[2]=['Волновой анализ','Wave analysis'];
materials[3]=['Экономический календарь','Economic calendar'];
materials[4]=['Таблица процентных ставок','Interest rates table'];

// Частота посещения wap сайта
var wap_site_visiting = new Array();
wap_site_visiting[0]=['0','daily'];
wap_site_visiting[1]=['1','several times a week'];
wap_site_visiting[2]=['2','several times a month'];
wap_site_visiting[3]=['3','rarer than once a month'];
wap_site_visiting[4]=['4','for the first time'];

// Частота посещения сайта
var site_visiting = new Array();
site_visiting[0]=['0','daily'];
site_visiting[1]=['1','several times a week'];
site_visiting[2]=['2','several times a month'];
site_visiting[3]=['3','rarer than once a month'];
site_visiting[4]=['4','for the first time'];

// Курсы обучения
var training = new Array();
training[0]=['0','yes, in Your Company'];
training[1]=['1','yes, in other Company'];
training[2]=['2','no, but would like to'];
training[3]=['3',"no, I don't need it"];

// Источник
var source = new Array();
source[0]=['0','Web search'];
source[1]=['1','Web advertisement'];
source[2]=['2','Printed media'];
source[3]=['3','TV'];
source[4]=['4','Radio'];
source[5]=['5','Outdoor advertising'];
source[6]=['6','Personal recommendation of a relative/friend'];
source[7]=['7','Other'];

// Пол / sex
var sex = new Array();
sex[0]=['0','Mr'];
sex[1]=['1','Ms'];

// Форма открытия / doc_id
var doc_id = new Array();
doc_id[0]=['doc','Documentary'];
doc_id[1]=['nondoc','Non-Documentary'];

// Способ оплаты / pay_id
var pay_id = new Array();
pay_id[0]=['bUAHrs','Bank transfer in UAH to current account'];
pay_id[1]=['bUAHks','Bank transfer in UAH to paycard account'];
pay_id[2]=['bUSD','Bank transfer in US dollars'];
pay_id[3]=['WM','Payment via WebMoney'];
pay_id[4]=['RP','Payment via RUPAY'];
pay_id[5]=['eG','Payment via e-gold'];
pay_id[6]=['YD','Payment via Yandex.Money'];

// Другой способ оплаты / pay_id2
var pay_id2 = new Array();
pay_id2[0]=['bUAH','Bank transfer in UAH'];
pay_id2[1]=['bUSD','Bank transfer in US dollars'];
pay_id2[2]=['P24','Payment via Приват-24'];
pay_id2[3]=['WM','Payment via WebMoney'];
pay_id2[4]=['RP','Payment via RUPAY'];
pay_id2[5]=['eG','Payment via e-gold'];
pay_id2[6]=['YD','Payment via Yandex.Money'];

// Лицо / persontype
var persontype = new Array();
persontype[0]=['f','Physical entity'];
persontype[1]=['u','Legal entity'];

// Страна / country
var country = new Array();
country[0]=['gb','Great Britain'];
country[1]=['us','USA'];
country[2]=['ru','Russia'];
country[3]=['ua','Ukraine'];
country[4]=['au','Australia'];
country[5]=['at','Austria'];
country[6]=['az','Azerbaijan'];
country[7]=['ar','Argentina'];
country[8]=['am','Armenia'];
country[9]=['by','Belarus'];
country[10]=['be','Belgium'];
country[11]=['bg','Bulgaria'];
country[12]=['bo','Bolivia'];
country[13]=['br','Brasil'];
country[14]=['hu','Hungary'];
country[15]=['ve','Venezuela'];
country[16]=['de','Germany'];
country[17]=['nl','Holland'];
country[18]=['gr','Greece'];
country[19]=['ge','Georgia'];
country[20]=['dk','Denmark'];
country[21]=['il','Israel'];
country[22]=['in','India'];
country[23]=['id','Indonesia'];
country[24]=['iq','Iraq'];
country[25]=['ir','Iran'];
country[26]=['es','Spain'];
country[27]=['it','Italy'];
country[28]=['kz','Kazakhstan'];
country[29]=['ca','Canada'];
country[30]=['kg','Kyrgyzstan'];
country[31]=['cn','China'];
country[32]=['lv','Latvia'];
country[33]=['lt','Lithuania'];
country[34]=['lu','Luxemburg'];
country[35]=['md','Moldova'];
country[36]=['nz','New Zealand'];
country[37]=['no','Norway'];
country[38]=['py','Paraguay'];
country[39]=['pe','Peru'];
country[40]=['pl','Poland'];
country[41]=['ro','Romania'];
country[42]=['sa','Saudi Arabia']
country[43]=['sk','Slovakia'];
country[44]=['tj','Tajikistan'];
country[45]=['th','Tailand'];
country[46]=['tr','Turkey'];
country[47]=['tm','Turkmenistan'];
country[48]=['uz','Uzbekistan'];
country[49]=['uy','Uruguay'];
country[50]=['fi','Finland'];
country[51]=['fr','France'];
country[52]=['hr','Croatia'];
country[53]=['cz','Czechia'];
country[54]=['ch','Switzerland'];
country[55]=['se','Sweden'];
country[56]=['ec','Equador'];
country[57]=['ee','Estonia'];
country[58]=['za','SAR'];
country[59]=['jp','Japan'];
country[60]=['??','Other'];

// Месяц года
var month_name = new Array();
month_name[0]=['1','January'];
month_name[1]=['2','February'];
month_name[2]=['3','March'];
month_name[3]=['4','April'];
month_name[4]=['5','May'];
month_name[5]=['6','June'];
month_name[6]=['7','July'];
month_name[7]=['8','August'];
month_name[8]=['9','September'];
month_name[9]=['10','October'];
month_name[10]=['11','November'];
month_name[11]=['12','December'];

function LocalizeHistory()
{
    var spans = document.getElementsByName('payid');
    for (var i = 0; i < spans.length; i++) {
        var span = spans[i];
        var code = span.innerText;
        var value = GetSourceValue(pay_id, code, code);
        if (value == code)
            value = GetSourceValue(pay_id2, code, code);
        span.innerText = value;
    }
}

// Выполняет локализацию указанного контрола
function Localize(fieldName, fieldType, controlId)
{
    var ctl = document.getElementById(controlId);
    if (!ctl) 
    {
        return;
    }

    eval('ProcessField(ctl,' + fieldName + ',fieldType)');
}

// Выполняет обработку полей
function ProcessField(ctl, source, fieldType)
{
    switch (fieldType)
    {
        case 'select':
            ProcessFieldSelect(ctl, source);
            break;
        case 'radio':
            ProcessFieldRadio(ctl, source);
            break;
	case 'multichoice':
            ProcessFieldMultiChoice(ctl, source);
            break;
        case 'text':
            ProcessFieldText(ctl, source);
            break;
        case 'datetimedropdown':
            ProcessFieldDTDropdown(ctl, source);
            break;
        default:
            alert('Тип поля не определен!');
    }
}

// Выполняет обработку поля типа Dropdown выбора даты
function ProcessFieldDTDropdown(ctl, source)
{
    for (var i=0; i < ctl.childNodes.length; i++)
    {
        var child = ctl.childNodes[i];
        if (child.nodeName == 'OPTION')
            child.text = GetSourceValue(source, child.value, child.text);
    }
}

// Выполняет обработку поля типа Text
function ProcessFieldText(ctl, source)
{
    ctl.innerHTML = GetSourceValue(source, ctl.innerHTML, ctl.innerHTML);
}

// Выполняет обработку поля типа Select
function ProcessFieldSelect(ctl, source)
{
    for (var i=0; i < ctl.childNodes.length; i++)
    {
        var child = ctl.childNodes[i];
        if (child.nodeName == 'OPTION')
            child.text = GetSourceValue(source, child.value, child.text);
    }
}

// Выполняет обработку поля типа Radio
function ProcessFieldRadio(ctl, source)
{
    var tbody = FindControlUnder(ctl, 'TBODY');
    
    for (var i=0; i < tbody.childNodes.length; i++)
        if (tbody.childNodes[i].nodeName == 'TR')
        {
            var tr = tbody.childNodes[i];
            var td = FindControlUnder(tr, 'TD');
            var input = FindControlUnder(td, 'INPUT');
            var label = FindControlUnder(td, 'LABEL');
            label.innerHTML = GetSourceValue(source, input.value);
        }

}

// Выполняет обработку поля типа MultiChoice
function ProcessFieldMultiChoice(ctl, source)
{
    var tbody = FindControlUnder(ctl, 'TBODY');
    
    for (var i=0; i < tbody.childNodes.length; i++)
        if (tbody.childNodes[i].nodeName == 'TR')
        {
            var tr = tbody.childNodes[i];
            var td = FindControlUnder(tr, 'TD');
            var input = FindControlUnder(td, 'INPUT');
            var label = FindControlUnder(td, 'LABEL');
            label.innerHTML = GetSourceValue(source, label.innerHTML);
        }
}

// Поиск заданного контрола
function FindControlUnder(parent, nodeName)
{
    for (var i=0; i < parent.childNodes.length; i++)
        if (parent.childNodes[i].nodeName == nodeName)
            return parent.childNodes[i];
        
    return;
}

// Получение строки из объекта локализации
function GetSourceValue(source, key, oldValue)
{
    for (var j=0; j < source.length; j++)
        if (key == source[j][0])
            return source[j][1];   
            
    return oldValue;
}
