function $(i){
  return document.getElementById(i);
}

function hos(i){
  if($(i).style.display == 'block'){
    $(i).style.display = 'none';
  }
  else $(i).style.display = 'block';
}
function show(i){
	$(i).style.display = 'block';
}

function hide(i){
	$(i).style.display = 'none';
}
function hideLoader(){
	hide('caricamento');
}
function showLoader(){
	show('caricamento');
}
function isEmail(indirizzo) {
  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(indirizzo) && regv.test(indirizzo))
      return true;
    return false;
	}
  else {
    if(indirizzo.indexOf("@") >= 0)
      return true;
    return false;
 	}
}

function login_gologin(){
	show('loginLoader');
	var req = new Ajax($('server_home').value + 'moduli/login/ajax_request.php');
	req.json = true;
	req.data.push('username=' + $('username').value);
	req.data.push('password=' + hex_sha1($('password').value));
	req.onload = function(text){
		$('evErrori').innerHTML = text.msg;
		$('evErrori').className = text.classe;
		hide('loginLoader');
		if(text.error == 0){
			history.go(-1);
		}
	}
	req.send();
	
}


function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function inviaMessaggio(id_oggetto){
	if($('nome').value == ''){
		alert('Il nome non puņ essere vuoto');
	}
	else if($('email').value != '' && !isEmail($('email').value)){
			alert('L\'indirizzo mail scelto non č valido');
	}
	else {
		var req = new Ajax($('server_home').value + 'moduli/linguaggi/ajax/inviaMessaggio.php');
		req.method = 'post';
		req.data.push('id_oggetto=' + id_oggetto);
		req.data.push('nome=' + $('nome').value);
		req.data.push('sitoweb=' + $('sitoweb').value);
		req.data.push('email=' + $('email').value);
		req.data.push('testo=' + $('testo').value);
		req.onload = 'messaggi';	
		req.send();
	}
}

function isearch(){
	location.href = $('server_home').value + 'search=' + $('q').value;
}

function inserisciSmile(oggetto){
	
	$('testo').value += oggetto.alt;
	$('testo').focus();
}
function addPreferiti(id, rimuovi, funct){
	var req = new Ajax($('server_home').value + "moduli/mynotes/ajax/add_preferiti.php");
	req.data.push("id=" + id);
	if(rimuovi == true){
		req.data.push("rimuovi=true");
	}
	req.onload = function(text){
		if(funct) caricaPreferiti('preferiti');
		else $('add_preferiti').innerHTML = text;
	}
	req.send();
}
function caricaPreferiti(iddiv){
	if(iddiv == false){
		iddiv = 'preferiti';
	}
	var req = new Ajax($('server_home').value + "moduli/mynotes/ajax/carica_preferiti.php");
	req.onload = iddiv;
	req.send();
} 