window.onload = function(e) { marginReset(); fillPrintableContent(); }
window.onresize = function(e) { marginReset(); }
function marginReset() {
    var l_header = document.getElementById("header_common");
    var l_content = document.getElementById("block_base1");
    if ((l_header) && (l_content)) {
        if (document.body.offsetWidth < 1016) {
            l_header.style.marginLeft = "0px";
            l_content.style.marginLeft = "0px";
            l_header.style.left = "0px";
            l_content.style.left = "0px";
        } else {
            l_header.style.marginLeft = "-500px";
            l_content.style.marginLeft = "-500px";
            l_header.style.left = "50%";
            l_content.style.left = "50%";
        }
    }
}

// возвращает параметр по его имени из строки запроса
function GetUrlParam(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}


/* ========================================================================== */
/*  для взаимодействия с порталом минсвязи 10.02.2004 */
/* ========================================================================== */

function CheckURL() {
    try {
        if ((window.parent.document.URL != document.URL) &&
			(window.parent.document.URL != "http://www.minsvyaz.ru/post_index.html")) {
            window.parent.location.href = document.URL;
        }
    } catch (er) {
        window.parent.location.href = document.URL;
    }
}


/* ========================================================================== */
/*  валидаторы */
/* ========================================================================== */

function validateAndSubmit() {
    with (document.F1) {

        if (regLogin.value == "") {
            alert('Пожалуйста, укажите Логин!');
            regLogin.focus();
            return false;
        }

        if (regPassword.value == "") {
            alert('Пожалуйста, укажите Пароль!');
            regPassword.focus();
            return false;
        }

        return true;

    }
}


function cSubmit() {
    with (document.F1) {
        if (regLogin.value == "") {
            alert('Пожалуйста, укажите Логин!');
            regLogin.focus();
            return false;
        }
        else {
            if (regPassword.value == "") {
                alert('Пожалуйста, укажите Пароль!');
                regPassword.focus();
                return false;
            }
            submit();
        }
    }
}


function show(num, bln) {
    var link = "/resp_engine.aspx?Path=RU/Home/aboutrussianpost/russianpoststructure/fps" + "&XMLPARAM_num=" + num;
    //num.href=link;
    if (bln == 1) {
        nw = window.open(link, "", "menubar=no,scrollbars=0,resizable=no,width=450, height=280");
        // num.href="javascript:";
    }
}

function openInNewWindow(wLink, wHeight, wWidth, wResize, wScrollBars, wMenuBar) {
    if (wScrollBars == null) wScrollBars = 0;
    if (wMenuBar == null) wMenuBar = 0;
    window.open(wLink, "_blank", "height=" + wHeight + ",width=" + wWidth + ",menubar=" + wMenuBar + ",scrollbars=" + wScrollBars + ", resizable=" + wResize);
}

function sendMail() {
    with (document.F1) {
        WHEREONOK.value = "COMPANY/RU/Home/Press/Accreditation/SubmitOk";
        PATHFROM.value = "COMPANY/RU/Home/Press/Accreditation/SubmitFailed";
        submit();
    }
}


/* ========================================================================== */
/* поиск по порталу */
/* ========================================================================== */

function sendSearch2() {
    var strSearch = document.F1.searchAdd.value;
    var strLink = "/resp_engine.aspx?Path=RP/INDEX/RU/Home/Search" + "&keyword=" + strSearch;
    //alert(strLink);
    document.location = strLink;
    return false;
}

function sendSearch2OnEnter(evt) {
    if (null == evt) { evt = window.event; }
    var code = evt.keyCode;
    //alert(code);
    if (code == 13) {
        sendSearch2();
        return false;
    } else {
        return true;
    }
}


/* ========================================================================== */
/* поиск по порталу (старый)*/
/* ========================================================================== */

function sendSearch() {
    var strSearch = document.F1.TEXTSEARCH.value;
    document.F1.action = "/resp_engine.aspx?Path=" + document.F1.PATHPAGE.value
		+ "&SEARCHSTR=" + strSearch
		+ "&PATHWEB=" + document.F1.PATHWEB.value
		+ "&PATHPAGE=" + document.F1.PATHPAGE.value;
    document.F1.submit();
}

function changeSearchText() {
    var strSearch = document.F1.TEXTSEARCH.value;
    document.F1.action = "/resp_engine.aspx?Path=" + document.F1.PATHPAGE.value
		+ "&SEARCHSTR=" + strSearch
		+ "&PATHWEB=" + document.F1.PATHWEB.value
		+ "&PATHPAGE=" + document.F1.PATHPAGE.value;
}


/* ========================================================================== */
/* версия для печати */
/* ========================================================================== */


function SetPrintableOld() {
    with (document.F1) {
        var PT, PB, link
        //PRINTTITLE.value=PrintTitleDiv.innerHTML;
        //PRINTBODY.value=PrintBodyDiv.innerHTML;
        link = "/resp_engine.aspx?Path=PORTAL/RU/Home/print";
        //   action=link;
        window.open(link, "", "menubar=yes,scrollbars=1,resizable=yes,width=750, height=500");

    }
}

function SetPrintable() {
    var strLink;
    var strSeparator = "";
    strLink = window.location.href;
    strSeparator = (strLink.indexOf("?") != -1) ? "&" : "?";
    var arrayStr = strLink.split("#");
    strLink = (arrayStr[0] != null) ? arrayStr[0] : "";
    strLink += strSeparator + "print=1";
    window.open(strLink, "", "menubar=yes, scrollbars=1, resizable=yes, width=750, height=500");
}

function GetPrintable() {
    var titleNodeSrc = window.opener.parent.document.getElementsByTagName("title");

    if (titleNodeSrc != null && titleNodeSrc[0].innerText != null) {
        document.title = titleNodeSrc[0].innerText;
    }

    var blockMainSrc = window.opener.parent.document.getElementById("block_main");
    var locatorSrc;

    if (blockMainSrc != null) {
        locatorSrc = blockMainSrc.getElementsByTagName("ul");
        if (locatorSrc != null) {
            locatorNode = document.getElementById("LocatorDiv");
            if (locatorNode != null && locatorSrc[0].outerHTML != null) {
                locatorNode.innerHTML = locatorSrc[0].outerHTML;
            }
        }
    }

    var linksDiv = document.getElementById("LinksDiv")
    if (linksDiv != null && window.opener.parent.location != null) {
        linksDiv.innerHTML = window.opener.parent.location;
    }

    with (document.F1) {
        //alert(window.opener.parent.F1.PrintBodyDiv.innerHTML);

        if (!(window.opener.parent.document.all.item("PRINTTITLE") == null)) {
            PrintTitleDiv.innerHTML = window.opener.parent.document.all.item("PRINTTITLE").innerHTML;
        }

        if (!(window.opener.parent.document.all.item("PRINTBODY") == null)) {
            PrintBodyDiv.innerHTML = window.opener.parent.document.all.item("PRINTBODY").innerHTML;
        }
    }
}

// заполняет контент версии для печати

function fillPrintableContent() {
    var l_isPrintable = GetUrlParam('print');
    if (l_isPrintable) {
        if (!(window.opener.parent.document.getElementById("PRINTTITLE") == null)) {
            document.getElementById("PRINTTITLE").innerHTML = window.opener.parent.document.getElementById("PRINTTITLE").innerHTML;
        }

        if (!(window.opener.parent.document.getElementById("PRINTBODY") == null)) {
            document.getElementById("PRINTBODY").innerHTML = window.opener.parent.document.getElementById("PRINTBODY").innerHTML;
        }
    }
}

/* ========================================================================== */
/* открытки */
/* ========================================================================== */

function EditPostCard(_postcardId) {
    openInNewWindow('/postcards/sendpostcard_new.asp?POSTCARD=' + _postcardId, 1500, 1000, 1, 1);
}

/* ========================================================================== */
/* Вакансии                                                                   */
/* ========================================================================== */

function sendResume(_vacancyId) {
    openInNewWindow('/Forms/Vacancies/additem.aspx?VacancyId=' + _vacancyId, 500, 500, 1, 0);
}

/* ========================================================================== */
/* Подписка на новости                                                        */
/* ========================================================================== */

function isEmail2(who) {
    var email = /^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
    return (email.test(who));
}

function cEdit() {
    with (document.F1) {
        var str = password.value;
        var strMsg = '';

        if (isEmail2(email.value) && (password.value) != '') {
            var str = '';
            str = '/sub.aspx?LangID=1&OP=2&password=' + password.value + '&Email=' + email.value;
            //alert(str);
            window.open(str, "_", 'width=750, height=410, resizable=yes, scrollbars=yes');
        }
        else {
            if ((password.value) == '') {
                strMsg = 'Введите пароль, пароль не должен состоять только из пробелов.\n';
                password.focus();
            }
            //alert(email.value);
            if (!isEmail2(email.value)) {
                strMsg = strMsg + 'Введите E-Mail латинскими буквами, \nформат ввода name@domain.(x), x - зона домена \n не должна содержать цифры.';
                email.focus();
            }
            alert(strMsg);
        }
    }
}


//-------------------------------------------------------------------------------------------------------------

function cSubMain() {
    with (document.F1) {
        if (isEmail2(email.value)) {
            var str = '';
            str = '/sub.aspx?LangID=1&email=' + email.value + '&OP=-1';
            window.open(str, '_', 'width=760, height=390, resizable=1, scrollbars=1');
            OP.value = '2';
            //target='_';
        }
        else {
            str = '/sub.aspx?LangID=1';
            window.open(str, '_', 'width=760, height=390, resizable=1, scrollbars=1');
            OP.value = '2';
            //target='_';
        }
    }
}


//-------------------------------------------------------------------------------------------------------------
function cResend() {
    with (document.F1) {
        if (isEmail2(email.value)) {
            var str = '';
            str = '/resp_engine.aspx?Action=SS_Resend&OP=2&LangId=1&password=' + password.value + '&email=' + email.value;

            window.open(str, '_', 'width=740, height=380, resizable=1, scrollbars=1');
            OP.value = '2';
            //target='_';
        }
        else {
            alert('Введите E-Mail');
            email.focus();
        }
    }
}

//-------------------------------------------------------------------------------------------------------------
function cAdd() {
    with (document.F1) {

        if (email.value != '') {
            OP.value = '1';
            var link = "/sub.aspx?", strsend = '';
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == true) {
                    strsend = strsend + 'item=' + item[i].value + '&';
                }


            }
            if (formattype[0].checked == true)
            { strsend = strsend + 'formattype=1'; }

            if (formattype[1].checked == true)
            { strsend = strsend + 'formattype=0'; }

            if (codetype[0].checked == true)
            { strsend = strsend + '&codetype=1'; }

            if (codetype[1].checked == true)
            { strsend = strsend + '&codetype=0'; }

            // '&codetype=' +codetype.value;

            strsend = strsend + '&email=' + email.value + '&OP=1';
            window.open(link + strsend, "", "menubar=no,scrollbars=1,resizable=1,width=840, height=200");

            //submit();
        }
        else {
            alert('Введите E-Mail');
            email.focus();
        }
    }
}
//-------------------------------------------------------------------------------------------------------------
function cClearForm() {
    with (document.F1) {

        for (var i = 0; i < item.length; i++) {
            item[i].checked = false;
        }
    }
}
var bl = 0;
//-------------------------------------------------------------------------------------------------------------
function cEmail() {
    if (bl == 0) {
        F1.email.value = '';
        bl = 1;
    }
}
//-------------------------------------------------------------------------------------------------------------
function MakeSubscribe(num) {
    with (document.F1) {
        var link = "/resp_engine.aspx?Path=RU/Home/Services/rpprojects/cyberpost/pkd/pkd&NEWSID=" + num;
        window.open(link, "", "menubar=no,scrollbars=1,resizable=no,width=750, height=500");

    }
}
////////////////////////////////////////////////////////////
// Функции отслеживания почтовых отправлений
////////////////////////////////////////////////////////////              
function Wind(ID) {

    var link = "resp_engine.aspx?Path=RP/SERVISE/RU/Home/postuslug/SearchOPS/SearchOPSPortalExtended&NEWSID=" + ID;
    window.open(link, "", "menubar=no,scrollbars=1,resizable=no,width=750, height=500");
    //var dep= document.getElementById("ref")              
    //window.open ("http://info.russianpost.ru/servlet/department?action=show_info&depID="+ ID, 'Index',               
    //config='height=600,width=600,status=no,resizable=no,toolbar=no,menubar=no,scrollbars=no,location=no')              
}

function WindNew(ID, OPER) {
    //var dep= document.getElementById("ref")              
    if (OPER == "2") //открываем окно только при операции вручения              
    {

        var link = "resp_engine.aspx?Path=RP/SERVISE/RU/Home/postuslug/SearchOPS/SearchOPSPortalExtended&NEWSID=" + ID;
        window.open(link, "", "menubar=no,scrollbars=1,resizable=no,width=750, height=500");
        //window.open ("http://info.russianpost.ru/servlet/department?action=show_info&depID="+ ID, 'Index',                
        //config='height=600,width=600,status=no,resizable=no,toolbar=no,menubar=no,scrollbars=no,location=no')              
    }
}

function CheckInputCode_old() {
    var validcode = document.getElementById("validcode");
    var BarCode = document.getElementById("BarCode");
    var searchsign = document.getElementById("searchsign");
    var lblVldCdeErrMsg = document.getElementById("lblVldCdeErrMsg");
    var lblBrcdErrMsg = document.getElementById("lblBrcdErrMsg");

    if (validcode.value == "") {
        lblVldCdeErrMsg.innerHTML = "Не введён проверочный код!";
        lblBrcdErrMsg.innerHTML = "";
        return;
    }
    else if (BarCode.value == "") {
        lblBrcdErrMsg.innerHTML = "Не введён почтовый идентификатор!";
        lblVldCdeErrMsg.innerHTML = "";
        return;
    }

    if ((BarCode.value != "") && (validcode.value != "")) {
        searchsign.value = "1";
        document.forms[0].submit();
    }
}


function CheckInputCode() {
    var validcode = document.getElementById("validcode");
    var BarCode = document.getElementById("BarCode");
    var searchsign = document.getElementById("searchsign");
    var lblVldCdeErrMsg = document.getElementById("lblVldCdeErrMsg");
    var lblBrcdErrMsg = document.getElementById("lblBrcdErrMsg");

    if (BarCode.value == "") {
        lblBrcdErrMsg.innerHTML = "Не введён почтовый идентификатор!";
        //lblVldCdeErrMsg.innerHTML = "";              
        return;
    }

    var checkPatern = /\d{14}/;
    if (!checkPatern.test(BarCode.value)) {
        var chechInternationalWorld = /[a-z]{2}\d{9}[a-z]{2}$/i;
        if (!chechInternationalWorld.test(BarCode.value)) {
            lblBrcdErrMsg.innerHTML = "Неверно введен почтовый идентификатор!";
            return;
        }
    }


    if (BarCode.value != "") {
        searchsign.value = "1";
        document.forms[0].submit();
    }
}              
             
