  var isIE = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ));
  
  function save()
  { 
  	if (isIE) if (document.comment_form.comment_text.createTextRange()) document.comment_form.comment_text.caretPos = document.selection.createRange().duplicate();
  }
  
  function insert(txt)
  {
  	if (document.comment_form.comment_text.createTextRange() && document.comment_form.comment_text.caretPos)
  	{      
  		var cp = document.comment_form.comment_text.caretPos; 
  		cp.text = cp.text.charAt(cp.text.length - 1) == " " ? txt + " " : txt;
  	}
  	
  	<!--else document.comment_form.comment_text.value += txt;-->
  	document.comment_form.comment_text.focus(cp);
  }
  
  function printpost(post)
  {
  	pp = window.open("printpost.php?post_id=" + post,"pp","location=no,statusbar=no,menubar=no,scrollbars=yes");
  	pp.focus();
  }
  
  function sendpost(post)
  {
  	sp = window.open("sendpost.php?post_id=" + post,"sp","width=630,height=400,location=no,statusbar=no,menubar=no,scrollbars=yes");
  	sp.focus();
  }
  
  function insert_smiley(sm)
  {
      if (isIE) insert(sm); document.comment_form.comment_text.value = document.comment_form.comment_text.value + " " + sm;
  }
  
  function insert_code(tag_desc,open_tag,close_tag)
  {
  	var sm = prompt(tag_desc,"");
      if (sm) {
  	  sm = open_tag+sm+close_tag;
  	} else {
  	  sm = "";
  	}
  	if (isIE) insert(sm); else document.comment_form.comment_text.value = document.comment_form.comment_text.value + " " + sm;
  }
  
  function preview_form()
  {
  	var win=window.open("", "p", "left=50,top=30,width=725,height=450,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
  
  	win.document.write("<html><body>");
  	win.document.write("<form name=\"p\" action=\"preview_post.php\" method=\"post\">");
  	var exists = eval(document.comment_form["user_name"]);
  	if (exists) {
  		win.document.write("<input type=\"hidden\" name=\"user_name\" value=\""+document.comment_form.user_name.value+"\">");
  	}
  
  	win.document.write("<input type=\"hidden\" name=\"comment_text\" value=\"\">");
  	win.document.write("<input type=\"hidden\" name=\"preview\" value=\"yes\">");
  	win.document.write("</form></html>");
  	win.document.p.comment_text.value = document.comment_form.comment_text.value;
  	win.document.p.submit();
  	win.focus();
  
  }