var xmlHttp;

function comment_page( category_type, foreign_id, smIndex )
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="/comment.php";
    url=url+"?smIndex="+escape(smIndex);
    url=url+"&category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);

}
function comment_delete( comment_id, category_type, foreign_id, smIndex )
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="/comment.php";
    url=url+"?smIndex="+escape(smIndex);
    url=url+"&category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    url=url+"&task=comment_delete";
    url=url+"&comment_id="+escape(comment_id);
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);

}

function subtree_delete( comment_id, category_type, foreign_id, smIndex )
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="/comment.php";
    url=url+"?smIndex="+escape(smIndex);
    url=url+"&category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    url=url+"&task=subtree_delete";
    url=url+"&comment_id="+escape(comment_id);
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);

}

function reply_delete( reply_id, category_type, foreign_id, smIndex )
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    var url="/comment.php";
    url=url+"?smIndex="+escape(smIndex);
    url=url+"&category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    url=url+"&task=reply_delete";
    url=url+"&reply_id="+escape(reply_id);
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);

}

function user_ban( user_id, category_type, foreign_id, smIndex )
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    
    var url="/comment.php";
    url=url+"?smIndex="+escape(smIndex);
    url=url+"&category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    url=url+"&task=user_ban";
    url=url+"&user_id="+escape(user_id);
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);

}



function comment_answer( rid, category_type, ccid, level, smIndex, foreign_id )
{
    //alert("Äÿêóºìî çà Âàøó ðåïë³êó!");
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

   //var poststr = encodeURI(document.getElementById("textarea_"+rid+"_"+ccid).value);
    var poststr = document.getElementById("textarea_"+rid+"_"+ccid).value;
    
    document.getElementById("comm_added_"+rid+"_"+ccid).innerHTML = '';
    
    poststr = poststr.replace(/\n/gi,"<br>");

    document.getElementById("comm_added_"+rid+"_"+ccid).innerHTML = '<div align=center><img src="images/loading.gif" width="32" height="32" border="0"></div>';
        
  
    var url="/comment.php";
    url=url+"?rid="+escape(rid);
    url=url+"&category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    url=url+"&level="+escape(level);
    url=url+"&smIndex="+escape(smIndex);
    url=url+"&ccid="+escape(ccid);
    url=url+"&comment_text="+poststr;
    url=url+"&task=comment_answer";
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);
    
}

function save_comment( category_type, foreign_id, smIndex )
{
    //alert("Äÿêóºìî çà Âàø Êîìåíòàð!");
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }

    //var poststr = encodeURI(document.getElementById("review_text").value);
    var poststr = document.getElementById("review_text").value;
    
    document.getElementById("comm_added").innerHTML = '';
    
    document.getElementById("comm_added").innerHTML = '<div align=center><img src="images/loading.gif" width="32" height="32" border="0"></div>';
      
    //poststr = poststr.replace("\n","<br>");  

    poststr = poststr.replace(/\n/gi,"<br>");
	
    var url="/comment.php";
    url=url+"?category_type="+escape(category_type);
    url=url+"&foreign_id="+escape(foreign_id);
    url=url+"&smIndex="+escape(smIndex);
    url=url+"&review_text="+poststr;
    url=url+"&task=save_comment";
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.send(null);
    
}

function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        var response = xmlHttp.responseText;
        document.getElementById("comment_list").innerHTML = response;
    }
}

function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
        catch (e)
        {
            //Internet Explorer
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }

    return xmlHttp;
}