﻿/*
-----------------file name       : jspublic.js 
-----------------version         : 1.0
-----------------developed by    : abhishek bhalani-----------------*/
var updateID = 0;
var t = 0; var Ptimer;
var varcatId = 0;
var indx = 1, Tindx = 1;
var Cind = 1;
var pos = 0, bpos = 0;
var catobj, divmoremain, objbtnmore, imgCat;
var _catIdArray = new Array();
var varjoinlink = 'joinoGoing';
var setID, setreplyToUser = "", setreplyId = 0, setrplUsrID = 0, setcatID = 0, setAction;
//default set to null for decrease count by 1 
var upLbl = null;
var varURL = new Object();
if (window.location.href.lastIndexOf("/") > 0) {
    varURL = window.location.href.substring(window.location.href.lastIndexOf("/") + 1, window.location.href.length);
}
/** retweet function used to open popup **/
function tweetPopUp(oBt, action, objuser) {
    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 RetweetpageURL = "http://twitter.com/intent/retweet?tweet_id=" + pr;
    var FavpageURL = "http://twitter.com/intent/favorite?tweet_id=" + pr;
    var ReplypageURL = "http://twitter.com/intent/tweet?in_reply_to=" + pr;
    var w = 500;
    var h = 300;
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    var targetWin;
    var isIE = (navigator.appName == "Microsoft Internet Explorer");
    if (action == "retweet") {
        if (isIE) {
            window.open(RetweetpageURL, 'Retweet_Action_from_Ogoing', 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',resizable');
        } else
            targetWin = window.open(RetweetpageURL, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    }
    else if (action == "favorite") {
        if (isIE)
            window.open(FavpageURL, 'favorite_Action_from_Ogoing', 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',resizable');
        else
            targetWin = window.open(FavpageURL, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    }
    else if (action == "reply") {
        if (isIE)
            window.open(ReplypageURL, 'Reply_User_Action_from_Ogoing', 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',resizable');
        else
            targetWin = window.open(ReplypageURL, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    }
    //    if (action == "retweet") {
    //        Retweet(oBt);
    //    }
    //    else if (action == "favorite") {
    //        FavTweet(oBt);
    //    }
    //    else if (action == "reply") {
    //        ShareTweet(oBt, objuser);
    //    }
}
function show() {
    $(".wait").show();
}
function showM() {
    $("#imgWait").show();
}
//used for main top 10 updates 
function hide() {
    $(".wait").hide();
}
function hideM() {
    $("#imgWait").hide();
}
//used for public live update tab
function showmorewait() {
    $("#imgmorelve").show();
    $("#lblmorelve").hide();
}
//used for public live update tab
function hidemorewait() {
    $("#imgmorelve").hide();
    $("#lblmorelve").show();
}
//used for Home update tab
function showmorewait_Hm() {
    $("#imgmore").show();
    $("#lblmore").hide();
}
//used for Home update tab
function hidemorewait_Hm() {
    $("#imgmore").hide();
    $("#lblmore").show();
}
//used for Category show loading bar
function showCatwait() {
    $(objbtnmore).hide();
    $(imgCat).show();
}
//used for Category hide loading bar and show label
function hideCatwait() {
    $(objbtnmore).show();
    $(imgCat).hide();
}
function hideBox() {
    $(".amore").addClass("clsNo");
}
function showBox() {
    $(".amore").removeClass("clsNo");
}
function ClearFields() {
    if (escape(window.location.href.lastIndexOf("?status=%40")) <= 0) {
        if (t == '1') {

            if ($("[id$='txtUpdateText']").val().indexOf('@') == -1 && $("[id$='txtUpdateText']").val() != '')
                $("[id$='txtUpdateText']").val('');
        }
        //$("#[id$='imgBtnUpdateAll']").innerHTML = 'Update';
        getHashLink();
    }
    $("#[id$='_txtUrl']").val(varhttplink);

    $("[id$='_lblCharCnt']").text('3500');

    if ($("#[id$='_Ig']"))
        $("#[id$='_Ig']").css("display", "none");

    $("[id$='_hdnselected']").html('');
    $("[id$='_hdnselected']").val('');
    $("[id$='_hdnIsImgAtt']").val(false);
    $("#hdn").html('');
    $("#hdn").val('');
}
/****/
// used to get more update of public timeline
function getMore() {
    showmorewait();
    $.ajax({
        type: "POST",
        url: "Service/publicTM.asmx/GetPublicTimeline",
        data: "{PageIndex : " + (++indx) + " }",
        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;
                    if (msg.d.UpTime && msg.d.LtstUp && $("[id$='_LtstUp']").length > 0 && $("[id$='_UpTime']").length > 0) {
                        $("[id$='_LtstUp']").text(msg.d.LtstUp);
                        $("[id$='_UpTime']").text(msg.d.UpTime);
                    }
                    else
                        $("#divltst").hide();
                    document.getElementById('Div1').appendChild(dynDiv);
                    $('div#Div1').find('table').slideDown(); getHashLink();
                }
                if (msg.d.IsShow) {
                    hidemorewait();
                    $(".moreUpslve").show('slow', function () {
                        $(this).css("display", "inline-block");
                    });
                }
                else
                    $(".moreUpslve").hide();
                if (msg.d.TotalNewConversation != 0)
                    updateID = msg.d.TotalNewConversation;
            }
        }
    });
}
// It was used for load updates on scroll event.
// Now it is not used for getting update on  mouse scroll event
function scrollEvent() {
    if (bpos != 0 && pos != 0) {
        try {
            pos = jQuery($(".tp")).position().top;
            bpos = jQuery($(".btm")).position().top;
            //      hide for ipad device it getting wrong position
            //        if( pos >= bpos){               
            //            if(varcatId == 0)
            //                getMore();
            //            else
            //                LoadCat(varcatId, 1);
            //        }
        }
        catch (err) {
            //handle ((err && err.message) || err.toString())            
            $(".btm").html("try again");
        }
    }
};

// get reply updates if url is reply
function ReplyUps() {
    $.ajax({
        type: "POST",
        url: "Service/Def.asmx/GetRpl",
        data: "{ PageIndex : 1}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            document.getElementById('childDiv').innerHTML = msg.d.HtmlStream;
            $('div#childDiv').children().slideDown();
            showMainWait(false);
            if (msg.d.IsShow) {
                $(".moreUps").show('slow', function () {
                    $(this).css("display", "inline-block");
                });
                $(".moreUps").css("display", "none");
                
            }
            else
                $(".moreUps").css("display", "none");
            ClearFields();
        },
        error: function (xhr, ajaxOptions, thrownError) {
        }
    });
}
// reply conversation updates
function ReplyConvLoad() {
    $(".moreUps_rep").css("display", "none");
    
    if ($("#[id$='_lblnoRCFnd']") != null)
        $("#[id$='_lblnoRCFnd']").css("display", "none");
    $.ajax({
        type: "POST",
        url: "Service/Pro.asmx/GetRplConv", // will change webservise
        data: "{ PageIndex : 1}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            document.getElementById('MchildDiv').innerHTML = msg.d.HtmlStream;
            $('div#MchildDiv').children().slideDown();
            if (msg.d.IsShow) {
                $('#lblmoreConv').css("display", "block");
                $(".moreUps").show('slow', function () {
                    $(this).css("display", "inline-block");
                });
            }
            else {
                $('#lblmoreConv').css("display", "none");
                $(".moreUps").css("display", "none");
            }
            
            ClearFields();
            var Mid = $("Div#divRepConv").find("Div#MchildDiv");
            var rows = $(Mid).find("table#HomeTimeline").find('tbody > tr').get();
            var rowlen = $(Mid).find("table#HomeTimeline").find('tbody > tr').length;
        },
        error: function (xhr, ajaxOptions, thrownError) {
            showMainWait(false);
        }
    });
}

// Get update of reply conversation 
function GetReply_Convs() {
    if (document.getElementById('DivlblAct') != null)
        document.getElementById('DivlblAct').style.display = 'none';
    if (document.getElementById('DivlblAct1') != null)
        document.getElementById('DivlblAct1').style.display = '';
    $("#div_ConSrh").show();
    /*** load js files ***/
    //    $.getScript("js/ui.tabs.js", function () {
    //        $('#container1-1 > ul').tabs();
    //        if (window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
    //            $("#container1-1").tabs({ selected: 1 });
    //        }
    //        else {
    //            $("#container1-1").tabs({ selected: 0 });
    //         }
    //    });
    $("#BGSelector a").click(function () {
        var imgLink = $("img", this).attr("src");
    });
    /*** end **/
    var SelectedTab = 0;
    // get Replied
    if (window.location.href.toLowerCase().lastIndexOf("replies") > 0) {
        ReplyUps();
    }
    else if (window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
        //reset Conv Pageindex
        indRepConv = 1;
        // call function to get reply conversation updates.
        ReplyConvLoad();
    }
    // end
}
// to get twitter updates by logged In userID.
// It used to store twitter udpates for current user
// It call asynchronousr after getting update on live page
function getTwitts() {
    //UserTextUpdate_Insert
    $.ajax({
        type: "POST",
        url: "Service/Def.asmx/InsertTFeedsByToken",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
        }
    });
}

// Load public Update list for live/login page
function loadPublicUps() {
     
    $(".moreUpslve").hide();
    $(".moreUps").hide();
    if (document.getElementById('childDiv') != null) {
        Isshow_loading(true);
        showM();
        $(".moreUpslve").hide();
        $.ajax({
            type: "POST",
            async: false,
            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('childDiv').innerHTML = msg.d.HtmlStream;
                        $('div#childDiv').children().slideDown();
                        // added Hyperlinks
                        getHashLink();
                        // Added : 
                        if ($("[id$='_LtstUp']").length > 0 && $("[id$='_UpTime']").length > 0) {
                            $("[id$='_LtstUp']").text(msg.d.LtstUp);
                            $("[id$='_UpTime']").text(msg.d.UpTime);
                        }
                    }
                    if (msg.d.IsShow) {
                        //$(".moreUps").show();
                        hidemorewait();
                        $(".moreUpslve").show('slow', function () {
                            $(this).css("display", "inline-block");
                        });
                    }
                    else
                        $(".moreUpslve").hide();
                    if (msg.d.TotalNewConversation != 0)
                        updateID = msg.d.TotalNewConversation;

                }
                Isshow_loading(false);
                hideM();
                // call the Get Tweet function after getting public update list.                        
               // getTwitts();
            }
        });
    }
}
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

// this fun is call when reviews tab click by user.
function loadreviews() {
 
    
    $(".moreUpslve").hide();
    $(".moreUps").hide();
    if (document.getElementById('childDiv') != null) {
        Isshow_loading(true);
        showM();
        $(".moreUpslve").hide();

        $.ajax({
            type: "POST",
            async: false,
            url: "Service/publicTM.asmx/GetReviews",
            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('childDiv').innerHTML = msg.d.HtmlStream;
                       
                        $('div#childDiv').children().slideDown();
                        // added Hyperlinks
                        getHashLink();
                        // Added : 
                        if ($("[id$='_LtstUp']").length > 0 && $("[id$='_UpTime']").length > 0) {
                            $("[id$='_LtstUp']").text(msg.d.LtstUp);
                            $("[id$='_UpTime']").text(msg.d.UpTime);
                        }
                    }
                    else {
                        if (msg.d.TotalCount == 0) {
                            document.getElementById('childDiv').innerHTML = "<div style='font-size:18px;padding-bottom:101px;padding-top:120px;text-align:center;width:100%;'> No Update Found </div>";
                        } 
                    }
                    if (msg.d.IsShow) {
                        //$(".moreUps").show();
                        hidemorewait();
                        $(".moreUpslve").show('slow', function () {
                            $(this).css("display", "inline-block");
                        });
                    }
                    else
                        $(".moreUpslve").hide();
                    if (msg.d.TotalNewConversation != 0)
                        updateID = msg.d.TotalNewConversation;

                }
                else {
                    if (msg.d.TotalCount == 0) {
                        document.getElementById('childDiv').innerHTML = "<div style='font-size:18px;padding-bottom:101px;padding-top:120px;text-align:center;width:100%;'> No Update Found </div>";
                    }
                }
                Isshow_loading(false);
                hideM();


            },
            error: function (msg) {
                alert(msg);
                document.getElementById('childDiv').innerHTML = "<div style='font-size:18px;padding-bottom:101px;padding-top:120px;text-align:center;width:100%;'> No Update Found </div>";


            }

        });
    }       
}
// get total category of current portal
function GetCategoryList() {
    $.ajax({
        type: "POST",
        url: "Service/Def.asmx/GetCategoryList",
        data: "{ }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg.d.HtmlStream != null) {
                var CatArray = msg.d.HtmlStream.split(',');
                for (var i = 1; i <= parseInt(msg.d.TotalCount); i++) {
                    document.getElementById("lblcat" + i.toString()).style.display = "";
                    document.getElementById("spncat" + i.toString()).style.display = "";
                    document.getElementById("LCat" + i.toString()).style.display = "";
                    if (document.getElementById("lblcat" + i.toString()).innerHTML != null)
                        document.getElementById("lblcat" + i.toString()).innerHTML = CatArray[i - 1].substring(0, CatArray[i - 1].lastIndexOf('_'));
                    _catIdArray[i] = CatArray[i - 1].substring(CatArray[i - 1].lastIndexOf('_') + 1);
                    if (i == 6)
                        break;
                }
            }
            // shows social tabs like "T" (twitter) and "F"(facebook)
            ShowHide_socialTabs(true);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            // hide social tabs like "T" (twitter) and "F"(facebook)
            ShowHide_socialTabs(false);
        }
    });
}

//for loading Updates with Category wise
function LoadCat(CatID, ismore) {
    Isshow_loading(true);
    varcatId = CatID;
    LoadCatobjs(CatID);
    hideBox();
    var _CatID; _CatID = _catIdArray[CatID];
    if (ismore == 0) {
        Cind = 1;
        $.ajax({
            type: "POST",
            async: false,
            url: "Service/publicTM.asmx/GetCatByID",
            data: "{  CatID : " + _CatID + ",PageIndex : " + 1 + ",isProfile : " + false + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                Isshow_loading(false);
                if (msg.d != null) {
                    if (msg.d.HtmlStream != null) {
                        var dynDiv = document.createElement("div");
                        dynDiv.id = "divCatSub";
                        dynDiv.innerHTML = msg.d.HtmlStream;
                    }
                    if (msg.d.TotalCount == 0) {
                        if (catobj != null) {
                            dynDiv.innerHTML = "<div style='font-size:18px;padding-bottom:101px;padding-top:120px;text-align:center;width:100%;'> No Update Found </div>";
                        }
                        $(divmoremain).hide();
                    }
                    if (msg.d.IsShow) {
                        $(divmoremain).show(); hideCatwait(); showBox();
                    }
                    else {
                        $(divmoremain).hide();
                    }
                    catobj.innerHTML = "";
                    catobj.appendChild(dynDiv);
                    $("div#" + catobj.id).find('table').slideDown();
                    //  Added Hyperlinks
                    getHashLink();
                }
            }
        });
        //hide();
    }
    else {
        if ($(objbtnmore).is(":visible")) {
            showCatwait();
            $.ajax({
                type: "POST",
                async: false,
                url: "Service/publicTM.asmx/GetCatByID",
                data: "{  CatID : " + _CatID + ",PageIndex : " + ++Cind + ",isProfile : " + false + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    Isshow_loading(false);
                    if (msg.d != null) {
                        if (msg.d.HtmlStream != null) {
                            var dynDiv = document.createElement("div");
                            dynDiv.id = "divCatSub";
                            dynDiv.innerHTML = msg.d.HtmlStream;
                        }
                        if (msg.d.TotalCount == 0) {
                            if (catobj != null) {
                                dynDiv.innerHTML = "<div style='font-size:18px;padding-bottom:101px;padding-top:120px;text-align:center;width:100%;'> No Update Found </div>";
                            }
                            $(divmoremain).hide();
                        }
                        if (msg.d.IsShow)
                        { $(divmoremain).show(); hideCatwait(); showBox(); }
                        else
                            $(divmoremain).hide();
                        //catobj.innerHTML = "";          
                        catobj.appendChild(dynDiv);
                        $("div#" + catobj.id).find('table').slideDown(); getHashLink();
                    }
                    hideM();
                }
            });
        }
        else
            hideM();
    }
}
// Load category objects
function LoadCatobjs(CatID) {
    catobj = document.getElementById("divCat" + CatID.toString());  //catobj : where load all the sub content of update text
    divmoremain = ".moreUpsCat" + CatID;   // main class of label more and wait progress bar        
    objbtnmore = document.getElementById("lblmoreCat" + CatID.toString()); // Label more object for all categories
    imgCat = document.getElementById("imgmoreCat" + CatID.toString()); // loading image for all categories        
}

// timer to check is latest updates found or not
function checkLatest() { clearInterval(Ptimer); Ptimer = setInterval(getLatestUps, 1000 * 60); }

// function to used to getting new updates from database
function getLatestUps() {
    t = t + 1;
    if (t > 20) { clearInterval(Ptimer); Ptimer = null; }
    if (updateID != 0) {
        $.ajax({
            type: "POST",
            url: "Service/publicTM.asmx/IsNewPublicRecordsFound",
            data: "{ updateID : " + updateID + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d.TotalNewConversation != 0) {
                    if (varcatId == 0) loadPublicUps();
                    else {
                        if (varcatId != null && varcatId != 'undefined') {
                            LoadCat(varcatId, 0);
                        }
                    }
                }
            }
        });
    }
}
//end  

// function used to redirect to page 
function redLogn(obj) {
    top.location = obj;
}

// Load home timeline updates
function LoadHmUps() {

    $(".moreUpslve").hide();
    Isshow_loading(true);
    $.ajax({
        type: "POST",
        async: false,
        url: "Service/Def.asmx/GetHmTimeline",
        data: "{ PageIndex : 1}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            document.getElementById('childDiv').innerHTML = msg.d.HtmlStream;
            $('div#childDiv').children().slideDown();
            Isshow_loading(false);
            if (msg.d.IsShow) {
                hidemorewait_Hm();
                $(".moreUps").show('slow', function () {
                    $(this).css("display", "inline-block");
                });
            }
            else {
                $(".moreUps").hide();
            }
            $("[id$='_LtstUp']").text(msg.d.LtstUp);
            $("[id$='_UpTime']").text(msg.d.UpTime);
            ClearFields();
            Isshow_loading(false);
        },
        error: function (err) {
              Isshow_loading(false);
         
        }
    });
}

// Used to get more update of User's Hometimeline
function more() {
    // hide more wait 'moreUpslve' box for home tab
    $(".moreUpslve").hide();
    if (varURL.toLowerCase() == "home" || varURL.toLowerCase().substring(0, 4) == "home") {
        Isshow_loading(true);
        showmorewait_Hm();
        $.ajax({
            type: "POST",
            url: "Service/Def.asmx/GetHmTimeline",
            data: "{ PageIndex : " + ++ind + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var dynDiv = document.createElement("div");
                dynDiv.id = "divDyna";
                dynDiv.innerHTML = msg.d.HtmlStream;
                document.getElementById('Div1').appendChild(dynDiv);
                $('div#Div1').find('table').slideDown(); getHashLink();
                if (msg.d.IsShow) {
                    hidemorewait_Hm();
                    $(".moreUps").show('slow', function () {
                        $(this).css("display", "inline-block");
                    });
                }
                else {
                    $(".moreUps").hide();
                }
                Isshow_loading(false);
            },
            error: function (err) {
                Isshow_loading(false);
                hidemorewait_Hm();
            }
        });
    }
    else if ((varURL.toLowerCase() == "replies"  || window.location.href.toLowerCase().lastIndexOf("conversation") > 0 ) && varURL.toLowerCase() != "conversation") {
    
        // Call the service if page is replies or conversation
        $.ajax({
            type: "POST",
            url: "Service/Def.asmx/GetRpl",
            data: "{ PageIndex : " + ++ind + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var dynDiv = document.createElement("div");
                dynDiv.id = "divDyna";
                dynDiv.innerHTML = msg.d.HtmlStream;
                showMainWait(false);
                if (!msg.d.IsShow)
                    $("#[id$='_BtnMore']").css("display", "none");
                else
                    $("#[id$='_BtnMore']").css("display", "");
                document.getElementById('Div1').appendChild(dynDiv);
                $('div#Div1').find('table').slideDown(); getHashLink();
            }
        });
    }    
    else if (window.location.href.lastIndexOf("search/q") > 0) {
        /// get search result Updates if page contains "search/q"
        var starttime = new Date();
        $.ajax({
            type: "POST",
            url: "../Service/Def.asmx/GetSrch",
            data: "{ PageIndex : " + ++ind + ", 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) {
                var dynDiv = document.createElement("div");
                dynDiv.id = "divDyna";
                dynDiv.innerHTML = msg.d.HtmlStream; getHashLink();
                showMainWait(false);
                if (msg.d.IsShow) {
                    hidemorewait();
                    $(".moreUps").show('slow', function () {
                        $(this).css("display", "inline-block");
                    });
                }
                else {
                    $(".moreUps").hide();
                }
                //                if (msg.d.IsShow)
                //                    $("#[id$='_BtnMore']").css("display", "");
                //                else
                //                    $("#[id$='_BtnMore']").css("display", "none");
                document.getElementById('Div1').appendChild(dynDiv);
                $('div#Div1').find('table').slideDown();
            }
        });
    }
    else if (window.location.href.toLowerCase().lastIndexOf("favorites") > 0) {
        // getting favorite update list
        var urlname = window.location.href.substring(0, window.location.href.lastIndexOf("/"));
        var uname = urlname.substring(urlname.lastIndexOf("/") + 1, urlname.length);
        if (uname != "") {
            $.ajax({
                type: "POST",
                url: "../Service/Def.asmx/GetFvrt",
                data: "{ PageIndex : " + ++ind + ", u:'" + uname + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    var dynDiv = document.createElement("div");
                    dynDiv.id = "divDyna";
                    dynDiv.innerHTML = msg.d.HtmlStream;
                    showMainWait(false);
                    if (!msg.d.IsShow)
                        $("#[id$='_BtnMore']").css("display", "none");
                    else
                        $("#[id$='_BtnMore']").css("display", "");
                    document.getElementById('Div1').appendChild(dynDiv);
                    $('div#Div1').find('table').slideDown(); getHashLink();
                }
            });
        }
    }
}
function moreCon() {
 
    // hide more wait 'moreUpslve' box for home tab
    $(".moreConv").hide();

    showMainWait(true);
        // Call the service if page is replies or conversation
    $.ajax({
        type: "POST",
        url: "Service/Pro.asmx/GetRplConv",
        data: "{ PageIndex : " + ++ind + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var dynDiv = document.createElement("div");
            dynDiv.id = "divDyna";
            dynDiv.innerHTML = msg.d.HtmlStream;
            showMainWait(false);
            if (!msg.d.IsShow) {
                $(".moreUps").css("display", "none");
                $("#[id$='_lblmoreConv']").css("display", "none");
            }
            else {
                $("#[id$='_lblmoreConv']").css("display", "");
                $(".moreUps").css("display", "");
            }
            document.getElementById('divRepConv').appendChild(dynDiv);
            $('div#divRepConv').find('table').slideDown(); getHashLink();
        }
    });
 
     
}
// used to get search results
function getSrhResults() {
    HideHome_Feed();
    $(".moreUpslve").hide();
    $(".moreUps").hide();
    var starttime = new Date();
    //$("#imgTwit").attr("src", "../images/twiticon.gif");
    if ($("#[id$='_iLoadmor']"))
        $("#[id$='_iLoadmor']").css("display", "");
    showmorewait_Hm();
    $.ajax({
        type: "POST",
        url: "../Service/Def.asmx/GetSrch",
        data: "{ PageIndex : 1, s:'" + window.location.href.substring(window.location.href.lastIndexOf("search/q=") + 9, window.location.href.length) + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        //async : false,
        success: function (msg) {
            if (msg) {
                if (msg.d.TotalCount > 0)
                    document.getElementById('childDiv').innerHTML = msg.d.HtmlStream;
                $('div#childDiv').children().slideDown();
                showMainWait(false);
                if ($("#[id$='_iLoadmor']"))
                    $("#[id$='_iLoadmor']").css("display", "none");
                if (msg.d.IsShow) {
                    hidemorewait_Hm();
                    $(".moreUps").show('slow', function () {
                        $(this).css("display", "inline-block");
                    });
                }
                else {
                    $(".moreUps").hide();
                }
                //$("#[id$='_BtnMore']").css("display", "none");
                //else
                //$("#[id$='_BtnMore']").css("display", "");
                if ($("#[id$='div_srh']"))
                    $("#[id$='div_srh']").css("display", "");
                var endtime = new Date();
                var fnl = endtime.getSeconds() - starttime.getSeconds();
                var secDiff = endtime.getMilliseconds() - starttime.getMilliseconds();
                if (secDiff < 0)
                    secDiff = 10;
                if (msg.d.TotalCount > 0)
                    $("#[id$='_lblTime']").text(decodeURI(window.location.href.substring(window.location.href.lastIndexOf("search/q=") + 9, window.location.href.length)).replace(/\%20/g, " ").replace(/\%26/g, "\"").replace(/\%27/g, "'").replace(/\%23/g, "#")
                            + ' ' + msg.d.TotalCount + ' records found in ' + fnl + '.' + Math.round((secDiff / 10)) + ' second(s)');
                else {
                    $("#[id$='_lblTime']").text('No records found.');
                    $("#[id$='_realTmText']").hide();
                }
            }
            // clear/reset objects
            ClearFields();
        },
        error: function (xhr, ajaxOptions, thrownError) {
            showMainWait(false);
            hidemorewait_Hm();
        }
    });
    showMainWait(false);
}

// Load homepage Data. (home tab)
// Used to get Homepage timeline 
function loadhmData() {
    varcatId = 0;
    if (varURL.toLowerCase() == "home" || varURL.substring(0, 4).toLowerCase() == "home" || varURL.toLowerCase() == "home#" || varURL.toLowerCase() == "Home#") {
        LoadHmUps();
    }
    //    else if (window.location.href.toLowerCase().lastIndexOf("replies") > 0 || window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
    //        GetReply_Convs();
    //    }
}
// used to load data 
function LoadData() {
    // initialize category ID
    varcatId = 0;
    if (varURL.toLowerCase() == "home" || varURL.substring(0, 4).toLowerCase() == "home" || varURL.toLowerCase() == "home#" || varURL.toLowerCase() == "Home#") {
        if ($('#container-1').length > 0)
            $('#container-1 > ul').tabs();
        $("#container-1").tabs({ selected: 0 });
        //loadhmData();
        //LoadHmUps();
     
        // get category tabs
        if (document.getElementById("lblcat1") != null) {
            GetCategoryList();
        }
        loadPublicUps();
    }
    else if (window.location.href.toLowerCase().lastIndexOf("replies") > 0 || window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
        if ($('#container1-1').length > 0)
            $('#container1-1 > ul').tabs();
        if (window.location.href.toLowerCase().lastIndexOf("replies") > 0) {
            $("#container1-1").tabs({ selected: 0 });
        }
        else if (window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
            $("#container1-1").tabs({ selected: 1 });
        }
        // Load replied/conversation HTML data if URL like conversation or reply
        if (window.location.href.toLowerCase().lastIndexOf("conversation") > 0 || window.location.href.toLowerCase().lastIndexOf("replies") > 0)
            GetReply_Convs();
    }
    // Load search update results if URL like 'search/q'
    else if (window.location.href.toLowerCase().lastIndexOf("search/q") > 0) {
        getSrhResults();
    }
    // now favorite is not used
    else if (window.location.href.toLowerCase().lastIndexOf("favorites") > 0) {
        HideHome_Feed();
        var urlname = window.location.href.substring(0, window.location.href.lastIndexOf("/"));
        var uname = urlname.substring(urlname.lastIndexOf("/") + 1, urlname.length);
        if (uname != "") {
            $.ajax({
                type: "POST",
                url: "../Service/Def.asmx/GetFvrt",
                data: "{ PageIndex : 1 , u:'" + uname + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    document.getElementById('childDiv').innerHTML = msg.d.HtmlStream;
                    $('div#childDiv').children().slideDown();
                    showMainWait(false);
                    if (!msg.d.IsShow)
                        $("#[id$='_BtnMore']").css("display", "none");
                    else
                        $("#[id$='_BtnMore']").css("display", "");
                    ClearFields();
                }
            });
        }
    }
    // Load most trends topics
    else if (window.location.href.toLowerCase().lastIndexOf("mosttrend") > 0) {
        HideHome_Feed();
        $(".h_box").hide();
        if ($('#new_results_notification').length > 0) $('#new_results_notification').css("display", "none");
        $.ajax({
            type: "POST",
            url: "Service/Topics.asmx/GetTpcs",
            data: "{ UpdateID :'" + $.query.get('UpdateID') + "' , op : '" + $.query.get('op') + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                document.getElementById('childDiv').innerHTML = msg.d.HtmlStream;
                $('div#childDiv').children().slideDown();
                showMainWait(false);
                if (!msg.d.IsShow)
                    $("#[id$='_BtnMore']").css("display", "none");
                else
                    $("#[id$='_BtnMore']").css("display", "");
                bindTopiclink();
                ClearFields();
            }
        });
    }
    // load public updates
    else {
        if ($('#container-1').length > 0)
            $('#container-1 > ul').tabs();
        //  Load public updates
        // get category tabs
        if (document.getElementById("lblcat1") != null) {
            GetCategoryList();
            // Comment for stop fetching new updates from Database in every minute        
            // if (window.location.href.toLowerCase().toString().indexOf('live') > 0) { checkLatest(); }
        }
         loadPublicUps();
    }
}

// Used to dynamic linking the hash keywords in updates on all pages except userprofile, this function is used in userprofile page too
function getHashLink() {
    var obj = $(".com_text");
    obj.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>";
            return "<a target='_self' class='msg_links' href='" + getBaseURL() + "oGoingResult.aspx?Ftext=" + encodeURIComponent($1.replace('#', '')) + "'>" + $1 + "</a>";            
        }));
    });
}


// This function used to load more function for the category updtaes
function loadmoreCat() {
    LoadCat(varcatId, 1);
}
// open popup for login actions
function LoginForAction(obja, action) {
    setAction = action;
    $(function () {
        $("#btnjoin").show();
        $("#btnLogin").show();
        $("#divLgJn").show();
        $("#divLgJn").dialog('open');
        $(".ui-resizable-se").hide();
    });
}
//function AskForLogin() {
// if user not logged In then set action and variable after logged in
function AskForLogin(objaID, objareplyToUser, objareplyId, objarplUsrID, objacatID) {

    setID = objaID;
    setreplyToUser = objareplyToUser;
    setreplyId = objareplyId;
    setrplUsrID = objarplUsrID;
    setcatID = objacatID;
    if (arguments.length == 2) {
        //LoginForAction(setID, setreplyToUser);
        setAction = setreplyToUser;
        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 () {
        $("#btnjoin").show();
        $("#btnLogin").show();
        $("#divLgJn").show();
        $("#divLgJn").dialog('open');
        $(".ui-resizable-se").hide();
    });
}
// used to store data
function storeAttDc(objuAttID, uid) {
    if (uid == 0) showPopup();
    //else {showPopup(varURL); }
}

// render the popup of sign in or signup block
function showPopup() {
    $("#divlgntoDn").show();
    $("#divlgntoDn").dialog('open');
    $(".ui-resizable-se").hide();
    return false;
}
// check the user is user validate or follower.
function getfollow() {
    $.ajax({
        type: "POST",
        url: "Service/usrVldte.asmx/getflw",
        data: "{ }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            window.location = window.location.href;
            return true;
        },
        error: function (xhr, ajaxOptions, thrownError) {
        }
    });
}
// why join popUp
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function () {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query = popURL.split('?');
    var dim = query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;
    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top': -popMargTop,
        'margin-left': -popMargLeft
    });
    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function () { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function () {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});
/******************************************
* PopUp Box
******************************************/
//adTime = 45;  // seconds ad reminder is shown
adTime = 30;
chanceAd = 1; // ad will be shown 1 in X times (put 1 for everytime)
var ns = (document.layers);
var ie = (document.all);
var w3 = (document.getElementById && !ie);
var calunit = ns ? "" : "px"
adCount = 0;
// function used for initialize the popup box
function initAd() {
    if (!ns && !ie && !w3) return;
    if (ie) adDiv = eval('document.all.sponsorAdDiv.style');
    else if (ns) adDiv = eval('document.layers["sponsorAdDiv"]');
    else if (w3) adDiv = eval('document.getElementById("sponsorAdDiv").style');
    randAd = Math.ceil(Math.random() * chanceAd);
    // To show/hide popup on live page
    // Add : adDiv.display = "block";    
    if (adDiv != null) {
        //adDiv.display = "block";
        /***** below service used to set session for popup.
        first time session is null and set the popup visible for xx seconds
        after that popup will not shown still browser not closed.
        **/
        $.ajax({
            type: "POST",
            url: "Service/publicTM.asmx/IsPopUpVisible",
            data: "{ }",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (msg) {
                if (msg) {
                    if (msg.d) {
                        adDiv.display = "block";
                    }
                    else {
                        adDiv.display = "none";
                    }
                }
            }, error: function (xhr, ajaxOptions, thrownError) { adDiv.display = "none"; }
        });
        /****** end ********/
    }
    if (randAd == 1) showAd();
}
// function used to render PopUp to page
function showAd() {
    if (adCount < adTime * 10) {
        adCount += 1;
        if (ie) {
            documentWidth = truebody().offsetWidth / 2 + truebody().scrollLeft - 20;
            documentHeight = truebody().offsetHeight / 2 + truebody().scrollTop - 20;
        }
        else if (ns) {
            documentWidth = window.innerWidth / 2 + window.pageXOffset - 20;
            documentHeight = window.innerHeight / 2 + window.pageYOffset - 20;
        }
        else if (w3) {
            documentWidth = self.innerWidth / 2 + window.pageXOffset - 20;
            documentHeight = self.innerHeight / 2 + window.pageYOffset - 20;
        }
        if (adDiv != null) {
            adDiv.left = documentWidth - 300 + calunit;
            adDiv.top = documentHeight - 197 + calunit;
        }
        setTimeout("showAd()", 100);
    }
    else closeAd();
}
// function used to close PopUp 'why join popup'
function closeAd() {
    if (adDiv != null) {
        adDiv.display = "none";
    }
}
// function used to open PopUp 'why join popup'
function openAd() {
    adCount = 0; adTime = 300;
    if (adDiv != null) {
        adDiv.display = "block";
    }
}
function truebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

// Initialize Popup on event "onload" 
if (window.location.href.indexOf("live") > 0 || window.location.href.indexOf("login") > 0)
    onload = initAd;
//End--> 

// open the popup for resend password It would be called after three user login attempt 
function ThreeAttempt(objval) {
    $.fn.jmodal({
        title: 'Information',
        content: 'Forgot password! Don`t worry click on yes button for retrive your password',
        buttonText: { ok: 'Yes,It is.', cancel: 'No' },
        okEvent: function (obj, args) {
            window.open('resendpassword?UserName=' + objval, target = '_self');
        }
    });
}
// check is user validate 
function getValidate(objUsr, objPwd) {
    try {
        $.ajax({
            type: "POST",
            //url: "Service/usrVldte.asmx/isUsrVlidte",
            url: "Service/usrVldte.asmx/IsUserAuthenticate",
            data: "{ txtunm : \"" + objUsr + "\",txtpass : \"" + objPwd + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (msg) {

                if (msg.d.StrTitle != "") {
                    $('#boxlblError').fadeIn('fast');
                    $('#boxlblError').text(msg.d.StrTitle);
                    return false;
                }
                else {
                    if (msg.d.IsAdmin)
                        window.location = "admin/default.aspx";
                    else {
                        if (setID && setAction && setAction != "" && setID != null) {
                            SetUserActions(setID, setAction);
                        }
                        else if (setID && setreplyId && setrplUsrID != 0 && setreplyToUser != "") {
                            SetTextBox(setID, setreplyToUser, setreplyId, setrplUsrID, setcatID);
                        }
                        else {
                            window.location = "home";
                            //window.location = window.location.href;
                        }
                    }
                    return true;
                }
            }, error: function (xhr, ajaxOptions, thrownError) { return false; }
        });
    }
    catch (err) { return false; }
}
// used to login box render
function loadLoginBox() {
    // reset the error box
    $('#boxlblError').text('');
    //show login dialog box
    $("#lgnDialog").show();
    $('#lgnDialog').dialog('open');
    $("#lgnDialog").addClass("loginbox");
}
function LoadCnvSearch() {
    Isshow_loading(true);
    indRepConv = 1;
    //var RCnvTxt="";
    if ($("#[id$='_txtConvSrh']") && $.trim($("#[id$='_txtConvSrh']").val()) != "") {
        RCnvTxt = $.trim($("#[id$='_txtConvSrh']").val());
        if (RCnvTxt != null && RCnvTxt != "") {
            // $("#container1-1").tabs({ selected: 1 });
            $.ajax({
                type: "POST",
                url: "Service/Pro.asmx/GetRplConvSrchRes",
                data: "{ PageIndex : 1, RCnvTxt: '" + RCnvTxt + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    Isshow_loading(false);
                    if (msg.d.HtmlStream != null && msg.d.HtmlStream != "") {
                        document.getElementById('MchildDiv').innerHTML = "";
                        document.getElementById('MchildDiv').innerHTML = msg.d.HtmlStream;
                        $('div#MchildDiv').children().slideDown();
                        if ($("#[id$='_lblnoRCFnd']") != null)
                            $("#[id$='_lblnoRCFnd']").css("display", "none");
                    }
                    else {
                        if ($("#[id$='_lblnoRCFnd']") != null)
                            $("#[id$='_lblnoRCFnd']").css("display", "");
                    }
                    if (msg.d.IsShow)
                        $(".moreUpslve").show('slow', function () {
                            $(this).css("display", "inline-block");
                        });
                    else
                        $(".moreUpslve").css("display", "none");
                    ClearFields();
                    var Mid = $("Div#divRepConv").find("Div#MchildDiv");
                    var rows = $(Mid).find("table#HomeTimeline").find('tbody > tr').get();
                    var rowlen = $(Mid).find("table#HomeTimeline").find('tbody > tr').length;
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    Isshow_loading(false);
                }
            });
        }
    }
}
function ShowHide_socialTabs(objS) {
    try {
        if (!objS) {
            if (!$("#lifeed").hasClass("clsHd"))
                $("#lifeed").addClass("clsHd");
            if (!$("#lifb").hasClass("clsHd"))
                $("#lifb").addClass("clsHd");
        }
        else {
            var isvisT = $("[id$='_lblTFeed']").is(":Visible") && $("[id$='_lblTFeed']").length > 0;
            var isvisF = $("[id$='_lblFacebook']").is(":Visible") && $("[id$='_lblFacebook']").length > 0;
            if (isvisT) $("#lifeed").removeClass("clsHd");
            else if (!$("#lifeed").hasClass("clsHd"))
                $("#lifeed").addClass("clsHd");

            if (isvisF) $("#lifb").removeClass("clsHd");
            else if (!$("#lifb").hasClass("clsHd"))
                $("#lifb").addClass("clsHd");
        }
    }
    catch (err) {
        $("#lifeed").css("display", "none");
        $("#lifb").css("display", "none");
    }
}
// window ready event to initialize page control
$(document).ready(function () {
    // call the default load function        
    LoadData();
    //    if (varURL.toLowerCase() == "home" || varURL.substring(0, 4).toLowerCase() == "home" || varURL.toLowerCase() == "home#" || varURL.toLowerCase() == "Home#") {
    //        if ($('#container-1').length > 0)
    //            $('#container-1 > ul').tabs();
    //    }
    //else 
    //{
    //        if ($('#container1-1').length > 0)
    //            $('#container1-1 > ul').tabs();
    //        if (window.location.href.toLowerCase().lastIndexOf("replies") > 0) {
    //            $("#container1-1").tabs({ selected: 0 });
    //        }
    //        else if (window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
    //            $("#container1-1").tabs({ selected: 1 });
    //        }
    //        if (window.location.href.toLowerCase().lastIndexOf("conversation") > 0 || window.location.href.toLowerCase().lastIndexOf("replies") > 0)
    //            GetReply_Convs();
    //}
    $("#BGSelector a").click(function () { var imgLink = $("img", this).attr("src"); });

    if ($(".tp").length > 0) { pos = jQuery($(".tp")).position().top; bpos = jQuery($(".btm")).position().top; window.onscroll = scrollEvent; }

    //    document.addEventListener('touchend', function(e) {
    //        e.preventDefault();
    //        var touch = e.touches[0];
    ////        document.write(touch.pageX + " - " + touch.pageY);
    //    }, false);
    $(".rightside").click(function () {
        $(".huinfo").css("display", "none");
    });
    //get more updates on click event      
    $(".moreUps").click(function () {
        //$(this).hide();
        more();
    });
    $(".moreUpslve").click(function () {
        //        $(this).hide();
        getMore();
    });
    //get more updates on mouse over 
    //    $(".moreUps").mouseover(function () {
    //        $(this).hide();
    //        more();
    //    });
    //    $(".moreUpslve").mouseover(function () {
    //        $(this).hide();
    //        getMore();
    //    });

    var tg = 0;
    //   $(".menu ul").mouseover(function(){
    //        if(!$("#signin_menu").is(":visible"))
    //        $(this).css("background-color","#5DA8DD");
    //   });
    //   $(".menu ul").mouseout(function(){
    //    $(this).css("background-color","#6DBDFA");
    //   });

    //click event is used to fade in /fade out signin div/container of JoinoGoing.aspx page.
    // it is also used to change the background image/color of the menu.

    $("[id$='_A6']").click(function () {

        $("#header").css("position", "relative");
        //        $("#signin_menu").css("display","block");
        //$("#signin_menu").toggle(function () { });
        //$("#signin_menu").slideToggle(500, function () { });
        //css("display","block");        
        if (!$("#signin_menu").is(":visible"))
            $("#signin_menu").fadeIn(300);
        else
            $("#signin_menu").fadeOut(500);
        if ($("#txtUname").length > 0)
            $("#txtUname").focus();
        else if ($("[id$='_txtUname']").length > 0)
            $("[id$='_txtUname']").focus();
        //        $("#signin_menu").toggle('slow', 
        //            function () {
        //                if ($(this).is(":visible"))
        //                    $(this).slideUp();
        //                else 
        //                    $(this).slideDown(); 
        //});            
        if (tg == 0) {
            $(".menu ul").css("background-color", "#6DBDFA");
            $(".clsTop span").css("background-image", "url(images/slide_btn_up.png)");
            tg = 1;
        }
        else {
            $(".menu ul").css("height", "15px");
            $(".menu ul").css("background", "#FFF");
            $(".clsTop span").css("background-image", "url(images/slide_btn_down.png)"); tg = 0;
        }
    });
    //$(".moreUpsCat1,.moreUpsCat2,.moreUpsCat3,.moreUpsCat4,.moreUpsCat5,.moreUpsCat6").mouseover(function () { loadmoreCat(); });
    $(".moreUpsCat1,.moreUpsCat2,.moreUpsCat3,.moreUpsCat4,.moreUpsCat5,.moreUpsCat6").click(function () { loadmoreCat(); });

    $(function () {
        $('#lgnDialog').dialog({ autoOpen: false, width: 260 }); // Descrease dialogbox width
        $('#divLgJn').dialog({ autoOpen: false, width: 350 }); // Increase dialogbox width
        $('#divlgntoDn').dialog({ autoOpen: false, width: 355 });
    });
    $(".reasClose").click(function () { closeAd(); });
    $("#hlnWhyJoin").click(function () { initAd(); openAd(); });
    $("#btnjoin").click(function () { redLogn(varjoinlink); });
    $("#btnsignin").click(function () { $("#divLgJn").dialog("close"); loadLoginBox(); });
    $("#signinDw").click(function () { $("#divlgntoDn").dialog("close"); loadLoginBox(); });
    // add get Conversation Search results    
    //    $("#[id$='_btnSrhConv']").click(function () {
    //        LoadCnvSearch();
    //    });
    /******** 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);
    //    });
    /** end **/
});

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;
}
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;
}
function SetTextBox(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') {
        var oBt = objID;
        var act = 0;
        if (oBt.src != null) {
            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";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserUpdateTextID : " + pr + ", Fvrt :  " + act + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (msg) {
                window.location = "home";
            }
        });
    }
    else if (objAct.toLowerCase() == 'liked') {
        var oBt = objID;
        var pr = oBt.id.substring(oBt.id.lastIndexOf('_') + 1, oBt.id.length);
        var serveURL = getBaseURL() + "Service/CommonService.asmx/SetLkd";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserUpdateTextID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (msg) {
                window.location = "home";
            }
        });
    }
    else if (objAct.toLowerCase() == 'share') {
        //ShareUpdate(objID);
        var oBt = objID;
        var act = 0;
        if (oBt.src != null) {
            if (oBt.src.indexOf("shrd.gif") > 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/ShareUserUpdate";
        $.ajax({
            type: "POST",
            url: serveURL,
            data: "{ UserUpdateTextID : " + pr + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (msg) {
                if (msg.d == "2") {
                    alert('You do not have any followers to share this update.');
                }
                else {
                    if (oBt.src != null) {
                        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.');
                    window.location = "home";
                }
            }
        });
    }
}

// Below function used for new Index (login) page : call the perticular tab after succesfully file uploads
function reloadPubs() {
    try {
        if (isTwit != 1) {
            if ($("[id$='_hdnCatIndex']") && $("[id$='_hdnCatIndex']").length > 0) {
                // load perticular tab click event
                $("#LCat" + $("[id$='_hdnCatIndex']").val()).click();
            }
            else {
                // load default method
                LoadData();
            }
        }
    }
    catch (er) {
        LoadData();
    }
}

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");
    }
}
// generate Html  for Who's Here Users  popup on mouse over event 
function WhoUserover(obj) {
    $(".whos").html("");
    var x = jQuery(obj).position().left + jQuery(obj).outerWidth();
    var y = jQuery(obj).position().top; //- jQuery(document.parentNode).scrollTop();
    var ele = $(obj);
    ele.next(".huinfo").css("right", (324 - parseInt(x)));
    if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        ele.next(".huinfo").css("top", (y - 80));
    else
        ele.next(".huinfo").css("top", (y - 55));

    var MoreInfoURL = obj.id.replace("imgbtnUserPicture", "hdnMoreInfoURL");
    var OneLineBio = obj.id.replace("imgbtnUserPicture", "hdnOneLineBio");
    var Location = obj.id.replace("imgbtnUserPicture", "hdnLocation");
    var Username = obj.id.replace("imgbtnUserPicture", "hdnUsername");
    var UserFullName = obj.id.replace("imgbtnUserPicture", "hdnUserFullName");
    var iUs = obj.id.replace("imgbtnUserPicture", "iUs");
    var USerImage = document.getElementById(iUs);
    ele.next(".huinfo").css("display", "block");
    var str = "<div class='huinfo-profile'><a target='_blank' hreflang='en' class='avatar' href='/" + obj.childNodes[4].value + "'>";
    str += "<img id='Img1' runat='server' height='48' border='0' width='48' style='vertical-align: middle;'  src='" + USerImage.src + "' />";
    str += "</a>";
    str += "<div class='huinfo-name'>";
    str += "<strong>";
    str += obj.childNodes[5].value;
    str += "</strong>";
    str += "</div>";
    str += "<span class='huinfo-username'>@<a href='/" + obj.childNodes[4].value + "'>" + obj.childNodes[4].value + "</a></span>";
    str += "<span class='huinfo-location'>";
    str += obj.childNodes[3].value;
    str += "</span><span class='huinfo-Bio'>";
    str += obj.childNodes[2].value;
    str += "</span><span class='huinfo-MoreInfo'>";
    str += obj.childNodes[1].value;
    str += "</span>";
    str += "</div>";
    str += "<div class='huinfo-update'>";
    str += "<div class='huinfo-label'>";
    str += "Recently Updated:</div>";
    str += "<div class='huinfo-uptext'>";
    str += "" + obj.childNodes[5].value + "</div>";
    str += "<div class='huinfo-dur'>";
    str += "" + obj.childNodes[6].value + "</div>";
    str += "</div>";
    str += "<div class='huinfo-pointer'>";
    str += "&nbsp;</div>";


    $(".whos").append(str);
}

// generate Html  for Featured Users  popup on mouse over event 
function featureUserover(obj) {

    $(".feature").html("");
    var x = jQuery(obj).position().left + jQuery(obj).outerWidth();
    var y = jQuery(obj).position().top; //- jQuery(document.parentNode).scrollTop();
    var ele = $(obj);
    ele.next(".huinfo").css("right", (324 - parseInt(x)));
    if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        ele.next(".huinfo").css("top", (y - 30));
    else
        ele.next(".huinfo").css("top", (y - 55));
    ele.next(".huinfo").css("display", "block");
    var iUs = obj.id.replace("imgbtnUserPicture", "iUs");
    var USerImage = document.getElementById(iUs);
    var str = "<div class='huinfo-profile'><a target='_blank' hreflang='en' class='avatar' href='/" + obj.childNodes[4].value + "'>";
    str += "<img id='Img1' runat='server' height='48' border='0' width='48' style='vertical-align: middle;'  src='" + USerImage.src + "' />";
    str += "</a>";
    str += "<div class='huinfo-name'>";
    str += "<strong>";
    str += obj.childNodes[5].value;
    str += "</strong>";
    str += "</div>";
    str += "<span class='huinfo-username'>@<a href='/" + obj.childNodes[4].value + "'>" + obj.childNodes[4].value + "</a></span>";
    str += "<span class='huinfo-location'>";
    str += obj.childNodes[3].value;
    str += "</span><span class='huinfo-Bio'>";
    str += obj.childNodes[2].value;
    str += "</span><span class='huinfo-MoreInfo'>";
    str += obj.childNodes[1].value;
    str += "</span>";
    str += "</div>";
    str += "<div class='huinfo-pointer'>";
    str += "&nbsp;</div>";


    $(".feature").append(str);
}



// Hide Just Joined Users  popup on mouse out event 
function MostUserOut(obj) {
    $(".huinfo").css("display", "none");
}
// generate Html  for Just Joined Users  popup on mouse over event 
function MostUserover(obj) {

    $(".most").html("");
    var x = jQuery(obj).position().left + jQuery(obj).outerWidth();
    var y = jQuery(obj).position().top; //- jQuery(document.parentNode).scrollTop();
    var ele = $(obj);
    ele.next(".huinfo").css("right", (324 - parseInt(x)));
    if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent))
        ele.next(".huinfo").css("top", (y - 30));
    else
        ele.next(".huinfo").css("top", (y - 55));
    var iUs = obj.id.replace("imgbtnUserPicture", "iUs");
    var USerImage = document.getElementById(iUs);
    ele.next(".huinfo").css("display", "block");
    var str = "<a target='_blank' hreflang='en' class='avatar'><img id='Img1' runat='server' height='48' border='0' width='48' style='vertical-align: middle;'  src='" + USerImage.src + "' />  </a>";
    str += "<div class='huinfo-name'><strong>" + obj.childNodes[5].value + "</strong></div><span class='huinfo-username'>@<a href='/" + obj.childNodes[4].value + "'> " + obj.childNodes[4].value + "</a></span><span class='huinfo-location'>"
    str += "" + obj.childNodes[3].value + "  </span><span class='huinfo-Bio'> " + obj.childNodes[2].value + " </span><span class='huinfo-MoreInfo'>" + obj.childNodes[1].value + "</span>";
    str += "<div class='huinfo-pointer'>";
    str += "&nbsp;</div>";
    $(".most").append(str);
}

function attachJq() {

    $("[id$='_imgbtnUserPicture']").mouseout(function () {
        $(this).next(".huinfo").css("display", "none");
    });
}
/** end **/
