/**
 * @author yorgos
 */
/* -----------------------------------------------------------------------------------------
Title:				Global Javascript Functions for www.quadlock.gr
File:				/assets/js/global.js
Author:				George Komianos
Copyright:			2005 Acrodev.com - Unless otherwise noted.
					No portion of this document may be reproduced, unless otherwise stated.
					Any GNL code is noted accordingly.
			                 			
Description:		

Created:			
Modified:			

TODO:			
BUG/FIX:					
----------------------------------------------------------------------------------------- */


function objectExists()
{
	if (typeof document.getElementById == 'undefined') 
	{
		return false;
	}
	else if (typeof document.createTextNode == 'undefined') 
	{
		return false;
	}
	else if (typeof document.getElementsByTagName == 'undefined') 
	{
		return false;
	}
	else {
		return true;
	}
}

/** -----------------------------------------------------------------------------------------
* Summary: 			Opens a new window.
* Parameters: 		theURL,winName,features
----------------------------------------------------------------------------------------- */
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* -----------------------------------------------------------------------------------------
* Summary: 			Opens links with attribute rel="external" in a new window.
----------------------------------------------------------------------------------------- */
function externalLinks() 
{
	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i=0; i<anchors.length; i++) 
	{
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href") && 
			(anchor.getAttribute("rel") == "external" || anchor.className.match("external")))
		{
			anchor.target = "_blank";
			anchor.setAttribute('title', 'Ανοίγει σε νέο παράθυρο')
		}
		
	}
}

/* -----------------------------------------------------------------------------------------
* Summary: 			Toggles an element;s visibility.
* Parameters: 		targetId - the id of the element to be toggled.
* Author:			George Komianos
----------------------------------------------------------------------------------------- */
function toggle (targetId) 
{
	if (document.getElementById) 
	{
		var target = document.getElementById(targetId);
		
		if (target.style.display == "none") 
		{
			target.style.display = "block";
		} else 
		{
			target.style.display = "none";
		}
	}	
}

/* -----------------------------------------------------------------------------------------
* Summary: 			adds the onclick popup attribute to appropriate links
* Parameters: 		None
----------------------------------------------------------------------------------------- */

function addPopTrigger () 
{
	if (!document.getElementsByTagName) return false;
	
	var links = document.getElementsByTagName("a");
	
	if (links) 
	{
		for (var i=0; i < links.length; i++) 
		{
			var anchor = links[i];
			
			if (anchor.className.match("popup")) 
			{
				anchor.onclick = function() 
				{
					imgPop (this.href, this.title); 
					return false;
				}
			}
		} // end loop
		
	} else return false;
	return null;	
}

function imgPop (imageURL,imageTitle) 
{
	//pass both parameters in the URL
	var newWin = window.open( "/assets/pop_img.html?"+imageURL+"?"+imageTitle, "popImg",  'status=yes,scrollbars=no,resizable=yes,width=600,height=600');
}

/* -----------------------------------------------------------------------------------------
* Summary: 			Makes an element visibile.
* Parameters: 		targetId - the id of the element to be displayed.
* Author:			George Komianos
----------------------------------------------------------------------------------------- */
function show (targetId) {
	if (document.getElementById) {
			var target = document.getElementById(targetId);
			
			if (target.style.display == "none") {
					target.style.display = "block";
			} else return false;
	}	
}


/* -----------------------------------------------------------------------------------------
* Summary: 			Makes an element invisibile.
* Parameters: 		targetId - the id of the element to be hidden.
* Author:			George Komianos
----------------------------------------------------------------------------------------- */
function hide (targetId) {
	if (document.getElementById) {
			var target = document.getElementById(targetId);
			
			if ( (target.style.display == "block") || (target.style.display == "") ) {
					target.style.display = "none";
			} 
			else {
					target.style.display = "block";
			}
	}	
}



/* ------------- Image Popups ------------- */



// function to add the onclick popup attribute to appropriate links
function addPop() 
{
	if (!document.getElementsByTagName)
	{
		return false;	
	}
	
	var links = document.getElementsByTagName("a");
	
	for (var i=0; i < links.length; i++) 
	{
		if (links[i].className.match("popup")) 
		{
			links[i].onclick = function() 
			{
				popImage(this.href, this.title); 
				return false;
			}
		}
	} // end loop
}

function closeWin () 
{
	self.close()	
}


function nav () 
{
	
	if (document.getElementById('nav-side')) 
	{
		var container = document.getElementById('nav-side');	// the div container 
	}
	else 
	{
		return false;	
	}
	
	var menu = container.childNodes[1];
	
	var activeSubClass = 'activesub';			// class used to for the active (open) sublist
	var inactiveSubClass = 'notactivesub';		// class used to for the inactive (hidden) sublists
	
	var parentClass = 'isParent';				// class assigned to all LIs with a sublist
	var parentOpen = 'parentOpen';				// class assigned to all LIs with a sublist
	var activeParentClass = 'isActive';			// class assigned to the parent LI of the active sublist
	var activeOpen = 'activeOpen';
	
	var toHideClass = 'hideChild';				// class used to hide an element
	var toShowClass = 'showChild';				// class used to show an element
	var currentClass = 'active';				// class of the current link
	
	
	// Fist of all... stop if DOM isn't available
	if (!document.getElementById && !document.createTextNode)
	{
		return;
	}	
	
	// only proceed if the navigation element exists
	if (menu) {
		
		// set the variables to be used
		var lis, i, firstUL, j, apply;
		
		lis = menu.getElementsByTagName('li');		// get all the LIs in the menu
		
		// loop through all LIs and check which ones have a nested UL
		for (i=0; i<lis.length; i++)
		{
			firstUL = lis[i].getElementsByTagName('ul')[0]; // since we're looping there is only one sublist at a time, thus [0]
			
			// if there is a nested UL, deactivate the first nested link and apply the parentClass
			if (firstUL)
			{
				lis[i].childNodes[0].onclick = function() { return false; } 				// deactivate 
				lis[i].className += lis[i].className == ''?parentClass:' '+parentClass; 	// add the parentClass
				
				//var sublist = lis[i].getElementsByTagName('ul');
				var sublinks = lis[i].getElementsByTagName('li');
				
				for (a=0; a<sublinks.length; a++) 
				{					
					var parentUL = firstUL;			// the sublist		
					
					// if an active LI is found, apply the activeSubClass to its UL and stop the loop, 
					// otherwise apply the inactiveSubClass.
					if (sublinks[a].id == 'active')
					{
						firstUL.setAttribute ('class', activeSubClass);
						firstUL.setAttribute ('className', activeSubClass);
						lis[i].setAttribute ('class', activeOpen);
						lis[i].setAttribute ('className', activeOpen);
						
						//firstUL.className += lis[i].className == ''?activeSubClass:' '+activeSubClass;
						//lis[i].className += lis[i].className == ''?activeParentClass:' '+activeParentClass;		
						break
					} else
					{
						//firstUL.className += lis[i].className == ''?inactiveSubClass:' '+inactiveSubClass;
						firstUL.setAttribute ('class', toHideClass);
						firstUL.setAttribute ('className', toHideClass);
						
					}
					
				} // loop of sub LIs
			} // loop of LIs with sublists 
		} // loop of all menu LIs
		
		
		// apply the onclick event to the Parent LIs
		// find all the subULs and apply the onclick event to their Parent LI
		lis = menu.getElementsByTagName('li');
		for (i=0; i<lis.length; i++)
		{
			if ( (lis[i].className.match(parentClass)) || (lis[i].className.match(activeParentClass)) || (lis[i].className.match(activeOpen))  )
			{
				lis[i].onclick = function() { doMenuToggle (this); }
			}
		}
		
	} // end if menu
	
	
	function doMenuToggle (o)
	{
				
		lis = menu.getElementsByTagName('li');
		targetUL = o.childNodes[2];
		
		for (i=0; i<lis.length; i++)
		{
			//var subUL = lis[i].getElementsByTagName('ul')[0];
			var subUL = lis[i].getElementsByTagName('ul');
			
			/*
				if it's an active UL and it's the target UL, toggle it and hide the others
				if it's an active UL and it's not the target UL, toggle it and hide the others
					
				if it's an inactive and it's the target UL, toggle it and hide the others including the active one.
				if it's an inactive and it's not the target UL, toggle it and hide the others including the active one.
					
			*/
			
			if (subUL) 
			{
				for (j=0; j<subUL.length; j++)
				{
					var parentLI = subUL[j].parentNode;
					//alert (parentLI.className);
					if ( ((subUL[j].className.match (activeSubClass)) || (subUL[j].className.match (inactiveSubClass))) &&  (targetUL == subUL[j]) )
					{ 
						if ( (subUL[j].className.match (activeSubClass)) || (subUL[j].className.match (inactiveSubClass)) )
						{ //alert ('found active target');
							if (subUL[j].style.display == "none") 
							{
								subUL[j].setAttribute ('class', activeSubClass);
								subUL[j].setAttribute ('className', activeSubClass); 
								subUL[j].style.display = "block";
								parentLI.setAttribute ('class', activeOpen);
								parentLI.setAttribute ('className', activeOpen);
							} else 
							{
								subUL[j].setAttribute ('class', inactiveSubClass);
								subUL[j].setAttribute ('className', inactiveSubClass); 
								subUL[j].style.display = "none";
								parentLI.setAttribute ('class', activeParentClass);
								parentLI.setAttribute ('className', activeParentClass);
							}
						}
						
						
					}
					 
					if ( ((subUL[j].className.match (activeSubClass)) || (subUL[j].className.match (inactiveSubClass))) &&  (targetUL != subUL[j]) )
					{ //alert ('found active but NOT target');

								subUL[j].setAttribute ('class', inactiveSubClass);
								subUL[j].setAttribute ('className', inactiveSubClass); 
								subUL[j].style.display = "none";
								parentLI.setAttribute ('class', activeParentClass);
								parentLI.setAttribute ('className', activeParentClass);
						
					}
					
					if ( ((subUL[j].className.match (toHideClass)) || (subUL[j].className.match (toShowClass))) &&  (targetUL == subUL[j]) )
					{  
						//alert ('found inactive target');
						if ( subUL[j].className.match (toHideClass) )
						{  
							subUL[j].setAttribute ('class', toShowClass);
							subUL[j].setAttribute ('className', toShowClass); 	// IE understands this
							o.setAttribute ('class', parentOpen);
							o.setAttribute ('className', parentOpen);
						}
						else if ( targetUL.className.match (toShowClass) )
						{  
							subUL[j].setAttribute ('class', toHideClass);
							subUL[j].setAttribute ('className', toHideClass); 	// IE understands this
							parentLI.setAttribute ('class', parentClass);
							parentLI.setAttribute ('className', parentClass);
						}
						
					} 
					
					if ( ((subUL[j].className.match (toHideClass)) || (subUL[j].className.match (toShowClass))) &&  (targetUL != subUL[j]) )
					{ //alert ('found inactive - NOT target');
						
							subUL[j].setAttribute ('class', toHideClass);
							subUL[j].setAttribute ('className', toHideClass); 	// IE understands this
							parentLI.setAttribute ('class', parentClass);
							parentLI.setAttribute ('className', parentClass);
						
					} //else return false;
					//alert (parentLI.className);
										
					} // end subULs loop
				
				} // end subUL conditional
				
		} // end all LIs loop
		
	} // doMenuToggle
	
} 
// end menu function



/* -----------------------------------------------------------------------------------------
* Summary: 			Unobtrusive image gallery. Attaches the onclick event to show enlarged photo inside a container/placeholder.
					In this case it is used to display form elements.
* Last Edited:		02/12/25 - added the "loading" gif					
----------------------------------------------------------------------------------------- */

function prepareGallery() {
	
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("imagegallery")) return false;
	
	var gallery = document.getElementById("imagegallery");
	var links = gallery.getElementsByTagName("a");
	
	for ( var i=0; i < links.length; i++) {		
		links[i].onclick = function() {
		  return showPic(this);
		}
	} // end loop
}

function showPic (whichpic) 
{	
	if (!document.getElementById) return true;
	
	container = document.getElementById('placeholder');
	
	// if target img is the current enlarged img, don't do anything
	if (container.src == whichpic.href) return false;
	
	
	// quick/multiple clicks overload the script  due to the timer/loading times
	// to avoid this, check whether the target image has been defined but has not finished loading and reset the timeInterval.
	if (window.target_img) 
	{
		if (!target_img.width) {
			alert ('Please wait for the image to load.');
			clearInterval(timerid);
			replace_img();
		}
	} 
	
	// create the 2 images required
	loading_img = new Image();
	loading_img.src = 'http://www.bougarinihomes.local/images/loading_med.gif';
	
	target_img = new Image();
    target_img.src = whichpic.href;
	
	// show the loading gif first
	container.src = loading_img.src;
	
	// after loading the loading_img run the replace_img function

	/*if (loading_img.complete) 
	{
		replace_img();
		alert ('loading image has loaded');
	}*/
	replace_img();
  return false;
}

function replace_img()
{		
	// if the image has not been loaded, set time interval and load the target_img
	// if it has already been loaded, check if a timer exists and:
	// clear it and load the target_img if it does, or just load the target_img if it doesn't.
	if (!target_img.complete) 
	{
		var timerid = setInterval("replace_img()", 400);
		
		if (target_img.width) 
		{
			container.src = target_img.src;
			clearInterval(timerid);
		} 
	} else {
		container.src = target_img.src;
		
		if (timerid) {
		clearInterval(timerid);
		} else false;
	}
}

function removeRectagle() 
{
	if (!document.getElementsByTagName)
	{
		return false;
	}
	var links = document.getElementsByTagName('a');
	
	if (objectExists(links)) 
	{
        for (var i = 0; i < links.length; i++) 
		{
            links[i].onmousedown = function() 
			{
                this.blur();
                return false;
            }
        }
    }
}

/** ----------------------------------------------------------------------------
* Summary: 			Obfuscates provided string.
* Parameters: 		String to be obfuscated.
---------------------------------------------------------------------------- */
function obfuscate (text)
{
    var obfuscated = '';

    for (i = 0; i < text.length; i++) {
		obfuscated += "&#" + text.charCodeAt(i);
	}
	return (obfuscated);
}
/** ----------------------------------------------------------------------------
* Summary: 			Writes the obfuscated mailto link to the page.
* Parameters: 		Mailbox user name - string.
					Optional - String with the link text.
---------------------------------------------------------------------------- */
function show_address (mailbox, domain, link_text)
{
	if (mailbox == '') {
		return false;
	}
	
	if (domain == '') {
		var domain_name	= 'quadlock.gr';
	}
	else var domain_name	= domain;
	
	var email	 	= mailbox + '@' + domain_name;
	var email_obf 	= obfuscate (email);

	// use the link_text provided or the address if it's not.
	if (link_text != '') {
		var link_text_obf = obfuscate (link_text);
	}
	else {
		var link_text_obf = email_obf;
	}
	document.write('<a href="mailto:' + email_obf + '">' + link_text_obf + '</a>');
}
/**
 * 
 */
function doList()
{
	if (!document.getElementById || !document.createTextNode)
	{
		return false;
	}
	
	// find the list and close all dds
	// add a link to the dts - add the onclick behaviour
	// add the 'close' text link at the bottom of the dd - add the onclick behaviour
	
	var listClass	 		= 'toToggle';	// class of the list whose elements should toggle		
	var listToToggle 		= '';			// assigned to the dl element to be toggled	
	
	var parentClass 		= 'isParent';				
	
	var toHideClass 		= 'hideChild';				
	var toShowClass 		= 'showChild';				
	
	var dLists = document.getElementsByTagName('dl');
	
	if (!objectExists(dLists)) 
	{
		return false;	
	}
	for (i = 0; i < dLists.length; i++)
	{
		if (dLists[i].className.match(listClass))
		{
			var listToToggle 	= dLists[i];
			var allTerms 		= listToToggle.getElementsByTagName('dt'); // this includes elements in sublists
			var allDefinitions 	= listToToggle.getElementsByTagName('dd'); // this includes elements in sublists
			
			// give it an id
			var list_id = 'list'+ i;
			dLists[i].setAttribute ('id', list_id); 
			
			/* Asign consecutive ids to appropriate dts
			---------------------------------------------------------- */
			
			// set an id no. which will increment and will be used to set the elements Ids.
			// it has to be different than allTerms[j] so that there are no gaps in the sequence
			// note: 
			var id_no = 1;
			for (var j = 0; j < allTerms.length; j++) 
			{
	            // we only need the dts who are direct children of the list to be toggled
				// not the dts of any nested lists.
				if (allTerms[j].parentNode.className.match(listClass))
				{
					// create the id value like so: list1t1
					var newIdNumber = id_no++;
					var newId = 'list' + i + 't' + newIdNumber;
					
					// set dt attributes
					allTerms[j].setAttribute ('id', newId);
					allTerms[j].setAttribute ('title', 'εμφάνιση απάντησης'); 
					allTerms[j].setAttribute ('class', 'plus');
					allTerms[j].setAttribute ('className', 'plus'); 
					
					// get the text
					var term_txt = allTerms[j].firstChild.nodeValue;					
					
					// create the link
					var term_link = document.createElement('a');	
					term_link.setAttribute('href','javascript:;');
					
					// add the onclick event.
					term_link.onclick = function (){ 
														toggleData(this);
													}
					
					// create a new text node with required text
					var term_txt_new = document.createTextNode(term_txt);
					
					allTerms[j].removeChild(allTerms[j].firstChild);
					
					// add text to the link
					term_link.appendChild(term_txt_new);
					
					// add the link to the parent.
					allTerms[j].appendChild(term_link); 
					
	            }
	        }
			
			/* Asign consecutive ids to appropriate dds - add link and trigger behaviour
			---------------------------------------------------------- */
			var id_no = 1;
			for (var j = 0; j < allDefinitions.length; j++) 
			{
	            // we only need the dds who are direct children of the list to be toggled
				// not the dds of any nested lists.
				
				if (allDefinitions[j].parentNode.className.match(listClass))
				{
					// hide all the definitions
					allDefinitions[j].style.display = 'none'; 
					
					// create the id in the form of: list1t1
					var newId = 'list'+i+'d'+id_no++;
					
					allDefinitions[j].setAttribute ('id', newId); 
					allDefinitions[j].setAttribute ('class', 'toggled');
					allDefinitions[j].setAttribute ('className', 'toggled'); 
					
					var triggerBoxClass = 'test';
					var triggerTxt = 'απόκρυψη';
					
					// create the span element
					var trigger_box = document.createElement('span');					
					trigger_box.setAttribute('class',triggerBoxClass);
					trigger_box.setAttribute('className', triggerBoxClass);
			
					// create the link and set its class the same with the dd's id
					// so that it can be retrieved by hideData();
					var trigger_link = document.createElement('a');	
					trigger_link.setAttribute('href','javascript:;');
					trigger_link.setAttribute ('title', 'απόκρυψη απάντησης');
					trigger_link.setAttribute ('class', newId);
					trigger_link.setAttribute ('className', newId);
			
					// add the onclick event.
					trigger_link.onclick = function () { 
															hideData(this);
														}
					
					var trigger_text_new = document.createTextNode(triggerTxt);
					
					// add text to the link
					trigger_link.appendChild(trigger_text_new); 
					
					// add the link to the span
					trigger_box.appendChild(trigger_link); 
					
					// add the trigger box at the bottom of the dd
					var insertHere = document.getElementById(newId); 
					insertHere.appendChild(trigger_box);
	            }
	        }
			
			/* Add Toggle All link for the current list
			---------------------------------------------------------- */
			
			//createToggleAllTrigger (list_id, dLists[i]); 
			addToggleAllTrigger (list_id);
			//createToggleAllTrigger (list_id); 
			
		} // end loop for required lists
		
	} // end document List loop
	
	
	function hideData (close_link)
	{
		var dd_id = close_link.className; // get the id from the link's class
		var dd = document.getElementById(dd_id);
		var dt_id = dd.previousSibling.previousSibling.id;
		
		hide (dd_id);
		setDtAttribute (dt_id, dd_id);
	}
	
	
	function toggleData (dt_link)
	{
		var termId = getTermId (dt_link);
		var listNo = getListNo (termId);
		var termNo = getTermNo (termId);
		
		var dd_id = 'list' + listNo + 'd' + termNo; // ie. list2d8
		
		toggle (dd_id);
		setDtAttribute (termId, dd_id);
	}
	
	function setDtAttribute (termId, dd_id)
	{
		var dt = document.getElementById(termId);
		var dd = document.getElementById(dd_id);
		
		if ( (dd.style.display == '') || (dd.style.display == 'none') )
		{
			dt.setAttribute ('title', 'εμφάνιση απάντησης');
			dt.setAttribute ('class', 'plus');
			dt.setAttribute ('className', 'plus'); 
		} 
		else 
		{
			dt.setAttribute ('title', 'απόκρυψη απάντησης');
			dt.setAttribute ('class', 'minus');
			dt.setAttribute ('className', 'minus'); 
		}
	}
	
	function getTermId (dt_link)
	{
		var termId = dt_link.parentNode.id;
		return termId;
	}
	
	function getListNo (termId)
	{
		// find the index of the 2 't's in the Id (list20t15) 
		// and get the value in between
		var delimeter1 	= termId.indexOf('t'); 		// the fist 't'
		var delimeter2 	= termId.lastIndexOf('t'); 	// the second 't'
		var listNo		= termId.substring(delimeter1 +1, delimeter2)
		
		return listNo;
	}
	
	function getTermNo (termId)
	{
		var delimeter 	= termId.lastIndexOf('t');
		var termNo 		= termId.substring(delimeter +1, termId.length)
		
		return termNo;
	}
	
	function addToggleAllTrigger (list_id)
	{
		var toggleClass = 'list-hidden';
		
		var thelist = document.getElementById(list_id);
		var hd = thelist.previousSibling.previousSibling; 
		
		var hd_text = hd.innerHTML;		
		hd.removeChild(hd.childNodes[0]);
		
		var toggle_link = createLink(hd_text);
		toggle_link.setAttribute('title','Εμφάνιση Απαντήσεων Ενότητας');
		toggle_link.setAttribute('href','javascript:;');
		toggle_link.onclick = function() 
				{
					toggleSection (this, list_id);				
				}
				
		hd.appendChild(toggle_link);
		
		// set the class for the heading
		toggle_link.parentNode.setAttribute ('class', toggleClass);
		toggle_link.parentNode.setAttribute ('className', toggleClass);
	}
	
	function toggleSection (trigger_link, dl_id)
	{
		var theList 	= document.getElementById(dl_id);
		var trigger_class = trigger_link.parentNode.className;		
		var allListData = theList.getElementsByTagName('dd');
	
		
		for (var k = 0; k < allListData.length; k++) 
		{
            // only the children of this list. Not any of the nested lists
			
			if (allListData[k].parentNode == theList)
			{
				var dd = allListData[k];
				
				if (trigger_class == 'list-hidden') 
				{
					trigger_link.parentNode.setAttribute('class', 'list-visible');
					trigger_link.parentNode.setAttribute('className', 'list-visible');
					trigger_link.setAttribute('title','Απόκρυψη Απαντήσεων Ενότητας');
					
					dd.style.display = "block";
				}
				else if (trigger_class == 'list-visible') 
				{
					trigger_link.parentNode.setAttribute('class', 'list-hidden');
					trigger_link.parentNode.setAttribute('className', 'list-hidden');
					trigger_link.setAttribute('title','Εμφάνιση Απαντήσεων Ενότητας');
					dd.style.display = "none";
				}
				
				// set the correct class for the dt
				var dd_id = dd.id;
				var dt_id = dd.previousSibling.previousSibling.id;
				setDtAttribute (dt_id, dd_id);
			}
		}	
	}
		
	function createToggleAllTrigger (list_id) 
	{
		// only create if it doesn't exist.
		if (!document.getElementById(toggle_box))
		{
			var toggleBoxClass = 'hidden';
			var toggleLinkClass = 'hidden';
			var toggleTxt = 'Εμφάνιση όλων';
			
			// create the span element
			var toggle_box = document.createElement('span');
			toggle_box.setAttribute('class',toggleBoxClass);
			toggle_box.setAttribute('className', toggleBoxClass);
	
			// create the link and set its class the same with the dd's id
			// so that it can be retrieved by hideData();
			var toggle_link = document.createElement('a');	
			toggle_link.setAttribute('href','javascript:;');
			toggle_link.setAttribute ('class', toggleLinkClass);
			toggle_link.setAttribute ('className', toggleLinkClass);
	
			// add the onclick event.
			toggle_link.onclick = function () { 
													toggleAllData (this, list_id);
												}
			
			var toggle_text_new = document.createTextNode(toggleTxt);
			
			// add text to the link
			toggle_link.appendChild(toggle_text_new); 
			
			// add the link to the span
			toggle_box.appendChild(toggle_link); 
			
			// -- add link to the page -- //
			// add the trigger box at the top of the list
			//var contentDiv = document.getElementById('content-main'); 
			var thelist = document.getElementById(list_id);
			
			// get the parent Node of the list
			var contentDiv = thelist.parentNode;
			// get the child Node after which the trigger will be inserted 
			// first previousSibling is the text and the next is the heading.
			var hd = thelist.previousSibling.previousSibling; 
			
			contentDiv.insertBefore(toggle_box, thelist);
		}
	}
	
	function trigger_swap (trigger_link, state) 
	{	
		if (state == 'show') 
		{
			var new_text = document.createTextNode('Απόκρυψη όλων');
			var new_class = 'visible';
		}
		else if (state == 'hide') 
		{
			var new_text = document.createTextNode('Εμφάνιση όλων');
			var new_class = 'hidden';
		}
		
		//replace old textNode title
		var old_text = trigger_link.childNodes[0];
		//alert (old_text);
		trigger_link.replaceChild (new_text, old_text); 
		
		// set the link's class
		trigger_link.setAttribute('class', new_class);
		trigger_link.setAttribute('className', new_class);
		
		// append new text/title to link.
		trigger_link.appendChild(new_text); 
	}
	
	function toggleAllData (trigger_link, dl_id)
	{
		var theList 	= document.getElementById(dl_id);
		var trigger_class = trigger_link.className;
		var toggleTxt 	= 'Εμφάνιση όλων';
		var allListData = theList.getElementsByTagName('dd');
	
		
		for (var k = 0; k < allListData.length; k++) 
		{
            // only the children of this list. Not any of the nested lists
			
			if (allListData[k].parentNode == theList)
			{
				var dd = allListData[k];
				
				if (trigger_class == 'hidden') 
				{
					trigger_swap (trigger_link, 'show');
					dd.style.display = "block";
				}
				else if (trigger_class == 'visible') 
				{
					trigger_swap (trigger_link, 'hide');
					dd.style.display = "none";
				}
				
				// set the correct class for the dt
				var dd_id = dd.id;
				var dt_id = dd.previousSibling.previousSibling.id;
				setDtAttribute (dt_id, dd_id);
			}
		}	
	}
}

// creates and returns a link element
function createLink (link_text)
{
	var element = document.createElement('a');	
	element.setAttribute('href','javascript:;');
	element.onmousedown = function() { this.blur(); return false; }
	element.innerHTML = link_text;
	return element;
}
window.onload=function()
{
	nav ();
	addPop ();
	externalLinks ();
	doList();
	removeRectagle () ;
}

