﻿//проверка заполенности поля ввода поисковой фразы
function CheckInitSearch() {
    var form_obj = document.SearchForm;
    if ((form_obj.srch98query.value != form_obj.srch98query.defaultValue) && (form_obj.srch98query.value.length > 0)) {
        form_obj.submit();
    } else {
        alert("Необходимо задать условия поиска");
    }
    return false;
}

function window_open(title, href, target, width, height) {
    width = parseInt(width, 10);
    height = parseInt(height, 10);
    var wind_img = window.open('', target, 'width=' + (height > 800 ? width + 16 : width) + ',height=' + (height > 800 ? 800 : height) + (height > 800 ? ',scrollbars=yes' : '') + ',resizable=yes');
    wind_img.focus();
    wind_img.document.open();
    wind_img.document.write('<html><head><META http-equiv="Content-Type" content="text/html; charset=windows-1251">' + (title ? '<title>' + title + '</title>' : '<title>Большое изображение</title>') + '</head>');
    wind_img.document.write('<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0"><img src="' + href + '" border="0" width="' + width + '" height="' + height + '" title="' + title + '" alt="' + title + '">');
    wind_img.document.write('</body></html>');
    wind_img.document.close();
    return false;
}

var PrintView = {

    _printIndex: -1,
    _printLink: null,
    enabled: false,

    enable: function() {
        if (this.enabled) return;
        $('#logo_print').attr('src', '/i/print/logo_print.jpg');
        if (this._printLink == null) {
            this._printLink = document.createElement("link");
            this._printLink.setAttribute("rel", "stylesheet");
            this._printLink.setAttribute("href", "/_css/print.css");
            document.body.appendChild(this._printLink);
            this._printIndex = document.styleSheets.length - 1;
        }
        this.enabled = true;
        for (var i = 0; i < document.styleSheets.length; ++i) {
            if (i == this._printIndex)
                document.styleSheets[i].disabled = false;
            else
                document.styleSheets[i].disabled = true;
        }
    }
  ,
    disable: function() {
        if (this._printLink == null || !this.enabled) return;
        this.enabled = false;
        for (var i = 0; i < document.styleSheets.length; ++i) {
            if (i == this._printIndex)
                document.styleSheets[i].disabled = true;
            else
                document.styleSheets[i].disabled = false;
        }
    }
  ,
    autoPrint: function() {
        if (document.location.search.indexOf("?printv") >= 0 || document.location.search.indexOf("&printv") >= 0) {
            this.run();
        }
    }
  ,
    run: function() {
        this.enable();
        window.print();
    }
  ,
    openWindow: function() {
        var url = document.location.pathname+document.location.search;
        if (document.location.search.indexOf('?') >= 0) url += "&printv";
        else url += "?printv";
        url += document.location.hash;
        var pwin = window.open(url, 'printWindow');
    }
}

jQuery(function() { PrintView.autoPrint(); });

function AddToFavorites(obj, title, url) {
    if (window.sidebar) {
        // Mozilla Firefox 
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.external) {
        // IE 
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) {
        //Opera
        obj.setAttribute('href', url);
        obj.setAttribute('title', title);
        obj.setAttribute('rel', 'sidebar');
        obj.click();
    }
    return false;
}

function ChangeCalendar(calendarDivId, idSubContainer, year, month) {

    // alert(calendarId + ' ' + year + ' ' + month);
    var url = "/_modules/calendar/calendar.ashx"

    $.ajax({
        type: "POST",
        url: url,
        data: "id_sub_container=" + idSubContainer + "&year=" + year + "&month=" + month,
        cache: false,
        success: function(data) { UpdateCalendar(calendarDivId, data); },
        error: function() { alert("Произошла ошибка на вызываемой странице."); }
    });
}

function UpdateCalendar(calendarDivId, data) {
    if (data != "") {
        $("#" + calendarDivId).replaceWith(data);
    }
}