//------------------------Nella Home--------------------------------------
function cerca(lingua,tipoRicerca){//1 artista - 2 titolo
  document.myForm2.tipoRicercaHid.value=tipoRicerca;
  var parola=RTrim(LTrim(document.myForm2.parolaCercata.value));
  
  var msg1ITA="Inserire almeno 3 lettere";
  var msg2ITA="Inserire almeno una lettera";
  var msg1ENG="Enter at least 3 letters";
  var msg2ENG="Enter at least one letter";
  
  var msg1=msg1ITA;
  var msg2=msg2ITA;

  if(lingua=='EN'){
   msg1=msg1ENG;
   msg2=msg2ENG;
  }
  var ritorno=true;
    
  if(tipoRicerca=='2'){//ricerca per titolo
    if(parola.length<3){  
       //alert(msg1);
       document.getElementById('msgRicerca').innerHTML=msg1;
       setTimeout("document.getElementById('msgRicerca').innerHTML=''",3000);
       ritorno=false; 
   }}  
   else{ //ricerca per artista
   if(parola.length<1){  
      //alert(msg2);
	   document.getElementById('msgRicerca').innerHTML=msg2;
	   setTimeout("document.getElementById('msgRicerca').innerHTML=''",3000);
	   ritorno=false;
    }
   }
   
  return ritorno;  
}

//------------------------Nella Home fine---------------------------------



//------------------------Utilità---------------------------------
function evidenziaParola(node,word,elemento,classe) {
	//alert('ciao');
        // Iterate into this nodes childNodes
        if (node.hasChildNodes) {
                var hi_cn;
                for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
                        evidenziaParola(node.childNodes[hi_cn],word,elemento,classe);
                }
        }
        // And do this node itself
        if (node.nodeType == 3) { // text node
                tempNodeVal = node.nodeValue.toLowerCase();
                tempWordVal = word.toLowerCase();
                if (tempNodeVal.indexOf(tempWordVal) != -1) {
                        pn = node.parentNode;
                        // check if we’re inside a "nosearchhi" zone
                        checkn = pn;

                        while (checkn.nodeType != 9 && checkn.nodeName.toLowerCase() == elemento) {
                        // 9 = top of doc
                                if (checkn.className.match(/\bnosearchhi\b/)) { return; }
                                checkn = checkn.parentNode;
                        }
                        if (pn.className != "searchword" && pn.className == classe) {
                                // word has not already been highlighted!
                                nv = node.nodeValue;
                                ni = tempNodeVal.indexOf(tempWordVal);
                                // Create a load of replacement nodes
                                before = document.createTextNode(nv.substr(0,ni));
                                docWordVal = nv.substr(ni,word.length);
                                after = document.createTextNode(nv.substr(ni+word.length));
                                hiwordtext = document.createTextNode(docWordVal);
                                hiword = document.createElement("span");
                                hiword.className = "searchword";
                                hiword.appendChild(hiwordtext);
                                pn.insertBefore(before,node);
                                pn.insertBefore(hiword,node);
                                pn.insertBefore(after,node);
                                pn.removeChild(node);
                       }
                }
        }
}

function RTrim(stringa)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(stringa);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
       i--;
      s = s.substring(0, i+1);
   }
   return s;
}

function LTrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}



function emailErrata(mail){	
    var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;	
    if (!espressione.test(mail))
    	   return true;//errata	
    else	   
         return false;
}

//------------------------Utilità fine---------------------------------


function tuttoOk(){
    document.getElementById('artistaStella').style.visibility='hidden'; 
    document.getElementById('titoloStella').style.visibility='hidden'; 
    document.getElementById('emailStella').style.visibility='hidden'; 
    document.getElementById('testoStella').style.visibility='hidden';
    var ritorno=true;
    
    var artistaValido=true;
    var titoloValido=true;
    var emailValida=true;
    var testoValido=true;
    
    var artista=RTrim(LTrim(document.myForm.artista.value));
    var titolo=RTrim(LTrim(document.myForm.titolo.value));
    var email=RTrim(LTrim(document.myForm.email.value));
    var testo=RTrim(LTrim(document.myForm.testo.value));
    
    //alert('artista:'+artista);
    //alert('titolo:'+titolo);
    //alert('email:'+email);
    //alert('testo:'+testo);
    
    if(artista.length==0) artistaValido=false;
    if(titolo.length==0) titoloValido=false;
    if(email.length==0 || emailErrata(email)) emailValida=false;
    if(testo.length==0) testoValido=false;
              
    if(!artistaValido){ document.getElementById('artistaStella').style.visibility='visible'; ritorno=false;}
    if(!titoloValido){ document.getElementById('titoloStella').style.visibility='visible'; ritorno=false;}
    if(!emailValida){ document.getElementById('emailStella').style.visibility='visible'; ritorno=false;}
    if(!testoValido){ document.getElementById('testoStella').style.visibility='visible'; ritorno=false;}           

    return ritorno;
 }


function tuttoOk2(){//testo correttto
    document.getElementById('emailStella').style.visibility='hidden'; 
    document.getElementById('testoStella').style.visibility='hidden';
    var ritorno=true;
    
    var emailValida=true;
    var testoValido=true;
    
    var email=RTrim(LTrim(document.myForm.email.value));
    var testo=RTrim(LTrim(document.myForm.testo.value));
    
    //alert('artista:'+artista);
    //alert('titolo:'+titolo);
    //alert('email:'+email);
    //alert('testo:'+testo);
    
    if(email.length==0 || emailErrata(email)) emailValida=false;
    if(testo.length==0) testoValido=false;
              
    if(!emailValida){ document.getElementById('emailStella').style.visibility='visible'; ritorno=false;}
    if(!testoValido){ document.getElementById('testoStella').style.visibility='visible'; ritorno=false;}           

    return ritorno;
 }



