function registra(obj){

    new Ajax.Updater('log',  urlo + '/restajax/?op=reg', {
        onLoading: function(request){
            ajaxload()
        },
        onComplete: function(request){
            ajaxcompleted()
        },
        evalScripts: true,
        parameters: Form.serialize(obj),
        insertion: Insertion.Insert,
        asynchronous: true
    });

}

function ajaxload(){
$('loading').style.display='block';
}


function ajaxcompleted(){
$('loading').style.display='none';
}





function controlpas(obj){
		if($(obj).value!=$('pass').value){
			$('ctrlpass').update('Le password non coincidono');
			return false;
		}
		if($(obj).value=='' || $('pass').value==''){
			$('ctrlpass').update('Inserisci la password');
			return false;
		}
		
		
		
		return true;
}

function psu(obj){
	if (obj.checked) {
		$('psudo').style.display='block';
	} else {
		$('psudo').style.display='none';
	}
	
}




function isCodiceFiscale(obj)
{
 var nTempNum;
 var nAppoNum;
 var i;
 var szTempCodFisc;
 var szLastChar;
 var szValued;
 var szInValued;
 
 szCodFisc = obj.value;
 
 if (szCodFisc.length<16) return false
 if (szCodFisc == "") return false;
 else {
  szCodFisc =szCodFisc.toUpperCase();
  szLastChar = szCodFisc.substr(szCodFisc.length - 1,1);
  szTempCodFisc =szCodFisc.substr(0,szCodFisc.length - 1);
  nTempNum = 0;
  i = 0;
 
  while (true) {
   szValued="B1A0KKPPLLC2QQD3RRE4VVOOSSF5TTG6UUH7MMI8NNJ9WWZZYYXX";
   // I DISPARI
   szInValued=szTempCodFisc.substr(i,1);
   nAppoNum = szValued.search(szInValued);
   nTempNum = nTempNum + (nAppoNum &  0x7FFE) / 2;
   i = i + 1;
   if (i>15)
    break;
   szValued="A0B1C2D3E4F5G6H7I8J9KKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ";
   // I PARI
   szInValued=szTempCodFisc.substr(i,1);
   nAppoNum = szValued.search(szInValued);
   nTempNum =  nTempNum + (nAppoNum &  0x7FFE) / 2;
   i = i + 1;
  }
  nTempNum = nTempNum % 26; //mod
  szValued="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  szValued= szValued.substr(nTempNum, 1);
  if (szValued==szLastChar) return true;
  else return false;
 }
}
 
 function controlla_cf(){
 	 if ((aForm.cod_fisc.value==0) && !isCodiceFiscale(aForm.cod_fisc))
 {
  alert("Codice Fiscale non valido");
  aForm.cod_fisc.focus();
  return false;
 }
 }
 
function trukurl(truk,ref){
if(ref=='') return;
new Ajax.Request('rest/it/truk', {
         parameters: {'tr':truk,'ref':ref}
	});
}








function aprivideo(video,titolo){
var code='<a href="" id="player" style="width:704px;height:500px;">';
 new_dialog(code, 365,0,0,'Premio Terna 03 - '+titolo ,true);
pl=document.getElementById('player');
pl.href= 'http://video.premioterna.it/pt03/artworks/'+ video;
$('contenuto_diag').style.height='510px'; 
 flowplayer("player", "http://www.premioterna.it/pt02/videoplayer/flowplayer.commercial-3.1.0.swf",  { 
    key: '$56476ee4249fec5dec7', 
 	clip: {
	scaling: "fit"
	}
 	});
}



function new_dialog(testoalvolo, larg, alt, apertura, titolo, ov){
    $$('select', 'object', 'embed').each(function(node){
        node.style.visibility = 'hidden'
    });
    
    if (titolo) {
        var titolodiag = titolo;
    }
    else 
        var titolodiag = 'Premio Terna 03';
    
    if (larg > 0) {
        var larg = larg;
    }
    else {
        var larg = 200;
    }
    
    if (alt > 0) {
        var alt = alt + 'px';
    }
    else {
        var alt = 'auto';
    }
    
    var objBody = $$('body')[0];
    arrayPageScroll = document.viewport.getScrollOffsets();
    var page = Array(document.viewport.getWidth(), document.viewport.getHeight())
    var arrayPageSize = Array(page[0] + arrayPageScroll[0], page[1] + arrayPageScroll[1]);
    
    
    if (ov == true) {
        var over = document.createElement('div');
        over.setAttribute('id', 'newover');
        // over.setAttribute('onclick', 'chiudi_newdialog()');
        over.style.display = 'none';
        over.style.width = arrayPageSize[0] + 'px';
        var heightover;
//         if ($$('body')[0].getHeight() > arrayPageSize[1]) {
//             over.style.height = $$('body')[0].getHeight() + 'px';// arrayPageSize[1] + 'px';
//         }
//         else {
            over.style.height = arrayPageSize[1] + 'px';// arrayPageSize[1] + 'px';
//         }
        
        
        objBody.appendChild(over);
        
        new Effect.Appear(over, {
            duration: 0.5,
            from: 0.0,
            to: 0.4
        });
        
    }
    
    
    
    var lightbox = document.createElement('div');
    
    var close = document.createElement('div');
    var lightinner = document.createElement('div');
    var lightinner2 = document.createElement('div');
    var lightinner3 = document.createElement('div');
    
    lightbox.setAttribute('id', 'minidiag');
    lightbox.setAttribute('class', 'lightbox-border');
    lightinner.setAttribute('class', 'lightbox-border-inner')
    lightinner2.setAttribute('class', 'lightbox-border-inner2')
    lightinner3.setAttribute('class', 'lightbox-border-inner3')
    lightinner3.setAttribute('id', 'contenuto_diag')
    
    lightbox.style.display = 'none';
    close.setAttribute('id', 'close');
    // close.setAttribute('class','close-light')
    //    var closew = (2 * larg) - 34;
    //    close.style.left = closew + 'px';
    
    $(lightinner2).update(titolodiag);
    
    objBody.appendChild(lightbox);
    
    
    cancImage = new Image();
    cancImage.src = urlimg + 'cancel.gif';
    pageX = page[0];
    pageY = page[1];//altezza scroll
    pageH = page[1];//alteza finestra browser
    //pageH = page[1];
    xx = larg;
    yy = 300;
    
    a = 2 * xx;
    b = 2 * yy + 60;
    oldy = pageY / 2;
    oldx = pageX / 2;
    
    Nxx = oldx - xx
    
    
    
    var pulsante = document.createElement('img');
    pulsante.setAttribute('id', 'cancel_dialog');
    pulsante.setAttribute('onclick', 'chiudi_newdialog()');
    pulsante.setAttribute('src', cancImage.src);
    pulsante.setAttribute('alt', 'Chiudi');
    pulsante.setAttribute('title', 'Chiudi');
    pulsante.style.cursor = 'pointer';
    close.appendChild(pulsante);
    
    lightbox.appendChild(close);
    lightbox.appendChild(lightinner);
    lightinner.appendChild(lightinner2);
    
   var contenuto = lightinner3
    contenuto.innerHTML = testoalvolo;
    lightinner.appendChild(lightinner3);
    
    
    if (apertura > 0) {
        var apertura = apertura;
    }
    else {
        var apertura = arrayPageScroll[1] + (pageH / 12);
    }
    lightbox.style.top = apertura + 'px';
    lightbox.style.left = Math.round(Nxx) + 'px';
    lightbox.style.width = Math.round(a) + 'px';
    lightbox.style.height = alt;
    
    new Draggable(lightbox);
    
    new Effect.Appear(lightbox, {
        duration: 0.5,
        from: 0.0,
        to: 1
    });
    // solo per form registrazione
    delete xx;
    delete yy;
    
}//fine mostra
function chiudi_newdialog(){
    var scopri = true;
    //     if ($('minicont').innerHTML.include('<!--x-->')) {
    //         scopri = false;
    //     }
    //   
    new Effect.Fade('minidiag')
    
    // $('login').innerHTML = "";
    if ($('newover')) {
        $('newover').remove();
    }
    $('minidiag').remove();
    
    if (scopri) {
        $$('select', 'object', 'embed').each(function(node){
            node.style.visibility = 'visible';
        });
    }
}

