var act=0;
var sel=0;
var ssel=0;
var out=0;

function formular(obj_id) {
	var in1=1;
	var obj = document.getElementById(obj_id);
	var list = obj.getElementsByTagName("input");
	for(var i=0;i<list.length;i++) {
		if(!(list[i].name.indexOf("a2_")>-1 ||
		   list[i].name.indexOf("logo")>-1 ||
		   list[i].name.indexOf("da_")>-1 ||
		   list[i].name.indexOf("me_")>-1 ||
		   list[i].name.indexOf("so_")>-1 ||
		   list[i].name.indexOf("ki_")>-1 ||
		   list[i].name.indexOf("pr_")>-1 ||
		   list[i].name.indexOf("fax")>-1 ||
		   list[i].name.indexOf("position")>-1 ||
		   list[i].name.indexOf("sc_")>-1) && 
		  (list[i].value=="" && document.getElementById("akz")!=list[i])) {
			in1=0;
			//alert(list[i].name);
		}
	}
	
	if(in1==0) {
		document.getElementById("formular_daten").innerHTML="<b>Bitte alle Felder ausf&uuml;llen!</b>";
	} else if(document.getElementById("akz").checked==false) {
		document.getElementById("formular_daten").innerHTML="<b>Bitte Stammdatenkorrektheit best&auml;tigen.</b>";
	} else if(document.getElementById("n_password").value!=document.getElementById("n_password1").value) {
		document.getElementById("formular_daten").innerHTML="<b>Die Passworte m&uuml;ssen &uuml;bereinstimmen!</b>";
	} else {
		document.forms[obj_id].submit();	
	}
}

function resize() {
	if(document.body!=null) {
		var gw = document.body.offsetWidth;
		var gh = document.body.offsetHeight;
				
		var objs = document.getElementById("background").getElementsByTagName("img");
		for(var i=0;i<objs.length;i++) {
			objs[i].style.height="auto";
			objs[i].style.width=gw+"px";
			if(objs[i].offsetHeight<gh) {
				objs[i].style.height=gh+"px";
				objs[i].style.width="auto";
			}
			
			var rw = (objs[i].offsetWidth-gw)/2;
			var rh = (objs[i].offsetHeight-gh)/2;
			
			objs[i].style.marginTop=(-1*rh)+"px";
			objs[i].style.marginLeft=(-1*rw)+"px";
		}
	}
	
	var ol = document.getElementById("navigation-wrapper").offsetLeft;
	var gl = document.getElementById("global-wrapper").offsetLeft;
	document.getElementById("navigation-wrapper").style.width=(gw-ol-gl)+"px";
}

function init_lib() {
	resize();
	var objs = document.getElementById("background").getElementsByTagName("img");
	for(var i=0;i<objs.length-1;i++) {
		$(objs[i]).fadeOut("slow");	
	}
	act = i;
	
	var obj = document.getElementById("selected");
	if(obj!=null) {
		sel = obj.offsetLeft+obj.offsetWidth+50;
		document.getElementById("navigation_selector").style.width=(obj.offsetLeft+obj.offsetWidth+50)+"px";
	}
		
	var obj = document.getElementById("sselected");
	if(obj!=null) {
		ssel = obj.offsetLeft+obj.offsetWidth+50;
		document.getElementById("subnavigation_selector").style.width=(obj.offsetLeft+obj.offsetWidth+50)+"px";
	}
	$("#loader").fadeOut("slow");
	
	setInterval(function() {next();},10000);
}

function next() {
	var objs = document.getElementById("background").getElementsByTagName("img");
	$(objs[act]).fadeOut("slow");
	if(act>=objs.length-1) act=0; else act++;	
	$(objs[act]).fadeIn("slow");
	resize();
}

function jump(obj,b) {
	var iobj = 	document.getElementById("navigation_selector");
	if(b==0) {
		$(iobj).stop().animate({ width: (obj.offsetLeft+obj.offsetWidth+50)+"px" }, 300);
  	} else {
	  	$(iobj).stop().animate({ width: (sel)+"px" }, 300);
  	}
}

function jumpSub(obj,b) {
	var iobj = 	document.getElementById("subnavigation_selector");
	if(b==0) {
		$(iobj).stop().animate({ width: (obj.offsetLeft+obj.offsetWidth+50)+"px" }, 300);
  	} else {
	  	$(iobj).stop().animate({ width: (ssel)+"px" }, 300);
  	}
}

window.onresize = function() { resize(); }
window.onload = function() { init_lib(); }
