/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var bustcachevar=1 	// bust potential caching of external pages after initial request? (1=yes, 0=no)
var bustcacheparameter=""

window.setTimeout("document.getElementById('logos').style.visibility='hidden'",180000);

function ajaxpage(url, containerid) {
	var page_request = false
	if (window.XMLHttpRequest) 			// if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ 		// if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
	return false

	page_request.onreadystatechange=function() {
		loadpage(page_request, containerid)
	}

	if (bustcachevar) 				// if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
		page_request.open('GET', url+bustcacheparameter, true)
		page_request.send(null)
}

function loadpage(page_request, containerid) {
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML=page_request.responseText
}


/***********************************************
* Trick captured from elsewhere
***********************************************/

function findPosX(objname) {
	var curleft = 0;
	obj = document.getElementById(objname);
	if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}


/***********************************************
* Routinen von Helge T. Kautz
***********************************************/

bar_open = false;
moving = false;
first_click = true;
current_bar = "none";
current_topic = "none";
current_whatis = "none";
current_vid = "none";
current_newspage = "none";
interval = false;
animstep = 1;
par = 0;

function findWidth(objname) {
	var obj = document.getElementById(objname);
	return obj.offsetWidth;
}
			
function setTabPos(objname) {
	var tab = document.getElementById("submenu_tab");
	tab.style.left = findPosX(objname) - 286;
	tab.style.width = findWidth(objname) + 7;
}

function opensub(sub) {
	
	moving = true;
		
	bar = document.getElementById('submenu_bar').style;
	bar_pos = parseInt(bar.left);
				
	if (first_click) {
			document.getElementById('submenu_content').innerHTML = menu[sub];
			setTabPos("men_"+sub);
			first_click = false;
			anim_wallpaper(sub);
			return;
	}
	if (bar_open == true) {
		if (bar_pos > -578) {
			bar.left = bar_pos - 20;
			bar_timer = window.setTimeout("opensub('"+sub+"')",2);
			if (current_bar != "none") {
				document.getElementById("men_"+current_bar).style.color = "#a3a37a";
				current_bar = "none";
			}
		} else {
			document.getElementById('submenu_content').innerHTML = menu[sub];
			setTabPos("men_"+sub);
			bar_open = false;
			anim_wallpaper(sub);
		}
	} else {
		if (bar_pos < 0) {					
			bar.left = bar_pos + 20;
			bar_timer = window.setTimeout("opensub('"+sub+"')",5);
		} else {
			document.getElementById("men_"+sub).style.color = "#ffffff";
			
			// ***** Superbloeder Hack *****
			if (sub == "galerie") {
				current_topic = "screenshots";
			} else if (sub == "news") {
				current_topic = "aktuelles";
			} else if (sub == "community") {
				current_topic = "links";
			}
			if (current_topic != "none") document.getElementById("top_"+current_topic).style.color = "#ffffff";
			// ***** Ende superbloeder Hack *****
			
			bar_open = true;
			current_bar = sub;
			moving = false;
		}
	}
}

function anim_wallpaper(sub) {
	var wp1 = document.getElementById("wallpaper1");
	var wp2 = document.getElementById("wallpaper2");
	if (animstep == 1) {
		wp1.style.zIndex = "3";
		wp2.style.zIndex = "2";
		var curr_wp = parseInt(wp1.style.left);
		if (curr_wp < 0) {
			curr_wp +=25;
			wp1.style.top = 0;
			wp1.style.left = curr_wp;
		} else {
			animstep = 2;
			wp2.style.top = -400;
			wp2.style.left = 0;
			wp2.innerHTML="<img src='/"+sub+"/wp2.jpg'>";
		}	
	} else if (animstep == 2) {
		wp1.style.zIndex = "2";
		wp2.style.zIndex = "3";
		var curr_wp = parseInt(wp2.style.top);
		if (curr_wp <0) {
			curr_wp +=25;
			wp2.style.top = curr_wp;
		} else {
			animstep = 3;
			wp1.style.left = 800;
			wp1.style.top = 0;
			wp1.innerHTML="<img src='/"+sub+"/wp3.jpg'>";
		}	
	} else if (animstep == 3) {
		wp1.style.zIndex = "3";
		wp2.style.zIndex = "2";
		var curr_wp = parseInt(wp1.style.left);
		if (curr_wp > 0) {
			curr_wp -=25;
			wp1.style.left = curr_wp;
		} else {
			animstep = 4;
			wp2.style.top = 400;
			wp2.style.left = 0;
			wp2.innerHTML="<img src='/"+sub+"/wp_stop.jpg'>";
		}		
	} else if (animstep == 4) {
		wp1.style.zIndex = "2";
		wp2.style.zIndex = "3";
		var curr_wp = parseInt(wp2.style.top);
		if (curr_wp > 0) {
			curr_wp -=25;
			wp2.style.top = curr_wp;
		} else {
			animstep = 1;
			wp1.style.left = -1000;
			wp1.innerHTML="<img src='/"+sub+"/wp1.jpg'>";
			window.setTimeout("show_content_area('"+sub+"')",5);
			return;
		}		
	}
	window.setTimeout("anim_wallpaper('"+sub+"')",1);
}

function show_content_area(sub) {
	var ct = document.getElementById("inner_frame");
	var curr_ct = parseInt(ct.style.top);
	if (curr_ct < 40) {
		curr_ct += 30;
		ct.style.top = curr_ct;
		window.setTimeout("show_content_area('"+sub+"')",3);
	} else {
		ct.style.top = 25;
		window.setTimeout("opensub('"+sub+"')",5);
	}
}

function hide_content_area(sub) {
	var ct = document.getElementById("inner_frame");
	var curr_ct = parseInt(ct.style.top);
	if (curr_ct > -350) {
		curr_ct -=30;
		ct.style.top = curr_ct;
		window.setTimeout("hide_content_area('"+sub+"')",3);
	} else {
		var cmd="ajaxpage('"+sub+"/index.php?title="+document.getElementById("men_"+sub).innerHTML+"','content')";
		eval(cmd);
		// interval=setInterval(cmd,10000);
		window.setTimeout("opensub('"+sub+"')",5);
	}
}

function goto_page(sub) {
	
	if (moving == true) return;		// keine klicks akzeptieren, solange sich was bewegt.
	
	current_whatis="none";
	if (interval) clearInterval(interval);
	if (current_topic != "none") {
		document.getElementById("top_"+current_topic).style.color = "#a3a37a";
		current_topic = "none";
	}
	hide_content_area(sub);
}

function goto_topic(sup,sub) {
	current_whatis="none";
	if (interval) clearInterval(interval);
	if (current_topic != "none") document.getElementById("top_"+current_topic).style.color = "#a3a37a";
	document.getElementById("top_"+sub).style.color = "#ffffff";
	current_topic = sub;
	var cmd="ajaxpage('"+sup+"/"+sub+".php?title="+document.getElementById("top_"+sub).innerHTML+"','content')";
	eval(cmd);
//	interval=setInterval(cmd,10000);
}

function goto_dl(arg) {
	current_whatis="none";
	if (interval) clearInterval(interval);
	if (current_topic != "none") document.getElementById("top_"+current_topic).style.color = "#a3a37a";
	document.getElementById("top_"+arg).style.color = "#ffffff";
	current_topic = arg;
	var cmd="ajaxpage('downloads/dl.php?t="+arg+"','content')";
	eval(cmd);
//	interval=setInterval(cmd,10000);
}

function goto_sub(sup,sub,par) {
	if (interval) clearInterval(interval);
	cmd="ajaxpage('"+sup+"/"+sub+".php?par='+par,'content')";
	eval(cmd);
//	interval=setInterval(cmd,10000);
}

function whatis(item) {
	if (interval) clearInterval(interval); // schmutziger Trick, aber sieht ja eh keiner :-D
	if (current_whatis != "none") document.getElementById(current_whatis).style.visibility="hidden";
	document.getElementById(item).style.visibility="visible";
	document.getElementById("banner").style.visibility="hidden";
	current_whatis=item;
}
function switchsides(whatarmy) {
	current_whatis = "none";
	goto_sub('das_spiel',whatarmy);
}

function viewscreen(imgname) {
	document.getElementById("screener").src = "galerie/screens/medium/"+imgname;
}

function screenspage(page) {
	var cmd="ajaxpage('galerie/screenshots.php?current_page="+page+"&title=Screenshots','content')";
	eval(cmd);
}

function viewconcept(imgname) {
	document.getElementById("screener").src = "galerie/concepts/medium/"+imgname;
}

function conceptsspage(page) {
	var cmd="ajaxpage('galerie/konzeptzeichnungen.php?current_page="+page+"&title=Konzeptzeichnungen','content')";
	eval(cmd);
}

function showvideo(vid) {
	if (current_vid != "none") document.getElementById(current_vid).style.visibility="hidden";
	document.getElementById(vid).style.visibility="visible";
	current_vid = vid;
}

function newspage(p) {
	var cmd="ajaxpage('news/aktuelles.php?pg="+p+"&title=AKTUELLES','content')";
	eval(cmd);
}

function presspage(p) {
	var cmd="ajaxpage('news/presse.php?pg="+p+"&title=PRESSE','content')";
	eval(cmd);
}

function showNews(k,p) {
	var cmd="ajaxpage('news/newsarticle.php?pg="+p+"&k="+k+"','content')";
	eval(cmd);

}

function anmelden(status) {
	var cmd="ajaxpage('community/links.php?st="+status+"','content')";
	eval(cmd);
}

function checkinput() {
	var v = document.getElementById('de_vorname').value;
	var n = document.getElementById('de_name').value;
	var u = document.getElementById('de_url').value;
	var e = document.getElementById('de_email').value;
	
	if (v=="") {
		alert("Bitte geben Sie Ihren Vornamen an!");
	} else {
		if (n=="") {
			alert("Bitte geben Sie Ihren Namen an!");
		} else {
			if ((u=="http://") || (u=="")) {
				alert("Bitte geben Sie eine gültige URL an!");
			} else {
				var okmail = validate_email(e);
				if (okmail == false) {
						//
				} else {
					var subm = "?st=s&v="+v+"&n="+n+"&u="+u+"&e="+e;
        			var cmd="ajaxpage('community/links.php"+subm+"','content')";
        			eval(cmd);
				}
			}
		}
	}
}

function validate_email(input_str){

	var input_len1=input_str.length;
	var iserror=0;

    
	input_len1=input_str.length;
    
	if (input_len1<=5) {
		alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\n");
		iserror=1;
	}

	var lastdot=-1;
	var lastat=-1;
	var numberat=0
    
	for (var j = 0; j < input_len1; j++) {
		var ch2 = input_str.substring(j, j + 1);
		if (((ch2 < "a") ||  (ch2 > "z")) && ((ch2 < "A") || (ch2 > "Z")) && ((ch2 < "0") ||  (ch2 > "9")) && (ch2 != "@" ) && (ch2 != ".") && (ch2 != "_") && (ch2 != "-")){
			alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nFolgende Zeichen dürfen benutzt werden: A-Z, a-z, 0-9, -, _, . und @");
			iserror=1;
		}
		if (ch2==".") {
			if ( j == lastdot + 1) {
				alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nZwei Punkte hintereinander sind nicht gestattet'..'.");
				iserror=1;
			}
			lastdot=j;
		}
		if (ch2=="@") {
			lastat=j;
			numberat=numberat+1
		}
		if (ch2==" ") {
			alert("Bitte geben Sie eine gültige E-Mail-Adresse an!!\nEs dürfen keine Leerzeichen enthalten sein!");
			iserror=1;
		}
	}
	if (lastat == -1) {
		alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nSie haben kein '@'-Zeichen eingegeben!");
		iserror=1;
	}
	if (lastat == 0) {
		alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nEs fehlt ein Name vor dem '@'-Zeichen.");
		iserror=1;
	}
	if (numberat > 1) {
	alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nEs darf nur ein '@'-Zeichen enthalten sein.");
	iserror=1;
	}
	if ((lastdot <= lastat) || (lastdot > input_len1 - 3 ) || (input_len1 - lastdot > 4)) {
		alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nSie benutzen keinen zulässigen Domainnamen!\nBitte benutzen Sie  .com, .org, .net, .fr, etc.");
		iserror=1;
	}
	if (lastdot == lastat + 1) {
		alert("Bitte geben Sie eine gültige E-Mail-Adresse an!\nSie benutzen keinen korrekten Organisationsnamen!\n Benutzen Sie name@organisation.domain.");
		iserror=1;
	}
	if (iserror==1) {
		return false;
	}
	return true;
}
