function controlForm(oForm){
  if(oForm.name=='frmC'){
    if(!oForm.elements[0].value){
      alert("Attenzione: per proseguire è necessario inserire il titolo!");
      oForm.elements[0].focus();
      return false;
    }
  }
  else if(oForm.name=='frmP'){
    if(!oForm.elements[0].value || oForm.elements[0].value.length<6){
      alert("Attenzione: per proseguire è necessario inserire lo username min 6 caratteri!");
      oForm.elements[0].focus();
      return false;
    }
    else if(!oForm.elements[1].value || oForm.elements[1].value.length<6){
      alert("Attenzione: per proseguire è necessario inserire la password min 6 caratteri!");
      oForm.elements[1].focus();
      return false;
    }
  }
  else if(oForm.name=='frmS'){
    if(!oForm.elements[0].value){
      alert("Attenzione: per proseguire è necessario inserire la domanda!");
      oForm.elements[0].focus();
      return false;
    }
  }
  else if(oForm.name=='frmCamp'){
    if(!oForm.elements[0].value){
      alert("Attenzione: per proseguire è necessario inserire il nome!");
      oForm.elements[0].focus();
      return false;
    }
  }
  return true;
}

function confirmByMsg(msg){
  if(confirm(msg)) 
    return true;
  else
    return false;
}

function toggleDisplay(id){
 o = document.getElementById(id);
 if(o) {
   if(o.style.display=='none') o.style.display='';
   else o.style.display='none';
 }
}
var imgBasePath = '../img/';
function changeImg(idimg,img1,img2){
 oimg = document.getElementById(idimg);
 strimg = oimg.src;
 confront = strimg.substr(strimg.lastIndexOf("/")+1);
 if(confront==img1) oimg.src=imgBasePath+img2;
 else oimg.src=imgBasePath+img1;
}

function changeTitle(id,title1,title2){
 o = document.getElementById(id);
 confront = o.title;
 if(confront==title1) o.title=title2;
 else o.title=title1;
}

/************************************************************************************/

function apriPopup(pagina, w, h, nome, attributi, x, y){ 
	// Se non sono stati passati x e y apro la finestra al centro dello schermo
	if (!x) x = Math.ceil( (window.screen.width - w) / 2 ); 
	if (!y) y = Math.ceil( (window.screen.height - h) / 4 ); 
	// Se non sono stati passati gli attributi...
  if (!attributi) attributi = 'resizable=yes,toolbar=no,status=no,scrollbars=yes,menubar=yes';
	// Se non è stato passato il nome della finestra ne imposto uno di default
	if (!nome) nome = "popup_window";
	popup = window.open(pagina, nome, attributi + ',width=' + w + ',height=' + h); 
	popup.moveTo(x,y);
	popup.focus(); 
}

function changeBkgImg(imgname,iddest){
  document.getElementById(iddest).style.background='#ffffff  url('+ imgname +') no-repeat center center';
}

function changeClass(o,classname){
  o.className = classname;
}

/***********************************************************************************/
/* Per gallery home page in js */
var intervalID;
var scrollValue;
var div_name = 'imgslice';

function scrollById(){
    document.getElementById(div_name).scrollLeft += scrollValue;
}
function scrollDiv(value){
  scrollValue = value;
  intervalID = setInterval(scrollById,50);
}
function stopScroll(){
  clearInterval(intervalID);
}
/*********************************************************************************/
/* Per sondaggi home page in js */
var intervalID2;
var scrollValue2;
var div_name2 = 'sondaggio';

function scrollById2(){
    document.getElementById(div_name2).scrollTop += scrollValue2;
}
function scrollDiv2(value){
  scrollValue2 = value;
  intervalID2 = setInterval(scrollById2,100);
}
function stopScroll2(){
  clearInterval(intervalID2);
}
/*********************************************************************************/
/*RSS*/
var intervalID3;
var scrollValue3;
var div_name3 = 'rss';

function scrollById3(){
    document.getElementById(div_name3).scrollLeft += scrollValue3;
    if(document.getElementById(div_name3).scrollLeft+document.getElementById(div_name3).clientWidth >= document.getElementById(div_name3).scrollWidth)
      document.getElementById(div_name3).scrollLeft = 0;
}
function scrollDiv3(value){
  scrollValue3 = value;
  intervalID3 = setInterval(scrollById3,30);
}
function stopScroll3(){
  clearInterval(intervalID3);
}
/***************************************************************************************/
var currentIndex = 0;
var aImgG = null;
function changeImgGallery(action,imgid){
  if(action=="prev") newIndex=currentIndex-1;
  else if(action=="next") newIndex=currentIndex+1;
  oimg = document.getElementById(imgid);
  if(aImgG && aImgG[newIndex]){
    oimg.src="get_file.php?preset=home_new&id="+aImgG[newIndex];
    currentIndex = newIndex;
  }
}

function changeImgGallery2(imgname,iddest,index){
  currentIndex = index;
  document.getElementById(iddest).src=imgname;
}
/**************************************************************************************************/
// var currentIndex2 = 0;
// var aSlide = null;
// function slide(){  
//   if(!aSlide){
//     clearInterval(slideInterval);
//     return false;
//   }
//   currentIndex2++;
//   if(!aSlide[currentIndex2]) currentIndex2 = 0;
//   document.getElementById('slideshow').innerHTML = aSlide[currentIndex2];
// }
// var slideInterval = setInterval(slide,4000);
var currentIndex3 = 0;
var totslide = 0;
function slide3(){  
  currentIndex3++;
  if(currentIndex3==totslide) currentIndex3=0;
  for(i=0;i<totslide;i++){
    if(i==currentIndex3)  
      document.getElementById('divslide_'+i).style.display = '';
    else
      document.getElementById('divslide_'+i).style.display = 'none';
  }
}
var slideInterval3 = setInterval(slide3,7000);
/********************************************************************************************/
function playVideo(boxid,srcvideo,idclear,w,h){
  if(idclear) clearInterval(idclear);
  var s ='<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mPlayer/en/nsmp2inf.cab#Version=6,4,7,1112" name="player" width="'+w+'px" height="'+h+'px" id="player">';
  s +='<param name="AutoStart" value="1">';
  s +='<param name="ShowControls" value="1">';
  s +='<param name="ShowDisplay" value="0">';
  s +='<param name="ShowStatusBar" value="0">';
  s +='<param name="AllowChangeDisplaySize" value="0">';
  s +='<param name="EnableFullScreenControls" value="0">';
  s +='<param name="URL" value="'+srcvideo+'">';
  s +='<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/windowsmedia/download/" src="'+srcvideo+'" Name="MediaPlayer" AutoStart="1" ShowControls="1" ShowDisplay="0" ShowStatusBar="0" width="'+w+'px" height="'+h+'px"></embed>';						
  s +='</object>';
  document.getElementById(boxid).innerHTML=s;
  
}
/********************************************************************************************/
function validate_comment(oform){
  if(!oform.nome.value){
    alert("Devi specificare il tuo nome");
    oform.nome.focus();
    return false;
  }
  if(!oform.email.value){
    alert("Devi specificare l'indirizzo email");
    oform.email.focus();
    return false;
  }
  if(!checkemail1(oform.email)){
    alert("La email inserita non è corretta");
    oform.email.focus();
    return false;
  }
  if(!oform.messaggio.value){
    alert("Devi specificare il tuo messaggio");
    oform.messaggio.focus();
    return false;
  }
}

function validate_search_video(oform){
  if(!oform.search.value){
    alert("Devi specificare il testo da cercare");
    oform.search.focus();
    return false;
  }
  else if(oform.search.value.length<3){
    alert("Devi specificare un testo di almeno 3 caratteri");
    oform.search.focus();
    return false;
  } 
}

function checkemail1(x){
  var str=x.value
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (filter.test(str))
  testresults=true
  else{
  testresults=false
  }
  return (testresults)
}