
/* old svz javascript file, needed for landing pages only */

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
dom = (document.getElementById)? true:false;

function isArray(object) {
  if (!window.Array) return false;
  else return object.constructor == window.Array;
}

function toggleVisibility(e) {
  if (typeof(e) == "string") e=$(e);
  if (isArray(e)) for (i=0; m=e[i]; i++) toggleVisibility(m);
  else {
    if (e.style.display == "none") showElement(e); else hideElement(e);
  }
}

function showElement(e) {
  if (typeof(e) == "string") $('#' + e).show();
  if (isArray(e)) for (i=0; m=e[i]; i++) showElement(m);
}

function hideElement(e) {
  if (typeof(e) == "string") $('#' + e).hide();
  if (isArray(e)) for (i=0; m=e[i]; i++) hideElement(m);
}

function prepareAppearers() {
  e = selectElements('.appearer');
  for (i=0; m=e[i]; i++) { m.className = "appearer2"; hideElement(m); }
}

function clickAttachPic() {
  if ($('#attach_pic').attr('checked', true)) showElement('attach_pic_div');
  else hideElement('attach_pic_div');
}

function gofriendslink(id, category_id, cat5_uni_id) {
  newHref = "friends.php?";
  if( id ) newHref += "ids=" + id;
  // newHref += "&link_id=" + link_id;
  newHref += "&category_id=" + category_id;
  newHref += "&uni_id=" + cat5_uni_id;
  window.location.href = newHref;
}

function getNextFormField(field) {
  var i;
  for (i = 0; i < field.form.elements.length; i++) {
    if (field == field.form.elements[i]) { break; }
  }
  i = (i + 1) % field.form.elements.length;
  return(field.form.elements[i]);
}

function checkPicAgree(allowNone) {
  if (document.frm.pic.value) {
    if (document.frm.agree.checked) { document.frm.submit(); }
    else { alert (studivzjstext['agreeItsYourPic']); }
  } else if (allowNone) { document.frm.submit(); }
}

function getAllChildren(e) {
  return e.all ? e.all : e.getElementsByTagName('*');
}

function selectElements(selector) { // (C) Simon Willison
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    if (!currentContext[0]){
    	return;
    }
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}
function checkInfoChange(selects){
	if(selects == 1){
		document.getElementById('showinfoChange').innerHTML = studivzjstext['markedPersonLinked'];
	}else{
		document.getElementById('showinfoChange').innerHTML = studivzjstext['deleteAllLinks'];
	}
}
function onlyHide(element){
	if(document.getElementById(element)){
		document.getElementById(element).style.visibility = 'hidden';
		document.getElementById(element).style.overflow = 'hidden';
		document.getElementById(element).style.display = 'none';
	}
}
function onlyShow(element){
	if(document.getElementById(element)){
		document.getElementById(element).style.visibility = 'visible';
		document.getElementById(element).style.overflow = 'visible';
		document.getElementById(element).style.display = 'block';
	}
	if(element == 'friendscroll'){
		if(document.getElementById('friendsName'))
		document.getElementById('friendsName').focus();
	}
}
function show(element){
	if (document.getElementById(element).style.visibility == "hidden")
	onlyShow(element);
	else{ onlyHide(element);}
}

/* Functions for history redirect*/
var GO = '';
function addPageToHistory(goNow){
	GO = goNow;
	url = 'ajax/redirect.php';
  var myAjax = new Ajax.Request(
    url, { method: 'post', postBody:Form.serialize(document.forms['history_form']), onCreate: startAdd(), onSuccess: stopAdd });
}
function startAdd() {	}
function stopAdd(originalRequest) {
  window.location.href = GO;
}
function goToHistoryPage(){
	url = 'ajax/redirect.php';
  var myAjax = new Ajax.Request(
    url, { method: 'post', postBody:Form.serialize(document.forms['history_form']), onCreate: startGo(), onSuccess: stopGo });
}
function startGo(){}
function stopGo(originalRequest) {
  eval("var data = "+originalRequest.responseText+';');
  window.location.href = data['go_url'] ;
}

function textAreaCeckLength(id, maxlength){
	var elem = document.getElementById(id);
	var text;
	var textIsLong = false;
	
	switch (elem.tagName.toUpperCase()){
		case 'TEXTAREA':
			text = elem.value;
		break;
		case 'DIV':
			text = elem.innerHTML;
		break;
		default:
			text = elem.value;
		break;
	}
	var length = text.length;
	var elemOut = document.getElementById('counter');	
	if(elemOut) {
		if (length > maxlength){
	 		textIsLong = true;
		}
		if ( (length < maxlength) && (length >= maxlength - 100) ){
			elemOut.innerHTML = (maxlength - length) + ' ' + 'Zeichen übrig';
		} else if (length >= maxlength) {
			elemOut.innerHTML = '0 ' + 'Zeichen übrig';
			elem.value = text.substring(0, maxlength);			
		} else {
			elemOut.innerHTML = '';
		}
	}
		
	if (textIsLong==true){
		return false;
	}else{
		return true;
	}	
}

function turnCacheDedugArray(id) {
	spanElement = document.getElementById(id);
	if (spanElement.style.display == 'none') {
		spanElement.style.display = 'inline';
	} else {
		spanElement.style.display = 'none';
	}
}