//for uploading photo
function fnSHupload() {
	
	document.getElementById("tabviewppro").style.display="none"
	document.getElementById("upload_file_ajax").style.display=""
	document.getElementById("upload_area").style.display="none"
}
function fnClose() {
	
	document.getElementById("tabviewppro").style.display=""
	document.getElementById("upload_file_ajax").style.display="none"
	document.getElementById("upload_area").style.display=""
}
//for uploading photo ends here
function fnAddFriend(ids){
	
	if(confirm("Do you really want to add as a friend?")){
		location.href=base_url+"messagecenter_save/regtype/addfriend_dj/PUId/"+ ids;
	}
	
	return
}
function fnDJComposes(ids){
	
		location.href=base_url+"messagecenter_djcompose/regtype/senddjmsg/PUId/"+ ids;
		
}
function fnDJVideos(id,id1){
	location.href=id1+"djvideos_public/"+ id;
}
function fnDJMusic(id,id1){
	location.href=id1+"mp3";
}

/*functions from djprofile.php*/
$(function() {
    ddsmoothmenu.init({
        mainmenuid: "smoothmenu1",
        orientation: 'h',
        classname: 'ddsmoothmenu',
        contentsource: "markup"
    });
    /*if($("#from_page").val()=='blog') {
        fnyourblogs('my_profileblogs_dj',1,document.getElementById("dj_id").value)
    } else {
        fnuseraboutus(document.getElementById("dj_id").value)
    }*/
});
function setAjaxProcess( id )
{
    $(id).html("<img src='" + base_url + "images/loading.gif'>");
}
function fnyourrating( rate, user_id) {
    var id = '#resultform1';
    setAjaxProcess( id );
    var params = {"rid" : rate, "old_user" : user_id};

    $.post( base_url + "dj_inlineprofile", params, function( data ) {
        $( id ).html( data );
    });
    return false;
}
function fnuseraboutus( user_id ) {
    setAjaxProcess('#about_me');
    $.post( base_url + "dj_aboutus", {"uid" : user_id}, function( data ) {
        $('#about_me').html( data );
    });
    return false;
}
function fnyourblogs( pagename, page, user_id ) {
    var id = '#about_me';
    setAjaxProcess( id );
    var params = {"blogs" : user_id, "page" : page};

    $.post( base_url + pagename, params, function( data ) {
        $( id ).html( data );
    });
    return false;
}
function fnyourblogcomment( user_id ) {
    var id = '#about_me';
    setAjaxProcess( id );
    var params = {"blog" : user_id};

    $.post( base_url + 'blogcomments_dj', params, function( data ) {
        $( id ).html( data );
    });
    return false;
}
function fndjphotos( pagename, page, user_id ) {
    var id = '#about_me';
    setAjaxProcess( id );
    var params = {"blogs" : user_id, "page" : page};

    $.post( base_url + pagename, params, function( data ) {
        $( id ).html( data );
    });
    return false;
}
function fndjmusic( pagename, page, user_id ) {
    var id = '#about_me';
    setAjaxProcess( id );
    var params = {"blogs" : user_id, "page" : page};

    $.post( base_url + pagename, params, function( data ) {
        $( id ).html( data );
        var playerxml = $('#playerxml').val();
        var so = new SWFObject(base_url+ "player/ep_player.swf", "ep_player", "269", "226", "9", "#000000");
        so.addVariable("skin", base_url+"player/skins/nobius_platinum/skin.xml");
        so.addVariable("playlistxml",playerxml );
        so.addVariable("autoplay", "false");
        so.addVariable("shuffle", "false");
        so.addVariable("repeat", "false");
        so.addVariable("buffertime", "1");
        so.addParam("allowscriptaccess", "always");
        so.write("flashcontent");
    });
    return false;
}
function fnPostComment() {
    var comments = $('#comments');
    if( comments.val() == "" ) {
        alert("Please enter comments");
        comments.focus();
        return false;
    }
    var comment_by = $('#comment_by');
    if( comment_by.val() == "" ) {
        alert("Please enter your name");
        comment_by.focus();
        return false
    }
    var url = $('#url').val();
    var comment_by = comment_by.val();
    var message = comments.val();
    var blog_id = $('#blog_id').val();
    message = message.replace(/&/g,";amp;");
    message = message.replace(/\"/g,";dqtos;");
    message = message.replace(/\'/g,";sqtos;");
    message = message.replace(/\#/g,";hash;");
    message = message.replace(/\,/g,";cama;");
    var params = {"url":url,"comment_by":comment_by,"blog_id":blog_id,"comments":message};
    $.post( base_url + 'add_djppost', params,function( blog_id ) {
        fnyourblogcomment(blog_id);
    });
    return false;
}
function remove_dj(id) {
    $('#recipient_item_'+id).fadeOut(function(){
        selected_dj.splice(selected_dj.indexOf(id),1);
        $(this).remove();
    });
}
var dj_selected = '<span class="ui-icon ui-icon-circle-check dj_selected"></span>';
var remove_dj_link = "<a class='ui-state-default ui-corner-all removeDj' onclick='remove_dj(_dj_id)'><span class='ui-icon ui-icon-circle-minus'></span></a>";
var dj_list_item = "<li id = 'recipient_item__id'><span style='float:left;'>_dj_name</span>" + remove_dj_link + "</li>";
var selected_dj = new Array();
function findRecipients() {
    $('#recipientsList').empty();
    var match = $('#recipient_match').val();
    $.post(base_url+'getvipusers',{'dj_name':match,'recipients' : selected_dj.join(',')},function(data) {
        $('#recipientsList').html(data);
    });
}
function selectRecipient( id ) {
    var dj_name =  $('#recipient_'+id).html();
    $('#recipient_'+id).parent().html( dj_name + dj_selected );
    selected_dj.push(id);
    var dj_item = dj_list_item.replace("_id",id).replace("_dj_name",dj_name).replace('_dj_id',id);
    $('.recipients_list li:last').after(dj_item);
}
function sendMessageFromDj() {
    var params = {'recipients' : selected_dj.join(','), 'message_subject' : $('#message_subject').val(), 'message_message' : $('#message_message').val()};
    $.blockUI({message: '<h1><img src="busy.gif" /> Processing...</h1>'});
    $.post(base_url+'send_message', params, function( data ) {
        $.unblockUI();
        if( data.msg != null ) {
            $.jGrowl(data.msg);
        }
    },'json');
}
function fnphotos(){
	document.location.href="<?=set_url('managephotos')?>";
}

function fnmusic(){
	document.location.href="<?=set_url('dj_managemusic')?>";
}
function fnvideos(){
	document.location.href="<?=set_url('dj_videos')?>";
}
function deleteEvent( event_id ){
    if( confirm( "Delete event?" ) ) {
        $.post( base_url+"deleteevent", { "event_id" : event_id },function(){
            $('#event_block_'+event_id).fadeIn(function(){
                $(this).remove();
            })
        });
    }
}
function setactiveMCLinks(link){
    $('.conbox li a').removeClass('activeMClink')
    $(link).addClass('activeMClink');
}
function setactiveNAVLinks(link){
    $('.conbox li a').removeClass('activeMClink')
    $('.profilenav li a').removeClass('current')
    $(link).addClass('current');
}

function dj_send_message()
{
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+"dj_send_message",{},function( data ) {
         setactiveNAVLinks('#profile_link');
         setactiveMCLinks('#send_message_link');
        $('#profilecontent').html( data );
    });
}
function dj_inbox_message()
{
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+"dj_inbox",{},function( data ) {
        setactiveNAVLinks('#dj_inbox_link');
        $('#profilecontent').html( data );
    });
}
function dj_privateprofile()
{
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+"djprofile_content",{},function( data ) {
        setactiveNAVLinks('#profile_link');
        $('#profilecontent').html( data );
    });
}
function dj_blogs() {
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+"dj_blogs",{},function( data ) {
        setactiveNAVLinks('#dj_blogs_link');
        $('#profilecontent').html( data );
    });
}
function dj_editprofile() {
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+user_role+"_editprofile",{},function( data ) {
        setactiveNAVLinks('#edit_profile_link');
        $('#profilecontent').html( data );
    });
}
function dj_events() {
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+"dj_events",{},function( data ) {
        setactiveNAVLinks('#dj_events_link');
        $('#profilecontent').html( data );
    });
}
function add_event() {
    setAjaxProcess( '#profilecontent' );
    $.get(base_url+"dj_eventreg",{},function( data ) {
        setactiveNAVLinks('#dj_events_link');
        $('#profilecontent').html( data );
    });
}
function initProfileAdress(){
    $.address.change(function(event) {
        if( event.value == '/' ) {
            event.value = user_role+'/profile_content'
        }
        adress_controller(event.value);
        return false;
    });
}
function editBlog( blog_id ) {
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"manage_blog",{'blog_id':blog_id},function( data ) {
        setactiveNAVLinks('#dj_blogs_link');
        $('#profilecontent').html( data );
    });
}
function editEvent( event_id ) {
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"dj_eventreg_edit",{'event_id':event_id},function( data ) {
        setactiveNAVLinks('#dj_events_link');
        $('#profilecontent').html( data );
    });
}
function friends() {
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"friends",{},function( data ) {
        setactiveNAVLinks('#friends_link');
        $('#profilecontent').html( data );
    });
}
function dj_upload() {
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"dj_upload",{},function( data ) {
        setactiveNAVLinks('#dj_upload_link');
        $('#profilecontent').html( data );
    });
}
function managephotos(){
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"managephotos",{},function( data ) {
        setactiveNAVLinks('#dj_upload_link');
        $('#profilecontent').html( data );
    });
}
function dj_sent(){
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"dj_sent",{},function( data ) {
        setactiveNAVLinks('#profile_link');
        setactiveMCLinks('#sent_messages_link');
        $('#profilecontent').html( data );
    });
}
function editGallery(album_id){
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"editalbum",{'gallery_id':album_id},function( data ) {
        setactiveNAVLinks('#dj_upload_link');
        $('#profilecontent').html( data );
    });
}
function sendMessage(message_id){
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"sent_fullmsg",{'message_id':message_id},function( data ) {
        setactiveNAVLinks('#profile_link');
        setactiveMCLinks('#sent_messages_link');
        $('#profilecontent').html( data );
    });
}
function readMessage(message_id){
    setAjaxProcess( '#profilecontent' );
    $.post(base_url+"inbox_fullmsg",{'message_id':message_id},function( data ) {
        setactiveNAVLinks('#inbox_link');
        $('#profilecontent').html( data );
    });
}
function adress_controller( address )
{
    switch( address )
    {
        case "/djprofile_content" :
            dj_privateprofile();
            break;
        case "/send_message" :
            dj_send_message();
            break;
        case "/inbox_messages" :
            dj_inbox_message();
            break;
        case "/dj_blogs" :
            dj_blogs();
            break;
        case "/dj_events" :
            dj_events();
            break;
        case "/dj_editprofile" :
            dj_editprofile();
            break;
        case "/add_event" :
            add_event();
            break;
        case "/dj_upload" :
            dj_upload();
            break;
        case "/managephotos" :
            managephotos();
            break;
        case "/friends" :
            friends();
            break;
        case "/sent_messages" :
            dj_sent();
            break;
        default :
            if( address.indexOf('/manage_blog/') != -1 ) {
                var blog_id = address.replace('/manage_blog/blog_id/',"");
                if( parseInt( blog_id ) != blog_id ) {
                    blog_id = 0;
                }
                editBlog( blog_id );
            } else if( address.indexOf('/manage_event/') != -1 ) {
                var event_id = address.replace('/manage_event/event_id/',"");
                if( parseInt( event_id ) != event_id ) {
                    addEvent();
                } else {
                    editEvent( event_id );
                }
            } else if( address.indexOf('/edit_album/') != -1 ) {
                var album_id = address.replace('/edit_album/album_id/',"");
                if( parseInt( album_id ) == album_id ) {
                    editGallery(album_id);
                }
            } else if( address.indexOf('/sent_messages/') != -1 ) {
                var message_id = address.replace('/sent_messages/message_id/',"");
                if( parseInt( message_id ) == message_id ) {
                    readMessage(message_id);
                }
            } else { 
                dj_privateprofile();
            }
            break;

    }
}
function deleteDjBlog(id) {
    if( confirm( "Delete blog" ) ) {
        $.post(base_url+'delete_dj_blog',{"blog_id":id},function( data ) {
            if( data == 1 ) {
                $('#blog_block_'+id).fadeIn(function(){
                    $(this).remove()
                })
            }
        });
    }
}