function literatureSearch(filter) {
  
  if (filter.length > 0) {
    
    filter = filter.toLowerCase();
    
    products = document.getElementsByName('literature');
    for (var i = 0; i < products.length; i++) {
      product_id  = products[i].id.substring("literature_".length, products[i].id.length);
      
      description = $("#literature_description_" + product_id).val();
      product = $("#literature_" + product_id);
      descriptionList = description.split("\\s+");
      found = false;
      for (var j = 0; j < descriptionList.length && !found; j++) {
        found |= (descriptionList[j].toLowerCase().search(filter) >= 0);
      }
      
      if (found) {
        product.css({"display" : "block"});
      } else {
        product.css({"display" : "none"});
      }
      
    }
  } else {
    products = document.getElementsByName('literature');
    for (var i = 0; i < products.length; i++) {
      product = $("#literature_" + product_id);
      product.css({"display": "block"});
    }
  }
  
  productCategories = document.getElementsByName('literature_author');
  for (var i = 0; i < productCategories.length; i++) {
    visible = false;
    n = productCategories[i].nextSibling;
    while ((n) && (n.id) && (n.id.search("literature_author") < 0) && (!visible)) {
      if ((n.id.search(/literature/) >= 0)) {
        visible |= (n.style.display.search("block") >= 0);
      }
      n = n.nextSibling;
    }
    productCategories[i].style.display = (visible) ? "inline" : "none";
  }
  
  productCategories = document.getElementsByName('literature_category');
  for (var i = 0; i < productCategories.length; i++) {
    visible = false;
    n = productCategories[i].firstChild;
    while ((n) && (!visible)) {
      if ((n.id) && (n.id.search("literature_category") < 0) && (n.id.search("literature") >= 0)) {
        visible |= n.style.display == 'inline' || n.style.display == 'block';
      }
      n = n.nextSibling;
    }
    productCategories[i].style.display = (visible) ? "block" : "none";
  }
}

function filterTable(phrase, _id) {
	var words = phrase.value.toLowerCase().split(" ");
	var table = document.getElementById(_id);
	var ele;
	for (var r = 1; r < table.rows.length; r++){
		ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
	  var displayStyle = 'none';
	  for (var i = 0; i < words.length; i++) {
		  if (ele.toLowerCase().indexOf(words[i])>=0)
			  displayStyle = '';
		  else {
			  displayStyle = 'none';
			  break;
		  }
	  }
		table.rows[r].style.display = displayStyle;
	}
}

function filterTableCells(phrase, _id, showAll) {
  var words = phrase.value.toLowerCase().split(" ");
	var table = document.getElementById(_id);
	var ele;
	for (var r = 1; r < table.rows.length; r++){
	  for (var c = 0; c < table.rows[r].cells.length; c++){
	    if (showAll) {
        displayStyle = '';
      } else {
    		ele = table.rows[r].cells[c].innerHTML.replace(/<[^>]+>/g,"");
    	  var displayStyle = 'none';
    	  for (var i = 0; i < words.length; i++) {
    		  if (ele.toLowerCase().indexOf(words[i])>=0)
    			  displayStyle = '';
    		  else {
    			  displayStyle = 'none';
    		  }
    	  }
    	}
  		table.rows[r].cells[c].style.display = displayStyle;
  	}
	}
}

function filterPersonTable(phrase, _id, categorySearch, innerTablePrefix) {
	var words = phrase.value.toLowerCase().split(" ");
	var table = document.getElementById(_id);
	var ele;
	var title;
	var id;
	for (var r = 1; r < table.rows.length; r++){
	  id = table.rows[r].id;
	  title = $('#'+id).find('h2').html().toLowerCase();
	  id = id.substring(id.length - 4);
	  if (categorySearch) {
	    ele = id;
	  } else {
		  ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
		  ele = ele.toLowerCase();
		}
	  var displayStyle = 'none';
	  
	  var inTitle = false;
	  for (var i = 0; (i < words.length) && !inTitle; i++) {
		  if (title.indexOf(words[i])>=0) {
			  inTitle = true;
			}
	  }
	  
	  for (var i = 0; i < words.length; i++) {
		  if (ele.indexOf(words[i])>=0) {
			  displayStyle = '';
			  filterTableCells(phrase, innerTablePrefix + id, categorySearch || inTitle);
			} else {
			  displayStyle = 'none';
			  break;
		  }
	  }
		table.rows[r].style.display = displayStyle;		
	}
}

function filterSeminarTable(start_phrase, end_phrase, _id) {
  if (start_phrase.length == 10) {
    start_phrase = start_phrase.substring(6,10) + '-' +
                   start_phrase.substring(3,5) + '-' +
                   start_phrase.substring(0,2);
  } else if ((start_phrase.length == 4) && (start_phrase.indexOf(".") < 0)) {
    start_phrase += "-00-00";
  } else {
    start_phrase = "";
  }
  
  if (end_phrase.length == 10) {
    end_phrase = end_phrase.substring(6,10) + '-' +
                 end_phrase.substring(3,5) + '-' +
                 end_phrase.substring(0,2);
  } else if ((end_phrase.length == 4) && (end_phrase.indexOf(".") < 0)) { 
    end_phrase += "-99-99";
  } else {
    end_phrase = "";
  }
  
  if (end_phrase.length == 0) end_phrase = '9999-99-99';

  var table = document.getElementById(_id);
	var ele;
	var productId;
	var startDate;
	var endDate;
	var l = _id.length + 5;
	for (var r = 1; r < table.rows.length; r++){
	  productId = table.rows[r].id.substring(l);
	  
	  startDate = document.getElementById(_id + '_start_' + productId).value;
	  endDate = document.getElementById(_id + '_end_' + productId).value;
	  
	  if ((startDate >= start_phrase) && (startDate <= end_phrase))
	    displayStyle = '';
	  else
	    displayStyle = 'none';
	    
		table.rows[r].style.display = displayStyle;
	}
}

function filterSeminarTableByDepartment(department_phrase, _id) {
  var table = document.getElementById(_id);
	var productId;
	var department;
	var departments;
        var found;
	var l = _id.length + 5;
	for (var r = 1; r < table.rows.length; r++) {
	  productId = table.rows[r].id.substring(l);

          department = document.getElementById(_id + '_department_' + productId).value;
          departments = department.toLowerCase().split(" ");
	  
          found = department_phrase == 0;
  	  for (var j = 0; (j < departments.length) && !found; j++) {
            found |= department_phrase == departments[j];
          }

	  if (found)
	    displayStyle = '';
	  else
	    displayStyle = 'none';
	    
		table.rows[r].style.display = displayStyle;
	}
}

function sendMessage() {
  var email = $('#contact_email').val();
  var name = $('#contact_name').val();
  var captcha = $('#contact_captcha').val();

  var verified = true;

  //verify email
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
  if (email.search(emailRegEx) == -1) {
    verified = false;
    $('#contact_email').css({'color': 'red',
                             'border': '2px solid red',
                             'font-weight': 'bold'});
    $('#label_contact_email').css({'color': 'red',
                                   'font-weight': 'bold'});
    $('#contact_error_email').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_email').css({'color': 'black',
                             'border': '1px solid gray',
                             'font-weight': 'normal'});
    $('#label_contact_email').css({'color': 'black',
                                   'font-weight': 'normal'});
    $('#contact_error_email').css({'display': 'none'});
  }
  
  //verify name
  if (name.length == 0) {
    verified = false;
    $('#contact_name').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_name').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_name').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_name').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_name').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_name').css({'display': 'none'});
  }
  
  //verify captcha
  if (captcha.length < 5) {
    verified = false;
    $('#contact_captcha').css({'color': 'red',
                               'border': '2px solid red',
                               'font-weight': 'bold'});
    $('#label_contact_captcha').css({'color': 'red',
                                     'font-weight': 'bold'});
    $('#contact_error_captcha').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_captcha').css({'color': 'black',
                               'border': '1px solid gray',
                               'font-weight': 'normal'});
    $('#label_contact_captcha').css({'color': 'black',
                                     'font-weight': 'normal'});
    $('#contact_error_captcha').css({'display': 'none'});
  }
  
  if (verified) {
    $("#contact_form_container").css({"display" : "none"});
    $("#contact_form_wait").css({"display" : "block"});
  
    $.post('http://www.isi-hamburg.org/contact.php',
      {
        email:    email,
        name:     name,
        mode:     $('#contact_mode').val(),
        phone:    $('#contact_phone').val(),
        receiver: $('#contact_receiver').val(),
        subject:  $('#contact_subject').val(),
        message:  $('#contact_message').val(),
        captcha:  captcha,
        sendcopy: $('#send_copy:checked').val()
      },
      function(data) {
        $("#contact_form_wait").css({"display" : "none"});
        $("#contact_form_container").css({"display" : "block"});
        
	// spam protection
        if (data == '') {
          $('#contact_captcha').css({'color': 'red',
                                     'border': '2px solid red',
                                     'font-weight': 'bold'});
          $('#label_contact_captcha').css({'color': 'red',
                                           'font-weight': 'bold'});
          $('#contact_error_captcha').css({'display': 'block'});
          
          newCaptcha("captcha_image");
        } else {
          $('#contact_captcha').css({'color': 'black',
                                     'border': '1px solid gray',
                                     'font-weight': 'normal'});
          $('#label_contact_captcha').css({'color': 'black',
                                           'font-weight': 'normal'});
          $('#contact_error_captcha').css({'display': 'none'});
          
          $('#contact_form_container').html(data);
        }
      }
    );
    
  } else {
    
  }
}

function registerBooking() {
  var sex = $("input[@name='contact_sex']:checked").val()
  var firstname = $('#contact_first_name').val();
  var lastname = $('#contact_last_name').val();
  var extra = $('#contact_address_extra').val();
  var street = $('#contact_street').val();
  var house = $('#contact_house').val();
  var zip = $('#contact_zip').val();
  var city = $('#contact_city').val();
  var landline = $('#contact_landline').val();
  var mobile = $('#contact_mobile').val();
  var email = $('#contact_email').val();
  var bday = $('#contact_bday').val();
  var job = $('#contact_job').val();
  var message = $('#contact_message').val();
  var disclaimer = $('#contact_disclaimer').attr('checked'); 
  var captcha = $('#contact_captcha').val();
  var mode = $('#contact_mode').val();
  var product = $('#product_id').val();
  var numWorkshop = $('#optional_reg_entries').val();

  //get workshops
  var workshop = new Array();
  for (var i = 0; i < numWorkshop; i++) {
    workshop[i] = $('#workshop_' + product + '_' + i).val();
  }

  var verified = true;

  //verify email
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
  if (email.search(emailRegEx) == -1) {
    verified = false;
    $('#contact_email').css({'color': 'red',
                             'border': '2px solid red',
                             'font-weight': 'bold'});
    $('#label_contact_email').css({'color': 'red',
                                   'font-weight': 'bold'});
    $('#contact_error_email').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_email').css({'color': 'black',
                             'border': '1px solid gray',
                             'font-weight': 'normal'});
    $('#label_contact_email').css({'color': 'black',
                                   'font-weight': 'normal'});
    $('#contact_error_email').css({'display': 'none'});
  }
  
  //verify name
  if (firstname.length == 0) {
    verified = false;
    $('#contact_first_name').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_first_name').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_first_name').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_first_name').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_first_name').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_first_name').css({'display': 'none'});
  }
  
  if (lastname.length == 0) {
    verified = false;
    $('#contact_last_name').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_last_name').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_last_name').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_last_name').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_last_name').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_last_name').css({'display': 'none'});
  }

  //verify address
  if (street.length == 0) {
    verified = false;
    $('#contact_street').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_street').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_street').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_street').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_street').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_street').css({'display': 'none'});
  }

  if (house.length == 0) {
    verified = false;
    $('#contact_house').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_house').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_house').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_house').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_house').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_house').css({'display': 'none'});
  }

  if (zip.length < 5) {
    verified = false;
    $('#contact_zip').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_zip').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_zip').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_zip').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_zip').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_zip').css({'display': 'none'});
  }

  if (city.length == 0) {
    verified = false;
    $('#contact_city').css({'color': 'red',
                            'border': '2px solid red',
                            'font-weight': 'bold'});
    $('#label_contact_city').css({'color': 'red',
                                  'font-weight': 'bold'});
    $('#contact_error_city').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_city').css({'color': 'black',
                            'border': '1px solid gray',
                            'font-weight': 'normal'});
    $('#label_contact_city').css({'color': 'black',
                                  'font-weight': 'normal'});
    $('#contact_error_city').css({'display': 'none'});
  }

  //verify bday
  if (bday.length < 8) {
    verified = false;
    $('#contact_bday').css({'color': 'red',
                               'border': '2px solid red',
                               'font-weight': 'bold'});
    $('#label_contact_bday').css({'color': 'red',
                                     'font-weight': 'bold'});
    $('#contact_error_bday').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_bday').css({'color': 'black',
                               'border': '1px solid gray',
                               'font-weight': 'normal'});
    $('#label_contact_bday').css({'color': 'black',
                                     'font-weight': 'normal'});
    $('#contact_error_bday').css({'display': 'none'});
  }

  //verify disclaimer
  if (!disclaimer) {
    verified = false;
    $('#label_contact_disclaimer').css({'color': 'red',
                                     'font-weight': 'bold'});
    $('#contact_error_disclaimer').css({'display': 'block'});
  } else {
    verified &= true;
    $('#label_contact_disclaimer').css({'color': 'black',
                                     'font-weight': 'normal'});
    $('#contact_error_disclaimr').css({'display': 'none'});
  }

  //verify captcha
  if (captcha.length < 5) {
    verified = false;
    $('#contact_captcha').css({'color': 'red',
                               'border': '2px solid red',
                               'font-weight': 'bold'});
    $('#label_contact_captcha').css({'color': 'red',
                                     'font-weight': 'bold'});
    $('#contact_error_captcha').css({'display': 'block'});
  } else {
    verified &= true;
    $('#contact_captcha').css({'color': 'black',
                               'border': '1px solid gray',
                               'font-weight': 'normal'});
    $('#label_contact_captcha').css({'color': 'black',
                                     'font-weight': 'normal'});
    $('#contact_error_captcha').css({'display': 'none'});
  }
  
  if (verified) {
    $("#register_form_container").css({"display" : "none"});
    $("#register_form_wait").css({"display" : "block"});
  
    var time = new Date();  
    var millis = time.getTime();

    var arguments = {
      email:      email,
      sex:        sex,
      firstname:  firstname,
      lastname:   lastname,
      extra:      extra,
      street:     street,
      house:      house,
      zip:        zip,
      city:       city,
      landline:   landline,
      mobile:     mobile,
      bday:       bday,
      job:        job,
      disclaimer: disclaimer,
      message:    message,
      captcha:    captcha,
      mode:       mode,
      product:    product,
      workshops:  workshop.length,
    };

    for (var i = 0; i < workshop.length; i++) {
      arguments['workshop' + i] = workshop[i];
    }

    $.post('http://www.isi-hamburg.org/register.php?x=' + millis, arguments,
      function(data) {
        $("#register_form_wait").css({"display" : "none"});
        $("#register_form_container").css({"display" : "block"});
        
	// spam protection
        if (data == '') {
          $('#contact_captcha').css({'color': 'red',
                                     'border': '2px solid red',
                                     'font-weight': 'bold'});
          $('#label_contact_captcha').css({'color': 'red',
                                           'font-weight': 'bold'});
          $('#contact_error_captcha').css({'display': 'block'});
          
          newCaptcha("captcha_image");
        } else {
          $('#contact_captcha').css({'color': 'black',
                                     'border': '1px solid gray',
                                     'font-weight': 'normal'});
          $('#label_contact_captcha').css({'color': 'black',
                                           'font-weight': 'normal'});
          $('#contact_error_captcha').css({'display': 'none'});
          
          $('#register_form_container').html(data);
        }
      }
    );
    
  } else {
    
  }
}

function newCaptcha(id) {
  var time = new Date();  
  var millis = time.getTime();
  document.getElementById(id).src = "http://www.isi-hamburg.org/captcha/captcha.php?x=" + millis;
}

function toggleDisplay(id) {
  var e = $('#' + id);
  var show = e.css('display') == 'none';
  if (show)
    e.css({'display' : 'block'});
  else
    e.css({'display' : 'none'});
}

function hideDisplay(id) {
  var e = $('#' + id);
  var show = e.css('display') == 'none';
  if (!show)
    e.css({'display' : 'none'});
}

function showDisplay(id) {
  var e = $('#' + id);
  var show = e.css('display') == 'none';
  if (show)
    e.css({'display' : 'block'});
}

function toggleSlide(id) {
  var e = $('#' + id);
  if (e.is(":hidden"))
    showSlide(id);
  else
    hideSlide(id);
}

function hideSlide(id) {
  var e = $('#' + id);
  if (!e.is(":hidden"))
    e.slideUp("fast");
}

function showSlide(id) {
  var e = $('#' + id);
  if (e.is(":hidden"))
    e.slideDown("fast");
}

/////////////////////////////////////////////////////
// dialog stuff

$.ui.dialog.defaults.bgiframe = true;

function showFastContactDialog(personId) {
  var time = new Date();  
  var millis = time.getTime();

  $('body').append("<div id='popupFastContactDialog'>" + 
                   "<div id='contact_form_wait' style='padding-top:180px;'><table style='width:100%;'><tr><td style='text-align:center;'><img src='http://www.isi-hamburg.org/image/wait.gif' style='border-color:red;border-width:1px;border-style:solid;' /></td></tr></table></div>" +
                   "</div>");
  
  $("#popupFastContactDialog").dialog({
    modal: true,
    position: 'center',
    width: 395,
    height: 490,
    resizable: false,
    title: "Kontakt",
                   
    close: function(event, ui) {
      $("#popupFastContactDialog").dialog('destroy'); 
      $("#popupFastContactDialog").remove();
    }
  }).load('http://www.isi-hamburg.org/fast_contact.php', {person : personId, time : millis}, function(responseText, textStatus, XMLHttpRequest) {
    $("#popupFastContactDialog").dialog('option', 'title', $("#popupTitle").val());
    //alert($("#popupTitle").val());
  });
}

function closeFastContactDialog() {
  $("#popupFastContactDialog").dialog('close');
}

function closeFastRegisterDialog() {
  $("#popupRegisterDialog").dialog('close');
}

function showFastRegisterDialog(productId, numOptionalChoice, optionalItems) {
  var time = new Date();  
  var millis = time.getTime();

  $('body').append("<div id='popupRegisterDialog'>" + 
                   "<div id='register_form_wait' style='padding-top:180px;'><table style='width:100%;'><tr><td style='text-align:center;'><img src='http://www.isi-hamburg.org/image/wait.gif' style='border-color:red;border-width:1px;border-style:solid;' /></td></tr></table></div>" +
                   "</div>");
  
  $("#popupRegisterDialog").dialog({
    modal: true,
    position: 'center',
    width: 490,
    height: 610 + (numOptionalChoice * 30),
    resizable: false,
    title: "Online-Anmeldung",
                   
    close: function(event, ui) {
      $("#popupRegisterDialog").dialog('destroy'); 
      $("#popupRegisterDialog").remove();
    }
  }).load('http://www.isi-hamburg.org/product_register.php', {product : productId, time : millis}, function(responseText, textStatus, XMLHttpRequest) {

    if (numOptionalChoice > 0) {
      options = createOptions(optionalItems);
      for (i = numOptionalChoice; i-- > 0; ) {
        label = (i == 0) ? "Workshop" : "Alternative " + i;
        entry = createOptionalRegisterEntry("workshop_" + productId + "_" + i, label, options);
        $("#optional_entry").after(entry);
      }
      $("#optional_reg_entries").val(numOptionalChoice);
    }

    $("#popupRegisterDialog").dialog('option', 'title', $("#popupTitle").val());
    //alert($("#popupTitle").val());
  });
}

function createOptions(values) {
  html = "";
  for(i = 0; i < values.length; i++)
    html += "<option value='" + values[i] + "'>" + values[i] + "</option>";
  return html;
}

function createOptionalRegisterEntry(id, label, values) {
  html = "<tr>" + 
         "<td><label for='" + id + "' id='label_" + id + "'>" + label + ":</label></td>" + 
         "<td colspan='2' ><select name='" + id + "' id='" + id + "' style='width:280px;'>" + values + "</select></td>" + 
         "<td></td></tr>";
  return html;
}

////////////////////////////////////////////
// init

var global_current_site    = -1;
var global_current_section = "";

function global_init_isi(currentSection, currentSite) {
  global_current_section = currentSection;
  global_current_site    = currentSite;
  
  start('http://www.isi-hamburg.org/image');

  $.datepicker.setDefaults( { dateFormat: 'dd.mm.yy' } );

  $("a.menu_item").mouseover( function() {
    $(this).css({"color" : "red"});
    //$(this).animate({color: "black"}, 700);
  });

  $("a.menu_item").mouseout( function() {
    //$(this).css({"color" : "red"});
    $(this).animate({color: "black"}, 700);
  });
  
  $(".contact_link").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250
  }); 
  
  $(".tooltip").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250
  }); 
  
  if (global_current_section == 'site')
    initSite();

  $(".small_person_foto").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250,
    bodyHandler: function(e) {
      var time = new Date();  
      var millis = time.getTime();
      var personId = $(this).attr('id').substring(18);
      var result = $("<span/>").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
      $.get("http://www.isi-hamburg.org/person_info.php", {person : personId, time : millis}, function(data) { result.html(data); }, "html");
      return result;
    }
  });

  $('img.thumbnail').imgZoom( { duration : 100 } );
}

////////////////////////////////////////////////////////
// product init

//////////////////////////////////////////////////////
// site init

function initSite() {

  switch(global_current_site) {
    case 6015: initSiteSeminarList(); break;
    case 6016: 
    case 6050: 
    case 6051: initSiteEmployeeList(); break;
    case 6057: initSiteTest(); break;
    case 6060: initSiteSitemap(); break;
    case 6061: initSiteRegister(); break;
  }
}

function initSiteTest() {
  initSiteEmployeeList();
}

// sitemap
function initSiteSitemap() {
  $("#sitemap").load("http://www.isi-hamburg.org/sitemap-fancy.php", {}, function(responseText, textStatus, XMLHttpRequest) { 
    
    $("#sitemap_tree").treeview({
  	  animated: "medium"
  	});
  	
  	//$("#sitemap").dynatree({
    //  fx: { height: "toggle", duration: 200 }
    //});
  });
  
  /*$("#sitemap").dynatree({
    onClick: null,
    initAjax: {url: "http://www.isi-hamburg.org/sitemap-json.php", data: {key: "root"}},
    fx: { height: "toggle", duration: 200 }
  });*/
  
}

// seminar list
function initSiteSeminarList() {
  $("#tabs_seminars").tabs();
  $("#next_seminars_date_search_start").datepicker({
    onSelect: function(dateText, inst) {
      filterSeminarTable($('#next_seminars_date_search_start').val(), $('#next_seminars_date_search_end').val(), 'next_seminars');
      $('#next_seminars_text_search').val('');
      $('#next_seminars_department_search').val('0');
    }
  });
  $("#next_seminars_date_search_end").datepicker({
    onSelect: function(dateText, inst) {
      filterSeminarTable($('#next_seminars_date_search_start').val(), $('#next_seminars_date_search_end').val(), 'next_seminars');
      $('#next_seminars_text_search').val('');
      $('#next_seminars_department_search').val('0');
    }
  });

  $("#next_sonderseminars_date_search_start").datepicker({
    onSelect: function(dateText, inst) {
      filterSeminarTable($('#next_sonderseminars_date_search_start').val(), $('#next_sonderseminars_date_search_end').val(), 'next_sonderseminars');
      $('#next_sonderseminars_text_search').val('');
    }
  });
  $("#next_sonderseminars_date_search_end").datepicker({
    onSelect: function(dateText, inst) {
      filterSeminarTable($('#next_sonderseminars_date_search_start').val(), $('#next_sonderseminars_date_search_end').val(), 'next_sonderseminars');
      $('#next_sonderseminars_text_search').val('');
    }
  });

  $("#archiv_seminars_date_search_start").datepicker({
    onSelect: function(dateText, inst) {
      filterSeminarTable($('#archiv_seminars_date_search_start').val(), $('#archiv_seminars_date_search_end').val(), 'archiv_seminars');
      $('#archiv_seminars_text_search').val('');
    }
  });
  $("#archiv_seminars_date_search_end").datepicker({
    onSelect: function(dateText, inst) {
      filterSeminarTable($('#archiv_seminars_date_search_start').val(), $('#archiv_seminars_date_search_end').val(), 'archiv_seminars');
      $('#archiv_seminars_text_search').val('');
    }
  });

  $(".small_person_foto").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250,
    bodyHandler: function() {
      var time = new Date();  
      var millis = time.getTime();
      var personId = $(this).attr('id').substring(18);
      var result = $("<span/>").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
      $.get("http://www.isi-hamburg.org/person_info.php", {person : personId, time : millis}, function(data) { result.html(data); }, "html");
      return result;
    }
  });

  $(".seminar_indicator").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250
  });   

  $(".closed_group_indicator").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250
  });
}

function makePersonFotoTooltip() {
  $(".small_person_foto").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250,
    bodyHandler: function() {
      var time = new Date();  
      var millis = time.getTime();
      var personId = $(this).attr('id').substring(18);
      var result = $("<span/>").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
      $.get("http://www.isi-hamburg.org/person_info.php", {person : personId, time : millis}, function(data) { result.html(data); }, "html");
      return result;
    }
  });
}

// employee list
function initSiteEmployeeList() {
  $("#tabs_employees").tabs();

  $("#employee_list").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
  $("#pool_list").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
  $("#alumni_list").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
  $("#coop_list").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");

  $.post("http://www.isi-hamburg.org/person_lister.php", {'list' : 'employee'}, function(data) {
    $("#employee_list").html(data);
    makePersonFotoTooltip();
    $(".employee_list_row_sub").hide();
  });

  $.post("http://www.isi-hamburg.org/person_lister.php", {'list' : 'pool'}, function(data) {
    $("#pool_list").html(data);
    makePersonFotoTooltip();
  });

  $.post("http://www.isi-hamburg.org/person_lister.php", {'list' : 'alumni'}, function(data) {
    $("#alumni_list").html(data);
    makePersonFotoTooltip();
  });

  $.post("http://www.isi-hamburg.org/person_lister.php", {'list' : 'coop'}, function(data) {
    $("#coop_list").html(data);
  });

  /*$(".small_person_foto").tooltip({
    delay: 0,
    showURL: false,
    opacity: 1,
    fade: 250,
    bodyHandler: function(e) {
      var time = new Date();  
      var millis = time.getTime();
      var personId = $(this).attr('id').substring(18);
      var result = $("<span/>").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
      $.get("http://www.isi-hamburg.org/person_info.php", {person : personId, time : millis}, function(data) { result.html(data); }, "html");
      return result;
    }
  });*/
}

// register
function initSiteRegister() {
  var e = $("#contact_bday"); 
  e.datepicker({
    /*beforeShow: function(input) {
      if (e.val().length == 0) e.val("01.01.1979");
    }*/
  });
  
  $(".tooltip_input").tooltip({
    delay: 0,
    showURL: true,
    opacity: 1,
    fade: 250
  });  
}

////////////////////////////////////
// person search
function personSearch() {
  $("#psearch_result").hide();
  $("#psearch_status").show();

  var time = new Date();  
  var millis = time.getTime();
  var personCategory = $("#psearch_category").val().substring(9);
  var personName = unescape($("#psearch_name").val() );
  var personCity = $("#psearch_city").val();
  var personZip  = $("#psearch_zip").val();

  $("#psearch_result").load('http://www.isi-hamburg.org/search_person.php', {
    personCategory : personCategory,
    personName : personName,
    personCity : personCity,
    personZip : personZip,
    time : millis},
    function(responseText, textStatus, XMLHttpRequest) {
      $("#psearch_status").hide();
      $("#psearch_result").show();

      $(".small_person_foto").tooltip({
        delay: 0,
        showURL: false,
        opacity: 1,
        fade: 250,
        bodyHandler: function(e) {
          var time = new Date();  
          var millis = time.getTime();
          var personId = $(this).attr('id').substring(18);
          var result = $("<span/>").html("<img src='http://www.isi-hamburg.org/image/wait_single.gif' alt='lade Inhalt...' />");
          $.get("http://www.isi-hamburg.org/person_info.php", {person : personId, time : millis}, function(data) { result.html(data); }, "html");
          return result;
        }
      });

      $(".contact_link").tooltip({
        delay: 0,
        showURL: false,
        opacity: 1,
        fade: 250
      }); 
  
      $(".tooltip").tooltip({
        delay: 0,
        showURL: false,
        opacity: 1,
        fade: 250
      }); 
    }
  );
}


