/////////////////////////////////////////////////////////
// code for folder view action
/////////////////////////////////////////////////////////
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {
	isID = 1; isDHTML = 1;
} else {
	if (document.all) {
		isAll = 1; isDHTML = 1;
	} else {
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
			isLayers = 1; isDHTML = 1;
		}
	}
}

function toggle(objectID, objectID2) {
	if (isAll || isID) {
		if (document.getElementById(objectID).style.display=='block') {
			document.getElementById(objectID).style.display='none';
			document.getElementById('pic'+objectID).src = "images/sidearrow.png";		
		} else {
			document.getElementById(objectID).style.display='block';
			document.getElementById('pic'+objectID).src = "images/downarrow.png";
		}
	}
	return;
}

/////////////////////////////////////////////////////////
//code for allowing popups to control back
/////////////////////////////////////////////////////////
function openinback(toGo) {
	window.opener.top.location.href = toGo;
}

/////////////////////////////////////////////////////////
//code for replacing entire page from within iframe
/////////////////////////////////////////////////////////
function interlink(toGo) {
	top.location.href = toGo;
}

/////////////////////////////////////////////////////////
// code to reset size of iFrame of above - NOT FUNCTIONING YET
/////////////////////////////////////////////////////////
function adjustIFrameSize(id) {
	var myIframe = document.all.myframe;//getElementById(id);
	//
	if (myIframe) {
		if (myIframe.contentDocument && myIframe.contentDocument.body.offsetHeight) {
				// W3C DOM (and Mozilla) syntax
				myIframe.height = myIframe.contentDocument.body.offsetHeight;
		} else if (myIframe.Document && myIframe.Document.body.scrollHeight) {
				// IE DOM syntax
				myIframe.height = myIframe.Document.body.scrollHeight;
			}
			// bind onload events to iframe
			if (myIframe.addEventListener) {
				myIframe.addEventListener("load", resizeIframe, false);
			} else {
			myIframe.attachEvent("onload", resizeIframe);
			}
		}
	}

function resizeIframe(evt) {
	evt = (evt) ? evt : event;
	var target = (evt.target) ? evt.target : evt.srcElement;
	// take care of W3C event processing from iframes's root document
	if (target.nodeType == 9) {
		if (evt.currentTarget && evt.currentTarget.tagName.toLowerCase() == "iframe") {
			target = evt.currentTarget;
		}
	}
	if (target) {
		adjustIFrameSize(target.id);
	}
}

/////////////////////////////////////////////////////////
// code to open pop-ups
/////////////////////////////////////////////////////////
function Start(page) {
	OpenWin = window.open(page, "full", "toolbar=yes,location=yes,status=no,menubar=yes,directories=no,scrollbars=yes,resizable=yes,width=640,height=400");
}

function Popup(page) {
	OpenWin = window.open(page, "popup", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,width=540,height=400");
}

function SuggStart(page) {
	OpenWin = window.open(page, "suggstart", "toolbar=yes,location=yes,status=no,menubar=yes,directories=no,scrollbars=yes,resizable=yes,width=540,height=400");
}

function StartSmall(page) {
	OpenWin = window.open(page, "startsmall", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=no,resizable=no,width=340,height=400");
}

function StartQuicklinks(page) {
	OpenWin = window.open(page, "quicklinks", "toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=no,resizable=no,width=300,height=420");
}

/////////////////////////////////////////////////////////
// code for icon rollover labels
/////////////////////////////////////////////////////////
var titles = new Array();

titles = ['','Quick Links','Site Map','EU Today'];

function changeTitle(blip){
 document.getElementById("quicktitle").innerHTML = '<p class="quicklabel">'+titles[blip]+'</p>';
}

function refresh(page){
destination =  '../'+page;
parent.location = destination;
}

/////////////////////////////////////////////////////////
// Random factoid image script.
/////////////////////////////////////////////////////////
var theImages = new Array();
var theCaptions = new Array();
var theAlttags = new Array();

theImages[0] = 'images/factoid/image1.jpg'; theCaptions[0] = 'Copenhagen European Council, Definition of Accession Criteria'; theAlttags[0] = 'Copenhagen European Council, Definition of Accession Criteria';
theImages[1] = 'images/factoid/image2.jpg'; theCaptions[1] = 'Euro - The Singe European Currency'; theAlttags[1] = 'Euro - The Singe European Currency';
theImages[2] = 'images/factoid/image3.jpg'; theCaptions[2] = 'European Convention, 18 July 2003'; theAlttags[2] = 'European Convention, 18 July 2003';
theImages[3] = 'images/factoid/image4.jpg'; theCaptions[3] = 'European Parliament Headquarters in Strasbourg'; theAlttags[3] = 'European Parliament Headquarters in Strasbourg';
theImages[4] = 'images/factoid/image5.jpg'; theCaptions[4] = 'Flags of EU Member Nations'; theAlttags[4] = 'Flags of EU Member Nations';
theImages[5] = 'images/factoid/image6.jpg'; theCaptions[5] = 'Jacques Delors, Commission President 1985-95'; theAlttags[5] = 'Jacques Delors, Commission President 1985-95';
theImages[6] = 'images/factoid/image7.jpg'; theCaptions[6] = 'Jean Monnet'; theAlttags[6] = 'Jean Monnet';
theImages[7] = 'images/factoid/image8.jpg'; theCaptions[7] = 'Physical Map of Europe'; theAlttags[7] = 'Physical Map of Europe';
theImages[8] = 'images/factoid/image9.jpg'; theCaptions[8] = 'Robert Schuman'; theAlttags[8] = 'Robert Schuman';
theImages[9] = 'images/factoid/image10.jpg'; theCaptions[9] = 'Romano Prodi, President of the Commission'; theAlttags[9] = 'Romano Prodi, President of the Commission';
theImages[10] = 'images/factoid/image11.jpg'; theCaptions[10] = 'Signatures on the Treaty of Rome'; theAlttags[10] = 'Signatures on the Treaty of Rome';
theImages[11] = 'images/factoid/image12.jpg'; theCaptions[11] = 'Javier Solana and Vladimir Putin'; theAlttags[11] = 'Javier Solana and Vladimir Putin';
theImages[12] = 'images/factoid/image13.jpg'; theCaptions[12] = 'Charles de Gaulle, President of France'; theAlttags[12] = 'Charles de Gaulle, President of France';

var j = 0;
var p = theImages.length;
var preBuffer = new Array();
for (i = 0; i < p; i++) {
   preBuffer[i] = new Image();
   preBuffer[i].src = theImages[i];
}

var whichImage =   Math.floor(Math.random() * (1 + 12 - 0) + 0);

function showImage() {
	document.write('<img border="1" src="'+theImages[whichImage]+'" alt="'+theAlttags[whichImage]+'"><br /><h1><b>'+theCaptions[whichImage]+'</b></h1>');
}

/////////////////////////////////////////////////////////
// Random factoid text script.
/////////////////////////////////////////////////////////
var theShortlines = new Array();
var theLinks = new Array();

theShortlines[0] = 'About the two Councils? '; theLinks[0] = 'factoids/factoid1.html';
theShortlines[1] = 'About Jean Monnet\'s Cognac? '; theLinks[1] = 'factoids/factoid2.html';
theShortlines[2] = 'About the pope and subsidiarity? '; theLinks[2] = 'factoids/factoid3.html';
theShortlines[3] = 'About Norway\'s resistance to EU membership? '; theLinks[3] = 'factoids/factoid4.html';
theShortlines[4] = 'About the Danish brake on Maastricht? '; theLinks[4] = 'factoids/factoid5.html';
theShortlines[5] = 'About the 380 language combinations in the European Parliament? '; theLinks[5] = 'factoids/factoid6.html';
theShortlines[6] = 'About the Japanese family origins of an early Europeanist? '; theLinks[6] = 'factoids/factoid7.html';
theShortlines[7] = 'About the idea of merging the British and French Parliaments? '; theLinks[7] = 'factoids/factoid8.html';
theShortlines[8] = 'About the renegade socialist background of the first architect of &quot;European Union?&quot; '; theLinks[8] = 'factoids/factoid9.html';
theShortlines[9] = 'About the affiliations of Members of the European Parliament?'; theLinks[9] = 'factoids/factoid10.html';

var j = 0;
var p = theShortlines.length;
var preBuffer = new Array();
for (i = 0; i < p; i++) {
   preBuffer[i] = new Image();
   preBuffer[i].src = theShortlines[i];
}

var whichFact = Math.floor(Math.random() * (1 + 9 - 0) + 0);

function showFactoid() {
document.write('<div id="factoid"><a href="javascript:StartSmall(\''+theLinks[whichFact]+'\')">'+theShortlines[whichFact]+'</a></div>');
}

/////////////////////////////////////////////////////////
// code to full page of folder view - Research
/////////////////////////////////////////////////////////
function loadPage(){
 var srchString = unescape(location.search.substring(6, location.search.length));
 var menuhtml = '';
 var resourarray = new Array();
 var biblioarray = new Array();
 resourarray = ['General Resources','Subject Guides','Books &amp; Articles','News &amp; Analysis','Maps &amp; Atlases','Treaties &amp; Legal','Statistics','All Resources'];
 biblioarray = ['Histories &amp; Interpretations','Origins','Institutions &amp; Law','Politics of Integration','Economics of Integration','Geography of Integration','Social Europe','EC/EU, Europe &amp; The World','Personalities &amp; Memoirs','Periodicals &amp; Newspapers','Complete Bibliography'];

 if (srchString == 'paper') { menuhtml = '<p><img src="images/noarrow.png" width="15" height="15" alt=" " /><span id="present">Research Paper</span><br />';
 } else { menuhtml = '<p><img src="images/noarrow.png" width="15" height="15" alt=" " /><a href="resources.html?page=paper">Research Paper</a><br />';}

 if (srchString == 'shortpapers') { menuhtml = menuhtml + '<img src="images/noarrow.png" width="15" height="15" alt=" " /><span id="present">Short Papers</span><br />';
 } else { menuhtml = menuhtml + '<img src="images/noarrow.png" width="15" height="15" alt=" " /><a href="resources.html?page=shortpapers">Short Papers</a><br />';}

 if (srchString == 'strateg') { menuhtml = menuhtml + '<img src="images/noarrow.png" width="15" height="15" alt=" " /><span id="present">Research Strategies</span><br />';
 } else { menuhtml = menuhtml + '<img src="images/noarrow.png" width="15" height="15" alt=" " /><a href="resources.html?page=strateg">Research Strategies</a><br />';}

var srchString = unescape(location.search.substring(6, 12));

if (srchString == 'resour') {
	menuhtml = menuhtml + '<a href="javascript:toggle(\'A0\');"><img id="picA0" src="images/sidearrow.png" width="15" height="15" alt=" " /></a><a href="javascript:toggle(\'A0\')">Resources</a><span id="A0">';
    
	var srchString = unescape(location.search.substring(12, 14));
	
    for (var z = 1; z <= 8; z++) {
		if (srchString != z) {
			menuhtml = menuhtml + '<a href="resources.html?page=resour'+z+'">'+resourarray[z - 1]+'</a><br />';
		} else {
			menuhtml = menuhtml + '<span id="present">'+resourarray[z - 1]+'</span><br />';
		}
    }
} else {
	menuhtml = menuhtml + '<a href="javascript:toggle(\'A0\');"><img id="picA0" src="images/sidearrow.png" width="15" height="15" alt=" " /></a><a href="javascript:toggle(\'A0\')">Resources</a><span id="A0">';
	for (var z = 1; z <= 8; z++) {
		menuhtml = menuhtml + '<a href="resources.html?page=resour'+z+'">'+resourarray[z - 1]+'</a><br />';
	}
}
menuhtml = menuhtml + '</span><br />';

if (srchString == 'biblio') {
	menuhtml = menuhtml + '<a href="javascript:toggle(\'A1\');"><img id="picA1" src="images/sidearrow.png" width="15" height="15" alt=" " /></a><a href="javascript:toggle(\'A1\')">Bibliography</a><span id="A1">';

    var srchString = unescape(location.search.substring(12, 14));
	
	for (var z = 1; z <= 11; z++) {
		if (srchString != z) {
	menuhtml = menuhtml + '<a href="resources.html?page=biblio'+z+'">'+biblioarray[z - 1]+'</a><br />';
		} else {
			menuhtml = menuhtml + '<span id="present">'+biblioarray[z - 1]+'</span><br />';
		}
	}
} else {
	menuhtml = menuhtml + '<a href="javascript:toggle(\'A1\');"><img id="picA1" src="images/sidearrow.png" width="15" height="15" alt=" " /></a><a href="javascript:toggle(\'A1\')">Bibliography</a><span id="A1">';	
	for (var z = 1; z <= 11; z++) {
		menuhtml = menuhtml + '<a href="resources.html?page=biblio'+z+'">'+biblioarray[z - 1]+'</a><br />';
	}
}
menuhtml = menuhtml + '</span><p>&nbsp;</p><br /></p>';
 
document.getElementById("menu").innerHTML = menuhtml;

var srchString = unescape(location.search.substring(6, location.search.length));

document.getElementById("page").innerHTML = '<iframe id="myFrame" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="100%" height="5000" src="research/'+srchString+'.html" scrolling="no" style="overflow:visible"></iframe>';

//this formats the bibliography better - don't know why it's needed
document.getElementById('A1').style.display='none';
document.getElementById('picA1').src = "images/sidearrow.png";	

var srchString = unescape(location.search.substring(6, 12));
var menuhtml = '';

var daState = 1;//getCookie("userName");

if (daState == 3) {
		document.getElementById('A0').style.display='block';
		document.getElementById('picA0').src = "images/downarrow.png";
		document.getElementById('A1').style.display='block';
		document.getElementById('picA1').src = "images/downarrow.png";
} else {
	if (srchString == 'resour'){
		document.getElementById('A0').style.display='block';
		document.getElementById('picA0').src = "images/downarrow.png";
	}
		
	if (srchString == 'biblio'){
		document.getElementById('A1').style.display='block';
		document.getElementById('picA1').src = "images/downarrow.png";
	}
}
}




function saveData() {
	//var expDate = getExpDate(180, 0, 0);
	//var datatosave = '3';
	//setCookie("userName", "3", expDate);
}

function getExpDate(days, hours, minutes) {
 var expDate = new Date();
 if (typeof days =="number" && typeof hours == "number" && typeof minutes == "number")
 {
	 expDate.setDate(expDate.getDate() + parseInt(days));
	 expDate.setHours(expDate.getHours() + parseInt(hours));
	 expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
	 return expDate.toGMTString();

 }
}