/**
 * instantiates a new xmlhttprequest object
 *
 * @return xmlhttprequest object or false
 */
function getXMLRequester( )
{
    var xmlHttp = false;
            
    // try to create a new instance of the xmlhttprequest object        
    try
    {
        // Internet Explorer
       
        // Mozilla, Opera und Safari
        if( window.XMLHttpRequest )
        {
            xmlHttp = new XMLHttpRequest();
        } else if( window.ActiveXObject )
        {
            for( var i = 8; i; i-- )
            {
                try
                {
                    // loading of a newer version of msxml dll (msxml3 - msxml5) failed
                    // use fallback solution
                    // old style msxml version independent, deprecated
                    if( i == 2 )
                    {
                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }
                    // try to use the latest msxml dll
                    else
                    {
                        
                        xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
                    }
                    break;
                }
                catch( excNotLoadable )
                {                        
                    xmlHttp = false;
                }
            }
        }
    }
    // loading of xmlhttp object failed
    catch( excNotLoadable )
    {
        xmlHttp = false;
    }
    return xmlHttp ;
}

function mozInsert(txtarea, openTag, closeTag)
{
  var scrollTop = ( typeof(txtarea.scrollTop) == 'number' ? txtarea.scrollTop : -1 );

  if (txtarea.selectionEnd > txtarea.value.length) { txtarea.selectionEnd = txtarea.value.length; }

  var startPos = txtarea.selectionStart;
  var endPos = txtarea.selectionEnd+openTag.length;

  txtarea.value=txtarea.value.slice(0,startPos)+openTag+txtarea.value.slice(startPos);
  txtarea.value=txtarea.value.slice(0,endPos)+closeTag+txtarea.value.slice(endPos);

  txtarea.selectionStart = startPos+openTag.length;
  txtarea.selectionEnd = endPos;
  txtarea.focus();

  if( scrollTop >= 0 ) { txtarea.scrollTop = scrollTop; }
}
     
function storeCaret (textEl) {
 if (textEl.createTextRange) 
   textEl.caretPos = document.selection.createRange().duplicate();
   //alert("store");
}
function insertAtCaret (textEl, text) {
 if (textEl.createTextRange && textEl.caretPos) {
   
   //alert(textEl.createTextRange);
   //alert(textEl.caretPos.text);
   var caretPos = textEl.caretPos;
   caretPos.text = '['+text+']' + textEl.caretPos.text +'[/'+text+']';
   
   
 }
 else if ((textEl.selectionEnd | textEl.selectionEnd == 0) && (textEl.selectionStart | textEl.selectionStart == 0))
     {
        mozInsert(textEl, '['+text+']', '[/'+text+']');
     }
 else
 {
  alert("else");
  textEl.value  = text;
 }
 storeCaret(textEl);
}



