// Script modificat dupa codul http://www.tbg5-finance.org/?iban.shtml datat 2004-05-06  
// more languages are welcome. please sent your list of country names and explain text to TBG5 administrator. thnx

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");
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","LU","LV","LT","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,  21,  20,  27,  31,  18,  15,  28,  25, 24, 24,  19,  24,  24);
ctynm = new Array ("Andorra","Austria","Belgia","Elvetia","Cipru","Cehia","Germania","Danemarca","Estonia","Spania","Finlanda","Insulele Faroe","Franta","Gibraltar","Marea Britanie","Groelanda",
                "Grecia","Ungaria","Irlanda","Islanda","Italia","Lichtenstein","Luxemburg","Letonia","Lituania","Monaco","Malta","Olanda","Norvegia","Polonia","Portugalia","Romania","Suedia","Slovenia","Slovacia","Tunisia", 
                "Andorra","Austria","Belgium","Switzerland","Cyprus","Czech Republic","Germany","Denmark","Estonia","Spain","Finland","Faroe Islands","France","Gibraltar","Great Britain","Greenland",
                "Greece","Hungary","Ireland","Iceland","Italy","Lichtenstein","Luxemburg","Latvia","Lithuania","Monaco","Malta","Netherlands","Norway","Poland","Portugal","Romania","Sweden","Slovenia","Slovak Republic","Tunisia");
altxt = new Array ("Codul IBAN contine caractere ilegale.","Structura codului IBAN este eronata.","Cifrele de verificare sunt eronate.","Nu se poate verifica lungimea corecta a IBAN-ului deoarece ",
                " nu este cunoscuta(?).","Lungimea IBAN-ului nu este corecta. Lungimea IBAN-ului pt "," este "," caractere.","Codul IBAN este corect.","Codul IBAN nu este corect.",
                "The IBAN contains illegal characters.","The structure of IBAN is wrong.","The check digits of IBAN are wrong.","Can not check correct length of IBAN because ",
                " is currently not respected.","The length of IBAN is wrong. The IBAN of "," needs to be "," characters long.","The IBAN seems to be correct.","The IBAN is incorrect.");
examples = new Array ("AD1200012030200359100100","AT611904300234573201","BE68539007547034","CH9300762011623852957","CY17002001280000001200527600","CZ6508000000192000145399","DE89370400440532013000",
                "DK5000400440116243","EE382200221020145685","ES9121000418450200051332","FI2112345600000785","FO...","FR1420041010050500013M02606","GI75NWBK000000007099453","GB29NWBK60161331926819","GL...",
                "GR1601101250000000012300695","HU42117730161111101800000000","IE29AIBK93115212345678","IS140159260076545510730339","IT60X0542811101000000123456","LI21088100002324013AA",
                "LU280019400644750000","LV80BANK0000435195001","LT121000011101001000","MC...","MT84MALT011000012345MTLCAST001S","NL91ABNA0417164300","NO9386011117947","PL27114020040000300201355387",
                "PT50000201231234567890154","RO49AAAA1B31007593840000","SE3550000000054910000003","SI56191000000123438","SK3112000000198742637541","TN5914207207100707129648");
prefixl = new Array ("Lungime: ","Length: ");
prefixe = new Array ("Exemplu: ","Example: ");

lgc = 2; // we have currently 2 languages
ctcnt = ctynm.length/lgc; // we have currently # countries
atcnt = altxt.length/lgc; // we have currently # alert texts

lngg = 1; // use language 2 by default

function rcty(tnum) { return ctynm[tnum+ctcnt*(lngg-1)]; }
function ralt(tnum) { return altxt[tnum+atcnt*(lngg-1)]; }

function checkiban(iban) {
    ibano = iban; // remember for later use
    illegal = /\W|_/; // contains chars like not(a-zA-Z0-9_) or _ 
    if(illegal.test(iban)) { return false; } // yes, alert and exit
    else { // no, continue
        illegal = /^\D\D\d\d.+/; // first chars are letter letter digit digit
        if(illegal.test(iban) == false) {  return false; } // 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)) {  return false; } // 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
                     return false; 
                    lofi = iban.length; }  // but continue
                if ((iban.length-lofi) != 0) {  return false; } // fits length to country; no, alert 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") { return true; } // and prompt result
                    else {  return false; }}}}}}

// some convenience to list the countries

function rcc(tnum) { return ilbc[tnum]; }
function rcn(tnum) { return rcty(tnum); } 
function rcl(tnum) { return prefixl[lngg-1]+ilbc[ctcnt+tnum]; } 
function rce(tnum) { return prefixe[lngg-1]+examples[tnum]; } 

function listcountries(columni,llngg) {
    lngg = llngg;  // use language 2
    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);
    for (i = 0; i < numberofrows; i++) {
        document.write("<tr class=\"tbg5crl\">");
        for (j = 0; j < columni; j++) {
            if ((i*columni+j)<ctcnt) {
                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, daß die servisierede 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; 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; ES Spain includes Canary Islands, Ceuta and Melilla; "+
                        "PT Portugal includes Azores and Madeira");
    document.write(xpltxt[llngg-1]); }


function isstr(s) { 
  var valNumb='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  var nrCifre=0;
  for (var i=0; i < s.length; i++) {
    var c=s.charAt(i);
    if( valNumb.indexOf(c) != -1 ) nrCifre++;
  }
  if( nrCifre< 3 ) return false;
  return true;
}

function isnum(s) { 
  var valNumb='0123456789';
  var nrCifre=0;
  for (var i=0; i < s.length; i++) {
    var c=s.charAt(i);
    if( valNumb.indexOf(c) != -1 ) { 
        nrCifre++;
    } else {
        return false;
    }
  }
  if( nrCifre< 3 ) return false;
  return true;
}

function isemail(s) {
  if (window.RegExp) {
    var reg1str = "(@.*@)(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(s) && reg2.test(s)) {
     return true;
    }
    return false;
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    return false;
  }
}

function isCNP(s) {
    if(s.length!=13 || !isnum(s)) {
        return false;
    }
    c = (s.charAt(0)*2+s.charAt(1)*7+s.charAt(2)*9+s.charAt(3)*1+s.charAt(4)*4+s.charAt(5)*6+s.charAt(6)*3+s.charAt(7)*5+s.charAt(8)*8+s.charAt(9)*2+s.charAt(10)*7+s.charAt(11)*9) % 11;
    if ((c==10 && s.charAt(12)==1) || (c<10 && s.charAt(12)==c)) {
        return true;
    } else {
        return false;
    }
}

function isCIF(s) {
    if(s.length>10 || !isnum(s)) {
        return false;
    }
    c = (s.charAt(0)*2+s.charAt(1)*3+s.charAt(2)*5+s.charAt(3)*7+s.charAt(4)*1+s.charAt(5)*2+s.charAt(6)*3+s.charAt(7)*5+s.charAt(8)*7) % 11;
    if ((c==10 && s.charAt(9)==0) || (c<10 && s.charAt(9)==c)) {
        return true;
    } else {
        return false;
    }
}

function restrictUpperCharsNums(obj) {
    val='';
    if(obj.value!=obj.value.toUpperCase(obj.value)) obj.value=obj.value.toUpperCase(obj.value);
    for(i=0;i<=obj.value.length;i++) {
        char = obj.value.charCodeAt(i);
        if((char>=65 && char <=90) || (char>=97 && char<=122) || (char>=48 && char<=57)) {
            val+=obj.value.substr(i,1);
        }
    }
    if(obj.value!=val) obj.value=val;
}

function restrictDomain(obj) {
    val='';
    if(obj.value!=obj.value.toLowerCase(obj.value)) obj.value=obj.value.toLowerCase(obj.value);
    for(i=0;i<=obj.value.length;i++) {
        char = obj.value.charCodeAt(i);
        if((char>=65 && char <=90) || (char>=97 && char<=122) || (char>=48 && char<=57) || char==45 || char==46) {
            val+=obj.value.substr(i,1);
        }
    }
    if(obj.value!=val) obj.value=val;
}

function restrictNums(obj) {
    val='';
    for(i=0;i<=obj.value.length;i++) {
        char = obj.value.charCodeAt(i);
        if(char>=48 && char<=57) {
            val+=obj.value.substr(i,1);
        }
    }
    if(obj.value!=val) obj.value=val;
}

function restrictPhone(obj) {
    val='';
    for(i=0;i<=obj.value.length;i++) {
        char = obj.value.charCodeAt(i);
        if(char>=48 && char<=57 || char==43 || char==45 || char==46) {
            val+=obj.value.substr(i,1);
        }
    }
    if(obj.value!=val) obj.value=val;
}

function updatePhone(obj) {
	if(document.getElementById('country').options[document.getElementById('country').selectedIndex].value=='RO') {
		if(obj.value.length<7)
			return;
/*		obj.value = obj.value.trim(); */
		if(obj.value.substr(0,3) == '+40') {
		} else if(obj.value.substr(0,3) == '004')
			obj.value = '+40'+obj.value.substr(3,99);
		else if(obj.value.substr(0,2) == '07')
			obj.value = '+40'+obj.value.substr(1,99);
		else if(obj.value.substr(0,1) == '0')
			obj.value = '+40'+obj.value.substr(1,99);
		else
			obj.value = '+40'+obj.value;
	} 
}

function changeCountry(obj) {
	if(document.getElementById('country').options[document.getElementById('country').selectedIndex].value=='RO') {
		document.getElementById('state').style.display = "";
		document.getElementById('state_nonro').style.display = "none";
	} else {
		document.getElementById('state').style.display = "none";
		document.getElementById('state_nonro').style.display = "";
	}
}

function changeRole() {
	var role = 'pf';
	if(document.getElementById("rol1") != null)
		if(document.getElementById("rol1").checked)
			role = 'pj';
    if(role=='pj' || document.frm1.rol.value=='pj') {
        document.getElementById("pj1").style.display = "";
        document.getElementById("pj2").style.display = "";
        document.getElementById("pj3").style.display = "";
        document.getElementById("pj4").style.display = "";
        document.getElementById("pj5").style.display = "";
        document.getElementById("pj6").style.display = "";
        document.getElementById("pj7").style.display = "";
        document.getElementById("pf1").style.display = "none";
    } else {
        document.getElementById("pj1").style.display = "none";
        document.getElementById("pj2").style.display = "none";
        document.getElementById("pj3").style.display = "none";
        document.getElementById("pj4").style.display = "none";
        document.getElementById("pj5").style.display = "none";
        document.getElementById("pj6").style.display = "none";
        document.getElementById("pj7").style.display = "none";
        document.getElementById("pf1").style.display = "";
    }
}

function checkPass() {
				var pass1 = document.getElementById('pass');
				var pass2 = document.getElementById('pass2');

				if(pass1.value!=pass2.value) {
					pass1.style.backgroundColor='#EEAAAA'; 
					pass2.style.backgroundColor='#EEAAAA'; 
				} else if(pass1.value.length<=4) {
					pass1.style.backgroundColor='#EEEEAA'; 
					pass2.style.backgroundColor='#EEEEAA'; 
				} else {
					pass1.style.backgroundColor='#AAEEAA';
					pass2.style.backgroundColor='#AAEEAA';
				}
}
