function createObjectHttp() {
   var xmlhttp = false;
   try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch(e) {
      try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
         xmlhttp = false;
      }
   }

   if(!xmlhttp && document.createElement){
      xmlhttp = new XMLHttpRequest();
   }

   return xmlhttp;
}

function resultUrl(Url, Operation) {

   var notCatch = Math.floor(Math.random() * 10000);
   Url += "&notCatch=" + notCatch;

   xmlhttp = createObjectHttp();
   xmlhttp.open(Operation, Url, false);

   if(Operation == "POST") {
      xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620");
   }

   xmlhttp.send(null);

   /* 
   Make sure that the transaction has finished. The XMLHttpRequest object 
   has a property called readyState with several states:
   0: Uninitialized
   1: Loading
   2: Loaded
   3: Interactive
   4: Finished 
   */

   if( xmlhttp.readyState == 4 ) {
      if( xmlhttp.status == 200 )
         return xmlhttp.responseText;
      else
         return false;
   }
   else
      return false;
}

function replaceText(text, textarea)
{
   // Attempt to create a text range (IE).
   if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
   {
      //alert('ie');
      var caretPos = textarea.caretPos;

      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
      caretPos.select();
   }
   // Mozilla text range replace.
   else if (typeof(textarea.selectionStart) != "undefined")
   {
      //alert('Mozilla');
      var begin = textarea.value.substr(0, textarea.selectionStart);
      var end = textarea.value.substr(textarea.selectionEnd);
      var scrollPos = textarea.scrollTop;

      textarea.value = begin + text + end;

      if (textarea.setSelectionRange)
      {
         textarea.focus();
         textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
      }
      textarea.scrollTop = scrollPos;
   }
   // Just put it on the end.
   else
   {
      //alert('else');
      textarea.value += text;
      textarea.focus(textarea.value.length - 1);
   }
}
