function checkField(field,error){
	if(document.getElementById(field).value==""){
		alert(error);
		return false;
	}else return true;
}
function checkMail(field){
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
			
	if(document.getElementById(field).value==""){
		return false;
	}if(!email_reg_exp.test(document.getElementById(field).value)){
		return false;
	}else return true;
}

function isString(s) {
    return typeof s == 'string';
}

function trim(stringa){
    stringa=String(stringa);
    while ((stringa.substring(0,1) == ' ') || (stringa.substring(0,1) == '\n')){
        stringa = stringa.substring(1, stringa.length);
    }
    while ( (stringa.substring(stringa.length-1) == ' ') || (stringa.substring(stringa.length-1) == '\n')){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

function getVal(id){
  if(esiste(id)){
    return trim(document.getElementById(id).value);
  }else return "";
}

function setVal(id,val){
  if(esiste(id)){
    if(val!=null && val!='undefined')document.getElementById(id).value=trim(val);
    else document.getElementById(id).value="";
    return true;
  }else return false;
}

function isChecked(id){
  if(esiste(id)){
     return document.getElementById(id).checked;
  }else return "";	
}

function getInnerHTML(id){
  if(esiste(id)){
    return trim(document.getElementById(id).innerHTML);
  }else return "";
}

function setInnerHTML(id,val){
  if(esiste(id)){
    if(val!=null && val!='undefined')document.getElementById(id).innerHTML=trim(val);
    else document.getElementById(id).innerHTML="";
    return true;
  }else return false;
}

function esiste(id){
	if(document.getElementById(id)!= null)return true;
	else return false;
}
//se non esiste o � valorizzato ritorna false
function vuoto(id){
	if(esiste(id) && (getVal(id)==""))return true;
	else return false;
}
//se non esiste o � numerico ritorna false
function noNumero(id){
	if(esiste(id) && isNaN(getVal(id)))return true;
	else return false;
}
function evidenzia(id,color){
	if(esiste(id)){
		document.getElementById(id).style.borderColor=color;
		document.getElementById(id).style.borderWidth='2px';
	}
}
function diversi(id1,id2){
	if(esiste(id1) && esiste(id1) && (getVal(id1)!=getVal(id2)))return true;
	else return false
}

function str_replace(search, replace, subject) {
 
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

function get(querystring){
  location.href = 'diz.php?'+querystring;
}

function refresh(){
  location.reload(true);
}

function castToNUM(val){
	retval = val.replace(",",".");
	if (isNaN(retval)){
	   return "NaN";
	} else return retval;	
}

/*
 * Aabilita o disabilita un elemento html
 * ID = nome elemento
 * boolval True x disabilitare e False per abilitare
 */
function disableElement(ID, boolval){
  if(document.getElementById(ID)!=null)document.getElementById(ID).disabled = boolval;	
}

function random(){
  Math.floor(Math.random()*Math.pow(10,16));
}

/*------------------------------*/
/* Funzione che era in menu.php */
/*------------------------------*/
//JavaScript Document
//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/
function buildsubmenus()
{
	for (var i=0; i<menuids.length; i++)
	{
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
		var curr_menu = $('#'+menuids[i]);
		var ul_length = curr_menu.find('ul').length;
    	for(var t=0; t<ul_length; t++)
		{
    		var curr_tag = curr_menu.find('ul:eq('+t+')');
    		var prev_tag = curr_menu.find('ul:eq('+(t-1)+')');
    		curr_tag.parent().find('a:eq(0)').attr('class','sottomenu');
			if (curr_tag.parent().parent().attr('id')==menuids[i]) //if this is a first level submenu
			curr_tag.css('left',curr_tag.parent().width()+"px");//dynamically position first level submenus to be width of main menu item
			else //else if this is a sub level submenu (ul)
			curr_tag.css('left',prev_tag.width()+"px");//position menu to the right of menu item that activated it
			curr_tag.parent().mouseover(function(){$(this).find('ul:eq(0)').show();});
			curr_tag.parent().mouseout(function(){$(this).find('ul:eq(0)').hide();});
    	}
		for (var t=ultags.length-1; t>-1; t--)
		{ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
			var curr_tag = curr_menu.find('ul:eq('+t+')');
			curr_tag.css('visibility','visible');
			curr_tag.hide();
		}
	}
}
/*------------------------------*/

