<!--

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function focusNext(current)
{
	if ( current )
	{
		if ( current.id )
		{
			var partName = current.id;
			
			switch(partName)
			{
				case 'nr_a':
						next = 'nr_b'; 
					break;
				case 'nr_b':
						next = 'nr_c'; 
					break;
				case 'nr_c':
						next = 'nr_d'; 
					break;
				default:
						next = '*'; 
					break;														
			}
			
			if ( next != '*' )
			{
				var obj = document.getElementById(next);
				if ( obj )
				{
					obj.focus();
				}
			} 
		}
	}
}//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function focusPrev(current)
{
	if ( current )
	{
		if ( current.id )
		{
			var partName = current.id;
			
			switch(partName)
			{
				case 'nr_b':
						next = 'nr_a'; 
					break;
				case 'nr_c':
						next = 'nr_b'; 
					break;
				case 'nr_d':
						next = 'nr_c'; 
					break;					
				default:
						next = '*'; 
					break;														
			}
			
			if ( next != '*' )
			{
				var obj = document.getElementById(next);
				if ( obj )
				{
					obj.focus();
				}
			} 
		}
	}
}

//------------------------------------------------------------------------------------------------------------------------------------------------------

function editCardNumber(e, obj)
{
	var keycode = '';	
		
	if(window.event) // IE
	{
		keycode = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keycode = e.which;
	}
	
	if (obj)
	{
		if ( keycode == 8 )
		{
			if ( obj.value.length == 0 )
				focusPrev(obj);
		}
		else
		{
			if ( obj.value.length == 4 )
				focusNext(obj);
		}
	}								
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function clearErrors()
{
	var o = document.getElementById('errors');
	
	if ( o )
		o.innerHTML = '';
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function showErrorMessage(msgText)
{
	if ( msgText )
	{
		var o = document.getElementById('errors');
		
		if ( o )
		{
			o.innerHTML = msgText;
			o.style.color = 'red';
		}
	}
	
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function showMessage(msgText, mode, color)
{
	if ( !color )
		color = 'orange';
		
	if ( !mode )
		mode = 1;
		
	if ( msgText )
	{
		var o = document.getElementById('errors_' + mode);
		
		if ( o )
		{
			o.innerHTML = msgText;
			o.style.color = color;
			o.style.fontWeight = 'bold';
			o.style.display = 'block';			
		}
	}
	
	var r = document.getElementById('result_' + mode);
	
	if ( r )
	{
		r.style.display = 'none';
	}
	
}

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function validateAccountNumber(f,re,eMsg)
{
	var myErr = "";
	var fv = '';
	var fo = document.getElementById(f);
	
	if ( fo )
		fv = fo.value;

	var rex = new RegExp(unescape(re));
	
	var t = eval(rex.test(fv));	
	
	if(fv.length <= 0 || !t)
	{	
		myErr+="eMsg";
	}		
	else if( fv.length > 0 && !t)
	{

		myErr += "eMsg";
	}

	errorFields = new Array('acc', 'strAcc');
		
	if ( myErr.length > 0 )
	{
  		errorHighlight('on');
  		showMessage(unescape(eMsg), 1, 'red');	  		
  	}
  	else
  	{
  		errorHighlight('off');  
  		clearErrors();	
  	}

	document.reallySubmit = (myErr=="");
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function validateBranchAccount() 
{
	var i,p,q,nm,test,num,min,max,errors='',args=validateBranchAccount.arguments;
	
	var o = document.getElementById(args[0]);
	var bValue = '';
	
	if ( o )
		bValue = o.value;
		
	if ( bValue == '' )
		errors += "\n" + ralt(10);  
  
	if (errors)
	{ 
  		showMessage(errors, 1, 'red');
  		errorFields = new Array('branch', 'strBranch');
  		errorHighlight('on');
  	}
  	else  
  	{
  		errorFields = new Array('branch', 'strBranch');
  		errorHighlight('off');
		validateAccountNumber('acc','%5E%5B0-9%5D%7B9%7D$',ralt(11));
	}  	
  	  	
	document.reallySubmit = (errors == '' && document.reallySubmit);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function validate(string) {
    if (!string) return false;
	//if (string.length < 4) return false;
    var Chars = "0123456789";

    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
		
function validateCardNumber()
{
	var abc = new Array('a', 'b', 'c', 'd');
	
	for( i in abc)
	{
		lauks = document.getElementById('nr_' + abc[i]);

		if ( lauks )
		{
			var str = lauks.value;
			if( !validate(str) || (str.length != 4))
			{
				document.reallySubmit =  false;
				
		  		showMessage(ralt(9), 2, 'red');
		  		errorFields = new Array('strCardNumber', 'nr_a', 'nr_b', 'nr_c', 'nr_d');
		  		errorHighlight('on');
		  		
				return;
			} 
		}
		else
		{
			alert(abc[i] + ' --- ' + i);
	  		showMessage(ralt(9), 2, 'red');
	  		errorFields = new Array('strCardNumber', 'nr_a', 'nr_b', 'nr_c', 'nr_d');
	  		errorHighlight('on');		
			document.reallySubmit =  false;
			return;
		}
	}
	
	errorFields = new Array('strCardNumber', 'nr_a', 'nr_b', 'nr_c', 'nr_d');
	errorHighlight('off');	
	clearErrors();	
	
	document.reallySubmit =  true;
	return;	
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//we have currently 4 languages   1 deutsch, 2 english, 3 italiano, 4 norsk
lgc = 4;


//letters will be replaced with digits
repl = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
				 "10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35");
				 
//country codes, fixed length for those countries and appliance of EU REGULATION 2560/2001
ilbc = new Array ("AD","AT","BE","CH","CY","CZ","DE","DK","EE","ES","FI","FO","FR","GI","GB","GL","GR","HU","IE","IS","IT","LI","LT","LU","LV","MC","MT","NL","NO","PL","PT","RO","SE","SI","SK","TN",
				   24,  20,  16,  21,  28,  24,  22,  18,  20,  24,  18,  18,  27,  23,  22,  18,  27,  28,  22,  26,  27,  21,  20,  20,  21,  27,  31,  18,  15,  28,  25,  24,  24,  19,  24,  24,
				  "n", "y", "y", "n", "y", "y", "y", "y", "y", "y", "y", "n", "p", "y", "y", "n", "y", "y", "y", "n", "y", "y", "y", "y", "y", "n", "y", "y", "n", "y", "y", "n", "y", "y", "y", "n" );
				  
//country names
ctynm = new Array ("Andorra","Österreich","Belgien","Schweiz","Zypern","Tschechien","Deutschland","Dänemark","Estland","Spanien","Finnland","Färöer","Frankreich","Gibraltar","Großbritannien","Grönland",
				"Griechenland","Ungarn","Irland","Island","Italien","Liechtenstein","Litauen","Luxemburg","Lettland","Monaco","Malta","Niederlande","Norwegen","Polen","Portugal","Rumänien","Schweden","Slowenien","Slowakei","Tunesien",
				
				"Andorra","Austria","Belgium","Switzerland","Cyprus","Czech Republic","Germany","Denmark","Estonia","Spain","Finland","Faroe Islands","France","Gibraltar","Great Britain","Greenland",
				"Greece","Hungary","Ireland","Iceland","Italy","Liechtenstein","Lithuania","Luxemburg","Latvia","Monaco","Malta","Netherlands","Norway","Poland","Portugal","Romania","Sweden","Slovenia","Slovak Republic","Tunisia",
				
				"Andorra","Austria","Belgio","Svizzera","Cipro","Repubblica Ceca","Germania","Danimarca","Estonia","Spagna","Finlandia","Isole Faroe","Francia","Gibilterra","Gran Bretagna","Groenlandia",
				"Grecia","Ungheria","Irlanda","Islanda","Italia","Liechtenstein","Lituania","Lussemburgo","Lettonia","Monaco","Malta","Paesi Bassi","Norvegia","Polonia","Portogallo","Romania","Svezia","Slovenia","Slovacchia","Tunisia",
				
				"Andorra","Østerrike","Belgia","Sveits","Kypros","Tsjekkia","Tyskland","Danmark","Estland","Spania","Finland","Færøyene","Frankrike","Gibraltar","Storbritannia","Grønland",
				"Hellas","Ungarn","Irland","Island","Italia","Liechtenstein","Litauen","Luxemburg","Latvia","Monaco","Malta","Nederland","Norge","Polen","Portugal","Romania","Sverige","Slovenia","Slovakia","Tunis");
//error messages

var countryList = new Array("ru","en","lv");

countryList['lv'] = new Array
(
  "Andorai"
, "Austrijai"
, "Beļģijai"
, "Šveicei"
, "Kiprai"
, "Čehijas Republikai"
, "Vācijai"
, "Dānijai"
, "Igaunijai"
, "Spānijai"
, "Somijai"
, "Fēru Salām"
, "Francijai"
, "Gibraltāram"
, "Lielbritānijai"
, "Grenlandei"
, "Grieķijai"
, "Ungārijai" 
, "Īrijai"
, "Islandei"
, "Itālijai"
, "Lihtenšteinai"
, "Lietuvai"
, "Luksemburgai"
, "Latvijai"
, "Monako valstij"
, "Maltai"
, "Nīderlandei"
, "Norvēģijai"
, "Polijai"
, "Portugālei"
, "Rumānijai"
, "Zviedrijai"
, "Slovēnijai"
, "Slovākijas Republikai"
, "Tunisijai"
);

countryList['en'] = new Array
(
  "Andorra",
  "Austria",
  "Belgium",
  "Switzerland",
  "Cyprus",
  "Czech Republic",
  "Germany",
  "Denmark",
  "Estonia",
  "Spain",
  "Finland",
  "Faroe Islands",
  "France",
  "Gibraltar",
  "Great Britain",
  "Greenland",
  "Greece",
  "Hungary",
  "Ireland",
  "Iceland",
  "Italy",
  "Liechtenstein",
  "Lithuania",
  "Luxemburg",
  "Latvia",
  "Monaco",
  "Malta",
  "Netherlands",
  "Norway",
  "Poland",
  "Portugal",
  "Romania",
  "Sweden",
  "Slovenia",
  "Slovak Republic",
  "Tunisia"
);

countryList['ru'] = new Array
(
  "Андорра", 
  "Австрия", 
  "Бельгия", 
  "Швейцария", 
  "Кипр", 
  "Чешская Республика", 
  "Германия", 
  "Дания", 
  "Эстония", 
  "Испания", 
  "Финляндия", 
  "Фарерские острова", 
  "Франция", 
  "Гибралтар", 
  "Великобритания", 
  "Гренландия", 
  "Греция", 
  "Венгрия", 
  "Ирландия", 
  "Исландия", 
  "Италия", 
  "Лихтенштейн", 
  "Литва", 
  "Люксембург", 
  "Латвия", 
  "Монако", 
  "Мальта", 
  "Нидерланды", 
  "Норвегия", 
  "Польша", 
  "Португалия", 
  "Румыния", 
  "Швеция", 
  "Словения", 
  "Словацкая Республика", 
  "Тунис"
);
 
// we have currently # countries
ctcnt = ctynm.length/lgc;
// we have currently # alert texts
//atcnt = altxt.length/lgc;

//use language 2 (english) by default
lngg = 2;

//gets the country name 
//function rcty(tnum) { return ctynm[tnum+ctcnt*(lngg-1)]; }
function rcty(tnum,lang) { 
	if(typeof lang != 'undefined')
		if(typeof countryList[lang] != 'undefined')
			return countryList[lang][tnum];
	return countryList['lv'][tnum];
}
//gets the error text
//function ralt(tnum) { return altxt[tnum+atcnt*(lngg-1)]; }
function ralt(tnum) { return messages[tnum]; }

//the magic core routine
function checkiban(iban,lang) 
{

	if ( iban.length == 0 )
	{
		showMessage(ralt(12), 3, 'red');
		return;
	}
	
	ibano = iban; // remember for later use
	illegal = /\W|_/; // contains chars other than (a-zA-Z0-9) 
	if(illegal.test(iban)) { showMessage(ralt(0),3,'red'); } // yes, alert and exit
	else { // no, continue
		illegal = /^\D\D\d\d.+/; // first chars are letter letter digit digit
		if(illegal.test(iban) == false) { showMessage(ralt(1), 3, 'red'); } // no, alert and exit
		else { // yes, continue
			illegal = /^\D\D00.+|^\D\D01.+|^\D\D99.+/; // check digit are 00 or 01 or 99
			if(illegal.test(iban)) { showMessage(ralt(2), 3, 'red'); } // yes, alert and exit
			else { // no, continue
				iban = iban.toUpperCase(); // uppercase, to ease
				cntry = iban.substr(0,2); // fetch country
				lofi = 6; // "default" length of IBAN
				for (i = 0; i < ctcnt; i++) {	if (cntry == ilbc[i]) { lofi = ilbc[ctcnt+i]; ctck=i; }}  // yes, country respected
				if (lofi == 6) { // no, alert
					showMessage(ralt(3)+ ' "' + cntry + '" ' + ralt(4), 3, 'red'); 
					lofi = iban.length; }  // but continue
				if ((iban.length-lofi) != 0) { showMessage(ralt(5) + ' ' + rcty(ctck,lang) + ' ' + ralt(6) + ' ' +ilbc[ctck+ctcnt] + '!', 3, 'red'); } // fits length to country; no, x and exit
				else { // yes, continue
					iban = iban.substr(4,lofi-4) + iban.substr(0,4); // country and check digits to the end
					for (i = 0; i <= 25; i++) { // replace letters with digits
						while (iban.search(repl[i])!= -1) { iban = iban.replace(repl[i],repl[i+26]); }} // all of them
					coss = Math.ceil(iban.length/7); // calc count of substrings
					rmndr = ""; // remainer starts empty and always preceeds the current substring
					for (i = 1; i <= coss; i++) { // step by step
						rmndr = String(parseFloat(rmndr+iban.substr((i-1)*7,7))%97); } // modulo division 97
					if (rmndr == "1") { showMessage(ralt(7),3, 'green'); } // and prompt result
					else { showMessage(ralt(8), 3, 'red'); }}}}}} //WRONG IBAN


//some convenience to list the countries
function rcc(tnum) { return ilbc[tnum]; } //country code by number
function rcn(tnum) { return rcty(tnum); } //country name by number
function rcl(tnum) { return prefixl[lngg-1]+ilbc[ctcnt+tnum]; } //hover text for code
function rce(tnum) { return prefixe[lngg-1]+examples[tnum]; } //hover text for name

//list countries in x columns with language y
function listcountries(columni,llngg) {
	lngg = llngg; //use language parameter
	document.write("<table class=\"tbg5ct\">\r\n<TR class=\"tbg5crt\"><TD class=\"tbg5cdt\" colspan=\""+columni*2+"\"> </TD></TR>\r\n");
	numberofrows = Math.ceil(ctcnt/columni); //calculate rows
	for (i = 0; i < numberofrows; i++) { //for each row
		document.write("<tr class=\"tbg5crl\">");
		for (j = 0; j < columni; j++) { //for each column
			if ((i*columni+j)<ctcnt) { //fill cell
				document.write("<td class=\"tbg5cdc\" title=\""+rcl(i*columni+j)+"\">"+rcc(i*columni+j)+"</td><td class=\"tbg5cdn\" title=\""+rce(i*columni+j)+"\">"+rcn(i*columni+j)+"</td>"); }}
		document.write("</tr>\r\n"); }
	document.write("</table>\r\n"); }

//some convenience for explain 
function doexplain(llngg) {
	xpltxt = new Array ("IE Irland kann für GB Großbritannien Konten benutzt werden im Fall, dass die servisierende Bank in Nord Irland situiert ist und das Clearingsystem Irlands benutzt; "+
						"GG Guernsey und JE Jersey benutzen entweder GB Großbritannien oder FR Frankreich abhängig vom Clearingsystem, das die servisierende Bank benutzt; "+
						"GF Französisch Guiana, GP Guadeloupe, MQ Martinique und RE Réunion benutzen FR Frankreich und unterliegen der EU-Regulative 2560/2001; "+
						"NC Neu Caledonien, PF Französisch Polynesien, PM Saint Pierre und Miquelon, TF Südfranzösische Territorien, WF Wallis und Futuna und YT Mayotte benutzen FR Frankreich; "+						
						"ES Spanien inkludiert die Kanarischen Inseln, Ceuta und Melilla; PT Portugal inkludiert die Azoren und Madeira",
						"IE Ireland may be used for GB Great Britain accounts in case the servicing bank is situated in North Ireland and uses the clearing system of the Republic of Ireland; "+
						"GG Guernsey and JE Jersey are using either GB Great Britain or FR France depending on the clearing system used by the servicing bank; "+
						"GF French Guiana, GP Guadeloupe, MQ Martinique and RE Réunion are using FR France and EU REGULATION 2560/2001 applies; "+
						"NC New Caledonia, PF French Polynesia, PM Saint Pierre and Miquelon, TF French Southern Territories, WF Wallis and Futuna and YT Mayotte are using FR France; "+
						"ES Spain includes Canary Islands, Ceuta and Melilla; PT Portugal includes Azores and Madeira",
						"IE Irlanda può essere usata per conti di GB Gran Bretagna se la banca amministrante è localizzata in Irlanda del Nord e usa il clearing della Repubblica di Irlanda; "+
						"GG Guernsey e JE Jersey usano sia GB Gran Bretagna oppure FR Francia in relazione a quale clearing viene usato dalla banca che amministra il conto; "+
						"GF Guyana Francese, GP Guadalupa, MQ Martinica e RE Isole Riunione usano FR Francia e adottano il Regolamento 2560/2001; "+
						"NC Nuova Caledonia, PF Polinesia Francese, PM Saint-Pierre e Miquelon, TF Territori Francesi di Oltremare, WF Wallis e Futuna e YT Mayotte usano FR Francia; "+
						"ES Spagna comprende Isole Canarie, Ceuta e Melilla; PT Portogallo comprende Isole Azzorre e Madeira",
						"IE Irland kan benyttes for konti i GB Storbritannia dersom servicebanken er lokalisert i Nord-Irland og benytter avregningssentralen i Den Irske Republikk; "+
						"GG Guernsey og JE Jersey bruker enten GB Storbritannia eller FR Frankrike avhengig av  avregningssentralen benyttet av servicebanken; "+
						"GF Fransk Guiana, GP Guadeloupe, MQ Martinique og RE Réunion benytter FR Frankrike og dekkes av  EU REGULATIV  2560/2001; "+
						"NC Ny-Caledonia, PF Fransk Polynesia, PM Saint Pierre og Miquelon, TF Franske Sørlige  Territorier, WF Wallis og  Futunaøyene og YT Mayotte benytter FR Frankrike; "+
						"ES Spaina inkluderer Kanariøyene, Ceuta og Melilla; PT Portugal inkluderer Azorene og Madeira");
	document.write(xpltxt[llngg-1]); }
//script end

//-->


