var Browser = {
  Version: function() {
    var version = 999;
    if (navigator.appVersion.indexOf("MSIE") != -1)
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}
function displayMap() {

   var overlay = document.createElement("div");
   
   overlay.setAttribute("id","overlay");
   overlay.setAttribute("class", "overlay");
   overlay.setAttribute("onclick", "restore()");
   
   document.body.appendChild(overlay);
   document.body.appendChild(byID('google_maps_karte'));
      
   byID('google_maps_karte').style.display = 'inline-block';
   byID('google_maps_karte').setAttribute("onclick", "restore()");
}
function restore() {
   document.body.removeChild(document.getElementById("overlay"));
   byID('google_maps_karte').style.display = 'none';
}

function byID(id)
{
  return document.getElementById(id);
}
// Je nachdem, welcher Kostenträger gewählt wurde, die anderen ausblenden
window.onload = ktSelect;
function ktSelect()
{
  if(!byID('sem_anm_frm')) return false;

  kt = ['ba','s','sz','ag'];
  c1 = 'anm_table_kt_nofocus';
  c2 = 'anm_table_kt_focus';
  x = byID('sem_anm_frm').anm_kt_typ;
  
  if(!x)
    return false;

  for(i=0;i<x.length;i++)
  {
    if(x[i].checked)
      r = x[i].value;
  }

  for(i=0;i<kt.length;i++)
  {    
    class1 = (r == kt[i]) ? c1 : c2;
    class2 = (r == kt[i]) ? c2 : c1;
        
    classSwitch('anm_table_kt_'+kt[i],class1,class2);
  }
}
// Tauscht die Class von ID gegen Class2 (wenn nicht vorhanden wird sie hinzugefügt)
function classSwitch(cid,class1,class2)
{
  $("#"+cid).hasClass(class1)
  {
    $("#"+cid).removeClass(class1);
  }
  $("#"+cid).addClass(class2);
}
// Fügt Class zu Classes von ID hinzu, wenn nicht schon vorhanden
function joinClass(cid,class1)
{
  var classes = byID(cid).className.split(' ');
  if(!classes.indexOf(class1))
  {
    byID(cid).className = classes.push(class1).join(' ');
  }
}
function remove_att()
{
  byID('filefield').value = '';
  byID('att_remove_field').value = '1';

  if(byID('filename'))
    byID('filename').style.display = 'none';
    
  byID('att_file_div').style.display = 'none';
  byID('att_remove_div').style.display = 'none';
}
function selectedFile()
{
  val = byID('filefield').value;
  
  if(val)
  {
    var icons = new Array();
    icons[0] = new Array();
    
    icons[0]['.doc'] = 'ms-word.gif';
    icons[0]['.docx'] = 'ms-word.gif';
    icons[0]['.zip'] = 'zip-file.gif';
    icons[0]['.xls'] = 'excel-file.gif';
    icons[0]['.xlsx'] = 'excel-file.gif';
    icons[0]['.flv'] = 'flash-file.gif';
    icons[0]['.psd'] = 'photoshop-file.gif';
    icons[0]['.psd'] = 'photoshop-file.gif';
    icons[0]['.pdf'] = 'pdf.gif';
    icons[0]['.exe'] = 'exe-file.gif';
    icons[0]['.txt'] = 'text-file.gif';
    icons[0]['default'] = 'file.gif';

    icon_file = (icons[0][val.substr(val.lastIndexOf('.'),val.length)]) ? icons[0][val.substr(val.lastIndexOf('.'),val.length)] : icons[0]['default'];

    icon = '<img src="./Bilder/Icons/Files/' + icon_file + '" alt="" /> ';

    byID('filename').style.display = 'block';
    byID('filename').style.marginTop = '10px';
    
    val = val.substr(val.lastIndexOf('\\')+1,val.length);
    byID('filename').innerHTML = icon + val;
    
    byID('att_file_div').style.display = 'none';
    byID('att_remove_div').style.display = 'block';
    byID('att_remove_field').value = '';
  }
  
  window.setTimeout('selectedFile()',500);
}
function checkBox(f,cb)
{
 document.forms[f]['checkbox[' + cb + ']'].checked = 
 (document.forms[f]['checkbox[' + cb + ']'].checked) ? false : true;
}

var http_request = false;
function do_req(req_act,req_do,req_val) {

    http_request = false;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        return false;
    }
    
    http_request.onreadystatechange = handle_req;
    
    if(req_act == 'validate')
      http_request.open('GET', './index.php?cat=seminar_anmeldung&var=' + req_do + '&val=' + req_val + '&&ajax_req=1&ajax_id=' + byID('ajax_id').value, true);
    else
      http_request.open('GET', './ajax-req.php?act=' + req_act + '&do=' + req_do + '&val=' + req_val, true);

    http_request.send(null);

}

function handle_req()
{
  if(http_request.readyState == 4)
  {
    if(http_request.status == 200)
      eval(http_request.responseText);
    else 
      return false;
  }
}
// Hover-Effekt für "Termine einblenden"
function t_hid_hover(switch_var,tid)
{ 
  temp_transp(switch_var,tid);
}

// Termine bei Mouseover über "Ausblenden" transparent machen
function temp_transp(var_switch,tid)
{
  byID('t-vis-bgdiv-' + tid).className = (var_switch) ? 'transparent' : 'nontransparent';
  byID('t-vis-bgdiv-' + tid).style.display = (var_switch) ? 'block' : 'none';
}

// Termine ausblenden oder einblenden und in Session-Cookie mithilfe von ajax-req.php vermerken
var expand;
function show_termine(tid,save,ajax_id)
{
  if(tid)
  {
    var t_vis = byID('t-vis-' + tid);
    var t_hid = byID('t-hid-' + tid);
  
    if(!t_vis)
      return false;
    
    t_vis.style.display = (t_vis.style.display == 'block') ? 'none' : 'block';
    t_hid.style.display = (t_hid.style.display == 'block') ? 'none' : 'block';

    <!-- Einstellung merken //-->
    if(save)
    {
      var stat = (t_vis.style.display == 'block') ? 1 : 2;
      do_req('termine-set-opt',tid + '_' + stat,ajax_id);
    }
  }
  else
  {
    byID('show-all-div').style.display = (expand) ? 'block' : 'none'; 
    byID('hide-all-div').style.display = (expand) ? 'none' : 'block';
  
    for(i=1;i<=6;i++)
    {
      if(!byID('t-vis-' + i))
        continue;
      
      byID('t-vis-' + i).style.display = (expand) ? 'none' : 'block';
      byID('t-hid-' + i).style.display = (!expand) ? 'none' : 'block';
    }
    expand = (expand) ? 0 : 1;
    
    <!-- Einstellung merken //-->
    if(save)
    {
      do_req('termine-set-opt','all-expanded_' + expand,ajax_id);
    }
  }
}

// Füllt Ort nach PLZ autom. aus (Value ID1, Value ID2)
function ort_by_plz(id_plz,id_ort)
{
  if(!byID(id_ort).value)
    do_req('ort_by_plz',byID(id_plz).value+"-"+id_ort,byID('ajax_id').value);
}

// Wählt ein Radio/Checkbox aus
function mark(ID)
{
  if(byID(ID).type == 'checkbox')
    byID(ID).checked = (byID(ID).checked == true) ? false : true;
  else if(byID(ID).type == 'radio' && byID(ID).checked == false)
    byID(ID).checked = true;
  else
    return false;
}
