/************************************************************************************
* vBSEO Auto Save for vBulletin v3.6.x by Crawlability, Inc.                        *
*-----------------------------------------------------------------------------------*
* http://www.crawlability.com/                                                      *
************************************************************************************/

function vBSEO_replyalert()
{
	var link_ajax = null;
	var editor = null;
	var me = this;
	var oldcontent = '';
	var saveobj;
	var lastpost = 0;
	var postid = 0;

    this.check_reply = function()
    {
       	if((typeof(ajax_last_post)!='undefined') 
	       	&& (ajax_last_post > me.lastpost))
       	{
       		me.dismiss();
   			me.lastpost = ajax_last_post;
       	}

        return false;
    }

    this.dismiss = function()
    {
		fetch_object('qr_ralert').style.display = 'none';
   		fetch_object('qr_ralert_td').innerHTML = '';
        return false;
    }

    this.reply_alert = function(threadid)
    {
       	this.link_ajax = new vB_AJAX_Handler(true);
       	this.link_ajax.onreadystatechange(this.ralert_ready);
       	
       	var par = 'do=ralert&threadid=' + threadid +'&lastpost='+me.lastpost;

       	if(me.editor && me.editor.editwin && me.editor.editwin.hasfocus)
       		this.link_ajax.send("ajax.php?" + par, par);

        return false;
    }

    this.ralert_ready = function()
    {
    	if (me.link_ajax.handler.readyState == 4 && me.link_ajax.handler.status == 200)
    	{
    		if (me.link_ajax.handler.responseXML)
    		{
    			var rXML = me.link_ajax.handler.responseXML;
    			var B=rXML.getElementsByTagName("postbit");
    			var L=rXML.getElementsByTagName("lastpost")[0].firstChild.nodeValue;
    			if(L>0 && (L != me.lastpost))
    			{
        			if(B.length)
	    			for(var D=0;D<B.length;D++)
    				{
        				fetch_object('qr_ralert').style.display = '';
    		   			fetch_object('qr_ralert_td').innerHTML += B[D].firstChild.nodeValue;
    		   		}
	    	   		else
    	   			{
    	   				me.dismiss();
	   		   		}

	        		me.lastpost = L;
        		}
    		}

    		if (is_ie)
    		{
    			me.link_ajax.handler.abort();
    		}
    	}
    }

    this.show_post = function(postid)
    {
    	me.postid = postid;
    	YAHOO.util.Connect.asyncRequest("POST","showpost.php?p="+postid,
	    	{
    		success:this.display_post,
    		timeout:vB_Default_Timeout,
	    	scope:this
	    	},
    	SESSIONURL+"securitytoken="+SECURITYTOKEN+"&ajax=1&replyalert=1&postid="+postid
    	);
    	return false;
    };


    this.display_post = function(A)
    {
    	if(A.responseXML)
    	{
	    	var B=A.responseXML.getElementsByTagName("postbit");
    		if(B.length)
    		{
			    var C = fetch_object("ralert"+me.postid);
		    	C.innerHTML = B[0].firstChild.nodeValue;
    			PostBit_Init(fetch_object("post"+me.postid), me.postid);
	    	}
	    }
    }
    return true;
}
