var admin = false;
var levelString = '';

/* anti 5P4M device */
function callClient(ext, dom, usr, callSubject, callBody) {
	callSubject = (callSubject == null) ? '' : callSubject;
	callBody = (callBody == null) ? '' : callBody;

	qstring = (callSubject == '') ? '' : '?subject=' + encodeURIComponent(callSubject);
	qstring += (callBody == '') ? '' : (qstring == '') ? '?body=' + encodeURIComponent(callBody) : '&body=' + encodeURIComponent(callBody);
	document.location.href = 'mailto:' + usr + '@' + dom + '.' + ext + qstring;
}

function showPeople(url) {
	if (url != '') {
		document.location.href = url;
	}
	return false;
}

function changeOffice() {
	var selectElement = document.forms['officeForm'].elements['office'];

	var office = selectElement.options[selectElement.options.selectedIndex].value; 
	if (office != '') {
		document.location.href = office;
	} else {
		return false
	};	
}

function email(requestType, variable, ext, dom, usr, mailSubject, mailBody) {

	mailSubject = (mailSubject == null) ? '' : mailSubject;
	mailBody = (mailBody == null) ? '' : mailBody;
	
	
	formFile = ''
	switch(requestType) {
	case 'callback':
		formFile = 'callback.php';
		
		break;
	case 'subscribe':
		formFile = 'subscribe.php';
		break;

	case 'reserve place':
		formFile = 'reserve-place.php';
		var moduleID = variable;
		var town = ext;
		break;
	}

	if (formFile != '') {
		// create the page cover (semi-transparent black cover)
		var el = document.createElement('div');
		el.setAttribute('id','formCover');
		el.setAttribute('class','open');
		//document.body.insertBefore(el, document.getElementById('lala'));
		document.body.appendChild(el);
	
		if (document.height) {
			var pageHeight = (document.documentElement.scrollHeight > document.height) ? document.documentElement.scrollHeight : document.height;
		} else {
			var pageHeight = document.documentElement.scrollHeight;
		}
		el.style.height = pageHeight + 'px'; // make it fit the window;
	
	
	
		el = document.createElement('div');
		el.setAttribute('id','formIframe');
		//document.body.insertBefore(el, document.getElementById('lala'));
		document.body.appendChild(el);
		el.style.top = (document.documentElement.scrollTop + 20) + 'px';
		var windowWidth = getWindowWidth();
		el.style.left = ((windowWidth - 960) / 2) + 'px';
	
		var qString = '';
		switch (requestType) {
		case 'callback':
			qString = 'launchPage=' + variable;
			break;
		case 'subscribe':
			qString = 'subscribe_to=' + variable;
			break;
		case 'reserve place':
			qString = 'module_id=' + moduleID + '&town=' + town;
			break;
		}
		el.innerHTML = '<iframe name="formIframe" src="' + levelString + 'forms/' + formFile + '?' + qString + '" width="940" height="555" frameborder="no" border="0" scrolling="no" style="border:0;"></iframe>';
	} else {

		switch(requestType) {
		case 'email cv':
			callClient(ext, dom, usr, mailSubject, mailBody);
			break;
		case 'ask question':
		
			callClient(ext, dom, usr, 'I have a question' + ((variable != '') ? ' about ' + variable : ''), mailBody);
			break;
/*		case 'email target event':
			callClient(ext, dom, usr, mailSubject, 'Please reserve me a place on the event on ' + mailBody);
			break;
*/
		case 'email industry event':
			callClient(ext, dom, usr, mailSubject, 'Please send me more information for this event: ' + mailBody);
			break;
		case 'email corporate event':
			callClient(ext, dom, usr, mailSubject, 'Please let me know if I can attend this event: ' + mailBody);
			break;
		default:
			callClient(ext, dom, usr, mailSubject, mailBody);
			break;
		}
			
		
	}
}

function closeFormFrame() {
	if (document.getElementById('formIframe')) {
		document.getElementById('formCover').parentNode.removeChild(document.getElementById('formCover'));
		document.getElementById('formIframe').parentNode.removeChild(document.getElementById('formIframe'));
	} else {
		parent.document.getElementById('formIframe').parentNode.removeChild(parent.document.getElementById('formIframe'));
		parent.document.getElementById('formIframe').parentNode.removeChild(parent.document.getElementById('formIframe'));
	}
}
			 
			 
function getWindowWidth() {
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
		myWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}

var currentFrontpageArticle = 0;
function frontpageArticle(direction) {
	if (articlesArray != '') {
		if (direction == '+') {
			currentFrontpageArticle ++;
			if (currentFrontpageArticle + 1 > articlesArray.length) {
				currentFrontpageArticle = 0;
			}
		} else {
			currentFrontpageArticle --;
			if (currentFrontpageArticle < 0) {
				currentFrontpageArticle = articlesArray.length - 1;
			}
		}
		document.getElementById('articleTitel').innerHTML = articlesArray[currentFrontpageArticle][0];
		document.getElementById('articleTopicArea').innerHTML = articlesArray[currentFrontpageArticle][1];
		document.getElementById('articleDescription').innerHTML = articlesArray[currentFrontpageArticle][2];
		document.getElementById('articleUrl').innerHTML = '<a class="standAlone" href="' + articlesArray[currentFrontpageArticle][3] + '">Read the full article</a>';

//	' . $fileUrl . 
	}
}

function createProjector() {
	// create the page cover (semi-transparent black cover)
	var el = document.createElement('div');
	el.setAttribute('id','pageCover');
	el.setAttribute('class','open');
	if (el.addEventListener) {
		el.addEventListener('click',closeProjector,false);
	} else {
		el.onclick = closeProjector;	
	}

	document.getElementById('center').appendChild(el); // NB doesn't show in IE7,but better than the next option
	//document.body.appendChild(el); 

	if (document.height) {
		var pageHeight = (document.documentElement.scrollHeight > document.height) ? document.documentElement.scrollHeight : document.height;
	} else {
		var pageHeight = document.documentElement.scrollHeight;
	}
	el.style.height = pageHeight + 'px'; // make it fit the window;



	el = document.createElement('div');
	el.setAttribute('id','flashMovie');
	/*
	document.body.appendChild(el);
	el.style.left = ((windowWidth - 940) / 2) + 'px';
*/

	document.getElementById('center').appendChild(el);
	el.style.top = (document.documentElement.scrollTop + 50) + 'px';
	el.style.left = '32px';	
	return el;
}

function playAnimation() {
	
	el = createProjector();
	el.innerHTML = document.getElementById('hiddenFlashMovie').innerHTML;
}

function closeProjector() {
	if (document.getElementById('flashMovie')) {
		document.getElementById('pageCover').parentNode.removeChild(document.getElementById('pageCover'));
		document.getElementById('flashMovie').parentNode.removeChild(document.getElementById('flashMovie'));
	} else {
		parent.document.getElementById('pageCover').parentNode.removeChild(parent.document.getElementById('pageCover'));
		parent.document.getElementById('flashMovie').parentNode.removeChild(parent.document.getElementById('flashMovie'));
	}
}


function launchServicesList() {
	el = createProjector();
	el.innerHTML = '<iframe name="projectorIframe" id="projectorIframe"  src="' + levelString + 'services/all-services.php" width="902" height="555" border="0" frameborder="0" style="border:0; margin-left:20px;" scrolling="no" ></iframe>';
}