       var xmlHttp;

   ///////// editor 








        function saveEditor(){

            var firm=window.confirm('คุณต้องการสมัคร Editor?');
			if(firm==true){
				var editor_blog_id=document.getElementById("editor_blog_id").value;
				var editor_user_id=document.getElementById("editor_user_id").value;
				var editor_nickname=document.getElementById("editor_nickname").value;
		

				loadingEditor();
				var url="http://story.yenta4.com/home/gen_editor.php?sid=" + Math.random()+"&blog_id="+editor_blog_id+"&user_id="+editor_user_id+"&user_nick="+editor_nickname;
				xmlHttp=GetXmlHttpObject(stateChangedEditor);
				xmlHttp.open("GET", url , true);
				xmlHttp.send(null);
			}

		}


		var k=0;
		var o;
		function loadingEditor(){
		    document.getElementById("status_editor").style.display='';
			if(k==0){
				document.getElementById("status_editor").innerHTML="กำลังสมัคร  . . .";
				k++;
			}else if(k==1){
				document.getElementById("status_editor").innerHTML="กำลังสมัคร    ";
				k++;
			}else if(k==2){
				document.getElementById("status_editor").innerHTML="กำลังสมัคร  . ";
				k++;
			}else{
				document.getElementById("status_editor").innerHTML="กำลังสมัคร  . . ";
				k=0;
			}
			o=setTimeout("loadingEditor()",500);

		}



		function stateChangedEditor(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					endLoadingEditor();
					document.getElementById("status_editor").style.display='';
					document.getElementById("status_editor").innerHTML=xmlHttp.responseText ;

				} 
		} 

        function endLoadingEditor(){
           clearTimeout(o);
           document.getElementById("status_editor").style.display='none';
	    }



////////



		function saveFavorite(){ 
            var favorite_name=document.getElementById("favorite_name").value;
			var favorite_blog_id=document.getElementById("favorite_blog_id").value;
			var favorite_user_id=document.getElementById("favorite_user_id").value;
			var favorite_blog_name=document.getElementById("favorite_blog_name").value;
			 if (favorite_name=="") {
				alert("กรอกข้อมูลด้วยคับ");
				return false;
			 }

	        loading();
			if (favorite_name.length > 0){ 
			    document.getElementById("record").disabled=true;
				var url="http://story.yenta4.com/home/gen_favorites.php?sid=" + Math.random()+"&name="+favorite_name+"&blog_id="+favorite_blog_id+"&user_id="+favorite_user_id+"&favorite_blog_name="+favorite_blog_name;
				xmlHttp=GetXmlHttpObject(stateChanged);
				xmlHttp.open("GET", url , true);
				xmlHttp.send(null);
			}else{ 
			 
			} 

		} 






		function stateChanged(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					endLoading();
					document.getElementById("status_text").style.display='';
					document.getElementById("status_text").innerHTML=xmlHttp.responseText ;
					//document.getElementById("status_text").innerHTML="บันทึกเรียบร้อยแล้ว";
					document.getElementById("favorite_name").value='';
					document.getElementById("record").disabled=false;
				} 
		} 


		function GetXmlHttpObject(handler){ 

					 var objXmlHttp=null;

					if(navigator.userAgent.indexOf("Opera")>=0){
								alert("This example doesn't work in Opera") ;
								return 
					}
					if (navigator.userAgent.indexOf("MSIE")>=0){ 

								var strName="Msxml2.XMLHTTP";

								if(navigator.appVersion.indexOf("MSIE 5.5")>=0){
											strName="Microsoft.XMLHTTP";
								}

								try{ 
											objXmlHttp=new ActiveXObject(strName);
											objXmlHttp.onreadystatechange=handler ;
											return objXmlHttp;
								}catch(e){ 
											alert("Error. Scripting for ActiveX might be disabled") ;
											return ;
								} 

				  } 


				 if (navigator.userAgent.indexOf("Mozilla")>=0){
							objXmlHttp=new XMLHttpRequest();
							objXmlHttp.onload=handler;
							objXmlHttp.onerror=handler ;
							return objXmlHttp;
				 }

		} 



   //// end ajax


       function hideFavorite(){
            document.getElementById("favorite_form").style.display='none';
		    document.getElementById("status_text").style.display='none';
	   }


		function TrimString(sInString) {

		  sInString = sInString.replace( /^\s+/g, "" );// strip leading
		  return sInString.replace( /\s+$/g, "" );// strip trailing

		}


		var c=0;
		var t;
		function loading(){
		    document.getElementById("status_text").style.display='';
			if(c==0){
				document.getElementById("status_text").innerHTML="กำลังบันทึกข้อมูล  . . .";
				c++;
			}else if(c==1){
				document.getElementById("status_text").innerHTML="กำลังบันทึกข้อมูล    ";
				c++;
			}else if(c==2){
				document.getElementById("status_text").innerHTML="กำลังบันทึกข้อมูล  . ";
				c++;
			}else{
				document.getElementById("status_text").innerHTML="กำลังบันทึกข้อมูล  . . ";
				c=0;
			}
			t=setTimeout("loading()",500);

		}


      function endLoading(){
           clearTimeout(t);
           document.getElementById("status_text").style.display='none';
	  }

        function addFavorite(){
         document.getElementById("favorite_form").style.display='';
	   }


 /////////////// emotion

		function showEmo() {
			   el = document.getElementById('emoticon');
			   if(el.style.display == 'none'){
					  el.style.display = '';
			   }else{
					 el.style.display = 'none';							
			   }
		}


		function Initialize() {
			   el = document.getElementById('emoticon');
			   if(el.style.visibility == 'visible'){
					  el.style.visibility = 'hidden';
			   }else{
					  t= getAbsoluteOffsetTop(getObj('icons'));
					  l= getAbsoluteOffsetLeft(getObj('icons'));
					 el.style.top=t;
					 el.style.left=l;
					 el.style.visibility = 'visible';							
			   }
		}

		
		 function getObj(id) {
			return document.getElementById(id);
		 }

		 function getAbsoluteOffsetTop(obj) {
			var top = obj.offsetTop;
			var parent = obj.offsetParent;
			while (parent != document.body) {
				top += parent.offsetTop;
				parent = parent.offsetParent;
			}
			return top;
		 }
		 
		 function getAbsoluteOffsetLeft(obj) {
			var left = obj.offsetLeft;
			var parent = obj.offsetParent;
			while (parent != document.body) {
				left += parent.offsetLeft;
				parent = parent.offsetParent;
			}
			return left;
		 }



		function check() {
				frm = document.DataEntryForm;
				if(frm.comment_name.value != '' && frm.comment_detail.value != ''){
					frm.sub.value = 'กำลังบันทึกข้อมูล ............';
					frm.sub.disabled = true;
					frm.submit();
				}else{
					alert('กรุณาใส่ข้อมูลให้ครบถ้วนด้วยครับ');
				}
		}


		function editor_insertHTML(tmp,what){
			document.DataEntryForm.comment_detail.value = document.DataEntryForm.comment_detail.value+' '+what;
			document.DataEntryForm.comment_detail.focus();
		}

          function openCategory(name,value){
			  window.location='http://story.yenta4.com/'+name+'/category/'+value;
		}
		function openArchives(name,value){
			   if(value!=0) window.location='http://story.yenta4.com'+name+'/'+value;
		}
		function openFavorite(value){
			   if(value!=0) window.open('http://.story.yenta4.com/'+value);
		}