﻿var varwhats = "", varhttplink = "http:// share link";
var t = "0";
var isCatLoad = 0;
var selIn = 0;
var Isauthenticate = false;
var isTwit = 0;
// used for clear field after updates
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');
    //$("#txtUpdateText").val('');
    //$("#txtUpdateText").val(varwhats);
    wait_IsHide(true);

    //reset all hidden info.
    $("[id$='_hdnselected']").html('');
    $("[id$='_hdnselected']").val('');
    $("[id$='_hdnIsImgAtt']").val(false);
    $("#hdn").html('');
    $("#hdn").val('');
}
// clear data from web catch html objects (eq. attach url data)
function removeWebCatch() {
    try {
        if ($(".webcatch_Content").length) {
            $(".webcatch_Content").html('');
            $(".snap_Title").html("");
            $(".snap_Thumbs").html("");
            $(".snap_Subtitle").html("");
            $("#pagelet_composer").hide();
        }
    }
    catch (err) { }
}

// check the browser type
function getIEversion() {
    // Returns the version of Internet Explorer or a -1
    // (indicating the use of another browser).
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
// check browser type/version 
function checkVersionLocal() {
    var ver = getIEversion();
    if (ver == -1) {
        return false;
    }
    else
        return true;
}
// replace encry "Quote" to html form
function replaceQu(objStr) {
    objStr = objStr.replace(/\"/g, '\&quot;');
    objStr = objStr.replace(/\'/g, "\'");
    return objStr;
}
// used for the hide/show loader 
function wait_IsHide(ob) {
    if (ob)
        $("#imgWait").hide();
    else
        $("#imgWait").show();
}
// check the is HTML format is encrypted or not
function isEncHTML(str) {
    if (str.search(/&amp;/g) != -1 || str.search(/&lt;/g) != -1 || str.search(/&gt;/g) != -1)
        return true;
    else
        return false;
}
// If content is in encrption format then decrypt HTML contents
function decHTMLifEnc(str) {
    if (isEncHTML(str)) {
        return str.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/"\n"/g, "<br />").replace(/"\r"/g, "<br />");
    }
    return str;
}
// decrypt the string
function decr(str) {
    return str.replace(/"&lt;br \/&gt;"/g, " ");
}
// used for delay in xx seconds 
function sleep(usec) {
    var endtime = new Date().getTime() + usec;
    while (new Date().getTime() < endtime)
        ;
}
/// this function used to set temp text from update box
//function storeJsvar(UpdateText, txtUrl, loc, UIDs, uCatId, lblcatTxt, strattchtext, fbpost) 
function storeJsvar(UpdateText, txtUrl, loc, UIDs, r, u, uCatId, catchImg, isuploadCatch, strattchtext, fbpost) {
    //setValforUps(UpdateText, txtUrl, loc, UIDs, uCatId, lblcatTxt, strattchtext, fbpost);
    setValforUps(UpdateText, txtUrl, loc, UIDs, r, u, uCatId, catchImg, isuploadCatch, strattchtext, fbpost);
    return true;
}
// this function used to set value for update or post comment
//function setValforUps(UpdateText, txtUrl, loc, UIDs, uCatId, lblcatTxt, strattchtext, fbpost) 
function setValforUps(UpdateText, txtUrl, loc, UIDs, r, u, uCatId, catchImg, isuploadCatch, strattchtext, fbpost) {
    var serveURL = getBaseURL() + "Service/publicTM.asmx/setTempText";
    var IsSplUp = false;
    $.ajax({
        type: "POST",
        url: serveURL,
        //data: "{ UpdateText: \"" + UpdateText + "\" ,txtUrl : \"" + txtUrl + "\" ,loc: \"" + loc + "\" ,UIDs: \"" + UIDs + "\" ,RplID: \"" + RplID + "\",RplUsID: \"" + RplUsID + "\", uCatId : \"" + uCatId + "\",  catchimg: \"" + catchimg + "\" ,IsImgAttachment: \"" + IsImgAttachment + "\" , lblcatTxt: \"" + lblcatTxt + "\" ,strattchtext: \"" + strattchtext + "\",fbpost: \"" + fbpost + "\"}",
        data: "{ UpdateText : \"" + replaceQu(UpdateText).toString() + "\" ,txtUrl: \"" + replaceQu(txtUrl).toString() + "\" ,loc:\"" + loc.toString() + "\" ,IsSplUp:\"" + IsSplUp.toString() + "\" ,UIDs:\"" + UIDs.toString() + "\" , RplID:\"" + r.toString() + "\" , RplUsID:\"" + u.toString() + "\", UCatID:\"" + uCatId.toString() + "\",catchimg:\"" + catchImg.toString() + "\",IsImgAttachment:\"" + isuploadCatch.toString() + "\",attchtext:\"" + replaceQu(strattchtext.toString()) + "\",fbpost:\"" + fbpost + "\"}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            $(".osx").click();
        }
    });
}

//    function getValforUps() {
//        var serveURL = getBaseURL() + "Service/publicTM.asmx/getTempText";
//        $.ajax({
//            type: "POST",
//            url: serveURL,
//            data: "{ }",
//            contentType: "application/json; charset=utf-8",
//            dataType: "json",
//            success: function (msg) {
//                if (msg.d && msg.d != null && msg.d != "" && msg.d.UpdateText != "") {
//                    CallUpdateSer(msg.d.UpdateText, msg.d.txtUrl, msg.d.loc, false, msg.d.UIDs, msg.d.uCatId, msg.d.lblcatTxt, msg.d.strattachtext, msg.d.fbpost);
//                }
//            }
//        });
//    }

// this function used to send update via webservice
function CallUpdateSer(UpdateText, txtUrl, loc, IsSplUp, UIDs, uCatId, lblcatTxt, strattchtext, fbpost) {     
    if (isUploaded == 1)
    //$("#[id$='_btnimgBtnUpdateAll']").attr("disabled", "disabled");
        $("#imgBtnUpdateAll").attr("disabled", "disabled");
    //document.getElementById('btnimgBtnUpdateAll').disabled = true;    
    var v = new RegExp();
    v.compile("[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (txtUrl == '' && txtUrl == varhttplink) {
        alert("Please enter valid Link");
        wait_IsHide(true);
        return false;
    }
    if (UpdateText == 'Get started with your first update..')
        return false;
    UpdateText = UpdateText.replace(/^\s+|\s+$/g, "");
    var r = document.getElementById('hdReplyID').value.toString();
    var u = document.getElementById('hdRplUsID').value.toString();
    if (UpdateText != '' && UpdateText.length <= 3500) {
        if ($("#txtUpdateText").val() != "") {
        
            $("[id$='_LtstUp']").text(decHTMLifEnc($("#txtUpdateText").val()));
            $("[id$='_UpTime']").text("less than 1 seconds ago");
        }
        // change update url for drive thru option
        var serveURL = getBaseURL() + "Service/Def.asmx/UpdateStatus";
        var catchImg = "";
        if (checkVersionLocal()) {
            catchImg = $("[id$='_hdnselected']") != null ? $("[id$='_hdnselected']").val() : '';
        }
        else {
            catchImg = $("[id$='_hdnselected']") != null ? $("[id$='_hdnselected']").text() : '';
        }
        var isuploadCatch = $("[id$='_hdnIsImgAtt']") != null ? $("[id$='_hdnIsImgAtt']").val() : 'false';

        /// if is auth then allow to update
        if (Isauthenticate) {
            wait_IsHide(false);
            $.ajax({
                type: "POST",
                url: serveURL,
                data: "{ UpdateText : \"" + replaceQu(UpdateText).toString() + "\" ,txtUrl: \"" + replaceQu(txtUrl).toString() + "\" ,loc:\"" + loc.toString() + "\" ,IsSplUp:\"" + IsSplUp.toString() + "\" ,UIDs:\"" + UIDs.toString() + "\" , RplID:\"" + r.toString() + "\" , RplUsID:\"" + u.toString() + "\", UCatID:\"" + uCatId.toString() + "\",catchimg:\"" + catchImg.toString() + "\",IsImgAttachment:\"" + isuploadCatch.toString() + "\",attchtext:\"" + replaceQu(strattchtext.toString()) + "\",fbpost:\"" + fbpost + "\"}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {                    
                    if (msg.d != '' && msg.d != null) {
                        if (msg.d == "Error") {
                            alert("We are unable to connect to twitter with your current username and password. Please update your twitter username & password in account setting.");
                        }
                        $('#imgBtnUpdateAll').text("Update");
                        ind = 1; indRepConv = 1;
                        if (isTwit == 1) {
                            if (isUploaded == 1) {
                                $("[id$='_btnUpload']").click();
                                $("input[name=RemoveRow]").click();
                                sleep(2000);
                            }
                            //$("#hlnkTwit").click();
                            // call home tab if twitter is checked
                            //$("#LCat0").click();
                            $("#LCat" + selIn).click();
                        }
                        // facebook post
                        if (fbpost == 1) {
                            try {
                                if (isUploaded == 1) {
                                    $("[id$='_btnUpload']").click();
                                    $("input[name=RemoveRow]").click();
                                    sleep(2000);
                                }
                                $("#hlnkfb").click();
                            }
                            catch (err) { }
                        }
                        ind = 1; indRepConv = 1;
                        $('#' + upLbl).text(parseInt($('#' + upLbl).text()) + 1);
                        var flag = 0;
                        if (isTwit == 1 || fbpost == 1)
                            flag = 1;
                        if (flag != 1) {
                            if (isUploaded == 1) {
                                $("[id$='_btnUpload']").click();
                                $("input[name=RemoveRow]").click();
                                sleep(2000);
                                isUploaded = 0;
                            }
                            else {
                                if (!window.location.href.toLowerCase().lastIndexOf("favorites") > 0) {
                                    if (!($("#LCat" + selIn).is(":visible"))) {
                                        $("span#spncat" + selIn).show();
                                        $("#lblcat" + selIn).show();
                                        $("#LCat" + selIn).show();
                                    }
                                }
                                if (!(window.location.href.toLowerCase().lastIndexOf("replies") > 0 || window.location.href.toLowerCase().lastIndexOf("conversation") > 0))
                                    $("#LCat" + selIn).click();
                            }
                            if (window.location.href.toLowerCase().lastIndexOf("replies") > 0 || window.location.href.toLowerCase().lastIndexOf("conversation") > 0) {
                                var seltab = $("#container1-1").tabs().data('selected.tabs');
                                if (seltab == 0)
                                    $("#hlnkRep").click();
                                else
                                    $("#RepCon").click();
                                //GetReply_Convs();
                            }
                            else if (window.location.href.toLowerCase().lastIndexOf("search/q") > 0) {
                                getSrhResults();                                
                            }
                        }
                        else if (window.location.href.toLowerCase().lastIndexOf("search/q") > 0) {
                            getSrhResults();
                            getSrhResults();
                        }
                        /**** remove webcatch data ****/
                        removeWebCatch();
                        
                        if ($("#txtUpdateText").val() != "") {
                            $("[id$='_LtstUp']").text(decHTMLifEnc($("#txtUpdateText").val()));
                            $("[id$='_UpTime']").text("less than 1 seconds ago");
                        }
                        $("#txtUpdateText").val('');
                    }
                    else {
                        $("#clearQueueLink").click();
                        alert("Whoops ! you already said that.. Please post a new Update.");
                        removeWebCatch();
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    //document.getElementById("btnimgBtnUpdateAll").disabled = false;
                    //$("#[id$='_btnimgBtnUpdateAll']").removeAttr("disabled");
                    $("#imgBtnUpdateAll").removeAttr("disabled");
                    removeWebCatch();
                }
            });            
            //document.getElementById("btnimgBtnUpdateAll").disabled = false;
            //$("#[id$='_btnimgBtnUpdateAll']").removeAttr("disabled");
            $("#imgBtnUpdateAll").removeAttr("disabled");
            if ($("#upbxaddphoto").length > 0) {                
                var e = document.getElementById('content_imgbox');
                        e.style.display = 'none';              
            } 
            ClearFields();
            //replyToUserid remove after update send to timeline
            document.getElementById('hdReplyID').value = '0';
            document.getElementById('hdRplUsID').value = '0';
        }
        else {
            storeJsvar(replaceQu(UpdateText).toString(), replaceQu(txtUrl).toString(), loc.toString(), UIDs.toString(), r.toString(), u.toString(), uCatId.toString(), catchImg.toString(), isuploadCatch.toString(), replaceQu(strattchtext.toString()), fbpost);
        }
    }
}

// used to call async upload file
function UpdPanelUpdate() {
    __doPostBack($("[id$='_RadAsyncUpload1']"), 'OnClick');
}

//    /// this function used to call update after file uploads
function reloadPubs() {    
    if (isTwit && isTwit != 'undefined') {
        if (isTwit != 1) {
            if ($("[id$='_hdnCatIndex']") && $("[id$='_hdnCatIndex']").length > 0)
                $("#LCat" + $("[id$='_hdnCatIndex']").val()).click();
            else
                LoadData();
        }
    }
}
// document load function
function show() {
    $(".wait").show();
}
function showM() {     
    $("#imgWait").show();
}
//used for main top 10 updates 
function hide() {
    $(".wait").hide();
}
function hideM() {   
    $("#imgWait").hide();
}
function LoadTwitUpdate() {
    //$("#[id$='_btnRepMore']").css("display", "none");
    $(".moreUps_rep").css("display", "none");
    Isshow_loading(true);
    $.ajax({
        type: "POST",
        url: "Service/Def.asmx/GetTFeed", // get Twitter Feed
        data: "{ PageIndex : 1}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            if (msg != null) {
                document.getElementById('MchildDiv').innerHTML = "";
                if (document.getElementById("divDynaRep") != null)
                    document.getElementById("divDynaRep").innerHtml = "";
                if (msg.d.HtmlStream != "")
                    document.getElementById('MchildDiv').innerHTML = msg.d.HtmlStream;
                $('div#MchildDiv').children().slideDown();
                if (msg.d.IsShow)
                    $(".moreUps_rep").show('slow', function () {
                        $(this).css("display", "inline");
                    });
                //$("#[id$='_btnRepMore']").css("display", "none");
                else {
                    //$("#[id$='_btnRepMore']").css("display", "");
                    $(".moreUps_rep").hide();
                }
                // ClearFields();
                if (msg.d.HtmlStream == "") {
                    $("#twitterHng").show();
                    $("#divreld").show();
                }
                else {
                    $("#twitterHng").hide();
                    $("#divreld").hide();
                }
                //$("#container-1").tabs({ selected: 1 });
                var index = $('#container-1 a[href="#ReplyConv"]').parent().index();
                $('#container-1').tabs('select', index);
                ClearFields();
                Isshow_loading(false);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            Isshow_loading(false);
        }
    });
}
// get facebook wall update 
function LoadFBUpdate(ismore) {
    if (ismore) {
        if (document.getElementById('Img_fbwait') != null)
            document.getElementById('Img_fbwait').style.display = '';
    }
    Isshow_loading(true);
    document.getElementById('btnFBmore').style.display = "none";
    $.ajax({
        type: "POST",
        url: "Service/Fb.asmx/GetHmPost", // get Twitter Feed
        data: "{ Ismore : " + ismore + " }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            Isshow_loading(false);
            if (msg != null && msg.d) {
                if (msg.d.HtmlStream != "") {
                    if (ismore) {
                        try {
                            var dynDiv = document.createElement("div");
                            dynDiv.id = "divFBDyna";
                            dynDiv.innerHTML = msg.d.HtmlStream;
                            document.getElementById('divFacebook').appendChild(dynDiv);
                        }
                        catch (err) { }
                    }
                    else {
                        if (document.getElementById('divFacebookChild') != null) {
                            document.getElementById('divFacebookChild').innerHTML = "";
                            document.getElementById('divFacebookChild').innerHTML = msg.d.HtmlStream;
                        }
                    }
                    bindFacebookFeed();
                    $('div#divFacebookChild').children().slideDown();
                    if (document.getElementById('Img_fbwait') != null)
                        document.getElementById('Img_fbwait').style.display = 'none';
                }
                if (!msg.d.IsShow)
                    document.getElementById('btnFBmore').style.display = "none";
                else
                    document.getElementById('btnFBmore').style.display = "";
                ClearFields();                
                hideM();
            }
            else {
                document.getElementById('btnFBmore').style.display = "none";
                if (document.getElementById('Img_fbwait') != null)
                    document.getElementById('Img_fbwait').style.display = 'none';
                ClearFields();
                Isshow_loading(false);
            }

            Isshow_loading(false);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            if (document.getElementById('Img_fbwait') != null)
                document.getElementById('Img_fbwait').style.display = 'none';
            document.getElementById('btnFBmore').style.display = "none";
            Isshow_loading(false);
        }
    });
}
// end facebook wall update
$(document).ready(function () {
    $("#hlnkTwit").click(function () {
        if ($("#[id$='_lblTFeed']").is(":Visible")) {
            Isshow_loading(true);
            showM();
            LoadTwitUpdate();
        }
    });
    //get facebook update on Feed butoon click
    $("#hlnkfb").click(function () {
        if ($("[id$='_lblFacebook']").is(":Visible")) {
            Isshow_loading(true);
            showM();
            LoadFBUpdate(false);
        }
    });
    //    $("#hlnkRep").click(function () { ReplyUps(); });
    //    $("#RepCon").click(function () { ReplyConvLoad(); });
    
    var varupt = $("#txtUpdateText").length > 0 ? $("#txtUpdateText").val() : "";
    //    if (!Isauthenticate) {
    //        $(".flt").hide(); $("#divltst").hide(); 
    //    }
    //    else { $(".flt").show(); $("#divltst").show(); }

    //    if (!Isauthenticate) { $(".update_optation").hide(); }
    //    else { $(".update_optation").show(); }

    /**** hide show add show add photo div ***/
    //    if (!Isauthenticate) {
    //        try {
    //        if ($(".add_photo").length > 0)
    //            $(".add_photo").hide();
    //        }
    //        catch (err) { }
    //    }
    //    else {
    //        try {
    //            $(".add_photo").show();
    //        } 
    //        catch (err) { }
    //    }
    /**** End ****/

    if (window.location.href.indexOf("search/") > 0) {
        $("#imgBtnUpdateAll").attr("src", "../images/btn_update.png");
        $("#imgmorelve").attr("src", "../images/loading.gif");
        $("#imgmore").attr("src", "../images/loading.gif");
    }
    
    if (escape(window.location.href.indexOf("?status=%40")) <= 0) {
        if (varupt.indexOf("@") == -1) {
            $("#txtUpdateText").val(varwhats);
            $("#txtUpdateText").addClass("txtup");
        }
        else
            $("#txtUpdateText").css('color', 'black');
    }
    else {
        setCaretToPos(document.getElementById('txtUpdateText'), document.getElementById('txtUpdateText').value.length + 1);
        $("#txtUpdateText").css('color', 'black');
    }
    $("#txtUpdateText").click(function () {
        $(this).css("height", "87px");
        if ($.trim($(this).val()) == varwhats) {
            $(this).val('');
            $(this).removeClass('txtup');
        }
    });
    //$("#txtUrl")
    $("#[id$='_txtUrl']").focus(function () {
        if ($.trim($(this).val()) == varhttplink) {
            $(this).val('');
            $(this).removeClass('txtup');
        }
    });
    $("#[id$='_txtUrl']").keyup(function (evt) {
        var code = (evt.keyCode ? evt.keyCode : evt.which);
        if (code == "13")
            $("#btnattach").click();
    });
    $(".water").focus(function () {
        if ($(this).val() == this.defaultValue) {
            $(this).val("");
            $(this).removeClass("water");
        }
    });
    $(".water").blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).val(this.defaultValue); $(this).addClass("water");
        }
    });
    //    $(".Upwater").focus(function () {
    //        if (this.defaultValue == "Get started with your first update..") {
    //            if ($(this).val() == this.defaultValue) {
    //                $(this).val("");
    //                $(this).removeClass("Upwater");
    //            }
    //        }
    //    });
    //    $(".Upwater").blur(function () {
    //        if ($.trim($(this).val()) == "") {
    //            if (t == "0") {
    //                $(this).val(this.defaultValue); $(this).addClass("Upwater");
    //            }
    //        }
    //    });
    $("#txtUpdateText").focus(function () {        
        $("#divPop").css("display", "none");
        $(this).removeClass('txtup');
        $(this).css("height", "87px");
    });
    $("#txtUpdateText").blur(function () {
        if ($.trim($(this).val()) == varwhats) {
            $(this).addClass('txtup');
            //$(this).css("height", "50px");
        }
    });
    // event is used to send update to ogoing    
    $("#imgBtnUpdateAll").click(function () {
        // if (Isauthenticate) {
        if ($.trim($("#txtUpdateText").val()) == varwhats) {
            return false;
        }
        if ($("#txtUpdateText").val().replace("'", "\'") == '') {
            $("#txtUpdateText").focus();
            return false;
        }
        else {
            // hide attached link button 
            $("#btnattach").css("display", "none");
            $("#txtUpdateText").focus();
            var UpdateText, txtUrl, loc, UIDs = "", uCatId;
            // reset special update
            issp = false;
            isTwit = 0;
            UpdateText = $("#txtUpdateText").val().replace("'", "\'");
            //txtUrl = $("#txtUrl").val().replace("'", "\'");
            txtUrl = $.trim($("#[id$='_txtUrl']").val().replace("'", "\'"));
            //remove ddlSpecialUpdate selectedIndex value => loc = 2;            
            loc = document.getElementById('ddlSpecialUpdate').options[document.getElementById('ddlSpecialUpdate').selectedIndex].value;
            var ddlcat = 'ddlCategory';
            var rdlcat = 'rdlCategory';
            try {
                if (ddlcat && ddlcat != null && varIsSubPortal.toLowerCase() === "true") {
                    uCatId = document.getElementById(ddlcat).options[document.getElementById(ddlcat).selectedIndex].value;
                    selIn = document.getElementById(ddlcat).selectedIndex;
                    lblcatTxt = document.getElementById(ddlcat).options[document.getElementById(ddlcat).selectedIndex].text;
                }
                else if ($("[id$='_" + rdlcat + "']") && $("[id$='_" + rdlcat + "']") != null) {
                    uCatId = $("[id$='_" + rdlcat + "'] :checked").val();
                    // added +1 for the selected perticular category on update sent.
                    selIn = parseInt($("[id$='_" + rdlcat + "'] :checked").attr("ID").substring($("[id$='_" + rdlcat + "'] :checked").attr("ID").lastIndexOf("_") + 1)) + 1;
                    lblcatTxt = $("[id$='_" + rdlcat + "'] :checked").next().text();
                }
                // Selected index set to 1 if it 0 and not subportal to reset service index
                if ((selIn === 0 || selIn === -1) && varIsSubPortal.toLowerCase() != "true")
                    selIn = 1;
                if (lblcatTxt === undefined || lblcatTxt === "")
                    lblcatTxt = "home";
            }
            catch (err) { }
            //set the active index
            $("[id$='_hdnCatIndex']").val(selIn);
            isCatLoad = parseInt(selIn);
            /**** get checkbox value for social checkboxes ***/
            if ($("#[id$='_chktw']") != null) {
                /******** new placed twitter checkbox ***********/
                //    for (i = 0; i < 1; i++) {
                //        if ($("#[id$='_chktw" + "_" + i + "']") != null && $("#[id$='_chktw" + "_" + i + "']").checked) {
                //            UIDs += ',' + $("#[id$='_chktw" + "_" + i + "']").parentNode.attributes["mainValue"].value;
                //            if (i == 0) {
                //                if ($('#imgTwit').length != 0) {
                //                    isTwit = 1;
                //                }
                //            }
                //        }
                //    }
                isTwit = $("#[id$='_chktw']").attr("checked");
                if (isTwit == 1) {
                    UIDs = "0";
                }
            }
            var fbpost = false;
            try {
                fbpost = $("#[id$='_chkFB']").attr("checked");
            }
            catch (err) {
                fbpost = false;
            }

            //           
            //            try {
            //                if ($("#[id$='_chkFB" + "_" + 0 + "']") && $("#[id$='_chkFB" + "_" + 0 + "']").length > 0) {
            //                    for (i = 0; i < 1; i++) {
            //                        if ($("#[id$='_chkFB" + "_" + i + "']") != null && $("#[id$='_chkFB" + "_" + i + "']").checked) {
            //                            fbpost = true;
            //                        }
            //                    }
            //                }
            //            }
            //            catch (err) {
            //                fbpost = false;
            //            }

            /*** end ****/
            /** add webcather details ***/
            var strattchtext = "";
            if ($("#pagelet_composer").is(":visible")) {
                strattchtext = " <br /> " + ($(".snap_Title").html() != null ? $(".snap_Title").html().replace("'", "\'") : "") + "  <br /> " + ($(".snap_Subtitle").html() != null ? $(".snap_Subtitle").html().replace("'", "\'") : "");
            }
            if (txtUrl.toLowerCase() === 'add link http://' || txtUrl.toLowerCase() === 'http:// share link')
                txtUrl = "";
            if (issp == true) {
                CallUpdateSer(UpdateText, txtUrl, loc, true, UIDs, uCatId, lblcatTxt, strattchtext, fbpost);
            }
            else {
                CallUpdateSer(UpdateText, txtUrl, loc, false, UIDs, uCatId, lblcatTxt, strattchtext, fbpost);
            }
            return false;
        }
        //}
        //        else {
        //            storeJsvar();
        //            $(".osx").click();
        //        }
    });


    $("#signin").click(function () {
        $(".simplemodal-close").click();
        $("[id$='_A6']").click();
    });
    $("#signup").click(function () {
        location.href = "joinogoing";
    });

    /******** Used for Drive thru popup ************/
    $('#drvthru').click(function () {
        clrDriveThru();
        $(".simplemodal-close").click();
        $(".overlayOuter_driveThru").fadeIn(300);
        $("[id$='_txtpostfullname']").focus();
    });
    $(".ogo-dialog-close_driveThru").click(function () {
        $(".overlayOuter_driveThru").fadeOut(300);
    });
    //    $("#btnpostupdate").click(function () {
    //        alert($("#txtpostfullname").val() + ',' + $("#txtpostcompanyname").val()
    //        + ',' + $("#txtpostcompemail").val() + ',' + $("#txtpostweburl").val()
    //        + ',' + $("#txtpostlocation").val() + ',' + $("#txtpostupdate").val());
    //        return false;
    //    });

    $('a#btn_drvth').click(function () {
        try {
            if ($(".overlayOuter_driveThru").length > 0) {
                clrDriveThru();
                $(".overlayOuter_driveThru").fadeIn(300);
                if ($("[id$='_txtpostfullname']").length > 0)
                    $("[id$='_txtpostfullname']").focus();
            }
        }
        catch (err) { }
    });
});
// clear the drive thru elements
function clrDriveThru() {
    $("#txtpostfullname").val('');
    $("#txtpostcompanyname").val('');
    $("#txtpostcompemail").val('');
    $("#txtpostweburl").val('');
    $("#txtpostlocation").val('');
    $("#txtpostupdate").val('');
}
function setSelectionRange(input, selectionStart, selectionEnd) {
    if (input.setSelectionRange) {
        input.focus();
        input.setSelectionRange(selectionStart, selectionEnd);
    }
    else if (input.createTextRange) {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveEnd('character', selectionEnd);
        range.moveStart('character', selectionStart);
        range.select();
    }
}
function setCaretToPos(input, pos) {
    setSelectionRange(input, pos, pos);
}
