	function redir(url)
	{
		location.href = url
	}

	function newWindow(url)
	{
		window.open(url)
	}

	function redirParent(url)
	{
		if (parent.document) parent.document.location.href = url
	}

	function isValidEmail(email)
	{
		reg = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i
		return reg.test(email)
	}

	function redirFrame(url, title)
	{
		if (title != "")
		{
			document.title = title
		}
		if (window.frames && window.frames['frame'])
		{
			window.frames['frame'].document.location.href = url
		}
		else
		{
			document.location.href = url
		}
	}
	
	function setMainFrameTitle(mainTitle)
	{
		if (parent)
		{
			var obj = parent
			while (obj.parent)
			{
				var obj = obj.parent.document
			}
			obj.title = mainTitle
		}
		else
		{
			document.title = mainTitle
		}
	}

	function logout()
	{
		if (confirm('Вы уверены, что хотите выйти из системы?')) redir("disp_logout.asp")
	}

	function clearMessage()
	{
		if (document.getElementById("message")) 
		{
			document.getElementById("message").innerText = ""
		}
		else
		{
			setTimeout(clearMessage, 5000)
		}
	}
	
	function sessionRefresh()
	{
		if (window.frames && window.frames['frameSessionRefresh'])
		{
			window.frames['frameSessionRefresh'].document.location.reload()
			setTimeout(sessionRefresh, 60000)
		}
	}

	function trim(str) 
	{ 
		var re1 = /^\s*/
		var re2 = /\s*$/
		return str.replace(re1, "").replace(re2, "")
	}
	
	function getAttributeByIndex(txt, ind, divider)
	{
		if (txt.substr(txt.length-1, 1) != divider) txt += divider
		attr = ''
		ii = 0
		while ((txt != '') && (ii < ind))
		{
			d =	txt.indexOf(divider)
			if (d >= 0)
			{
				attr = txt.substr(0, d)
				txt = txt.substr(d+1, txt.length)
			}
			else
			{
				attr = ''
			}
			ii += 1
		}
		return attr
	}

    function getClientWidth()
    {
        return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth
    }

    function getClientHeight()
    {
        return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight
    }

    function getClientSTop()
    {
        return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop)
    }

    function getClientSLeft()
    {
        return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft)
    }

    function showMessage(id)
    {
        var objMessage = document.getElementById("message")
        if (objMessage)
        {
            w = 600
            h = 500
            objMessage.src = ""
            objMessage.src = "/pages/about/message.asp?id=" + id
            objMessage.style.width = w
            objMessage.style.height = h

            var cWidth = getClientWidth()
            var cHeight = getClientHeight()
            var cSLeft = getClientSLeft()
            var cSTop = getClientSTop()
    /*
            var h = objImgDiv.offsetWidth
            var w = objImgDiv.offsetHeight
    */

            objMessage.style.left = (cWidth - w) / 2 + cSLeft
            objMessage.style.top = (cHeight - h) / 2 + cSTop

            objMessage.style.display = ''
        }
    }

    function showBanner(id)
    {
        var objMessage = document.getElementById("message")
        if (objMessage)
        {
            w = 600
            h = 500
            objMessage.src = ""
            objMessage.src = "/pages/about/banner.asp?id=" + id
            objMessage.style.width = w
            objMessage.style.height = h

            var cWidth = getClientWidth()
            var cHeight = getClientHeight()
            var cSLeft = getClientSLeft()
            var cSTop = getClientSTop()
    /*
            var h = objImgDiv.offsetWidth
            var w = objImgDiv.offsetHeight
    */

            objMessage.style.left = (cWidth - w) / 2 + cSLeft
            objMessage.style.top = (cHeight - h) / 2 + cSTop

            objMessage.style.display = ''
        }
    }

    function hideMessage()
    {
        if (parent)
        {
            var obj = parent.document.getElementById("message")
            if (obj)
            {
                obj.style.display = 'none'
            }
        }
    }

    function showQuestioning(id) {
        var objQuestioning = document.getElementById("questioning")
        if (objQuestioning) {
            w = 600
            h = 500
            objQuestioning.src = ""
            objQuestioning.src = "/pages/about/questioning.asp?id=" + id
            objQuestioning.style.width = w
            objQuestioning.style.height = h

            var cWidth = getClientWidth()
            var cHeight = getClientHeight()
            var cSLeft = getClientSLeft()
            var cSTop = getClientSTop()
            /*
            var h = objImgDiv.offsetWidth
            var w = objImgDiv.offsetHeight
            */

            objQuestioning.style.left = (cWidth - w) / 2 + cSLeft
            objQuestioning.style.top = (cHeight - h) / 2 + cSTop

            objQuestioning.style.display = ''
        }
    }

    function hideQuestioning() {
        if (parent) {
            var obj = parent.document.getElementById("questioning")
            if (obj) {
                obj.style.display = 'none'
            }
        }
    }

    function submitQuestioning()
    {
        document.getElementById("formSubmit").submit()
    }

    function regTypeOnChange(th)
    {
        if (th.options[th.selectedIndex].value == "UR") document.getElementById("tbodyUR").style.display = ""
        else document.getElementById("tbodyUR").style.display = "none"
    }

    function imgNumberRefresh(inKey)
    {
        var d = new Date()
        var t = d.getTime()
        document.getElementById('imgNumber').src = "/ssi/getImageNumber.asp?inkey=" + inKey + "&" + t
    }

    function formRegSubmit()
    {
		msg = ''
		if (document.getElementById('phoneCode').value == "")
		{
			if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			msg += 'Введите код телефона.'
		}
		if (document.getElementById('phoneNumber').value == "")
		{
			if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			msg += 'Введите номер телефона.'
		}
		if (!((document.getElementById('isRegUser').value == "1") && (document.getElementById('password').value == "") && (document.getElementById('repassword').value == "")))
		{
		    if ((document.getElementById('password').value == '') || (document.getElementById('repassword').value == ''))
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите Пароль и Повтор пароля.'
		    }
		    else
		    {
			    if (document.getElementById('password').value != document.getElementById('repassword').value)
			    {
				    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
				    msg += 'Пароль и Повтор пароля не совпадают.'
			    }
		    }
        }
		if ((document.getElementById('isRegUser').value != "1") && (document.getElementById('accType').options[document.getElementById('accType').selectedIndex].value == 'UR'))
		{
		    if (document.getElementById('account').value == '')
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите название Организации.'
            }
		}
		if (document.getElementById('accType').options[document.getElementById('accType').selectedIndex].value == 'UR')
		{
		    if (document.getElementById('inn').value == '')
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите ИНН Организации.'
		    }
		    if (document.getElementById('kpp').value == '')
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите КПП Организации.'
		    }
		    if (document.getElementById('urAddress').value == '')
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите Юр. адрес Организации.'
		    }
		}
		if (document.getElementById('name').value == "")
		{
			if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			msg += 'Введите ФИО.'
		}

		if (document.getElementById('email').value != "")
		{
			if (!isValidEmail(document.getElementById('email').value))
			{
				if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
				msg += 'EMail некорректного формата.'
			}
		}

		if (document.getElementById('checkNumber'))
		{
		    if (document.getElementById('checkNumber').value == "")
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите контрольное число.'
		    }
		}

		if (msg != '') {
		    alert(msg)
		    return false;
		}
		else {
		    document.getElementById("tbodySubmit").style.display = "none"
		    document.getElementById("tbodyLoader").style.display = ""
		    //document.getElementById("formReg").submit()
		    return true
		}
    }

    function formProposalSubmit()
    {
		msg = ''
		if (document.getElementById('name').value == "")
		{
			if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			msg += 'Введите название.'
		}
		if (document.getElementById('ingredients'))
	    {
		    if (document.getElementById('ingredients').value == "")
		    {
			    if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			    msg += 'Введите ингредиенты.'
		    }
        }
		if (document.getElementById('descr').value == "")
		{
			if (msg != '') msg += String.fromCharCode(10) + String.fromCharCode(13)
			msg += 'Введите описание.'
		}

		if (msg != '')
		{
		    alert(msg)
		    return false;
		}
    }

    function accountListOnClick(t, id)
    {
        var objSub = $("sub_" + id)
        var objSubCont = $("subCont_" + id)
        objSubCont.innerHTML = "<img src='/images/loader7.gif'>"
        if (objSub.style.display == 'none')
        {
            var d = new Date()
            var tt = d.getTime()
            url = "getItem.asp?type=" + t + "&id=" + id + '&' + tt
            var ajax = createAjax()
            if (ajax) {
                objSub.style.display = ""
                ajax.onreadystatechange = function() {
                    if (ajax.readyState == 4) {
                        txt = ajax.responseText
                        objSubCont.innerHTML = txt
                        ajax = null
                    }
                }
                ajax.open("GET", url, true)
                ajax.send("null")
            }
        }
        else
        {
            objSub.style.display = "none"
        }
    }

    function saveListForm(id)
    {
        $("btnSave_" + id).style.display = "none"
        var objSubCont = $("subCont_" + id)
        document.getElementById('form_' + id).submit()
        objSubCont.innerHTML = "<img src='/images/loader7.gif'>"
    }

    function showQuestioningQuestionTextAnswers(id) {
        var objg = $('qta' + id)
        if (objg.style.display != 'none') {
            objg.style.display = 'none'
        }
        else {

            var obj = $('qtav' + id)
            if (obj.innerHTML == '') {
                var ajax = createAjax()
                if (ajax) {
                    var objl = $('qtal' + id)
                    objl.style.display = ''
                    ajax.onreadystatechange = function () {
                        if (ajax.readyState == 4) obj.innerHTML = ajax.responseText
                        objl.style.display = 'none'
                    }
                    ajax.open("GET", 'getQuestionAnswers.asp?id=' + id, true)
                    ajax.send("null")
                }
            }

            objg.style.display = ''
        }
    }
