function switchLiveFeed(channelId) {
    if(channelId != "0") {
        var feed = new Ajax.Request("/ajaxRequests/switch_feed.php", 
            { 
                method: 'post', 
                postBody: 'idChannel='+ channelId,
                /* DEBUG */
                onSuccess: function(transport){
                    var response = transport.responseText || "canalul TV nu este disponibil";
                    $('live-feed').innerHTML= response;
                }
                /*, onFailure: function() { 
                    alert('Ceva a mers aiurea...');
                }
                /* END DEBUG */
            });
    }
}

function loadCinemas(cityid, restrict_) {
    var cinemas = new Ajax.Updater('cinema', '/ajaxRequests/run_cinemas.php', {
              method: 'post',
              parameters: { city: cityid, mode: 'dropdown', restrict: restrict_ }
            });
}

function loadCinemaMovies() {
    var cinema = $('cinema').value;
    
    window.location = cinema;
}

function showCriteria(type) {
    var sections = ['a','genre','year','rating'];
    
    for(var i = 0; i < sections.length; ++i) {
		var section = sections[i];
        
        if(type == section) {
            $(section + '-sorting').show();
        } else {
            $(section + '-sorting').hide();
        }
	}
}

function rateMovie(rate, movie_id) {
    var feed = new Ajax.Request("/ajaxRequests/movie_rating.php", 
        { 
            method: 'post', 
            postBody: 'vote='+ rate + '&movie_id=' + movie_id,
            onSuccess: function(){
                window.location.reload(true);
            }
        });
}

function rateShow(rate, show_id, channel_id) {
    var feed = new Ajax.Request("/ajaxRequests/show_rating.php", 
        { 
            method: 'post', 
            postBody: 'vote='+ rate + '&show_id=' + show_id + '&channel_id=' + channel_id,
            onSuccess: function(){
                window.location.reload(true);
            }
        });
}

function rateTheatre(rate, theatre_id) {
    var feed = new Ajax.Request("/ajaxRequests/theatre_rating.php", 
        { 
            method: 'post', 
            postBody: 'vote='+ rate + '&theatre_id=' + theatre_id,
            onSuccess: function(){
                window.location.reload(true);
            }
        });
}

function tellAFriend(type, movie_id) {
    var tell = new Ajax.Request("/ajaxRequests/tell_a_friend.php", 
        { 
            method: 'post', 
            postBody: 'type='+ type + '&movie_id=' + movie_id + '&to=' + $('to').value,
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                $('taf').innerHTML= response;
            }
        });
}

function discuss(type, movie_id, channel_id) {
    var tell = new Ajax.Request("/ajaxRequests/discuss.php", 
        { 
            method: 'post', 
            postBody: 'type='+ type + '&movie_id=' + movie_id + '&channel_id=' + channel_id + '&content=' + $('message').value + '&author=' + $('author').value,
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                $('discution').innerHTML= response;
            }
        });
}

function showMessage(block_) {
    new Effect.Appear(block_, {duration: 1});
    new Effect.Fade(block_, {duration: 1, delay: 3});
}

function addToFav(type, id) {
    var tell = new Ajax.Request("/ajaxRequests/add_to_fav.php", 
        { 
            method: 'post', 
            postBody: 'type='+ type + '&id=' + id,
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                window.location.reload(true);
            }
        });
}

function addToAlerts(id, time) {
    var tell = new Ajax.Request("/ajaxRequests/add_to_alert.php", 
        { 
            method: 'post', 
            postBody: 'time='+ time + '&id=' + id,
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                window.location.reload(true);
            }
        });
}

function addToAlertsGuest(id, time) {
    var email = prompt('Introdu adresa ta de email', '');
    
    var tell = new Ajax.Request("/ajaxRequests/add_to_alert.php", 
        { 
            method: 'post', 
            postBody: 'time='+ time + '&id=' + id + '&email=' + email + '&guest=1',
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                window.location.reload(true);
            }
        });
}

function deleteFav(id) {
    if(confirm('Aceasta intrare va fi sterasa !')) {
        var tell = new Ajax.Request("/ajaxRequests/delete_fav.php", 
            { 
                method: 'post', 
                postBody: 'id=' + id,
                onSuccess: function(transport){
                    var response = transport.responseText || "nici un raspuns";
                    window.location.reload(true);
                }
            });
    } else {
        return false;
    }
}

function deleteAlert(id) {
    if(confirm('Aceasta alerta va fi sterasa !')) {
        var tell = new Ajax.Request("/ajaxRequests/delete_alert.php", 
            { 
                method: 'post', 
                postBody: 'id=' + id,
                onSuccess: function(transport){
                    var response = transport.responseText || "nici un raspuns";
                    window.location.reload(true);
                }
            });
    } else {
        return false;
    }
}

function generatePtvCode() {
    $('ptv_form').hide();
    
    var copypaste = new Ajax.Request("/ajaxRequests/ptv_code.php", 
        { 
            method: 'post', 
            postBody: $('ptv_code').serialize(),
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                $('ptvcopypaste').innerHTML = response;
            }
        });
    
    var example = new Ajax.Request("/ajaxRequests/ptv_code.php", 
        { 
            method: 'post', 
            postBody: $('ptv_code').serialize() + '&jscode=true',
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                $('ptvexample').value = response;
            }
        });
    
    $('ptvoutput').show();
}

function generateCinemaCode() {
    $('cinema_form').hide();
    
    var copypaste = new Ajax.Request("/ajaxRequests/cinema_code.php", 
        { 
            method: 'post', 
            postBody: $('cinema_code').serialize(),
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                $('cinemacopypaste').innerHTML = response;
            }
        });
    
    var example = new Ajax.Request("/ajaxRequests/cinema_code.php", 
        { 
            method: 'post', 
            postBody: $('cinema_code').serialize() + '&jscode=true',
            onSuccess: function(transport){
                var response = transport.responseText || "nici un raspuns";
                $('cinemaexample').value = response;
            }
        });
    
    $('cinemaoutput').show();
}

function copyPaste(id) {
    if (window.clipboardData) {
        window.clipboardData.setData("Text", $(id).value);
    } else {
        var flashcopier = 'flashcopier';
        
        if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        
        var divinfo = '</p><embed src="_clipboard.swf" flashvars="clipboard='+escape($(id).value)+'" type="application/x-shockwave-flash" height="0" width="0">';
        
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
    
    alert('Codul a fost copiat in ClipBoard.');
}

function deleteComment(type, id) {
    var feed = new Ajax.Request("/ajaxRequests/delete_comment.php", 
        { 
            method: 'post', 
            postBody: 'type='+ type + '&id=' + id,
            onSuccess: function(){
                window.location.reload(true);
            }
        });
}