
// XUM:
// Kommentare fuer die Umstrukturierung
//
//
// Hier sind erstmal alle Funktionen rausgeflogen. Wenn etwas fehlt und
// wirklich in die "general" Version hinein soll, muss das nach Bedarf
// geschehen.
//
// over() und out() funktionieren nicht im Mozilla
//


// on load instructions at the end of this file

var rbPopupID = "RBDocumentPopup";
var STATUS_OPENED_IN_POPUP = 1;
var STATUS_OPENED_IN_MAIN_WINDOW = 2;

//---- functions ----

function BrowserCheck() {
	ver=navigator.appVersion;
	b = navigator.appName;
	dom=document.getElementById?1:0;

	ie=(b.indexOf("Microsoft Internet Explorer")!= -1)?1:0;
	ns=(b.indexOf("Netscape")!= -1)?1:0;
	ie4=(document.all && !dom)?1:0;
	ie5=((ver.indexOf("MSIE 5")>-1 ||ver.indexOf("MSIE 6")>-1)  && dom)?1:0;
	ie6=(ver.indexOf("MSIE 6")>-1 && dom)?1:0;
	ns4=(document.layers && !dom)?1:0;
	ns5=(dom && parseInt(ver) >= 5) ?1:0;
	macns4=(ver.indexOf("Mac")!= -1 && ns4)?1:0;
	macns5=(ver.indexOf("Mac")!= -1 && ns5)?1:0;
	macie45=(ver.indexOf("Mac")!= -1 && ie4)?1:0;
	macie5=(ver.indexOf("Mac")!= -1 && ie5)?1:0;
}

function FrameCheck() {

	var cookieUniqueID = "COMnoFramingCookie";

	//var url = this.document.URL;
	var url = this.document.location.href;
	/*
	alert ("url : " + url
			+ "\nhref: " + this.document.location.href
			+ "\ntop.location: " + top.location
			);
	*/

	if (url.search('/consultantforaday.+/')!=-1) return;
	
	// set cookie if url contains keyword ("noframing")
	if (url.indexOf ("noframing") != -1) {
		//setCookie (cookieUniqueID, "yes", "/", window.location.hostname);
		setCookie (cookieUniqueID, "yes");
		return;
	}

	// remove cookie if url contains keyword ("noframing")
	if ((url.indexOf ("framing") != -1) && (url.indexOf ("noframing") == -1)) {
		deleteCookie (cookieUniqueID);
	}

	// skip auto-framing if there is a cookie set
	if (getCookie (cookieUniqueID) != null) {
		return;
	}


	// frame or not frame that is the question
	if (self==top) {
		var target=self.location.pathname;

		var status=openObject(target);

		if (status == STATUS_OPENED_IN_POPUP && self.name != rbPopupID) {
			// object was opened in popup, so redirect main
			// window to homepage
			self.location.href = "http://www.rolandberger.com/";
		}
	}
}


function CSSFileChooser() {
	BrowserCheck();
	if (ie || macie5 || ns5) document.write("<link rel='stylesheet' type='text/css' href='/general/css/rb.css' /><link rel='shortcut icon' href='/favicon.ico' />");
	else if (ns4) document.write("<link rel=\"stylesheet\" type=\"text/css\" href=../webgallerie_files/submenu_files//%22/general/css/rb_n4.css/%22 /><link rel='shortcut icon' href='/favicon.ico' />");
	else if (macns4) document.write("<link rel='stylesheet' type='text/css' href='/general/css/rb_macn4.css' /><link rel='shortcut icon' href='/favicon.ico' />");
	document.write("<link rel='stylesheet' type='text/css' href='/general/css/rb_js.css' />");
}

function over (name,id) {
	if (ns5) {
		img = document.getElementsByName(name)[0];
		//img.src = img.src.replace('_p\.gif','_a.gif');
		img.setAttribute('src', img.getAttribute('src').replace('_p\.gif','_a.gif'));
	}
	else {
		var x=document.images[name].src;
		x= x.replace(/_p\.gif/,'_a.gif');
		document.images[name].src=x;
	}
}

function out (name,id) {
	if(ns5) {
		img = document.getElementsByName(name)[0];
		img.setAttribute('src', img.getAttribute('src').replace('_a\.gif','_p.gif'));
	}
	else {
		var x=document.images[name].src;
		x= x.replace(/_a\.gif/,'_p.gif');
		document.images[name].src=x;
	}
}


function overer (name,id) {
	if (ns5) {
		img = document.getElementsByName(name)[0];
		//img.src = img.src.replace('_p\.gif','_a.gif');
		img.setAttribute('src', img.getAttribute('src').replace('_normal\.gif','_over.gif'));
	}
	else {
		var x=document.images[name].src;
		x= x.replace(/_normal\.gif/,'_over.gif');
		document.images[name].src=x;
	}
}

function outer (name,id) {
	if(ns5) {
		img = document.getElementsByName(name)[0];
		img.setAttribute('src', img.getAttribute('src').replace('_over.gif','_normal.gif'));
	}
	else {
		var x=document.images[name].src;
		x= x.replace(/_over.gif/,'_normal.gif');
		document.images[name].src=x;
	}
}


function preload(imgObj,imgSrc) {
	eval(imgObj+' = new Image()');
	eval(imgObj+'.src = "'+imgSrc+'"');
}

// fill status line
function fillStatus(txt) {
	self.status = txt
}

// clear status line
function emptyStatus() {
	self.status = ""
}

//function for building valid e-mail adresses to protect rb from spam
function getContact( domain, name ) {
	var result = "&#x6D;&#97;&#105;&#108;&#116;&#111;&#58;" + name + "&#64" + domain;
	return result; 
}


// popup of contact servlet to HTTPS server
function contact_https(URL) {
	oldURL = URL;
	str = window.location.href;
	skipChars = str.indexOf('//');
	if (skipChars > -1) {
		cutAt = str.indexOf('/', skipChars+2)
			if (cutAt > -1) {
				hostname=str.substr(skipChars+2, cutAt-skipChars-2);
				// workaround for the certificate
				if (hostname != "alumni" && hostname != "projects") {
					hostname = "www.rolandberger.de";
				}
				URL="https://" + hostname + URL
			}
	}
	win = window.open( URL ,"contact","toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,dependent=0,width=500,height=480");
	win.focus();
}


// pull down trigger; the "formfield" argument is the select box
function pulldownChange(formfield) { // call page in the same frame
	pulldownChangeWithTarget (formfield, self);
}

// pull down trigger; the "formfield" argument is the select box
function pulldownChangeWithTarget(formfield, target) {
	// call page in specified frame
	var info = formfield.selectedIndex
		if (formfield.options[info].value != "0") {
			target.location=formfield.options[info].value;
		}
}

function openObject (p_object) {

	var msg = "object: " + p_object + "\n"
		+ "this: " + self.name + "\n"
		+ "parent: " + parent.name + "\n"
		+ "\n";

	//Path to NaviServlet
	var naviServletSubcontentPath='/www/NavigationServlet/en/navigation/0/mainFrame?subcontentpage=';
	//http://www.google.de&menuealias=HELP

	var naviServletPathEn = "/www/NavigationServlet/en/navigation/0/mainFrame?contentpage=";
	var naviServletPathDe = "/www/NavigationServlet/de/navigation/0/mainFrame?contentpage=";

	// get type from suffix
	var type = p_object.substring (p_object.lastIndexOf (".") + 1, p_object.length);

	//alert (msg);

	// brain document popups
	if (pos = p_object.indexOf('/documents/')!=-1 ) {
		showObject_BRAINDoc (p_object);
		return STATUS_OPENED_IN_POPUP;

		// PDF document
	} else if (type.length > 0 && type.toLowerCase() == "pdf") {
		showInPopup(p_object, 770, 449);
		return STATUS_OPENED_IN_POPUP;

		// global-network popups
	} else if (pos = p_object.indexOf('join_us/recruiting_contacts/')!=-1 ) {
	return;
		showObject_recruitingContact (p_object);
		//return STATUS_OPENED_IN_POPUP;
		return STATUS_OPENED_IN_POPUP;

		// Topics popup
	} else if ((pos = p_object.indexOf('/customized/topics/'))!=-1 ) {
		showObject_topics (p_object);
		return STATUS_OPENED_IN_POPUP;

		// customized popup
	} else if ((pos = p_object.indexOf('/customized/'))!=-1 ) {
		showInPopup (p_object, 800, 600);
		return STATUS_OPENED_IN_POPUP;

		// metadata sitemap popup
	} else if ((pos = p_object.indexOf('/metadata/en/html/sitemap/'))!=-1 ) {
		showObject_sitemap (p_object);
		return STATUS_OPENED_IN_POPUP;

		// schon mit NaviServletPfad
	} else if (p_object.indexOf('/www/NavigationServlet/')!=-1) {
		replaceLocation (p_object);
		return STATUS_OPENED_IN_MAIN_WINDOW;

	} else if (p_object.indexOf("/de/")!= -1) {
		// opens a content page by using the naviservlet
		replaceLocation (naviServletPathDe + p_object);
		return STATUS_OPENED_IN_MAIN_WINDOW;

	// everything in general should not be opened as single document
	} else if (p_object.indexOf("/general/") == 0) {
		//self.location.href = "http://www.rolandberger.com/";
		replaceLocation ("http://www.rolandberger.com/");

	} else if (p_object.indexOf("/en/")!= -1) {
		// opens a content page by using the naviservlet
		replaceLocation (naviServletPathEn + p_object);
		return STATUS_OPENED_IN_MAIN_WINDOW;
	}

	// opens remaining documents (e.g. homepage)
	return STATUS_OPENED_IN_MAIN_WINDOW;

}

// general popup function
function showInPopup(p_url, p_width, p_height, p_popupId, properties) {

	// normally the popup will get the standard popup-id as name
	var id = rbPopupID;

	if (p_popupId != undefined) {
		id = p_popupId;
	}

	/*
	alert ("popupId: " + id
			+ "\nthis.name: " + this.name
			+ "\np_url: " + p_url
			+ "\nthis.location.pathname: " + this.location.pathname
			);
	*/
	if (this.location.pathname == p_url && this.name == rbPopupID ) {
		// recursive call to this function so we do not open this document
		// again

		//alert ("recursion aborted");
		return;
	}

	var popUpHandler;
	// open document in popup
	eval ("popUpHandler=window.open('" + p_url + "','" + id + "','width=" + p_width + ",height=" + p_height + ",scrollbars=yes,location=no,resizable=yes,directories=no,status = 1,menubar = 0,toolbar = no,titlebar = 1,left = 50,top=50')");

	// does this work?
	popUpHandler.focus();
}

// location replace function
function replaceLocation (p_url, p_targetObject) {
	// default target is "this"
	var target=this;

	// get target if specified as argument
	if (p_targetObject != undefined) {
		target = p_targetObject;
	}

	//alert ("oeffne " + p_url);
	// if there is js 1.1 support (document.images do exist)...
	if(document.images) {
		// ...use replace since this will handle the history the right way
		target.location.replace(p_url); 
	}
	else {
		target.location.href = p_url ;
	}
}

// opens a recruiting contact in a popup
function showObject_recruitingContact (p_url) {
	var url = p_url;

	var lastSlash = url.lastIndexOf ("/");
	var basename = url.substring (lastSlash + 1, url.length);
	var pathname = url.substring (0, lastSlash + 1);

	// if this is only the head frame just get the url of the content frame
	if (basename.indexOf ("_head.html") != -1) {
		var newBasename = basename.substring (0, basename.indexOf ("_head.html")) + ".html";
		//alert("head frame! " + basename + " -> " + newBasename);
		basename = newBasename;
		url = pathname + basename;
	}
	
	// pages need an own frameset so if there is no "fs" after the last '/' the
	// frameset has to be added.
	if (basename.indexOf ("fs") != 0) {
		// insert "fs" before filename
		var url = pathname + "fs" + basename;
	}

	/*
	alert ("url: " + url
			+ "\npathname: " + pathname + "   basename: " + basename
			+ "\nthis.name: " + this.name
			+ "\nurl: " + url
			+ "\nthis.location.pathname: " + this.location.pathname
			);
	*/
	var rbRecruitingContactsPopupId = "RBRecruiting";
	if (this.name == rbRecruitingContactsPopupId) {
		//alert ("no popup!");
		//if (url != this.location.pathname) {
			replaceLocation (url, rbRecruitingContactsPopupId);
		//}
	}
	else {
		//alert ("popup!");
		showInPopup (url, 420, 350, rbRecruitingContactsPopupId);
	}
}

// opens sitemap in a popup
function showObject_sitemap (p_url) {
	var url = p_url;

	// replace filename with sitemap frameset name
	positionOfLastSlash = url.lastIndexOf('/') + 1;
	url = url.substring(0, positionOfLastSlash) + "fs-sitemap.html";
	url = "/www/sefeeder/";

	showInPopup (url, 780, 550, 'RBSitemap');
}


// opens the topic window
function showObject_topics (p_url) {
	topics = top.open("http://topics.rolandberger.com/detection.html","topics","width=800,height=600,left=20,top=50,menubar=no,locationbar=no,toolbar=no");
	//topics.moveTo(screen.width/2-400,screen.height/2-300);
	topics.focus();
	return;
}

function showObject_BRAINDoc (p_url) {
	var suffix = p_url.substring (p_url.lastIndexOf (".") + 1, p_url.length);
	var popWidth = 800;
	var popHeight = 600;
	if (suffix.length > 0 && suffix.toLowerCase() == "pdf") {
		window.open(p_url, "researchPopup","height=" + popHeight + ", width=" + popWidth + ",scrollbars=yes,resizable=yes,location=yes,status=1,toolbar=yes");
		return;
	}


	// frameset construction
	var html = '<html><head><title>Roland Berger Strategy Consultants</title>'
		+ '</head>'
		+ '<frameset rows="55,*,26" border="0" framespacing="0" frameborder="0" marginwidth="0" marginheight="0">'
		+ '    <frame name="header" src="/general/html/popup_head_varsize.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize>'

		+ '        <frame name="content" src="' + p_url + '" marginwidth="10" marginheight="0" scrolling="yes" frameborder="0" noresize>'
		+ '    <frame name="footer" src="/general/en/html/popup_footer_varsize.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" noresize>'
		+ '</frameset>'
		+ '<body bgcolor="#ffffff">'
		+ '</body></html>';
	var _w = null;
	_w = window.open('', "researchPopup","height=" + popHeight + ", width=" + popWidth + ",scrollbars=yes,resizable=yes");
	//_w.moveTo (0, 0);
	_w.focus();
	_w.document.open();
	_w.document.write(html);
	_w.document.close();

}
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
   (defaults to end of current session)
   [path] - path for which the cookie is valid
   (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
   (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
   a secure transmission
 * an argument defaults when it is assigned null as a placeholder
 * a null placeholder is not required for trailing omitted arguments
 */

function setCookie(name, value, expires, path, domain, secure) {
	var date = new Date(expires);
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + date.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}


/*
   name - name of the desired cookie
   return string containing value of specified cookie or null
   if cookie does not exist
 */

function getCookie(name) {
	if (!document.cookie) {
		return null;
	}
	var dc = document.cookie;

	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
   create cookie)
   path and domain default if assigned null or omitted if no explicit
   argument proceeds
 */

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

//---- on load code goes here ----

BrowserCheck();
FrameCheck();

