﻿
/*** This file used for User profile page  ***/

/*** varibles ***/
var ind = 1, Cind = 1, catobj, objbtnmore; 
// for the category objects
var ImgCat,indRepConv = 1,attachedID = null, releaseit, facset = false;
var setID, setreplyToUser = "", setreplyId = 0, setrplUsrID = 0, setcatID = 0, setAction;
var varjoinlink = 'joinoGoing';

// check if user authenticate or not
var Isauthenticate = false;

/*** end ***/

// mouse over event for update text
function mouseOverTD(ctl) {
    var pr = ctl.substring(ctl.lastIndexOf('_') + 1, ctl.length);
    var cat = ctl.substring(ctl.indexOf('_') + 1, ctl.lastIndexOf('_') + 1);
    document.getElementById(ctl).style.backgroundcolor = '#FCFCFC';
    if (document.getElementById('iShareTrue_' + cat + pr) != null)
        document.getElementById('iShareTrue_' + cat + pr).style.display = "";
    if (document.getElementById('iShareFalse_' + cat + pr) != null)
        document.getElementById('iShareFalse_' + cat + pr).style.display = "";
    if (document.getElementById('iFavTrue_' + cat + pr) != null)
        document.getElementById('iFavTrue_' + cat + pr).style.display = "";
    if (document.getElementById('iFavFalse_' + cat + pr) != null)
        document.getElementById('iFavFalse_' + cat + pr).style.display = "";
    if (document.getElementById('iLikeTrue_' + cat + pr) != null)
        document.getElementById('iLikeTrue_' + cat + pr).style.display = "";
    if (document.getElementById('iLikeFalse_' + cat + pr) != null)
        document.getElementById('iLikeFalse_' + cat + pr).style.display = "";
    if (document.getElementById('iDelTrue_' + cat + pr) != null)
        document.getElementById('iDelTrue_' + cat + pr).style.display = "";
    if (document.getElementById('iDelFalse_' + cat + pr) != null)
        document.getElementById('iDelFalse_' + cat + pr).style.display = "";
    if (document.getElementById('iRepTrue_' + cat + pr) != null)
        document.getElementById('iRepTrue_' + cat + pr).style.display = "";
    if (document.getElementById('iRepFalse_' + cat + pr) != null)
        document.getElementById('iRepFalse_' + cat + pr).style.display = "";
    if (document.getElementById('iShare_' + cat + pr) != null)
        document.getElementById('iShare_' + cat + pr).style.display = "";
    if (document.getElementById('iFav_' + cat + pr) != null)
        document.getElementById('iFav_' + cat + pr).style.display = "";
    if (document.getElementById('iLike_' + cat + pr) != null)
        document.getElementById('iLike_' + cat + pr).style.display = "";
    if (document.getElementById('iDel_' + cat + pr) != null)
        document.getElementById('iDel_' + cat + pr).style.display = "";
    if (document.getElementById('iRep_' + cat + pr) != null)
        document.getElementById('iRep_' + cat + pr).style.display = "";
}

// Mouse out event for update text
function mouseOutTD(ctl) {
    var pr = ctl.substring(ctl.lastIndexOf('_') + 1, ctl.length);
    var cat = ctl.substring(ctl.indexOf('_') + 1, ctl.lastIndexOf('_') + 1);
    if (document.getElementById('iShareTrue_' + cat + pr) != null)
        document.getElementById('iShareTrue_' + cat + pr).style.display = "none";
    if (document.getElementById('iShareFalse_' + cat + pr) != null)
        document.getElementById('iShareFalse_' + cat + pr).style.display = "none";
    if (document.getElementById('iFavTrue_' + cat + pr) != null) {
        if (document.getElementById('iFavTrue_' + cat + pr).src.indexOf('star_sel.gif') < 0) {
            document.getElementById('iFavTrue_' + cat + pr).style.display = "none";
        }
    }
    if (document.getElementById('iFavFalse_' + cat + pr) != null) {
        if (document.getElementById('iFavFalse_' + cat + pr).src.indexOf('star_sel.gif') < 0) {
            document.getElementById('iFavFalse_' + cat + pr).style.display = "none";}
    }
    if (document.getElementById('iLikeTrue_' + cat + pr) != null)
        if (document.getElementById('iLikeTrue_' + cat + pr).src.indexOf('lk.gif') < 0)
            document.getElementById('iLikeTrue_' + cat + pr).style.display = 'none';
    if (document.getElementById('iLikeFalse_' + cat + pr) != null)
        if (document.getElementById('iLikeFalse_' + cat + pr).src.indexOf('lk.gif') < 0)
            document.getElementById('iLikeFalse_' + cat + pr).style.display = 'none';
    if (document.getElementById('iDelTrue_' + cat + pr) != null)
        document.getElementById('iDelTrue_' + cat + pr).style.display = "none";
    if (document.getElementById('iDelFalse_' + cat + pr) != null)
        document.getElementById('iDelFalse_' + cat + pr).style.display = "none";
    if (document.getElementById('iRepTrue_' + cat + pr) != null)
        document.getElementById('iRepTrue_' + cat + pr).style.display = "none";
    if (document.getElementById('iRepFalse_' + cat + pr) != null)
        document.getElementById('iRepFalse_' + cat + pr).style.display = "none";
    if (document.getElementById('iShare_' + cat + pr) != null)
        document.getElementById('iShare_' + cat + pr).style.display = "none";
    if (document.getElementById('iFav_' + cat + pr) != null) {
        if (document.getElementById('iFav_' + cat + pr).src.indexOf('star_sel.gif') < 0) {
            document.getElementById('iFav_' + cat + pr).style.display = "none";
        }
    }
    if (document.getElementById('iLike_' + cat + pr) != null)
        if (document.getElementById('iLike_' + cat + pr).src.indexOf('lk.gif') < 0)
            document.getElementById('iLike_' + cat + pr).style.display = 'none';
    if (document.getElementById('iDel_' + cat + pr) != null)
        document.getElementById('iDel_' + cat + pr).style.display = "none";
    if (document.getElementById('iRep_' + cat + pr) != null)
        document.getElementById('iRep_' + cat + pr).style.display = "none";
}

// get unique records: reliable code
function getUnique(arrayA, arrayB) {
    var shownArray = $.grep(arrayA, function (element) {
        return $.inArray(element, arrayB);
    });
    return shownArray;
}
// get unique Javascript method : pure javascript function
function getCommon(a, b) {
    var c = [];
    var ta = a.slice().sort();
    var tb = b.slice().sort();
    var t, found;
    for (var i = 0, iLen = ta.length; i < iLen; i++) {
        t = ta[i];
        found = false;
        for (var j = 0, jLen = tb.length; j < jLen && !found; j++) {
            if (t == tb[j]) {
                c.push(tb.splice(j, 1));
                found = true;
            }
        }
    }
    return c;
}

// Replaces all instances of the given substring.
String.prototype.replaceAll = function (
strTarget, // The substring you want to replace
strSubString // The string you want to replace in.
) {
    var strText = this;
    var intIndexOfMatch = strText.indexOf(strTarget);
    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1) {
        // Relace out the current instance.
        strText = strText.replace(strTarget, strSubString)

        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf(strTarget);
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return (strText);
}

// Method is used for Delete Update Text
function ConfirmDelete(oBt) {
    var res = confirm('Are you sure want to delete this update? there is NO undo!');
    if (res) {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var cat = oBt.id.substring(oBt.id.indexOf('_') + 1, oBt.id.lastIndexOf('_') + 1);
        if (document.getElementById('hID_' + pr) != null) {
            $('div#' + 'divUpdates_' + pr).fadeOut(1000);
            $.ajax(
            {
                type: "POST",
                url: "Service/CommonService.asmx/DeleteUserUpdate",
                data: "{ UserUpdateID : " + pr + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    $('#' + uplbl).text(parseInt($('#' + uplbl).text()) - 1);
                    CheckCatCount(cat);
                }
            });
        }
    }
}

// Method is used for Share UpdateText
function ShareUpdate(oBt) {
    var act;
    if (oBt.src.indexOf("shrd.gif") > 0)
        act = 0;
    else
        act = 1;
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    if (document.getElementById('hID_' + pr) != null) {
        $.ajax(
        {
            type: "POST",
            url: "Service/CommonService.asmx/ShareUserUpdate",
            data: "{ UserUpdateTextID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d == "2")
                    alert('You do not have any followers to share this update.');
                else
                    if (act) {
                        oBt.src = 'images/shrd.gif';
                        oBt.title = 'shared update';
                    }
                    else {
                        oBt.src = 'images/share.gif';
                        oBt.title = 'share this update';
                    }
                alert('Update has been shared.');
            }
        });
    }
}

/*** start : twitter like update action ***/
function SetTLiked(oBt) {
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/SetTLkd";
    var Source = "twitter";
    $.ajax({
        type: "POST",
        url: serveURL,
        data: "{ TwitterUpdateID : " + pr + ",Source: \"" + Source + "\"}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d && msg.d != "" && msg.d != "0")
                $(oBt).html("Like (" + msg.d + ")");
        }
    });
}

// used to share Twt update
function TShareUpdate(oBt, objclass) {
    var act = 0;
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var cat = oBt.id.substring(oBt.id.indexOf('_') + 1, oBt.id.lastIndexOf('_') + 1);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/TShareUserUpdate";
    $.ajax({
        type: "POST",
        url: serveURL,
        //data: "{ UpdateScrapText: \"" + objTxt + "\",TwitterUpdateID: " + pr + "}",
        data: "{ TwitterUpdateID: " + pr + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d == "2") {
                alert('You do not have any followers to share this update.');
            }
            else {
                if (act) {
                    oBt.title = 'shared update';
                }
                alert('Update has been shared.');
            }
        }
    });
}

// store comments for twitter updates
function setTComment(oBt, objtxt, objComms, imgObj, objuser, objuserfullname, objmrurl) {
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/SetTwitterComments";
    var txtcomments = $("#" + objtxt).val();
    if (!Isauthenticate) {
        if (txtcomments != "" && txtcomments != 'write comment')
            setValforcomms(pr, txtcomments);
        else {
            loadLoginBox();
        }
    }
    else if (txtcomments && txtcomments != "" && txtcomments != "write comment") {
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ TwitterUpdateID : " + pr + ", Comments: \"" + txtcomments + "\" }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d.LtstUp != "not authenticate") {
                    var comid = msg.d.LtstUp;
                    if (msg.d.TotalCount != null && msg.d.TotalCount > 0)
                        $("#icommCount_" + pr).html("Comment (" + msg.d.TotalCount + ")");
                    else if (msg.d.TotalCount != null && msg.d.TotalCount == 0) {
                        $("#icommCount_" + pr).html("Comment");
                    }
                    $("#" + objComms).append(regenCombox(imgObj, txtcomments, objuser, objuserfullname, objmrurl, comid, pr));
                }
                else if (msg.d.LtstUp == "not authenticate") {
                    loadLoginBox();
                }
                $("#" + objtxt).val('write comment');
            }
        });
    }
}

// Method is used for Favorite Updates
function SetFavorite(oBt) {
    var act;
    if (oBt.src.indexOf("star_sel") > 0)
        act = 0;
    else
        act = 1;
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    if (document.getElementById('hID_' + pr) != null) {
        $.ajax({
            type: "POST",
            url: "Service/CommonService.asmx/SetUnFvrt",
            data: "{UserUpdateTextID : " + pr + ", Fvrt : " + act + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (act) {
                    oBt.src = 'images/star_sel.gif';
                    oBt.title = 'un-favorite this update';
                }
                else {
                    oBt.src = 'images/star.gif';
                    oBt.title = 'favorite this update';
                }
            }
        });
    }
}
//used to delete social network comments
function ConfirmCommDeleteSoc(oBt, parentID, source) {
    var res = confirm('Are you sure want to delete this comment? there is NO undo!');
    if (res) {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var serveURL = getBaseURL() + "Service/CommonService.asmx/DeleteUserCommentSoc";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ CommentID : " + pr + ",SocialUpdateID: " + parentID + ",Source:\"" + source + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                // if Browser type is IE then remove filter
                if (jQuery.browser.msie) {
                    $('div#divcomm_' + pr).animate({ opacity: 0.4, width: 'toggle', height: 'toggle' }, { duration: 500, specialEasing: { width: 'linear', height: 'easeOutBounce' }, complete: function () { $('div#divcomm_' + pr).fadeOut(500); } });
                }
                else {
                    $('div#divcomm_' + pr).fadeOut(200);
                }
                if (msg.d.TotalCount != null && msg.d.TotalCount > 0)
                    $("#icommCount_" + parentID).html("Comment (" + msg.d.TotalCount + ")");
                else if (msg.d.TotalCount != null && msg.d.TotalCount == 0)
                    $("#icommCount_" + parentID).html("Comment");
            }
        });
    }
}
//$('.fav').live('touchstart', SetFavorite(this));
$('.fav').live('touchend', function () {
    //    alert(this);
    SetFavorite(this);
});

// Method is used for Favorite Updates
function SetLiked(oBt) {

    if (oBt != null) {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        if (pr != null) {
            $.ajax({
                type: "POST",
                url: "Service/CommonService.asmx/SetLkd",
                data: "{ UserUpdateTextID : " + pr + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
            //      oBt.src = 'images/lk.gif';
            //      oBt.title = 'liked update';
                    if (oBt.src && oBt.src != null) {                        
                        oBt.src = 'images/lk.gif';                        
                    }
                    else {
                        if (msg.d && msg.d != "" && msg.d != "0")
                            $(oBt).html("Like (" + msg.d + ")");                        
                    }
                }
            });
        }
    }
}
// get most 5 user attachments
function getUserAttachments(uid) {
    if ($("div#user_photos > div").size() <= 0) {
        if (uid != null && uid != 0) {
            $.ajax({
                type: "POST",
                url: "Service/Pro.asmx/GetUserAttachments",
                data: "{ UserID : " + uid + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (msg.d != null) {
                        if (msg.d.HtmlStream != null && msg.d.HtmlStream != "") {
                            var dynDiv = document.createElement("div");
                            dynDiv.id = "divUsrAt";
                            dynDiv.innerHTML = msg.d.HtmlStream;
                            //$('div#user_photos').html('');                            
                            $('div#user_photos').hide();
                            $('div#user_photos').html(dynDiv);
                            $('div#user_photos').show(1500, function () {//$('div#user_photos').slideToggle('slow'); //$('div#user_photos').slideDown(function () { $(this).fadeIn('slow'); });
                                $('div#user_photos').fadeIn(3500);
                            });
                        }
                    }
                    else {
                        $('div#user_photos').hide();
                    }
                }
            });
        }
    }
}
// used to redire to another page
function redLogn(obj) {
    top.location = obj;
}
// Method is used for get top user attachments
function getMostAttachment(uid) {
    setTimeout(function () { getUserAttachments(uid) }, 1000);
}
//get ret with link
function getHashLink() {
    var _DURL = new Object();
    if (window.location.href.lastIndexOf("/") > 0) {
        _DURL = window.location.href.substring(0, window.location.href.lastIndexOf("/"));
    }
    if ($("[id$='_A6']").length == 0) // no element found
    {
        $('.com_text').each(function (index) {
            $(this).html($(this).html().replace(/(#\w+)/g, "<a target='_self' class='msg_links' href='" + _DURL + "/search/q=$1'>$1</a>"));
        });
    }
    else // Without login hash tag.
    {
        $('.com_text').each(function (index) {
            $(this).html($(this).html().replace(/(#\w+)/g, "<a target='_self' class='msg_links' href='" + _DURL + "/search/q=$1'>$1</a>"));
        });
    }
}
// it used for check if any update category update exit or not
function CheckCatCount(CategoryID) {
    CategoryID = CategoryID.replaceAll("_", "");
    var ServeURL = getBaseURL() + "Service/Def.asmx/GetCatCountByID";
    $.ajax({
        type: "POST",
        url: ServeURL,
        data: "{ CatID : " + CategoryID + ", isProfile : true}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg != null) {
                if (msg.d.TotalCount == 0) {
                    $(".catcls" + CategoryID).hide();
                    $("#LCat0").click();
                }
                else
                    LoadProfile();
            }
            else
                LoadProfile();
        },
        error: function (xhr, ajaxOptions, thrownError) { LoadProfile(); return false; }
    });
}

// Create a link for facebook username
function facebookLinked() {
    var lnk = "http://www.facebook.com/";
    $(function () {
        if ($(".profile_bd label.facebook").length != 0 && !facset) {
            var re = new RegExp("(?:http:\/\/)?((?:www\.)?facebook.com/)([^<]*)", "gi");
            if ($(".profile_bd label.facebook").html().indexOf("facebook.com") >= 0)
                $(".profile_bd label.facebook").html($(".profile_bd label.facebook").html().replace(re, "<a href='http://$1$2' target='_blank'> $2 </a>"));
            else
                $(".profile_bd label.facebook").html($(".profile_bd label.facebook").html().replace($(".profile_bd label.facebook").html(), "<a href='" + lnk + $('.profile_bd label.facebook').html() + "' target='_blank'> " + $(".profile_bd label.facebook").html() + " </a>"));
            facset = true;
        }
    });
}

// Show the login dialog box when user not authenticate to do action (like, share and comment etc.)
function loadLoginBox() {
    $('#boxlblError').text('');
    //for login box
    $("#lgnDialog").show();
    $('#lgnDialog').dialog('open');
}

// Method used to get follow from user profile page
function getfollowPro() {
    $.ajax({
        type: "POST",
        url: getBaseURL() + "Service/usrVldte.asmx/getflw",
        data: "{ }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            window.location = window.location.href;
            //return true;
            //releasefile();
            return false;
        },
        error: function (xhr, ajaxOptions, thrownError) {
        }
    });
}
// It used to release file when user tries to download file from profile page.
function releasefile() {
    $.ajax({
        type: "POST",
        url: getBaseURL() + "Service/usrVldte.asmx/releaseFile",
        data: "{ attachUpdateID: '" + attachedID + "' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d) {
                releaseit = msg.d.StrTitle;
                if (releaseit) {
                    window.location = releaseit;
                    //window.location = window.location.href;
                }
            }
            return false;
        },
        error: function (xhr, ajaxOptions, thrownError) {
        }
    });
}
// Method was used for favorite tweets from profile page
function FavTweet(oBt) {
    var act;
    if (oBt.src.indexOf("star_sel") > 0)
        act = 0;
    else
        act = 1;
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var cat = oBt.id.substring(oBt.id.indexOf('_') + 1, oBt.id.lastIndexOf('_') + 1);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/FavoriteTweet";
    $.ajax({
        type: "POST",
        url: serveURL,
        data: "{ UserUpdateTextID : " + pr + ", IsFavorite : " + act + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (act) {
                if (window.location.href.lastIndexOf("search/q") > 0)
                    oBt.src = '../images/star_sel.gif';
                else
                    oBt.src = 'images/star_sel.gif';
                oBt.title = 'shared update';
            }
            else {
                if (window.location.href.lastIndexOf("search/q") > 0)
                    oBt.src = '../images/star.gif';
                else
                    oBt.src = 'images/star.gif';
                oBt.title = 'share this update';
            }
            if (act)
                alert('Update has been favorited.');
            else
                alert('Update has been unfavorited.');
        }
    });
}
// used for delete tweet
function ConfirmDeleteTweet(oBt) {
    var res = confirm('Are you sure want to delete this Tweet? there is NO undo!');
    if (res) {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var cat = oBt.id.substring(oBt.id.indexOf('_') + 1, oBt.id.lastIndexOf('_') + 1);
        $("#iTDelete_" + pr).hide();
        var serveURL = getBaseURL() + "Service/CommonService.asmx/DeleteTweet";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserUpdateTextID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                // if Browser type is IE then remove filter
                if (jQuery.browser.msie) {
                    $('div#divUpdatesTrue_' + cat + pr).parent().parent().animate({ opacity: 0.4, width: 'toggle', height: 'toggle' }, { duration: 500, specialEasing: { width: 'linear', height: 'easeOutBounce' }, complete: function () { $('div#divUpdatesTrue_' + pr).parent().parent().fadeOut(500); } });
                    $('div#divUpdatesFalse_' + cat + pr).parent().parent().animate({ opacity: 0.4, width: 'toggle', height: 'toggle'
                    }, { duration: 300, specialEasing: { width: 'linear', height: 'easeOutBounce' }, complete: function () { $('div#divUpdatesFalse_' + pr).parent().parent().fadeOut(300); } });
                }
                else {
                    $('div#divUpdatesTrue_' + cat + pr).parent().parent().fadeOut(200);
                    $('div#divUpdatesFalse_' + cat + pr).parent().parent().fadeOut(200);
                }
                if ($('div#divUpdatesTrue_' + cat + pr).parent().parent().parent().find('tr:visible').size() == 1) {
                    var hdid = $('input#hID_' + cat + pr).val();
                    $('#imgColConv_' + hdid).hide();
                }
                if ($('div#divUpdatesFalse_' + cat + pr).parent().parent().parent().find('tr:visible').size() == 1) {
                    var hdid = $('input#hID_' + cat + pr).val();
                }
            }
        });
    }
}
//function AskForLogin() {
//    ishowBtn = false;
//    $("#jquery-jmodal").width(350);
//    $.fn.jmodal({
//        title: 'Please login/register for this action',
//        content: "<div style='clear: left; display: block; left: 33%;' id='divLgJn' class='round'><div style='padding: 13px 30px 0 10px;'><table cellpadding='0' cellspacing='0'><tr><td align='center'><div class='signin_lable_box'><div ><div class='status-btn'><input type='button' id='btnLogin' class='status-btn round-btn' value='Sign In' onclick=\"redLogn('login')\" style='cursor: pointer;font-weight: bold; font-size: 12px !important;' /></div></div></div></td><td align='center'><div class='signin_lable_box'><div><div class='status-btn'><input type='button' id='btnjoin' class='status-btn round-btn' onclick=\"redLogn('joinoGoing')\" value='Sign Up'style='cursor: pointer; font-weight: bold; font-size: 12px !important;'/></div></div></div></td></tr></table></div></div>"
//    });
//    $("#jqbtnOK").css("display", "none");
//    return false;

function AskForLogin(objaID, objareplyToUser, objareplyId, objarplUsrID, objacatID) {
    setID = objaID;
    setreplyToUser = objareplyToUser;
    setreplyId = objareplyId;
    setrplUsrID = objarplUsrID;
    setcatID = objacatID;
    if (arguments.length == 2) {
        setAction = objareplyToUser;
        try {
            var varobjID = $(objaID).attr("id");
            setreplyId = varobjID.substring(varobjID.lastIndexOf('_') + 1, varobjID.length);
        }
        catch (err) { }
        varjoinlink = "joinogoing?repUpdateID=" + setreplyId + "&action=" + setAction;
    }
    else {
        varjoinlink = "joinogoing?status=" + encodeURIComponent(setreplyToUser) + "&repUpdateID=" + setreplyId + "&repUserID=" + setrplUsrID + "&catid=" + setcatID;
    }
    $(function () {
        $("#divActionbtns").show();
        $("#divActionbtns").dialog('open');
        //$(".ui-resizable-se").hide();	    	        
    });
}
function AskForConnect() {
    $(function () {
        storeConnectUser();
    });
}
/******* start authentication code *****/
function toMemLoad() {
    //getBaseURL function get from headermenu control     
    if (jQuery.trim($("#txtJUsername").val()) != '' && jQuery.trim($("#txtJPassword").val()) != '') {
        $.ajax({
            type: "POST",
            url: getBaseURL() + "Service/usrVldte.asmx/IsUserAuthenticate",
            data: "{ txtunm : '" + jQuery.trim($("#txtJUsername").val()) + "',txtpass : '" + jQuery.trim($("#txtJPassword").val()) + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d.StrTitle != "") {
                    $('#boxlblError').fadeIn('fast'); $('#boxlblError').text(msg.d.StrTitle);
                }
                else {
                    if (msg.d.IsAdmin)
                        window.top.location.href = "admin/default.aspx";
                    else {
                        //window.top.location.href = "home";
                        if (setID && setAction && setAction != "" && setID != null) {
                            SetUserActions(setID, setAction);
                        }
                        else if (setID && setreplyId && setrplUsrID != 0 && setreplyToUser != "") {
                            SetTextBoxUser(setID, setreplyToUser, setreplyId, setrplUsrID, setcatID);
                        }
                        else if (window.location.href.indexOf("#") > 0)
                            window.top.location.href = window.location.href.substring(0, window.location.href.indexOf("#"));
                        else
                        //window.top.location.href = "home";
                            window.top.location.href = window.location.href;
                    }

                    return true;
                }
            },
            error: function (xhr, ajaxOptions, thrownError) { return false; }
        });
        return false;
    }
    else {
        $('#boxlblError').fadeIn('fast');
        $('#boxlblError').css("opacity", "1");
        $('#boxlblError').text("Please enter username or password ");
        return false;
    }
}

function delMem() {
    eraseCookie('theName');   // make sure to add the eraseCookie function for every field
    eraseCookie('theEmail');
}
function newCookie(name, value, days) {
    var days = 1;   // the number at the left reflects the number of days for the cookie to last
    // modify it according to your needs
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameSG = name + "=";
    var nuller = '';
    if (document.cookie.indexOf(nameSG) == -1)
        return nuller;
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length, c.length);
    }
    return null;
}
function eraseCookie(name) { newCookie(name, "", 1); }
/******* end authentication code *****/

// use to store connectuser name to session
function storeConnectUser() {
    $.ajax({
        type: "POST",
        url: getBaseURL() + "Service/usrVldte.asmx/addConnectUser",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d) {
                $("#divActionbtns").show();
                $('#divActionbtns').dialog('option', 'title', 'Please SignIn/SignUp for Connect');
                var CobjURL = [];
                if (window.location.href.lastIndexOf("/") > 0) {
                    CobjURL = window.location.href.substring(window.location.href.lastIndexOf("/") + 1, window.location.href.length);
                }
                $("#btnjoin").attr("href", "joinogoing?connect=" + CobjURL);
                $("#divActionbtns").dialog('open');
            }
            else
                return false;
        },
        error: function (xhr, ajaxOptions, thrownError) { return false; }
    });
    return false;
}
function showPopup(objattID, objUnm) {
    attachedID = objattID;
    if (objUnm != "") {
        $(function () {
            $("#divfollowActionMsgBox").show();
            $("#divfollowActionMsgBox").dialog('open');
            $("#spnfollowtxt").text("Please follow " + objUnm + " to download the file");
        });
    }
    else {
        $(function () {
            $("#divDownloadMsgBox").show();
            $("#divDownloadMsgBox").dialog('open');
            //$(".ui-resizable-se").hide();
        });
    }
}
function initActionDialog() {
    $('#divActionbtns').dialog({
        autoOpen: false,
        width: 333,
        resizable: false
    });
    $('#divActionbtns1').dialog({
        autoOpen: false,
        width: 333,
        resizable: false
    });
    $('#lgnDialog').dialog({
        autoOpen: false,
        width: 260,
        resizable: false
    });
    // download attachment box
    $('#divDownloadMsgBox').dialog({
        autoOpen: false,
        //width: 333,
        width: 355,
        resizable: false
    });

    $('#divfollowActionMsgBox').dialog({
        autoOpen: false,
        width: 333, resizable: false
    });
    $("#btnsignin").click(function () {
        $("#divActionbtns").dialog("close");
        loadLoginBox();
    });
    $("#btndownloadIn").click(function () {
        $("#divDownloadMsgBox").dialog("close");
        loadLoginBox();
    });
    $("#btnfollowtoDw").click(function () {
        getfollowPro();
        $("#divfollowActionMsgBox").dialog("close");
        return false;
    });
    // add dynamic join link with jquery
    $("#btnjoin").click(function () { redLogn(varjoinlink); });
}
// function to use set reply when user not logged in
function SetTextBoxUser(ID, replyToUser, replyId, rplUsrID, catID) {
    //var catID = 1;
    //window.location = "\Home?status=" + encodeURIComponent(replyToUser) + "&repUpdateID=" + replyId + "&repUserID=" + rplUsrID;
    window.location = "\Home?status=" + encodeURIComponent(replyToUser) + "&repUpdateID=" + replyId + "&repUserID=" + rplUsrID + "&catid=" + catID;
}

//function is used to call action methods
function SetUserActions(objID, objAct) {
    if (objAct.toLowerCase() == 'favorite') {
        SetFavorite(objID);
        window.location = "home";
    }
    else if (objAct.toLowerCase() == 'liked') {
        SetLiked(objID);
        window.location = "home";
    }
    else if (objAct.toLowerCase() == 'share') {
        ShareUpdate(objID);
        window.location = "home";
    }
}
var objUserPath = {};
var uname = {};
if (window.location.href.lastIndexOf("/") > 0) {
    objUserPath = window.location.href;
    uname = objUserPath.substring(objUserPath.lastIndexOf("/") + 1, objUserPath.length);
}
// get facebook wall update 
function LoadFBUpdate(ismore) {
    if (document.getElementById('Img_fbwait') != null)
        document.getElementById('Img_fbwait').style.display = '';
    document.getElementById('btnFBmore').style.display = "none";
    $.ajax({
        type: "POST",
        url: "Service/Fb.asmx/GetWallPost", // get Twitter Feed
        data: "{ Username : \"" + uname + "\", Ismore : " + ismore + " }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg != null && msg.d) {
                if (msg.d.HtmlStream != null && msg.d.HtmlStream != "") {
                    if (ismore) {
                        try {
                            var dynDiv = document.createElement("div");
                            dynDiv.id = "divFBDyna";
                            dynDiv.innerHTML = msg.d.HtmlStream;
                            document.getElementById('divFacebook').appendChild(dynDiv);
                        }
                        catch (err) { }
                    }
                    else {
                        if (document.getElementById('divFacebookChild') != null) {
                            document.getElementById('divFacebookChild').innerHTML = "";
                            document.getElementById('divFacebookChild').innerHTML = msg.d.HtmlStream;
                        }
                    }
                    bindFacebookFeed();
                    $('div#divFacebookChild').children().slideDown();
                    if (document.getElementById('Img_fbwait') != null)
                        document.getElementById('Img_fbwait').style.display = 'none';
                }
                if (!msg.d.IsShow)
                    document.getElementById('btnFBmore').style.display = "none";
                else
                    document.getElementById('btnFBmore').style.display = "";
            } else {
                document.getElementById('btnFBmore').style.display = "none";
                if (document.getElementById('Img_fbwait') != null)
                    document.getElementById('Img_fbwait').style.display = 'none';
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            document.getElementById('btnFBmore').style.display = "none";
            if (document.getElementById('Img_fbwait') != null)
                document.getElementById('Img_fbwait').style.display = 'none';
        }
    });
}

// Use to dynamic bind text link to hyperlink within entier text
//function bindFacebookFeed() {
//    $('#divFacebook .com_text_fb').each(function (index) {
//        $(this).html(linkify($(this).html()));
//    });
//}
function bindFacebookFeed() {
    $('div.com_text_fb').each(function (index) {
        if ($(this).html().indexOf("<a") == -1)
            $(this).html(linkify($(this).html()));
    });
}
//function replaceURLWithHTMLLinks(text) {
//    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
//    var replacedtext;
//    return text.replace(exp, "<a class='msg_links' target='_blank' href='$1'>$1</a>");
//}

// function to use to find pattern of URL link within the text and make a hyperlink 
function linkify(inputText) {
    var replaceText, replacePattern1, replacePattern2, replacePattern3;
    //URLs starting with http://, https://, or ftp://
    replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
    replacedText = inputText.replace(replacePattern1, '<a class="msg_links" href="$1" target="_blank">$1</a>');
    //URLs starting with www. (without // before it, or it'd re-link the ones done above)
    replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
    replacedText = replacedText.replace(replacePattern2, '$1<a class="msg_links" href="http://$2" target="_blank">$2</a>');
    //Change email addresses to mailto:: links
    //    replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
    //    replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
    return replacedText
}
function FBLikeUpdate(oBt) {
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var cat = oBt.id.substring(oBt.id.indexOf('_') + 1, oBt.id.lastIndexOf('_') + 1);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/FBLikeUpdate";
    fireactions(serveURL, pr, "Liked");
}
function ShareFBUpdate(oBt) {
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var cat = oBt.id.substring(oBt.id.indexOf('_') + 1, oBt.id.lastIndexOf('_') + 1);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/FBShareUpdate";
    fireactions(serveURL, pr, "Shared");
}
function fireactions(objUrl, ObjPostID, action) {
    $.ajax({
        type: "POST",
        url: objUrl,
        data: "{ UserUpdateTextID : " + ObjPostID + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (action.toLowerCase() == "liked") {
                if (window.location.href.lastIndexOf("search/q") > 0)
                    oBt.src = '../images/lk.gif';
                else
                    oBt.src = 'images/lk.gif';
            }
            if (action.toLowerCase() == "shared") {
                if (window.location.href.lastIndexOf("search/q") > 0)
                    oBt.src = '../images/shrd.gif';
                else
                    oBt.src = 'images/shrd.gif';
            }
            oBt.title = action + ' update';
            alert('Update has been ' + action + '.');
        }
    });
}

function getActionMenu() {
    var proURL = {};
    if (window.location.href.lastIndexOf("/") > 0) {
        proURL = window.location.href.substring(window.location.href.lastIndexOf("/") + 1, window.location.href.length);
    }
    var objUrl = "Service/FL.asmx/GetActionMenu";
    $.ajax({
        type: "POST",
        url: objUrl,
        data: "{ ProfileUsername : \"" + proURL + "\" }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg && msg.d) {
                if (msg.d.HtmlStream && msg.d.HtmlStream != "")
                    $("#actddm").html('');
                $("#actddm").html(msg.d.HtmlStream);
            }
        }
    });
}

//function expandDiv(ufID) {
//    var menuName = ufID + "_menu";
//    var img = ufID + "_act";
//    var imgObj = document.getElementById(img);
//    $('ul.the_menu').slideUp('fast');
//    $('#' + imgObj.id).removeClass('act_off');
//    $('span.act_off').removeClass('act_off');
//    if ($('ul#' + menuName).is(':hidden')) {
//        $('ul#' + menuName).slideDown('fast');
//        $('#' + imgObj.id).addClass('act_off');
//    }
//    else {
//        $('ul#' + menuName).slideUp('fast');
//        $('#' + imgObj.id).addClass('act_on');
//        $('span.act_off').addClass('act_on');
//    }
//}
function successAct(ResponseObject, ResponseAsXml, ResponseAsText) {
    $(".pro_action_over").removeClass('actwait_on').addClass("act_off");
    getActionMenu();
}
function errorAct(args) {
    alert("Error occurred:" + args._message);
}
function FollowUser(UID, FID, objDiv) {
    //document.getElementById(objDiv + "_menu").style.display = 'none';    
    $('.pro_action_over').removeClass('act_off').addClass('actwait_on');
    CService.FollowUser(UID, FID, 0, successAct, errorAct);
    var flLbl = 0;
    if ($("[id$='_lblFollowing']").length > 0)
        $("[id$='_lblFollowing']").text(parseInt($("[id$='_lblFollowing']").text()) + 1);
}
function UnFollowUser(UID, FID, objDiv) {
    $('.pro_action_over').removeClass('act_off').addClass('actwait_on');
    objfollowActID = objDiv;
    CService.UnFollowUser(UID, FID, successAct, errorAct);
    if ($("[id$='_lblFollowing']").length > 0)
        $("[id$='_lblFollowing']").text(parseInt($("[id$='_lblFollowing']").text()) - 1);
}
function BlockUser(UID, FID, objDiv) {
    $('.pro_action_over').removeClass('act_off').addClass('actwait_on');
    //$('#' + document.getElementById(objDiv + "_act").id).addClass('wait_on');
    if (confirm('Blocking will prevent this user from following you. And you wont see their updates in your timeline. Are you sure you want to block?')) {
        CService.BlockUser(UID, FID, successAct, errorAct);
        if ($("[id$='_lblFollowing']").length > 0)
            $("[id$='_lblFollowing']").text(parseInt($("[id$='_lblFollowing']").text()) - 1);
    }
}
function oneDm() {    
    SendMessageValid();
}

/*** open action dialog box when user not logged In ***/
function openActnDialog() {
    if ($("#divActionbtns") && $("#divActionbtns").length > 0) {
        //        //$("#btn_drvth").show();
        //        $("#btnjoin").show();
        //        $("#btnLogin").show();
        $("#divActionbtns").show();
        $("#divActionbtns").dialog('open');
    }
}
// post user comments
function showcomments(oBt, objComms, divcbox, mainCdiv) {    
    if ($("#" + mainCdiv).is(":visible")) {
        $("#" + mainCdiv).hide();
    }
    else {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var serveURL = getBaseURL() + "Service/publicTM.asmx/getAllcomentesByUpdateID";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserTextUpdateID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {            
                $("#" + objComms).html('');
                $("#" + mainCdiv).show();           
                $("#" + objComms).append(msg.d);
                //$("#" + divcbox).fadeIn(1000);                
                $("#" + divcbox).show();                
            }
        });
    }
}
// show twitter update comments if not open then get all the comments of twitter update
function showTcomments(oBt, objComms, divcbox, mainCdiv) {    
    if ($("#" + mainCdiv).is(":visible")) {
        $("#" + mainCdiv).hide();
    }
    else {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var serveURL = getBaseURL() + "Service/publicTM.asmx/getAllcomentesByTwitterUpdateID";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ TwitterUpdateID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {                
                $("#" + objComms).html('');
                $("#" + mainCdiv).show();
                $("#" + objComms).append(msg.d);
                $("#" + divcbox).show();
            }
        });
    }
}
/// used to set comments
function setComment(oBt, objtxt, objComms, imgObj, objuser, objuserfullname, objmrurl) {
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/SetComments";
    var txtcomments = $("#" + objtxt).val();
    if (!Isauthenticate) {
//        if (txtcomments != "" && txtcomments != 'write comment')
//            setValforcomms(pr, txtcomments);
//        else { openActnDialog(); }
        openActnDialog();
    }
    else if (txtcomments && txtcomments != "" && txtcomments != "write comment") {
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserTextUpdateID : " + pr + ", Comments: \"" + txtcomments + "\" }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d.LtstUp != "not authenticate") {
                    var comid = msg.d.LtstUp;
                    if (msg.d.TotalCount != null && msg.d.TotalCount > 0)
                        $("#icommCount_" + pr).html("Comment (" + msg.d.TotalCount + ")");
                    else if (msg.d.TotalCount != null && msg.d.TotalCount == 0)
                        $("#icommCount_" + pr).html("Comment");
                    $("#" + objComms).append(regenCombox(imgObj, txtcomments, objuser, objuserfullname, objmrurl, comid, pr));
                }
                else if (msg.d.LtstUp == "not authenticate") {
                    openActnDialog();
                }
                $("#" + objtxt).val('write comment');
            }
        });
    }
}
function CheckCommentLenth(obj,e) {
    var str = obj.value;
    if (obj.value.length < 250) {
        obj.value = str;
    }
    else {
        obj.value = str.substring(0, 250);
    }
}
function ConfirmCommDelete(oBt, parentID) {
    var res = confirm('Are you sure want to delete this comment? there is NO undo!');
    if (res) {
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var serveURL = getBaseURL() + "Service/CommonService.asmx/DeleteUserComment";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ CommentID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                // if Browser type is IE then remove filter
                if (jQuery.browser.msie) {
                    $('div#divcomm_' + pr).animate({ opacity: 0.4, width: 'toggle', height: 'toggle' }, { duration: 500, specialEasing: { width: 'linear', height: 'easeOutBounce' }, complete: function () { $('div#divcomm_' + pr).fadeOut(500); } });
                    //$('div#divcomm_' + pr).animate({ opacity: 0.4, width: 'toggle', height: 'toggle' }, { duration: 300, specialEasing: { width: 'linear', height: 'easeOutBounce' }, complete: function () { $('div#divcomm_' + pr).fadeOut(300); } });
                }
                else {
                    $('div#divcomm_' + pr).fadeOut(200);
                }
                if (msg.d.TotalCount != null && msg.d.TotalCount > 0)
                    $("#icommCount_" + parentID).html("Comment (" + msg.d.TotalCount + ")");
                else if (msg.d.TotalCount != null && msg.d.TotalCount == 0)
                    $("#icommCount_" + parentID).html("Comment");
            }
        });
    }
}
// link hyperlinks
function replaceURLWithHTMLLinks(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp, "<a href='$1'>$1</a>");
}
// RegenCombox to show recent comments
function regenCombox(imgObj, txtcomments, objuser, objuserfullname, objmrurl, comid, parentID) {
    str = "";
    txtcomments = txtcomments.replace(/\n/g, " <br /> ");
    txtcomments = txtcomments.replace(/\r/g, " <br /> ");
    txtcomments = txtcomments.replace("&quot;", "\"");
    txtcomments = txtcomments.replace("&amp;", "&");
    txtcomments = txtcomments.replace("&nbsp;", " ");
    txtcomments = replaceURLWithHTMLLinks(txtcomments);
    str = "<div id='divcomm_" + comid + "' class='dv_inr_bx'><div id='imgphoto' class='img_lgn'><a id='lnkUserProf' target='_blank' href='" + objmrurl + "'><img src='" + imgObj + "' height='35px' width='35px' /></a></div>";
    str += "<div class='message_b2' style='width: 450px; height: auto;position:relative;overflow:visible'><a id='lnkUserProf1' class='msg_links' target='_blank' href='" + objmrurl + "'><span class='profile_name'> " + objuserfullname + " (" + objuser + ")</span></a> <br /><span class='com_text' style='display:block;width:450px'><div>" + txtcomments + "</div></span><span class='uptext' style='clear:both;float:left'>less than 1 seconds ago</span></div>";
    str += "<div class='comdiv'> <a class='comhide' id='lnkUpdelete_" + comid + "' href='javascript:void(0)' onclick='ConfirmCommDelete(this,\"" + parentID + "\"); return false;' /> </div>";
    str += "</div>";
    return str;
}
// to show hide comment text : water mark text
function iwatermark(inputId, text) {
    var inputBox = document.getElementById(inputId);
    if (inputBox.value.length > 0) {
        if (inputBox.value == 'write comment')
            inputBox.value = '';
    }
    else
        inputBox.value = text;
}
// Blur event of water mark text
function iwatermark_blr(inputId, text) {
    var inputBox = document.getElementById(inputId);
    if (inputBox.value.length > 0) {
        if (inputBox.value == 'write comment')
            inputBox.value = '';
    }
    else
        inputBox.value = text;
}
// end facebook wall update
$(document).ready(function () {
    initActionDialog();
    // get action menus
    getActionMenu();
    // function used to call direct message to profiel user at once
    $("#btnSndmsg").click(function () {
        SendMessageValid();
        //SendMessageOLDValidation();
    });
 
});

// this fun. is used to call UpdateRecommend web service.and toggle approve button.

function approve(obj, userid, usertextupdateid) 
{
    
    var status;
    if (obj.value.toLowerCase() == "approve") {
        obj.value = "DisApprove";
        status = true;
    }
    else {
        obj.value = "Approve";
        status = false;
    }
    try {
        $.ajax({
            type: "POST",
            url: getBaseURL() + "Service/srchUsr.asmx/UpdateRecommend",
            data: "{id: \"" + unescape(usertextupdateid) + "\",usertextupdateid:" + unescape(userid) + "\,isapprove:" + status + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(thrownError.toString());
            }
        });
    }
    catch (err) {
    }
    return false;
}



//this fun. is used to call GetRecommendList web service.

function GetRecommendList(userid, pagesize, ismore) {
    
    if (!ismore) {
        cnt = 0;
    }
    try {
        $.ajax({
            type: "POST",
            url: getBaseURL() + "Service/srchUsr.asmx/GetRecommendList",
            data: "{id: \"" + unescape(userid) + "\",pageIndex :" + ++cnt + ",pageSize:" + pagesize + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                
                if (msg.d) {
                    if (msg.d.HtmlStream && msg.d.HtmlStream != "") {
                        if (!ismore) {
                            $('#RecommendUser').html('');
                            $('#RecommendUser').html(msg.d.HtmlStream);
                        }
                        else
                            $('#RecommendUser').append(msg.d.HtmlStream);
                        if (msg.d.IsShow && msg.d.IsShow == true)
                            $("#" + "[id$='_BtnMore']").show();
                        else
                            $("#" + "[id$='_BtnMore']").hide();
                        $("#loading").hide();
                        $("#imgload").hide();
                    } else {
                        $('#ress').html("<div style='padding:40px 0px 0px;width:465px;margin:0 auto'><span class='profile_name' id='NoRow'>We couldn't find any record. Please try again with other criteria.</span> </div> ");
                        $("#loading").hide();
                        $("#imgload").hide();
                        $("#" + "[id$='_BtnMore']").hide();
                    }
                    return false;
                }
                else {
                    $('#RecommendUser').html("<div style='padding:40px 0px 0px;width:465px;margin:0 auto'><span class='profile_name' id='NoRow'>We couldn't find any record. Please try again with other criteria.</span> </div> ");
                    $("#loading").hide();
                    $("#imgload").hide();
                    return false;
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $("#loading").hide();
                $("#imgload").hide();
            }
        });
    }
    catch (err) {
        $("#loading").hide();
        $("#imgload").hide();
    }
    return false;
}
