
function silentDelete(p_id)
{

    if (window.XMLHttpRequest)     // Object of the current windows
    {
            request = new XMLHttpRequest();     // Firefox, Safari, ...
            //request.overrideMimeType('text/xml');
    }
    else
    if (window.ActiveXObject)   // ActiveX version
    {
           request = new ActiveXObject('Microsoft.XMLHTTP');    // Internet Explorer
    }
    request.onreadystatechange = function()
    {

        // instructions to process the response
        if (request.readyState == 4)
            {
            // received, OK
            if (request.status == 200) 
            {

                //tuwas
    			document.getElementById('p' + p_id).style.display = 'none';	
    			
            }

        } else
        {
           // wait...
        }
    }    
    request.open('GET', 'include/silent_delete.php?p_id=' + p_id, true);
    request.send(null);
}

function silentDeleteComment(comment_id)
{

    if (window.XMLHttpRequest)     // Object of the current windows
    {
            request = new XMLHttpRequest();     //Firefox, Safari, ...
            //request.overrideMimeType('text/xml');
    }
    else
    if (window.ActiveXObject)   // ActiveX version
    {
           request = new ActiveXObject('Microsoft.XMLHTTP');    //Internet Explorer
    }
    request.onreadystatechange = function()
    {

        // instructions to process the response
        if (request.readyState == 4)
            {
            // received, OK
            if (request.status == 200) 
            {
    			document.getElementById('com_id' + comment_id).style.display = 'none';		
            }

        } else
        {
           // wait...
        }
    }    
    request.open('GET', 'include/silent_delete_comment.php?comment_id=' + comment_id, true);
    request.send(null);
}

function commentPost(post_id)
{
    if(document.getElementById('com' + post_id).style.display == 'block')
    {	
        document.getElementById('com' + post_id).style.display = 'none';	    
    }
    else
    {    
        document.getElementById('save'+post_id).style.display = 'block';
        document.getElementById('com' + post_id).style.display = 'block';
		
		findComments(post_id);		
    }  
}

function findComments(post_id)
{
             
    //hier dann per ajax auf comments.php zugreifen.
        
    if (window.XMLHttpRequest)     // Object of the current windows
    {
            request = new XMLHttpRequest();     // Firefox, Safari, ...
            //request.overrideMimeType('text/xml');
    }
    else
    if (window.ActiveXObject)   // ActiveX version
    {
           request = new ActiveXObject('Microsoft.XMLHTTP');    // Internet Explorer
    }
    request.onreadystatechange = function()
    {

        // instructions to process the response
        if (request.readyState == 4)
        {
        
            // received, OK
            if (request.status == 200) 
            {

                //tuwas	
                //var doc = req.responseXML;   // assign the Xml file to a var
                //var element = doc.getElementsByTagName('root').item(0);   // read the first element with a dom's method
                var el = request.responseXML.childNodes[0];
                var el2;
				var icount = 1;
				var newcontent = "";
				                				
                if ( el.childNodes.length > 0)
                {				
                
                    document.getElementById('com' + post_id).innerHTML = "";
                    newcontent += "<h3>Comments:</h3><ul class = \"commentlist\" id = \"comments" + post_id + "\">";
                    for(i = 0; i < el.childNodes.length; i++)
                    {
                    
                        el2 = el.childNodes[i];
                        newcontent += '<li id = "com_id' + el2.childNodes[5].childNodes[0].nodeValue + '" '; 
                        if(icount % 2 == 0)
                        {
                            newcontent += 'class = "evenpost">';
                        }
                        else
                        {
                            newcontent += 'class = "oddpost">';
                        }
                        newcontent += '<img src = "http://www.gravatar.com/avatar.php?gravatar_id=' + el2.childNodes[3].childNodes[0].nodeValue + '&amp;size=36" alt = "gravatar" class = "photo" />'; 
                        newcontent += '<h4>' + el2.childNodes[0].childNodes[0].nodeValue + ' sagt:</h4>'; 
                        newcontent += '<p>' + el2.childNodes[1].childNodes[0].nodeValue + '</p>'; 
                        newcontent += '<p>' + el2.childNodes[2].childNodes[0].nodeValue + '</p>'; 
                        if(el2.childNodes[4].childNodes[0].nodeValue == '1')
                        {
                            newcontent += '<p><a href = "javascript:silentDeleteComment(' + el2.childNodes[5].childNodes[0].nodeValue + ')"><img src = "http://philippwagenblast.de/assets/images/famfam/comment_delete.png" alt = "delete" /></a></p>'; 
                        }
                        newcontent += '</li>'; 
                        
                        icount += 1;
                       
                    }
                    newcontent += "</ul>";
                    
                    //das sollte im prinzip alles nicht hier sein...
                    newcontent += "<div class = \"commentform\" id = \"save" + post_id + "\">"; 
	                newcontent += "<h3>Comment!</h3>";
				    newcontent += "<span class = \"desc\">";
        		    newcontent += "<label for =\"uname" + post_id + "\">username:</label>";
                    newcontent += "<label for = \"email" + post_id + "\">email:</label>";
                    newcontent += "<label for = \"cont" + post_id + "\">text:</label>";
				    newcontent += "</span>";
				    newcontent += "<span class = \"items\">";
                    newcontent += "<input id = \"uname" + post_id + "\" type = \"text\" name = \"username\" />";
                    newcontent += "<input id = \"email" + post_id + "\" type = \"text\" name = \"email\" />";
				    newcontent += "<input id = \"cont" + post_id + "\" type = \"text\" name = \"text\" />";
				    newcontent += "</span>";
	                newcontent += "<a href = \"javascript:postComment('" + post_id+ "')\" style = \"margin: 0 auto; width: 10em;\"><img src = \"http://philippwagenblast.de/assets/images/famfam/comments_add.png\" alt = \" \" /> save comment</a>";
					newcontent += "</div>";
                    
                    
				    document.getElementById('com' + post_id).innerHTML = newcontent;
				    document.getElementById('com' + post_id).display = "inline";
                }
				
            }
        } 
        else
        {
           // wait...
        }
    }
    
    request.open('GET', 'include/comments.php?pid=' + post_id, true);
    request.send(null);  
        

}

function postComment(post_id)
{
              
    var name = document.getElementById('uname'+post_id).value;    
    var email = document.getElementById('email'+post_id).value;    
    var cont = document.getElementById('cont'+post_id).value;    
          
    //hier dann per ajax drauf zugreifen.
        
    if (window.XMLHttpRequest)     // Object of the current windows
    {
            request = new XMLHttpRequest();     // Firefox, Safari, ...
            //request.overrideMimeType('text/xml');
    }
    else
    if (window.ActiveXObject)   // ActiveX version
    {
           request = new ActiveXObject('Microsoft.XMLHTTP');    // Internet Explorer
    }

    request.onreadystatechange = function()
    {

        // instructions to process the response

        if (request.readyState == 4)
        {
             
                
            // received, OK
            if (request.status == 200) 
            {

                //tuwas	
                findComments(post_id);
                document.getElementById('save'+post_id).style.display = 'none';
            }
        } 
        else
        {
           // wait...
        }
    }
    
    if(name != "")
    {
        if(email != "")
        {
            request.open('GET', 'include/savecomment.php?pid=' + post_id + '&name=' + name + '&email=' + email + '&cont=' + cont, true);
            request.send(null);  
        }  
    }
}

function silentLog(post_id)
{
          
    //hier dann per ajax drauf zugreifen.
        
    if (window.XMLHttpRequest)     // Object of the current windows
    {
            request = new XMLHttpRequest();     // Firefox, Safari, ...
            //request.overrideMimeType('text/xml');
    }
    else
    if (window.ActiveXObject)   // ActiveX version
    {
           request = new ActiveXObject('Microsoft.XMLHTTP');    // Internet Explorer
    }

    request.onreadystatechange = function()
    {

        // instructions to process the response

        if (request.readyState == 4)
        {
                
            // received, OK
            if (request.status == 200) 
            {
                    //tuwas	
            }
        } 
        else
        {
           // wait...
        }
    }
    
    request.open('GET', 'include/log.php?pid=' + post_id, true);
    request.send(null);  

}

 function showhideDelete(lid)
{
      docid = document.getElementById(lid);
      
      if(docid.style.display == 'none')
      {
          docid.style.display = 'inline';
      }
      else
      {
          docid.style.display = 'none';
      }	  
}
function editInplace(pid, content)
{
    
    var newcontent = "";
    
    //@: editieren, sonst speichern
    if(content == '@')
    {
        newcontent += "<input type = \"text\" id = \"cdesc" + pid + "\" name = \"newext\" value = \"add description\" /> <a href = \"#\" onclick =\"saveInplace('" + pid + "')\">save</a>";
    }
    else 
    {
        newcontent += content;
    }    
    document.getElementById('desc' + pid).innerHTML = newcontent;
    
    
}
function saveInplace(pid)
{
       
    var newdesc = document.getElementById('cdesc' + pid).value;    
          
    //hier dann per ajax drauf zugreifen.
        
    if (window.XMLHttpRequest)     // Object of the current windows
    {
            request = new XMLHttpRequest();     // Firefox, Safari, ...
            //request.overrideMimeType('text/xml');
    }
    else
    if (window.ActiveXObject)   // ActiveX version
    {
           request = new ActiveXObject('Microsoft.XMLHTTP');    // Internet Explorer
    }

    request.onreadystatechange = function()
    {

        // instructions to process the response

        if (request.readyState == 4)
        {
             
                
            // received, OK
            if (request.status == 200) 
            {

                //tuwas	
                editInplace(pid, newdesc);
            
            }
        } 
        else
        {
           // wait...
        }
    }
    
    request.open('GET', 'include/saveInplace.php?pid=' + pid + '&desc=' + newdesc, true);
    request.send(null);  
        

}


