var curr_row=new Array();
var jarr=new Array(1000);
for (i=0; i<1000;i++) 
  {jarr[i] = new Array(2); }
jarr[0][0]=1234;
jarr[0][1]='pippo';

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


/*
function inputchiave(domid,pw) {
//alert ("domid ---> "+domid +'      ----      pw    '+pw);
var chiave=prompt("Esiste gią una domanda inserita per questo bollettino\nDigitare la chiave personale per accedere in modifica",'');	
//while(!chiave)
// chiave = prompt("Esiste gią una domanda inserita per questo bollettino\nDigitare la chiave personale per accedere in modifica",'');	
xajax_validachiave(chiave, domid,pw);
}
*/






function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break; 
}
}
}
return unescape(strReturn);
} 


function stampa_cancella(nomefile){
alert(nomefile);
//window.print(); 
var myObject;
myObject = new ActiveXObject("Scripting.FileSystemObject");
var f = myObject.GetFile(".\\grad.txt");
alert('cancello il file ');
f.Delete();
return true;
}




function stampa_jarr(){
	alert(jarr[0][0]);
	alert(jarr[0][1]);
	return false;
}

function onEnter(){
if(event.keyCode==13)
document.frmPassword.btnEnter.click();
}

function gofirstpagehttp(){
	
var pagina = document.getElementById('initpage').value;
location.href= 'http://appintra.cosmag.it/'+document.getElementById('initpage').value; 
}


function gofirstpage(){
	
var pagina = document.getElementById('initpage').value;
location.href= document.getElementById('initpage').value; 
}



function cpw() {
id = document.getElementById('acode');
var chiave = id.value;
var domid = document.getElementById('domid').value;
var upd = document.getElementById('upd').value;
xajax_checkchiave(chiave, domid) 
//visualizzadiv('bnavanti'); 
return true;
}



function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="' + jsFile + '"></script>'); 
}




function showgrad() {
dist  = document.getElementById('distrecodice');
boll  = document.getElementById('bollettini');
uffg  = document.getElementById('sedipubblicate');
tipo  = document.getElementById('tipograd');
ordi  = document.getElementById('sortradio');
tdom  = document.getElementById('tipodom');
nrecs = document.getElementById('nrecs');
var id_dist = dist.value;
var id_boll = boll.value;
var id_sede = uffg.value;
var id_tipo = tipo.value;
var id_nrecs = nrecs.value;
var id_ordi = ordi.value;
var id_tdom = tdom.value;
//alert(id_dist+'    '+id_boll+'    '+id_sede+'    '+id_tipo+'    '+id_ordi);
xajax_showgrad(id_dist,id_boll,id_sede,id_tipo,id_ordi,id_tdom,id_nrecs) ;
return true;
}


function grad_apply_updates(note,n_item,csmid,domid,pos,id_tipo,stato ) {
//alert ('prima ======     elemento '+n_item+'   csmid    '+csmid+'  domid    '+domid+'   distretto '+id_dist+'  boll  '+id_boll+'  sede   '+id_sede+' tipo grad '+id_tipo+'    stato   '+stato+'   note '+note );
dist    = document.getElementById('distrecodice');
boll    = document.getElementById('bollettini');
uffg    = document.getElementById('sedipubblicate');
//tipo    = document.getElementById('tipograd');
note    = document.getElementById('StatusNote['+n_item+']');
stat    = document.getElementById('status_'+n_item);
var id_dist   = dist.value;
var id_boll   = boll.value;
var id_sede   = uffg.value;
//var id_tipo   = tipo.value;

if (note===null)  {var id_note = '';  } else {var id_note   = note.value; } 
if (stat===null)  {var id_stato=0;  } else {var id_stato = stat.value; } 
//alert ('dopo ========   elemento '+n_item+'   csmid    '+csmid+'  domid    '+domid+'   distretto '+id_dist+'  boll  '+id_boll+'  sede   '+id_sede+' tipo grad '+id_tipo+'    stato   '+id_stato+'   note '+id_note );
xajax_gradstatoupd(id_note,csmid,domid,id_boll,id_tipo,id_sede,pos,id_stato,n_item );
return false;
}



function sortmake()  { 
var idtbgrad;
idtbgrad = document.getElementById('tbgrad');
ts_makeSortable(idtbgrad)
}


function loadgrad() {
dist  = document.getElementById('distrecodice');
boll  = document.getElementById('bollettini');
uffg  = document.getElementById('sedipubblicate');
tipo  = document.getElementById('tipograd');
//ordi  = document.getElementById('sortradio');
var id_dist = dist.value;
var id_boll = boll.value;
var id_sede = uffg.value;
var id_tipo = tipo.value;
var id_ordi = 'G';
xajax_loadgrad(id_dist,id_boll,id_sede,id_tipo,id_ordi) 
tipo  = document.getElementById('agraduatoria');

var agrad = tipo;
alert ('tipo --> '+agrad);
xajax_ordinamento(agrad); 
return true;
}



function campopw() {
id = document.getElementById('acode');
if (id.value == '' )  { alert("campo obbligatorio");  document.getElementById('acode').focus(); return false;}
cpw();
return true;
}

function inputchiave(domid,pw) {
nascondidiv('bnavanti');
visualizzadiv('div_pw');
document.getElementById('acode').focus();


/*
if (cpw(document.getElementById(acode))) {
  nascondidiv('div_pw');
  visualizzadiv('bnavanti');
  var chiave = document.getElementById(acode).value;
  alert ("domid ---> "+domid +'      ----      pw    '+pw+'     chiave     '+chiave);
  xajax_validachiave(chiave, domid,pw);

//var chiave = document.getElementById(acode).value;
//alert ("domid ---> "+domid +'      ----      pw    '+pw+'     =====      '+chiave);
//var chiave=prompt("Esiste gią una domanda inserita per questo bollettino\nDigitare la chiave personale per accedere in modifica",'');	
//while(!chiave)
// chiave = prompt("Esiste gią una domanda inserita per questo bollettino\nDigitare la chiave personale per accedere in modifica",'');	
//xajax_validachiave(chiave, domid,pw);
*/
}


function CodiceFiscaleValido(codice) 
  { 
//    alert ('codice  --->   '+codice.value + '   nome '+codice.name); 
//    var pattern = new RegExp("[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]");
    var pattern = new RegExp("[a-zA-Z]{6}[0-9]{2}[/abcdehlmprstABCDEHLMPRST/][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]");
    if (!pattern.test( codice.value )) 
    { alert("Il formato del Codice Fiscale non č valido"); 
	  document.getElementById(codice.name).focus(); 
	  return false; 
	}	
	else 
	{  return true; }
 };

       
function indirizzoEmailValido(indirizzo) {
 
//var ind = indirizzo.replace(/^\s+|\s+$/g,"");
var ind = indirizzo.trim();
 if (window.RegExp)
  {
var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv  = new RegExp(valido);
   if (!regnv.test(ind) && regv.test(ind))  return true;
return false;
 }
 else 
 {
   if(ind.indexOf("@") >= 0)       return true;
return false;
 }
 };






function impostafocus(id,variabile)
{
   eval(variabile+'='+id);
}
function cambiaindex(oggetto)
{
  oggetto.selectedIndex=0;
  /*for (var i=0; i < oggetto.options.length; i++)
  {
    oggetto.options[i].selected = false;
  }*/
}


function findPos(obj) {
    //ottiene la posizione assoluta di un elemento
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			if (obj.nodeName!="BODY")
			curtop-=obj.scrollTop;
		}
	  }

       return [curleft,curtop];
    }


function titolicurriculum(pulsante) {
       id=pulsante.id;
//       alert( 'id ---->  '+id);	   
       
var arstr=id.split('_');
    sid=arstr.pop();
    sid=arstr.pop();
//alert( 'sid ---->  '+sid);
    if (sid=='titcurr')
       curr_row[1]=id; //titoli professionali

inptext=document.getElementById(id);
       pos=findPos(inptext);
       ileft=pos[0];
       itop =pos[1]; //eliminare +20
       var ssel=document.getElementById("div_titcurr");
//alert( 'ssel ---->  '+ssel);
document.getElementById(sid).style.display='block';
document.getElementById(sid).style.visibility='visible'; //'sedi','comuni'
ssel.style.left=ileft;
ssel.style.top=itop;
//return true;       
    }  


function sediuniversita(pulsante) {
       id=pulsante.id;
//       alert( 'id ---->  '+id);	   
       
	   var arstr=id.split('_');
       sid=arstr.pop();
       sid=arstr.pop();
//alert( 'sid ---->  '+sid);
       if (sid=='universita')
          curr_row[1]=id; //universita
       if (sid=='facolta')
          curr_row[1]=id; //universita
       if (sid=='titolo')
          curr_row[1]=id; //universita
       if (sid=='comunecorti')
         curr_row[4]=id+'_i'; //comuni

       inptext=document.getElementById(id);
       pos=findPos(inptext);
       ileft=pos[0];
       itop =pos[1]; //eliminare +20
       var ssel=document.getElementById("div_"+sid);
//alert( 'ssel ---->  '+ssel);
document.getElementById(sid).style.display='block';
 	   document.getElementById(sid).style.visibility='visible'; //'sedi','comuni'
       ssel.style.left=ileft;
       ssel.style.top=itop;
	   //return true;       
    }  



function visualizzadiv(id)
{
//alert ('id--visualizza---->   '+id);

var div=document.getElementById(id);  
//   alert ('stile prima ---> '+  div.style.display);
if (!(null === div)) {       
   div.style.display='block';     
   div.style.visibility='visible'
}   
//   alert ('stile dopo ---> '+  div.style.display);
}	


function nascondidiv(id)
{
//alert ('id--visualizza---->   '+id);
var div=document.getElementById(id);  
   if (!(null === div))   {
	   
	   div.style.display='none';
  	   div.style.visibility='hidden';
	   
	   }   
}	


function sedicomuni(pulsante) {
       id=pulsante.id;
       var arstr=id.split('_');
       sid=arstr.pop();
       curr_row[1]=id+'_i'; //comuni
       inptext=document.getElementById(id+'_i');
//       alert ('id -->  '+pulsante.id+'   inptext '+inptext+ '    ______     '+inptext.id+ '   sid   '+sid );
       pos=findPos(inptext);
       ileft=pos[0];
       itop =pos[1]; //eliminare +20
 //      alert ('id ----->    '+id+ '    pos   '+ ileft+'    '+itop);
  //     var ssel=document.getElementById('div_comune');
       var ssel=document.getElementById('div_comune');
  //     alert ('ssel in sedicomuni----->    '+ssel );
	   var cc = document.getElementById('comune');
//	   alert ('cc ----->    '+cc );
       cc.style.display='block';
       cc.style.visibility='visible'; 
 //      alert ('ssel in sedicomuni- dopo---->    '+ssel );
       ssel.style.left=ileft;
       ssel.style.top=itop;

 }  



function seleziona(oggetto)
   {
id=1;
var campo_id  = curr_row[id];
//alert ('idcampo --> '+campo_id);
var campo_cod = campo_id.substring(0,campo_id.length-1)+'c';
//alert ('nomecampo --> '+campo_cod);
if (!(typeof curr_row[id]=="undefined")&& (curr_row[id]!=""))  
     {
        xsvalue=oggetto.options[oggetto.selectedIndex].value;
        svalue= xsvalue.split(",");
//alert ('svalue1 '+svalue[0]+'svalue2 '+svalue[1]);
		stext=oggetto.options[oggetto.selectedIndex].innerHTML;
		oggetto.style.display='none';
 	    oggetto.style.visibility='hidden';

      if (id!=3)
        {
          inp=document.getElementById(curr_row[id]);
		  hid=document.getElementById(curr_row[id]+'_hid');
          hid1=document.getElementById(campo_cod+'_hid');		          

          hid.value=svalue[0];
          hid1.value=svalue[1];		  
 		  inp.value=stext;
//alert('curr -->  '+curr_row[id]);
//alert('hid -->  '+hid);
//alert('hid1 -->  '+hid1);		  

}
	    else
	    {

  	      arstr=curr_row[id].split('_');
          sid=arstr.pop();
  	      clickedid=1*arstr.pop();
  	      clickedname=arstr.pop();
	    }
     }
   }


function seleziono(oggetto)
   {
id=1;
var campo_id  = curr_row[id];
//alert ('idcampo --> '+campo_id);
if (!(typeof curr_row[id]=="undefined")&& (curr_row[id]!=""))  
     {
        svalue=oggetto.options[oggetto.selectedIndex].value;
		stext=oggetto.options[oggetto.selectedIndex].innerHTML;
		oggetto.style.display='none';
 	    oggetto.style.visibility='hidden';
   if (id!=3)
        {
          inp=document.getElementById(curr_row[id]);
		  hid=document.getElementById(curr_row[id]+'_hid');
          hid.value=svalue
 		  inp.value=stext;
		}
	    else
	    {
  	      arstr=curr_row[id].split('_');
          sid=arstr.pop();
  	      clickedid=1*arstr.pop();
  	      clickedname=arstr.pop();
	    }
     }
   }


function nasconditutti()
{
   id='iDiv_titolistudio';
   document.getElementById(id).style.display='none';
   id='iDiv_seminari';
   document.getElementById(id).style.display='none';
   id='iDiv_curriculum';
   document.getElementById(id).style.display='none';
   id='iDiv_sedirichieste';
   document.getElementById(id).style.display='none';
   id='iDiv_dichiarazioni';
   document.getElementById(id).style.display='none';
   id='iDiv_pubblicazioni';
   document.getElementById(id).style.display='none';
//   id='Div_titstudio_note';
//   document.getElementById(id).style.display='none';
return true;
}


function attivadiv(oggetto)
{
//alert('attivadiv   '+document.getElementById(oggetto).name);
    nascondidiv();
	nomediv='i'+oggetto.id;
    pos=findPos(oggetto);
//    document.getElementById(nomediv).style.left=pos[0]+16;
    document.getElementById(nomediv).style.left=pos[0];
    document.getElementById(nomediv).style.top=pos[1]+30;
    document.getElementById(nomediv).style.display='block';
    document.getElementById(nomediv).style.visibility='visible';
	return true;
}


function attiva_titstudio_note(oggetto)
{
//alert('attivadiv   '+document.getElementById(oggetto).name);
   zz='div_titstudio_note';
   document.getElementById(zz).style.display='none';

	nomediv='i'+oggetto.id;
    pos=findPos(oggetto);
//    document.getElementById(nomediv).style.left=pos[0]+16;
    document.getElementById(nomediv).style.left=pos[0];
    document.getElementById(nomediv).style.top=pos[1]+30;
    document.getElementById(nomediv).style.display='block';
    document.getElementById(nomediv).style.visibility='visible';
	return true;
}


/*
function nascondidiv()
{
   id='iDiv_titolistudio';
   document.getElementById(id).style.display='none';
   document.getElementById(id).style.visibility='hidden';   
   id='iDiv_seminari';
   document.getElementById(id).style.display='none';
   document.getElementById(id).style.visibility='hidden';   
   id='iDiv_sedirichieste';
   document.getElementById(id).style.display='none';
   document.getElementById(id).style.visibility='hidden';   
   id='iDiv_curriculum';
   document.getElementById(id).style.display='none';
   document.getElementById(id).style.visibility='hidden';   
   id='iDiv_pubblicazioni';
   document.getElementById(id).style.display='none';
   document.getElementById(id).style.visibility='hidden';   
   id='iDiv_dichiarazioni';
   document.getElementById(id).style.display='none';
   document.getElementById(id).style.visibility='hidden';   

return true;
}

*/


function mostra_note_titstudio(n1,n2)   //  ( this, titstudio_note )
	{

var at=document.getElementById(n2);  
nomediv=n1.id;
pos=findPos(n1);
document.getElementById(n2).value = n1.value;
var ssel=document.getElementById("div_titstudio_note");
ssel.style.top=pos[1]+30;     // top
ssel.style.left=pos[0]-240;      // left

//document.getElementById(n2).style.display='block';
//document.getElementById(n2).style.visibility='visible';
return true;

}


function mostra_note_curriculum(n1,n2)   //  ( this, curriculum_note )
{
var at=document.getElementById(n2);  
nomediv=n1.id;
pos=findPos(n1);
document.getElementById(n2).value = n1.value;
var ssel=document.getElementById("div_curriculum_note");
ssel.style.top=pos[1]+30;     // top
ssel.style.left=pos[0]-240;      // left
//document.getElementById(n2).style.display='block';
//document.getElementById(n2).style.visibility='visible';
return true;

}





function ck_recapito(form) {
/*
if ( 
	 ( form.recapito_comune_i.value.trim() == ""      ) || 
	 ( form.recapito_comune_i.value.trim() == "Vuoto" ) ||
	 ( form.recapito_comune_i.value.trim() == "00000" ) 	 
   )   
*/
{
form.recapito_comune_i_hid.value = form.residenza_comune_i_hid.value ;
     form.recapito_comune_i.value     = form.residenza_comune_i.value ;  
     form.viarecapito.value           = form.viaresidenza.value ;  	 
     form.caprecapito.value           = form.capresidenza.value ;  	 
     return true ;
   }	
	
}

function conferma(form) {
if  (form.name == 'formAnag') {
if (confirm ('Attenzione, tornando alla pagina iniziale si perderanno \n tutte le informazioni digitate!! \n Continuare?' ))
    { return true; } else  { return false; }
}
}




function validate(form) {

if (form.name=='showboll')
{ 
//alert("bollettino   "+document.getElementById('mobollid').value);
//alert("domanda "+document.getElementById('tipodomanda').value);

if    ( form.mobollid.value    < 1 ) { alert("Selezionare un bollettino"); form.mobollid.focus() ;	return false; }
if    ( form.tipodomanda.value < 1 ) { alert("Selezionare un tipo domanda"); form.tipodomanda.focus() ;	return false; }  
}



if  (form.name == 'formAnag') 
{

if (form.codfisc.value == "") 
 { alert("Codice Fiscale obbligatorio"); form.codfisc.focus(); 	return false; }
 
if (form.codfisc.value != "") 
 { 
// var pattern = new RegExp("[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]");
   var pattern = new RegExp("[a-zA-Z]{6}[0-9]{2}[/abcdehlmprstABCDEHLMPRST/][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]");
     if (!pattern.test(form.codfisc.value )) 
    { alert("formato Codice Fiscale non valido"); form.codfisc.focus(); return false; }	 
 }

if (form.cognome.value == "") 
{ alert("Cognome obbligatorio"); form.cognome.focus(); return false; }
if (form.nome.value == "") 
 { alert("Nome obbligatorio"); form.nome.focus();  return false; }

if (form.datanascita_i.value == "") 
 { alert("Data nascita obbligatoria"); form.datanascita.focus(); 	return false; }

//if (!ValidaData(form.datanascita.value )) {form.datanascita.focus(); return false; }	 

//alert( ' nascita a --->  '+form.nascita_comune_i.value+ '  - > '+form.nascita_comune_i_hid.value);
if ( form.nascita_comune_i.value == "" )      {form.nascita_comune_i_hid.value = ""; }

if    (!form.nascita_comune_i_hid.value > 0 )  	 
{ alert("Luogo nascita obbligatorio"); form.nascita_comune_i.focus(); 	return false; }

if ( form.residenza_comune_i.value == "" )      {form.residenza_comune_i_hid.value = ""; }
if    (!form.residenza_comune_i_hid.value > 0 )  	 
{ alert("Luogo residenza obbligatorio"); form.residenza_comune_i.focus(); 	return false; }


if (form.capresidenza.value == "") 
 { alert("CAP residenza obbligatoria"); form.capresidenza.focus(); 	return false; }

if (form.capresidenza.value != "") 
 { var pattern = new RegExp("[0-9]{5}");
     if (!pattern.test(form.capresidenza.value )) 
    { alert("CAP valido 5 cifre"); form.capresidenza.focus(); return false; }	 
 }

if (form.viaresidenza.value == "") 
 { alert("Indirizzo residenza obbligatorio"); form.viaresidenza.focus(); return false; }

if ( (form.email.value != "") && (indirizzoEmailValido(form.email.value) == false ))
 { alert("eMail non formalmente corretta"); form.email.focus(); return false; }

if (form.codfisc.value == "") 
 { alert("Codice Fiscale obbligatorio"); form.codfisc.focus(); 	return false; }
 
if (form.codfisc.value != "") 
 { 
// var pattern = new RegExp("[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]");
 var pattern = new RegExp("[a-zA-Z]{6}[0-9]{2}[/abcdehlmprstABCDEHLMPRST/][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]");
     if (!pattern.test(form.codfisc.value )) 
    { alert("formato Codice Fiscale non valido"); form.codfisc.focus(); return false; }	 
 }

if  ((form.codfisc.value !=  "" ) && 
     (form.codfisc.value.toUpperCase() != CalcolaCodiceFiscale(form.cognome.value.toUpperCase(),
                      (form.nome.value.toUpperCase()).trim(),
                      form.sesso.value.toUpperCase(),
                      form.datanascita_i.value,
   		              form.nascita_comune_c_hid.value) ) )
{alert("Codice Fiscale incongruente con i dati anagrafici immessi"); form.codfisc.focus(); 	return false; }

if ( form.recapito_comune_i.value.trim() == "" )           {form.recapito_comune_i_hid.value = ""; }
if ( form.recapito_comune_i.value.trim() == "Vuoto" )      {form.recapito_comune_i_hid.value = ""; }
if    (!form.recapito_comune_i_hid.value > 0 )  	 
{ alert("Luogo recapito obbligatorio"); form.recapito_comune_i.focus(); 	return false; }


}

if  (form.name == 'dom_documentazione') 
{

// -------------------------------------------------
for (var I=1;I<= form.nmaxsedi.value;I++) 
{	
   if    (document.getElementById('sede[1]').value == 0 ) 
    { alert("Inserire almeno una sede con preferenza 1"); document.getElementById('sede['+I+']').focus() ;	return false; }
}

for (var I=1;I< form.nmaxsedi.value;I++) 
{	
   for (var X=I+1;X<= form.nmaxsedi.value;X++) {
      if    
        (  
		 ((document.getElementById('sede['+X+']').value > 0 ) && (document.getElementById('sede['+I+']').value > 0 ))
     	  && (document.getElementById('sede['+X+']').value == document.getElementById('sede['+I+']').value  ) 
		 ) 
           { alert("Scelta duplicata nelle sedi"); document.getElementById('sede['+X+']').focus() ;	return false; }
}
}



// ---------------------------------------------------------
for (var I=1;I<=document.getElementById('hid_curriculum').value ;I++) 
{	
 var aa = 'riga_'+I+'_tabella3_titcurr_i_hid';
  try  {
         var bb = document.getElementById(aa).value; 
         var vd1 = 'riga_'+I+'_tabella3_da_i'; 
         var vd2 = 'riga_'+I+'_tabella3_a_i'; 		 
         d1 =  document.getElementById(vd1).value.trim();
         d2 =  document.getElementById(vd2).value.trim();		 
         if (d2 == "" ) { 
		   xajax_setdatafinale(vd2,document.getElementById('mobollid').value);	
           d2 =  document.getElementById(vd2).value.trim();		 		   
		   return false;	 }
         var v1 = d1.split("/");
		 var v2 = d2.split("/");
		 var dd1 = v1[2]+v1[1]+v1[0];
 		 var dd2 = v2[2]+v2[1]+v2[0];
         if (dd1>dd2) 
		  { alert("Nella sezione CURRICULUM la data iniziale deve essere precedente a quella finale"); 
            return false; 		    	  }
    }	
catch (error)    {  aa=aa; }
finally          {  aa=aa; }
}

// ---------------------------------------------------------
}


if  (form.name == 'getdom') 
{ 
  if    ( form.codfisc.value == '' ) { alert("Inserire il codice fiscale"); form.codfisc.focus() ;	return false; }
  if    ( form.key.value == '' )     { alert("Inserire la chiave di accesso"); form.key.focus() ;	return false; }  
}



return true;
}





function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
return this.obj
}




var consonanti =  "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
var numeri = "0123456789";


function CalcolaCodiceFiscale(Cognome,Nome,Sesso,DataNascita,CodComune)
	{
     var data = new Array();
     data = DataNascita.split("/");
		 GiornoNascita=data[0];
		 MeseNascita= data[1];
		 AnnoNascita=data[2];
     ComuneCalcolato=CodComune;
     rc = CalcolaCognome(Cognome);
 	   rn = CalcolaNome(Nome)
	   rN = CalcolaNascita(GiornoNascita, MeseNascita, AnnoNascita, Sesso);

      var cf = rc+rn+rN+ComuneCalcolato;
      cf += CalcolaK(rc+rn+rN+ComuneCalcolato);
 		  return  cf;
		

}


function id_comune(stringa)
{
 		 var cod = new Array();
		 cod = stringa.split("-");
     return cod[1];
}


function cod_comune(stringa)
{
 		 var cod = new Array();
		 cod = stringa.split("-");
     return cod[0];
}

function CalcolaCognome(Cognome)
{
   var code = "";
   code = GetConsonanti(Cognome);
   if (code.length >= 3)
      code = code.substring(0, 3);
   else
   {
      code += GetVocali(Cognome).substring(0, 3 - code.length)
      if (code.length < 3)
         for (i = code.length; i < 3; i++)
            code += "X";
   }
   return code;
}

function CalcolaNome(Nome)
{
   var code = "";
   cons = GetConsonanti(Nome);
   if (cons.length > 3)
      code = cons.substring(0, 1) + cons.substring(2, 3) + cons.substring(3, 4);
   else if (cons.length == 3)
      code = cons;
   else
   {
      code = cons + GetVocali(Nome).substring(0, 3 - cons.length);
      if (code.length < 3)
         for (i = code.length; i < 3; i++)
            code += "X";
   }
   return code;
}

function GetConsonanti(Stringa)
{
   var cns = "";
   for (i = 0; i < Stringa.length; i++)
      if (consonanti.indexOf(Stringa.substring(i, i + 1)) != -1)
         cns += Stringa.substring(i, i + 1);
   return cns.toUpperCase();
}

function GetVocali(Stringa)
{
   var voc = "";
   for (i = 0; i < Stringa.length; i++)
      if (consonanti.indexOf(Stringa.substring(i, i + 1)) == -1 && Stringa.substring(i, i + 1) != " ")
         voc += Stringa.substring(i, i + 1);
   return voc.toUpperCase();
}

function CalcolaNascita(Giorno, Mese, Anno, Sesso)
{
   var letteramese = "ABCDEHLMPRST"; 
   var code = "";
   code += Anno.substring(2, 4) + letteramese.charAt(Mese-1);
   if (Sesso == "M")
      code += Giorno;
   else
      code += parseInt(40, 10) + parseInt(Giorno, 10);
   return code;
}

function CalcolaComune(Comune)
{
var flag = -1;

   for (i = 0; i < parent.comuni.arrComuni.length; i++)
   {
      if(Comune.toUpperCase() == parent.comuni.arrComuni[i][1])
      {
         flag = i;
         break;
      }
   }
   if (flag < 0)
      return -1;
   else
      return parent.comuni.arrComuni[flag][0];            
}

function CalcolaK(Stringa)
{
   var somma = 0, k;
   var arrPari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var arrDispari = new Array(
      Array(0,1),
      Array(1,0),
      Array(2,5),
      Array(3,7),
      Array(4,9),
      Array(5,13),
      Array(6,15),
      Array(7,17),
      Array(8,19),
      Array(9,21),
      Array("A",1),
      Array("B",0),
      Array("C",5),
      Array("D",7),
      Array("E",9),
      Array("F",13),
      Array("G",15),
      Array("H",17),
      Array("I",19),
      Array("J",21),
      Array("K",2),
      Array("L",4),
      Array("M",18),
      Array("N",20),
      Array("O",11),
      Array("P",3),
      Array("Q",6),
      Array("R",8),
      Array("S",12),
      Array("T",14),
      Array("U",16),
      Array("V",10),
      Array("W",22),
      Array("X",25),
      Array("Y",24),
      Array("Z",23)
   );
   for (i = 0; i < Stringa.length; i += 2)
   {
      for (j = 0; j < arrDispari.length; j++)
      {
         if (Stringa.substring(i, i + 1).toUpperCase() == arrDispari[j][0])
         {
            somma += parseInt(arrDispari[j][1], 10);
            break;
         }
      }
   }
   for (i = 1; i < Stringa.length; i += 2)
   {
      if (isNaN(Stringa.substring(i, i + 1)))
         somma += parseInt(arrPari.indexOf(Stringa.substring(i, i + 1)), 10);
      else
         somma += parseInt(Stringa.substring(i, i + 1), 10);
   }
   k = somma % 26;
   k = arrPari.charAt(k);
   return k;
}



function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

//alert ("elemento obj   "+self.response);
                                if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "table"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}



// ------------------


var SORT_COLUMN_INDEX;

function sortables_init() {
    // Find all tables with class sortable and make them sortable
    if (!document.getElementsByTagName) return;
    tbls = document.getElementsByTagName("table");
    for (ti=0;ti<tbls.length;ti++) {
        thisTbl = tbls[ti];
        if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
            //initTable(thisTbl.id);
            ts_makeSortable(thisTbl);
        }
    }
}

function ts_makeSortable(table) {
    if (table.rows && table.rows.length > 0) {
        var firstRow = table.rows[0];
    }
    if (!firstRow) return;
    
    // We have a first row: assume it's the header, and make its contents clickable links
    for (var i=0;i<firstRow.cells.length;i++) {
        var cell = firstRow.cells[i];
        var txt = ts_getInnerText(cell);
        cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'+txt+'<span class="sortarrow">&nbsp;&nbsp;&nbsp;</span></a>';
    }
}

function ts_getInnerText(el) {
	if (typeof el == "string") return el;
	if (typeof el == "undefined") { return el };
	if (el.innerText) return el.innerText;	//Not needed but it is faster
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += ts_getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
	}
	return str;
}

function ts_resortTable(lnk) {
    // get the span
    var span;
    for (var ci=0;ci<lnk.childNodes.length;ci++) {
        if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
    }
    var spantext = ts_getInnerText(span);
    var td = lnk.parentNode;
    var column = td.cellIndex;
    var table = getParent(td,'TABLE');
    
    // Work out a type for the column
    if (table.rows.length <= 1) return;
    var itm = ts_getInnerText(table.rows[1].cells[column]);
    sortfn = ts_sort_caseinsensitive;
    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
    if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
    SORT_COLUMN_INDEX = column;
    var firstRow = new Array();
    var newRows = new Array();
    for (i=0;i<table.rows[0].length;i++) { firstRow[i] = table.rows[0][i]; }
    for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }

    newRows.sort(sortfn);

    if (span.getAttribute("sortdir") == 'down') {
        ARROW = '&nbsp;&nbsp;&uarr;';
        newRows.reverse();
        span.setAttribute('sortdir','up');
    } else {
        ARROW = '&nbsp;&nbsp;&darr;';
        span.setAttribute('sortdir','down');
    }
    
    // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
    // don't do sortbottom rows
    for (i=0;i<newRows.length;i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
    // do sortbottom rows only
    for (i=0;i<newRows.length;i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
    
    // Delete any other arrows there may be showing
    var allspans = document.getElementsByTagName("span");
    for (var ci=0;ci<allspans.length;ci++) {
        if (allspans[ci].className == 'sortarrow') {
            if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
                allspans[ci].innerHTML = '&nbsp;&nbsp;&nbsp;';
            }
        }
    }
        
    span.innerHTML = ARROW;
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}
function ts_sort_date(a,b) {
    // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa.length == 10) {
        dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
    } else {
        yr = aa.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
    }
    if (bb.length == 10) {
        dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
    } else {
        yr = bb.substr(6,2);
        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
        dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
    }
    if (dt1==dt2) return 0;
    if (dt1<dt2) return -1;
    return 1;
}

function ts_sort_currency(a,b) { 
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
    return parseFloat(aa) - parseFloat(bb);
}

function ts_sort_numeric(a,b) { 
    aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
    if (isNaN(aa)) aa = 0;
    bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); 
    if (isNaN(bb)) bb = 0;
    return aa-bb;
}

function ts_sort_caseinsensitive(a,b) {
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}

function ts_sort_default(a,b) {
    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (aa==bb) return 0;
    if (aa<bb) return -1;
    return 1;
}


function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 





var MD5 = function (string) {

    function RotateLeft(lValue, iShiftBits) {
        return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
    }

    function AddUnsigned(lX,lY) {
        var lX4,lY4,lX8,lY8,lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    }

    function F(x,y,z) { return (x & y) | ((~x) & z); }
    function G(x,y,z) { return (x & z) | (y & (~z)); }
    function H(x,y,z) { return (x ^ y ^ z); }
    function I(x,y,z) { return (y ^ (x | (~z))); }

    function FF(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function GG(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function HH(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function II(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWords_temp1=lMessageLength + 8;
        var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
        var lWordArray=Array(lNumberOfWords-1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount-(lByteCount % 4))/4;
        lBytePosition = (lByteCount % 4)*8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
        lWordArray[lNumberOfWords-2] = lMessageLength<<3;
        lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
        for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
        }
        return WordToHexValue;
    };

    function Utf8Encode(string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    };

    var x=Array();
    var k,AA,BB,CC,DD,a,b,c,d;
    var S11=7, S12=12, S13=17, S14=22;
    var S21=5, S22=9 , S23=14, S24=20;
    var S31=4, S32=11, S33=16, S34=23;
    var S41=6, S42=10, S43=15, S44=21;

    string = Utf8Encode(string);

    x = ConvertToWordArray(string);

    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

    for (k=0;k<x.length;k+=16) {
        AA=a; BB=b; CC=c; DD=d;
        a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
        d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
        c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
        b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
        a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
        d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
        c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
        b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
        a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
        d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
        c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
        b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
        a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
        d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
        c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
        b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
        a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
        d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
        c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
        b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
        a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
        d=GG(d,a,b,c,x[k+10],S22,0x2441453);
        c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
        b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
        a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
        d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
        c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
        b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
        a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
        d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
        c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
        b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
        a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
        d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
        c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
        b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
        a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
        d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
        c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
        b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
        a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
        d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
        c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
        b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
        a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
        d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
        c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
        b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
        a=II(a,b,c,d,x[k+0], S41,0xF4292244);
        d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
        c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
        b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
        a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
        d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
        c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
        b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
        a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
        d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
        c=II(c,d,a,b,x[k+6], S43,0xA3014314);
        b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
        a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
        d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
        c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
        b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
        a=AddUnsigned(a,AA);
        b=AddUnsigned(b,BB);
        c=AddUnsigned(c,CC);
        d=AddUnsigned(d,DD);
    }

    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);

    return temp.toLowerCase();
}


