﻿var ind = 1;
var indCnv = 1;
var indRepConv = 1;
var Cind = 1;
var catobj, objbtnmore; // for the category objects
var _catIdArray = new Array();
var _catIdArrayShown = new Array();
var ImgCat;
var sta = 0;
var glbUpTxtLen = 0;
var glbTxtUrl = 0;
var setTwtUpdate = 0;
var isUploaded = 0;
var RCnvTxt = "";
var lblcatTxt = "";
// added catchWeb javascript
document.write('<scr' + 'ipt src="' + getBaseURL() + 'js/catchWeb.js" ></scr' + 'ipt>');
jQuery.timer = function(interval, callback) {
    var interval = interval || 100;
    if (!callback)
        return false;
    _timer = function(interval, callback) {
        this.stop = function() {
            clearInterval(self.id);
        };
        this.internalCallback = function() {
            callback(self);
        };
        this.reset = function(val) {
            if (self.id)
                clearInterval(self.id);

            var val = val || 100;
            this.id = setInterval(this.internalCallback, val);
        };
        this.interval = interval;
        this.id = setInterval(this.internalCallback, this.interval);
        var self = this;
    };
    return new _timer(interval, callback);
};

// 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;
    //set start from 1 because it is undefined on pos 0
    for (var i = 0, iLen = ta.length; i < iLen; i++) {
        t = ta[i];
        found = false;
        //start from 1 because it is undefined on pos 0
        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);
}
// it used for get base url
function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));
    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);
        return baseLocalUrl + "/";        
    }
    else {
        // Root Url for domain name        
        return baseURL + "/";        
    }
}
function postProcessUpdateKeypressCall(box, e, imgBt) {
    var obj = document.getElementById(box);
    if (document.getElementById(imgBt) != null && document.getElementById(imgBt).innerHTML) {
        //    if (obj.value.substring(0, 1) == "@")        
        //        document.getElementById(imgBt).innerHTML = " Reply ";        
        //    else
        document.getElementById(imgBt).innerHTML = "Update";
    }
    var val = obj.value;
    updateStatusTextCharCounter(obj, val);
    
    // fetch the web url from update textbox
    txtUpdatekeyUp(box,e);
}
function postProcessURLBlurCall(box, e, isTweet, txtUpLen, objChk) { 
//lenght of the url after shorted
    if (box != null) {
        //if (document.getElementById(box).value.length != 0 && document.getElementById(box).value != "Add link http://")
        if ($("#" + box).val().length != 0 && $("#" + box).val().toLowerCase() != "add link http://" && $("#" + box).val().toLowerCase() != "http:// share link")
            glbTxtUrl = 21;
        else
            glbTxtUrl = 0;  
    }
    var UpLen = txtUpLen.length + glbTxtUrl;    
    var _obj = document.getElementById(objChk + '_' + isTweet.toString());
    if (UpLen > 140 && isTweet >= 0) {
        if (objChk != null) {
            if (_obj != null) {
                _obj.disabled = 'disable';
//              _obj.checked = false;
                //isTwit = 0;
                //_obj.checked = true;
                isTwit = 1;
            }
        }
    }
    else {
        if (_obj != null) {
            _obj.disabled = false;
            //if (setTwtUpdate == 1)
            //_obj.checked = true;
            //else _obj.checked = false;
        }
    }
}
function updateStatusTextCharCounterCall(box, objText, lblChar, isTweet, objChk) {    //objText.value = 4000 - objText.length;
    if (glbTxtUrl != 0)
        glbUpTxtLen = objText.length + glbTxtUrl;
    else
        glbUpTxtLen = objText.length;
    var _obj = document.getElementById(objChk + '_' + isTweet.toString());
    document.getElementById(lblChar).innerHTML = 3500 - parseInt(objText.length, 0);
    if (parseInt(glbUpTxtLen) > 140 && isTweet >= 0) {
        if (objChk != null) {
            if (_obj != null) {
                _obj.disabled = 'disable';
//                _obj.checked = false;
                //                isTwit = 0;
              //  _obj.checked = true;
                isTwit = 1;
            }
        }
    }
    else {
        if (_obj != null) {
            _obj.disabled = false;
            //if (setTwtUpdate == 1)
            //_obj.checked = true;
            //else _obj.checked = false;
        }
    }
    if (objText.length > 3100 && objText.length < 3300) {
        box.style.color = '#1A9910';
    } else if (objText.length > 3300) {
        box.style.color = '#3F44A9';
    }
    else {
        box.style.color = 'black';
    }
}
/*function Trimstring(obj, val) {
obj.value = obj.value.substring(0, 4000);
}*/
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 = "";
}

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)
    { 
        if (document.getElementById('iShareTrue_' + cat + pr).src.indexOf('shrd.gif') < 0) {
            document.getElementById('iShareTrue_' + cat + pr).style.display = "none";
        }       
    }
    if (document.getElementById('iShareFalse_' + cat + pr) != null)
    {
    if (document.getElementById('iShareFalse_' + cat + pr).src.indexOf('shrd.gif') < 0) {
            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";
}


function SetTextBoxCall(ctl, replyToUser, replyId, txtUp, hdnFld, imgAll, rplUsrID, ctlDDLCat, hdnCatID) {    
    var txtString = document.getElementById(txtUp).value;    
    var hidId = document.getElementById(hdnFld).value;
    var sCatInd = 0;
    if (txtString != '') {
        if (txtString.indexOf(replyToUser) >= 0) {
            txtString = txtString.replace(replyToUser, '');
            hidId = hidId.replace(replyId + ',', '');
        }
    }
    document.getElementById(txtUp).focus();
    document.getElementById(txtUp).value = replyToUser + " " + txtString;
    document.getElementById(hdnFld).value = replyId;
    document.getElementById(ctl).value = rplUsrID;
    //document.getElementById(imgAll).src = 'Images/ReplyUpdate.png';
    //document.getElementById(imgAll).value = 'Reply';
//    if (hdnCatID != null && hdnCatID != 0) {
//        if (document.getElementById("hdnCat_" + hdnCatID.toString()) != null) {
//            sCatInd = document.getElementById("hdnCat_" + hdnCatID.toString()).value;
//        }
//    }
    var objDdlcat = document.getElementById(ctlDDLCat);
    if (objDdlcat != null) {
        $("#" + objDdlcat).val(hdnCatID.toString());
    }
    //    document.getElementById('<%= ddlCategory.ClientID %>').options[document.getElementById('<%= ddlCategory.ClientID %>').selectedIndex].value;    
    return false;
}
// 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);        
        $("#iDelFalse_" + pr).hide();        
        var serveURL = getBaseURL()  + "Service/CommonService.asmx/DeleteUserUpdate";                 
        if (document.getElementById('hID_' + pr) != null) {
            $.ajax({
                type: "POST",
                url: serveURL,
                data: "{ UserUpdateID : " + 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); } });
                        // Decrease the update by 1
                        if (upLbl !=null || $('#' + upLbl) != null)
                            $('#' + upLbl).text(parseInt($('#' + upLbl).text()) - 1);
                    }
                    else {
                        $('div#divUpdatesTrue_' + cat + pr).parent().parent().fadeOut(200);
                        $('div#divUpdatesFalse_' + cat + pr).parent().parent().fadeOut(200);
                        // Decrease the update by 1                        
                        if ($('#' + upLbl) != null)
                            $('#' + upLbl).text(parseInt($('#' + upLbl).text()) - 1);
                    }

                    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();
                        $('#imgColConv_' + hdid).hide();
                    }
                    // onDeleted fit to LatestUpdate as next Tr inner Text
                    //getLatestUpdate();
                    //LoadData();
                    //check if any category update found or not
                    if(cat != null && cat !="")
                    CheckCatCount(cat);
                }
            });
        }
    }
}
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");
            }
        }); 
    }
}
//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");
            }
        });
    }
}
// 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 : false}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg != null) {
                if (msg.d.TotalCount == 0) {
                // remove and show all the tabs on homepage
//                    $(".catcls" + CategoryID).hide();
//                    $("#LCat0").click();
                }
                else
                    LoadData();
            }
            else
                LoadData();
        },
        error: function (xhr, ajaxOptions, thrownError) { LoadData(); return false; }
    });
}

function isSubpath() {
    try {
        if (window.location.href.toLowerCase().lastIndexOf("search/q") > 0 || window.location.href.toLowerCase().lastIndexOf("favorites") > 0)
            return true;
        else
            return false;
    }
    catch (err) { return false; }
}
// Method is used for Share UpdateText
function ShareUpdate(oBt) {
    var act = 0;
    if (oBt != null && $.trim(oBt.innerHTML).toLowerCase() == "shared")
        act = 0;
    else if (oBt != null && $.trim(oBt.innerHTML).toLowerCase() == "share")
        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/ShareUserUpdate";    
        if (document.getElementById('hID_' + pr) != null) {
            $.ajax({
                type: "POST",
                url: serveURL,
                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.title = 'shared update';
                        }
                    }
                    alert('Update has been shared.');
                }
            });         
        }
    }

    /**** Shared update for twitter 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: "{ 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.');
            }
        });
        //}
    }
    /*** end ***/
    function replaceAll(string, replaceString, replaceWith) {
        return string.replace(new RegExp(replaceString, 'g'), replaceWith);
    }
    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>");        
    }

//    string = string.replace(/\n/g, "");
//    string = replaceAll(string, "<br />>", "<br />");
    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>";
        if (parentID.length < 6)
            str += "<div class='comdiv'> <a class='comhide' id='lnkUpdelete_" + comid + "' href='javascript:void(0)' onclick='ConfirmCommDelete(this,\"" + parentID + "\"); return false;' /> </div>";
        else
            str += "<div class='comdiv'> <a class='comhide' id='lnkUpdelete_" + comid + "' href='javascript:void(0)' onclick='ConfirmCommDeleteSoc(this,\"" + parentID + "\",\"twitter\"); return false;' /> </div>";
        str += "</div>";
        return str;
    }
    function setValforcomms(UserTextUpdateID, txtcomments) {
        var serveURL = getBaseURL() + "Service/publicTM.asmx/setTempcommts";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserTextUpdateID : \"" + UserTextUpdateID + "\" ,txtcomments: \"" + replaceQu(txtcomments).toString() + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                openActnDialog();
            }
        });
    }
    /// 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(); }
        }
        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');
            }
        });
    }
}
// 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 { openActnDialog(); }
    }
    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") {
                openActnDialog();
            }
            $("#" + objtxt).val('write comment');
        }
    });
    }
}
    // 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
    function showTcomments(oBt, objComms, divcbox, mainCdiv) {
        if ($("#" + mainCdiv).is(":visible")) {
            $("#" + mainCdiv).hide();
        }
        else {
            $("#" + divcbox).show();
            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();                    
                }
            });
        }
    }
    /*** open action dialog box when user not logged In ***/
    function openActnDialog() {
        if ($("#btnjoin") && $("#btnjoin").length > 0 && $("#divLgJn") && $("#divLgJn").length > 0) {
            $("#btn_drvth").show();
            $("#btnjoin").show();
            $("#btnLogin").show();
            $("#divLgJn").show();
            $("#divLgJn").dialog('open');
        }
    }
// Method is used for Favorite Updates
    function SetLiked(oBt) {
    
    var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/SetLkd";
        if (document.getElementById('hID_' + pr) != null) {
            $.ajax({
                type: "POST",
                url: serveURL,
                data: "{ UserUpdateTextID : " + pr + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    if (oBt.src && oBt.src != null) {
                        if (isSubpath()) {
                            oBt.src = '../images/lk.gif';
                        }
                        else {
                            oBt.src = 'images/lk.gif';
                        }
                    }
                    else {
                    if(msg.d && msg.d != "" && msg.d != "0")
                        $(oBt).html("Like (" + msg.d + ")");
//                        var getnum = $(oBt).html().match(/[\d\.]+/g);
//                        if(!getnum)
//                            $(oBt).html("Like (1)");
//                        else
//                            $(oBt).html("Like ("+(parseInt(getnum) + 1).toString()+")");
                        //$(oBt).html("Like");
                    }
                }
            });
        }
}

/*** 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 (oBt.src && oBt.src != null) {
    //                    if (isSubpath()) {
    //                        oBt.src = '../images/lk.gif';
    //                    }
    //                    else {
    //                        oBt.src = 'images/lk.gif';
    //                    }
    //                }
    //                else {
                    if (msg.d && msg.d != "" && msg.d != "0")
                        $(oBt).html("Like (" + msg.d + ")");
                //}
            }
        });     
}

/**** end : twitter update like action ***/
// 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);
    var serveURL = getBaseURL() + "Service/CommonService.asmx/SetUnFvrt";
        if (document.getElementById('hID_' + pr) != null) {
            $.ajax({
                type: "POST",
                url: serveURL,
                data: "{ UserUpdateTextID : " + pr + ", Fvrt : " + act + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    if (act) {
                        if (isSubpath())
                            oBt.src = '../images/star_sel.gif';
                        else
                            oBt.src = 'images/star_sel.gif'; 
                        oBt.title = 'un-favorite this update';
                    }
                    else {
                        if (isSubpath())
                            oBt.src = '../images/star.gif';
                        else
                            oBt.src = 'images/star.gif';
                        oBt.title = 'favorite this update';
                    }
                }
            });         
    }
}
function ExpConv(UpID) {
    $('#imgExpConv_' + UpID).attr('src', 'images/loading.gif');
    if (window.location.href.lastIndexOf("search/q") > 0 || window.location.href.toLowerCase().lastIndexOf("favorites") > 0) {
        $.ajax({
            type: "POST",
            url: "../Service/Pro.asmx/ExpConvs",
            data: "{ UpID : " + UpID + ", PageIndex : " + indCnv + " ,s : 1 }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                $('tr#tr' + UpID).after("<tr><td>" + msg.d.HtmlStream + "</td></tr>");
                $('tr#tr' + UpID).next('tr').find('table').find('div').css('background-color', '#EFEFEF');
                $('tr#tr' + UpID).next('tr').find('table:first').fadeIn(700);
                $('#imgExpConv_' + UpID).attr('src', 'images/slide_btn_down.png');
                $('#imgColConv_' + UpID).show();
                $('#imgExpConv_' + UpID).hide();
            }
        });
    }
    else {
        var isShown = 0;
        $.ajax({
            type: "POST",
            url: "Service/Pro.asmx/ExpConvs",
            data: "{ UpID : " + UpID + ", PageIndex : " + indCnv + ", s : 0,PageSize : 2 }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                $('tr#tr' + UpID).after("<tr><td>" + msg.d.HtmlStream + "</td></tr>");
                $('tr#tr' + UpID).next('tr').find('table').find('div').css('background-color', '#EFEFEF');
                $('tr#tr' + UpID).next('tr').find('table:first').fadeIn(700);
                $('#imgColConv_' + UpID).show();
                $('#imgExpConv_' + UpID).attr('src', 'images/slide_btn_down.png');
                $('#imgExpConv_' + UpID).hide();
                $('#imgExpConv_Read' + UpID).hide();
                getHashLink();
                // check new conversation Icon is Show or not
                if ($('#imgNewConv_' + UpID).is(":visible")) {
                    //isShown = 1;
                    isShown = msg.d.TotalNewConversation;
                }
                //$('#imgNewConv_' + UpID).hide();
                if ($('tr#tr' + UpID).find('#divmore').size() == 1);
                $('#lnk_' + UpID).show();
                //  var _objURL = new Object();
                //  if (window.location.href.lastIndexOf("/") > 0) {
                //      _objURL = window.location.href.substring(window.location.href.lastIndexOf("/") + 1, window.location.href.length);
                //  }
                //  if (_objURL.substring(0, 9).toLowerCase() != "mosttrend")
                getCount();
            }
        });
    }   
}
function setMessageShared(cat,pr)
{
//    if($('div#divUpdatesTrue_' + cat + pr) != null)
//        {
//            $('div#divUpdatesTrue_' + cat + pr).find(".message_b2").append("<span style='float: left; padding-left: 3px;' class='uptext'>&nbsp;&nbsp; shared by : you </span>");            
//            //$('div#divUpdatesTrue_' + cat + pr).find(".message_b2").val();
//        }
//    if($('div#divUpdatesFalse_' + cat + pr) != null)
//        $('div#divUpdatesFalse_' + cat + pr).find(".message_b2").append("<span style='float: left; padding-left: 3px;' class='uptext'>&nbsp;&nbsp; shared by : you </span>");
}
function ColConv(UpID) {
    $('tr#tr' + UpID).next('tr').find('table:first').fadeOut(700);
    $('#imgColConv_' + UpID).hide();
    $('#divmore').show();
    $('#imgExpConv_' + UpID).show();
    $('#imgExpConv_Read' + UpID).show();
    $('#lnk_' + UpID).hide();
}
function CheckCommentLenth(obj) {
    var str = obj.value;
    if (obj.value.length < 250) {
        obj.value = str;
    }
    else {
           obj.value = str.substring(0,250); 
    }
}
$(document).ready(function () {
    function loadMain() {
        if (isTwit != 1) {
            if ($("#[id$='_hdnCatIndex']") && $("#[id$='_hdnCatIndex']").val() != null && $("#[id$='_hdnCatIndex']").val() != "")
                $("#LCat" + $("#[id$='_hdnCatIndex']").val()).click();
        }
    }
    $('#new_results_notification').click(function () {
        $('div#new_results_notification').slideUp();
        if (window.location.href.toLowerCase().lastIndexOf("replies") > 0 || window.location.href.toLowerCase().lastIndexOf("conversation") > 0)
            LoadData();
        else
            $("#LCat0").click();
    });
    /******** used to twitter reply ************/
    $("[id$='btnReplyTweet']").click(function () {
        if ($("[id$='_txtTwitreply']")) {
            rplytweets($("[id$='_txtTwitreply']").val());
            $("[id$='_txtTwitreply']").val('');
            $(".overlayOuter").fadeOut(300);
        }
    });
    $(".ogo-dialog-close").click(function () {
        $(".overlayOuter").fadeOut(300);
    });
    $('.write_text_value_sml').bind('change input keyup keydown keypress mouseup mousedown cut copy paste', function ()
    { return ($(this).val().length <= 100) });
    /** end **/
});
if (window.location.href.lastIndexOf("search/q") > 0) {
    $.timer(60000, function(timer) {
        //msg.d.TotalCount = 0;
        if ($('div#Div1').find('div#childDiv').find('table#HomeTimeline').find('tr:first').attr('id') != null)
            var trID = $('div#Div1').find('div#childDiv').find('table#HomeTimeline').find('tr:first').attr('id');
        if (trID != null) {
            var numID = trID.substring(2, trID.length)
            $.ajax({
                type: "POST",
                url: "../Service/Pro.asmx/IsNewRecordsAvInSr",
                data: "{ numID : " + numID + ", s:'" + window.location.href.substring(window.location.href.lastIndexOf("search/q=") + 9, window.location.href.length) + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",                
                success: function(msg) {
                    if (msg.d.TotalCount > 0) {
                        if (msg.d.IsShow) {
                            $('div#new_results_notification').slideDown();
                            $('#results_update').text(msg.d.TotalCount + ' more update(s) since you started searching.');
                        }
                    }
                    else {
                        $('div#new_results_notification').slideUp();
                    }
                }
            });
        }
        //timer.stop();
    });
}
// check if new update found in database.
else if (window.location.href.lastIndexOf("home") > 0 || window.location.href.lastIndexOf("Home") > 0 || window.location.href.lastIndexOf("HOME") > 0) {
    $.timer(55000, function (timer) {    
        var trID = "1";
        var numID = "2";
        $.ajax({
            type: "POST",
            url: "Service/Pro.asmx/IsNewRecordsAvInSr1",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            //async: false,
            success: function(msg) {
                if (msg.d.TotalCount > 0) {
                    if (msg.d.IsShow) {
                        $('div#new_results_notification').slideDown();
                        $('#results_update').text(msg.d.TotalCount + ' new update(s).');
                    }
                }
                else {
                    $('div#new_results_notification').slideUp();
                }
            }
        });
        //timer.stop();
    });
}
else if (window.location.href.lastIndexOf("Conversation") > 0 || window.location.href.lastIndexOf("conversation") > 0) {
 
    $.timer(75000, function(timer) {
        var trID = "1";
        var numID = "2";
        $.ajax({
            type: "POST",
            url: "Service/Pro.asmx/IsNewRecordsAvInReConv",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            //async: false,
            success: function(msg) {
                if (msg.d.TotalCount > 0) {
                    if (msg.d.IsShow) {
                        $('div#new_results_notification').slideDown();
                        $('#results_update').text(msg.d.TotalCount + ' new conversation(s).');
                    }
                }
                else {
                    $('div#new_results_notification').slideUp();
                }
                $("[id$='_lnkRepCon']").text('Conversation (' + msg.d.TotalCount + ')');
            }
        });
        //timer.stop();
    });
}
else if (window.location.href.lastIndexOf("Replies") > 0 || window.location.href.lastIndexOf("replies") > 0) {
 
    $.timer(60000, function(timer) {
        var trID = "1";
        var numID = "2";
        $.ajax({
            type: "POST",
            url: "Service/Pro.asmx/IsNewRecordsAvInReps",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            //async: false,
            success: function(msg) {
                if (msg.d.TotalCount > 0) {
                    if (msg.d.IsShow) {
                        $('div#new_results_notification').slideDown();
                        $('#results_update').text(msg.d.TotalCount + ' new mention reply.');
                    }
                }
                else {
                    $('div#new_results_notification').slideUp();
                }
            }
        });
        //timer.stop();
    });
}
function getAllRepConv(UpID) {
    var isShown = 0;
    $.ajax({
        type: "POST",
        url: "Service/Pro.asmx/ExpConvs",
        data: "{ UpID : " + UpID + ", PageIndex : " + indCnv + ", s : 0,PageSize : 99999999 }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {

            $('tr#tr' + UpID).next('tr').find('table:first').remove();
            $('tr#tr' + UpID).after("<tr><td>" + msg.d.HtmlStream + "</td></tr>");
            $('tr#tr' + UpID).next('tr').find('table').find('div').css('background-color', '#EFEFEF');
            $('tr#tr' + UpID).next('tr').find('table:first').fadeIn(700);
            $('#imgColConv_' + UpID).show();
            $('#imgExpConv_' + UpID).attr('src', 'images/slide_btn_down.png');
            $('#imgExpConv_' + UpID).hide();
            $('#imgNewConv_' + UpID).hide();
            if ($('tr#tr' + UpID).find('#divmore').size() == 1);
            // show expand link for the conversation updates
            $('#lnk_' + UpID).show();
            // hide expand link for the conversation updates 
            $('#lnk_' + UpID).hide();
            if ($('tr#tr' + UpID).find('#divmore').size() == 1);
            $('#lnk_' + UpID).show();
            // add or subtract new conversation total count at Conversation at Right panel 
            // it shows the total new conversation
            if ('<%= ((HyperLink)(((UserControl)(ucRp.FindControl("ucRightTopPanel"))).FindControl("lnkRepCon"))) %>' != null)
                var varReCon = '<%= ((HyperLink)(((UserControl)(ucRp.FindControl("ucRightTopPanel"))).FindControl("lnkRepCon"))).ClientID %>';
            // get current new conversation
            var varReConCount = $("[id$='_lnkRepCon']").text();
            // set the new conversation count
            varReConCount = varReConCount.substring(varReConCount.lastIndexOf('(') + 1, varReConCount.lastIndexOf(')'));

            varReConCount = parseInt(varReConCount) - parseInt(msg.d.TotalNewConversation);
            if (parseInt(varReConCount) > 0) {
                varReConCount = parseInt(varReConCount) - parseInt(isShown);
            }
            if (parseInt(varReConCount) >= 0) {
                //finally set the new conversation are found or left when conversation is loaded.
                $("[id$='_lnkRepCon']").text('Conversation (' + varReConCount + ')');
            }
            //            if(msg.d.TotalNewConversation == 0)
            //                $("[id$='_lnkRepCon']").text('Conversation (0)');
            $('#divmore').hide();
            $('#divmore2').hide();
        }
    });
}
// now it is not used when delete update click
// hold it
function getLatestUpdate() {
    $.ajax({
        type: "POST",
        url: "Service/Def.asmx/getLatestUpdateofUser",
        data: "{  }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            if (msg.d.HtmlStream != "") {
                $("[id$='_LtstUp']").text(msg.d.HtmlStream);
                $("[id$='_UpTime']").text(msg.d.UpTime);
            }
        }
    });
}
function getCount() {
    $.ajax({
        type: "POST",
        url: "Service/Pro.asmx/IsNewRecordsAvInReConv",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        //async: false,
        success: function(msg) {
            if (msg.d.TotalCount > 0) {
                if (msg.d.IsShow) {
                    $('div#new_results_notification').slideDown();
                    $('#results_update').text(msg.d.TotalCount + ' new conversation(s).');
                }
            }
            else {
                $('div#new_results_notification').slideUp();
            }
            $("[id$='_lnkRepCon']").text('Conversation (' + msg.d.TotalCount + ')');
        }
    });
}
function showScrap(objTxtDv) 
{
    var objD = document.getElementById("sub_" + objTxtDv);
    var objMD = document.getElementById("main_" + objTxtDv);
    if (objD.style.display != 'none') {
        objD.style.display = "none";
        objMD.style.display = "inline-block";
        $("#hlshow_" + objTxtDv).text("- collapse");
    }
    else {
        objD.style.display = "inline-block";
        $("#hlshow_" + objTxtDv).text("+ read more...");
        objMD.style.display = "none";
    } return false;
}
// Resend Confirm Email 
function ResendConfirmEmail() {
$.ajax({
        type: "POST",
        url: "Service/usrVldte.asmx/ReSendConfirmationEmail",
        data: "{ }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        //async: false,
        success: function (msg) {
            if (msg) {
                if ($(".dvconfeml")) {
                    if (msg.d.StrTitle && msg.d.StrTitle != "") {
                        $("#dvconfeml").html(msg.d.StrTitle);
                        $("#dvconfeml").slideDown();
                        setTimeout(showconfirm, 5000);
                    }
                }
            }
        }
    });
}
function showconfirm() {
    $("#dvconfeml").slideUp(1000);
}
//function BindCommaLink(objComms) {
//    $(objComms + '.com_text').each(function (index) {
//        $(this).html(linkify($(this).html()));
//    });
//} 
// create search link with '#' word
function getHashLink()
{
    $('.com_text').each(function(index) {        
         $(this).html($(this).html().replace(/(#\w+)/g, function($0, $1) {
            return "<a target='_self' class='msg_links' href='http://" + document.domain + "/search/q=" + encodeURIComponent($1) + "'>" + $1 + "</a>";
         }));
  });
}
// Use to dynamic bind text link to hyperlink within entier text
//function bindFacebookFeed() {
//    $('#divFacebook > div.com_text_fb').each(function (index) {
//        if($(this).html().indexOf("<a") > 0)
//        $(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()));
    });
}
// Use to dynamic bind text link to hyperlink within entier text
function bindTopiclink() {
    $('.com_text').each(function (index) {
      $(this).html(linkify($(this).html()));
     });
}
// 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 Retweet(oBt) {
    var act = 0;
    //if (oBt.src.indexOf("Unretweet.png") > 0)
    if (oBt.src != null) {
        if (oBt.src.indexOf("retweeted.png") > 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/Retweet";
    $.ajax({
        type: "POST",
        url: serveURL,
        data: "{ UserUpdateTextID : " + pr + ",IsUndo:" + (parseInt(act) == 0 ? 1 : 0) + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {            
            if (act) {
                if (window.location.href.lastIndexOf("search/q") > 0)
                    oBt.src = '../images/retweeted.png';
                else
                    oBt.src = 'images/retweeted.png';
                //$(oBt).append("<input type='hidden' id='hdnundo" + pr + "' value='" + msg.d + "' /> ");
                oBt.title = 'Retweeted update';
            }
            else {
                //                if ($(oBt).find("#" + "hdnundo" + pr + ""))
                //                    $(oBt).find("#" + "hdnundo" + pr + "").remove();
                if (window.location.href.lastIndexOf("search/q") > 0)
                    oBt.src = '../images/retweet.png';
                else
                    oBt.src = 'images/retweet.png';
                oBt.title = 'Retweet this update';
            }
            alert('Update has been retweeted.');
        }
    });
}
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.');
        }
    });
}

var glbl_UptxtID;
// used to Reply update to twitter status
function ShareTweet(oBt,atuser) {    
    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 repname = "@" + atuser + " ";
    $("#lblreplyto").html("<h4 style='margin: 10px 0pt;'>Reply to <strong>" + repname + "</strong></h4>");    
    glbl_UptxtID = pr;
    $(".overlayOuter").fadeIn(300);
    $("[id$='_txtTwitreply']").focus();
    $("[id$='_txtTwitreply']").val(repname);
}
function rplytweets(replmsg) {    
    var serveURL = getBaseURL() + "Service/CommonService.asmx/RpliedTweet";
    if (glbl_UptxtID && glbl_UptxtID != undefined && glbl_UptxtID != null) {
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserUpdateTextID : " + glbl_UptxtID + ",strReplyMsg : \"" + replmsg + "\" }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert('Replied update has been sent.');
                try {
                    LoadTwitUpdate();
                }
                catch (err) { throw err; }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                glbl_UptxtID = null;
            }
        });
        glbl_UptxtID = null;
    }
}
// facebook like update action
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(oBt,serveURL, pr, "Liked");
}
// facebook share update action
function FBShareUpdate(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(oBt,serveURL, pr, "Shared");
}
function fireactions(oBt,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 + '.');
        }
    });
}
// used for Save Search/Remove search
function saveSrch() {
    try {
        var srchUrl = getBaseURL() + "Service/srchUsr.asmx/SaveSrch";
        var savesrch = window.location.href.substring(window.location.href.indexOf('q=') + 2);
        $.ajax({
            type: "POST",
            url: srchUrl,
            data: "{ savesrch: \"" + savesrch + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                try {
                    $("[id$='_lnkSaveSearch']").text(msg.d.StrText);
                    $("[id$='_imgAddSaveSearch']").attr("src",msg.d.StrImgUrl);
                    $("[id$='_lnkSaveSearch']").css("width", msg.d.Width);
                }
                catch (err) {
                    throw err;
                }
            }
        });
    }
    catch (err1) { }
}
function Isshow_loading(isvisible) {    
    if (isvisible) {
        if ($("[id$='_Imgld']") && $("[id$='_Imgld']").length > 0)
            $("[id$='_Imgld']").css("display", "");
    }
    else {
        if ($("[id$='_Imgld']") && $("[id$='_Imgld']").length > 0)
            $("[id$='_Imgld']").css("display", "none");
    }
}
function hidewait() {
    $("#lveImgCat").hide();
}
function showwait() {
    $("#lveImgCat").show();
}
// get more update from get public timeline
function getMore() {
    showwait();
    $.ajax({
        type: "POST",
        url: "Service/publicTM.asmx/GetPublicTimeline",
        data: "{PageIndex : " + (++ind) + " }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d != null) {
                if (msg.d.HtmlStream != null) {
                    var dynDiv = document.createElement("div");
                    dynDiv.id = "divDyna";
                    dynDiv.innerHTML = msg.d.HtmlStream;
                    document.getElementById('divlve').appendChild(dynDiv);
                    $('div#divlve').find('table').slideDown(); 
                    getHashLink();
                }
                if (msg.d.IsShow) {                    
                     $("#BtnlveMore").show('slow', function () {
                        $(this).css("display", "inline-block");
                    });
                }
                else
                    $("#BtnlveMore").hide();
            }
            hidewait();
        }
    });
}
// call public timeline
function loadPublicUps() {
    if (document.getElementById('lvechildDiv') != null) {
        showwait();
        $.ajax({
            type: "POST",
            url: "Service/publicTM.asmx/GetPublicTimeline",
            data: "{PageIndex : 1 }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d != null) {
                    if (msg.d.HtmlStream != null) {
                        document.getElementById('lvechildDiv').innerHTML = msg.d.HtmlStream;
                        $('div#lvechildDiv').children().slideDown();
                        // added Hyperlinks
                        getHashLink();
                    }
                    if (msg.d.IsShow) {
                        $("#BtnlveMore").show('slow', function () {
                            $(this).css("display", "inline-block");
                        });
                    }
                    else
                        $("#BtnlveMore").hide();
                    if (msg.d.TotalNewConversation != 0)
                        updateID = msg.d.TotalNewConversation;
                }
                hidewait();
            }
        });
    }
}
