﻿// JScript File
SULEKHA.namespace("Commnets");

function getCookie(name) 
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) 
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
function Result_Login(result)
{
    if (result == 'false')
        window.location.href ='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
    else
        sChkLogin=1;
}

function fnShowInputBox(obj)
{
    var inputobj = document.getElementById('input'+obj);
    if (inputobj.style.display == "block")
    {
        inputobj.style.display='none'; 
        inputobj.innerHTML ='';
    }    
    else
    {
        inputobj.innerHTML='<label>Comment : </label><textarea onfocus="javascript:fnChkLogin();" ID="comment" name="comment"  Rows="8" style="width:450px;"></textarea><br/><center><a id="bSave" class="source" href="javascript:fnSaveComment();">Save Comment</a></center>';
        inputobj.style.display='block'; 
    }    
}

//added for comments and nested comments by

var iObj = 0;

function getCookie(name) 
{
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) 
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
var sChkLogin=0;


var sReplyBox = '';
function fnCommentInputBox(obj)
{
    fnChkLogin();
    if (sChkLogin == 1)
    {
        if (sReplyBox == 'undefined'  || sReplyBox == '')
        { }
        else
        {
            var PrevForm = document.getElementById (sReplyBox);
            PrevForm.innerHTML='';
        }
        var replyobj = document.getElementById('hidereply'+obj);
        var inputobj = document.getElementById('input'+obj);
        inputobj.style.display='block'; 
        inputobj.innerHTML ='<div name="divReply" id="divReply'+obj+'" class="cmtcontent"><div class="hd cmtreply_hd">Reply to this comment</div><div class="bd cmtreply_bd"><div class="postcomments"><p><div id="dyTxtCommend'+obj+'" name="dyTxtCommend"></div></p><div id="commentresult'+obj+'"  style="display:none"></div><div align="right" class="postbut"><span class="linkbutton yellow_but"><a href="javascript:fnsavecomment('+"'nestedcomments'"+','+ obj +');">Post this comment</a></span></div></div></div><br/></div>';		
        
        if ( fck == null)
        {
            var fck = new FCKeditor("dytxtcommend");
            fck.ToolbarSet = 'Comments';
            fck.BasePath = sBasePath;   
                 
        }    
        document.getElementById('dyTxtCommend'+obj).innerHTML = fck.CreateHtml();
        sReplyBox = "input"+obj;
    }
}



function fnshowcommentpanel()
 {
     var objCommnerPanel = document.getElementById('commentpanel');
     var objResult= document.getElementById('commentresult');
     objResult.style.display="none";
     objCommnerPanel.style.display=""; 
     fnWait(false,'');  
 }
  
function fnclear()
{
     var objResult= document.getElementById('commentresult');
     if(objResult.style.display=="")
        objResult.style.display="none";
}
function fnsavecomment(type,parentcommentid)
{
        var sComments = ""; 
        var oCommentForm = document.getElementById('leavecomment');
        var objResult="";
        
        if(type == "photocomment")
            parentcommentid = document.getElementById('hdparentcontentid').value;
       
        if(type == "blogcomment" || type =="commentdisplay" || type =="photocomment" || type=="singlecomment" )
        {
            objResult= document.getElementById('commentresult');
            //sComments = document.getElementById('txtcomment').value;
            sComments = GetContents('txtcomment');
            document.getElementById('txtcomment').value=sComments;
        }
        else if(type == "nestedcomments")
        {
            sComments = GetContents('dytxtcommend');
            document.getElementById('dytxtcommend').value=sComments;
            objResult= document.getElementById('dytxtcommend');
            document.getElementById('txtcomment').value=sComments;
            //sComments = document.getElementById('comment'+parentcommentid).value;
            var sThreadId=document.getElementById('hdthreadid' +parentcommentid).value;
            var sThreadOwner = document.getElementById('hdthreadowner' +parentcommentid).value;
        }
        try
        {
             var callback =
             {
                success: handleCommentSuccess,
                failure: handleCommmentFailure,
                argument: [parentcommentid,type]
            };
            if(sComments != null && sComments != '')
            {
                fnWait(true,'Saving comment, please wait...');
                YAHOO.util.Connect.setForm(oCommentForm);
                if(type=="nestedcomments")
                    YAHOO.util.Connect.asyncRequest('POST', '/mp/postacomment.aspx?hdparentcommentid=' + parentcommentid + "&hdthreadid=" + sThreadId + "&hdthreadowner=" + sThreadOwner, callback);
                else if(type =="commentdisplay")
                    YAHOO.util.Connect.asyncRequest('POST', '/mp/postacomment.aspx?hdthreadid=0', callback);
                else
                    YAHOO.util.Connect.asyncRequest('POST', '/mp/postacomment.aspx', callback);
            }
            else
            {
              
               if(objResult!=null)
               { 
                    if(objResult.style.display=="none")
                        objResult.style.display="";
                    objResult.innerHTML ="<span style='margin:.5em;border:1px solid red;'>Please enter comments.</span>";
               }
           }
        }
        catch(e)
        {
            alert(e);
        }
    }
    
    var PostCommentTransactionObject = {
	    start:function(type, args){
	                YAHOO.namespace("sulekha.container");
                    if (!YAHOO.sulekha.container.wait) 
                    {
                        YAHOO.sulekha.container.wait = new YAHOO.widget.Panel("wait",{x:200, width: "240px", fixedcenter: true, close: false, draggable: false, modal: true,visible: false } );
                        YAHOO.sulekha.container.wait.setHeader("Saving comment, please wait...");
                        YAHOO.sulekha.container.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
                        YAHOO.sulekha.container.wait.render(document.body);
                        YAHOO.sulekha.container.wait.show();
                    }
	    },
	    complete:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    success:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    failure:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    abort:function(type, args){ YAHOO.sulekha.container.wait.hide();}
    };
   
    var handleCommentSuccess = function(sResult)
    {
        fnWait(false,'');
        var Result =sResult.responseText;
        var Parentcommentid = sResult.argument[0];
        var Type = sResult.argument[1];
        var objCommentPanel = document.getElementById('input'+Parentcommentid);
        var objResult="";
        if(Type =="blogcomment")
        {
             //window.location.href = window.location.href;
             objResult= document.getElementById('commentresult');
        }
        else if(Type =="nestedcomments")
        {
            //window.location.href = window.location.href;
            objResult= document.getElementById('commentresult'+Parentcommentid);
        }
        else if(Type =="photocomment")
        {
            window.location.href = window.location.href;
            objResult= document.getElementById('commentsdisplaypanel');
        }
        if(Result !== undefined)
        {
            if (Result == 'not loggedin')
            {
                window.location.href='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
            }
            else if(Result == "success")
            {
                
                var objCommnetPanel = document.getElementById('commentpanel');
                var sTitleurl = window.location.href.replace('.htm','/comments.htm');
                if(Type=="blogcomment")
                {
                    
                    var objBlogcmtCnt = document.getElementById('blogcommentcount');
                    var objReadcmtcnt = document.getElementById('readcommentcount');
                    var objReadcmtcmtLink = document.getElementById('showreadcommentslink');
                    var BlogcmtCnt="";
                    var Readcmtcnt="";
                    if(objBlogcmtCnt!=null)
                    {
                        BlogcmtCnt = document.getElementById('blogcommentcount').innerHTML;
                        BlogcmtCnt = ++BlogcmtCnt
                        objBlogcmtCnt.innerHTML="";
                        objBlogcmtCnt.innerHTML = BlogcmtCnt; 
                    }
                    if(objReadcmtcnt!=null)
                    {
                        if(objReadcmtcmtLink!=null)
                            objReadcmtcmtLink.style.display ='';    
                        Readcmtcnt = document.getElementById('readcommentcount').innerHTML;
                        Readcmtcnt = ++Readcmtcnt;
                        objReadcmtcnt.innerHTML="";
                        objReadcmtcnt.innerHTML = Readcmtcnt; 
                        var objCommentlink = YAHOO.util.Dom.get("commentlink");
                        if(objCommentlink!=null)
                            objCommentlink.innerHTML = "<a href='"+ sTitleurl + "'>Comment (" + Readcmtcnt  + ")</a>";
                    }
                    
                    if(objResult.style.display="none")
                          objResult.style.display="";
                    
                    var sText ='';
                    var Baseaddress = fnGetCookie('sulekha_baseaddress') + "/dashboard.htm";
                    if(BlogcmtCnt !="1")
                    {
                        sText = "Your Comment Saved Successfully.";
                        fnWait(true,sText);
                        SULEKHA.Commnets.wait.setBody("<div align='left'><h6>Go to</h6><ul class='thankulist'><li><a href='" + sTitleurl.replace('/comments/comments.htm','/comments.htm') +"'>Read other comments</a></li><li><a href='http://blogs.sulekha.com'>Blogs home page</a></li><li><a href='"+sTitleurl.replace('/comments/comments.htm','.htm')+"'>Current Blog</a></li></ul></div><br/><p align='right'><span class='linkbutton yellow_but yellow_but_plain'><a href='javascript:close();'>Post another comment</a></span>&nbsp;<span class='linkbutton yellow_but yellow_but_plain'><a href='http://www.sulekha.com/mp/dashboard.aspx'>Go to Dashboard</a></span></p>");
                    }
                    else
                    {
                        sText = "Your Comment Saved Successfully.";
                        fnWait(true,sText);
                        SULEKHA.Commnets.wait.setBody("<div align='left'><h6>Go to</h6><ul class='thankulist'><li><a href='" + sTitleurl.replace('/comments/comments.htm','/comments.htm') +"'>Read other comments</a></li><li><a href='http://blogs.sulekha.com'>Blogs home page</a></li><li><a href='"+sTitleurl.replace('/comments/comments.htm','.htm')+"'>Current Blog</a></li></ul></div><br/><p align='right'><span class='linkbutton yellow_but yellow_but_plain'><a href='javascript:close();'>Post another comment</a></span>&nbsp;<span class='linkbutton yellow_but yellow_but_plain'><a href='http://www.sulekha.com/mp/dashboard.aspx'>Go to Dashboard</a></span></p>");
                    }
                    objCommnetPanel.style.display="none";                   
                }
                else if(Type =="singlecomment")
                {
                    //alert("calling showreplies");
                    showreplies('sc',Parentcommentid); 
                }
                else if(Type=="nestedcomments")
                {
                    sText = "Your Comment Saved Successfully.";
                    fnWait(true,sText);
                    SULEKHA.Commnets.wait.setBody("<div align='left'><h6>Go to</h6><ul class='thankulist'><li><a href='" + sTitleurl.replace('/comments/comments.htm','/comments.htm') +"'>Read other comments</a></li><li><a href='http://blogs.sulekha.com'>Blogs home page</a></li><li><a href='"+sTitleurl.replace('/comments/comments.htm','.htm')+"'>Current Blog</a></li></ul></div><br/><p align='right'><span class='linkbutton yellow_but yellow_but_plain'><a href='javascript:close();'>Post another comment</a></span>&nbsp;<span class='linkbutton yellow_but yellow_but_plain'><a href='http://www.sulekha.com/mp/dashboard.aspx'>Go to Dashboard</a></span></p>");
                }
                else if(Type=="commentdisplay")
                {
                    var contentid = document.getElementById('hdparentcontentid').value;
                    var oCommentPanel = document.getElementById('commentsdisplaypanel');
                    if(oCommentPanel.style.display=="none")
                        oCommentPanel.style.display ='';
                    
                    var objBlogcmtCnt = document.getElementById('blogcommentcount');
                    var objReadcmtcnt = document.getElementById('divcommentcnt');
                    var BlogcmtCnt="";
                    var Readcmtcnt="";
                    
                    if(objBlogcmtCnt!=null)
                    {
                        BlogcmtCnt = document.getElementById('blogcommentcount').innerHTML;
                        BlogcmtCnt = ++BlogcmtCnt
                        objBlogcmtCnt.innerHTML="";
                        objBlogcmtCnt.innerHTML = BlogcmtCnt; 
                    }
                    if(objReadcmtcnt!=null)
                    {
                        Readcmtcnt = BlogcmtCnt;
                        objReadcmtcnt.innerHTML="";
                        objReadcmtcnt.innerHTML = "Comments (" + Readcmtcnt + ")"; 
                    }
                    //showreplies('c',contentid);
                    sText = "Your Comment Saved Successfully.";
                    fnWait(true,sText);
                    SULEKHA.Commnets.wait.setBody("<div align='left'><h6>Go to</h6><ul class='thankulist'><li><a href='" + sTitleurl.replace('/comments/comments.htm','/comments.htm') +"'>Read other comments</a></li><li><a href='http://blogs.sulekha.com'>Blogs home page</a></li><li><a href='"+sTitleurl.replace('/comments/comments.htm','.htm')+"'>Current Blog</a></li></ul></div><br/><p align='right'><span class='linkbutton yellow_but yellow_but_plain'><a href='javascript:close();'>Post another comment</a></span>&nbsp;<span class='linkbutton yellow_but yellow_but_plain'><a href='http://www.sulekha.com/mp/dashboard.aspx'>Go to Dashboard</a></span></p>");
                    //window.location.href = window.location.href;
                }
                else if(Type=="photocomment")
                {
                    window.location.href = window.location.href;
                }
                else 
                {
                   if(objResult.style.display="none")
                          objResult.style.display="";
                    objResult.innerHTML=Result;
                }
                document.getElementById('txtcomment').value="";
                recordParticipationMetric('/post/comment/'+Type);  
            }
            else if(Result =="abuse")
            {
                if(objResult.style.display="none")
                      objResult.style.display="";
                 objResult.innerHTML ="Your Comment contains abusive content.So please change and post again.";
            }
        }
    };
    var handleCommmentFailure = function(o)
    {
        var Result = o.status + " " + o.statusText;
        alert("Transaction failed.  The error is: " + Result);
    };
    
   
    
function showreplies(type,parentcommentid)
{
    fnWait(true,"Loading comments, Please wait...");
    var sAction="";
    var ShowReplycallback =
    {
            success: ShowReplySuccess,
            failure: ShowReplyFailure,
            argument: [parentcommentid,type]
//            customevents:{
//            onStart:ShowRepliesTransactionObject.start,
//            onComplete:ShowRepliesTransactionObject.complete,
//            onSuccess:ShowRepliesTransactionObject.success,
//            onFailure:ShowRepliesTransactionObject.failure,
//            onAbort:ShowRepliesTransactionObject.abort
//            }
            
    };
    if(type == "nc")
        sAction="getnestedcomments";
    else if(type =="c")
        sAction="getcomments"; 
    else if(type =="pc")
        sAction="getphotocomments";
    else if(type =="sc")
        sAction ="singlecomments"; 
    
    YAHOO.util.Connect.asyncRequest('POST', '/mp/postacomment.aspx?action='+ sAction + '&hdparentcommentid=' + parentcommentid, ShowReplycallback);
}

var ShowRepliesTransactionObject = {
	    start:function(type, args){
	    //alert("start");
	                YAHOO.namespace("sulekha.container");
                    if (!YAHOO.sulekha.container.wait) 
                    {
                        YAHOO.sulekha.container.wait = new YAHOO.widget.Panel("wait",{x:200, width: "240px", fixedcenter: true, close: false, draggable: false, modal: true,visible: false } );
                        YAHOO.sulekha.container.wait.setHeader("Loading, please wait...");
                        YAHOO.sulekha.container.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
                        YAHOO.sulekha.container.wait.render(document.body);
                        YAHOO.sulekha.container.wait.show();
                    }
	    },
	    complete:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    success:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    failure:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    abort:function(type, args){ YAHOO.sulekha.container.wait.hide();}
    };
    var ShowReplySuccess = function(sResult)
    {
        fnWait(false,''); 
        var Result =sResult.responseText;
        var Parentcommentid = sResult.argument[0];
        var Type = sResult.argument[1];
        var objShowReply = document.getElementById('showreply'+Parentcommentid);
        var ObjHideReply = document.getElementById('hidereply'+Parentcommentid);
        var ObjCommentDisplaypanel = document.getElementById('commentsdisplaypanel');
//        if(Type =="pc")
//            ObjCommentDisplaypanel = document.getElementById('photocommentsdisplaypanel');
        
        if(Result !== undefined)
        {
            if (Result == 'not loggedin')
            {
                window.location.href='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
            }
            else if(Result !='not loggedin' && Result != "")
            {
               if(Type=="nc")
               {
                   ObjHideReply.style.display="none";
                   if(objShowReply.style.display="none")
                        objShowReply.style.display="";
                   objShowReply.innerHTML =Result; 
               }
               else if(Type=="c" || Type =="pc" || Type =="sc")
               {
                    //alert(ObjCommentDisplaypanel); 
                    //alert(ObjCommentDisplaypanel.style.display);
                    if(ObjCommentDisplaypanel.style.display="none")
                        ObjCommentDisplaypanel.style.display="";
                    ObjCommentDisplaypanel.innerHTML = Result;
               }
               
            }
            else if(Result =="abuse")
            {
    //            var objResult= document.getElementById('commentresult');
    //            if(objResult.style.display="none")
    //                  objResult.style.display="";
    //             objResult.innerHTML ="Your Commnet contains abusive content.So please change and post again.";
            }
        }
    };
    var ShowReplyFailure = function(o)
    {
        fnWait(false,''); 
        var Result = o.status + " " + o.statusText;
        alert("Transaction failed.  The error is: " + Result);
    };
  
function hidereplies(parentcommentid)
{
     var objShowReply = document.getElementById('showreply'+parentcommentid);
     var ObjHideReply = document.getElementById('hidereply'+parentcommentid);
     //alert(objShowReply.style.display + ObjHideReply.style.display);
     //alert(objShowReply.id + ObjHideReply.id);
     if(objShowReply.style.display =="" || objShowReply.style.display =="block")
        objShowReply.style.display="none";
     else
        objShowReply.style.display="block";
     
     if(ObjHideReply.style.display =="none")
        ObjHideReply.style.display="block";
     else
        ObjHideReply.style.display="none";
}

function showallcomments(contentid)
{
    fnWait(true,'Loading comments, Please wait...');
    var sAction="";
    var ShowReplycallback =
    {
            success: ShowReplySuccess,
            failure: ShowReplyFailure,
            argument: [parentcommentid,type]
//            customevents:{
//            onStart:ShowRepliesTransactionObject.start,
//            onComplete:ShowRepliesTransactionObject.complete,
//            onSuccess:ShowRepliesTransactionObject.success,
//            onFailure:ShowRepliesTransactionObject.failure,
//            onAbort:ShowRepliesTransactionObject.abort
//            }
            
    };
    if(type == "nc")
        sAction="getnestedcomments";
    else if(type =="c")
        sAction="getcomments"; 
    YAHOO.util.Connect.asyncRequest('POST', '/mp/postacomment.aspx?action='+ sAction + '&hdparentcommentid=' + parentcommentid, ShowReplycallback);
}

function showvotes(service)
{
    
}
function fnrecommend(service)
{
    var oCommentForm = document.getElementById('leavecomment');
    
    var oRate = "";
    if(document.getElementById('ratingcount')!=null)
        oRate = document.getElementById('ratingcount').innerHTML;
    //alert(oRate);
    fnWait(true,'Saving recommendation, please wait...');
    var Recommendcallback =
    {
        success: RecommendSuccess,
        failure: ShowReplyFailure,
        argument: [service,oRate]
//        customevents:{
//        onStart:RecommendTransactionObject.start,
//        onComplete:RecommendTransactionObject.complete,
//        onSuccess:RecommendTransactionObject.success,
//        onFailure:RecommendTransactionObject.failure,
//        onAbort:RecommendTransactionObject.abort
//        }
    };
    if (fnGetCookie('sulekha_screenname') != null)
    {
        YAHOO.util.Connect.setForm(oCommentForm);
        if(service =="blogentries" || service =="photoentries")
            YAHOO.util.Connect.asyncRequest('POST', '/mp/recommends.aspx?servicename=' + service, Recommendcallback);
    }
    else
        window.location.href ='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
    
}

var RecommendSuccess = function(sResult)
{
    fnWait(false,''); 
    var Result=sResult.responseText;
    var Ratevalue = sResult.argument[1];
    var Service = sResult.argument[0];
    //alert(Ratevalue);
    if(sResult!==undefined)
    {
        if(Ratevalue!=null)
        {
            if(Ratevalue == Result)
            {
                var Oerror= document.getElementById('errormsg');
                if(Oerror!=null)
                {
                    if(Service =="blogentries")
                        Oerror.innerHTML = 'You have already recommended this blog.'; 
                    else if(Service =="photoentries")
                        Oerror.innerHTML = 'You have already voted this photo.'; 
                }
            }
            
        }
        if(Result!='' && (Result.indexOf('error') < 0 ))
        { 
            document.getElementById('ratingpanel').style.display='';
            document.getElementById('ratingcount').innerHTML = Result; 
        }
    }
}

 var RecommendTransactionObject = {
	    start:function(type, args){
	    //alert("start");
	                YAHOO.namespace("sulekha.container");
                    if (!YAHOO.sulekha.container.wait) 
                    {
                        YAHOO.sulekha.container.wait = new YAHOO.widget.Panel("wait",{x:200, width: "240px", fixedcenter: true, close: false, draggable: false, modal: true,visible: false } );
                        YAHOO.sulekha.container.wait.setHeader("Saving recommendation, please wait...");
                        YAHOO.sulekha.container.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
                        YAHOO.sulekha.container.wait.render(document.body);
                        YAHOO.sulekha.container.wait.show();
                    }
	    },
	    complete:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    success:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    failure:function(type, args){ YAHOO.sulekha.container.wait.hide();},
	    abort:function(type, args){ YAHOO.sulekha.container.wait.hide();}
    };
    
    
function fnchangedisporder()
{
    var objOrder = document.getElementById('dispoption');
    var sUrl = window.location.href;
    var sQry = '?';
    
    if (sUrl.indexOf('?') >= 0)
        sQry = '&';
    if (sUrl.indexOf('?mode') >= 0)
    {
        sUrl= sUrl.substring(0,sUrl.indexOf('?mode'));
        sQry = '?';
    }
    else if (sUrl.indexOf('&mode') >= 0)
    {
        sUrl= sUrl.substring(0,sUrl.indexOf('&mode'));
        sQry = '&'; 
    }
     if (sUrl.indexOf('&sort') >= 0)
    {
        sUrl+= sUrl.substring(0,sUrl.indexOf('&sort'));
        sQry = '&'; 
    }
  
    if (objOrder.value == 0)
        sUrl = sUrl + sQry + 'mode=normal';
    else if(objOrder.value == 1)
        sUrl = sUrl + sQry + 'mode=expand';
    else if(objOrder.value == 2)
        sUrl = sUrl + sQry + 'mode=collapse';
        
    window.location.href = sUrl;
 }
function fnchangesortorder()
{
    var objOrder = document.getElementById('sortoption');
    var sUrl = window.location.href;
    var sQry = '?';
    
    if (sUrl.indexOf('?') >= 0)
        sQry = '&';
    if (sUrl.indexOf('?sort') >= 0)
    {
        sUrl= sUrl.substring(0,sUrl.indexOf('?sort'));
        sQry = '?'
    }
    else if (sUrl.indexOf('&sort') >= 0)
    {
        sUrl= sUrl.substring(0,sUrl.indexOf('&sort'));
        sQry = '&';
    }
    
    if(objOrder.value == 0)
         sUrl = sUrl + sQry + 'sort=desc';
    else if(objOrder.value == 1)
         sUrl = sUrl + sQry + 'sort=asc';

    window.location.href = sUrl;
}
function fnSetdisptype()
{
    var objDispOrder = document.getElementById('dispoption');
    var Qryvalue = window.location.href;
    if(Qryvalue.indexOf('mode')>=0)
    {
        if(Qryvalue.indexOf('normal') >= 0 )
            objDispOrder.options[0].selected = true;
        else if(Qryvalue.indexOf('expand') >= 0)
            objDispOrder.options[1].selected = true;
        else if(Qryvalue.indexOf('collapse') >= 0)
            objDispOrder.options[2].selected = true;
        else
            objDispOrder.options[1].selected = true;
    }
    else
    {
        objDispOrder.options[1].selected = true;
    }
}   
function fnSetsorttype()
{
    var objSortOrder = document.getElementById('sortoption');
    var Qryvalue = window.location.href;
    
    if(Qryvalue.indexOf('sort')>=0)
    {
        if(Qryvalue.indexOf('desc') >= 0)
            objSortOrder.options[0].selected = true;
        else if(Qryvalue.indexOf('asc') >= 0)
            objSortOrder.options[1].selected = true;
        else
            objSortOrder.options[0].selected = true;
    }
    else
    {
        objSortOrder.options[0].selected = true;
    }
}   

function fnChkLogin()
{
    sChkLogin=0;
    if (fnGetCookie('sulekha_screenname') != null)
        sChkLogin=1;    
    else
        window.location.href ='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
}
function Result_Login(result)
{
    if (result == 'false')
        window.location.href ='http://www.sulekha.com/network/signin.aspx?nexturl='+window.location.href;
    else
        sChkLogin=1;
}

function fnShowInputBox(obj)
{
//alert(obj);
    var inputobj = document.getElementById('input'+obj);
    if (inputobj.style.display == "block")
    {
        inputobj.style.display='none'; 
        inputobj.innerHTML ='';
    }    
    else
    {
        inputobj.innerHTML='<br/><label class=lblcomment>Discuss:</label>&nbsp;&nbsp;<textarea onfocus="javascript:fnChkLogin();" ID="comment" name="comment"  Rows="8" style="width:450px;"></textarea><br/><br/><center><span class="linkbutton"><a id="bSave" class="linkbutton" style="color:white;" href="javascript:fnSaveComment('+ obj +');">Save Comment</a></span></center>';
        inputobj.style.display='block'; 
    }    
}

function fnEditorPostComment(obj)
{
    //var contentid = document.getElementById('hParentCid').value;
    var contentid = document.getElementById('hCid'+obj).value;
    var userhost = getCookie('sulekha_baseaddress');
    var postingurl = '';
    
    if (userhost == 'http://www.sulekha.com/myhome.aspx')
        postingurl = 'http://www.sulekha.com/mp/postcommentv2.aspx?cid=' + contentid + '&type=comment#txttitle';
    else
        postingurl = userhost + '/mp/postcommentv2.aspx?cid=' + contentid + '&type=comment#txttitle';
        
    //http://mahadevanalagar.sulekha.com/mp/postcommentv2.aspx?cid=172294#txttitle
    //alert(postingurl);
    window.location.href = postingurl;
}




var CommentslisthandleSuccess = function(o)
    {
	  fnWait(false,'');
      o.responseText; 
      alert('your post successfull');   
    }
    var CommentslisthandleFailure = function(o)
    {
	    fnWait(false,'');
    }
    var callback_fnGetSaveComments = 
    {
        success:CommentslisthandleSuccess,
        failure:CommentslisthandleFailure
    }     
    function fnGetSaveComments(obj)
    {   
      var contentid = document.getElementById('hCid'+obj).value;
      var comments = document.getElementById('comment'+obj).value + '';
      var inputobj = document.getElementById('input'+obj);
      var parentcontentid = document.getElementById('hBaseId').value;
      var baseid = 0;
  
     if (contentid != parentcontentid)
          baseid = parentcontentid;
     if (comments == '')
      {
        alert('Please Fill The Form');
      }
    else
      {
        fnWait(true,'Saving Comment, Please wait');
        var sScreenName = '';
        if (fnGetCookie('sulekha_screenname') != null)
         {
            sScreenName = fnGetCookie('sulekha_screenname');
         }
        iObj = obj;

     YAHOO.util.Connect.asyncRequest('GET','/network/MemberProfile.asmx/fnSavenestComment?sCommentCid='+contentid+'&sComments='+comments+'&sBaseId='+baseid+'&sCurrentUser='+sScreenName,callback_fnGetSaveComments);
    }  
}


function fnLoadComment(commentcid)
{

    icommentcid = commentcid;
    var outputobj = document.getElementById('displaynestcomment-' + commentcid);
    if (outputobj.style.display == "block")
    {
        outputobj.style.display="none";
    }
    else
    {
        if (outputobj.innerHTML.length == 0)
        {
            Sulekha.WebService.MemberPages.MemberProfile.fnLoadMultipleCommentByID(commentcid, callback_fnLoadComment); 
        }    
        else
            outputobj.style.display="block";
    }       
}
function callback_fnLoadComment(result)
{
    var outputobj = document.getElementById('displaynestcomment-'+icommentcid);
    outputobj.style.display="block";
    outputobj.innerHTML = result;
   
}


function fnWait(sWait,headtext)
{
    //YAHOO.namespace("sulekha.container");
    if (sWait) 
    {
        SULEKHA.Commnets.wait = new YAHOO.widget.Panel("wait",{fixedcenter: true, width: "350px",close: false, draggable: false, modal: true,visible: false } );
        SULEKHA.Commnets.wait.setHeader(headtext);
        SULEKHA.Commnets.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
        SULEKHA.Commnets.wait.render(document.body);
        SULEKHA.Commnets.wait.show();
    }
    else
        SULEKHA.Commnets.wait.hide();
}

function fnshowratingvalue()
{
    var objRatingpanel = document.getElementById('ratingpanel');
    var objRatingCnt = document.getElementById('ratingcount');
    var sRatecnt = document.getElementById('hdratecnt').value;
    var objReadcmtcmtLink = document.getElementById('showreadcommentslink');
    if(objReadcmtcmtLink!=null)
        objReadcmtcmtLink.style.display='block';
    //alert(objReadcmtcmtLink.style.display);
    if(sRatecnt!='0' && sRatecnt !='')
    {
        objRatingpanel.style.display='';
        objRatingCnt.innerHTML = sRatecnt ;
    }
    
}
function fnCheckCommentscnt()
{
    var objCommentsoptionpanel = document.getElementById('commentoptionpanel');
    var sCommentcnt = document.getElementById('hdcommentcnt').value;
    if(sCommentcnt!='0' && sCommentcnt !='')
        objCommentsoptionpanel.style.display='';
}
function close()
{

    fnWait(false,''); 
    window.location.href=window.location.pathname;
}