// ======================================================================
// 
// JScript Source File -- copyright 2002 derStandard.at
// 
// NAME: State.js
// 
// AUTHOR: Michael Levitin, Bronner Online AG
// DATE  : 12.04.2005 v5.7
// 
// COMMENT: Client State Support 2002
// 
// sources are not to be used in other websites.
// if you want to use the navigation write to webmaster@derStandard.at
// =========================================================================

function State() {
	this.bgColor = '';
	this.bgColorC = false;
	this.bgImage = '';
	this.bgImageC = false;
	this.logoURL = '';
	this.logoURLC = false;
	this.logoLink = '';
	this.logoLinkC = false;
	this.Nav = [1,0,0];
	this.NavC = false;
	this.left = '';
	this.leftcp = '';
	this.leftC = false;
	this.uguid = '';
	this.uguidC = false;
	this.cptype = '';
	this.cp = '';
	
	this.IncludeADs = true;

	this.MozBBR = false;
	this.bosd = null;

	this.framesloaded=false;
	this.bottomloaded=false;

	this.Browser = new Is();
	
	this.Update = function(rCD) {
		if (State.Nav != rCD[0]) {
			State.Nav = rCD[0];
			State.NavC = true;
		}
		if (State.bgColor != (typeof(rCD[1][0])=='undefined'?'':rCD[1][0])) {
			State.bgColor = rCD[1][0];
			State.bgColorC = true;
			State.leftC = true;
		}
		if (State.bgImage != (typeof(rCD[1][1])=='undefined'?'':rCD[1][1])) {
			State.bgImage = rCD[1][1];
			State.bgImageC = true;
			State.leftC = true;
		}
		if (State.logoURL != (typeof(rCD[1][2])=='undefined'?'':rCD[1][2])) {
			State.logoURL = rCD[1][2];
			State.logoURLC = true;
		}
		if (State.logoLink != (typeof(rCD[1][3])=='undefined'?'':rCD[1][3])) {
			State.logoLink = rCD[1][3];
			State.logoLinkC = true;
		}
		if (State.left != rCD[2]) {
			State.left = rCD[2];
			State.leftC = true;
		}
		if (State.leftcp != rCD[3]) {
			State.leftcp = rCD[3];
			State.leftC = true;
		}
		if (State.uguid != rCD[4]) {
			State.uguid = rCD[4];
			State.uguidC = true;
		}
	}
	
	this.Change = function(cp) {
		function cutID(cp) {
			var cut;
			cut = cp.lastIndexOf('/');
			if (cut != -1) {	
				cp = cp.substr(0,cut);
				return cp;
			} else {
				return '';
			}
		}
		function findCD(cp) {
			var rCD= new Array;
			idFound:
			while(cp!='') {
				if (CD[cp]) {
					if (CD[cp][2]=='pro') {
						top.location.replace('http://'+CD[cp][1]+'/'+HAUPTFRAME.location.search+HAUPTFRAME.location.hash);
						return false;
						break idFound;
					}
					for (i=0; i<=2; i++) {
						if (!rCD[i] && CD[cp][i]) {
							rCD[i]=CD[cp][i];
						}
					}
					if (!rCD[3] && CD[cp][2]=='def') { rCD[3]=cp; }
					if (rCD[0] && rCD[1] && rCD[2] && (rCD[2]!='dcp' || rCD[3])) {
						return rCD;
						break idFound;
					}
				}
				cp = cutID(cp);
			}
			return false;
		}
		cp=cp.toLowerCase();
		if (cp.substring(0,3)=='cp/' || cp.substring(0,3)=='ad/') {
			State.cptype=cp.substring(0,3);
			cp=cp.substring(3,cp.length);
		} else {
			State.cptype='cp/';
		}
		if (State.cp != cp) {
			State.cp = cp;
			rCD=findCD(cp);
			if (!rCD) { return; }
			if (navigator.cookieEnabled && document.cookie) {
				rCD[4]=(document.cookie.indexOf('UGUID')==-1?'':document.cookie.substring(document.cookie.indexOf('UGUID')+6,(document.cookie.substring(document.cookie.indexOf('UGUID')+6,document.cookie.lenght).indexOf(';')==-1?document.cookie.length:document.cookie.substring(document.cookie.indexOf('UGUID')+6,document.cookie.lenght).indexOf(';')+document.cookie.indexOf('UGUID')+6)));
			}
			State.Update(rCD);
		}
		State.MakeItSo();
	}
	
	this.MakeItSo = function() {
		if(State.framesloaded) {
			if (State.leftC && State.Browser.safari) {
				State.leftC = false;
			}
			if (State.leftC) {
				if(State.left!='off') {
					top.document.getElementById('leftplc').style.width='120';
					top.document.getElementById('leftnav').style.width='120';
				} else {
					top.document.getElementById('leftplc').style.width='1';
					top.document.getElementById('leftnav').style.width='1';
				}
				if(State.left=='def' || State.left=='dcp') {
					top.leftnav.location.replace('http://'+top.RH_Host+'/?page=leftframe&dcp='+State.leftcp+(State.left=='dcp'?'&cp='+State.cp:''));
				} else if(State.left=='col' || State.left=='off') {
					if (State.Browser.opera) {
						top.leftnav.document.write('<html><head><title>NoNav</title></head><body bgcolor="'+State.bgColor+'"'+(State.bgImage?' background="'+State.bgImage+'"':'')+'></body></html>');
					} else {
						top.leftnav.location.replace('javascript:c=\'<html><head><title>NoNav</title></head><body bgcolor="'+State.bgColor+'"'+(State.bgImage?' background="'+State.bgImage+'"':'')+'></body></html>\'');
					}
				} else {
					top.leftnav.location.replace(State.left);
				}
				State.leftC=false;
			} else {
				if (top.leftnav.setadvframe) {
					top.leftnav.setadvframe('http://'+top.RH_Host+'/MetaAdServer/werbung.asp?rt='+State.cptype+State.cp+(!State.IncludeADs?'&s=0':''));
				}
			}
			if (State.bgColorC) {
				top.topnav.setbgColor(State.bgColor);
				State.bgColorC=false;
			}
			if (State.bgImageC) {
				top.topnav.setbgImage(State.bgImage);
				State.bgImageC=false;
			}
			if (State.logoURLC) {
				top.topnav.setlogoURL('http://'+top.RH_Host+'/img/site/logo/'+State.logoURL);
				State.logoURLC=false;
			}
			if (State.logoLinkC) {
				top.topnav.setlogoLink(State.logoLink);
				State.logoLinkC=false;
			}
			if (State.NavC) {
				top.topnav.setNav(State.Nav);
				State.NavC=false;
			}
			top.topnav.setadvframe('http://'+top.RH_Host+'/MetaAdServer/werbung.asp?rt='+State.cptype+State.cp+(!State.IncludeADs?'&s=0':''));
			if(State.bottomloaded) {
				if (State.uguidC) {
					top.fremdInterface.location.replace('http://'+top.RH_Host+'/?page=bosd');
					top.bottomnav.location.reload();
					State.uguidC=false;
				}
			} else {
				if (top.frames['bottomnav'] && State.cp.indexOf('error') != 0) {
					top.bottomnav.location.replace('http://'+top.RH_Host+(RH_PID=='Corporate'||RH_PID=='Zeitung'?'/'+RH_PID:'')+'/?page=bottomnav');
				}
			}
		} else {
			if (top.frames['topnav']) {
				top.topnav.location.replace('http://'+top.RH_Host+(RH_PID=='Corporate'||RH_PID=='Zeitung'?'/'+RH_PID:'')+'/?page=topnav');
			}
		}
	}
	
	this.loginstartcheck = function() {
		State.uguid = (document.cookie.indexOf('UGUID')==-1?'':document.cookie.substring(document.cookie.indexOf('UGUID')+6,(document.cookie.substring(document.cookie.indexOf('UGUID')+6,document.cookie.lenght).indexOf(';')==-1?document.cookie.length:document.cookie.substring(document.cookie.indexOf('UGUID')+6,document.cookie.lenght).indexOf(';')+document.cookie.indexOf('UGUID')+6)));
		State.uguidC = false;
	}
	
	this.logincheck = function() {
		if (State.uguid != (document.cookie.indexOf('UGUID')==-1?'':document.cookie.substring(document.cookie.indexOf('UGUID')+6,(document.cookie.substring(document.cookie.indexOf('UGUID')+6,document.cookie.lenght).indexOf(';')==-1?document.cookie.length:document.cookie.substring(document.cookie.indexOf('UGUID')+6,document.cookie.lenght).indexOf(';')+document.cookie.indexOf('UGUID')+6)))) {
			return true;
		} else {
			return false;
		}
	}
	
	this.login = function() {
		State.loginstartcheck();
		top.fremdInterface.location.replace('http://'+top.RH_Host+'/?page=bosd');
		top.bottomnav.location.reload();
	}
	
	this.logout = function() {
		State.uguid = '';
		State.uguidC = false;
		document.cookie = 'UGUID=BOAGFR:del; path=/;' + (top.RH_Host.toLowerCase()==top.RH_Server.toLowerCase()?' domain=.' + top.RH_Server + ';':'');
		top.bottomnav.location.reload();
		top.topnav.logout();
	}
}

// wichtigste funktionen sind newContent und newAlienContent
State = new State();

function newAlienContent(cp,url) {
	State.Change(cp);
}

function newContent(infos,cp) {
	if (typeof(infos) != 'string') {
		State.IncludeADs = infos[0];
	}
	State.Change(cp);
}
