// JavaScript Document	    
var xmlHttp;

	function createXMLHttpRequest() {
	     if (window.ActiveXObject) {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 } 
			else if (window.XMLHttpRequest) {
			 xmlHttp = new XMLHttpRequest();
			 }
		}
		
//////////////////////////////
				function startRequest2(sIdstory) {
		    createXMLHttpRequest();
			var sId = document.getElementById("id").value;
			var sDb = document.getElementById("db").value;
			var sLayout = document.getElementById("layout").value;
					
		 document.getElementById("message").innerHTML='<div class="unnamed1" align="center"><img src="../image/wait.gif" alt="" /><br /><br />กำลังโหลดคอมเมนต์...</div>';
            xmlHttp.open("get", "../sad_page/ajax/story/sad_getcomment2.php?idstory=" + sIdstory + "&id="+ sId +"&db="+ sDb +"&layout="+ sLayout, true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                         document.getElementById("message").innerHTML = xmlHttp.responseText;
						commentbox(sIdstory);
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
		
/////////////////////////////
     		function commentbox(sIdstory) {
		    createXMLHttpRequest();
     
		 document.getElementById("box").innerHTML='<div class="unnamed1" align="center"><img src="../image/wait.gif" alt="" /><br /><br />กำลังโหลด...</div>';
            xmlHttp.open("get", "../sad_page/ajax/story/sad_commentbox.php?idstory=" + sIdstory  , true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                           document.getElementById("box").innerHTML = xmlHttp.responseText;
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
////////////////////////////////

    function Addcomment(idstory) {
		   createXMLHttpRequest();
		
		   var txt = document.getElementById("txt").value;
		   var id = document.getElementById("id").value;
			var member = document.getElementById("member").value;
			if(member== -1)
					 var name = document.getElementById("name").value;  
			document.getElementById("box").innerHTML='<div class="unnamed1" align="center"><img src="../image/wait.gif" alt="" /><br /><br />กำลังบันทึกข้อความ...</div>';
            xmlHttp.open("post","../sad_page/ajax/story/sad_comment.php", true);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");  
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						startRequest2(idstory);
                    } else {
                        saveResult("พบข้อผิดพลาด " + xmlHttp.statusText);
                    }
                }            
            };
		  xmlHttp.send("name="+name+"&idstory="+idstory+"&id="+id+"&member="+member+"&txt="+txt);   
        }
////////////////////////////
     	function show(id) {
		 createXMLHttpRequest();
		 document.getElementById("story").innerHTML='<div class="unnamed1" align="center"><img src="../image/wait.gif" alt="" /><br /><br />กำลังโหลด...</div>';
            xmlHttp.open("get", "../sad_page/ajax/story/sad_show.php?id=" + id , true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                       document.getElementById("story").innerHTML = xmlHttp.responseText;
						gettopic(id);
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
		
/////////////////////////////////
     		function gettopic(sIdstory) {
		    createXMLHttpRequest();
            xmlHttp.open("get", "../sad_page/ajax/story/sad_gettopic.php?idstory="+sIdstory , true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						document.getElementById("top").innerHTML = xmlHttp.responseText;   
						getcontent(sIdstory);
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
//////////////////////////////////
function getcontent(sIdstory) {
		    createXMLHttpRequest();
            xmlHttp.open("get", "../sad_page/ajax/story/sad_getcontent.php?idstory="+sIdstory , true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						document.getElementById("content_").innerHTML = xmlHttp.responseText;
						startRequest2(sIdstory);
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
/////////////////////////////
function getcontent(sIdstory) {
		    createXMLHttpRequest();
            xmlHttp.open("get", "../sad_page/ajax/story/sad_getcontent.php?idstory="+sIdstory , true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						document.getElementById("content_").innerHTML = xmlHttp.responseText;
						startRequest2(sIdstory);
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
/////////////////////////////////////////
function sent(sIdstory,div) {
		    createXMLHttpRequest();
            xmlHttp.open("get", "../sad_page/ajax/story/sad_sent.php?id="+sIdstory +"&div="+div, true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						document.getElementById(div).innerHTML = xmlHttp.responseText;
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
		
function sentok()
{
	document.getElementById('frm').innerHTML = '<div class="unnamed1" align="center">เรียบร้อยครับ</div> ' ;
}

function mark(idstory,iddiary) {
		    createXMLHttpRequest();
            xmlHttp.open("get", "../sad_page/sad_addbookmark2.php?idstory="+idstory+"&iddiary="+iddiary , true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						document.getElementById("mark").innerHTML = xmlHttp.responseText;
                    } else {
                        displayInfo("พบข้อผิดพลาด: " + xmlHttp.statusText); 
                    }
                }            
            };
            xmlHttp.send(null);
        }
		

////////////////////////////////////////////////////////////////////////
function close_(div) {document.getElementById(div).innerHTML = "";}
