﻿
var _RecvUserDetails = null;
var arrViewProfile = null;
var newMsgArray = null;
var newMsgGUID = null;
var newMsgType = null;
var newMessageID = null;
var newMessageChainID = null;
var _allcookies = document.cookie;
var CookieGUIDValue = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
var dateJsonBit = null;
var newMsgTime = 20000;
var newChatTime = 10000;
var ChainID = '';
var responderGUID = '';
var NotCheckStatus = false;
//if(_allcookies!="")"
//{ 
//    var _pos = _allcookies.indexOf("Login");
//    if(_pos !=-1)
//    {
//        var _jj=document.cookie.substring(_pos, document.cookie.length);
//         if(_jj!="")
//         {
//           CookieGUIDValue =_jj.substring(_jj.indexOf('=')+1,_jj.length); 
//         }
//    }
CookieGUIDValue = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
//}
function ShowMessageChainBox(arrMsgChainDetail) {

    if (arrMsgChainDetail != null) {
        if (arrMsgChainDetail != null) {
            //arrViewProfile = arrMsgChainDetail["SenderUserDetail"];
            $("#MessageCreateDateDiv").html(arrMsgChainDetail.MessageCreateDate);

            var divString = "<div style='width:400px;'>"
                            + "<div class='msg_heading' style='height:30px;padding-top:14px;padding-bottom:0px;text-align:left'>" + arrMsgChainDetail.MessageTitle + "</div>"
                            + "<div style='height:33px;'>"
                            + "<div class='float'><img src='../Images/messages/delete.png' /></div>"
                            + "<div class='float' style='float:right;'><img class='jqModal' style='cursor:pointer' onclick=javascript:ShowProfile();  src='../Images/messages/view_profile.png' /></div>"
                            + "</div>"
                            + "<div style='clear:both;height:33px;'>"
                            + "<div class='float'><img src='../Images/messages/block.png' /></div>"
                            + "<div class='float' style='float:right;'><img src='../Images/messages/reply.png' class='jqModal' style='cursor:pointer' onclick=javascript:ShowMessageReplyDiv('dialog','" + ChainID + "','" + arrMsgChainDetail.MessageType + "','" + generateGuid() + "','Reply'); /></div>"
                            + "</div>"
                            + "<div style='clear:both;float:right;'>"
                            + "<div class='float'><img src='../Images/HomePage/Request-a-date.png' class='jqModal' style='cursor:pointer' onclick=javascript:ShowMessageReplyDiv('dialog','" + ChainID + "','" + arrMsgChainDetail.MessageType + "','" + generateGuid() + "','Date'); /></div>"
                            + "</div>"
                            + "</div>";
            $("#MessageDetaildiv").empty();
            var totLeft;
            totLeft = $(".main_content").offset().left + 264;
            $("#MessageDetaildiv").css({ left: totLeft + "px", top: "140px" });
            //         $("#dialog").css({left:"415px",top:"140px"});
            $("#MessageDetaildiv").append(divString);

        }
    }
}
function ReplyDateMessage(dialog, newMessageChainID, MessageDiv, ProfileGuid) {
    clearTimeout(currentVideoProcessid);
    //$("object").remove();    
    AcceptDeclineDate(CookieGUIDValue, 'false', newMsgGUID, 'cancel', 'responder', responderGUID, 'ReplyDateMessage', dialog, newMessageChainID, MessageDiv, ProfileGuid);

}
function ShowProfile(MessageGUID,id)
 {
    var imgStr = '';
    var strSendMessage = '';
    var strCloseClick = '';
    if ($.trim(newMsgType).toLowerCase() == "date") {
     //   ChangeMessageStatus(MessageGUID, 'Skipped');
        //strSendMessage = "class='RecMsgDtNameRedbar' style='top:-1px;opacity:0.5;filter:alpha(opacity=50);'> " + newMsgArray.UserDetail.ProfileTitle + ' has sent you a date request &nbsp';
        strSendMessage = "class='RecMsgNameRedbar'  style='top:-1px;width:621px;position:absolute;left:0px;_left:-2px;'> " + newMsgArray.UserDetail.ProfileTitle + ' has sent you a date request &nbsp';
        strCloseClick = "AcceptDeclineDate('" + CookieGUIDValue + "','false','" + newMsgGUID + "','cancel','responder','" + responderGUID + "')";
        $("#btnContact").hide('fast');
        $("#btnConnect").show('fast');
    }
    else {
        ChangeMessageStatus("'" + MessageGUID + "','Skipped'");
        strCloseClick = "ChangeMessageStatus('" + MessageGUID + "','Skipped')";
        strSendMessage = "class='RecMsgNameRedbar' style='top:-1px;width:621px;' >" + newMsgArray.UserDetail.ProfileTitle + ' has sent you a message';
        $("#btnConnect").hide('fast');
        $("#btnContact").show('fast');
    }

    //    <div id="divplayprofile"  class="play_profile_btn" >
    //                    <img id="btnplayprofile" class="CursorPointer"  src="/images/RecordProfile/playprofile.png"/>
    //                  </div>
    //                  

    var dialogString = ""  //<div class='Messagerep_l'  ///+ "<div class='header_rep'>"
              + "<div id='divNewMessageAlert' style='position:relative;width:650px;'>"                   
              + "<div id='divNewmessageRedbar' " + strSendMessage + " </div>"
              + "<div id='messagevideodiv' style='left:0px;padding-top:0px;padding-left:1px;' class='img_rep' >" + "<img src='" + siteURL + "Photo/Messages/" + newMsgGUID + ".jpeg' height='480px' width='640px'/>"
              + "</div>"
              + "<div class='play_message_btn' id='divPlayMessage'> "
              + "<div style='float:left' class ='playprofile_bg' id='btnplaymessage'></div>"
              +"<div style='float:left' ><img id='btnSlider'  src='/images/homePage/slider.png' /></div>"
              +"<div style='float:left' class ='FullScreenProfile_bg' id='btnFullScreenMessage'></div>"
              +"<div style='float:left' class ='ShareProfile_bg' id='btnShareMessage'></div> "
              //+ " <img id='btnplaymessage' class='CursorPointer'src='../images/RecordProfile/playprofile.png'/>"
              + "</div>"
              + "<div class='height_m clear font-size'></div>"
              + "<div class='clear rep_btn'>"
              +"<div class='height_5 clear font-size'></div>"
              + "</div>"
              + "</div>";
            
    $("#MessageDiv1").empty();
    $("#MessageDiv").empty();
    
    $("#divlogin").empty();
    $("#divlogin").append(dialogString);
    
    clearTimeout(currentVideoProcessid);
    $('#divVideo').hide('fast');
    $("#divlogin").show('fast');  
   
    $("#divProfileButtons").hide('fast');
    $("#divUnblockButtons").hide('fast');
    $("#divMessageButtons").show('fast');  
    
    if ($.trim(newMsgType).toLowerCase() == "date") {
        
        $("#btnContact").hide('fast');
        $("#btnConnect").show('fast');
        
        $("#btnConnect").unbind("click");
        $("#btnConnect").bind("click", function(e)
        {
             $("#divlogin").empty();
             $("#divlogin").hide('fast');
            ChangeMessageStatus(MessageGUID, 'Viewed');
            ShowcurrentProfileDetail();           
            AcceptDeclineDate(CookieGUIDValue,'true',newMsgGUID,'accept','responder',responderGUID);           
            
    });
     }
     else
     {
        $("#btnConnect").hide('fast');
        $("#btnContact").show('fast');
        $("#btnContact").unbind("click");
        $("#btnContact").bind("click", function(e)
        {
             $("#divlogin").empty();
             $("#divlogin").html('');
             ShowcurrentProfileDetail();
             ReplyMessage(MessageGUID ,'divOverlay',newMessageChainID,'MessageDiv',ProfileGuid);
    });
     }
        var ProfileGuid = newMsgArray.ProfileGuid;
        var ProfileTitle= newMsgArray.UserDetail.ProfileTitle;
        $("#divProfileTitle").html(addSpacesInString(newMsgArray.UserDetail.ProfileTitle,11));
        $("#divAge").html("Age: "+ newMsgArray.UserDetail.Age);
        $("#divCity").html("City: "+ setLength(newMsgArray.UserDetail.City,19));
        $("#divState").html("State: "+ setLength(newMsgArray.UserDetail.State,18));
        $("#divCountry").html("Country: "+ setLength(newMsgArray.UserDetail.Country,16));
        $("#divTags").html("Tagged: "+ replace(replace(setLength(addSpacesInString(newMsgArray.UserDetail.ProfileTag,15),33),', ...','...'),',...','...'));
        $("#divJoined").html("Joined: " + newMsgArray.CreatedDateStr);
        //$("#divResponseRate").html("Responds to: " + newMsgArray.UserResponseRate + "%");
        $("#divResponseRate").html("" );
        $("#divLastOnline").html("Last online: "+ newMsgArray.LastOnline);
        var gender= newMsgArray.UserGender;
        var category= newMsgArray.MemberCategory;
        var w2mMen= newMsgArray.Want2MeetMen;
        w2mMen= w2mMen== true ? "Men" : "f";
        var w2mWomen= newMsgArray.Want2MeetWomen;
        w2mWomen= w2mWomen == true ? "Women" : "f";
        var w2m  = w2mMen=="f"?(w2mWomen=="f"?"":w2mWomen):(w2mWomen=="f"?w2mMen:w2mMen+"/"+w2mWomen);
        $("#divProfileCreateDate").html(ConvertProperCaseSentence(gender + " seeking " + w2m + " for "+ category));
  
    $.ifixpng('../Images/HomePage/pixel.gif');
    $('img[src$=.png]').ifixpng();
    $('input[src$=.png]').ifixpng();

    $("#btnplaymessage").unbind("click");
    $("#btnplaymessage").bind("click", function(e) {
        $("#divNewmessageRedbar").hide('fast');
        $("#divPlayMessage").hide('fast');
        if ($("#object").length == 0) {
            var uid = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
            ChangeMessageStatus(newMsgGUID, 'Viewed');
            playMessageVideo(newMsgGUID, false, uid, "messagevideodiv", 'true', 'false', 'false');
        }
        else {
            $("#messagevideodiv").show("fast");
        }
    });

    //neha 27th Jan 2010
    $("#btnFullScreenMessage").unbind("click");
    $("#btnFullScreenMessage").bind("click", function(e) {
        $("#divNewmessageRedbar").hide('fast');
        $("#divPlayMessage").hide('fast');
        if ($("#object").length == 0) {
            var uid = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
            ChangeMessageStatus(newMsgGUID, 'Viewed');
            playMessageVideo(newMsgGUID, false, uid, "messagevideodiv", 'false', 'true', 'false');
        }
        else {
            $("#messagevideodiv").show("fast");
        }
    });
    $("#btnShareMessage").unbind("click");
    $("#btnShareMessage").bind("click", function(e) {
        $("#divNewmessageRedbar").hide('fast');
        $("#divPlayMessage").hide('fast');
        if ($("#object").length == 0) {
            var uid = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
            ChangeMessageStatus(newMsgGUID, 'Viewed');
            playMessageVideo(newMsgGUID, false, uid, "messagevideodiv", 'false', 'false', 'true');
        }
        else {
            $("#messagevideodiv").show("fast");
        }
    });
    $("#btnSkip").unbind("click");
    $("#btnSkip").bind("click", function(e) {
    ChangeMessageStatus(MessageGUID, 'Skipped');
    if ($.trim(newMsgType).toLowerCase() == "date")
    {
         AcceptDeclineDate(CookieGUIDValue,'false',newMsgGUID,'cancel','responder',responderGUID);
    }
    });
    $("#btnBlock").unbind("click");
    $("#btnBlock").bind("click", function(e) {
    $("object").remove();
      ChangeMessageStatus(MessageGUID, 'Viewed');
      var userguid = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
       SaveBlockUser(userguid,ProfileGuid,ProfileTitle,id);
       $("#divlogin").empty();
       $("#divlogin").html('');
    });     
    newMsgArray=null;
    $.ifixpng('../Images/HomePage/pixel.gif');
    $('img[src$=.png]').ifixpng();
    $('input[src$=.png]').ifixpng();

    //    setTimeout(function(){
    //    var uid=GetCookie("Login")==null?"":GetCookie("Login");
    //    playMessageVideo(newMsgGUID,false,uid,"messagevideodiv");
    //    },1000);

    //     if(newMsgType == "Date")
    //    {
    //           $("#dialog #sendMsgBtn").attr('src','../Images/Decline-button.png');
    //           $("#dialog #rqstDateBtn").attr('src','../Images/Accept-chat-invitation.png');
    //           $("#dialog #sendMsgA").removeAttr('onclick');
    //           $("#dialog #rqstDateA").removeAttr('onclick');
    //           $("#dialog #sendMsgBtn").attr('onclick',"Javascript:AcceptDeclineDate('"+CookieGUIDValue+"','false','"+newMsgGUID+"','cancel','responder','"+responderGUID+"')");
    //           $("#dialog #rqstDateBtn").attr('onclick',"Javascript:AcceptDeclineDate('"+CookieGUIDValue+"','true','"+newMsgGUID+"','accept','responder','"+responderGUID+"')");
    //    }
    //    else if(newMsgType == "Message")
    //    {
    //           $("#dialog #sendMsgBtn").attr('src','/Images/messages/reply.png');
    //           $("#dialog #sendMsgA").removeAttr('onclick');//alert(newMessageChainID);
    //           $("#dialog #sendMsgBtn").attr('onclick',"javascript:ShowMessageReplyDiv('dialog','"+newMessageChainID+"','Message','"+generateGuid()+"','Reply')");                          
    //    }   
}
function CloseMessageAlert() {
    $('#dialog').jqmHide();
    clearTimeout(currentVideoProcessid);
    $("object").remove();
}

function ReplyMessage(MessageGUID, dialog, newMessageChainID, MessageDiv, ProfileGuid) {
   
    try {
        clearTimeout(currentVideoProcessid);
        $("object").remove();
        var uid = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login');
        var MessageStatus = "viewed";
        var itemID = { "MessageGUID": MessageGUID, "MessageStatus": MessageStatus, "UserGUID" : uid };
        var jsonStr = JSON.stringify(itemID);
        // Call our Web Service, passing in our JSON params. The error function is called  
        // whenever an exception is thrown by the web service (among other times)  
        $.ajax({
            type: "POST",
            url: "/Default.aspx/UpdateMessage",
            data: jsonStr,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                var JObject = eval('(' + msg.d + ')');
                if (JObject.toLowerCase() == "ok" && MessageStatus.toLowerCase() == "viewed") {
                    //$("#dialogRedStrip").jqmHide();
                    ShowSendAMessage(dialog, newMessageChainID, MessageDiv, ProfileGuid);
                }
                newMsgArray = null;
            },
            error: function(xhr, msg) {

                var response = JSON.parse(xhr.responseText);

                return false;
            }
        });
        return false;
    }
    catch (err) {
    }

    //ChangeMessageStatus(MessageGUID,'Viewed'); 

}

//function to close dialog box
function HideDialogBox() {
    try {
        $("#dialog").jqmHide();
    }
    catch (err) {
    }
}

//function to close chat window
function HideChatBox() {
    try {
        $("#dialogChat").jqmHide();

    }
    catch (err) {
    }
}
//Fonction to show Message/Reply div
//DivType for  Reply or Date
function ShowMessageReplyDiv(dialogDivID, MessageChainID, MessageType, MessageGUID, DivType) {

    ShowSendAMessage(dialogDivID, MessageChainID, MessageType, MessageGUID, 'Message', 'MessageDiv');
    if (DivType == 'Reply') {
        $("#divSend").html("Reply a message");
        var btn = document.getElementById("btnImg");
        btn.src = '../Images/messages/reply.png';
    }
}


function IsActiveSession() {

    setTimeout(IsActiveSession, 60000);
    //var uid= GetCookie("Login");  
    //            var itemID= {"UserGuid" : "uid"};  
    var itemID = {};
    var retvalue;
    var jsonStr = JSON.stringify(itemID);
    // alert("IsActiveSession:" + uid );
    $.ajax({
        type: "POST",
        url: "Default.aspx/ISActiveSession",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            retvalue = eval('(' + msg.d + ')');
            //             alert(retvalue);
            SessionActive = retvalue;
            SetLoginLogOutDivVaribles();
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
        }
    });
    return retvalue;
}


//To check Message recevied or not and save it in array
function IsMesageReceived(UserProfileID) {
         
    if (newMsgArray != null) {
        setTimeout("IsMesageReceived('" + UserProfileID + "')", newMsgTime);
        return false;
    }
    var itemID = { "UserGUID": UserProfileID };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
    $.ajax({
        type: "POST",
        url: "/Default.aspx/GetNewMessages",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            if (msg.d == "") 
                return;
            var JObject = eval('(' + msg.d + ')');
            if (JObject != null && JObject.length > 0) {
                newMsgArray = JObject[0]["SenderUserDetail"];
                // alert("IsMessageRecv");
                newMsgGUID = JObject[0].MessageGUID;
                newMsgType = JObject[0].MessageDateType;
                newMessageID = JObject[0].MessageID;
                arrViewProfile = JObject[0]["SenderUserDetail"];
                responderGUID = JObject[0]["SenderUserDetail"].ProfileGuid;
                newMessageChainID = JObject[0]["MessageChainID"].MessageChainID;

                ///DJ: Shifted in different method in messages.js
                //           var UnreadMessage=JObject[0].MessageStayTime;           
                //           if(UnreadMessage>0)
                //           {
                //            document.getElementById("divMsgCnt").innerHTML =  '&nbsp;('+UnreadMessage +')';
                //           }
            }
        },
        error: function(xhr, msg) {

            var response = JSON.parse(xhr.responseText);


        }
    });
    setTimeout("IsMesageReceived('" + UserProfileID + "')", newMsgTime);
    return false;
}
function ShowNewMessageCount(UserProfileID) {
    var itemID = { "UserGUID": UserProfileID };
    var jsonStr = JSON.stringify(itemID);
    
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
    $.ajax({
        type: "POST",
        url: "/Default.aspx/GetNewMessagesCount",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            if (msg.d == "") return;
            var JObject = eval('(' + msg.d + ')');
            if (JObject != null && JObject.length > 0) {
                var UnreadMessage = JObject;
                if (UnreadMessage > 0) {
                    document.getElementById("divMsgCnt").innerHTML = '&nbsp;(' + UnreadMessage + ')';
                    var len = JObject.length;
                    len = len * 9;
                    var wid = len + 50;
                    $("#divInboxHover").css({ width: wid + "px" });
                    if (window.location.href.toLowerCase().indexOf('messageslist.aspx') > 0 || window.location.href.toLowerCase().indexOf('messageview.aspx') > 0)
                        $("#divInboxHover").show('fast');
                    //  SetHover(UnreadMessage);
                }
                else {
                    document.getElementById("divMsgCnt").innerHTML = '';
                    $("#divInboxHover").css({ width: 40 + "px" });
                    if (window.location.href.toLowerCase().indexOf('messageslist.aspx') > 0 || window.location.href.toLowerCase().indexOf('messageview.aspx') > 0)
                        $("#divInboxHover").show('fast');
                }
            }
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
        }
    });
    setTimeout("ShowNewMessageCount('" + UserProfileID + "')", newMsgTime);
    return false;
}
function SetHover(UserProfileID) {
    if ($("#divOverlay").is(":visible")) {
        $("#divInboxHover").hide('fast');
        setTimeout("SetHover('" + UserProfileID + "')", 10000);
        return;
    }
    
    var itemID = { "UserGUID": UserProfileID };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)  
    $.ajax({
        type: "POST",
        url: "/Default.aspx/GetNewMessagesCount",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            
            if (JObject != null && JObject.length > 0 && JObject > 0) {
                 //if (UnreadMessage > 0) {
                 //document.getElementById("divMsgCnt").innerHTML = '&nbsp;(' + UnreadMessage + ')';
                 
                 var len=JObject.length;
                 len=len*9;
                 var wid= len + 50;
                 $("#divInboxHover").css({ width: wid + "px" });
                 
                 $("#divInboxHover").show('fast');
                //}
            }
            else
            {
                $("#divInboxHover").css({width:"39px"});
                $("#divInboxHover").show('fast');
            }
            
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
        }
        
    });
    setTimeout("SetHover('" + UserProfileID + "')",10000);
    return false;
}
//function SetHover(msgcount)
//{
//  var len=msgcount.length;
//  len=len*9;
//  var wid= len + 50;
//  $("#divInboxHover").css({width:wid+"px"});
//}
function ShowMessageViewStrip(MessageGUID) {
    var totLeft;
    try {
        $("#MessageDiv1").empty(); $("#MessageDiv").empty();

        if ($.trim(newMsgType).toLowerCase() == "date") {
            var ResultString = "<div style='width: 672px; height: 587px;'><div style='cursor:pointer;left:2px;position:absolute;top:140px;' class='resultMsg2' onclick=Javascript:ChangeMessageStatus('" + MessageGUID + "','Viewed'); >"
                                    + "<center>"
                                    + "<div style='font-size:18px;padding-bottom:10px;'>Someone wants to talk to you!</div>"
                                    + "<div style='height:30px;padding-bottom:4px'>Click to play their message</div>"
                                    + "</center>"
                                    + "</div></div>";
            $("object").remove();
            $("#dialogRedStrip").empty();
            $("#dialogRedStrip").append(ResultString);
            totLeft = $(".main_content").offset().left + 138;
            $("#dialogRedStrip").css({ left: totLeft + "px", top: "135px" });
            $("#dialogRedStrip").jqmShow();
        }
        else {
            var ResultString = "<div style='width: 672px; height: 587px;'><div style='cursor:pointer;left:2px;position:absolute;top:140px;' class='resultMsg2'>"
                                    + "<center>"

                                    + "<div style='font-size:18px;padding-bottom:10px;'>There is a message for you!</div>"
                                    + "<div style='height:30px;padding-bottom:4px'><img src='../Images/Skip-button.png' ' alt='Skip' style='cursor:pointer' onclick=Javascript:ChangeMessageStatus('" + MessageGUID + "','Skipped') >&nbsp;<img src='../Images/View-button.png' style='cursor:pointer' onclick=Javascript:ChangeMessageStatus('" + MessageGUID + "','Viewed'); alt='View'></div>"
                                    + "</center>"


                                    + "</div></div>";
            $("#dialogRedStrip").empty();
            $("#dialogRedStrip").append(ResultString);
            totLeft = $(".main_content").offset().left + 138;
            $("#dialogRedStrip").css({ left: totLeft + "px", top: "135px" }); //left: 280px; top: 135px;
            $("#dialogRedStrip").jqmShow();
        }
    }
    catch (err) {

    }
}
function ChangeMessageStatus(MessageGUID, MessageStatus) {
    try {
    
        clearTimeout(currentVideoProcessid);
    //    $("object").remove();
        var uid = GetLoginGUID('Login') == null ? "" : GetLoginGUID('Login'); 
        var itemID = {"MessageGUID": MessageGUID, "MessageStatus": MessageStatus, "UserGUID" : uid  };
        var jsonStr = JSON.stringify(itemID);
        // Call our Web Service, passing in our JSON params. The error function is called  
        // whenever an exception is thrown by the web service (among other times)  
        $.ajax({
            type: "POST",
            url: "/Default.aspx/UpdateMessage",
            data: jsonStr,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                var JObject = eval('(' + msg.d + ')');
                if (JObject.toLowerCase() == "ok" && MessageStatus.toLowerCase() == "skipped") {
                        $("#divlogin").empty();
                        $("#divlogin").hide('fast');
                        ShowcurrentProfileDetail();
                }
                if (JObject.toLowerCase() == "ok" && MessageStatus.toLowerCase() == "viewed") {
                    $("#dialogRedStrip").jqmHide();
                }
                newMsgArray = null;
            },
            error: function(xhr, msg) {

                var response = JSON.parse(xhr.responseText);

                return false;
            }
        });
        return false;
    }
    catch (err) {
    }
}
//To check Date accepted or not
function IsDateAccepted(UserDateInitiatedGUID) {
    var _IsVisibleDate = $("#dialogDate").css("display");
    var _IsVisibleChat = $("#dialogChat").css("display");
    if (_IsVisibleDate == "block" || _IsVisibleChat == "block") {
        setTimeout("IsDateAccepted('" + UserDateInitiatedGUID + "')", newChatTime);
        return false;
    }
    var itemID = { "UserDateInitiatedGUID": UserDateInitiatedGUID };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)  
    $.ajax({
        type: "POST",
        url: "/Default.aspx/IsDateAccepted",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async:false ,
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            
            if (JObject != null) {
                //alert(JObject.UserDateMessageID);
                if (JObject.UserDateMessageID == 0) {
                    setTimeout("IsDateAccepted('" + UserDateInitiatedGUID + "')", 10000);
                    return false;
                }
                if (JObject.UserDateResponderAcceptDecline.toString() == 'true') {
                    ShowInviteAcceptDiv(JObject, UserDateInitiatedGUID);
                }
              
                if (JObject.UserDateResponderAcceptDecline.toString() == 'false') {
                   
                   // ShowDeclineDateLabel(JObject);
                   ShowChatStatusStrip(1,JObject.UserDateRespondName);
                   
                }
            }
//            if(ShowingDateAcceptd==false)
//                 {
                              setTimeout("IsDateAccepted('" + UserDateInitiatedGUID + "')", newChatTime);
//                 }
    //            setTimeout("IsDateAccepted('" + UserDateInitiatedGUID + "')", newChatTime);
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
            return false;
        }
    });
    return false;
}
//To show red bar for invite acceptation
function ShowInviteAcceptDiv(DateInvitiationArr, UserDateInitiatedGUID) {
  
    HideTheVideoAndMessage();
    var WaitingPersonName = '';
    if (GetLoginGUID("Login") == UserDateInitiatedGUID) {
        WaitingPersonName = DateInvitiationArr.UserDateRespondName; //+ "Initiated Name:= " + DateInvitiationArr.UserDateInitiateName  ; 
    }
    else {
        WaitingPersonName = DateInvitiationArr.UserDateInitiateName; //DateInvitiationArr.UserDateInitiateName; 
    }
     $("#divlogin").empty();   
     var _divString ="";  
     _divString = "<div style='position:absolute; top:138px;width:901px;z-index:500000;' class='inviteAcceptedDiv'>"
                     + "<center>"
                     + "<div style='font-size:34px;padding-bottom:34px;'>Your invite has been accepted!</div>"
                     + "<div style='font-size:14px;padding-bottom:39px;' id='divwating'>" + WaitingPersonName + " is waiting to talk to you.</div>"
                     + "<div style='height:30px;padding-bottom:16px'><img src='../Images/Decline-button.png'  alt='Cancel' style='cursor:pointer' onclick=Javascript:DeclineDate('" + CookieGUIDValue + "','false','" + DateInvitiationArr.UserDateMessageGUID + "','cancel','initiator','" + DateInvitiationArr.UserDateRespondGUID + "'); >&nbsp;<img src='../Images/Date-button.png' style='cursor:pointer' onclick=Javascript:AcceptDeclineDateRequest('" + CookieGUIDValue + "','true','" + DateInvitiationArr.UserDateMessageGUID + "','accept','initiator','" + DateInvitiationArr.UserDateRespondGUID + "','','','','',''); alt='Date'></div>"
                     + "</center>"
                     + "</div>";
    $("#divlogin").empty();   
    $("#divlogin").html(_divString);
    var totLeft;
    totLeft = $(".main_content").offset().left + 24;
   // $("#divCommonPopup").css({ left: totLeft + "px", top: "0px" });
//    //$("#dialogDate").css({left:"150px", top:"210px"});
   $("#divlogin").css("z-index", "50000");
    $("#divlogin").show('fast');
    ShowingDateAcceptd=true;
}
//function to show decline date label at top of window
function ShowDeclineDateLabel(DateInvitiationArr) {
   // alert( DateInvitiationArr.UserDateRespondName+ "decline");
   // $("#MessageDiv1").empty(); 
    //$("#MessageDiv").empty();
    try {

        var _declineDivStr = DateInvitiationArr.UserDateRespondName + " declined your chat invite";

        $("#declineBar").empty();
        $("#declineBar").append(_declineDivStr);
        //setTimeout("HideDeclineDateLabel('" + DateInvitiationArr.UserDateMessageGUID + "')", newChatTime);
    }
    catch (err) {
    }
}

function AcceptDeclineDateRequest(UserGUID, DateStatus, DateMessageGUID, Action, UserType, ResponderGUID, ReplyDateMessage, dialog, newMessageChainID, MessageDiv, ProfileGuid) {
    // alert("AcceptDeclineDate(" + UserGUID +","+ DateStatus +","+ DateMessageGUID +","+ Action +","+ UserType +","+ ResponderGUID +","+ ReplyDateMessage +","+  dialog +","+ newMessageChainID +","+ MessageDiv +","+ ProfileGuid );
    var itemID = { "pReceiverGuid": ResponderGUID, "pSenderGuid": UserGUID, "DateMessageGUID": DateMessageGUID, "DateStatus": DateStatus, "UserType": UserType, "pUserGUID": GetLoginGUID("Login") };
    var jsonStr = JSON.stringify(itemID);
    //  alert("jsonStr:"+ jsonStr);
    $.ajax({
        type: "POST",
        url: "/Default.aspx/GetValidUserCheckChatStatusAcceptDecline",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            
            if (JObject != "error") {
                if (JObject == -1) {
                    var strHtml = ""
                         + "<div style='width:640px;height:480px;background-color:#ff0000;position:absolute;z-index:300;left:1px;top:0px;opacity:0.5;filter:alpha(opacity=50);' >"
                         + "<div class='flag_cross'><img src='../Images/Homepage/cross.png' onclick= javascript:$('#divTemp').empty();$('#divTemp').hide('fast');  style='cursor:pointer;'/></div>"
                         + "<div style='top:203px;left:125px;position:relative;color:white;font-size:25px; '>"
                         + "User is not an active Vooji user."
                         + "</div>"
                         + "</div>";
                    $("object").remove();
                    $("#divTemp").html(strHtml);
                    $("#divTemp").show('fast');
                    return;
                }
                if (DateStatus == 'false') {

                }
                else {
                    var _JObject = JObject.split('|');
                    if (_JObject.length == 2) {
                        var ResponderName = _JObject[1];
                        var ChatStatus = _JObject[0];
                        //  alert(ChatStatus);
                        //alert(ResponderName);       
                        if (ChatStatus == "0") //Responder Logoff
                        {
                            UnbindTheMenuClickEvents();
                            ShowChatStatusStrip("0", ResponderName);

                        }
                        else if (ChatStatus == "1")//Responder decline
                        {
                            UnbindTheMenuClickEvents();
                            ShowChatStatusStrip("1", ResponderName);

                        }
                        else if (ChatStatus == "2")//chat end
                        {
                            UnbindTheMenuClickEvents();
                            ShowChatStatusStrip("2", ResponderName);

                        }
                        else if (ChatStatus == "4") {
                            UnbindTheMenuClickEvents();
                            ShowChatStatusStrip("0", ResponderName);
                        }
                    }
                    else {
                        if (JObject.toLowerCase() != 'error' && $.trim(Action) == 'accept') {
                            var DateId = JObject;
                            var _array = DateId.split("|");
                            DateId = _array[0];
                            vUserDateInitiateName = _array[1];
                            vUserDateRespondName = _array[2];
                            vChatUserGuid = _array[3];
                            $("#dialogDate").jqmHide();
                            var _ResponderGUID = '';
                            var _InitiateGUID = '';
                            if (UserType == 'responder') {
                                _ResponderGUID = UserGUID;
                                _InitiateGUID = ResponderGUID;
                            }
                            else {
                                _ResponderGUID = ResponderGUID;
                                _InitiateGUID = UserGUID;
                            }
                            ShowChatWindow(DateMessageGUID, _ResponderGUID, '', '', '', _InitiateGUID, UserType, DateId, vUserDateInitiateName, vUserDateRespondName, vChatUserGuid);
                            setTimeout("CheckChatStatus('" + _ResponderGUID + "','" + DateMessageGUID + "','" + UserType + "')", newChatTime);
                        }
                        else {
                            $('#divVideo').show('fast');
                            if (ReplyDateMessage == 'ReplyDateMessage') {
                                ShowSendAMessage(dialog, newMessageChainID, MessageDiv, ProfileGuid)
                            }
                            else {
                                $("#dialogDate").jqmHide();

                                $("#divlogin").empty();
                                $("#divlogin").hide('fast');
                                ShowcurrentProfileDetail();
                            }
                        }
                    }
                }
            }

        },
        error: function(xhr, msg) {
            alert("error");
            var response = JSON.parse(xhr.responseText);
        }
    });
    return false;
}




function AcceptDeclineDate(UserGUID, DateStatus, DateMessageGUID, Action, UserType, ResponderGUID, ReplyDateMessage, dialog, newMessageChainID, MessageDiv, ProfileGuid) {
   // alert("AcceptDeclineDate(" + UserGUID +","+ DateStatus +","+ DateMessageGUID +","+ Action +","+ UserType +","+ ResponderGUID +","+ ReplyDateMessage +","+  dialog +","+ newMessageChainID +","+ MessageDiv +","+ ProfileGuid );
       var itemID = {"pReceiverGuid": ResponderGUID,"pSenderGuid":UserGUID };
       var jsonStr = JSON.stringify(itemID);
     //  alert("jsonStr:"+ jsonStr);
       $.ajax({
           type: "POST",
           url: "/Default.aspx/GetValidUserToSendMessage",
           data: jsonStr,
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           async: false,
           success: function(msg) {
               var JObject = eval('(' + msg.d + ')');
              // alert("JObject:"+ JObject);
               if (JObject.toLowerCase() == "1" || JObject.toLowerCase() == "-2") {
                   if(DateStatus=='false'){
                   DeclineDate(UserGUID, DateStatus, DateMessageGUID, Action, UserType, ResponderGUID, ReplyDateMessage, dialog, newMessageChainID, MessageDiv, ProfileGuid)
                   }
                   else
                   {
                    AcceptDeclineDate1(UserGUID, DateStatus, DateMessageGUID, Action, UserType, ResponderGUID, ReplyDateMessage, dialog, newMessageChainID, MessageDiv, ProfileGuid)
                   }
               }
               else if (JObject.toLowerCase() == "-1") {
                   var strHtml = ""
                         + "<div style='width:640px;height:480px;background-color:#ff0000;position:absolute;z-index:300;left:1px;top:0px;opacity:0.5;filter:alpha(opacity=50);' >"
                         + "<div class='flag_cross'><img src='../Images/Homepage/cross.png' onclick= javascript:$('#divTemp').empty();$('#divTemp').hide('fast');  style='cursor:pointer;'/></div>"
                         + "<div style='top:203px;left:125px;position:relative;color:white;font-size:25px; '>"
                         + "User is not an active Vooji user."
                         + "</div>"
                         + "</div>";
                   $("object").remove();
                   $("#divTemp").html(strHtml);
                   $("#divTemp").show('fast');
                   //    alert("User is not an active Vooji user.");
               }
           },
           error: function(xhr, msg) {
               alert("error");
               var response = JSON.parse(xhr.responseText);
           }
       });
       return false; 
   }
//To accept date
//UserType is either initiator or responder decline or accept date
function DeclineDate(UserGUID, DateStatus, DateMessageGUID, Action, UserType, ResponderGUID, ReplyDateMessage, dialog, newMessageChainID, MessageDiv, ProfileGuid) {
    UserGUID = GetLoginGUID("Login");
    HideTheVideoAndMessage();
    var itemID = { "UserGUID": UserGUID, "DateMessageGUID": DateMessageGUID, "DateStatus": DateStatus, "UserType": UserType };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
    $.ajax({
        type: "POST",
        url: "/Default.aspx/AcceptDeclineDate",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
         async: false,
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            ShowingDateAcceptd=false;
            var vUserDateInitiateName = "";
            var vUserDateRespondName = "";
            var vChatUserGuid = "";
            if (JObject.toLowerCase() != 'error' && $.trim(Action) == 'accept') {
                var DateId = JObject;
                var _array = DateId.split("|");
                DateId = _array[0];
                vUserDateInitiateName = _array[1];
                vUserDateRespondName = _array[2];
                vChatUserGuid = _array[3];
                $("#dialogDate").jqmHide();
                var _ResponderGUID = '';
                var _InitiateGUID = '';
                if (UserType == 'responder') {
                    _ResponderGUID = UserGUID;
                    _InitiateGUID = ResponderGUID;
                }
                else {
                    _ResponderGUID = ResponderGUID;
                    _InitiateGUID = UserGUID;
                }
                ShowChatWindow(DateMessageGUID, _ResponderGUID, '', '', '', _InitiateGUID, UserType, DateId, vUserDateInitiateName, vUserDateRespondName, vChatUserGuid);
            }
            else {
                $('#divVideo').show('fast');
                if (ReplyDateMessage == 'ReplyDateMessage') {
                    ShowSendAMessage(dialog, newMessageChainID, MessageDiv, ProfileGuid)
                }
                else {
                    $("#dialogDate").jqmHide();
                    
                    $("#divlogin").empty();
                    $("#divlogin").hide('fast');
                    ShowcurrentProfileDetail();
                }
            }
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
            return false;
        }
    });
    return false;
}

//To accept date
//UserType is either initiator or responder decline or accept date
function AcceptDeclineDate1(UserGUID, DateStatus, DateMessageGUID, Action, UserType, ResponderGUID, ReplyDateMessage, dialog, newMessageChainID, MessageDiv, ProfileGuid) {
    UserGUID = GetLoginGUID("Login");
    
    HideTheVideoAndMessage();
    
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
   var _ResponderGUID = '';
    var _InitiateGUID = '';
    if (UserType == 'responder') {
        _ResponderGUID = UserGUID;
        _InitiateGUID = ResponderGUID;
        CheckChatStatusAcceptDecline(_ResponderGUID, DateMessageGUID,UserType ,DateStatus,Action,_InitiateGUID);
    }
    else {
        _ResponderGUID = ResponderGUID;
        _InitiateGUID = UserGUID;
        CheckChatStatusAcceptDecline(_InitiateGUID, DateMessageGUID, UserType,DateStatus,Action,_InitiateGUID);
    }   
    
    
}

function CheckChatStatusAcceptDecline(ResponderGUID, UserDateMessageGUID, UserType, DateStatus, Action, InitiateGUID) {
    if (NotCheckStatus)
        return;
    //var itemID = { "UserDateMessageGUID": UserDateMessageGUID, "UserResponderGUID": ResponderGUID ,"UserType":UserType };
    var itemID = { "UserDateMessageGUID": UserDateMessageGUID, "UserResponderGUID": GetLoginGUID("Login") ,"UserType":UserType };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)  
    $.ajax({
        type: "POST",
        url: "/Default.aspx/CheckChatStatus",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
         async: false,
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            var _JObject = JObject.split('|');
            var ResponderName = _JObject[1];
            var ChatStatus = _JObject[0];
            //alert(ChatStatus);
            //alert(ResponderName);       
            if (ChatStatus == "0") //Responder Logoff
            {
                ShowChatStatusStrip("0", ResponderName);

            }
            else if (ChatStatus == "1")//Responder decline
            {
                ShowChatStatusStrip("1", ResponderName);
            }
            else if (ChatStatus == "2")//chat end
            {
                ShowChatStatusStrip("2", ResponderName);
            }
            else if(ChatStatus == "4")
            {               
                 ShowChatStatusStrip("0", ResponderName);
            }
            else if(ChatStatus=="6")
            {
                ShowChatStatusStrip("6", ResponderName);
            }
            else 
            {
                var itemID1 = { "UserGUID": ResponderGUID, "DateMessageGUID": UserDateMessageGUID, "DateStatus": DateStatus, "UserType": UserType };
                var jsonStr1 = JSON.stringify(itemID1);
                $.ajax({
                type: "POST",
                url: "/Default.aspx/AcceptDeclineDate",
                data: jsonStr1,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                 async: false,
                success: function(msg) {
                var JObject1 = eval('(' + msg.d + ')');
                ShowingDateAcceptd=false;
                var vUserDateInitiateName = "";
                var vUserDateRespondName = "";
                var vChatUserGuid = "";
                if (JObject1.toLowerCase() != 'Error' && $.trim(Action) == 'accept') {
                    
                    var DateId = JObject1;
                    var _array = DateId.split("|");
                    DateId = _array[0];
                    vUserDateInitiateName = _array[1];
                    vUserDateRespondName = _array[2];
                    vChatUserGuid = _array[3];                    
                    //alert( DateId + vUserDateInitiateName+ vUserDateRespondName+vChatUserGuid);
                    $("#dialogDate").jqmHide();
//                    var _ResponderGUID = ResponderGUID;
//                    var _InitiateGUID = '';
//                    if (UserType == 'responder') {
//                        _ResponderGUID = UserGUID;
//                        _InitiateGUID = ResponderGUID;
//                        alert("responder");
//                    }
//                    else {
//                        _ResponderGUID = ResponderGUID;
//                        _InitiateGUID = InitiateGUID;
//                        alert("initor");
//                    }
                   // alert("ResponderGUID  " + ResponderGUID  + " InitiateGUID " +InitiateGUID + " UserType "+ UserType);
                    ShowChatWindow(UserDateMessageGUID, ResponderGUID, '', '', '', InitiateGUID, UserType, DateId, vUserDateInitiateName, vUserDateRespondName, vChatUserGuid);
                }
                else {
                    $('#divVideo').show('fast');
                    if (ReplyDateMessage == 'ReplyDateMessage') {
                        ShowSendAMessage(dialog, newMessageChainID, MessageDiv, ProfileGuid)
                    }
                    else {
                        $("#dialogDate").jqmHide();
                        
                        $("#divlogin").empty();
                        $("#divlogin").hide('fast');
                        ShowcurrentProfileDetail();
                    }
                }
                },
                error: function(xhr, msg) {
                    var response = JSON.parse(xhr.responseText);
                    return false;
                }
            });
            return false;
            }
            

        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);

            return false;
        }
    });
    return false;
}




// for blocking the user
function SaveBlockUser(BlockerUserGUID,BlockedUserGUID,ProfileTitle,id)
 {
    var itemID = { "UserBlockerGUID": BlockerUserGUID, "UserBlockedGUID": BlockedUserGUID};
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
    $.ajax({
        type: "POST",
        url: "/Default.aspx/SaveUserBlocked",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            if (JObject.toLowerCase() == 'ok') {
             var divstr=""    
//             +"<div class='red_box'></div>"
//             +"<div class='block_confirmation_txt'>"
//             +"<div class='block_confirmation_txt1'>"+ ProfileTitle +"</div>"
//             +"<div class='block_confirmation_txt1'>has been blocked from seeing</div>"
//             +"<div class='block_confirmation_txt1'>your profile and sending you</div>"
//             +"<div class='block_confirmation_txt1'>messages, or date requests. </div>"
//             +"</div>"
//             +"<div class='green_cross'><img src='/Images/Homepage/cross1.png' onclick= javascript:RemoveHtmlFromDiv('divlogin'); style='cursor:pointer;' /></div>";
//             $("#divTemp").empty();
//             $("#divTemp").html(divstr);
//             $("#divTemp").show('fast');
             
             //working
             globalJsonArray[id].IsBlocked=false;
             $("#divMessageButtons").hide('fast');  
             $("#divProfileButtons").hide('fast');
             $("#divUnblockButtons").show('fast');  
             var divstr=''
                +'<div class="red_box">'
                +'<div style="position:relative;top:200px;font-size:22px;text-align:center;color:#ffffff;">'
                + ProfileTitle
                +'<br/>has been blocked from seeing <br/>your profile and sending you <br/>messages, or date requests. '
                +'</div>'
                +'</div>';
               $("#divTemp").empty();
               $("#divTemp").html(divstr);
               $("#divTemp").show('fast');
               
             $("#btnUnblock").unbind("click");
             $("#btnUnblock").bind("click",function(e){
              var UserID;
              UserID=GetCookie("Login")==null?"":GetCookie("Login");
              
                 if(UserID!="")
                  {
                     DeleteBlockUser(BlockerUserGUID,BlockedUserGUID,id);
                  }
             });
            }
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
            return false;
        }
    });
    return false;
}
//function to hide decline date label at top of window
function HideDeclineDateLabel(UserDateMessageGUID) {
    $("#declineBar").empty();
    // AcceptDeclineDate(CookieGUIDValue,'false',DateInvitiationArr.UserDateMessageGUID,'decline','initiator')
    EndChat(UserDateMessageGUID, false);
}
function CloseChatDiv(DateMessageGuid)
{
 if (confirm("Are you sure you want to close live connection?"))  
 {
    EndChat(DateMessageGuid,false);
     $("#divOverlay").hide(0);
      $("#divInner").show(0);
       SetDefaultMenuHover();
    }
       
}
function UnbindTheMenuClickEvents()
{
    $("#divInviteMenu1").unbind("click");
    $("#divInviteMenu1").bind("click", function(e) { InviteRecord('dialog');});  
    $("#lnkSignIn1").unbind("click");
    $("#lnkSignIn1").bind("click", function(e) { ShowLoginDiv('','SignIn','dialog','home');});   
    $("#divImgRec").unbind("click");
    $("#divImgRec").bind("click", function(e) { window.location.href = siteURL + 'Recorder/CreateProfile.aspx';});
    $("#lnkSignOut1").unbind("click");
    $("#lnkSignOut1").bind("click", function(e) { SignOut('master');});
    $("#divFansMenu").unbind("click");
    $("#divFansMenu").bind("click", function(e) { window.location.href = siteURL + 'fans/FansFavorites.aspx?id=1';});  
    $("#divFavoritesMenu").unbind("click");
    $("#divFavoritesMenu").bind("click", function(e) { window.location.href = siteURL + 'fans/FansFavorites.aspx?id=2';});  
    $("#divInboxMenu").unbind("click");
    $("#divInboxMenu").bind("click", function(e) { window.location.href = siteURL + 'Messages/MessagesList.aspx';});  
    $("#divMyaccountMenu").unbind("click");
    $("#divMyaccountMenu").bind("click", function(e) { window.location.href = siteURL + 'Recorder/MyAccount.aspx';});                          
}
//To show chat window
function ShowChatWindow(UserDateMessageGUID, ResponderGUID, url, psw, email, InitiatorGUID, sender, DateID, vUserDateInitiateName, vUserDateRespondName,ChatUserGuid) {
//   + "<div id='divlogin' style='position: absolute; display: none; left: 9px; top: 8px;z-index: 1000000;'></div>"

    $("#divInviteMenu1").unbind("click");
     $("#divInviteMenu1").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0); 
            InviteRecord('dialog');
        }        
    });
    $("#lnkSignIn1").unbind("click");
    $("#lnkSignIn1").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0);
            ShowLoginDiv('','SignIn','dialog','home');
        }       
    });
    $("#divImgRec").unbind("click");
    $("#divImgRec").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0);
            window.location.href = siteURL + 'Recorder/CreateProfile.aspx';
        }       
    });
    $("#lnkSignOut1").unbind("click");
    $("#lnkSignOut1").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0);  
            SignOut('master');
        }       
    });
    
    $("#divFansMenu").unbind("click");
    $("#divFansMenu").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0); 
            window.location.href = siteURL + 'fans/FansFavorites.aspx?id=1';
        }       
    });
    
    $("#divFavoritesMenu").unbind("click");
    $("#divFavoritesMenu").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0);
            window.location.href = siteURL + 'fans/FansFavorites.aspx?id=2';
        }       
    });
    $("#divInboxMenu").unbind("click");
    $("#divInboxMenu").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0);
            window.location.href = siteURL + 'Messages/MessagesList.aspx';
        }       
    });
    $("#divMyaccountMenu").unbind("click");
    $("#divMyaccountMenu").bind("click", function(e) {  
     if (confirm("Are you sure you want to close live connection?"))       
        {
            EndChat(UserDateMessageGUID,false);
            $("#divOverlay").hide(0);
            $("#divInner").show(0);
            window.location.href = siteURL + 'Recorder/MyAccount.aspx';
        }       
    });

 $("#divlogin").empty();
 $("#divlogin").hide('fast');
 ShowingDateAcceptd=false;
 var _chatString = "<div class='header_top'><div style='padding-top:15px;padding-left:15px;'><div id='divHome' class='float subfindbar_bottom_border'><a href='javascript:void(0);' style='cursor:pointer;' class='find_bar_txt_font' onclick=javascript:CloseChatDiv('" + UserDateMessageGUID + "',false);> Home</a></div> <img alt='' src='../images/HomePage/circle.png'/> Live connection</div></div>"
                   + "<div style='width:920px; background-image:url(../Images/Homepage/content_bg.png);background-repeat:repeat-y;height:490px; margin:auto;'>"
                   +"<div style='position:relative;'>"
                   +"<div id='divlogin1' style='position: absolute; left: 9px; top: 8px;z-index: 1000000;'></div>"
                   +"</div>"
                   + "<div style='width:900px;margin:auto;height:480px;'>";
    if (sender == "initiator") {        
       // alert("responde  "+ vUserDateRespondName + " initiator " + vUserDateInitiateName + " ChatUserGuid-" +ChatUserGuid);
        _chatString += ChatObjectForInitator(vUserDateInitiateName, vUserDateRespondName, DateID, ChatUserGuid, UserDateMessageGUID);
    }
    else {
       // alert("responde  "+ vUserDateRespondName + " vUserDateInitiateName " + vUserDateInitiateName + " ChatUserGuid-" +ChatUserGuid);
        _chatString += ChatObjectForResponder(vUserDateInitiateName, vUserDateRespondName, DateID, ChatUserGuid, UserDateMessageGUID);
    }
    
    _chatString += "</div></div>";
    $("#dialogChat").empty();
    $("object").remove();    
    var myDiv = document.getElementById('dialogChat');
    myDiv.innerHTML = (_chatString);
    
    $("#divInner").hide('fast');
    $("#divOverlay").empty();
    $("#divOverlay").html(_chatString);
    $("#divOverlay").show('fast');
    $.ifixpng('../Images/HomePage/pixel.gif');
    $('img[src$=.png]').ifixpng();
    $('input[src$=.png]').ifixpng();
    //document.getElementById("btnCloseLiveConnection").focus();
    if (sender == "initiator") {
        CheckChatStatus(InitiatorGUID, UserDateMessageGUID, sender);
    }
    else {
        CheckChatStatus(ResponderGUID, UserDateMessageGUID,sender );
    }
}

//To end Chat
function EndChat(UserDateMessageGUID, showMessgeToUser) {
    UnbindTheMenuClickEvents();
    var itemID = { "UserDateMessageGUID": UserDateMessageGUID };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
    $.ajax({
        type: "POST",
        url: "/Default.aspx/EndChat",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            if (JObject.toLowerCase() == 'ok') {
                NotCheckStatus = true; //To stop checking for chat status
                //$("#dialogChat").jqmHide();
                //$("#dialogChat").jqmShow();    
                           
                $("#divInner").show('fast');
                $("#divOverlay").empty();
                $("#divOverlay").hide('fast');
                
                if (showMessgeToUser == true) {
                    ShowChatStatusStrip("5", " ");
                }
                else {
//                    var url = location.href;
//                    if (url.toLowerCase().indexOf('playinvitemessages') > 0) {
//                        window.location.href = siteURL + "Default.aspx";
//                    }
//                    if (url.toLowerCase().indexOf('recordaprofile.aspx') > 0) {
//                        window.location.href = siteURL + "recorder/recordaprofile.aspx";
//                    }
                }
            }
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
            return false;
        }
    });
    return false;
}

//To end Chat
function EndStartedChat() {
    UserGUID = GetLoginGUID("Login");
    if(UserGUID=='' || UserGUID==null)
    {
        return ;
    }
    var itemID = { "UserProfileGUID": UserGUID };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)
    $.ajax({
        type: "POST",
        url: "/Default.aspx/EndStatedChat",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            if (JObject.toLowerCase() == 'ok') {
               
            }
        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);
            return false;
        }
    });
    return false;
}


//function to check chat status and use login status
function CheckChatStatus(ResponderGUID, UserDateMessageGUID,UserType) {
    if (NotCheckStatus)
        return;
    var itemID = { "UserDateMessageGUID": UserDateMessageGUID, "UserResponderGUID": ResponderGUID ,"UserType":UserType };
    var jsonStr = JSON.stringify(itemID);
    // Call our Web Service, passing in our JSON params. The error function is called  
    // whenever an exception is thrown by the web service (among other times)  
    $.ajax({
        type: "POST",
        url: "/Default.aspx/CheckChatStatus",
        data: jsonStr,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            var JObject = eval('(' + msg.d + ')');
            var _JObject = JObject.split('|');
            var ResponderName = _JObject[1];
            var ChatStatus = _JObject[0];
           //  alert(ChatStatus);
            //alert(ResponderName);       
            if (ChatStatus == "0") //Responder Logoff
            {
                UnbindTheMenuClickEvents();
                ShowChatStatusStrip("0", ResponderName);

            }
            else if (ChatStatus == "1")//Responder decline
            {
               UnbindTheMenuClickEvents();
                ShowChatStatusStrip("1", ResponderName);

            }
            else if (ChatStatus == "2")//chat end
            {
                UnbindTheMenuClickEvents();
                ShowChatStatusStrip("2", ResponderName);

            }
            else if(ChatStatus == "4")
            {
                UnbindTheMenuClickEvents();
                 ShowChatStatusStrip("0", ResponderName);
            }
            else //chat Start
            {
                setTimeout("CheckChatStatus('" + ResponderGUID + "','" + UserDateMessageGUID + "','"+UserType+"')", newChatTime);
            }

        },
        error: function(xhr, msg) {
            var response = JSON.parse(xhr.responseText);

            return false;
        }
    });
    return false;
}

//To show chat status
function ShowChatStatusStrip(ChatStatus, ResponderName) {
    $("#divInner").show('fast');
    $("#divOverlay").empty();
    $("#divOverlay").hide('fast');
    $("#MessageDiv1").empty();
    if (ChatStatus == "0")
        chatResult = "Sorry! " + ResponderName + " is offline.";
    else if (ChatStatus == "1")
        chatResult = "Chat has been declined by " + ResponderName;
    else if (ChatStatus == "5") //If chat ended by current login user
        chatResult = "Chat has been ended. ";
    else if(ChatStatus =="6")
        chatResult = ResponderName +" is busy with other user" ;
    else
        chatResult = "Chat has been ended by " + ResponderName + ".";

    var ChatStatus = "<div style='width:901px; height:100px;'><div style='position:absolute;height:72px;padding-top:12px;cursor:pointer;top:200px;width:901px;' class='resultMsg3' onclick=Javascript:CloseChatStatusStrip(); >"
                                    + "<center>"
                                    + "<div style='font-size:18px;padding-bottom:10px;' class='redStrip'>" + chatResult + "</div>"
                                    + "<div style='height:30px;padding-bottom:4px' class='redStrip'>Click to close</div>"
                                    + "</center>"
                                    + "</div></div>";
    //$("#dialogChatStatus").empty();
    //$("#dialogChatStatus").append(ChatStatus);
//    $('#<% =divOnLine.ClientID%>').hide('fast'); 
   
    $("#divlogin").empty();
    $("#divlogin").html(ChatStatus);
    $("#divlogin").show('fast');
    
    var totLeft;
    totLeft = $(".main_content").offset().left + 53;
     $("#divlogin").css("z-index", "50000");
    $("#dialogChatStatus").css({ left: totLeft + "px", top: "200px" });
    //$("#dialogChatStatus").css({left:"426px",top:"160px"});
    $("object").remove();
   // $('#divVideo').hide('fast');
    //$("#dialogChatStatus").jqmShow();
}

//function to close chat status strip and chat dialog box
function CloseChatStatusStrip() {
//    $("#dialogChat").jqmHide();
    //    $("#dialogChatStatus").jqmHide();
    $("#divlogin").empty();
    $("#divlogin").hide('fast');
    var url = location.href;
    if (url.toLowerCase().indexOf('playinvitemessages') > 0) {
        window.location.href = siteURL + "Default.aspx";
    }
    if (url.toLowerCase().indexOf('recordaprofile.aspx') > 0) {
        window.location.href = siteURL + "recorder/recordaprofile.aspx";
    }
    //$('#divVideo').show('fast');
}
/*Live chat flash Functions Start */
function callExternalInterface() {
    thisMovie("recorder").goHome();
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
/*Live chat flash Functions End */
/*Test 1 Chat object of intitator*/
function ChatObjectForInitator(user1, user2, DateID, userguid, UserDateMessageGUID) {
   //alert("test1  " + userguid + " UserDateMessageGUID  " + UserDateMessageGUID);
    var FlashObjectText = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='900' height='480' id='Test1' align='middle wmode='opaque''>"
		                    + "<param name='allowScriptAccess' value='sameDomain' />"
		                    + "<param name='movie' value='" + "/Flash/Test1.swf?MessageGUID=" + UserDateMessageGUID + "&rtmPath=" + rtmPath + "/live&aspxPath=" + pixelPostPath + "&user1=" + user1 + "&user2=" + user2 + "&dateid=" + DateID + "&userguid=" + userguid + "'/>"
		                    + "<param name='quality' value='high' />"
		                     + "<param name='allowFullScreen' value='true' />"
		                     + "<param name='wmode' value='opaque' />"
		                    //+ "<param name='bgcolor' value='#333333' />"
		                    + "<embed src='" + "/Flash/Test1.swf?MessageGUID=" + UserDateMessageGUID + "&rtmPath=" + rtmPath + "/live&aspxPath=" + pixelPostPath + "&user1=" + user1 + "&user2=" + user2 + "&dateid=" + DateID + "&userguid=" + userguid + "' quality='high' wmode='transparent'  width='900' height='480' name='Test1' wmode='opaque' align='middle' allowFullScreen='true' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"
		                    + "</object>";
    return FlashObjectText;
}
/*Test 1 Chat object of intitator End*/

/*Test 2 Chat object of intitator*/
function ChatObjectForResponder(user1, user2, DateID, userguid, UserDateMessageGUID) {
//alert( "test2  " +  userguid   + " UserDateMessageGUID " + UserDateMessageGUID);
    var FlashObjectText = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='900' height='480' id='Test2' align='middle wmode='opaque''>"
		                     + "<param name='allowScriptAccess' value='sameDomain' />"
		                     + "<param name='movie' value='" + "/Flash/Test2.swf?MessageGUID=" + UserDateMessageGUID + "&rtmPath=" + rtmPath + "/live&aspxPath=" + pixelPostPath + "&user1=" + user1 + "&user2=" + user2 + "&dateid=" + DateID + "&userguid=" + userguid + "'/>"
		                     + "<param name='quality' value='high' />"
		                      + "<param name='allowFullScreen' value='true' />"
		                     + "<param name='wmode' value='opaque' />"
		                     //+ "<param name='bgcolor' value='#333333' />"
		                    + "<embed src='" + "/Flash/Test2.swf?MessageGUID=" + UserDateMessageGUID + "&rtmPath=" + rtmPath + "/live&aspxPath=" + pixelPostPath + "&user1=" + user1 + "&user2=" + user2 + "&dateid=" + DateID + "&userguid=" + userguid + "' quality='high' wmode='transparent'  width='900' height='480' name='Test2' wmode='opaque' align='middle' allowFullScreen='true' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"
		                    + "</object>";

    return FlashObjectText;
}
/*Test 2 Chat object of intitator End*/

function GetLoginGUID(cookie_name) {
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
} 

function ShowcurrentProfileDetail()
{
    $("#divProfileTitle").html(globalJsonArray[currentSlide].UserDetail.ProfileTitle);
    $("#divAge").html("Age: "+globalJsonArray[currentSlide].UserDetail.Age);
    $("#divCity").html("City: "+setLength(formatNameText(globalJsonArray[currentSlide].UserDetail.City), 19));
    $("#divState").html("State: "+setLength(formatNameText(globalJsonArray[currentSlide].UserDetail.State), 18));
    $("#divCountry").html("Country: " + setLength(formatNameText(globalJsonArray[currentSlide].UserDetail.Country), 16));
    //$("#divTags").html("Tagged: " + replace(replace(setLength(addSpacesInString(globalJsonArray[currentSlide].UserDetail.ProfileTag, 15), 33), ', ...', '...'), ',...', '...'));
    if (globalJsonArray[currentSlide].UserDetail.ProfileTag != "")
    {
        var _TagAfterFormat = addSpacesInString(globalJsonArray[currentSlide].UserDetail.ProfileTag,13);
             $("#divTags").html("Tagged: " +replace(replace(setLength(_TagAfterFormat,33),', ...','...'),',...','...'));
    }
    else
    {
        $("#divTags").empty();
    }
    $("#divJoined").html("Joined: " + globalJsonArray[currentSlide].CreatedDateStr);
    $("#divResponseRate").html("");
    $("#divLastOnline").html("Last online: "+ globalJsonArray[currentSlide].LastOnline);
    var gender= globalJsonArray[currentSlide].UserGender;
    var category= globalJsonArray[currentSlide].MemberCategory;
    var w2mMen= globalJsonArray[currentSlide].Want2MeetMen;
    w2mMen= w2mMen== true ? "Men" : "f";
    var w2mWomen= globalJsonArray[currentSlide].Want2MeetWomen;
    w2mWomen= w2mWomen == true ? "Women" : "f";
    var w2m  = w2mMen=="f"?(w2mWomen=="f"?"":w2mWomen):(w2mWomen=="f"?w2mMen:w2mMen+"/"+w2mWomen);
    $("#divProfileCreateDate").html(ConvertProperCaseSentence(gender + " seeking " + w2m + " for "+ category));
     $("#divMessageButtons").hide('fast');  
     $("#divUnblockButtons").hide('fast');  
     $("#divProfileButtons").show('fast');
}