function  change_number(way) {
    //check if we should increment or decrement
    if (way == "inc") {
        //two plus signs will increment our variable by one
        number++;
    } else if (way == "dec") {
        //two minus signs will decrement our variable by one
        number--;
    }
}
function popup(str,winName,larg,alt){
	finestra=window.open(str,winName,"width=" + larg + ", height="+alt+", left=" + ((screen.width-larg)/2) + ",top="+((screen.height-alt)/2)+", scrollbars, resizable" );
	finestra.focus();
}
function moveOver(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	if (tbox.options.length > 0 && tbox.options[0].value == 'temp')
	{
	  tbox.options.length = 0;
	}
	for (i = 0; i < tbox.options.length; i++) {
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < 1; i++) {
		arrLookup[fbox.value] = fbox.value;
		if (fbox.value != "") {
			arrTbox[tLength] = fbox.value;
			tLength++;
		}else {
			arrFbox[fLength] = fbox.value;
			fLength++;
	   }
	}
	arrFbox.sort();
	arrTbox.sort();
	fbox.value = '';
	tbox.length = 0;
	var c;
	for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for(c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	}
}
function move(fbox, tbox) {
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;
	if (tbox.options.length > 0 && tbox.options[0].value == 'temp')
	{
	  tbox.options.length = 0;
	}
	if (fbox.options.length > 0 && fbox.options[0].value == 'temp')
	{
	  fbox.options.length = 0;
	}
	for (i = 0; i < tbox.options.length; i++) {
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	for(i = 0; i < fbox.options.length; i++) {
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != "") {
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
		}else {
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
	   }
	}
	arrFbox.sort();
	arrTbox.sort();
	fbox.length = 0;
	tbox.length = 0;
	var c;
	for(c = 0; c < arrFbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for(c = 0; c < arrTbox.length; c++) {
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
	}
}
function removeMe(rbox) {
var boxLength = rbox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (rbox.options[i].selected) {
arrSelected[count] = rbox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (rbox.options[i].value == arrSelected[x]) {
rbox.options[i] = null;
   }
}
boxLength = rbox.length;
   }
}
function selectAll(selectBox,selectAll) {
    // have we been passed an ID
    if (typeof selectBox == "string") {
        selectBox = document.getElementById(selectBox);
    }

    // is the select box a multiple select box?
    if (selectBox.type == "select-multiple") {
        for (var i = 0; i < selectBox.options.length; i++) {
            selectBox.options[i].selected = selectAll;
        }
    }
}
function chk_cin(modulo)
{
 cc=modulo.cabi.value + modulo.ccab.value;
 cc = cc + modulo.ccor.value;
 aa="A0B1C2D3E4F5G6H7I8J9K#L#M#N#O#P#Q#R#S#T#U#V#W#X#Y#Z#-#.# #";
 bb="B1A0K#P#L#C2Q#D3R#E4V#O#S#F5T#G6U#H7M#I8N#J9W#Z#Y#X# #-#.#";
 dd=0;
 iban2="";
 cifre="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

 for (var k=1; k<22; k+=2)
     {
       dd = dd + Math.floor(aa.indexOf(cc.charAt(k))/2);
     }
 for (var k=0; k<22; k+=2)
     {
       dd=dd+Math.floor(bb.indexOf(cc.charAt(k))/2);
     }

 dd=dd-(Math.floor(dd/26)*26);

 cin = aa.charAt(dd*2);

 cc1 = cin+cc+"IT"+"00";
 for (var iban1=0;iban1<cc1.length;iban1++)
     {
       iban2+=cifre.indexOf(cc1.charAt(iban1));
     }
divisore=97;
div1=""
for (var ciclo1 = 0; ciclo1 < iban2.length; ciclo1++)
    {
      div1=div1+iban2.charAt(ciclo1);
      if (div1<divisore) continue;
      else 
         {
           div1=div1%divisore;
         }
    }

iban2=98 - div1;
iban2="0"+iban2;
iban2=iban2.charAt(iban2.length-2)+iban2.charAt(iban2.length-1);
iban = "IT"+iban2+cin+cc;
iban3 = iban.substr(0,4) + " " + iban.substr(4,4) + " ";
iban3 = iban3 + iban.substr(8,4) + " " + iban.substr(12,4) + " ";
iban3 = iban3 + iban.substr(16,4) + " " + iban.substr(20,4) + " ";
iban3 = iban3 + iban.substr(24,4) + " " + iban.substr(28,4) + " ";
iban3 = iban3 + iban.substr(31,3);
/*document.forms['output'].dcin.value = "CIN:";
document.forms['output'].cin.value = cin;
document.forms['output'].diban.value = "IBAN:";*/
modulo.IBAN.value = iban3;
}

function chk_cabi(modulo)
{
 modulo.cabi.value=modulo.cabi.value.toUpperCase();
 if (modulo.cabi.value.length!=5 )
    {
      alert("Attenzione il codice ABI deve essere di 5 caratteri" );
    }
}

function chk_ccab(modulo)
{
  modulo.ccab.value=modulo.ccab.value.toUpperCase();
  if (modulo.ccab.value.length!=5 )
     {
      alert("Attenzione il codice CAB deve essere di 5 caratteri" );
     }
}

function chk_all(modulo)
{
  chk_cabi(modulo);
  chk_ccab(modulo);
  modulo.ccor.value=modulo.ccor.value.toUpperCase();
  lunghezza=modulo.ccor.value.length;
  if (modulo.ccor.value.length<12 )
     {
       for(var i=1;i<(13-lunghezza);i++)
          {
            modulo.ccor.value="0"+modulo.ccor.value;
          }
     }
  if (modulo.ccor.value.length!=12 )
     {
       alert("ATTENZIONE - Il numero di C/C deve essere di 12 caratteri" ); 
     }
  chk_cin(modulo);
}
function show_hide(div){
	var element = document.getElementById(div);
	var status = element.style;
	if(status.display == 'block')
		status.display = 'none';
	else
		status.display = 'block';
}
