function expand(str)
{
    s = document.getElementById(str).style.display;
    if (s == 'none')
        document.getElementById(str).style.display = 'block';
    else
        document.getElementById(str).style.display = 'none';
}
	
function show(str)
{
    document.getElementById(str).style.display = 'block';
}
	
function hide(str)
{
    document.getElementById(str).style.display = 'none';
}	
	
function AJAXLoads(opt)
{
    if (opt == 'cart')
    {
        $.post('/WebControls/Scripts/CartTable.php', {}, function(html){
            $('#announce').replaceWith(html);
        }, "html");

    //        jsphp_shtml('announce','function/basket.php','');
    //        return;
    }
    
    if (opt != "" && opt != "cart")
    {
        jsphp_shtml('announce','function/zones.php','concert='+opt);
    }
}
	
function GOTOBasket()
{
    jsphp_shtml('announce','function/basket.php','');
}
	
function update_basket() {
    setTimeout("jsphp_shtml('bas','function/basket_info.php','cat={CAT}')", 1000);
}
		
function update_qbasket() {
    setTimeout("jsphp_shtml('qb_count','function/qb_count.php','cat={CAT}')", 1000);
    setTimeout("jsphp_shtml('qb_summ','function/qb_summ.php','cat={CAT}')", 1000);
}
		
var rotate_action = '';
	
function update_rotation(time) {
    if(rotate_action == 'stop') {
        return;
    }
    jsphp_shtml('announce','function/basket.php','');
    jsphp_shtml('bas','function/basket_info.php','cat={CAT}');
    setTimeout("update_rotation("+time+")", time);
}	
	
function auto_refresh_basket(action) {
    var time = 10;	//	время периодического обновления корзины, сек
    time = time*1000;
    rotate_action = action;
    setTimeout("update_rotation("+time+")", time);
}
		
var r_delivery = '0';
var payment = 'nal';
	
function send_info() {
    var info = 'confirm_delivery=true&info='+document.confirm_order.info.value
    +'&street='+document.confirm_order.street.value
    +'&house='+document.confirm_order.house.value
    +'&part='+document.confirm_order.part.value
    +'&pod='+document.confirm_order.pod.value
    +'&kv='+document.confirm_order.kv.value
    +'&level='+document.confirm_order.level.value
    +'&dph='+document.confirm_order.dph.value
    +'&ug='+document.confirm_order.ug.value
    +'&bus='+document.confirm_order.bus.value
    +'&buss='+document.confirm_order.buss.value
    +'&station='+document.confirm_order.station.value
    +'&delivery='+r_delivery
    +'&ids='+document.confirm_order.ids.value
    +'&payment='+payment;

    jsphp_shtml('announce','function/basket.php', info);
		
}
		
function send_request() {
    var request = 'make_request=true&tickets='+document.request.tickets_number.value
    +'&concert='+document.request.concert.value
    +'&message='+document.request.message.value;

    jsphp_shtml('announce','function/basket.php', request);
		
}		
		
var newWindow;
	
function show_scheme(id) {
    var windowFeatures="width=750,height=750,resizable,scrollbars ";
    newWindow = window.open("scheme_popup.php?scheme_id="+id,"myWindow",windowFeatures);
}	
		
function show(str)
{
    document.getElementById(str).style.display = 'block';
}
function hide(str)
{
    document.getElementById(str).style.display = 'none';
}
	
function go(url) {
    window.location = url;
}
		
function show_hide_delivery(str, val) {
    if(val == '0') {
        hide(str);
    }
    if(val != '0') {
        show(str);
    }
    r_delivery = val;
}
	
function setPayment(val)
{
    payment = val;
}



function showHideLoginForm() {
    if (document.getElementById("loginForm").style.display == "none") {
        document.getElementById("loginForm").style.display = "block";
    }
    else {
        document.getElementById("loginForm").style.display = "none";
    }
}

function checkOferta()
{
    if(document.oferta_form.oferta.checked == false)
    {
        alert("Для заказа билетов требуется принятие договора-оферты!");
        return;
    }

    document.location = "/index.php?cat=228&action=confirmOrder";

//    else
//    {
//        if(document.oferta_form.smsNotification != null && document.oferta_form.smsNotification.checked == true)
//        {
//            if (!document.oferta_form.CityCode.value || !document.oferta_form.Phone.value) {
//                alert("Вы неверно указали мобильный телефон!");
//            }
//            else
//            {
//                jsphp_shtml('announce','function/basket.php','confirm_order=true&smsNotification='+document.oferta_form.smsNotification.value+'&CityCode='+document.getElementById("CityCode").value+'&Phone='+document.getElementById("Phone").value);
//            }
//        }
//        else
//        {
//            jsphp_shtml('announce','function/basket.php','confirm_order=true');
//        }
//    }
}
	
function register_submit()
{
    if(!document.registration.phone.value)
    {
        alert("Вы не указали телефон!");
    }
    else
    {
        document.registration.Submit.style.display = "none";
        document.registration.submit();
    }
}
		
function load_iframe(src)
{
    document.getElementById('rapid').src=src;
    if(document.getElementById('rapid').style.visibility == "hidden")
    {
        document.getElementById('rapid').style.visibility = "visible";
        document.getElementById('rapid').style.height = "800px";
    }
}	

function instant_update_basket() {
    jsphp_shtml('bas','function/basket_info.php','cat={CAT}');
}
		
function submitRegister()
{
    var form = document.user_register;
    var alert_text = "";
    var pass = true;
		
    if(!form.fio.value)
    {
        alert_text += "Необходимо заполнить Ф.И.О.!\n";
        pass = false;
    }
    if(!form.phone.value)
    {
        alert_text += "Необходимо указать телефон.\n";
        pass = false;
    }
		
    if(!pass)
    {
        alert(alert_text);
    }
		
    return pass;
}
	
function submitLogin()
{
    var alert_text = "";
    var pass = true;
		
    if(!document.getElementById('login').value)
    {
        alert_text += "Необходимо ввести логин!\n";
        pass = false;
    }
    if(!document.getElementById('password').value)
    {
        alert_text += "Необходимо ввести пароль!\n";
        pass = false;
    }
		
    if(!pass)
    {
        alert(alert_text);
    }
    else
    {
        getLoginInfo();
    }
		
}	
	
function getLoginInfo()
{
    var url = "http://www.show.ru/lightlogin.php";
    var qs = "login="+$F('login')+"&password="+$F('password');
		
    var xhr = new Ajax.Request(
        url,
        {
            method: "get",
            parameters: qs,
            onComplete: showResponse
        }
        );
}
	
function userExit()
{
    var url = "http://www.show.ru/lightlogin.php";
    var qs = "action=exit";
		
    var xhr = new Ajax.Request(
        url,
        {
            method: "get",
            parameters: qs,
            onComplete: showResponse
        }
        );
}	
	
function showResponse(originalRequest)
{
    $('container').innerHTML = originalRequest.responseText;
}	
	
function chechCBFields()
{
    var form = document.payment_form;
    var alert_text = "";
    var pass = true;
		
    if(!form.amount.value)
    {
        alert_text += "Неверно указана сумма платежа.\n";
        pass = false;
    }
    if(!form.email.value)
    {
        alert_text += "Вы не указали адрес электронной почты.\n";
        pass = false;
    }
    if(!form.phone.value)
    {
        alert_text += "Вы не указали телефон.\n";
        pass = false;
    }
    if(!form.lastname.value)
    {
        alert_text += "Вы не указали Фамилию.\n";
        pass = false;
    }
    if(!form.firstname.value)
    {
        alert_text += "Вы не указали Имя.\n";
        pass = false;
    }
		
    if(!pass)
    {
        alert(alert_text);
        return false;
    }
    else
    {
        return true;
    }
}

function stay_here(_this)
{
    setTimeout(function(){
        _this.focus()
    }, 200);
}

function XmlHttp(idArray, uri, queryArray)
{
    var queryString = "";
    var syncStatus = true;

    if(idArray.length == 0)
    {
        syncStatus = false;
    }

    for(i in queryArray)
    {
        queryString += i+"="+escape(encodeURI(queryArray[i]))+"&";
    }
    queryString = queryString.substr(0, queryString.length-1);

    var oXmlHttp = zXmlHttp.createRequest();

    if(typeof XMLHttpRequest == "undefined")
    {
        LoadingAlert("show");
    }

    oXmlHttp.open("POST", uri, syncStatus);
    oXmlHttp.onreadystatechange = function()
    {
        if(oXmlHttp.readyState == 1)
        {
            if(typeof XMLHttpRequest != "undefined")
            {
                LoadingAlert("show");
            }
        }
        if(oXmlHttp.readyState == 4)
        {
            if(oXmlHttp.status == 200)
            {
                LoadingAlert("hide");
                for(i in idArray)
                {
                    document.getElementById(String(idArray[i])).innerHTML = oXmlHttp.responseText;
                }

            }
            else
            {
                LoadingAlert("hide");
                LoadingErrorAlert(oXmlHttp.statusText);
            }
        }
    }

    oXmlHttp.setRequestHeader("Method", "POST '"+uri+"' HTTP/1.1");
    oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oXmlHttp.send(queryString);
    if(!syncStatus)
    {
        return oXmlHttp.responseText;
    }
}

function zXmlHttp()
{
}

zXmlHttp.createRequest = function()
{
    if(typeof XMLHttpRequest != "undefined")
    {
        return new XMLHttpRequest();
    }
    else
    {
        var zXmlVersion = null;
        var zXmlVersions = ["MSXML2.XmlHttp.6.0","MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"];
        for(var i=0; i<zXmlVersions.length; i++)
        {
            try
            {
                new ActiveXObject(zXmlVersions[i]);
                zXmlVersion = zXmlVersions[i];
                break;
            }
            catch(oError)
            {
            }
        }

        if(zXmlVersion)
        {
            return new ActiveXObject(zXmlVersion);
        }
        else
        {
            throw new Error("Ваш браузер не поддерживает никакой XML HTTP Request! Выкиньте его в помойку.");
        }
    }
};

function LoadingAlert(action)
{
    if(action == "show")
    {
        document.body.style.cursor = "wait";
    }
    if(action == "hide")
    {
        document.body.style.cursor = "default";
    }
}

function LoadingErrorAlert(error)
{
    window.defaultStatus = "Ошибка загрузки: "+error;
}

function seatMouseEnter(seatId)
{
    $('#seat'+seatId).fadeTo('fast', 0.7);
}

function seatMouseLeave(seatId)
{
    $('#seat'+seatId).fadeTo('fast', 1);
}

function seatOwnedClick(seatId, x, y)
{
    $('#seat'+seatId).replaceWith('<div id="seat'+seatId+'" style="display: block; top: '+y+'px; left: '+x+'px; position: absolute;"><img src="/img/ajax-loader.gif"></div>');
    $.post("/Arena/WebControls/Scripts/GetSeatView.php", {
        seatId: seatId,
        action: "unreserve"
    }, function(html){
        $('#seat'+seatId).replaceWith(html);
        updateCartBlock();
        udpateCartLink();
    });
}

function seatFreeClick(seatId, x, y)
{
    $('#seat'+seatId).replaceWith('<div id="seat'+seatId+'" style="display: block; top: '+y+'px; left: '+x+'px; position: absolute;"><img src="/img/ajax-loader.gif"></div>');
    $.post("/Arena/WebControls/Scripts/GetSeatView.php", {
        seatId: seatId,
        action: "reserve"
    }, function(html){
        $('#seat'+seatId).replaceWith(html);
        updateCartBlock();
        udpateCartLink();
    });
}

function updateCartBlock()
{
    $.post('/WebControls/Scripts/CartBlock.php', {}, function(html){
        $('#event_cart').replaceWith(html);
    }, "html");
}

function udpateCartLink()
{
    $.post('/WebControls/Scripts/CartLink.php', {}, function(html){
        $('#bas').replaceWith(html);
    }, "html");
}
