function SetEventToElement(eventName, elementID)
{
    var el = document.getElementById(elementID);
    if (el.addEventListener)
    {
        // this code is for Mozilla and Opera
        el.addEventListener(eventName, disableEventPropagation, false);
    }
    else if (el.attachEvent)
    {
        // this code is for IE
        el.attachEvent(eventName, disableEventPropagation);
    }
}
function disableEventPropagation(event)
{
    if (event.stopPropagation)
    {
        // this code is for Mozilla and Opera
        event.stopPropagation();
    }
    else if (window.event)
    {
        // this code is for IE
        window.event.cancelBubble = true;
    }
}

function RemoveDoubleScripts()
{
    window.setTimeout("RemoveDblScripts()", 0);
}

function RemoveDblScripts()
{

    var deleteScripts = new Array();
    var scripts = document.getElementsByTagName("script");

    for (var s = 0; s < scripts.length; s++)
    {
        for (var j = s + 1; j < scripts.length; j++)
        {
            if (scripts[s].innerHTML != "" && scripts[s].innerHTML == scripts[j].innerHTML)
            {
                var isDeleted = false;
                for (var t = 0; t < deleteScripts.length; t++)
                {
                    if (deleteScripts[t] == scripts[j])
                    {
                        isDeleted = true;
                        break;
                    }
                }

                if (!isDeleted) deleteScripts[deleteScripts.length] = scripts[j];
            }
        }
    }

    for (var t = 0; t < deleteScripts.length; t++)
    {
        var par = scripts[t].parentNode;
        par.removeChild(scripts[t]);
    }

}

function GetPrintUrl(url, pgType)
{
    var urlstr = url.toString();
    var condition = 'print' + pgType + '=true';
    var nn = urlstr.split("#");
    var post = "";
    if (nn.length > 1)
    {
        urlstr = nn[0];
        post = "#" + nn[1];
    }

    if (url.search.length > 1)
        return urlstr + '&' + condition + post;
    else return urlstr + '?' + condition + post;



}

function $(id)
{
    return document.getElementById(id);
}

function topWordsSwitch(o, event)
{
    if (!event) var event = window.event;
    var targetElm = (event.target) ? event.target : event.srcElement;
    while (targetElm != o)
    {
        if (targetElm.tagName == "A")
        {
            return false;
        }
        targetElm = targetElm.parentNode;
    }

    o.className = (o.className == "expanded") ? "collapsed" : "expanded"
    o.blur();
}

var topWords = {
    timer: null,
    over: function(o)
    {
        if (this.timer)
        {
            clearTimeout(this.timer);
            this.timer = null;
        }
        o.className = "expanded";
    },

    out: function(o)
    {
        this.timer = setTimeout(function(o) { return function() { o.className = "collapsed"; } } (o), 300)
    }
}

var novFocus = null;
function $setNowFocus(id)
{
    novFocus = id;
}

var mainNav = {
    timer: null,
    idSwitch: "ctl00_glbMainNavSwitch",
    on: function(n)
    {
        if (this.timer)
        {
            clearTimeout(this.timer);
            this.timer = null;
        }
        if ($(this.idSwitch).className != "act" + n)
        {
            $(this.idSwitch).className = "act" + n;
        }

        if (novFocus != null)
        {
            $(novFocus).blur();
        }

    },

    off: function()
    {
        this.timer = setTimeout(function() { mainNav.doOff() }, 300);
    },

    doOff: function()
    {
        var sw = $(this.idSwitch);
        if (sw.className == "act3") sw.className = "act1";
        sw.className = "";
        
        this.timer = null;

        if (novFocus != null)
        {
            $(novFocus).focus();
        }
        $setNowFocus(null);


    },

    keep: function()
    {
        if (this.timer)
        {
            clearTimeout(this.timer);
            this.timer = null;
        }
    }
}

var contactsBlockNav = {
    timer: null,
    idSwitch: "glbContactSwitch",
    holdTrigger: false,
    isCollapsingPending: false,

    holdOn: function(o)
    {
        this.holdTrigger = true;
    },

    holdOff: function(o)
    {
        this.holdTrigger = false;
        if (this.isCollapsingPending)
        {
            this.collapse();
        }
    },


    expand: function(o)
    {
        if (this.timer)
        {
            clearTimeout(this.timer);
            this.timer = null;
        }
        $(this.idSwitch).className = "expanded";
        o.blur();
    },

    collapse: function()
    {
        this.isCollapsingPending = true;
        if (!this.holdTrigger)
        {
            this.timer = setTimeout(function() { contactsBlockNav.doCollapse() }, 300)
        }
    },

    doCollapse: function()
    {
        $(this.idSwitch).className = "collapsed";
        this.timer = null;
        this.isCollapsingPending = false;
    },

    keep: function()
    {
        this.isCollapsingPending = false;
        if (this.timer)
        {
            clearTimeout(this.timer);
            this.timer = null;
        }
    }
	,

    toggle: function(o)
    {
        var oP = $(this.idSwitch);
        oP.className = (oP.className == "expanded") ? "collapsed" : "expanded";
        o.blur();
    }
}


function clientInfoSwitch(o)
{
    var oP = o.parentNode.parentNode;
    oP.className = (oP.className == "expanded") ? "collapsed" : "expanded";
    o.blur();
}


function projectInfoSwitch(o)
{
    var oP = o.parentNode.parentNode;
    oP.className = (oP.className == "expanded") ? "collapsed" : "expanded";
    o.blur();
}

function contactFormSwitch(o)
{
    var oP = o.parentNode.parentNode;
    oP.className = (oP.className == "expanded") ? "collapsed" : "expanded";
    o.blur();
}

function whySaMSwitch(sndr, id)
{

    if (document.getElementById(id).style.display == 'none')
    {

        document.getElementById(id).style.display = 'block';
        sndr.style.cssText = 'background-position: -4998px 11px;';
    }
    else
    {

        document.getElementById(id).style.display = 'none';
        sndr.style.cssText = 'background-position: -3996px 8px;';
    }
}

function OnClickCollapsedHeaderToggle(collapsedHeader)
{
    var collapsedText = SearchNextCollapsedTextNode(collapsedHeader);
    //if (collapsedText == null) collapsedText = SearchNextCollapsedTextNode(collapsedHeader.parentNode);
    if (collapsedText != null) ToggleCollapsedText(collapsedHeader, collapsedText);

}
function ToggleCollapsedText(collapsedHeader, collapsedText)
{
    var h2 = collapsedHeader.getElementsByTagName("h2")[0];
    var header = h2 = h2.getElementsByTagName("a")[0];
    if (collapsedText.style.display == 'none' || collapsedText.style.display == '')
    {
        addToCookie(collapsedHeader.id);

        collapsedText.style.display = 'block';
        header.style.cssText = 'background-position: -4998px 11px;';
    }
    else
    {
        removeFromCookie(collapsedHeader.id);

        collapsedText.style.display = 'none';
        header.style.cssText = 'background-position: -3996px 8px;';
    }
}
function SearchNextCollapsedTextNode(collapsedHeader)
{
    var par = collapsedHeader.parentNode;
    var isAfter = false;

    for (var i = 0; i < par.childNodes.length; i++)
    {
        if (par.childNodes[i].className == "CollapsedHeader" && par.childNodes[i] == collapsedHeader)
        {
            isAfter = true;
            continue;
        }
        if (isAfter && par.childNodes[i].className == 'CollapsedText')
        {
            return par.childNodes[i];
        }
    }
    return null;
}

//Добавляет в куку, в которой хранится массив строк, еще одно значение
function addToCookie(value)
{
    //eraseCookie("OpenedAccordionId" + document.location);
    var valFromCookie = readCookie("OpenedAccordionId" + document.location);
    var listId = "";
    
    if (valFromCookie)
    {
        listId = valFromCookie + "*";


        if (listId.indexOf(value + "*") == -1)
        {
            listId = valFromCookie + "*" + value;
        }
        else
        {
            listId = valFromCookie;
        }
    }
    else listId = value;
    
    createCookie("OpenedAccordionId" + document.location, listId, 1);
}

//Удаляет из куки, в которой хранится массив строк, указанное значение, если оно было последнее, то кука удаляется
function removeFromCookie(value)
{
    
    var valFromCookie = readCookie("OpenedAccordionId" + document.location);
    
    if (valFromCookie)
    {
        var listId = valFromCookie + "*";
        if (listId.indexOf(value + "*") != -1)
        {
            listId = listId.replace(value + "*","");
        }
        if (listId.substr(listId.length - 1, 1) == "*")
        {
            listId = listId.substr(0, listId.length - 1);
        }
        if (listId.length == 0)
        {
            eraseCookie("OpenedAccordionId" + document.location);
        }
        else
        {
            createCookie("OpenedAccordionId" + document.location, listId, 1);
        }
    }
}

//Создает куку
//name - имя ключа, value - значение, days - время действия с начала создания
function createCookie(name, value, days)
{
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + ";path=/";
}
/*Возвращает данные куки*/
function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++)
    {
        var c = ca[i];
        //var dt = c.split('=');
        //if(dt[0]==name)return dt[1];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
/*Удаляет куку*/
function eraseCookie(name)
{
    //document.cookie = "";
    createCookie(name, "", -1);
}


function Recaptcha(capthaImgID, capthaInputID)
{
    var capthcaImg = $(capthaImgID);
    var newSrc;
    capthcaImg.src = capthcaImg.src + "?" + (new Date()).getTime().toString();
    var capthca = $(capthaInputID);
    capthca.value = "";
    return false;
}





//Что за браузер ?
netscape = "";
ver = navigator.appVersion; len = ver.length;
for (iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln + 1).toUpperCase() != "C");

	

