/* 
AOFoundationAOFbehaviours.js
Version: 2008-03-19 msc
Version: 2009-02-13 rsc
*/

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* getElementsByClassName */
/* optimierte getElementsByClassName (wp) */
document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  return elements;
} 

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* Suchfelder beim Fokus leeren : */
function changeSearchValue(){
	if(!document.getElementById("searchFor")) return false;
	var textField = document.getElementById("searchFor");
	var defaultValue = textField.getAttribute("value");
	var empty = "";
	
	textField.onfocus = function(){
		textField.setAttribute("value",empty);
		}
		
	textField.onblur = function(){
		if(textField.value=='')
		textField.setAttribute("value",defaultValue);
		}
}

function changeSearchValue2(){
	if(!document.getElementById("traumals")) return false;
	var textField = document.getElementById("traumals");
	var defaultValue = textField.getAttribute("value");
	var empty = "";
	
	textField.onfocus = function(){
		textField.setAttribute("value",empty);
		}
		
	textField.onblur = function(){
		if(textField.value=='')
		textField.setAttribute("value",defaultValue);
		}
} 

function changeSearchValue3(){
	if(!document.getElementById("traumaSearch")) return false;
	var textField = document.getElementById("traumaSearch");
	var defaultValue = textField.getAttribute("value");
	var empty = "";
	
	textField.onfocus = function(){
		textField.setAttribute("value",empty);
		}
		
	textField.onblur = function(){
		if(textField.value=='')
		textField.setAttribute("value",defaultValue);
		}
} 

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
/* calls listed functions via body onLoad="startFunctions();"  */
function startFunctions(){
	changeSearchValue();
	changeSearchValue2();
	changeSearchValue3();
	preloadImages();
}

/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
function changeURL2Login(){
	var sURL = document.URL;
	var iIndexPWPS = sURL.indexOf("/portal/wps/");
	var iIndexWPS = sURL.indexOf("/wps/portal");
	if( iIndexPWPS < 0){
		sURL = sURL.substring( 0, iIndexWPS) + "/wps/my" + sURL.substring(iIndexWPS + 5);
	}else{
		sURL = sURL.substring( 0, iIndexPWPS) + "/wps/my" + sURL.substring(iIndexPWPS + 12);
	};
	if(sURL.indexOf("http:") >= 0){
		sURL = "https:" + sURL.substring( 5);
	};
	window.location.href = sURL;
}

/* 2010-07-09 hea */
/* Dieses Script "schiebt" die Loginpage dazwischen und leitet nach erfolgreichem Login zur angeforderten URL weiter */
function changeURLToLogin(sURL){
	var sHost = window.location.hostname;
	var iIndexWPS = sURL.indexOf("/wps/portal");
	// evtl. 'my' dazwischen schieben
	if (iIndexWPS >= 0){
		sURL = sURL.substring(0, iIndexWPS) + "/wps/my" + sURL.substring(iIndexWPS + 5);
	}
	/* change to https if the environment is not development */
	if (sHost.indexOf("192.168.110.20") == -1) {
		if (sURL.indexOf("http:") >= 0){
			sURL = "https:" + sURL.substring(5);
		} else {
			sURL = "https://" + sHost + sURL;
		}
	}
	// encoding the comma is needed, because otherwise the parameter list of the forward after the login screen will end
	// by the comma!!!!
	var encodedURL = sURL.replace(",", "%2C");
	
	window.location.href = encodedURL;
}
