function swap_categories(str) {
	window.location.reload();
	return true;
}

var header_log = true;
var such_pane = true;
var galerie_log = true;

function initLinks()
{
	
	if (!document.getElementsByTagName){return;}
	var anchors = document.getElementsByTagName("a");
	
	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("class") == "smoothbox") {
			// anchor.onclick = function () {showLightbox(this); return false;}
		} else {
            if (anchor.href.indexOf('.pdf') != -1 || anchor.href.indexOf('.PDF') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_pdf';
            }
            if (anchor.href.indexOf('.doc') != -1 || anchor.href.indexOf('.DOC') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_doc';
            }
            if (anchor.href.indexOf('.docx') != -1 || anchor.href.indexOf('.DOCX') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_doc';
            }
            if (anchor.href.indexOf('.ppt') != -1 || anchor.href.indexOf('.PPT') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_ppt';
            }
            if (anchor.href.indexOf('.pptx') != -1 || anchor.href.indexOf('.PPTX') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_ppt';
            }
            if (anchor.href.indexOf('.pps') != -1 || anchor.href.indexOf('.PPS') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_ppt';
            }
            if (anchor.href.indexOf('.rtf') != -1 || anchor.href.indexOf('.RTF') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_doc';
            }
            if (anchor.href.indexOf('.xls') != -1 || anchor.href.indexOf('.XLS') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_xls';
            }
            if (anchor.href.indexOf('.zip') != -1 || anchor.href.indexOf('.ZIP') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_zip';
            }
            if (anchor.href.indexOf('.rar') != -1 || anchor.href.indexOf('.RAR') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_zip';
            }
            if (anchor.href.indexOf('.png') != -1 || anchor.href.indexOf('.PNG') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_img';
            }
            if (anchor.href.indexOf('.jpg') != -1 || anchor.href.indexOf('.JPG') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_img';
            }
            if (anchor.href.indexOf('.gif') != -1 || anchor.href.indexOf('.GIF') != -1) {
                anchor.setAttribute('target', '_blank');
                anchor.className = 'link_img';
            }
		}
	}
}

window.addEvent('domready', function() {

	if (document.getElementById('login_container') != undefined) {
		header_log = new Fx.Slide("login_container", {
				duration: 1000, 
				transition: Fx.Transitions.Quint.easeOut
		});
		header_log.hide(); 
	}

	if (document.getElementById('galerie_container') != undefined) {
		galerie_log = new Fx.Slide("galerie_container", {
				duration: 1000, 
				transition: Fx.Transitions.Quint.easeOut
		});
		galerie_log.hide(); 
		galerie_log.addEvent('complete', function() {
			show_flash();
			change_linktext();
		});
	}

	if (document.getElementById('gallery_link') != undefined) {
		$('gallery_link').addEvent('click', function(e) {
			e.stop();
			galerie_log.toggle();
		});
	}

	if (document.getElementById('suche') != undefined) {
		such_pane = new Fx.Slide("suche", {
				duration: 1000, 
				transition: Fx.Transitions.Quint.easeOut
		});
		such_pane.hide(); 
	}


		// change edit und remove link:
		var editlinks = $$('.link_edit');
		editlinks.each(function(el) {
			el.set('html', '&nbsp;<img src="/images/be_note_edit.gif" alt="Edit entry" title="Edit entry" />');
		});
		var editlinks = $$('.link_delete');
		editlinks.each(function(el) {
			el.set('html', '&nbsp;<img src="/images/be_note_remove.gif" alt="Delete entry" title="Delete entry" />');
		});

	initLinks();
	
});


/* EDIT */

/** XHConn - Simple XMLHTTP Interface - brad@xkr.us - 2005-01-24             **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4) {
        fnDone(xmlhttp); }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function delete_entry(entry_id, xid_hash) {
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	myConn.connect("http://www.si-hr.eu/intersys/index.php", "POST", "S=0&C=edit&M=delete_entries&delete%5B%5D="+ entry_id + "&XID=" + xid_hash, handle_res);
}

handle_res = function(z)  {
	//alert(z.responseText);
	// do a reload if successfull!
	location.reload();
}

/* SWITCHER */

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
