/********************************************************
	
	JavaScript Dokument
	Autor: dotfly.multimedia - Tobias Mueller
	Internet: www.dotfly.de

********************************************************/

function TMDomInit() {
	var agent = navigator.userAgent.toLowerCase();
	var os = navigator.platform.toLowerCase();
	var mac = (os.indexOf('mac') != -1) ? true : false;
	var isW3CDOM = (document.getElementById) ? true : false;
	if (window.opera && isW3CDOM) {
		isOPERA = true;
		isOPERA6 = (document.createElement && !document.addEventListener) ? true : false;
		isOPERA7 = (document.createElement && document.addEventListener) ? true : false;
	} else {
		isOPERA = false;
		isOPERA6 = false;
		isOPERA7 = false;	
	}
	if (document.all && isW3CDOM && !isOPERA) {
		isIE = true;
		isIE5 = (!document.createEventObject && !mac) ? true : false;
		isIE55 = (document.createEventObject && !document.compatMode && !mac) ? true : false;
		isIE6 = (document.compatMode && !mac) ? true : false;
		isIE5MAC = (mac) ? true : false;
	} else {
		isIE = false;
		isIE5 = false;
		isIE55 = false;
		isIE6 = false;
		isIE5MAC = false;
	}
	isKHTML = (isW3CDOM && document.clientWidth) ? true : false;
	isGECKO = (isW3CDOM && !isKHTML && !isIE && !isOPERA) ? true : false;
	isGECKOPR = (isGECKO && (agent.indexOf('rv') == -1) && !document.compatMode) ? true : false;
	isDOM = (isGECKO || isKHTML || isIE || isOPERA6 || isOPERA7) ? true : false;
}

TMDomInit();

function DFGetElem(obj)
{
	if (isDOM)
	{
		var a = arguments;
		if (typeof obj == 'string')
		{
			if (a.length == 1)
			{
				return document.getElementById(obj);
			}
			else if (a.length == 3 && typeof a[1] == 'string' && typeof a[2] == 'number')
			{
				if (a[1].toLowerCase() == 'name')
				{
					return document.getElementsByName(obj)[a[2]];
				}
				else if (a[1].toLowerCase() == 'tagname')
				{
					return document.getElementsByTagName(obj)[a[2]];
				}
			}
		}
		else if (typeof obj == 'object')
		{
			return obj;
		}
	}
}

function DFSwapImage(elem,path,ext)
{
	if (isDOM)
	{
		var args = arguments;
		var elem = DFGetElem(elem);
		var eventTarget = args[3] ? (document.all && !window.opera) ? window.event.srcElement : args[3].currentTarget : elem; 
		if (elem != currentActiveImg) 
			elem.src = path + '2.' + ext;
		eventTarget.onmouseout = function()
		{
			if (elem != currentActiveImg)
				elem.src = path + '1.' + ext;
			eventTarget.onmouseout = null;
			elem = null;
		}
	}
}


var DFNavigate = {
	init : function()
	{
		this.currentActiveImg = null;
		if (DFGetElem('HeadlineBanner'))
		{
			this.headlineBanner = DFGetElem('HeadlineBanner').getElementsByTagName('img')[0];
		}
		if (DFGetElem('MiddleContent00'))
		{
			this.currentActiveCont = DFGetElem('MiddleContent00');
		}
		if (DFGetElem('MiddleBox'))
		{
			this.mBox = DFGetElem('MiddleBox');
		}
		this.checkLocation();
	},
	
	swapContent : function(contElem,headPath,imgElem,path,ext)
	{
		this.currentActiveCont.style.display = 'none';
		this.newActive = DFGetElem(contElem)
		this.newActive.style.display = 'block';
		this.currentActiveCont = this.newActive;
		this.headlineBanner.src = headPath;
		if (this.currentActiveImg)
		{
			this.currentActiveImg.src = this.currentActivePath + '1.' + this.currentActiveExt;
		}
		if (imgElem)
		{
			this.currentActiveImg = DFGetElem(imgElem);
			this.currentActiveImg.src = path + '3.' + ext;
			this.currentActivePath = path;
			this.currentActiveExt = ext;
		}
		else
		{
			this.currentActiveImg = null;
		}
		return false;
	},
	
	swapImage : function(elem,path,ext)
	{
		if (isDOM)
		{
			this.args = arguments;
			this.SIElem = DFGetElem(elem);
			this.eventTarget = this.args[3] ? (document.all && !window.opera) ? window.event.srcElement : this.args[3].currentTarget : this.SIElem; 
			if (this.SIElem != this.currentActiveImg)
			{
				this.SIElem.src = path + '2.' + ext;
			}
			this.eventTarget.onmouseout = function()
			{
				if (DFNavigate.SIElem != DFNavigate.currentActiveImg)
				{
					DFNavigate.SIElem.src = path + '1.' + ext;
				}
				DFNavigate.eventTarget.onmouseout = null;
			}
		}
	},
	
	changeBg : function(c)
	{
		this.mBox.className = c;
	},
	
	checkLocation : function()
	{
		if (window.location.search.indexOf('showSolutions') != -1)
		{


//alert(window.location.search)
			this.loc = window.location.search;
			this.loc = this.loc.split('=');
			switch (this.loc[1])
			{
				case '01':
					return DFNavigate.swapContent('MiddleContent01','../images/p_loesungen/h_banner_' + solutionBanner + '_01.gif','SN' + solutionNum + '01','../images/p_navi_ebene2/loesungen/' + solutionPage + '1_','gif');
					break;
				
				case '02':
					return DFNavigate.swapContent('MiddleContent02','../images/p_loesungen/h_banner_' + solutionBanner + '_02.gif','SN' + solutionNum + '02','../images/p_navi_ebene2/loesungen/' + solutionPage + '2_','gif');
					break;
				
				case '03':
					return DFNavigate.swapContent('MiddleContent03','../images/p_loesungen/h_banner_' + solutionBanner + '_03.gif','SN' + solutionNum + '03','../images/p_navi_ebene2/loesungen/' + solutionPage + '3_','gif');
					break;
				
				case '04':
					return DFNavigate.swapContent('MiddleContent04','../images/p_loesungen/h_banner_' + solutionBanner + '_04.gif','SN' + solutionNum + '04','../images/p_navi_ebene2/loesungen/' + solutionPage + '4_','gif');
					break;
				
				case '05':
					return DFNavigate.swapContent('MiddleContent05','../images/p_loesungen/h_banner_' + solutionBanner + '_05.gif','SN' + solutionNum + '05','../images/p_navi_ebene2/loesungen/' + solutionPage + '5_','gif');
					break;
				
				case '06':
					return DFNavigate.swapContent('MiddleContent06','../images/p_loesungen/h_banner_' + solutionBanner + '_06.gif','SN' + solutionNum + '06','../images/p_navi_ebene2/loesungen/' + solutionPage + '6_','gif');
					break;
				
			}
		}
	}
}

function DFOpenWin(href,name,w,h,scrollbars,status,resize,center)
{
	if (center)
	{
		var pos = new Array();
		pos.x = (screen.width / 2) - (w / 2);
		pos.y = (screen.height / 2) - (h / 2);
	}
	var prop = '';
	prop += 'width=' + w + ',height=' + h;
	prop += center ? ',left=' + pos.x + ',top=' + pos.y : '';
	prop += scrollbars ? ',scrollbars=1' : '';
	prop += status ? ',status=1' : '';
	prop += resize ? ',resizable=1' : '';
	var win = window.open(href,name,prop);
	win.focus();
	return false;
}

function DF_OpenWindow(url,name,width,height,center) { 
	// Copyright 2005 dotfly.multimedia / Tobias Mueller. All rights reserved.
	if (url && name) {
		var posX, posY, prop = '', DFWin, a = arguments;
		if (width && height) {
			prop += 'width=' + width + ',height=' + height;
			if (center) {
				posX = (screen.width / 2) - (width / 2);
				posY = (screen.height / 2) - (height / 2);
				prop += ',left=' + posX + ',top=' + posY;
			}
		}
		if (a.length == 11) {
			prop += ',toolbar=' + a[5] + ',location=' + a[6] + ',status=' + a[7] + ',menubar=' + a[8] + ',scrollbars=' + a[9] + ',resizable=' + a[10];
		}
		DFWin = window.open(url,name,prop);
		DFWin.focus();
	}
	document.MM_returnValue = false;
}

function DFSetzeTargetBlank()
{
	if (document.getElementsByTagName)
	{
		var verweise, verweis, klasse, setzeziel;
		verweise = document.getElementsByTagName('a');
		for (var i = 0; i < verweise.length; i++)
		{
			verweis	= verweise[i];
			klasse = verweis.getAttribute('class') || verweis.className;
			if (klasse.indexOf('targetblank') != -1)
			{
				verweis.setAttribute('target','_blank');
			}
		}
	}
}

function TMCheckDelete() {
	var check = confirm("Wollen Sie diesen Eintrag wirklich löschen?");
	if (check == false) return false;
}

function TMCheckFile() {
	var check = confirm("Wollen Sie die Datei wirklich entfernen?");
	if (check == false) return false;
}

function TMPruefeFormular() {
	var fehler = '', nichtausgefuellt = '', a = arguments, formindex = a[0];
	for (var i = 1; i < (a.length-2); i+=3) {
		var feldname = a[i];
		var pruefen = a[i+1];
		var feldbez = a[i+2];
		var feld = document.forms[formindex][feldname];
		var feldwert = feld.value;
		if (feldwert == '' || feldwert == 0) {
			nichtausgefuellt += '- ' + feldbez + '\n';
		} else {
			if (pruefen.indexOf('pMail') != -1) {
				var AT = feldwert.indexOf('@');
				var letztesAT = feldwert.lastIndexOf('@');
				var letzterPunkt = feldwert.lastIndexOf('.');
				var laenge = feldwert.length;
				if ((laenge <= 6) || (laenge < (AT + 6)) || (AT != letztesAT) || (AT < 1) || (letzterPunkt <= (AT + 2)) || (letzterPunkt >= (laenge - 2))) {
					fehler += '- ' + feldbez + ' muss eine korrekte eMail-Adresse enthalten!\n';
				}
			} else if (pruefen.indexOf('pPLZ') != -1) {
				if ((isNaN(feldwert)) || (feldwert.length != 5)) {
					fehler += '- ' + feldbez + ' muss eine korrekte Postleitzahl enthalten!\n';
				}
			} else if (pruefen.indexOf('pZahl') != -1) {
				if (isNaN(feldwert)) {
					fehler += '- ' + feldbez + ' darf nur Zahlen enthalten!\n';
				}			
			}
		}
	}
	if (fehler || nichtausgefuellt) {
		var meldung = 'EINGABEFEHLER\n\n';
		var trenner = '-----------------------------------------------------------------------------------------------\t\t\n\n';
		meldung += trenner;
		if (nichtausgefuellt) {
			meldung += 'Folgende Felder muessen ausgefuellt werden:\n\n'
			meldung += nichtausgefuellt;
			if (fehler) {
				meldung += '\n'+trenner;
			}
		}
		if (fehler) {
			meldung += 'Folgende Felder wurden falsch ausgefuellt:\n\n'
			meldung += fehler;
			meldung += '\n';
		}
		alert(meldung);
		return false;
	}
}


window.onload = function()
{
	DFNavigate.init();
	DFSetzeTargetBlank();
}

var openCloseNews = function(id)
{
	var obj = document.getElementById(id);
	if (obj.className == 'active')
		obj.className = '';
	else
		obj.className = 'active'
	
};