﻿// More languages are welcome. Please send your list of country names, error messages, page text and explain text
// to TBG5 administrator. More advice at the end of this script. Thnx

// Special thx to:
// Italiano: Renato Polo				Norsk: Siri-Anne dos Santos
// French: Walter Hoffmann & Pierrick Daumain		Polski: Norbert Wozniak
// Romanian: Kalman Pusztai				Srpski, Serbian: Aleksandar Blagojevic
// Български, Bulgarian: Luben Karavelov		Slovenščina, Slovene: Alfred Anzlovar
// Nederlands: Mark Sensen				Russian: Vasiliy Marhotsky
// Magyar, Hungarian: Tibor Albert			Lietuvių, Lithuanian: Edmundas Kausikas
// Türkçe: Oguz Cekmeceligil				Català: Cristòfol-Josep Bordes i Figuerola
// Svenska, Swedish: Lars Madej				中文, Chinese: May Chen
// Greek: Stamatis Liatsos & Ian Gourley		Español Castellano: Jesús Ferreiro
// Shqip, Albanian: Artan Rrustemi			Português: Antonio Aguiar
// Česky: Pavel Pech & Eva Marešová 			Suomi, Finnish: Juha Keski-Nisula
// Slovenčina, Slovak: Lubomir Duchon			Dansk, Danish: Christian Staal
// Croatian: Zoran Babić				Latviešu, Latvian: Toms Abeltins
// Eesti, Estonian: Sven-Olav Paavel 			日本語, Japanese: Kenji Itoh

// Other: Markus Olderdissen 

// Scripting: Hendrik Muus

// add in_array method to arrays
Array.prototype.in_array = function(value) {
	var found = false;
	for (var i=0; i<this.length; i++) {
		if (this[i] == value) {
			found = i;
			break; }}
	return found; }
// add ISO13616Prepare method to strings
String.prototype.ISO13616Prepare = function() {
	var isostr = this.toUpperCase();
	isostr = isostr.substr(4) + isostr.substr(0,4);
	for (var i = 0; i <= 25; i++) {
		while (isostr.search(String.fromCharCode(i+65)) != -1) {
			isostr = isostr.replace(String.fromCharCode(i+65), String(i+10)); }}
	return isostr; }
// add ISO7064Mod97_10 method to strings
String.prototype.ISO7064Mod97_10 = function() {
	var parts = Math.ceil(this.length/7);
	var remainer = "";
	for (var i = 1; i <= parts; i++) {
		remainer = String(parseFloat(remainer+this.substr((i-1)*7, 7))%97); }
	return remainer; }
// replacement of === for javascript version < 1.2
function is_ident(a,b) {
	var identical = false;
	if (typeof(a)==typeof(b)) {
		if (a==b) {
			identical = true; }}
	return identical; }

// language codes
//			  1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30
var lngc = new Array (	"de","en","it","no","fr","pl","ro","sr","bg","sl","nl","ru","hu","lt","tr","ca","sv","zh","el","es","sq","pt","cs","fi","sk","da","hr","lv","et","ja");
// we have currently these languages:	1 deutsch, german, 2 english, 3 italiano, 4 norsk, 5 french, 6 polski, 7 romanian, 8 srpski, serbian, 9 Български, bulgarian, 10 slovenščina, slovene,
//					11 nederlands, 12 russian, 13 magyar, hungarian, 14 lietuvių, lithuanian, 15 türkçe, 16 català, 17 svenska, swedish, 18 中文, chinese, 19 greek,
//					20 español castellano, 21 shqip, albanian, 22 português, 23 česky, 24 suomi, finnish, 25 slovenčina, slovak, 26 dansk, danish, 27 croatian,
//					28 latviešu, latvian, 29 eesti, estonian, 30 日本語, japanese
// language selector
var lngsel =	"<option value=\"9\">Български, bulgarian</option>"+
		"<option value=\"16\">català</option>"+
		"<option value=\"23\">česky</option>"+
		"<option value=\"18\">中文, chinese</option>"+
		"<option value=\"27\">croatian</option>"+
		"<option value=\"26\">dansk, danish</option>"+
		"<option value=\"1\">deutsch, german</option>"+
		"<option value=\"29\">eesti, estonian</option>"+
		"<option value=\"2\">english</option>"+
		"<option value=\"20\">español castellano</option>"+
		"<option value=\"5\">french</option>"+
		"<option value=\"19\">greek</option>"+
		"<option value=\"3\">italiano</option>"+
		"<option value=\"30\">日本語, japanese</option>"+
		"<option value=\"14\">lietuvių, lithuanian</option>"+
		"<option value=\"28\">latviešu, latvian</option>"+
		"<option value=\"13\">magyar, hungarian</option>"+
		"<option value=\"11\">nederlands</option>"+
		"<option value=\"4\">norsk</option>"+
		"<option value=\"6\">polski</option>"+
		"<option value=\"22\">português</option>"+
		"<option value=\"7\">romanian</option>"+
		"<option value=\"12\">russian</option>"+
		"<option value=\"21\">shqip, albanian</option>"+
		"<option value=\"25\">slovenčina, slovak</option>"+
		"<option value=\"10\">slovenščina, slovene</option>"+
		"<option value=\"8\">srpski, serbian</option>"+
		"<option value=\"24\">suomi, finnish</option>"+
		"<option value=\"17\">svenska, swedish</option>"+
		"<option value=\"15\">türkçe</option>";
// country codes, fixed length for those countries, inner structure, appliance of EU REGULATION 924/2009 and IBAN example
var ilbced = new Array ("AD", 24, /\d{8}[a-zA-Z0-9]{12}/,		"n", "AD1200012030200359100100",	
			"AL", 28, /\d{8}[a-zA-Z0-9]{16}/,		"n", "AL47212110090000000235698741",	
			"AT", 20, /\d{16}/,				"y", "AT611904300234573201",	
			"BA", 20, /\d{16}/,				"n", "BA391290079401028494",	
			"BE", 16, /\d{12}/,				"y", "BE68539007547034",	
			"BG", 22, /[A-Z]{4}\d{6}[a-zA-Z0-9]{8}/,	"y", "BG80BNBG96611020345678",	
			"CH", 21, /\d{5}[a-zA-Z0-9]{12}/,		"n", "CH9300762011623852957",	
			"CY", 28, /\d{8}[a-zA-Z0-9]{16}/,		"y", "CY17002001280000001200527600",	
			"CZ", 24, /\d{20}/,				"y", "CZ6508000000192000145399",	
			"DE", 22, /\d{18}/,				"y", "DE89370400440532013000",	
			"DK", 18, /\d{14}/,				"y", "DK5000400440116243",	
			"EE", 20, /\d{16}/,				"y", "EE382200221020145685",	
			"ES", 24, /\d{20}/,				"y", "ES9121000418450200051332",	
			"FI", 18, /\d{14}/,				"y", "FI2112345600000785",	
			"FO", 18, /\d{14}/,				"n", "FO6264600001631634",	
			"FR", 27, /\d{10}[a-zA-Z0-9]{11}\d\d/,		"y", "FR1420041010050500013M02606",	
			"GB", 22, /[A-Z]{4}\d{14}/,			"y", "GB29NWBK60161331926819",	
			"GI", 23, /[A-Z]{4}[a-zA-Z0-9]{15}/,		"y", "GI75NWBK000000007099453",	
			"GL", 18, /\d{14}/,				"n", "GL8964710001000206",	
			"GR", 27, /\d{7}[a-zA-Z0-9]{16}/,		"y", "GR1601101250000000012300695",	
			"HR", 21, /\d{17}/,				"n", "HR1210010051863000160",	
			"HU", 28, /\d{24}/,				"y", "HU42117730161111101800000000",	
			"IE", 22, /[A-Z]{4}\d{14}/,			"y", "IE29AIBK93115212345678",	
			"IL", 23, /\d{19}/,				"n", "IL620108000000099999999",	
			"IS", 26, /\d{22}/,				"y", "IS140159260076545510730339",	
			"IT", 27, /[A-Z]\d{10}[a-zA-Z0-9]{12}/,		"y", "IT60X0542811101000000123456",	
			"LB", 28, /\d{4}[a-zA-Z0-9]{20}/,		"n", "LB62099900000001001901229114",	
			"LI", 21, /\d{5}[a-zA-Z0-9]{12}/,		"y", "LI21088100002324013AA",	
			"LT", 20, /\d{16}/,				"y", "LT121000011101001000",	
			"LU", 20, /\d{3}[a-zA-Z0-9]{13}/,		"y", "LU280019400644750000",	
			"LV", 21, /[A-Z]{4}[a-zA-Z0-9]{13}/,		"y", "LV80BANK0000435195001",	
			"MC", 27, /\d{10}[a-zA-Z0-9]{11}\d\d/,		"y", "MC1112739000700011111000h79",	
			"ME", 22, /\d{18}/,				"n", "ME25505000012345678951",	
			"MK", 19, /\d{3}[a-zA-Z0-9]{10}\d\d/,		"n", "MK07300000000042425",	
			"MT", 31, /[A-Z]{4}\d{5}[a-zA-Z0-9]{18}/,	"y", "MT84MALT011000012345MTLCAST001S",	
			"MU", 30, /[A-Z]{4}\d{19}[A-Z]{3}/,		"n", "MU17BOMM0101101030300200000MUR",	
			"NL", 18, /[A-Z]{4}\d{10}/,			"y", "NL91ABNA0417164300",	
			"NO", 15, /\d{11}/,				"y", "NO9386011117947",	
			"PL", 28, /\d{8}[a-zA-Z0-9]{16}/,		"y", "PL27114020040000300201355387",	
			"PT", 25, /\d{21}/,				"y", "PT50000201231234567890154",	
			"RO", 24, /[A-Z]{4}[a-zA-Z0-9]{16}/,		"y", "RO49AAAA1B31007593840000",	
			"RS", 22, /\d{18}/,				"n", "RS35260005601001611379",	
			"SA", 24, /\d{2}[a-zA-Z0-9]{18}/,		"n", "SA0380000000608010167519",	
			"SE", 24, /\d{20}/,				"y", "SE4550000000058398257466",	
			"SI", 19, /\d{15}/,				"y", "SI56191000000123438",	
			"SK", 24, /\d{20}/,				"y", "SK3112000000198742637541",	
			"SM", 27, /[A-Z]\d{10}[a-zA-Z0-9]{12}/,		"n", "SM86U0322509800000000270100",	
			"TN", 24, /\d{20}/,				"n", "TN5914207207100707129648",	
			"TR", 26, /\d{5}[a-zA-Z0-9]{17}/,		"n", "TR330006100519786457841326");
// we have currently # countries
var ctcnt = ilbced.length/5;
// use language 2 (english) by default
if (typeof(lngg) == 'undefined') {
	lngg = 2;
	// workaround
	if ((location.search != "") && (location.search != "?")) {
		sstr = window.location.search.substr(1,window.location.search.length-1);
		if (!isNaN(sstr ) && (sstr*1 > 0) && (sstr*1 < lngc.length)) {
			lngg = Number(sstr); }}}
// rearange country codes and related info
var ilbc = new Array ();
for (j = 0; j < 5; j++) {
	for (i = 0; i < ctcnt; i++) {
		ilbc[ilbc.length]=ilbced[j+i*5];  }}
// the magic core routine
function checkibancore(iban) {
	illegal = /\W|_/; // contains chars other than (a-zA-Z0-9) 
	if(illegal.test(iban)) { // yes, alert and exit
		alert(altxt[0]);
		return "0"; }
	else { // no, continue
		illegal = /^\D\D\d\d.+/; // first chars are letter letter digit digit
		if(illegal.test(iban) == false) { // no, alert and exit
			alert(altxt[1]); 
			return "0"; }
		else { // yes, continue
			illegal = /^\D\D00.+|^\D\D01.+|^\D\D99.+/; // check digit are 00 or 01 or 99
			if(illegal.test(iban)) { // yes, alert and exit
				alert(altxt[2]);
				return "0"; }
			else { // no, continue
				lofi = ilbc.slice(0,ctcnt).in_array(iban.substr(0,2).toUpperCase()); // test if country respected
				if (is_ident(false,lofi)) { ctck=-1; lofi=6; }  // country not respected
				else { ctck=lofi; lofi=ilbc[ctcnt+lofi]; } // country respected
				if (lofi == 6) { // not respected, alert
					alert(altxt[3]+iban.substr(0,2).toUpperCase()+altxt[4]); 
					lofi = iban.length; }  // but continue
				if ((iban.length-lofi) != 0) { // fits length to country
					alert(altxt[5]+ctynm[ctck]+altxt[6]+ilbc[ctck+ctcnt]+altxt[7]); // no, alert and exit
					return "0"; } // yes, continue
				if (ctck >= 0) { illegal = ilbc[ctck+ctcnt*2]; } // fetch sub structure of respected country
				else { illegal = /.+/; } // or take care of not respected country
				if (illegal.test(iban.substr(4)) == false) { // fits sub structure to country
					alert(altxt[1]); // no, alert and exit
					return "0"; }
				else { // yes, continue
					return iban.ISO13616Prepare().ISO7064Mod97_10(); }}}}} // calculate and return the remainer
// perform the check
function checkiban(iban) {
	if (checkibancore(iban) == "1") { alert(altxt[8]); } // and prompt result
	else { alert(altxt[9]); }}
// some convenience for web page
function langsel() { document.write(lngsel); } //language selector
function lginfo() {
	if (is_ident(false,lngc.in_array(hlc.substr(1,2)))) {
		document.write("<BR><small>"+hlc+" currently not translated, like to translate?</small>"); }}
function rwt(tnum) { 
	document.write(wptxt[tnum]); } //web page text by number
function rwt2(pos) { 
	if (wptxt[0] == pos) {
		document.write(" <a href='http://eur-lex.europa.eu/Result.do?RechType=RECH_celex&code=32009R0924&checktexts=checkbox' target='_blank' title='Regulation 924 on eur-lex.europa.eu'>EU Regulation 924/2009</a> "); }} //special web page text
// whole line of special web page text
function rwt3() { 
	document.write("<small><BR>(");
	rwt2(0);
	document.write("<span class=\"tbg5eray\">");
	rwt(3);
	document.write("</span> / <span class=\"tbg5eran\">");
	rwt(4);
	document.write("</span>");
	rwt2(1);
	document.write(")<BR><BR></small>"); }
// some convenience to list the countries
function rcr(tnum) { return ilbc[ctcnt*3+tnum]; } //country regulatory info by number
function rcl(tnum) { return wptxt[8]+ilbc[ctcnt*1+tnum]; } //hover text for code
function rce(tnum) { return wptxt[9]+ilbc[ctcnt*4+tnum]; } //hover text for name
// list countries in x columns with language y ##### old, use new please #####
function listcountries(columni,llngg) {
	listcountriesnew(columni,llngg,"n",""); }
// list countries in x columns with language y show flag y/n from path ##### new #####
// make sure the flag images are available at path and provide a style declaration like "img.tbg5cdf { height:20px; }" !!
function listcountriesnew(columni,llngg,flag,ipath) {
	lngg = llngg; //use language parameter
	if (flag == "n") {
		document.write("<table class=\"tbg5ct\">\r\n<TR class=\"tbg5crt\"><TD class=\"tbg5cdt\" colspan=\""+columni*2+"\">&nbsp;</TD></TR>\r\n"); }
	else {	document.write("<table class=\"tbg5ct\">\r\n<TR class=\"tbg5crt\"><TD class=\"tbg5cdt\" colspan=\""+columni*3+"\">&nbsp;</TD></TR>\r\n"); }
	var numberofrows = Math.ceil(ctcnt/columni); //calculate rows
	for (i = 0; i < numberofrows; i++) { //for each row
		document.write("<tr class=\"tbg5crl\">");
		for (var j = 0; j < columni; j++) { //for each column
			if ((i*columni+j)<ctcnt) { //fill cells
				document.write("<td class=\"tbg5cdc\" title=\""+rcl(i*columni+j)+"\"><span class=\"tbg5era"+rcr(i*columni+j)+"\">"+ilbc[i*columni+j]+"</span></td>"); //country code
				if (flag == "y") { //show flag
					document.write("<td class=\"tbg5cdf\"><img class=\"tbg5cdf\" src=\""+ipath+ilbc[i*columni+j]+".png\" alt=\""+ctynm[i*columni+j]+"\" title=\""+ctynm[i*columni+j]+"\"></td>"); }
				document.write("<td class=\"tbg5cdn\" title=\""+rce(i*columni+j)+"\"><span class=\"tbg5era"+rcr(i*columni+j)+"\">"+ctynm[i*columni+j]+"</span></td>"); }} //country name
		document.write("</tr>\r\n"); }
	document.write("</table>\r\n"); }
// some convenience for additional explanations
function doexplain(llngg) {
	document.write(xpltxt); }
// now load languagefile
function llanguagefile(language) {
	document.write('<script charset="utf-8" src="'+language+'" type="text/JavaScript"><\/script>'); }
function llanguage(language) {
	jsfile = 'http://www.tbg5-finance.org/'+lngc[language-1]+'.js';
	llanguagefile(jsfile); }
llanguage(lngg);

// translators please take a source language including // language ++++... from laguage file e.g. en.js
// translate and store in UTF-8 encoding to support your national characters
// only care about text surrounded by quotes, i.e. leave all other characters and format as is 
// send it
//
// please observe following special notation in translation of "web page" text
//
//                                    V
// wptxt = wptxt.concat ( new Array ( 0 ,"text 1","text 2","text 3","text 4","text 5","text 6","text 7","text 8","text 9"));
// results in
// "("+" EU Regulation 924/2009 "+"text 3"+"/"+"text 4"+")"
//
// while
//                                    V
// wptxt = wptxt.concat ( new Array ( 1 ,"text 1","text 2","text 3","text 4","text 5","text 6","text 7","text 8","text 9"));
// results in
// "("+"text 3"+"/"+"text 4"+" EU Regulation 924/2009 "+")"
//
// i.e. it is a language adaptor. Please choose properly. Thx
//
// therefore
// with 0 make it "text3","text 4 "
// with 1 make it " text3","text 4"

// script end
