/*----------------------------------------------------------------------------------------------------------------------------*/

//global var vor sluiten veld
//var sluitLanguage = null;


/* Simply swap an image */

function swapImg(img,src)
{
	img.src = src;
	return true;
}


/*----------------------------------------------------------------------------------------------------------------------------*/
/* URL encode and decode */
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return(encoded);
};

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return(plaintext);
};

/*----------------------------------------------------------------------------------------------------------------------------*/
/* Get something from GET query */

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return URLDecode(pair[1]);
    }
  } 
}



/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle mouseover for images in topmenu */

function topMenuOver(oImg)
{
	var newSrc = oImg.src.replace('.gif','_act.gif');
	return(newSrc);	
}

/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle mouseout for images in topmenu */

function topMenuOut(oImg)
{
	var newSrc = oImg.src.replace('_act.gif','.gif');
	return(newSrc);	
	
}


/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle AJAX requests for newsletters */

function handleNewsletter(vlag,nbid)
{
	if(nbid != 'undefined')
	{
		/* Specific newsletter */
		var url = '/modules/newsletter/newsletter.php?action=newsletter&vlag='+vlag+'&nbid='+nbid;
	}
	else
	{
		/* Overview */
		var url = '/modules/newsletter/newsletter.php?action=overview&vlag='+vlag;

	}
	
	/* Prevent IE from caching .. */
	var x = Math.round(100*Math.random());
	var y = Math.round(100*Math.random());
	var z = Math.round(10*Math.random());	
	var rand = ((x*y)/z);
	var url = url+'&rand='+rand;
	
	/* Send request */
	new Ajax.Updater('newslettercontent', url);
}

/*----------------------------------------------------------------------------------------------------------------------------*/
/* Handle AJAX requests for searches */

function handleSearch(vlag,query,secret,position,start,skipbackcheck)
{
	
	
	if(query != '') 
	{
	
	
	
	if(!skipbackcheck)
	{
	
		/* Check if user has pressed back button on browser, to make sure the correct AJAX call is made */
		var currentUrl = document.location.href;
		var currentUrlElements = currentUrl.split('#');
		if ((!isNaN(currentUrlElements[1])) && (!currentUrlElements[1].length == 0))
		{
			var start = currentUrlElements[1];
		}
	
	}

	
	
	/* Create URL */	
	//var url = '/modules/search/search.php?query='+encodeURIComponent(query)+'&vlag='+vlag+'&start='+start;
	//var url = '/modules/search/search.php?query='+encodeURIComponent(query)+'&vlag='+vlag+'&start='+start+'&sSecret='+secret+'&position='+position;
	var url = '/modules/search/search.php?query='+encodeURIComponent(query)+'&vlag='+vlag+'&start='+start+'&position='+position+'&sSecret='+secret;
	
	
	//alert(secret);
	
	/* Request AJAX Update */
	new Ajax.Updater('searchresults', url);
	}
	
}

function jumpURL(url)
{
	window.location = url;
}

function showLanguageList()
{
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
	document.getElementById('language_list').style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.language_list.style.visibity = 'visible';
		}
		else { // IE 4
			document.all.language_list.style.visibity = 'visible';
		}
	}
}

function hideLanguageList(event)
{

	var toElement = null;
	
	//if (event.srcElement.tagName == "DIV") 
	//divLayer.style.visibility='hidden';
	
	//if (!event.fromElement.contains(event.toElement) &&!document.getElementById('divGallery').contains( event.toElement))
	// divLayer.style.visibility='hidden';
	
	if (event.relatedTarget) 
	{
		toElement = event.relatedTarget;
	}
	else if (event.toElement) 
	{
		toElement = event.toElement;
	}
	
	while (toElement && toElement.id != 'language_list') 
	{
		toElement = toElement.parentNode;
	}
	
	if (!toElement) {
		if (document.getElementById) 
		{
			document.getElementById('language_list').style.display = 'none';
		}
		else
		{
			if (document.layers) 
			{ // Netscape 4
				document.language_list.style.visibity = 'none';
			}
			else 
			{ // IE 4
				document.all.language_list.style.visibity = 'none';
			}
		}
	}
}

//function realClose()	{
//	
//	if (document.getElementById) {
//		document.getElementById('language_list').style.display = 'none';
//	}
//	else
//	{
//		if (document.layers) { // Netscape 4
//			document.language_list.style.visibity = 'none';
//		}
//		else 
//		{ // IE 4
//			document.all.language_list.style.visibity = 'none';
//		}
//	}
//}



//function closeLanguageList()	{
//	//lijst sluiten op true
//	sluitLanguage = true;
//	//timer starten
//	setTimeout("mayClose()", 2000 );
//}
//
//function mayClose()	{
//	//controleren of sluitlanguage nog true is, zo ja sluiten
//	if (sluitLanguage)	{
//		if (document.getElementById) {
//			document.getElementById('language_list').style.display = 'none';
//		}
//		else 
//		{
//			if (document.layers) { // Netscape 4
//				document.language_list.style.visibity = 'none';
//			}
//			else 
//			{ // IE 4
//				document.all.language_list.style.visibity = 'none';
//			}
//		}
//			
//			
//	}
//	
//}

