function Request(sid, reqid, base, queryalAl, backupqual, htserver, loc)  {
    this.sid  = sid;
    this.reqid  = reqid;
    this.base  = base;
    this.queryalAl = queryalAl;
    this.backupqual = backupqual;
    this.htserver = htserver;
    this.location = loc;
};

function refresh (sid, reqid, base, queryalAl, backupqual, htserver, loc, h4update){
  debug("refresh: "+getTimeStamp());
  debug("base: "+base);
  initDocument (h4update);
  pushCheckedItems ();
  showInfo ();
  req= new Request (sid, reqid, base, queryalAl, backupqual, htserver, loc, h4update);
  if (queryalAl != "-") {
    mapDbItems ();
  }
  displaySubtrees ();
}

function cartDel ( recordid ,alink, atext, blink, btext) {
  jQuery.get('/vascoda',
    { SERVICE: "TEMPLATE", SUBSERVICE: "MERKLISTE_RAUS",
      SID: req.sid, HIT: recordid, AJAX: "TRUE"
    },
    function (cpd) {
      var _node=  jQuery('#jscartlist');
      var _link= "cartPut('"+recordid+"','"+blink+"','"+btext+"','"+alink+"','"+atext+"');return false;";
      if (_node.length > 0) {
        _node.empty().append( cpd.getElementsByTagName('cartlistlength').item(0).firstChild.data );
        jQuery('#cartput_' + recordid).empty().append('<a class="marker" href="'+alink+'" onclick="'+_link+'" title="'+atext+'"><img alt="'+atext+'" src="/' + req.location + '/images/icon_marker_e.gif"/></a>');
      }
      _node= jQuery('#cartstate');
      if (_node.length > 0) {
        _node.empty().append('<a class="marker" href="'+alink+'" onclick="'+_link+'" title="'+atext+'">'+atext+'</a>');
      }
    }
  );
}

function cartPut ( recordid ,alink, atext, blink, btext) {
  jQuery.get('/vascoda',
    { SERVICE: "TEMPLATE", SUBSERVICE: "MERKLISTE_REIN",
      SID: req.sid, HIT: recordid, AJAX: "TRUE",
      QUERY_alAL: req.queryalAl, USE_HTSERVER: req.htserver
    },
    function (cpd) {
      var _node=  jQuery('#jscartlist');
      var _link= "cartDel('"+recordid+"','"+blink+"','"+btext+"','"+alink+"','"+atext+"');return false;";
      if (_node.length > 0) {
        _node.empty().append( cpd.getElementsByTagName('cartlistlength').item(0).firstChild.data );
        jQuery('#cartput_' + recordid).empty().append('<a class="marker" href="'+alink+'" onclick="'+_link+'" title="'+atext+'"><img alt="'+atext+'" src="/' + req.location + '/images/icon_marker_i.gif"/></a>');
      }
      _node= jQuery('#cartstate');
      if (_node.length > 0)
        _node.empty().append('<a class="marker" href="'+alink+'" onclick="'+_link+'" title="'+atext+'">'+atext+'</a>');
    }
  );
}

var col1IsVisible = false;
function toggleCol1 () {
  if ( col1IsVisible ) {
    jQuery("#columns").removeClass("open").addClass("close");
    col1IsVisible = false;
  }
  else {
    jQuery("#columns").removeClass("close").addClass("open");
    col1IsVisible = true;
  }
  return false;
}

function suchmaske_leeren () {
   window.alert("Suchmaske wird geleert!");
  jQuery('#f_search').val('');
  $('#f_i1_all:checkbox').val(["on"]);
  jQuery('#f_i1_val').val('');
  jQuery('#f_i2_val').val('');
  jQuery('#f_i3_val').val('');
  jQuery('#f_i4_val').val('');
  }

/**
 *  Klasse fuer erweiterte Suchfelder
 *  added KS20090424
 *****************************************************************************/
function cExtendedFieldset () {
    var m_it = this;
    var m_sDiv = null; 
    var m_xDiv = null; 
    var state = null;
    var msg_reset_search = null;
    var msg_simplesearch = null;
    var msg_extsearch = null;
    var msg_htserver_ext = null;
    this.initialize = function (sElem, xElem) {
        m_sDiv = sElem;
        m_xDiv = xElem;
        /* window.alert( $('#initial_searchstate').html() ); */
        state = $('#initial_searchstate').html();
        msg_reset_search = $('#msg_reset_search').html();
        msg_simplesearch = $('#msg_simplesearch').html();
        msg_extsearch = $('#msg_extsearch').html();
        msg_htserver_ext = $('#msg_htserver_ext').html();
        $('<a href="#" class="reset" onclick="suchmaske_leeren()">'+msg_reset_search+'</a><br/>').insertBefore('#searchhelp');
        if ( state == "SIMPLE_SEARCH" ) {
            $(m_xDiv).hide ();
            $(m_sDiv).show ();
            // $('#QUERY_alAL_label').css('width', 'auto');
            $('#cb_extsearch').attr("value", "false");
            $('<a href="#" id="btclick" class="intern">'+msg_extsearch+'</a>').insertAfter('#searchhelp');
            $('#btclick').click(m_it.toggleDisplay);
            $('#USE_HTSERVER').attr("title", "");
        }
        else if ( state == "EXTSEARCH" ) {
            $(m_sDiv).hide();
            $(m_xDiv).show();
            // $('#QUERY_alAL_label').css('width', '');
            $('#cb_extsearch').attr("value", "true");
            $('<a href="#" id="btclick" class="intern">'+msg_simplesearch+'</a>').insertAfter('#searchhelp');
            $('#btclick').click(m_it.toggleDisplay);
            $('#USE_HTSERVER').attr("title", msg_htserver_ext);
        }
    },
    this.toggleDisplay = function () {
        if ( state == "SIMPLE_SEARCH" ) {
            // if ( ! m_it.checkFields() ) { return false; }
            state = "EXTSEARCH";
        }
        else {
            state = "SIMPLE_SEARCH";
        }
        $('#btclick').empty()
        if ( state == "SIMPLE_SEARCH" ) {
            $(m_xDiv).hide();
            $(m_sDiv).show();
            $('#cb_extsearch').attr("value", "false");
            // $('#f_search').attr("value", $('#f_i1_val').attr("value"));
            // $('#QUERY_alAL_label').css('width', '');
            $('#btclick').text(msg_extsearch);
            $('#USE_HTSERVER').attr("title", "");
        }
        else {
            $(m_sDiv).hide();
            $(m_xDiv).show();
            $('#cb_extsearch').attr("value", "true");
            // $('#f_i1_id').attr("value", "ANY");
            // $('#f_i1_val').attr("value", $('#f_search').attr("value"));
            // $('#QUERY_alAL_label').css('width', 'auto');
            $('#btclick').text(msg_simplesearch);
            $('#USE_HTSERVER').attr("title", msg_htserver_ext);
        }
        return true;
    },
    this.checkFields = function () {
        var modified = 0;
        $('div.extended_search > * > input:text, div.extended_search > * > select').each(function(){
            var id = $(this).attr("id");
            var val = $(this).attr("value");
            if ($(this).attr("name") == "COUNT") {
                var n = Number(val);
                if (n != 10) 
                    ++modified;
            }
            else if ($(this).attr("name") == "GWTIMEOUT") {
                var n = Number(val);
                if (n != 30) 
                    ++modified;
            }
            else {
                if (val != null) {
                    val = jQuery.trim(val);
                    if (val.length)
                        ++modified;
                }
            }
        });
        return !modified;
    }
    return false;
}

jQuery(document).ready(
  function () {
    // jQuery('<a href="#" id="navibutton"><img src="/' + loc + '/images/button_hide-navi.gif" width="17" height="173" alt="Navigation ausblenden" /></a>').prependTo("#col1");
    // col1IsVisible = true;
    // jQuery("#navibutton").bind("click", toggleCol1);
// KS20090423
    var xFieldSet = new cExtendedFieldset ().initialize ($('.simple_search'), $('.extended_search'));
  }
);
