        var xmlHttp;
		var url="http://blog.nationmultimedia.com";


		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("please input blog name");
				return false;
			 }

	        loading();
			document.getElementById("record").disabled=true;
			url=url+"/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;
			//alert(url);
			xmlHttp=GetXmlHttpObject(stateChangedFavorites);
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		
		} 



		function stateChangedFavorites(){ 

				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					alert('save favorite blog complete');
					document.getElementById("record").disabled=false;
					endLoading();
					document.getElementById("favorite_name").value='';
					hideFavorite();
				} 
		} 





		function vote(status,blog_id){ 

	        voting();
			url=url+"/home/vote.php?sid=" + Math.random()+"&status="+status+"&blog_id="+blog_id;
			xmlHttp=GetXmlHttpObject(stateChangedVote);
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		
		} 



		function stateChangedVote(){ 

				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					document.getElementById("status_vote").innerHTML=xmlHttp.responseText;
				} 
		} 




		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

		}


		
		function voting(){
			    document.getElementById("status_vote").style.display='';
				document.getElementById("status_vote").innerHTML="Vote  . . .";
		}


      function endVoting(){
           document.getElementById("status_vote").style.display='none';
	  }



		function loading(){
				document.getElementById("status_text").innerHTML="recording  . . .";
		}


      function endLoading(){
           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('please input data');
				}
		}


		function editor_insertHTML(tmp,what){
			document.DataEntryForm.comment_detail.value = document.DataEntryForm.comment_detail.value+' '+what;
			document.DataEntryForm.comment_detail.focus();
		}


		function sendMail(mail){
			  window.open("/mailto.php?email="+mail,"tofriend","top=150,left=200,toolbar=0,location=0,directories=0,status=1,statusbar=0,menuBar=0,scrollBars=0,resizable=0,width=300,height=200");
		}

		function sendMailFriend(link){
			  window.open("/maillink.php?link="+link,"tofriend","top=150,left=200,toolbar=0,location=0,directories=0,status=1,statusbar=0,menuBar=0,scrollBars=0,resizable=0,width=300,height=200");
		}


		function sendMSG(id){
			  window.open("http://blog.nationmultimedia.com/msgbox_new/receive_box.php?receiver_id="+id,"tofriend","top=150,left=200,toolbar=0,location=0,directories=0,status=1,statusbar=0,menuBar=0,scrollBars=0,resizable=0,width=300,height=200");
		}

		function printWindow(){
				browserVersion = parseInt(navigator.appVersion)
				if (browserVersion >= 4) window.print()
		}
