function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}



// INPUT Felder

function focus_(obj_) {
  obj_ = this;
  obj_.style.color = "#595A5A";
  obj_.style.backgroundColor ="#FFFFE5";
  obj_.focus();
  obj_.select();
  if(obj_.value == obj_.title) {
    obj_.value ="";
  }
}

function blur_(obj_) {
  obj_ = this;
  //alert(obj_.id)
  obj_.style.backgroundColor ="#FFFFFF";
  if(obj_.value.length == 0 || obj_.value == obj_.title) {
    obj_.value = obj_.title;
    if(obj_.id == "qs_inp") {
      obj_.style.color = "#969696";
    } else
      obj_.style.color = "#595A5A";
  }
}

/*function over_(obj_) {
  obj_ = this;
  obj_.style.backgroundColor ="#FFFFE5";
}

function out_(obj_) {
  obj_ = this;
  obj_.style.backgroundColor ="";
}*/

function getInpToFocus() {
  //if (!document.getElementById) return
  inp = document.getElementsByTagName("input");
  are = document.getElementsByTagName("textarea");
  for(i=0; i<inp.length; i++) {
    inp[i].onfocus = focus_;
    inp[i].onblur = blur_;
    //inp[i].onmouseover = over_;
    //inp[i].onmouseout = out_;
  }
  for(i=0; i<are.length; i++) {
    are[i].onfocus = focus_;
    are[i].onblur = blur_;
    //are[i].onmouseover = over_;
    //are[i].onmouseout = out_;
  }
}

function checkSearchVal(str) {
 if(isNaN(str) != true && str != "") {
  var goID = 'index.php?id='+ str;
  window.location.href = goID;
  return false;
 }
 if(str == document.qs_form.elements[0].title | str == "") {
  alert('Bitte geben Sie einen Suchbegriff oder eine Seiten-ID ein!');
  document.qs_form.elements[0].focus();
  document.qs_form.elements[0].select();
  return false;
 }
 else return true;
}


/* Using jQuery to prevent form submit when enter is pressed */
$(document).ready(function(){ 

  $("form").bind("keypress", function(e) {
    if (e.keyCode == 13) {
      search_solr();
      return false;
    }
  });
  
  
/*  Search */
  $( "#content" ).show();

  function search_solr() {    
    var toLoad = '/search/RH/solr.jsp?&searchlib=1';
    var searchtxt = $('#searchtxt').val();
    var searchlib = $('#searchlib').val();
    
    //   alert (searchterm);
    
    $('#container').addClass("no_background");    
    $('#content').hide();
    $('#solr_search').empty();
    $('#solr_search').slideUp('slow', loadContent);
    
    function loadContent() {
      $.ajax({
        type: 'GET',
        url: toLoad,
        data: {'searchtxt': searchtxt },
        dataType: 'html',
        
        success: function(data, textStatus) {
          $("#solr_search").html($("#solr_result",$(data)).html());
        },
        error: function(xhr, textStatus, errorThrown ){
          alert('Error!' + errorThrown );
        }
      });
    }
    $('#solr_search').fadeIn('normal');
  }
  
  $('.solr_button').click(search_solr);
  
  $(".search-browsebox a").live('click', function(){
    var moreLink = ($(this).attr("href"));
    //alert (moreLink);
    $('#solr_search').load(moreLink+' #solr_result');
    return false;
  });

  
  
  
  //font resizer
  $("#up").fontscale("#content_area,#left,#textsize","up",{unit:"percent",increment:15});
  $("#down").fontscale("#content_area,#left,#textsize","down",{unit:"percent",increment:15});  
  $("#reset").fontscale("#content_area,#left,#textsize","reset");
  
  //menu   
  $("ul.sf-menu").superfish();
  
  //$("#footer_right").tipTip();
  $(".tooltip").tipTip({maxWidth: "170px", edgeOffset: 0});
  
  //2colum table
  $('.csc-bulletlist').makeacolumnlists({cols:2,colWidth:0,equalHeight:false,startN:1});
  $('.csc-menu').makeacolumnlists({cols:2,colWidth:0,equalHeight:false,startN:1});
  
  //Shadowbox
  Shadowbox.init({
    handleOversize: "drag",
    overlayColor: "#999999",
    overlayOpacity: "0.9"
  });
  
  //scrollpane parts
  var scrollPane = $( ".scroll-pane" ),
      scrollContent = $( ".scroll-content" );
  
  //build slider
  var scrollbar = $( ".scroll-bar" ).slider({
    slide: function( event, ui ) {
      if ( scrollContent.width() > scrollPane.width() ) {
        scrollContent.css( "margin-left", Math.round(
          ui.value / 100 * ( scrollPane.width() - scrollContent.width() )
        ) + "px" );
      } else {
        scrollContent.css( "margin-left", 0 );
      }
    }
  });
  
  
  
  function openFile(file) { 
  }
  
  $('#rh_database').fileTree({ 
    root: '/data/www/fileadmin/html_datenbasis/RH-Datenbasis/',
    script: 'fileadmin/scripts/jqueryFileTree.php',
    expandSpeed: 1000,
    collapseSpeed: 1000,
    multiFolder: true
    //   }, 
    //   function(file) {
    //       openFile(file);
  });
  
});

// Grauer BG für linke Nav
/*
$(window).load(function() {
  $(window).resize(function(){
    var window_h = $(window).height();
    var container_h = $('#container').height();
    if (window_h < container_h) {
      $('#left').css('height', $('#container').height()-40);
      $('#right').css('height', $('#container').height()-80);
    }
    else {
      $('#left').css('height', $(window).height()-220);
      $('#right').css('height', $(window).height()-129);
    };
  });
  $(window).resize();
});
*/
// Horizontal Scroll (Zeitstrahl)

$(document).ready(function(){
  $("#content-slider").slider({
    animate: true,
    change: handleSliderChange,
    slide: handleSliderSlide
  });
});


function handleSliderChange(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").animate({scrollLeft: ui.value * (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100) });
}
