﻿
/*SHARE WIDGET*/
// Create and Publish User's Action  
// This method is associated with the "btnPublishAction" click
function showShareUI(commentText, title, desc, backLink, actionLink, previewImage) {

    // Constructing a UserAction Object
    var act = new gigya.services.socialize.UserAction();
    //alert("in");
    // Setting the default user message   
    // (will be presented as default text in the edit box on the Share UI)
    act.setUserMessage(commentText);
    // Setting the title and description   
    // (will be presented in the preview on the Share UI)
    act.setTitle(title);
    act.setDescription(desc);
    // Setting a link back to the publishing source
    //act.setLinkBack("http://www.backlik.watch?v=jqxENMKaeCU");
    act.setLinkBack(actionLink);
    // Adding Action Link  
    act.addActionLink("Watch the movie",
                actionLink);
    // Adding an image (will be presented in the preview on the Share UI)  
    //href: 'http://www.youtube.com/watch?v=G8IozVfph7I&feature=channel_page',
    var image = {
        src: previewImage,
        href: backLink,
        type: 'image'
    }
    act.addMediaItem(image);
    // Parameters for the showShareUI method, including the UserAction object  
    var params =
            {
                userAction: act  // The UserAction object enfolding the newsfeed data.                                              
                , onError: onError  // onError method will be summoned if an error occurs.   
                , onSendDone: onSendDone // onError method will be summoned after   
                // Gigya finishes the publishing process.  

                , showMoreButton: "true" // Enable the "More" button and screen  
                , showEmailButton: "true" // Enable the "Email" button and screen  

            };
    // alert("out")
    // Show the "Share" dialog
    //alert(params);
    gigya.services.socialize.showShareUI(conf, params);

}

// onError event handler
function onError(event) {
    //Log error in databse
    //alert('An error has occured' + ': ' + event.errorCode + '; ' + event.errorMessage);
    // alert(event.providers);
    var msg = 'An error has occured' + ': ' + event.errorCode + '; ' + event.errorMessage;
    var param = new Array();
    param[0] = "errMsg:'" + msg + " '";

    param.join(",");
    var url = "Share.aspx/Fail";
    AjaxCall(url, param);
}

// onSendDone event handler.   
// Displays in the status field, the list of providers to which the newsfeed has been   
// successfully published.
function onSendDone(event) {
    //Log error in databse
    //alert(event.providers);
    ///set media & user information & save information Data base

    try {

        var param = new Array();
        param[0] = "tableName:'" + $("#ctl00_CPMain_hdnTableName").val() + " '";
        param[1] = "id:'" + $("#ctl00_CPMain_hdnContentLikeId").val() + " '";
        param[2] = "userid:'" + readCookie('userid_') + " '";
        param[3] = "socialNetworkName:'" + event.providers + " '";
        param.join(",");
        var url = "Share.aspx/AddShare";
        AjaxCall(url, param);
        $(this).addClass("disable");
        //document.getElementById('status').style.color = "green";
        //document.getElementById('status').innerHTML ='The newsfeed has been posted to: '+ event.providers;
    }
    catch (e)
    { }
}  

