// ==============================================================
// Taal.js
// De scripts, die deel uit maken van het systeem om meerdere talen
// in een tekst te gebruiken zijn eigendom van Faase.
// Gebruik zonder schriftelijke toestemming is niet toegestaan.
// Bevat ook de funkties voor parameters lezen. Alleen die nodig gebruik dan param.js
// ==============================================================


// ==============================================================
// Schrijven van een Cookie.
// ==============================================================
function WriteCookie (cookieName, cookieValue)
{ document.cookie = cookieName + "=" + escape (cookieValue);};


// ==============================================================
// Lezen van een Cookie
// ==============================================================
function ReadCookie (CookieName)
{
  var CookieString = document.cookie;
  var CookieSet = CookieString.split (';');
  var SetSize = CookieSet.length;
  var CookiePieces
  var ReturnValue = "";
  var x = 0;

  for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++)
  {
    CookiePieces = CookieSet[x].split ('=');
    if (CookiePieces[0].substring (0,1) == ' ')
        CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);

    if (CookiePieces[0] == CookieName)
        ReturnValue = CookiePieces[1];
  }
  return ReturnValue;
}


// ---------------------------------------------------
// Paramaters uit pagina-aanroep halen.
// ---------------------------------------------------
function getParams()
{
 var idx = document.URL.indexOf('?');
 var params = new Array();
 if (idx != -1)
   {
    var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
    for (var i=0; i<pairs.length; i++)
       {
        nameVal = pairs[i].split('=');
        params[nameVal[0]] = nameVal[1];
       }
   }
 return params;
}

params = getParams();

// ---------------------------------------------------
// Omzetten paramaters uit pagina-aanroep in waarden.
// ---------------------------------------------------
function convertPlus(str)
{var out = "", flag = 0;
 for (i = 0; i < str.length; i++)
   {
    if (str.charAt(i) != "+") {out += str.charAt(i); flag = 0;}
    else {if(flag == 0) {out += " "; flag = 1;}}
   };
 return out.toLowerCase();
}


// ---------------------------------------------------
// Taal bepalen.
// 1 = ned, 2 = engels, 3 = turks
// ---------------------------------------------------
function Taal(voorkeur)
{
// if (voorkeur == 'undefined') voorkeur = 1;	// Geen waarde, dan 1 (nederlands).

 var ktl = convertPlus(unescape(params["tl"]));
 if (ktl == 'undefined')
  {
   koek = ReadCookie("vitaal");
   ktl = parseInt(koek);
   if (isNaN(ktl)) ktl = voorkeur;          // Voor als het cookie niet bestaat:
                                            // Neem voorkeur taal.
  };
 return ktl;
}



// -----------------------------------------------------
// Veranderen van taal.
// Variabele pagina zonder .htm geven
// vert: afwezig of h, dan horizontaal, v = vertikaal.
// talen: string met cijfers bv "124" = taal 1, 2 en 4.
// -----------------------------------------------------
function KiesTaal(vert, talen)
{
 docpl = document.location+" ";
 docpl = docpl.toLowerCase();  

 uitgang = docpl.indexOf(".html")>0?".html":".htm";
 
 pagdeelnr = docpl.indexOf(uitgang);
 pagdeel = docpl.substring(0, pagdeelnr)+uitgang;
                             // De pagina zelf uitzoeken.

 aanroep = parseInt(location.search.substring(1,100));
                             // Eventueel nummer van pagina overnemen.
                             // Bv. xxx.htm?3 geeft dan 3.

 if (isNaN(aanroep)) aanroeps = pagdeel+"?"
 else aanroeps = pagdeel+"?"+aanroep+"&";
                             // pagina plus al dan niet ? nummer.
                             // In dat geval & erachter.

 if (typeof vert == 'undefined') vert = "h";
                             // Standaard horizontaal.
 if (typeof talen == 'undefined') talen = "123";
                             // Standaard alle talen.

 tc = "</TD><TD WIDTH=35>";
 if (vert == "v") tc = "</TD></TR><TR><TD WIDTH=35>";

 mtk = "<A HREF="+apo+aanroeps+"tl="
 uit = "OnMouseOut="+apo+"nd()"+apo+">";

 document.write("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1>");
 document.write("<TR><TD WIDTH=35>");
 
 if ((talen.indexOf("1") > -1) && ( tl != "1"))
    {
     pt = "<IMG SRC="+apo+plsub+"nl.gif"+apo+" BORDER=0></A>";
     document.write(mtk+"1"+apo);
     document.write("OnMouseOver="+apo+"return overlib('Tekst in het Nederlands', FGCOLOR, 'yellow')"+apo);
     document.write(uit+pt+tc);
    };

 if ((talen.indexOf("2") > -1) && ( tl != "2"))
    {
     pt = "<IMG SRC="+apo+plsub+"gb.gif"+apo+" BORDER=0></A>";
     document.write(mtk+"2"+apo);
     document.write("OnMouseOver="+apo+"return overlib('Text in English', FGCOLOR, 'yellow')"+apo);
     document.write(uit+pt+tc);
    };

 if ((talen.indexOf("3") > -1) && ( tl != "3"))
    {
     pt = "<IMG SRC="+apo+plsub+"tr.gif"+apo+" BORDER=0></A>";
     document.write(mtk+"3"+apo);
     document.write("OnMouseOver="+apo+"return overlib('Türkçe tekst', FGCOLOR, 'yellow')"+apo);
     document.write(uit+pt+tc);
    };

 document.write("</TD></TR></TABLE>");
 WriteCookie ("vitaal", tl);
}


// ---------------------------------------------------
// Teksten voor verschillende talen. Inclusief neerzetten.
// ArT: een array met Ned, Engels, Turks.
// ---------------------------------------------------

function TTekst(ArT)
{
 tk = ArT[0];
 if (tl == 2) tk = ArT[1];
 if (tl == 3) tk = ArT[2];
 document.write(tk);
};

// ---------------------------------------------------
// Teksten voor verschillende talen. Zonder neerzetten voor in Regel().
// ArT is een array met Ned, Engels, Turks.
// ---------------------------------------------------

function TTr(ArT)
{
 tk = ArT[0];
 if (tl == 2) tk = ArT[1];
 if (tl == 3) tk = ArT[2];

 if (typeof tk == 'undefined') tk = "-";
 return tk;
};

