﻿// JScript File


function tree_node(node, imd_expanded, img_collapsed) 
{
	if (node.nextSibling.nextSibling.style.display == 'none') {
		if (node.hasChildNodes)	{
			if (node.firstChild.tagName == "IMG") {
				node.firstChild.src = imd_expanded;
				node.firstChild.alt = "свернуть";
			}
		}
		node.nextSibling.nextSibling.style.display = 'block';
	} else {
		if (node.hasChildNodes)	{
			if (node.firstChild.tagName == "IMG") {
				node.firstChild.src = img_collapsed;
				node.firstChild.alt = "развернуть";
			}
		}
		node.nextSibling.nextSibling.style.display = 'none';
	}
}

function show_img(wnd, url) 
{
		wnd = window.open(url, 0, "resizable=yes,scrollbars=yes,width=800,height=600,top=50,left=50");
} 

function goto_wmpay() 
{
	var amObj = document.getElementById('WMAmount');
	wnd = window.open("/WMpay.aspx?amount=" + amObj.value, "_blank", "resizable=yes,scrollbars=yes,width=750,height=550,top=50,left=50");
	return false;
}

function deletemessages() {
    if (!confirm('Удалить все отмеченные сообщения?')) {return;}
        var mes_list = "";
        $("span.checkitem").find("input:checked").each(function (ind, obj) {
            mes_list = mes_list + $(this).attr('id') + ";";
        });
        $.ajax({
            url: '/action.ashx?action=delete_selected_messages&listmes=' + mes_list,
            beforeSend: function () { },
            success: function (data) {
                window.location.reload();
            },
            error: function (handle, data, err) {
                alert(err);
            }
        });
}

function readmessages() {
    var mes_list = "";
    $("span.checkitem").find("input:checked").each(function (ind, obj) {
        mes_list = mes_list + $(this).attr('id') + ";";
        $(this).attr("checked", "");
    });
    $.ajax({
        url: '/action.ashx?action=read_selected_messages&listmes=' + mes_list,
        beforeSend: function () { },
        success: function (data) {
            var array = mes_list.split(';');
            for (i = 0; i < array.length; i++) $('#' + array[i] + 'span').attr('class', 'icon msgread');
        },
        error: function (handle, data, err) {
            alert(err);
        }
    });
}

//проверка текущего текстового поля
function find_number_mail(id_ctrl, is_pro) {
    var closed = $('input#close_ctrl').attr("value"); //не открываем подсказку,если она была закрыта для данного поля
    var template = "";
    var obj = "";

    var txt = $('input#' + id_ctrl).attr('value');
    if (txt != undefined) { obj = "input#" + id_ctrl; }
    else { obj = "textarea#" + id_ctrl; txt = $(obj).attr('value'); }

    var regexEmail = /\S+@\S+\.\w+/;
    regexEmail.ignoreCase = true;
    var regexNumPhone = /((\+7|8)((:?\s|\-)*([0-9]|(один)|З|з|l|o|O|о|О|(два)|(три)|(четыре)|(пять)|(шесть)|(семь)|(восемь)|(девять))){10})|(?:(?:\s|\-)*(?:[0-9]|(?:один)|(?:З)|(?:з)|(?:l)|(?:o)|(?:O)|(?:о)|(?:О)|(?:два)|(?:три)|(?:четыре)|(?:пять)|(?:шесть)|(?:семь)|(?:восемь)|(?:девять))){7}/;
    regexNumPhone.ignoreCase = true;

    //if (regexEmail.test(txt) || regexNumPhone.test(txt)) $(obj).addClass("error_mail_tel");
    //else $(obj).removeClass("error_mail_tel");

    if (regexNumPhone.test(txt) && regexEmail.test(txt)) { template = "адрес электронной почты и номер телефона"; }
    else
        if (regexNumPhone.test(txt)) { template = "номер телефона"; }
        else
            if (regexEmail.test(txt)) { template = "адрес электронной почты"; }

    if (template != "" && closed.indexOf(id_ctrl, 1) == -1) {
        $(obj).before($('div#hint_ctrl')); //вставляем подсказку в нужное место

        $('div#idhint').attr("class", "showhint");
        $('input#cur_ctrl').attr("value", id_ctrl);

        if (is_pro == "1") { document.getElementById("text_hint").innerHTML = "Рекомендуем разместить <b>" + template + "</b> в поле \"Дополнительная контактная информация\""; }
        else { document.getElementById("text_hint").innerHTML = "<b>Внимание!</b> Размещение контактов в несоответствующих полях является нарушением <a href=\"http://www.24au.ru/about/1/?#p8.20\">Правил</a> аукциона 24au.ru. Ваш лот будет снят с торгов. Для публикации контактной информации на страницах лотов подключите <a href=\"http://www.24au.ru/profile/pro/\">ПРО-аккаут</a> или создайте <a href=\"http://www.24au.ru/editadv/\">Объявление</a>."; }
    }
    else { $('div#idhint').attr("class", "hidehint"); }
}

function applyTBFilter(filter, text) {

    if (filter == 'Numbers') {
        var regex = /^[\d]*$/;
        if (!regex.test(text)) {
            var regex2 = /\d*/;
            return regex2.exec(text)[0];
        }
    } else {
        var reg = new RegExp("^" + filter + "$", "i")
        if (!reg.test(text)) {
            var regex2 = new RegExp(filter, "i")
            return regex2.exec(text)[0];
        }
    }

    return text;
}

function repeatlots() {
    if (!confirm('Перевыставить все отмеченные лоты?')) { return; }
    var lot_list = "";
    $("span.checkitem").find("input:checked").each(function (ind, obj) {
        lot_list = lot_list + $(this).attr('id') + ";";
        $(this).attr("checked", "");
    });
    $('img.waitmass').show();
    $("#checkall").attr("checked", "");
    $.ajax({
        url: '/action.ashx?action=repeat_selected_lots&listlot=' + lot_list,
        beforeSend: function () { },
        success: function (data) {
            if (data != "") {
                $('img.waitmass').hide();
                var error_lot = data.split('/');
                for (var i = 0; i < error_lot.length; i++) {
                    var lot = error_lot[i].split(';');
                    $('span#error' + lot[0]).text(lot[1]);
                    $('div#error' + lot[0]).show();
                }
                var hide_lot = lot_list.split(';');
                for (var i = 0; i < hide_lot.length; i++) {
                    if ($('span#error' + hide_lot[i]).text() == "")
                    { $('tr#' + hide_lot[i]).hide(); }
                }
            } else { window.location.reload(); }
        },
        error: function (handle, data, err) {
            alert(err);
            $('img.waitmass').hide();
        }
    });
}

function deletelots() {
    if (!confirm('Удалить все отмеченные лоты?')) { return; }
    var lot_list = "";
    $("span.checkitem").find("input:checked").each(function (ind, obj) {
        lot_list = lot_list + $(this).attr('id') + ";";
        $(this).attr("checked", "");
    });
    $('img.waitmass').show();
    $("#checkall").attr("checked", "");
    $.ajax({
        url: '/action.ashx?action=delete_selected_lots&listlot=' + lot_list,
        beforeSend: function () { },
        success: function (data) {
            if (data != "") {
                $('img.waitmass').hide();
                var error_lot = data.split('/');
                for (var i = 0; i < error_lot.length; i++) {
                    var lot = error_lot[i].split(';');
                    $('span#error' + lot[0]).text(lot[1]);
                    $('div#error' + lot[0]).show();
                }
                var hide_lot = lot_list.split(';');
                for (var i = 0; i < hide_lot.length; i++) {
                    if ($('span#error' + hide_lot[i]).text() == "")
                    { $('tr#' + hide_lot[i]).hide(); }
                }
            } else {window.location.reload(); }
        },
        error: function (handle, data, err) {
            alert(err);
            $('img.waitmass').hide();
        }
    });
}


