function me(obj) {return document.getElementById(obj)};
function me2(obj){return document.getElementsByName(obj)};

function PageLoad(page,sub,form){
    //alert(page+' - '+ form +' - '+ sub);
    //return
    if (page==20){
        window.location.href='index.asp?page_id=' + page + '&form_id='+form +'&sub_id=' + sub + '&collection=3';
    }else{
        window.location.href='index.asp?page_id=' + page + '&form_id='+form +'&sub_id=' + sub + '&collection=' + me('collection').value;
    }
    //document.form_main.submit();
}
function SetValue(value1){
    me('page_id').value = value1;
    document.frm_main.submit();
}
    
function GoToPage(value1){
    find = me('find').value;
    window.location.href='index.php?page_id=' + value1 +'&find='+find;
}
function GoToPageI(value1,page){
    find = me('find').value;
    window.location.href='index.php?page_id=' + value1 +'&find='+find+'&page='+page;
}


function GetPersona(persona_id,item_id,page){
    //alert(persona_id + "---" +item_id+ "---" +page);
    me('persona_id').value  = persona_id;
    me('item_id').value     = item_id;
    //page = me('page_id').value;
    SetValue(page);
}

function DeleteItem(item_id,page){
    if(confirm("Attenzione!\n\nCancellare l'item selezionato?\n")){
        me('item_id').value     = item_id;
        //page = me('page_id').value;
        SetValue(page);
    }else{
        return
    }
}

function ConfermaOrdine(value1){
    if(confirm("Attenzione!\n\nPrima di confermare l\'ordine prendere visione del biglietto da visita utilizzando il pulsante Preview (P).\n\nConfermando l\'ordine si assume un impegno vincolante con il fornitore per la stampa dei biglietti da visita.\nTerminata la procedura di conferma riceverai una E-mail con i dettagli dell'ordine.\n")){
        //window.location.href='index.php?page_id=' + value1;
        //document.frm_main.submit();
        SetValue(value1);
    }else{
        return
    }
}

/* funzione di controllo del form di ordine */
function FormControl(valore){
 if (me('nome').value == '') { alert("Per favore inserisci il tuo nome");   me('nome').focus();   return false; } if (me('cognome').value == '') { alert("Per favore inserisci il tuo cognome");   me('cognome').focus();   return false; }
  if (me('email').value == '') { alert("Per favore immetti il tuo indirizzo email");   me('email').focus();   return false; }if ((me('email').value.indexOf('@') == -1)||(me('email').value.indexOf('.') == -1)||(me('email').value.indexOf(' ') != -1)){alert("Per favore inserisci un indirizzo email corretto!");me('email').focus();return false;} 
 if (me('prefisso').value == '') { alert("Per favore inserisci il prefisso del recapito telefonico");   me('prefisso').focus();   return false; }
  if (me('telefono').value == '') { alert("Per favore inserisci il recapito telefonico");   me('telefono').focus();   return false; }
 
 if (me('prefisso_fax').value == '') { alert("Per favore inserisci il prefisso del numero di fax");   me('prefisso_fax').focus();   return false; }
 
 if (me('fax').value == '') { alert("Per favore inserisci il tuo numero di fax");   me('fax').focus();   return false; }
 
 if (me('carica').value == '') { alert("Per favore inserisci almeno una carica");   me('carica').focus();   return false; }
 
 if (me('indirizzo').value == 0 ) { alert("Per favore seleziona un Indirizzo");   me('indirizzo').focus();   return false; }
 
 if (me('tipo_stampa').value == 0) { alert("Per favore seleziona la tipologia della stampa");   me('tipo_stampa').focus();   return false; }
 
 if (me('tipo_biglietto').value == 0) { alert("Per favore seleziona la tipologia del biglietto");   me('tipo_biglietto').focus();   return false; }
 
 if (me('quantita').value == 0) { alert("Per favore inserire la quanità deisderata");   me('quantita').focus();   return false; }
 
 if (me('centro_di_costo').value == '') { alert("Per favore inserisci il centro di costo");   me('centro_di_costo').focus();   return false; }
 
 if (me('reparto').value == '') { alert("Per favore inserisci il reparto");   me('reparto').focus();   return false; }
 //ShowUpload();
 SetValue(valore);}

function CollectionLoad(page,sub){
    var n;
    n = me('collection').value;
    switch(n){
        case '1':
            window.location.href='index.asp?page_id=1&form_id=&sub_id=1&collection='+ n;
            break;    
        case '2':
            window.location.href='index.asp?page_id=30&form_id=&sub_id=1&collection='+ n;
            break;
        case '3':
            window.location.href='index.asp?page_id=20&form_id=&sub_id=&collection='+ n;
            break;
        default:
            /*code to be executed if n is
            different from case 1 and 2*/
    }
/*    return;
    me('page_id').value = page;
    me('sub_id').value = sub;
    document.form_main.submit();*/
}

function Move(ordine_visualizzazione,ordine_visualizzazione_destinazione,sub_id,language_id){
    window.location.href = 'ScambiaOrdineVisualizzazione.inc.asp?source='+ordine_visualizzazione+'&destination='+ordine_visualizzazione_destinazione+'&sub_id='+sub_id+'&lang='+language_id
}

function ModificaOrdinamento(page_id,sub_id,form_id){
    for (i=0; i<= me2("ordinamento_id").length; i++){
        if(true == me2("ordinamento_id")[i].checked ){
            window.location.href='index.asp?page_id='+page_id+'&sub_id='+ sub_id +'&form_id='+ form_id + '&lang='+ me2("ordinamento_id")[i].value;
            return;
        }
    }
}
function CancellaOrdinamento(tipo_team_id){
    if(confirm("Attention!\neDo you want to erase the selected ordination.\n")){
        for (i=0; i<= me2("ordinamento_id").length; i++){
            if(true == me2("ordinamento_id")[i].checked ){
                window.location.href='index.asp?page_id=16&form_id=2&lang=' + me2("ordinamento_id")[i].value+'&team='+tipo_team_id;
                return;
            }
        }
    }else{
        return
    }
}


function VideoLoad(page){
    window.location.href='index.asp?page_id='+ page +'&form_id=&sub_id='+ me('tipo_video').value;
}

function Download(page){
    window.location.href='index.asp?page_id='+ page +'&form_id=&sub_id='+ me('tipo_download').value;
}
//function PageLoad(page,form){
    //alert(page+' - '+ form);
    //return
  //  window.location.href='index.asp?page_id=' + page + '&form_id='+form;
    //document.form_main.submit();
//}

function LoadFormVariant(modello_id){
    window.location.href='index.asp?page_id=10&form_id=1&id=' + modello_id;
}

function LoadFormGoggleVariant(goggle_id){
    window.location.href='index.asp?page_id=33&form_id=1&collection=2&id=' + goggle_id;
}

function Load(page_id,form_id,sub_id,id,collection){
    window.location.href='index.asp?page_id='+page_id+'&form_id='+form_id+'&sub_id='+sub_id+'&id=' + id;
}

function LoadFormBiography(page_id,form_id,sub_id,atleta_id,bio_id){
    window.location.href='index.asp?page_id='+page_id+'&form_id='+form_id+'&sub_id='+sub_id+'&bio='+bio_id+'&id=' + atleta_id;
}

function ShowUpload(){
    var altezza = window.screen.height / 2;
    var larghezza = window.screen.width / 4;
    //alert(altezza + ' -- ' + larghezza)
    
    document.getElementById('azz').style.left=  altezza  + 'px';
    document.getElementById('azz').style.top=  larghezza+ 'px';
    if (document.layers)
	{
		vista = (document.layers.azz.visibility == 'hide') ? 'show' : 'hide'
		document.layers.azz.visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all.azz.style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all.azz.style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById('azz').style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById('azz').style.visibility = vista;
	}
    document.frm_main.submit();
}



function UploadFile(){
    var altezza = window.screen.height / 2;
    var larghezza = window.screen.width / 4;
    //alert(altezza + ' -- ' + larghezza)
    
    document.getElementById('azz').style.left=  altezza  + 'px';
    document.getElementById('azz').style.top=  larghezza+ 'px';
    if (document.layers)
	{
		vista = (document.layers.azz.visibility == 'hide') ? 'show' : 'hide'
		document.layers.azz.visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all.azz.style.visibility == 'hidden') ? 'visible'	: 'hidden';
		document.all.azz.style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById('azz').style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById('azz').style.visibility = vista;
	}
    
/*
    if (document.layers)
	{
		current = (document.layers.azz.display == 'none') ? 'block' : 'none';
		document.layers.azz.display = current;
	}
	else if (document.all)
	{
		current = (document.all.azz.style.display == 'none') ? 'block' : 'none';
		document.all.azz.style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById('azz').style.display == 'none') ? 'block' : 'none';
		document.getElementById('azz').style.display = vista;
	}
    //vista = (document.getElementById('azz').style.visibility == 'hidden') ? 'visible' : 'hidden';
	
	//document.getElementById('azz').style.visibility = vista;
*/

    if(me("url_image").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }
    if(me("url_image_swf").value!=''){
        me("swf").value = 1;
    }else{
        me("swf").value = 0;
    }
    document.form_main.submit();
}

function UploadGoggle(){
    //if(me("descrizione").value) 
    if(me("url_image").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }
    if(me("url_image_swf").value!=''){
        me("swf").value = 1;
    }else{
        me("swf").value = 0;
    }
    loopSelected();
}

function UploadAtleta(){
    //if(me("descrizione").value) 
    if(me("image_atleta").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }
    if(me("icon_atleta").value!=''){
        me("swf").value = 1;
    }else{
        me("swf").value = 0;
    }
    ShowUpload();
}

function UploadAtletaNew(){
    //if(me("descrizione").value) 
    if(me("image_atleta").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }
    if(me("icon_atleta").value!=''){
        me("swf").value = 1;
    }else{
        me("swf").value = 0;
    }
    if(me("portrait_atleta").value!=''){
        me("portrait").value = 1;
    }else{
        me("portrait").value = 0;
    }
    ShowUpload();
}

function ModificaAtleta(sub_id){
    for (i=0; i<= me2("atleta_id").length; i++){
        if(true == me2("atleta_id")[i].checked ){
            window.location.href='index.asp?page_id=3&sub_id='+ sub_id +'&form_id=3&id=' + me2("atleta_id")[i].value;
            return;
        }
    }
}

function ModificaContentHome(){
    for (i=0; i<= me2("home").length; i++){
        if(true == me2("home")[i].checked ){
            window.location.href='index.asp?page_id=2&form_id=3&id=' + me2("home")[i].value;
            return;
        }
    }
}

function UploadVideo(){
    var extensionFile = new RegExp(".(FLV|flv)$");
    if(me("descrizione").value=='' || me("video").value=='' || me("icon_video").value==''){
        alert("Required fields:\n\nTitle\nVideo\nThunbnail Video\n\n");
        return;
    }
    if (!IsSupportedFile('.flv',me("video").value)){
        alert("Attention! Video file not supported.\n\nFiles supported: flv.\n\n");
        return;
    }
    if(me("video").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }
    if(me("icon_video").value!=''){
        me("swf").value = 1;
    }else{
        me("swf").value = 0;
    }
    ShowUpload();
}

function UploadZipFile(){
    if (!IsSupportedFile('.zip',me("download1").value)){
        alert("Attention! File not supported.\n\nFiles supported: zip.\n\n");
        return;
    }/*
    if(me("download1").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }*/
    ShowUpload();
}

function UploadWallpapers(){
    var image='';
    if((me('download1').value!='' || me('download2').value!='' || me('download3').value!='') && me('icon_download').value==''){
        alert("Required fields:\n\nTitle\nThunbnail Wallpapers\n");
        return;
    }
    if(me('descrizione').value==''){
        alert("Required fields:\n\nTitle\nThunbnail Wallpapers\n");
        return;
    }
    if(me('icon_download').value!=''){
        image = image + '0 ';
    }
    if(me('download1').value!=''){
        image = image + '1 ';
    }
    if(me('download2').value!=''){
        image = image + '2 ';
    }
    if(me('download3').value!=''){
        image = image + '3 ';
    }
    me('image').value = image;
    ShowUpload()
}

function UpdateWallpapers(){
    var image='';
    if(me('icon_download').value!=''){
        image = image + '0 ';
    }
    if(me('download1').value!=''){
        image = image + '1 ';
    }
    if(me('download2').value!=''){
        image = image + '2 ';
    }
    if(me('download3').value!=''){
        image = image + '3 ';
    }
    me('image').value = image;
    ShowUpload()
}

function UpdateWallpapers(){
    var image='';
    if(me('icon_download').value!=''){
        image = image + '0 ';
    }
    if(me('download1').value!=''){
        image = image + '1 ';
    }
    if(me('download2').value!=''){
        image = image + '2 ';
    }
    if(me('download3').value!=''){
        image = image + '3 ';
    }
    me('image').value = image;
    ShowUpload()
}

function Riordina(ordine_visualizzazione_old,atleta_id,tipo_team_id,language_id,new_order){
    window.location.href='Riordina.inc.asp?page_id=16&sub_id='+ tipo_team_id +'&form_id=1&id=' + atleta_id + '&old_order='+ordine_visualizzazione_old+'&new_order='+ new_order + '&lang='+ language_id;
}

function UpdateVideo(){
    if(me("descrizione").value==''){
        alert("Required fields:\n\nTitle\n\n");
        return;
    }
    if (me("video").value!=''){
        if (!IsSupportedFile('.flv',me("video").value)){
            alert("Attention! Video file not supported.\n\nFiles supported: flv.\n\n");
            return;
        }
    }
    if(me("video").value!=''){
        me("image").value = 1;
    }else{
        me("image").value = 0;
    }
    if(me("icon_video").value!=''){
        me("swf").value = 1;
    }else{
        me("swf").value = 0;
    }
    ShowUpload();
}

function IsSupportedFile(file_type,value){
    var regExp=new RegExp(file_type);
    if (!regExp.test(value)){
        //alert("Attention! File not supported.\n\n")
        return 0;
    }else{
        return 1;
    }
}

function NotNewVariant(){
    me2("nuovo_modello")[0].checked = true ;
    alert('If this a new Model you can not select the NEW flag.');
    return;
}

function TestCancellaModello(){
    if(confirm("Attention!\nErasing the model you will erase any variants.\n")){
        for (i=0; i<= me2("modello").length; i++){
            if(true == me2("modello")[i].checked ){
                window.location.href='index.asp?page_id=1&form_id=3&id=' + me2("modello")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function ModificaVariante(variante_id,modello_id){
    window.location.href='index.asp?page_id=10&sub_id=1&form_id=2&id=' + modello_id + '&var=' + variante_id;
}

function ModificaVarianteGoggle(variante_id,modello_id){
    window.location.href='index.asp?page_id=33&sub_id=1&form_id=2&id=' + modello_id + '&var=' + variante_id;
}

function DeleteVariante(variante_id,modello_id){
    if(confirm("Attention!\nDo you want to erase the selected variant?.\n")){
        window.location.href='DeleteVariante.inc.asp?id=' + modello_id + '&var='+variante_id;
    }else{
        return
    }
}

function DeleteVarianteGoggle(variante_id,modello_id){
    if(confirm("Attention!\nDo you want to erase the selected variant?.\n")){
        window.location.href='DeleteGoggleVariante.inc.asp?id=' + modello_id + '&var='+variante_id;
    }else{
        return
    }
}

function ModificaModello(){
    for (i=0; i<= me2("modello").length; i++){
        if(true == me2("modello")[i].checked ){
            window.location.href='index.asp?page_id=1&form_id=2&id=' + me2("modello")[i].value;
            return;
        }
    }
}
function ModificaColoreLente(){
    for (i=0; i<= me2("colore_lente").length; i++){
        if(true == me2("colore_lente")[i].checked ){
            window.location.href='index.asp?page_id=11&sub_id=2&form_id=3&id=' + me2("colore_lente")[i].value;
            return;
        }
    }
}
function ModificaColoreLenteGoggle(){
    for (i=0; i<= me2("colore_lente").length; i++){
        if(true == me2("colore_lente")[i].checked ){
            window.location.href='index.asp?page_id=31&sub_id=2&form_id=3&id=' + me2("colore_lente")[i].value +'&collection='+me('collection').value;
            return;
        }
    }
}
function TestCancellaLente(){
    if(confirm("Attention!\n to erase the lens type: the lens type should not be associated to any model or variant.\n\n")){
        for (i=0; i<= me2("lente").length; i++){
            if(true == me2("lente")[i].checked ){
                window.location.href='index.asp?page_id=2&form_id=2&id=' + me2("lente")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function CancellaAtleta(sub_id){
    if(confirm("Attention!\nDo you want to erase this Athlete?\n\n")){
        for (i=0; i<= me2("atleta_id").length; i++){
            if(true == me2("atleta_id")[i].checked ){
                window.location.href='index.asp?page_id=3&form_id=2&sub_id='+ sub_id +'&id=' + me2("atleta_id")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaTechnology(){
    if(confirm("Attention!\nto erase the technology: the technology should not be associated to any variant.\n\n")){
        for (i=0; i<= me2("technology").length; i++){
            if(true == me2("technology")[i].checked ){
                window.location.href='index.asp?page_id=15&sub_id=6&form_id=2&id=' + me2("technology")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaHelmet(){
    if(confirm("Attention!\nDo you want to erase the selected helmet?\n\n")){
        for (i=0; i<= me2("helmet").length; i++){
            if(true == me2("helmet")[i].checked ){
                window.location.href='index.asp?page_id=20&form_id=2&collection=3&id=' + me2("helmet")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaGoggle(){
    if(confirm("Attention!\nerasing the model you will erase any variants\n\n")){
        for (i=0; i<= me2("goggle").length; i++){
            if(true == me2("goggle")[i].checked ){
                window.location.href='index.asp?page_id=30&form_id=2&collection=2&id=' + me2("goggle")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function ModificaTechnology(){
    for (i=0; i<= me2("technology").length; i++){
        if(true == me2("technology")[i].checked ){
            window.location.href='index.asp?page_id=15&sub_id=6&form_id=3&id=' + me2("technology")[i].value;
            return;
        }
    }
}

function ModificaHelmet(){
    for (i=0; i<= me2("helmet").length; i++){
        if(true == me2("helmet")[i].checked ){
            window.location.href='index.asp?page_id=20&collection=3&form_id=3&id=' + me2("helmet")[i].value;
            return;
        }
    }
}

function ModificaGoggle(){
    for (i=0; i<= me2("goggle").length; i++){
        if(true == me2("goggle")[i].checked ){
            window.location.href='index.asp?page_id=30&collection=2&form_id=3&id=' + me2("goggle")[i].value;
            return;
        }
    }
}

function TestCancellaFiltro(){
    if(confirm("Attention!\n erasing the filter, you will erase any reference to the lens technology.\n\n")){
        for (i=0; i<= me2("filtro").length; i++){
            if(true == me2("filtro")[i].checked ){
                window.location.href='index.asp?page_id=3&form_id=2&id=' + me2("filtro")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function CancellaLanguage(){
    if(confirm("Attention!\nDo you want to erase this language?\n\n")){
        for (i=0; i<= me2("materiale").length; i++){
            if(true == me2("materiale")[i].checked ){
                window.location.href='index.asp?page_id=7&form_id=2&id=' + me2("materiale")[i].value ;
                return;
            }
        }
    }else{
        return
    }
}

function CancellaNazionalita(){
    if(confirm("Attention!\nDo you want to erase this nationality?\n\n")){
        for (i=0; i<= me2("materiale").length; i++){
            if(true == me2("materiale")[i].checked ){
                window.location.href='index.asp?page_id=4&form_id=2&id=' + me2("materiale")[i].value ;
                //elabora(me2("materiale")[i].value);
                return;
            }
        }
    }else{
        return
    }
}

function CancellaNazionalita2(){
    var s=new String;
    var nomi = new Array();
	s = me("array").value;
	nomi = s.split(" ");
    for (j=0; j<= me2("materiale").length; j++){
        if(true == me2("materiale")[j].checked ){
            //window.location.href='index.asp?page_id=4&form_id=2&id=' + me2("materiale")[i].value ;
            /*for (i=0;i<nomi.length;i++){
                if(nomi[i] == me2("materiale")[j].value){ 
                    if(confirm("Attention!\nVouoi cancellare nationality e regione ?\n\n")){
                        window.location.href='index.asp?page_id=4&form_id=2&id=' + me2("materiale")[j].value ;
                        return;
                    }else{
                        return;
                    }
                }else{
                    if(confirm("Attention!\nDo you want to erase this nationality?\n\n")){
                        window.location.href='index.asp?page_id=4&form_id=2&id=' + me2("materiale")[j].value ;
                        return;
                    }else{
                        return;
                    }
                }
            }*/
            return me2("materiale")[j].value;
        }
    }
}

function elabora() {
        //var out = new String;
        var id = CancellaNazionalita2();
        var s=new String;
        var nomi = new Array();
        s = me("array").value;
        nomi = s.split(" ");
        //out = "Trovati " + nomi.length + " nomi.\n";
        //out += "Eccoli:\n";
        for (i=0;i<nomi.length;i++) {
            //out += i + ") " + nomi[i] + "\n";
            if(nomi[i]==id){
                //alert('trovato: '+ nomi[i] +' '+ id);
                //return;
                if(confirm("Attention!\nThis nationality is a region too. Do you want to erase it?\n\n")){
                    window.location.href='index.asp?page_id=4&form_id=2&id=' + id ;
                    return;
                }else{
                    return;
                }
            //}else{
             //   alert('non trovato: '+ nomi[i] +' '+ id);
            }
        };
        if(confirm("Attention!\nDo you want to erase this nationality?\n\n")){
            window.location.href='index.asp?page_id=4&form_id=2&id=' + id;
            return;
        }else{
            return;
        }
        //out += "Riuniamo i nomi separandoli con punti e virgola:\n";
        //out += nomi.join(";");
};

function ModificaLente(){
    for (i=0; i<= me2("lente").length; i++){
        if(true == me2("lente")[i].checked ){
            window.location.href='index.asp?page_id=2&form_id=3&id=' + me2("lente")[i].value;
            return;
        }
    }
}

function ModificaFiltro(){
    for (i=0; i<= me2("filtro").length; i++){
        if(true == me2("filtro")[i].checked ){
            window.location.href='index.asp?page_id=3&form_id=3&id=' + me2("filtro")[i].value;
            return;
        }
    }
}

function ModificaColoreMontatura(){
    for (i=0; i<= me2("colore").length; i++){
        if(true == me2("colore")[i].checked ){
            window.location.href='index.asp?page_id=12&sub_id=3&form_id=3&id=' + me2("colore")[i].value;
            return;
        }
    }
}

function ModificaColoreMontaturaGoggle(){
    for (i=0; i<= me2("colore").length; i++){
        if(true == me2("colore")[i].checked ){
            window.location.href='index.asp?page_id=32&sub_id=3&form_id=3&id=' + me2("colore")[i].value + '&collection=' + me('collection').value;
            return;
        }
    }
}

function CancellaVideo(sub_id){
    if(confirm("Attention!\nDo you want to erase the selected Video.\n\n")){
        for (i=0; i<= me2("video_id").length; i++){
            if(true == me2("video_id")[i].checked ){
                window.location.href='index.asp?page_id=5&sub_id='+sub_id+'&form_id=2&id=' + me2("video_id")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function CancellaDownload(sub_id){
    if(confirm("Attention!\nDo you want to erase the selected Download.\n\n")){
        for (i=0; i<= me2("download_id").length; i++){
            if(true == me2("download_id")[i].checked ){
                window.location.href='index.asp?page_id=6&sub_id='+sub_id+'&form_id=2&id=' + me2("download_id")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function ModificaVideo(sub_id){
    for (i=0; i<= me2("video_id").length; i++){
        if(true == me2("video_id")[i].checked ){
            window.location.href='index.asp?page_id=5&sub_id='+sub_id+'&form_id=3&id=' + me2("video_id")[i].value;
            return;
        }
    }
}

function ModificaDownload(sub_id){
    for (i=0; i<= me2("download_id").length; i++){
        if(true == me2("download_id")[i].checked ){
            window.location.href='index.asp?page_id=6&sub_id='+sub_id+'&form_id=3&id=' + me2("download_id")[i].value;
            return;
        }
    }
}

function TestCancellaColoreMontatura(){
    if(confirm("Attention!\nto erase the model's color: the model's color should not be associated to any model.\n\n")){
        for (i=0; i<= me2("colore").length; i++){
            if(true == me2("colore")[i].checked ){
                window.location.href='index.asp?page_id=12&sub_id=3&form_id=2&id=' + me2("colore")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaColoreMontaturaGoggle(){
    if(confirm("Attention!\nto erase the model's color: the model's color should not be associated to any model.\n\n")){
        for (i=0; i<= me2("colore").length; i++){
            if(true == me2("colore")[i].checked ){
                window.location.href='index.asp?page_id=32&collection='+ me('collection').value +'&sub_id=3&form_id=2&id=' + me2("colore")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaColreLente(){
    if(confirm("Attention!\nto erase the lens color: the lens color should not be associated to any lens.\n\n")){
        for (i=0; i<= me2("colore_lente").length; i++){
            if(true == me2("colore_lente")[i].checked ){
                window.location.href='index.asp?page_id=11&sub_id=2&form_id=2&id=' + me2("colore_lente")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaColreLenteGoggle(){
    if(confirm("Attention!\nDo you want to erase the selected lens color?\n\n")){
        for (i=0; i<= me2("colore_lente").length; i++){
            if(true == me2("colore_lente")[i].checked ){
                window.location.href='index.asp?page_id=31&sub_id=2&form_id=2&id=' + me2("colore_lente")[i].value ;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaMaterialeMontatura(){
    if(confirm("Attention!\n to erase the frame's material: the frame's material should not be associated to any model.\n\n")){
        for (i=0; i<= me2("materiale").length; i++){
            if(true == me2("materiale")[i].checked ){
                window.location.href='index.asp?page_id=13&sub_id=4&form_id=4&id=' + me2("materiale")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestCancellaFrameWraps(){
    if(confirm("Attention!\n to erase the frame's wraps: the frame's wraps should not be associated to any model.\n\n")){
        for (i=0; i<= me2("wraps").length; i++){
            if(true == me2("wraps")[i].checked ){
                window.location.href='index.asp?page_id=14&sub_id=5&form_id=4&id=' + me2("wraps")[i].value;
                return;
            }
        }
    }else{
        return
    }
}

function TestUpdateMaterialeMontatura(page,form,id){
    if(me("nome").value.length==0){
        alert("Required fields:\nFrame Material\n\n");
         return;
    }
    window.location.href='index.asp?page_id=' + page + '&form_id='+form+'&id='+id;
}


function TestLanguage(page,sub_id,form){
    if (page==7) {
        if(me("nome").value.length==0){
            alert("Required fields:\n\nLanguage\n\n");
            return
        }
    }
    if (page==4){
        if(me("sigla").value.length==0 || me("nome").value.length==0){
            alert("Required fields:\n\nNationality\nNationality Abbreviation\n");
            return
        }
    }
    if (page==9){
        if(me("descrizione").value.length==0){
            alert("Required fields:\n\nBiography\n");
            return
        }
    }
    me("page_id").value = page;
    me("sub_id").value = sub_id;
    me("form_id").value = form;
    //return
    document.form_main.submit();
}
function DeleteBiografia(form_id,sub_id,biography,atleta_id){
    if(confirm("Attention!\nDo you want to erase this biography?\n\n")){
            window.location.href='DeleteBiography.inc.asp?form_id='+ form_id +'&sub_id='+sub_id+'&id=' + atleta_id+'&bio_id=' + biography;
    }else{
        return
    }
}

function TestMaterialeMontatura(page,sub_id,form){
    if(me("nome").value.length==0){
        alert("Required fields:\nFrame Material\n\n");
         return;
    }
    me("page_id").value = page;
    me("sub_id").value = sub_id;
    me("form_id").value = form;
    document.form_main.submit();
}

function UpdateMaterialeMontatura(){
    me("page_id").value = 13;
    me("form_id").value = 2;
    me("sub_id").value = 4;
    document.form_main.submit();
}

function UpdateFrameWraps(){
    me("page_id").value = 14;
    me("form_id").value = 2;
    me("sub_id").value = 5;
    document.form_main.submit();
}

function UpdateLanguage(){
    me("page_id").value = 7;
    me("form_id").value = 3;
    document.form_main.submit();
}
function UpdateNationality(){
    me("page_id").value = 3;
    me("sub_id").value = 7;
    me("form_id").value = 3;
    document.form_main.submit();
}

function InsertOrdinamento(sub_id){
    if(me("region_id").value==0) return;
    me("page_id").value = 16;
    me("sub_id").value = sub_id;
    me("form_id").value = '';
    document.form_main.submit();
    //id = me("region_id").value;
    //Load(16,'',sub_id,id,'')
}

function SpareLens(){
    if(me("image").value==""){
        alert('Required fields:\nImage lens color\n\n');
        return;
    }
    ShowUpload();
}


function loopSelected(){
  var txtSelectedValuesObj = document.getElementById('spare_lenses_id');
  var selectedArray = new Array();
  var selObj = document.getElementById('spare_lenses');
  var i;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      selectedArray[count] = selObj.options[i].value;
      count++;
    }
  }
  txtSelectedValuesObj.value = selectedArray;
  //document.form_main.submit();
  ShowUpload();
}

function loopSelectedRegions(){
  var txtSelectedValuesObj = document.getElementById('region_id');
  var selectedArray = new Array();
  var selObj = document.getElementById('region');
  var i;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      selectedArray[count] = selObj.options[i].value;
      count++;
    }
  }
  txtSelectedValuesObj.value = selectedArray;
  //document.form_main.submit();
  ShowUpload();
}

function loopSelectedRegions2(){
  var txtSelectedValuesObj = document.getElementById('region_id');
  var selectedArray = new Array();
  var selObj = document.getElementById('region');
  var i;
  var count = 0;
  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      selectedArray[count] = selObj.options[i].value;
      count++;
    }
  }
  txtSelectedValuesObj.value = selectedArray;
  //document.form_main.submit();
  UploadFile();
}