
//als mensen bookmarks openen, komen ze niet terecht op de taalkeuze
//en wordt er geen cookie gezet
checkCookie();
//var lang = getLanguage();

function checkCookie()
{
  if(getLanguage() == null)
  {
    var docPath = (document.location.pathname).toUpperCase();	
    
    if(docPath.indexOf('/NL/')>-1)
    {
      	SetCookie('LANG', 'NL', exp);  
    }

    if(docPath.indexOf('/FR/')>-1)
    {
      SetCookie('LANG', 'FR', exp);  
    }
  }
}

// verwisselen van de taalkeuze
function getoppositelng()
{ 
  var dname = getDocName();
  var curlng = dname.substr(0,2) + "";
  var newDocLocation = '';
  
  //-- uitzonderingen 
  if (dname =='NLzoek.shtm')
  {
	newDocLocation = '../rechercher/FRrecherche.shtm';
  }
  
  if (dname =='NLzoektips.shtm')
  {
	newDocLocation = '../rechercher/FRtrucs.shtm';
  }
  
  if (dname =='FRrecherche.shtm')
  {
	newDocLocation = '../zoeken/NLzoek.shtm';
  }
  
  if (dname =='FRtrucs.shtm')
  {
	newDocLocation = '../zoeken/NLzoektips.shtm';
  }
   
  if ( dname.indexOf('newsletter')>-1) 
  {
	if (dname.indexOf('_fr.')>-1)
	{
	    curlng = 'FR';
		newDocLocation = '/subscribe/newsletter_index_nl.jsp';
	}
	else
	{
	    curlng = 'NL';
		newDocLocation = '/subscribe/newsletter_index_fr.jsp';
	}
  }
  //--

  if (curlng == 'FR')
  {
    SetCookie('LANG', 'NL', exp);  
  
    if(newDocLocation == '')
    {
      newDocLocation = '../NL/NL' + dname.substr(2,(dname.length - 2) );
    }	
  }
  
  if (curlng == 'NL')
  {
    SetCookie('LANG', 'FR', exp);
	
	if(newDocLocation == '')
    {
      newDocLocation = '../FR/FR' + dname.substr(2,(dname.length - 2) );
	}  
  }
  
  return newDocLocation;
}  

//    SCRIPT FOR LANGUAGE
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
	endstr = document.cookie.length;  
	//alert(unescape(document.cookie.substring(offset, endstr)));
  return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
  var arg = name + "=";  
  var alen = arg.length;  
  var clen = document.cookie.length;  
  var i = 0;  
  while (i < clen) {    
    var j = i + alen;    
    if (document.cookie.substring(i, j) == arg)      
      return getCookieVal (j);    
    i = document.cookie.indexOf(" ", i) + 1;    
    
	if (i == 0) break;   
  }  
  return null;
}

function SetCookie (name, value) {  
  var argv = SetCookie.arguments;  
  var argc = SetCookie.arguments.length;  
  var expires = (argc > 2) ? argv[2] : null;  
  var path = (argc > 3) ? argv[3] : null;  
  //path = ""; 
  path = "/"; 
  var domain = (argc > 4) ? argv[4] : null;  

  //domain = "ngi.be";
  var secure = (argc > 5) ? argv[5] : false;     
  document.cookie = name + "=" + escape (value) + 
     ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
     ((path == null) ? "" : ("; path=" + path)) +  
     ((domain == null) ? "" : ("; domain=" + domain)) +    
     ((secure == true) ? "; secure" : "");

}
function sethome() {
var favorite = GetCookie('LANG');
//alert ('favorite\n' + favorite);
if (favorite != null) {
  switch (favorite) {
    case 'NL' : 	
	url = '/NL/NL0.shtm'; 
	     	break;
    case 'FR' : 	url = '/FR/FR0.shtm'; 
	     	break;
}
window.location.href = url;
}

}

function getLanguage(){
		 	return GetCookie ('LANG');
		}	
   		
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
    endstr = document.cookie.length;
	//alert('unescape\n'+unescape(document.cookie.substring(offset, endstr)));  
  return unescape(document.cookie.substring(offset, endstr));
}






var isNav = (navigator.appName.indexOf("Netscape")>=0);

function getLayer(name) {
	var theObj = document.getElementById(name);
	if (theObj!=null) {
		return theObj.style
	 }  else {
	    return(null);
	 }
}
function moveLayer(name, x, y) {
	//alert (name +x+y);
  	var layer = getLayer(name);		
    layer.left = x + "px";
   	layer.top  = y + "px";
}
function setLayerBackgroundColor(name, color) {		
  	var layer = getLayer(name);		
	layer.backgroundColor = color;
}
function hideLayer(name) {		
  	var layer = getLayer(name);		
  	layer.visibility = "hidden";
}
function showLayer(name) {		
  	var layer = getLayer(name);		
  	layer.visibility = "visible";

}
var isMoving = false;
var idx, idy;
var idLayer;
var theX, theY;
function startMove(e, divId) {
	idLayer = document.getElementById(divId);
	isMoving = true;
	getXY(e);
	idx = theX - idLayer.offsetLeft;
	idy = theY - idLayer.offsetTop;
	document.onmousemove = updateMove;
	document.onmouseup = stopMove;
}
function getXY(e) {
	if (isNav) {
		theX=e.pageX;
		theY=e.pageY;
	} else {
		theX=event.clientX + document.body.scrollLeft;
		theY=event.clientY + document.body.scrollTop;
	}
	return false;
}
function updateMove(e) {
	if(!isMoving || (idLayer == null)) return;
	getXY(e);
	idLayer.style.left = theX - idx + "px";
	idLayer.style.top = theY - idy + "px";
	if (idLayer.offsetLeft < 0)
		idLayer.style.left = 0;
	if (idLayer.offsetTop < 0)
		idLayer.style.top = 0;
}

function stopMove() {
	if(!isMoving || (idLayer == null)) return;
	idLeft = idLayer.offsetLeft;
	idTop = idLayer.offsetTop;
	isMoving = false;
	idLayer = null;
}




function MM_reloadPage(init) {  //reloads the window if nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// <!-- fonctions utilies qui seront exportée dans un fichier scripts outils ... -->

function getDocName() {
	var docName;
	var docPath = document.location.pathname;
	var i = docPath.length - 1;
	while ((i >= 0) && (docPath.charAt(i) != "/")) {
		i--;
	};
	docName = docPath.substring(i + 1,docPath.length);
  	return docName;
}

function getServerName() {
	var ServerName = parent.document.location.host;
	//alert ('ServerName\n' + ServerName);
  	return ServerName;
}

function getindexof(thevalue,a)
{ 
    var i = 0;
    for (i = 0; i < a.length; i++) 
    {      if (a[i].name == thevalue ) 
           {         return i;      
           };   
    };
    return -1;
}

function linknamefrom(DocName,strbegin)
{ 
   var myDocName = DocName;
   var i = myDocName.indexOf('.');
   if (i < 1) 
   { i = myDocName.length;
   };
   var LinkName = strbegin + myDocName.substring(0,i);
   return LinkName; 
} 






// <!-- enkele regelmatig gebruikte functies... -->


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// <!-- om administratiekosten te laten zien -->

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function ShowAdmin() { //v3.0
  var i,p,v,obj,args=ShowAdmin.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}



// <!--  functie die illegale karaters filtert-->

function verifyAlpha_search(AZ) {
	var CorrChar = new Array();
	var pos = 0;
	
	// De Array CorrChar bevat de ASCII codes van toegelaten karakters. Om chars toe te voegen of te verwijderen moet je enkel 2 lijntjes initialisatie-code bijvoegen

	CorrChar[pos] = 13;
	pos++;
	
	CorrChar[pos] = 32;
	pos++;
	
	for (var l = 44; l < 47; l++){
		CorrChar[pos] = l;
		pos++;
	}
	
	CorrChar[pos] = 58;
	pos++;
	
	for (var l = 48; l < 58; l++){
		CorrChar[pos] = l;
		pos++;
	}
	
	for (var l = 64; l < 91; l++){
		CorrChar[pos] = l;
		pos++;
	}	
	
	for (var l = 95; l < 123; l++){
		CorrChar[pos] = l;
		pos++;
	}
	
	CorrChar[pos] = 224;
	pos++;
		
	CorrChar[pos] = 226;
	pos++;		
		
	CorrChar[pos] = 228;
	pos++;
	
	for (var l = 231; l < 236; l++){
		CorrChar[pos] = l;
		pos++;
	}	

	CorrChar[pos] = 244;
	pos++;
	
	CorrChar[pos] = 246;
	pos++;
	
	CorrChar[pos] = 249;
	pos++;
	
	CorrChar[pos] = 251;
	pos++;
	
	CorrChar[pos] = 255;
	pos++;
	
	//extra for search
	CorrChar[pos] = 39;
	pos++;
	
	CorrChar[pos] = 34;
	pos++;
		
	CorrChar[pos] = 42;
	pos++;
	
	CorrChar[pos] = 43;
	pos++;
	
	CorrChar[pos] = 45;
	pos++;
	
	CorrChar[pos] = 95;
	pos++;
	
	var validChar = false;
	
  	if (AZ.length!=0) {
	    for (var i=0; i<AZ.length; i++) {
			bValidChar = false;
		
			for (var j = 0; j < CorrChar.length; j ++){
				if (AZ.charCodeAt(i) == CorrChar[j]){
					bValidChar = true;
				}
			} 
			if(!bValidChar){
				AZ = AZ.replace(AZ.substring(i,i+1),"");
				i--;
			}
    	}
	}
	return AZ;
}

//this variable is used in the banner files to check if the siteMessage is active or not
//if set to false the message is never shown
var siteMessageActive = false;

//show on all pages or not:  if set to true the array 'pageArray' is not checked
var showOnAllPages = true;

//set the pages that must show the message
//you don't include the language in the page name: if the page is called NL1-9.shtm , you put 1-9.shtm in the array.
//if 'showOnAllPages' is set to true, this array will not be checked
var pageArray = ['0.shtm'];

//the message nl/fr
var siteMessageNL = '<font color="Purple"><strong>De winkel van het NGI zal gesloten zijn van 24 december 2011 tot en met 03 januari 2012.</strong></font>';
var siteMessageFR = '<font color="Purple"><strong>Le service de vente de l\'IGN sera ferm&eacute; du 24 d&eacutecembre 2011 au 03 janvier 2012 inclus. </strong></font>'; 

function showSiteMessage(messageLang)
{
	var dname = getDocName();
	var curLang = getLanguage();
	
	if(showOnAllPages)
	{
		makeSiteMessageVisible(messageLang);
	}
	else
	{
		var found = false;
		
		for(var i=0; (i <pageArray.length)&&(!found); i++)
		{
			if ( dname.indexOf(curLang+pageArray[i])>-1) 
			{
				makeSiteMessageVisible(messageLang);
				found = true;
			}
		}	
	}
}

function makeSiteMessageVisible(messageLang)
{ 
	if(messageLang == "NL")
	{
		document.getElementById("siteMessageText").innerHTML = siteMessageNL; 
	}
	else
	{
		document.getElementById("siteMessageText").innerHTML = siteMessageFR; 
	}
			
	document.getElementById("siteMessage").style.display = "";
}

function closeSiteMessage()
{
	document.getElementById("siteMessage").style.display = "none";
}

function $() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (arguments.length == 1)
				return element;
			elements.push(element);
		}		
		return elements;
		
}

