$(document).ready(function(){
    $(".on-button").livequery('click',function(){
        if($(this).hasClass('selected')){
            return false;
        }
        var profile = $(this).parents('div:first').attr('id');

        if ($("#email_validated").val())  {
            activateEmailPopup();
            return false;
            
        }else{
            if(profile == 'public'){
                sharepublicprofile(true);
            }
            
        }
        setProfileVisible(profile);
    })

     $(".off-button").livequery('click',function(){
          if($(this).hasClass('selected')){
            return false;
        }
        var profile = $(this).parents('div:first').attr('id');
        setProfilePrivate(profile);
    });


    $("#share_container .share").livequery('click',function(){
        //closeSharing();
    })
})
function openShareWindow(url,partner){
    if(partner == 'linkedin'){
        $.post('/cv/loginajax/addlinkedinacount',{type:partner},function(data){
            url = data;
            $.get(url,{type:partner},function(data){

            },'text')

        },'text')
    }else if(partner){
        $.post('/cv/loginajax/addAcount',{type:partner},function(data){
            
        },'text')
    }
    window.open(url,'Facebook','width=600,height=300')
    return false;
}

function showsidebarMessage(type, message, stayTime){
    if(!stayTime){
        stayTime = 3000;
    }
     $.noticeAdd({
                text: text(message),
                stay: false,
                type:type,
                stayTime:stayTime
            });
}


function sharepublicprofile(share){
    return;
   if(share){
       $("#show_message").val('1');
   }
    $("#share_container").dialog(
                    {modal: true ,
                        position:"center",
                        resizable: false,
                        draggable: false,
                        dialogClass: 'grid_10',
                        width: "550px",
                        title: "Tell your network about your meeCV profile?",
                        open: function(event, ui) {
                            
                            //$("#fb_share").html(fbHtml);alert($("#fb_tmp").length)
                        }

                    });
}

function shareprofile(){
    if(!$("#tw_check").is(':checked') && !$("#fb_check").is(':checked') && !$("#ln_check").is(':checked')){
        showErrorMessage('choose_chanel');
        return false;
    }
    var formvalues = $('#share_form').serialize();
    $.post('/cv/sidebarajax/share', formvalues, function(data){

            $("#visibility").html(data);
            var label = 'share_success';
            closeSharing();
            showSuccessMessage( text(label), 3500);
        }, 'text')
    return true;
}

function closeSharing(){
    
    $("a.ui-dialog-titlebar-close").click();
    var label = 'publish_public_success';
    $("#share_container").dialog("destroy");
    $(".ui-dialog").remove();
    if($("#show_message").val() == '1'){
        showsidebarMessage('notification-success', text(label), 3500);
        $("#show_message").val('0');
    }
    
}

