// JavaScript Document

/* Init include functions
 : Functions to be able to include other files inside this script
*/
/* Include JS
 : include Javascript file
 : PARAMETERS
 : filename : path of file
*/
function includeJS(filename)
{
	script = document.createElement("script");
	script.src = filename;
	script.type = "text/javascript";
	script.language = "Javascript";
	document.getElementsByTagName("head")[0].appendChild(script);
}

/* Include CSS
 : include CSS (stylesheet) file
 : PARAMETERS
 : filename : path of CSS file
*/
function includeCSS(filename, id)
{
	style = document.createElement("link");
	style.href = filename;
	style.type = "text/css";
	style.rel = "stylesheet";
	style.id = id;
	document.getElementsByTagName("head")[0].appendChild(style);
}

/* Change Lightwindow CSS file 
 : change the CSS file that's being used on the Lightwindow overlay (different styles for messages and videoplayer)
 : PARAMETERS
 : url : path of file
*/
function changeLightwindowCSS(url) {
	var el = document.getElementById("lightwindowCSS");
	el.href=url;
}



var myDomain = document.domain.split(".");
var loc = "";

switch(myDomain[2]) {
	case "jobs": 
		loc = "/careers/scripts/";
		break;
	case "intranet": 
		loc = "/eip/jvs_global/scripts/";
		break;
	default:
		loc = "/careers/scripts/";
}

/* Call Lightwindow Message
 : Open page/message inside an overlay, with a specific width, and height
 : PARAMETERS 
 : l : page to be displayed
 : t : title to be displayed
 : w : width of message box
 : h : height of message box
*/
function callLightWindowMessage(l,t,w,h) {
	<!-- Include LightWindow Scripts -->
	//setTimeout(function(){includeJS(loc + "prototype.js");},100);
	//setTimeout(function(){includeJS(loc + "effects.js");},700);
	//setTimeout(function(){includeJS(loc + "lightwindow.js");},1300);
	<!-- Include default LightWindow CSS -->
	setTimeout(function(){includeCSS("/xpedio/images/mult/350653_EN.css","lightwindowCSS");},100);
	
	setTimeout(function(){
		lightwindowInit();
		changeLightwindowCSS("/xpedio/images/mult/350653_EN.css");

		//Call Message
		//if (myLightWindow == null) {includeJS(loc + "lightwindow.js");}
		myLightWindow.activateWindow({
		href: l,
		title: t,
		width: w,
		height: h
		});
		//END Call Message
	},1500);
}

/* Call Lightwindow Videoplayer
 : Open videoplayer inside an overlay
 : PARAMETERS 
 : lang : language (used to load correct XML data)
 : site : site
 : cat : video category/group
 : name : name of video inside category
*/
function callLightWindowVideo(lang,site,cat, name) {
	<!-- Include LightWindow Scripts -->
	//setTimeout(function(){includeJS(loc + "prototype.js");},100);
	//setTimeout(function(){includeJS(loc + "effects.js");},700);
	//setTimeout(function(){includeJS(loc + "lightwindow.js");},1300);
	<!-- Include default LightWindow CSS -->
	setTimeout(function(){includeCSS("/xpedio/images/mult/350653_EN.css","lightwindowCSS");},100);
	<!-- Include Movie player functions-->
	setTimeout(function(){includeJS("/xpedio/images/mult/404807_EN.js");},500);
	
	setTimeout(function(){
		lightwindowInit();
		var xmlID = "404805" + "_" + lang; // = StellentID XML Movie data
		changeLightwindowCSS("/xpedio/images/mult/404919_EN.css");
		var playerWidth = getPlayerWidth(xmlID,site,cat,name);
		var playerHeight = getPlayerHeight(xmlID,site,cat,name);

		//Call Videoplayer
		//if (myLightWindow == null) {includeJS(loc + "lightwindow.js");}
		myLightWindow.activateWindow({
		href: 'showdoc2.jsp?htmlid=404803&site='+site+'&cat='+cat+'&name='+name+'&xmlID='+xmlID,
		title: ' Videoplayer',
		width: playerWidth,
		height: playerHeight,
		loadingAnimation: false
 		});
		//END Call Message
	},1500);
}

/* Tell a friend
 : Send a page to a friend. The function gets all paramaters from the url and puts them back together while linking to the TAF coupon.
 : RESULT
 : Redirect to the TAF coupon where you can enter the details.
*/
function tellAFriend() {
	 
	var docID = getArg('docid');
	var htmlID = getArg('htmlid');
	var menopt = getArg('menopt');
	var lang = getArg('lang');
	var docidRC = getArg('docidrc');
	var htmlidRC = getArg('htmlidrc');
	var lastSlash = window.location.href.lastIndexOf('/');
	var domain = window.location.href.substr(0,lastSlash+1);
	
	if (docID == null || docID == "") docID = "docid=";
	else docID = "docid=" + docID;
	
	if (htmlID == null || htmlID == "") htmlID = "htmlid=";
	else htmlID = "htmlid=" + htmlID;
	
	if (menopt == null || menopt == "") menopt = "menopt=";
	else menopt = "menopt=" + menopt;
	
	if (lang == null || lang == "") lang = "lang=";
	else lang = "lang=" + lang;
	
	if (docidRC == null || docidRC == "") docidRC = "docidrc=";
	else docidRC = "docidrc=" + docidRC;
	
	if (htmlidRC == null || htmlidRC == "") htmlidRC = "htmlidrc=";
	else htmlidRC = "htmlidrc=" + htmlidRC;
	
	var combine = docID + "&" + htmlID + "&" + menopt + "&" + lang + "&" + docidRC + "&" + htmlidRC;
	combine = escape(combine);
	var site = domain + "coupon.jsp?cp=TAF_Pages&"+menopt+"&GPEJobID=" + combine;
	window.location.href = site;

}

/* Create LinkedIn Connections link (HTML)
 : Create the HTML link to display the the LinkedIn Connections popup
 : PARAMETERS
 : xLabel : Label for the link
 : xCat : Category name of connections to be displayed
*/
function LinkedInBox(xLabel, xCat) {

	//includeJS("http://www.linkedin.com/companyInsider?script&useBorder=yes");

	var boxSTYLE="";
	var boxHTML="";
	var boxSCRIPT="";

	boxSTYLE+="span.linkedIn_out {color:#000000; font-weight: normal;}";
	boxSTYLE+="span.linkedIn_hover {color:#000000; font-weight: normal; text-decoration:underline; cursor:pointer;}";

	boxHTML+="<li class=bullet><span id='in1' style='vertical-align:top'>";
	boxHTML+="<span class=linkedIn_out onmouseover='this.className=\"linkedIn_hover\"' ";
	boxHTML+="onmouseout='this.className=\"linkedIn_out\"'>"+xLabel+"at <b>Linked</b></span>";
	boxHTML+="</span></li>";

	boxSCRIPT+="new LinkedIn.CompanyInsiderPopup('in1', '"+xCat+"');";

	var newStyle = document.createElement("style"); 
	newStyle.type= "text/css";
	newStyle.id = "linkedInStyle";
	try {
		newStyle.appendChild(document.createTextNode(boxSTYLE));}
	catch(e) {//IE
		newStyle.styleSheet.cssText = boxSTYLE;}
	var licb = document.getElementById("LinkedInConnectionsBox"); 
	licb.parentNode.insertBefore(newStyle, licb.nextSibling);

	var newBullet = document.createElement('ul'); 
	newBullet.id = "linkedInBulletItem";
	var list = document.getElementById('linkedInStyle'); 
	list.parentNode.insertBefore(newBullet, list.nextSibling);
	document.getElementById('linkedInBulletItem').innerHTML = boxHTML;

	var newScript = document.createElement('script'); 
	newScript.id = "linkedInScript";
	newScript.type = "text/javascript";
	newScript.language = "javascript";
	newScript.text = boxSCRIPT;
	var libi = document.getElementById('linkedInBulletItem'); 
	setTimeout(function() {libi.parentNode.insertBefore(newScript, libi.nextSibling)},300);

}

/* Open LinkedIn Connections box from a Flash element (FLASH)
 : Display the LinkedIn Connections popup triggered from inside a Flash element
 : PARAMETERS
 : xLabel : Label for the link (not used in this case)
 : xCat : Category name of connections to be displayed
*/
function LinkedInFlashBox(xLabel, xCat) {
	//includeJS("http://www.linkedin.com/companyInsider?script&useBorder=yes");
	
	var boxHTML="";
	
	boxHTML+='<style type="text/css">';
	boxHTML+='span.linkedIn_out {color:#000000; font-weight: bold;}span.linkedIn_hover {color:#000000; font-weight: bold; text-decoration:underline; cursor:pointer;}';
	boxHTML+='</style>';
	boxHTML+='<span id="in1" class="company-insider-pop-up" style="vertical-align: top;">';
	boxHTML+='</span>';
	
	document.getElementById('linkedInBox').innerHTML = boxHTML;
	
	new LinkedIn.CompanyInsiderPopup("in1", xCat);
	
	var positionLeft = findPosX(document.getElementById('linkedin'));
	var positionTop = findPosY(document.getElementById('linkedin'));
	var fullWidth = document.body.clientWidth;
	var docWidth = document.getElementById('header').offsetWidth;
	var pageLeftSpace = (fullWidth - docWidth) /2;
	var bannerWidth = document.getElementById('linkedin').width;
	var id = document.getElementById('linkedInBox');
	
	id.getElementsByTagName('img')[0].src = "images/shim.gif";
	id.getElementsByTagName('img')[0].style.width = "5px";
	if (bannerWidth == 224) {
		id.getElementsByTagName('img')[0].height = "15px";
		id.style.height = "15px";
		id.style.top=(positionTop) + "px";
		if (bName == "Microsoft Internet Explorer")	id.style.top=(positionTop + 95) + "px";
		}
	else {
		id.getElementsByTagName('img')[0].height = "45px";
		id.style.height="45px";
		id.style.top=(positionTop - 36) + "px";
		if (bName == "Microsoft Internet Explorer")	id.style.top=(positionTop + 70) + "px";
	}
	id.style.width = "5px";
	id.style.left = (positionLeft - pageLeftSpace) + 50 + "px";
	setTimeout("clickLinkedIn()",500);
}

/* Display the LinkedIn Connections box from a Flash element
 : This function is automatically called from inside the LinkedInFlashBox() function
 : Never call this function directly. Use LinkedInFlashBox() instead.
*/
function clickLinkedIn() {
	var id = document.getElementById('linkedInBox');
	if (bName == "Microsoft Internet Explorer") {
		id.getElementsByTagName('img')[0].click();
		}
	else {
		id.getElementsByTagName('img')[0].click = function() {
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);}
		id.getElementsByTagName('img')[0].click();
	} 

}

/* Find X Position of an object
 : Returns the X position (from the left) from the given object
 : PARAMETERS
 : obj : The (HTML) object from which the X coordinate should be returned (f.e. a div or an image)
*/
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

/* Find Y Position of an object
 : Returns the Y position (from the top) from the given object
 : PARAMETERS
 : obj : The (HTML) object from which the Y coordinate should be returned (f.e. a div or an image)
*/
function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

/* Get a specified argument from the url
 : Returns the value of the argument or returns an empty string in case the argument was not found
 : PARAMETERS
 : xArg : the name of the argument
*/
function getArg( xArg ) {
	var result = "";
	
	//URL inladen en opsplitsen in verschillende multilevel arrays.
	var mainURL = window.location.href;
	
	if (mainURL.indexOf('?') > -1) {
		var URLparts = mainURL.split('?');
		var Arguments = URLparts[1].split('&');
		var pair;
		//voor elke element in array Arguments ...
		for (i=0; i<Arguments.length; i++) {
		  //create nieuwe array in array Arguments. 
		  //Deze array zal elke keer maar uit twee elementen betalen nl. deel voor '=' en het deel na '='
		  pair = Arguments[i].split('='); 
		//Als deel 1 van array pair gelijk is aan waarde van xArg dan return deel 2 van array pair
		  if (pair[0]==xArg) { 
			result = pair[1]; 
		  }
		}
		return result;
	}
	else {
	//Indien niet gelijk return null (parameter bestaat niet in URL)
	return result;
	}
}

/* Switch between internet or intranet target link
 : If a page is published for internet as well as intranet, you can use this function to define two target urls for a link on the page.
 : PARAMETERS
 : internetLink : the target url for the internet version
 : intranetLink : the target url for the intranet version
 : popup : 'true" if you want the link to open in a new window, 'false' if you want the link to open in the same window.
*/
function selectLink(internetLink, intranetLink, popup) {
	var vLink;
	vLink = (window.location.hostname.indexOf('intranet')>-1)? intranetLink : internetLink;
	if (popup) {
		openWindowC(vLink,800,600,1,1,0,1,1,1);
	}
	else {
		window.location.href=vLink;
	}
}

