function textMainOver(th)
{
    th.style.background = "url(/images/pxTrG.png)"
}

function textMainOut(th)
{
    th.style.background = "none"
}

function shopcaseOver(obj)
{
    if (!obj) var obj = document.getElementById("shopcaseC")
    if (obj)
    {
        obj.style.display = "block"
    }
}

function shopcaseOut(obj)
{
    if (!obj) var obj = document.getElementById("shopcaseC")
    if (obj)
    {
        obj.style.display = "none"
    }
}

var shopcaseTop = ""

function shopcaseScroll()
{
    var obj = document.getElementById("shopcase")
    if (obj)
    {
        var cSTop = getClientSTop()
        if (shopcaseTop == "")
        {
            var objP = getAbsPos(obj)
            shopcaseTop = objP.y
        }

        if (cSTop > shopcaseTop)
        {
            obj.style.position = "relative"
            obj.style.top = (cSTop - shopcaseTop) + "px"
        }
        else
        {
            obj.style.position = "static"
            obj.style.top = "0px"
        }
    }
}

    function moveToPi(t, p)
    {
        var d = getDomain()
        if ((p == null) || (p == "")) var p = getURLPath(d)
        if (t == "1")
        {
            var s = "http://p."
            s = s + d + p
        } else var s = "http://" + d + p
        location.href = s
    }

    function moveToSu(t, p)
    {
        var d = getDomain()
        if ((p == null) || (p == "")) var p = getURLPath(d)
        if (t == "1")
        {
            var s = "http://s."
            s = s + d + p
        } else var s = "http://" + d + p
        location.href = s
    }

    function getDomain()
    {
        var d = window.location.hostname
        d = d.split(".")
        return (d[d.length-2] + "." + d[d.length-1])
    }

    function getURLPath(d)
    {
        if (d == "") d = getDomain()
        var p = window.location.href
        p = p.split(d)
        return (p[p.length-1])
    }

    function openPopup(title, head, content, resizable, height, width, btnSave)
    {
        var Dialog = new BX.CDialog({
	        title: title,
	        head: head,
	        content: content,
	        icon: 'head-block',
	        resizable: resizable,
	        draggable: true,
	        height: height,
	        width: width,
	        buttons: []
        });
        Dialog.SetButtons([
	        {
		        'title': 'Отправить',
		        'id': 'action_send',
		        'name': 'action_send',
		        'action': btnSave
	        },
	        {
		        'title': 'Закрыть',
		        'id': 'cancel',
		        'name': 'cancel',
		        'action': function(){
			        this.parentWindow.Close();
		        }
	        }
        ]);
        Dialog.Show();
    }

    function openOrderCall(name, pCode, pNumber)
    {
        var content = "<div id='callDiv' style='min-height:60px'>Ваше имя:<br><input id='callName' value='" + name + "'><br>Номер телефона:<br><input id=callPhoneCode size=3 maxlength=3 value='" + pCode + "'><input id=callPhoneNumber size=7 maxlength=7 value='" + pNumber + "'></div>"
        openPopup("Заказать звонок", "", content, false, "80", "240", wOrderCallSubmit)
    }

    function wOrderCallSubmit()
    {
        var callName = document.getElementById("callName")
        var callPhoneCode = document.getElementById("callPhoneCode")
        var callPhoneNumber = document.getElementById("callPhoneNumber")
        if (callName)
        {
            if (callName.value == "") alert("Введите Ваше имя")
            else if (callPhoneCode.value == "") alert("Введите Код телефона")
            else if (callPhoneNumber.value == "") alert("Введите Номер телефона")
            else
            {
                var callDiv = document.getElementById("callDiv")
                if (callDiv)
                {
                    var action_send = document.getElementById("action_send")
                    if (action_send) action_send.style.display = "none"
                    callDiv.innerHTML = ""
                    callDiv.style.background = "url(/images/loader1.gif) no-repeat center center"
                    var ajax = createAjax()
                    if (ajax)
                    {
					    ajax.onreadystatechange = function()
					    {
					        if (ajax.readyState == 4)
                            {
                                callDiv.innerHTML = "Спасибо!<br>Ожидайте, пожалуйста, звонка оператора."
                                callDiv.style.background = "none"
                                ajax = null
                            }
                        }
                        params = ""
                        params += "AccountName=" + callName.value + "&"
                        params += "PhoneCode=" + callPhoneCode.value + "&"
                        params += "PhoneNumber=" + callPhoneNumber.value

				        ajax.open("POST", '/opp/disp_saveShopcase.asp?' + params, true)
                        ajax.setRequestHeader("Accept-Charset", "windows-1251");
                        ajax.setRequestHeader("Accept-Language", "ru, en");
                        ajax.setRequestHeader("Connection", "close");
                        ajax.setRequestHeader("Content-length", params.length);
                        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        ajax.send("call=1")
				    }
                }
            }
        }
    }

    function startYashare(t, id, url, title, image)
    {
        id = "ya_share" + id
        document.getElementById(id).innerHTML = "<img src='/images/loader6.gif'>"
        switch (t)
        {
            case "main":
            {
                new Ya.share({
                element: id,
                    elementStyle: {
                        'type': 'button',
                        'border': true,
                        'quickServices': ['vkontakte','facebook','twitter','lj','moikrug','moimir','odnoklassniki','yaru','yazakladki','myspace','linkedin','friendfeed']
                    },
                    text: 'Поделиться ...',
                    link: encodeURI(url),
                    popupStyle: {
                        blocks: {
                            'Поделитесь с друзьями': ['vkontakte','facebook','twitter','lj','moikrug','moimir','odnoklassniki','yaru','yazakladki','myspace','linkedin','friendfeed','blogger','evernote','liveinternet','gbuzz','greader','juick']
                        }
                    }
                });
                break;
            }
            case "prod":
            {
                new Ya.share({
                element: id,
                    elementStyle: {
                        'type': 'button',
                        'border': false,
                        'quickServices': ['vkontakte','facebook','twitter','lj','moikrug','moimir','odnoklassniki']
                    },
                    text: 'Поделиться блюдом ...',
                    link: encodeURI(url),
                    title: title,
                    image: encodeURI(image),
                    popupStyle: {
                        blocks: {
                            'Поделитесь с друзьями': ['vkontakte','facebook','twitter','lj','moikrug','moimir','odnoklassniki','yaru','yazakladki','myspace','linkedin','friendfeed','blogger','evernote','liveinternet','gbuzz','greader','juick']
                        }
                    }
                });
                break;
            }
        }
    }

    function productOver(id, parentid)
    {
		var obj = document.getElementById("ya_shareP" + id)
        obj.style.display = ""
        var objI = document.getElementById("p" + id + "_i")
        if (objI) var img = objI.src.replace(window.location.hostname, MainDomain) + ".160"
        else var img = ""
        if (document.getElementById("ya_shareP" + id).innerHTML == "") startYashare("prod", "P" + id, "http://" + MainDomain + "/products/?id=" + id, document.title + " - " + document.getElementById("p" + id + "_n").innerHTML, img);
    }

    function productOut(id)
    {
		var obj = document.getElementById("ya_shareP" + id)
        obj.style.display = "none"
    }

    function myPizzaOpen()
    {
        var obj = document.getElementById("mypizza")
        if (obj)
        {
            var ajax = createAjax()
            if (ajax)
            {
                ajax.onreadystatechange = function () {
                    if (ajax.readyState == 4) {
                        txt = ajax.responseText
                        ajax = null
                        if (txt != "") {
                            obj.innerHTML = txt

                            myPizzaLoadJS("/games/myPizza/js/jquery.min.js");
                            myPizzaLoadJS("/games/myPizza/js/ui.core.min.js");
                            myPizzaLoadJS("/games/myPizza/js/ui.draggable.min.js");
                            myPizzaLoadJS("/games/myPizza/js/ui.droppable.min.js");
                            myPizzaLoadJS("/games/myPizza/js/script.php?" + t);

                            obj.style.display = "block"
                        }
                    }
                }

                var d = new Date()
                var t = d.getTime()
		        ajax.open("GET", '/games/myPizza/index.php?' + t, true)
                ajax.send("null")
	        }
	    }
    }

    function myPizzaLoadJS(url)
    {
        var ajax = createAjax()
        if (ajax) {
            ajax.onreadystatechange = function () {
                if (ajax.readyState == 4) {
                    eval(ajax.responseText);
                    ajax = null
                }
            }
            ajax.open("GET", url, false)
            ajax.send("null")
        }
    }
