function trim(arg)
{
  return leftTrim(rightTrim(arg));
}

function leftTrim(arg)
{
  return arg.replace(/^\s*/, '');
}

function rightTrim(arg)
{
  return arg.replace(/\s*$/, '');
}

function isEmpty(arg)
{
  return trim(arg) == '';
}

function copyToClipboard( ) {
    var inElement = document.getElementById( "searchResults" );

    if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range)
            range.execCommand('Copy');
    } else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="/dojo/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }
}

 function getHighlightedText( ) {
     var txt = '';
     if (window.getSelection) {
        txt = window.getSelection();
     } else if (document.getSelection) {
        txt = document.getSelection();
     } else if (document.selection) {
        txt = document.selection.createRange().text;
     }
     return txt;
 }

 function newSearch ( text ) {
     document.reSearchForm.searchText.value = text;
     document.reSearchForm.submit();
 }

 function extendCurrentSearch ( text ) {
     document.reSearchForm.searchText.value = document.reSearchForm.searchText.value + " " + text;
     document.reSearchForm.submit();
 }

 function dealWithPopupMenu ( command ) {
     var txt = getHighlightedText();

     if ( txt == '' ) {
         dijit.byId("menu1").setDisabled ( true );
         dijit.byId("menu2").setDisabled ( true );
         dijit.byId("menu3").setDisabled ( true );
     } else {
         dijit.byId("menu1").setDisabled ( false );
         dijit.byId("menu2").setDisabled ( false );
         dijit.byId("menu3").setDisabled ( false );
     }
 }

function showFieldList ( ) {
    window.open( 'fieldlist.html', 'fieldlist', 'width=500,height=400,menubar=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes' );
}

function browseNamespaceForSimpleSearch ( baseUrl ) {
    window.open( 'http://ndans1.nda.hu/index.php?eiszsearch=true&url=' + baseUrl + '/namespaceSimple.html' , 'namespace', 'width=840,height=580,menubar=no,toolbar=no,status=yes,resizable=yes,scrollbars=yes' );
}

function selectNamespaceEntityForSimpleSearch( id, name ) {
    form = document.getElementById( "mainForm" );

    if ( !isEmpty( form.searchText.value )) {
        form.searchText.value = form.searchText.value + ' vagy ("' + name + '")';
    } else {
        form.searchText.value = '"' + name + '"';
    }
}

function registerErrorTimeout () {
    setTimeout( "openSimpleSearchPage();//--", 20000 );
}

function openSimpleSearchPage () {
    window.location = "index.html";
}
