/**
 * @author Luke
 */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

function openTech(filename){
	myLightWindow.activateWindow({
		href: "/"+filename,
		author: 'CYTE-Team',
		title: '',
		left: 0,
		width: 462,
		height: 357,
		top: 400
	});
	return flase;
}

function redirect_to_start(){
	var cyteStart = readCookie('cyteStart');
	var url = window.location.href;
	var start_from = url.indexOf(".ch/");	
	var params = url.substring(start_from+4);



	if (params == "") {
		if (cyteStart) {
			switch (cyteStart) {
				case "cyte":
					window.location.replace('/cyte/');
					break;
				case "team":
					window.location.replace('/team/');
					break;
				case "angebot":
					window.location.replace('/angebot/');
					break;
				case "infos":
					window.location.replace('/infos/');
					break;
				default:
					window.location.replace('/cyte/');
					break;
			}
		}
	}
}

function lightWindow_DoneLoading(){
	var cyteStart = readCookie('cyteStart');
	var url = window.location.href;
	var start_from = url.indexOf(".ch/");	
	var params = url.substring(start_from+4);

	// Nur wenn das Root-verzeichnis aufgeruft wurde
	if (params == "") {
		if(!cyteStart) {
			openTech("welcome.html");
		}
	}
}   

redirect_to_start();

if (gup("welcome")){
	var date = new Date();
	date.setTime(date.getTime()+(365*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie ='cyteStart='+gup("welcome")+'; expires='+expires+'; path=/'
}




