	// Dojo configuration
	djConfig = {
		// preventBackButtonFix: true,
		baseScriptUri: "/cc8/sites/portal/dojo/",
		//bindEncoding: "utf-8",
		isDebug: false
	};

	dojo.require("dojo.io.*");

	// Get the path to the blob file from the xml
	function loadTxt(id, div) {
		var divToChange = document.getElementById(div);

		if(divToChange!=null) {
			dojo.io.bind({
				url: "/cc8/sites/library/getPath?id="+id, // id is the id of the xml file
				mimetype: "text/html",
				handle: function(type, data, e) {
					if(type == "load"){
							if(data!='' && data!=null && data!='null')
								loadTxtPath(data, div);
						} else if(type == "error") {
						if (e) {dojo.debug("Error! --> " + e.message);}
						else {dojo.debug("Unknown Error!" );}
					}
				},
				error: function(t, e) {
					dojo.debug("Error! --> " + e.message);
				}
			});
		}
	}

	// Load Contents of given blob file
	function loadTxtPath(id, div) {
		var divToChange = document.getElementById(div);

		if(divToChange!=null) {
			dojo.io.bind({
				url: "/cc8/sites/library/getText?id="+id, // id is the "path" to the blob file
				mimetype: "text/html",
				handle: function(type, data, e) {
					if(type == "load"){
							divToChange.innerHTML = data;
						} else if(type == "error") {
						if (e) {dojo.debug("Error! --> " + e.message);}
						else {dojo.debug("Unknown Error!" );}
					}
				},
				error: function(t, e) {
					dojo.debug("Error! --> " + e.message);
				}
			});
		}
	}

	// function that prints the path of the selected page
	function loadTitle(id, param, param2) {
		var divToChange = document.getElementById("dojoTop");

		if(divToChange!=null) {
			dojo.io.bind({
				url: "/cc8/sites/library/"+id+"&title=true", // param title indicates that only the "path" info of the generated xml should be rendered
				mimetype: "text/html",
				handle: function(type, data, e) {
					if(type == "load"){
							divToChange.innerHTML = data;
						} else if(type == "error") {
						if (e) {dojo.debug("Error! --> " + e.message);}
						else {dojo.debug("Unknown Error!" );}
					}
				},
				error: function(t, e) {
					dojo.debug("Error! --> " + e.message);
				}
			});
		}
		loadPath(id, param, param2);
	}

	// function that prints the title of the selected page
	function loadPath(id, param, param2) {
		var divToChange = document.getElementById("topPath");
		var isNews = '';

		if(divToChange!=null) {
			dojo.io.bind({
				url: "/cc8/sites/library/"+id+"&path=true", // param path indicates that only the "title" info of the generated xml should be rendered
				mimetype: "text/html",
				handle: function(type, data, e) {
					if(type == "load"){
							/* if(id=="graylit" || id=="portal_txt.phtml?prnbr=11723")
								divToChange.innerHTML = "Αναζήτηση Γκρίζας Βιβλιογραφίας";
							else */
								divToChange.innerHTML = data;
						} else if(type == "error") {
						if (e) { dojo.debug("Error! --> " + e.message);}
						else {dojo.debug("Unknown Error!" );}
					}
				},
				error: function(t, e) {
					dojo.debug("Error! --> " + e.message);
				}
			});
			isNews = 'false';       // if isNews = true, loadMain() produces the info in the newsbox of the first page
		}
		else								// else it produces the info of the inner pages
			isNews = 'true';

		if (param2 == 'gray' || param2 == 'maps')
			loadMain(id, param, param2);  // loadMain() will load the 'gray' or 'maps' search results
															// produced by the 'gray' or 'maps' search of the first page
		else
			loadMain(id, isNews);
	}

	// main function to dynamically load contents of pages depending on passed params
	function loadMain(id, param, param2) {
		var dojoLoad = "";
		var bookmark = "";

		// load the Gray Literature search form
		if(id=='portal_txt.phtml?prnbr=1198053971508') {
			document.getElementById(dojoDiv).innerHTML = '<p align="center">Φόρτωση...<br/><br/><br/><br/><img src="/cc8/sites/portal/pics/ajax-loader.gif"/></p>';
			dojoLoad = "/cc8/sites/AegeanGray/search.xqx";
			bookmark = id;
		}

		// load the AegeanAtlas webapp
		//if(id=='portal_txt.phtml?prnbr=1198054679816') {
			//document.getElementById(dojoDiv).innerHTML = '<p align="center">Φόρτωση...</p>';
			//document.getElementById(dojoDiv).href == "http://atlas.lib.aegean.gr:8080/cruiser2_aegean/aegean-atlas/AegeanAtlas.html?//channel=gr.talent.channel.aegean-atlas&locale=el";
			
			//bookmark = id;
		//}

		// load the results of the portal search
		else if(id == 'portalSearch') {
			document.getElementById("dojoTop").innerHTML = "<img align='absmiddle' src='/cc8/sites/portal/pics/patharrow.gif' border='0' /> Αναζήτηση στο site";
			document.getElementById("topPath").innerHTML = "Αποτελέσματα Αναζήτησης";
			document.getElementById(dojoDiv).innerHTML = "<p align='center'>Φόρτωση Αποτελεσμάτων...</p>";

			if(param!="" && param!=null && param!=" "){
				dojoLoad = "/cc8/sites/library/dosearch?q="+encodeURI(param.toUpperCase());
			}
			else {
				dojoLoad = "/cc8/sites/library/dosearch?q=";
			}
			/* window.open("/cc8/sites/library/dosearch?opts="+encodeURI(opts)); */
		}

		// Cocoon based portal search
		/* else if(id == 'portalSearch') {
			document.getElementById("dojoTop").innerHTML = "<img align='absmiddle' src='/cc8/sites/portal/pics/patharrow.gif' border='0' /> Αναζήτηση στο site";
			document.getElementById("topPath").innerHTML = "Αποτελέσματα Αναζήτησης";
			document.getElementById(dojoDiv).innerHTML = "<p align='center'>Φορτωση Αποτελεσμάτων...</p>";

			var opts = "";
			if(param!="" && param!=null && param!=" "){
				opts = "contains(translate(attribute[@name=\"Attribute_txsdesc\"]/string/@value,'αβγδεζηθικλμνξοπρστυφχψωςάέήίόύώϊϋΆΈΉΊΌΎΏΪΫabcdefghijklmnopqrstuvwxyz','ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΣΑΕΗΙΟΥΩΙYΑΕΗΙΟΥΩΙYABCDEFGHIJKLMNOPQRSTUVWXYZ'),translate('"+param+"', 'αβγδεζηθικλμνξοπρστυφχψωςάέήίόύώϊϋΆΈΉΊΌΎΏΪΫabcdefghijklmnopqrstuvwxyz','ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΣΑΕΗΙΟΥΩΙYΑΕΗΙΟΥΩΙYABCDEFGHIJKLMNOPQRSTUVWXYZ'))";
				opts += " or contains(translate(attribute[@name=\"Attribute_txdesc\"]/string/@value,'αβγδεζηθικλμνξοπρστυφχψωςάέήίόύώϊϋΆΈΉΊΌΎΏΪΫabcdefghijklmnopqrstuvwxyz','ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΣΑΕΗΙΟΥΩΙYΑΕΗΙΟΥΩΙYABCDEFGHIJKLMNOPQRSTUVWXYZ'),translate('"+param+"', 'αβγδεζηθικλμνξοπρστυφχψωςάέήίόύώϊϋΆΈΉΊΌΎΏΪΫabcdefghijklmnopqrstuvwxyz','ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΣΑΕΗΙΟΥΩΙYΑΕΗΙΟΥΩΙYABCDEFGHIJKLMNOPQRSTUVWXYZ'))";
			}
			else
				alert("Εισάγετε λέξη κλειδί!");

			dojoLoad = "/cc8/sites/library/dosearch?opts="+encodeURI(opts);
		} */

		// load the Maps search form
		else if(id=='portal_txt.phtml?prnbr=1198054699436') {
                        document.getElementById(dojoDiv).innerHTML = '<p align="center">Φόρτωση...</p>';
                        dojoLoad = "/cc8/sites/AegeanMaps/search.xqx";
                        bookmark = id;
		}

		// load first level details of the clicked Maps of GrayLit submission
		else if(param != 'false' && param != 'true'){
			dojoLoad = "/cc8/sites/"+param+"/searchSubmission?id="+id+"&action=getRecord";
			document.getElementById(id).style.display='';
			document.getElementById(id).innerHTML = "<p align='center'>Φόρτωση Εγγραφής...</p>";
		}

		// load the contents
		else {  
			dojoLoad = "/cc8/sites/library/"+id+"&main=true&isNews="+param;
			bookmark = id;
		}

		dojo.io.bind({
			url: dojoLoad, // load the above specified url
			mimetype: "text/html",
			changeURL: bookmark, // add a bookmark
			handle: function(type, data, e) {
				if(type == "load"){
					// decide where to display the generated data
					if(id=='portalSearch') {
						document.getElementById(dojoDiv).innerHTML = data;
						scrollingDetector(dojoDiv, data);
					}
					else if(id.charAt(0)=='p' && id!='portalSearch') {
						document.getElementById(dojoDiv).innerHTML = data;
						loadTxt(id.substring(id.indexOf('=')+1), 'portal_'+id.substring(id.indexOf('=')+1));
						scrollingDetector(dojoDiv, data);
						if (param2=="gray" || param2=="maps") {
							document.getElementById("id").value=decodeURI(param); // deal with the greek encoding issue
							doSearch('formAdvanced', 'formAdvanced');
						}
					}
					else
						document.getElementById(id).innerHTML = data;

				} else if(type == "error") {
					if (e) { dojo.debug("Error! --> " + e.message);}
				else {dojo.debug("Uknown Error!" );}
				}
			},
			error: function(t, e) {
				dojo.debug("Error! --> " + e.message);
			}
		});
	}

	// function to handle Gray Form and Maps queries
	function doSearch(form, id) {
		/* document.getElementById("formResults").innerHTML = "loading results...";*/

		dojo.io.bind({
			formNode: form,
			mimetype: "text/html",
			handle: function(type, data, e) {
					if(type == "load"){
						document.getElementById("formResults").innerHTML = data;
					}else if(type == "error"){
						dojo.debug("Error! --> " + e.message);
					}else{
						dojo.debug("Error! --> " + e.message);
					}
				},
			error: function(t, e) {
				dojo.debug("Error! --> " + e.message);
			}
		});
		return false;
	}

	// Switch between forms in Gray Literature Search
	function switchForm(appl) {
		document.getElementById('dojoBottom').innerHTML = "<iframe style='width: 610px; height: 900px' src='/cc8/sites/"+appl+"/submission.flow' frameborder='0' scrolling='no' class='grayFormFrame'></iframe>";
	}

	// get the corresponding pages of the footer links
	function getPage(url) {
		if(onLine=="true")	{
			if(url=='terms')
				loadTitle('portal_txt.phtml?prnbr=1198053972644');
			else if (url=='personal')
				loadTitle('portal_txt.phtml?prnbr=1198053972727');
			else if (url=='team')
				loadTitle('portal_txt.phtml?prnbr=1198053972810');
		}
		else {
			window.location='/portal/dt?AegeanLib/Body.setSelected=AegeanLib%2FBody%2FHome&last=false#'+url;
		}
	}

	// handle the different catalogue search options of the homepage
	function loadView() {
		var box = document.getElementById('searchDrop');
		var destination = box.options[box.selectedIndex].value;
		if (destination == "opac")
			document.getElementById('searchView').innerHTML ='<table cellspacing="2" cellpadding="0"><tr><td class="mainCatalogSearch"><a href="/portal/dt?AegeanLib/Body.setSelected=AegeanLib%2FBody%2FCataloges&last=false">Μετάβαση στον κύριο κατάλογο</a></td><td valign="bottom"><a href="/portal/dt?AegeanLib/Body.setSelected=AegeanLib%2FBody%2FCataloges&last=false"><img src="/cc8/sites/portal/pics/arrowsearch.gif" width="26" height="20" border="0"/></td></tr></a></table>';
		/* else if (destination == "tel"
			document.getElementById('searchView').innerHTML ='<script type="text/javascript" src="http://www.theeuropeanlibrary.org/portal/minitel/telsearchbox.js"></script><script>bid="f50f9a81-3fab-102a-81b6-ceee3e6c61a2";telSearchBox();</script>'; */
		else if (destination == "sel")
			document.getElementById('searchView').innerHTML ='<br/>';
		else
			document.getElementById('searchView').innerHTML ='<table border="0" cellspacing="2" cellpadding="0"><tr><td width="229" valign="top"><input class="advancedSearch" type="text" name="entry1" id="entry1" /></td><td valign="bottom"><input type="image" src="/cc8/sites/portal/pics/arrowsearch.gif" width="24" height="18" /></td></tr></table>';
	}

	// submit the query of the catalogue search box of the homepage
	function submitForm() {
		var box = document.getElementById('searchDrop');
		var destination = box.options[box.selectedIndex].value;
		var searchString = document.getElementById('entry1').value;
		if (destination == "heallink") {
			window.open('http://www.heal-link.gr/journals/quicksearch.jsp?tearm='+searchString+'&x=77&y=17',null,'top=180,left=100,directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes');
			return false;
		}
		else if (destination == "zefyros") {
			window.open('http://zephyr.libh.uoc.gr/cgi-bin/zap/zap/results.zap?start=1&number=1&scanposition=1&scannumber=25&type=basic&action=search&field1=Author-word-root&term1=&op1=and&field2=Title-word-root&term2=&op2=and&field3=FreeText-word-root&term3='+searchString+'&target=askt&target=uoa&target=aegean&target=auth&target=aua&target=uth&target=duth&target=ionio&target=uoi&target=uoclib&target=cyprus&target=uom&target=panteion&target=patra&target=unipi&target=tuc&target=aueb&target=hua&target=teiath&target=teiwm&target=teikas&target=teiflo&target=teiep&target=teiher&target=teimes&target=teiser&target=pischools&target=ekt&target=teipir&target=eap&target=teipat&target=ntua&target=heal&target=kdeod&',null,'top=180,left=100,directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes');
			return false;
		}
		else if (destination == "syllogikos") {
			window.open('http://147.102.210.203/cgi-bin-EL/egwcgi/26171/search.egw/1+0?menu1=%CF%F0%EF%F5%E4%DE%F0%EF%F4%E5&entry1='+searchString+'&logic1=And&menu2=%CF%F0%EF%F5%E4%DE%F0%EF%F4%E5&entry2=&logic2=And&menu3=%CF%F0%EF%F5%E4%DE%F0%EF%F4%E5&entry3=&submit=%C1%ED%E1%E6%DE%F4%E7%F3%E7&hits=10');
			return false;
		}
		else if (destination == "openarchgr") {
			window.open('http://www.openarchives.gr/results.php?query='+searchString+'&ok_submit=+%CE%91%CE%BD%CE%B1%CE%B6%CE%AE%CF%84%CE%B7%CF%83%CE%B7+');
			return false;
		}
		else if (destination == "gray") {
			window.location.href='/portal/dt?AegeanLib/Body/Home/HomeBody.setSelected=AegeanLib%2FBody%2FHome%2FHomeBody%2FOnline&last=false#gray='+searchString;
			return false;
		}
		else if (destination == "maps") {
			window.location.href='/portal/dt?AegeanLib/Body/Home/HomeBody.setSelected=AegeanLib%2FBody%2FHome%2FHomeBody%2FOnline&last=false#maps='+searchString;
			return false;
		}
	}

	// function to help solve greek encoding issues
	function replaceChars(entry) {
		out = "%25"; // replace this
		add = "%"; // with this
		temp = "" + entry; // temporary holder

		while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add +
		temp.substring((pos + out.length), temp.length));
		}
		return temp;
	}

	// go to first page
	function firstPage() {
		if (first=='true')
			window.location.href='http://portal.lib.aegean.gr/portal/dt?AegeanLib/Body/Home/HomeBody.setSelected=AegeanLib/Body/Home/HomeBody/HomeHidden&last=false';
		else
			window.location.href='http://portal.lib.aegean.gr/portal/dt?AegeanLib/Body.setSelected=AegeanLib%2FBody%2FHome&last=false';
	}

	//function to detect verical scrolling position. if 0 then no scrollbar
	function scrollingDetector(dojoDiv, data) {
		if (document.getElementById(dojoDiv).innerHeight >= document.getElementById(dojoDiv).outerHeight) {
			document.getElementById(dojoDiv).innerHTML = "<a name='top'></a>"+data+"<br/><a href='#top'><img src='/cc8/sites/library/media/11616/uparrow.gif' border='0'></a>&nbsp;<a href='#top'>Κορυφή</a><br/><br/>";
		}
	}

