﻿var ticket = function() {
    this.IsValid = function() {
        var isValid = true;

        var _userName = document.getElementById("UserName").value;
        var _userContacts = document.getElementById("UserContacts").value;
        var _userComments = document.getElementById("UserComments").value;

        if (_userName.length < 3 || _userName == "Представтесь, пожалуйста") {
            isValid = false;
            this.ShowError("UserName-error");
        } else {
            this.HideError("UserName-error");
        }

        if (_userContacts.length < 5 || _userContacts == "Контактная информация: e-mail, номер телефона, адрес, и т.д.") {
            isValid = false;
            this.ShowError("UserContacts-error");
        } else {
            this.HideError("UserContacts-error");
        }

        if (_userComments.length < 10 || _userComments == "Опишите коротко цели и задачи Вашего проекта") {
            isValid = false;
            this.ShowError("UserComments-error");
        } else {
            this.HideError("UserComments-error");
        }

        return isValid;
    }
    this.Submit = function() {
        var isValid = this.IsValid();
        if (isValid == false)
            return false;
        else {
            var _userName = document.getElementById("UserName").value;
            var _userContacts = document.getElementById("UserContacts").value;
            var _projectDirection = document.getElementById("project-direction").options[document.getElementById("project-direction").selectedIndex].value;
            var _userComments = document.getElementById("UserComments").value;

            this.iframeDoc().getElementById("UserName").value = _userName;
            this.iframeDoc().getElementById("UserContacts").value = _userContacts;
            this.iframeDoc().getElementById("ProjectDirection").value = _projectDirection;
            this.iframeDoc().getElementById("UserComments").value = _userComments;

            setTimeout("_ticket.iframeDoc().getElementsByTagName(\"form\")[0].submit();", 1000);

            return true;
        }

    }
    this.ShowError = function(id) {
        document.getElementById(id).style.display = "block";
    }
    this.HideError = function(id) {
        document.getElementById(id).style.display = "none";
    }
    this.iframeDoc = function() {
        var _doc = null;
        var _iframe = document.getElementById("iframe-ticket");
        if (_iframe != null) {
            if(_iframe.contentDocument)
                _doc = _iframe.contentDocument;
            else if(_iframe.contentWindow)
                _doc = _iframe.contentWindow.document;
            else if(_iframe.document)
                _doc = _iframe.document;
        }
        return _doc;
    }
}
var _ticket = new ticket();

promoUserName = {
    markText:["Представтесь, пожалуйста"],
    remInput : function(o, who){
                if(o.value == promoUserName.markText[who]){
                        o.value = "";
                }
        },
    repopInput : function (o, who){
                if (o.value == "") {
                    o.value = promoUserName.markText[who];
                }
    }
}
promoUserContacts = {
    markText:["Контактная информация: e-mail, номер телефона, адрес, и т.д."],
    remInput : function(o, who){
                if(o.value == promoUserContacts.markText[who]){
                        o.value = "";
                }
        },
    repopInput : function (o, who){
                if (o.value == "") {
                    o.value = promoUserContacts.markText[who];
                }
    }
}
promoUserComments = {
    markText:["Опишите коротко цели и задачи Вашего проекта"],
    remInput : function(o, who){
                if(o.value == promoUserComments.markText[who]){
                        o.value = "";
                }
        },
    repopInput : function (o, who){
                if (o.value == "") {
                    o.value = promoUserComments.markText[who];
                }
    }
}
var Library_Tabs = function(idContainer) {

    var container = document.getElementById(idContainer);

    var tabs = [];

    var navs = [];

    this.FindTabs = function() {

        var divs = container.getElementsByTagName("div");

        for (var i = 0; i < divs.length; i++) {

            if (divs[i].id.indexOf("Tab_Container_") != -1) {

                tabs.push(divs[i]);

            }

        }

        return tabs.length;

    }

    this.FindNavigation = function() {

        var uls = container.getElementsByTagName("ul");

        var lis = uls[0].getElementsByTagName("li");

        for (var i = 0; i < lis.length; i++) {

            navs.push(lis[i]);

        }

        return navs.length;

    }

    this.ChangeTab = function(index) {

        for (var j = 0; j < navs.length; j++) {

            if (j == index - 1) {
                if (navs[j].className != "Tabs_Button_Selected") {
                    navs[j].className = "Tabs_Button_Selected";
                }
                else {
                    return false;
                }
            }
            else {
                navs[j].className = "";
            }
        }
        for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].id == "Tab_Container_" + index) {
                tabs[i].className = "TabVisible Tabs";
            }
            else {
                tabs[i].className = "TabHide Tabs"
            }
        }
    }
}
function fnSelect(objId) {
    fnDeSelect();
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(document.getElementById(objId));
        range.select();

    } else
        if (window.getSelection) {
        var range = document.createRange();
        range.selectNode(document.getElementById(objId));
        window.getSelection().addRange(range);
    }
}
function fnDeSelect() {
    if (document.selection) document.selection.empty();
    else if (window.getSelection) window.getSelection().removeAllRanges();
}