/*****************************************************************
*  Spacemarc News 
*  Version: 1.2.0
*  Author and copyright (C): Marcello Vitagliano
*  Web site: http://www.spacemarc.it
*  License: GNU General Public License
*
*  This program is free software: you can redistribute it and/or 
*  modify it under the terms of the GNU General Public License 
*  as published by the Free Software Foundation, either version 3 
*  of the License, or (at your option) any later version.
*
*  Current file: javascript.js
*****************************************************************/

//funzione mostra/nascondi campo immagine
function showText(){
   if((document.getElementById('cb').checked == true) && (document.getElementById('immagine').style.display == 'none')){
      	document.getElementById('immagine').style.display = 'inline';
      	document.getElementById('immagine').value = 'http://';
   }							
   else if ((document.getElementById('cb').checked == false) && (document.getElementById('immagine').value != 'http://') && (document.getElementById('immagine').style.display != 'none')) {
	document.getElementById('immagine').value = 'http://';
	document.getElementById('immagine').style.display = 'none';
   }
	else if ((document.getElementById('cb').checked == false) && (document.getElementById('immagine').value == 'http://')) {
	document.getElementById('immagine').style.display = 'none';
}
}


//mostro-nascondo l'anteprima della notizia
function getEl(id) {
    element = document.getElementById(id);
    return element;
}
function hideEl(id) {
    var element = getEl(id);
    element.style.display = 'none';
}
function showEl(id) {
    var element = getEl(id);

    element.style.display = '';
}
function ShowHide() {
    var el = 'preview';
    if(getEl(el).style.display == 'none') {
        showEl(el);
        showEl('preview_n');
        hideEl('preview_y');
    } else {
        hideEl(el);
        showEl('preview_y');
        hideEl('preview_n');
    }
}


//mostro messaggi help per BBcode
var form_name = 'input_form';
b_help = "Grassetto: [b]testo[/b]";
i_help = "Corsivo: [i]testo[/i]";
u_help = "Sottolineato: [u]testo[/u]";
g_help = "Inserisci immagine: [img]http://url_immagine[/img]";
a_help = "Inserisci email: [email]nome@isp.xx[/email] o [email=nome@isp.xx]testo[/email]";
w_help = "Inserisci URL: [url]http://url[/url] o [url=http://url]testo[/url] Anche ftp:// e https://";
v_help = "Contatto Skype: [callto]callto:indirizzo[/callto] o [callto=callto:indirizzo]testo[/callto]";
y_help = "Video da YouTube: [yt]xxxxxxxxxxx[/yt]";
l_help = "Lista: [ul][li]oggetto1[/li][li]oggetto2[/li][/ul]";
q_help = "Citazione: [quote]testo[/quote]";
c_help = "Inserisci del codice: [code]codice[/code]";
s_help = "Dimensione font: [size=?]testo[/size]";


//visualizzo il messaggio di help per ciascun bbcode
function helpline(help) {
	document.forms[form_name].helpbox.value = eval(help + "_help");
}


//conto i caratteri nel campo Interessi dell'utente
function checklength(theform) {
	alert("Hai scritto "+theform.hobby.value.length+" caratteri");
}

//conto i caratteri in Note Email nelle impostazioni
function checklength2(theform) {
	alert("Hai scritto "+theform.note_email.value.length+" caratteri");
}

//seleziono tutti i checkbox
function checkTutti() {
  with (document.admin) {
    for (var i=0; i < elements.length; i++) {
        if (elements[i].type == 'checkbox' && elements[i].name == 'cb_id[]')
           elements[i].checked = true;
    }
  }
}


//deseleziono tutti i checkbox
function uncheckTutti() {
  with (document.admin) {
    for (var i=0; i < elements.length; i++) {
        if (elements[i].type == 'checkbox' && elements[i].name == 'cb_id[]')
           elements[i].checked = false;
    }
  }
}


//conferma operazioni sugli utenti e news
function dropdown(sel){
   if(sel.options.selectedIndex == 0){
      return false;
   }
	else{
	if (sel.options[sel.selectedIndex].value == 'attiva_utenti' || sel.options[sel.selectedIndex].value == 'disattiva_utenti' || sel.options[sel.selectedIndex].value == 'upload' || sel.options[sel.selectedIndex].value == 'letturestampe' || sel.options[sel.selectedIndex].value == 'tutto' || sel.options[sel.selectedIndex].value == 'nessuno' || sel.options[sel.selectedIndex].value == 'invia_email') {
		c = false;
		sel.form.submit();
	} else {
		c = confirm('ATTENZIONE. I dati cancellati non potranno essere recuperati: continuare?');
   	}
	if(c) {
		sel.form.submit();
	} else {
		sel.selectedIndex = 0;
	}
   }
}

//impedisco di inserire lettere o caratteri speciali nei campi letture e stampe
function getkey(e) {
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}
function onlynumbers(e, goods) {
var key, keychar;
key = getkey(e);
if (key == null) return true;

keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();

if (goods.indexOf(keychar) != -1)
	return true;
if (key==null || key==0 || key==8 || key==9 || key==13 || key==27)
   return true;

return false;
}


// nascode/mostra le immagini nella versione stampabile
function img_hide() {
	for(var i=0; i<document.images.length; i++) {
        document.images[i].style.display = 'none';
	}
			
}
function img_show() {
	for(var i=0; i<document.images.length; i++) {
        document.images[i].style.display = 'inline';
	}
}


//inserisce il testo in un punto preciso della textarea
function addText(instext) {
    var mess = document.input_form.testo;
        //IE support
        if (document.selection) {
            mess.focus();
            sel = document.selection.createRange();
            sel.text = instext;
            document.input_form.focus();
        }
        //MOZILLA/NETSCAPE support
        else if (mess.selectionStart || mess.selectionStart == "0") {
            var startPos = mess.selectionStart;
            var endPos = mess.selectionEnd;
            var chaine = mess.value;

            mess.value = chaine.substring(0, startPos) + instext + chaine.substring(endPos, chaine.length);

            mess.selectionStart = startPos + instext.length;
            mess.selectionEnd = endPos + instext.length;
            mess.focus();
        } else {
            mess.value += instext;
            mess.focus();
        }
    }

//conferma cancellazione files
function confirmSubmit() {
  var agree=confirm("Confermi la cancellazione dei files?");
    if (agree)
      return true ;
    else
      return false ;
}

//seleziono/deseleziono tutti le email
function listbox_selectall(email, isSelect) {
  var listbox = document.getElementById(email);
	 for(var count=0; count < listbox.options.length; count++) {
	   listbox.options[count].selected = isSelect;
	 }
}

