function message(){
	
	this.message_click_content=0;
	this.message_click_name=0;
	
	this.element='';
	this.time=0;
	// แสดงตัวอักษรวิ่ง
	this.list=function(){
		this.message_click_content=0;
		this.message_click_name=0;
		
		var j = new ajax();
		j.jaxinit();
		j.show_pleasewait=false;
		j.processOnly=true;
		j.addvar("cmd","message");
		j.addvar("mode","show_marquee");
		j.processajax("index.php");
		document.getElementById(this.element).innerHTML=j.responseText;
	}
	// แสดง Form สำหรับ Add 
	this.add=function(){
		var j = new ajax();
		j.jaxinit();
		j.show_pleasewait=false;
		j.addvar("cmd","message");
		j.addvar("mode","show_form");
		j.processajax("index.php","div_message");
			
		/*
		var j = new ajax();
		j.jaxinit();
		j.addvar("cmd","message");
		j.addvar("mode","chklogin"); // Check ว่า Login หรือยัง
		j.processOnly=true;
		j.processajax("index.php");
		
		if(j.responseText==1){
			j.jaxinit();
			j.show_pleasewait=false;
			j.addvar("cmd","message");
			j.addvar("mode","show_form");
			j.processajax("index.php","div_message");			
		}else{
			alert("กรุณา Login ก่อน");
		}*/
	}
	// Insert Data
	this.insert=function(content,name){
		if(this.message_click_content==0){
			alert("กรอก ข้อความ ด้วย ");
		}else if(this.message_click_name==0){
			alert("กรอก ชื่อ ด้วย ");
		}else if(content.length>100){
			alert("ข้อความเกิน 100 ตัวอักษร");	
		}else{
			var j = new ajax();
			j.jaxinit();
			j.addvar("content",encodeURI(content));
			j.addvar("name",encodeURI(name));
			j.addvar("cmd","message");
			j.addvar("mode","insert");
			j.processOnly=true;
			j.processajax("index.php");	
			
			if(j.responseText==1){
				alert("บันทึกข้อมูลเรียบร้อยแล้ว");	
				this.list();
			}else{
				alert("Error : ไม่สามารถบันทึกข้อมูลได้");	
			}		
		} //end  content.length>100
	}	
	// Set Input Box = ""
	this.setvaluenull_content=function(obj){
		if(!this.message_click_content){	
			obj.value='';	
			this.message_click_content=1;
		}
	}
	this.setvaluenull_name=function(obj){
		if(!this.message_click_name){	
			obj.value='';	
			this.message_click_name=1;
		}
	}	
	
	this.recur=function(){
		if(document.getElementById(this.element)){
			this.list();
			clearTimeout(this.time);
		}else{
			this.time=setTimeout("this.recur("+this.element+")",1000);
		}	
	}	
	
} //end class message