
function updateHistory()
{
    //$('#uservideos').show();
    //$('#list').load('/user/gethistoryview');
    openajaxModal('/user/gethistoryview','История просмотров',640,480);
};

function updatePlaylist()
{
    openajaxModal('/user/getplaylist','Плейлист',640,480);
};

function addvote(linkname, vote)
{
    
    var url = '/view/addvote?id='+linkname+'&vote='+vote;
    $( "#voteanswer" ).load(url);
};

function addToPlaylist(linkname)
{
    var params = 'id='+linkname;
    $.ajax({
        url:'/user/addvideoinplaylist',
        data:params,
        type:'POST'
    });
};

function delFromPlaylist(id)
{
    openajaxModal('/user/delvideofromplaylist?id='+id,'',640,480);
};


function deleteVideo(linkname)
{
    var params = 'id='+linkname;
    $.ajax({
        url:'/user/deletevideo',
        data:params,
        type:'POST'
    });
}

function openajaxModal_old(url, title, w, h, openfunction){
    $("#modal").remove();
    $("<div id='modal'>Загрузка...</div>").insertAfter("head");
    if (title==null) title='';
    if (w==null) w=420;
    if (h==null) h=380;
    $( "#modal" ).dialog({
        autoOpen: true,
        title:title,
        //resizable:false,
        modal: true,
        width: w,
        // position: 'top' ,
        show: "blind",
        draggable: true,
        height: h,
        close: function(event, ui) {
            $("#modal").remove()
        },
        open: function(event, ui) {
            $( "#modal" ).load(url);
            if (openfunction!=null) openfunction();
        }
    });
    
}

function openModalDiv(divid, title, w, h){
    if (title==null) title='';
    if (w==null) w=420;
    if (h==null) h=380;
    $('#'+divid).dialog({
        autoOpen: true,
        title:title,
        resizable: false,
        modal: true,
        width: w,
        height: h
    });
}

function confirm_old(message, action)
{
    $("<div id='confirm'>Загрузка...</div>").insertAfter("head");
    $( "#confirm" ).html(message);
    $( "#confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        close: function(event, ui) {
            $("#modal").remove()
        },
        buttons: {
            "Да": function() {
                $( this ).dialog( "close" );
                action();
                return true;
            },
            'Нет': function() {
                $( this ).dialog( "close" );
                return false;
            }
        }
    });
    return false;
}

function confirm(msg,callback) {
    $("#confirm").remove();

    $("<div class='jqmConfirm' id='confirm'><div class='jqmConfirmWindow'><div class='jqmConfirmTitle clearfix'><h1>Подтверждение...</h1><a href='#' class='jqmClose'><em>Close</em></a></div><div class='jqmConfirmContent'>  <p class='jqmConfirmMsg'>11</p></div><input type='submit' value='Да' /><input type='submit' value='Нет' /></p></div></div>").insertAfter("head");

    $('#confirm').jqm({
        overlay: 88,
        modal: true,
        trigger: false
    });

    $('#confirm')
    .jqmShow()
    .find('p.jqmConfirmMsg')
    .html(msg)
    .end()
    .find(':submit:visible')
    .click(function(){
        if(this.value == 'Да')
            (typeof callback == 'string') ?
            window.location.href = callback :
            callback();
        $('#confirm').jqmHide();
    });
}


function createModal(title, w, h)
{
    $("#message").remove();
    $("<div id='message' class='jqmAlertWindow' ><div class='jqmAlertTitle clearfix'><h1></h1><a href='#' class='jqmClose'><em>Close</em></a></div><div class='jqmAlertContent'></div></div>").prependTo("body");

    if (title=='') title='';
    if (w==null) 	w=650;
    if (h==null) 	h=400;

    $('.jqmAlertTitle>h1').html(title);
    $('#message').css('width',w);
    $('#message').css('height',h);
    $('#message').css('left',($(window).width()-w)/2);
    $('#message').css('top',($(window).height()-h)/2);

    // Close Button Highlighting. IE doesn't support :hover. Surprise?
    if($.browser.msie) {
        $('div.jqmAlert .jqmClose')
        .hover(
            function(){
                $(this).addClass('jqmCloseHover');
            },
            function(){
                $(this).removeClass('jqmCloseHover');
            });

        return $('#message');
    }
}

function openajaxModal(url, title, w, h, openfunction){
    createModal(title, w, h);

    $('#message').jqm({
        trigger: false,
        modal: false,
        ajax: url,
        target: 'div.jqmAlertContent',
        overlay: 30
    }).jqmShow();


}


function openModal(text, title, w, h){
    createModal(title, w, h);
    $('#message').jqm({
        trigger: false,
        overlay: 0
    }).jqmShow();
    $('#message div.jqmAlertContent').html(text);

}
