// JavaScript Document

function getObj(name) {
    if (document.getElementById) return document.getElementById(name);
    else if (document.all) return document.all[name];
    else if (document.layers) return document.layers[name];
    else return false;
}

function transparent(im) {
    if (!im.transparented && (/\.png/.test(im.src))) {
        im.transparented = 1;
        var picture = im.src;
        var w = im.width;
        var h = im.height;
        im.src = "i/no.gif";
        im.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='scale', src='" + picture + "');";
        //  im.width = w; im.height = h;
    }
    return "transparent";
}

function highlight() {
    var atags = document.getElementsByTagName('a');
    for (var i = 0; i < (atags.length); i++) {
        if (atags[i].className == "nav") {
            if (document.location.href.indexOf(atags[i].href) != -1) {
                atags[i].className = "active";
            }
        }
    }
}

function ShowHide(id) {

    if (id != '') {
        var itm = null;
        var pitm = null;
        if (document.getElementById) {
            itm = document.getElementById(id);
        }
        else if (document.all) {
            itm = document.all[id];
        }
        else if (document.layers) {
            itm = document.layers[id];
        }

        if (!itm) { /* do nothing */
        }
        else if (itm.style) {
            if (itm.style.display == "none") {
                itm.style.display = "";
            }
            else {
                itm.style.display = "none";
            }
        }
        else {
            itm.visibility = "show";
        }
    }

    // id.style.display="visible";
}

function isValidEmail(email) {
    re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;
    return re.test(email);
}


function makeCheck(address) {

    if (isValidEmail(address)) {
        return true;
        document.zakform.submit;
    } else {

        return false;

    }

    return false;
}


function send_problem() {

    var nameproblem = getObj('nameproblem').value;
    var kempredproblem = getObj('kempredproblem').value;
    var oblastproblem = getObj('oblastproblem').value;
    var predformsotproblem = getObj('predformsotproblem').value;
    var contactproblem = getObj('contactproblem').value;
    var descproblem = getObj('descproblem').value;
    var descnumlist = getObj('descnumlist').value;
//var descfileproblem = document.getElementById('descfileproblem').value;
//var descfileproblem = getObj('descfileproblem').value;

    var othdocsproblem = getObj('othdocsproblem').value;

    var onedocproblem = getObj('onedocproblem').value;
    var onedocnumlistproblem = getObj('onedocnumlistproblem').value;

    var twodocproblem = getObj('twodocproblem').value;
    var twodocnumlistproblem = getObj('twodocnumlistproblem').value;

    var threedocproblem = getObj('threedocproblem').value;
    var threedocnumlistproblem = getObj('threedocnumlistproblem').value;

    var fourdocproblem = getObj('fourdocproblem').value;
    var fourdocnumlistproblem = getObj('fourdocnumlistproblem').value;


    var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {

        if (req.readyState == 4) {
            // Write result to page element (_RESULT becomes responseJS).
            if (req.responseJS.result_error == '1') {
                alert('Спасибо, Ваше сообщение отправлено');
                document.getElementById('bankproblem').style.display = "none";
            } else {
                alert('Во время отправки возникла ошибка, попробуйте позже!');
                document.getElementById('bankproblem').style.display = "none";
            }
        }
    }

    //alert(document.getElementById('message').value);
    if (nameproblem == '' || kempredproblem == '' || oblastproblem == '' || predformsotproblem == '' || contactproblem == '') {
        alert('Заполните все поля!');
    } else {
        // Prepare request object (automatically choose GET or POST).
        req.open(null, './inc/_problem1.php', true);
        // Send data to backend.
        req.send({ nameproblem : nameproblem,
            kempredproblem : kempredproblem,
            oblastproblem : oblastproblem,
            predformsotproblem : predformsotproblem,
            contactproblem : contactproblem,
            descproblem : descproblem,
            descnumlist : descnumlist,
            descfileproblem : descfileproblem,
            onefileproblem : onefileproblem,
            twofileproblem : twofileproblem,
            threefileproblem : threefileproblem,
            fourfileproblem : fourfileproblem,

            othdocsproblem : othdocsproblem,

            onedocproblem : onedocproblem,
            onedocnumlistproblem : onedocnumlistproblem,

            twodocproblem : twodocproblem,
            twodocnumlistproblem : twodocnumlistproblem,

            threedocproblem : threedocproblem,
            threedocnumlistproblem : threedocnumlistproblem,

            fourdocproblem : fourdocproblem,
            fourdocnumlistproblem : fourdocnumlistproblem });

    }

}

function send_idea() {
    var nameidea = getObj('nameidea').value;
    var authoridea = getObj('authoridea').value;
    var oblastidea = getObj('oblastidea').value;
    var formsotrudidea = getObj('formsotrudidea').value;
    var sostpatsec = getObj('sostpatsec').value;
    var contactidea = getObj('contactidea').value;
    var descidea = getObj('descidea').value;
    var numlistidea = getObj('numlistidea').value;

    var schidea = getObj('schidea').value;
    var numlistschidea = getObj('numlistschidea').value;

    var otherdocidea = getObj('otherdocidea').value;

    var otheroneidea = getObj('otheroneidea').value;
    var othonenumlistidea = getObj('othonenumlistidea').value;

    var othertwoidea = getObj('othertwoidea').value;
    var othtwonumlistidea = getObj('othtwonumlistidea').value;

    var otherthreeidea = getObj('otherthreeidea').value;
    var oththreenumlistidea = getObj('oththreenumlistidea').value;

    var otherfouridea = getObj('otherfouridea').value;
    var othfournumlistidea = getObj('othfournumlistidea').value;


    var req = new JsHttpRequest();

    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            // Write result to page element (_RESULT becomes responseJS).

            if (req.responseJS.result_error == '1') {
                alert('Спасибо, Ваше сообщение отправлено');
                document.getElementById('inkid').style.display = "none";
            } else {
                alert('Во время отправки возникла ошибка, попробуйте позже!');
                document.getElementById('inkid').style.display = "none";
            }
        }
    }

    //alert(document.getElementById('message').value);
    if (nameidea == '' || authoridea == '' || oblastidea == '' || formsotrudidea == '' || sostpatsec == '' || contactidea == '') {
        alert('Заполните все поля!');
    } else {
        // Prepare request object (automatically choose GET or POST).
        req.open(null, './inc/_inkub1.php', true);
        // Send data to backend.
        req.send({ nameidea : nameidea,
            authoridea : authoridea,
            oblastidea : oblastidea,
            formsotrudidea : formsotrudidea,
            sostpatsec : sostpatsec,
            contactidea : contactidea,
            descidea : descidea,
            numlistidea : numlistidea,
            descfileidea : descfileidea,
            schfileidea : schfileidea,
            onefileidea : onefileidea,
            twofileidea : twofileidea,
            threefileidea : threefileidea,
            fourfileidea : fourfileidea,

            schidea : schidea,
            numlistschidea : numlistschidea,

            otherdocidea : otherdocidea,

            otheroneidea : otheroneidea,
            othonenumlistidea : othonenumlistidea,

            othertwoidea : othertwoidea,
            othtwonumlistidea : othtwonumlistidea,

            otherthreeidea : otherthreeidea,
            oththreenumlistidea : oththreenumlistidea,

            otherfouridea : otherfouridea,
            othfournumlistidea : othfournumlistidea });

    }
}

function ShowPL() {
    if (document.getElementById('platej').style.display == 'block') {
        document.getElementById('platej').style.display = 'none';
    } else {
        document.getElementById('platej').style.display = 'block';
    }
}

$(document).ready(function() {
    $('#angzbut').click(function() {
        var gzfullname = $('#gzfullname').val();
        var gzaddress = $('#gzaddress').val();
        var gzrnn = $('#gzrnn').val();
        var gzcontact = $('#gzcontact').val();
        var gzphone = $('#gzphone').val();
        var captcha = $('#gzcaptcha').val();
        var pageid = $('#pageid').val();

        if (gzfullname != '' && gzaddress != '' && gzrnn != '' && gzcontact != '' && gzphone != '') {
            $.ajax({
                type:'post',
                url:'index.php?act=gzaccess',
                dataType:'json',
                data:{
                    gzfullname:gzfullname,
                    gzaddress:gzaddress,
                    gzrnn:gzrnn,
                    gzcontact:gzcontact,
                    gzphone:gzphone,
                    page_id:pageid,
                    captcha:captcha
                },
                success:function(data) {
                    if (data.error == false) {
                        location.reload();
                    } else {
                        if (data.err_msg == 'captcha') {
                            alert('Не верный защитный код!');
                        } else if (data.err_msg == 'norequired') {
                            alert('Заполните все поля!');
                        }
                    }
                }
            });
        } else {
            alert('Заполните все поля!');
        }

        return false;
    });
});
