$(function() {
    $('.gotoHome').click(function() { window.location.href = 'http://' + window.location.hostname + '/' + $("html:first").attr("xml:lang") + "/" });
    $('form.podbor1 input[type=image]').click(function() { podbor($(this)); return false; });
    $('form.podbor2 input[type=image]').click(function() { podbor($(this)); return false; });
    $('form.podbor4 input[type=image]').click(function() { podbor($(this)); return false; });
});

function podbor (ths) {
    var str = "";
    var form = ths.closest("form");
    var tovarTypeId = ths.closest("form").find("input[name='tovarTypeId']").val();
    if (!tovarTypeId) tovarTypeId = 4;
//    ths.closest("form").find("select").each(function (i){
//	var option = $(this).find('option:selected');
    [1,2,3,4,5,6].forEach(function (element, index, array){
	var option = form.find('select[name="sel' + tovarTypeId + '-' +element + '"] option:selected');
	if (option.val()){
	    var text = option.text();
	    var val = option.val();
	    if (text.indexOf(' [') > 0) text = text.substring(0, text.indexOf(' ['));
	    if (val === text) text = "";
	    text = text.replace(new RegExp ('/', 'g'), '_');
	    val = val.replace(new RegExp ('/', 'g'), '_');
	    if (val > 0 & text != "") str = str + text + "-";
	    str = str + val + "/";
	}
    });

    if (tovarTypeId == 1) str = "shini/" + str;
    if (tovarTypeId == 2) str = "diski/" + str;
    if (tovarTypeId == 4) str = "auto/" + str;
    str = str.replace("&", "_");
    str = $("html:first").attr("xml:lang") + "/" + str;
//    alert(str);
    var hostname = window.location.hostname;
    // обрезаем поддомен
    if (hostname.indexOf("shinikiev") > -1) hostname = hostname.substr(hostname.indexOf("shinikiev"));
    window.location.href = 'http://' + hostname + '/' + str;
}

function myfunc() {
    if (arguments[0].length > 0) select_list_new_options('sel4-2', arguments[0]);
    select_list_new_options('sel4-3', arguments[1]);
}

