design_sex = 'm';
var productType = 'tie';
var productName = 'Галстук';
var addShirtSvc = 'addTie';
var last_meas_step = last_meas_mens_step;
var meas = meas_mens;

set_attr_defaults ();

function dbg(obj) {
    elt('dbg').innerHTML = dump_object(obj);
}

function dump_object(obj, prepend) {
    html = '';
    if(prepend == null)
        prepend = 'root:';
    for(var i in obj) {
        if(typeof obj[i] == 'object')
            html += prepend + i + ':<br/>' + dump_object(obj[i], prepend + ":" + i + ':') + '<br/>';
        else
            html += prepend + i + ': ' + obj[i] + '<br/>';
    }

    return html;
}

function empty( val ) {
    return ( val === "" || val === 0   || val === "0" || val === null  || val === false  ||  ( typeof val=='object' && (val instanceof Array) && val.length === 0 ) );
}

//Начальная отрисовка рабочего пространства
//Если не рисуются начальные значения - ругаться сюда
function draw_workspace () {
    if(product['useTieFabric'] != 'true')
        select_icon ('fabric', product.fabric);
    //product.fabric = null;
    else
        select_icon ('tieFabric', product.tieFabric);

    select_icon('tieEnding', product.tieEnding);
    //select_icon('tieLength', product.tieLength);
    select_icon('tieWidth', product.tieWidth);
    //select_icon('tieThickness', product.tieThickness);

    select_icon ('embroideryFont', product.embroideryFont);
    select_icon ('embroideryColor', product.embroideryColor);
    select_icon ('embroideryVariant', product.embroideryVariant);
    select_icon ('embroidery', product.embroidery);
    select_icon ('invertStripes', product.invertStripes);

    select_icon ('embroideryZodiac2', product.embroideryZodiac2);
    select_icon ('embroideryZodiac1', product.embroideryZodiac1);
    select_icon ('embroideryEastern', product.embroideryEastern);

    select_icon ('embroideryHearts', product.embroideryHearts);
    select_icon ('embroidery23Febr', product.embroidery23Febr);
    select_icon ('embroiderySmile', product.embroiderySmile);
    select_icon ('embroideryLogo', product.embroideryLogo);
    select_icon ('embroideryDifferent', product.embroideryDifferent);
}

function design_init (section) {
    init ();

    container = document.getElementById('right_bottom');
    //var html = parseObject(productAttr);
    //container.innerHTML = html;

    urlbase = design_base + product.fabric + '/';

    var s = '';
    var l = new Array ();
    l.push ('img_background_fabric');
    l.push ('img_mask');
    for (i in l)
        if (PNGfix)
            s += '<div id="' + l[i] + '"></div>';
        else
            s += '<img id="' + l[i] + '" src="/images/dummy.gif" />';
    //    s += '<a href="#"><img src="../../images/dummy.gif" ismap width="375" height="410" border="0" style="position:absolute;top:0;left:0;z-index:29" /></a>';



    write_inner ('shirt_design', s);

    write_fabric_popup ('tieFabric', 3);
    write_fabric_popup ('fabric', 3);

    write_popup ('tieEnding', 2);
    //write_popup ('tieThickness', 2);
    //write_popup ('tieWidth', 3);
    write_tieWidth_popup ('tieWidth', 3);

    write_popup ('embroidery', 3);
    write_popup ('embroideryFont', 2);
    write_buttonsThread_popup ('embroideryColor', 3);

    /*** ТИПЫ ВЫШИВКИ ***/
    write_unisex_popup('embroideryVariant', 3, false, 'select_embroidery_button', false, 'embVariant'); // ТИПЫ
    write_unisex_popup('embroideryEastern', 3, true, null, 'embroideryEastern', 'embEastern'); // ВОСТОЧНЫЙ ГОРОСКОП
    write_unisex_popup('embroideryZodiac1', 3, true, null, 'embroideryZodiac1', 'embZodiac1'); // ЗНАКИ ЗОДИАКА1
    write_unisex_popup('embroideryZodiac2', 3, true, null, 'embroideryZodiac2', 'embZodiac2'); // ЗНАКИ ЗОДИАКА2
    write_unisex_popup('embroideryLogo', 2, false, null, 'embroideryLogo', 'embLogo'); // ЛОТОТИП
    write_unisex_popup('embroideryHearts', 2, false, null, 'embroideryHearts', 'embHearts'); // СЕРДЕЧКО
    write_unisex_popup('embroidery23Febr', 3, true, null, 'embroidery23Febr', 'emb23Febr'); // 23 ФЕВРАЛЯ
    write_unisex_popup('embroiderySmile', 2, false, null, 'embroiderySmile', 'embSmile'); // СМАЙЛЫ
    write_unisex_popup('embroideryDifferent', 3, true, null, 'embroideryDifferent', 'embDifferent'); // РАЗНОЕ

    write_unisex_popup ('invertStripes', 2);
    write_attr_cost ('embroidery', 'cost');

    disable_button('embroideryColor');
    disable_button('embroideryFont');

    select_thickness(product.tieThickness);

    //Возьмем границы для выпадающего списка из полученного объекта
    max = currentProductAttr.tieWidth.attr.max;
    min = currentProductAttr.tieWidth.attr.min;

    //generateRangeDropdown(min, max, 1, 'tieWidthSelect'); //Сгенерируем выпадающий список

    hide_item ('please_wait');
    draw_workspace ();
    change_section (section ? section : 'tie_design');
    
    $('a#fabric').trigger('click');
}

