// -------------------------------------------------------
// galleria generale: selezione di una categoria di immagini
// -------------------------------------------------------
function SelectCategory(myvalue,url2prepend)
{
	var interfaceLanguage=document.getElementById('selectCategory').lang.value;
	document.location.href = url2prepend+"&categoria="+myvalue+"&lang="+interfaceLanguage;
}



// -------------------------------------------------------
// validazione registrazione
// -------------------------------------------------------
function validateRegistrazione()
{
 
  var nome    = document.getElementById('newsletterForm').registrazione_nome.value;
  var cogn    = document.getElementById('newsletterForm').registrazione_cognome.value;
  var mail    = document.getElementById('newsletterForm').registrazione_mail.value;
  var captcha = document.getElementById('newsletterForm').registrazione_captcha.value;
  
  
  if (nome && mail && cogn && captcha )
  {
    
    	if (mail.indexOf('@',0) != -1 && mail.indexOf('.',0) != -1)
         return true;
      else
      {
        alert('inserire un indirizzo di mail corretto.');
        return false;
      }
   
  }
  else
  {
     alert('compilare tutti i campi obbligatori.');
     return false;
  }
}

function validateUnRegistrazione()
{
 
  var mail    = document.getElementById('newsletterFormUn').registrazione_mail.value;
  
  
  if (mail)
  {
    
    	if (mail.indexOf('@',0) != -1 && mail.indexOf('.',0) != -1)
         return true;
      else
      {
        alert('inserire un indirizzo di mail corretto.');
        return false;
      }
   
  }
  else
  {
     alert('compilare tutti i campi obbligatori.');
     return false;
  }
}



// -------------------------------------------------------
// apertura pagina di edit delle schede
// -------------------------------------------------------
function EditSk(page)
{
  var wnd = window.opener;
  
  if ( (wnd != null) && (!wnd.closed) )
  {
    wnd.focus();
    wnd.location.href = page;
  }  
  else
    OpenWindow(page, 'EditSk', 700, 500);
}


// -------------------------------------------------------
// messaggio di conferma
// -------------------------------------------------------
function ConfirmDelete(msg)
{
  return confirm(msg);
}

// -------------------------------------------------------
// permette di digitare solo numeri
// -------------------------------------------------------
function numbersonly(myfield, e, dec)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // numbers
  else if ((("0123456789").indexOf(keychar) > -1))
     return true;
  
  // decimal point jump
  else if (dec && (keychar == "."))
     {
     myfield.form.elements[dec].focus();
     return false;
     }
  else
     return false;
}

// -------------------------------------------------------
// permette di digitare solo numeri e lettere
// -------------------------------------------------------
function letternumber(e)
{
  var key;
  var keychar;
  
  if (window.event)
     key = window.event.keyCode;
  else if (e)
     key = e.which;
  else
     return true;
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  
  // control keys
  if ((key==null) || (key==0) || (key==8) || 
      (key==9) || (key==13) || (key==27) )
     return true;
  
  // alphas and numbers
  else if (((" '.-abcdefghijklmnopqrstuvwxyz0123456789àèìòù?_,éç&âäèêëöüçß&()").indexOf(keychar) > -1))
     return true;
  else
     return false;
}

// -------------------------------------------------------
// classica openWindow
// -------------------------------------------------------
function OpenWindow(url, windowName, w, h)
{
   var wf = "";
   wf = wf + "width=" + w;
   wf = wf + ",height=" + h;
   wf = wf + ",resizable=yes";
   wf = wf + ",scrollbars=yes";
   wf = wf + ",menubar=no";
   wf = wf + ",toolbar=yes";
   wf = wf + ",directories=no";
   wf = wf + ",location=no";
   wf = wf + ",status=yes";
   var wnd = window.open(url,windowName,wf);
   wnd.focus();
}


// -------------------------------------------------------
// si muove tra le pagine del navigatore
// -------------------------------------------------------
function ChangeOffset(NewOffset) {
	if (document.getElementById('mainForm')) {
		var navigator_form=document.getElementById('mainForm');
		navigator_form.last_record.value=NewOffset;
		navigator_form.submit();
	} else {
		document.mainForm.last_record.value = NewOffset;
		document.mainForm.submit();
	}
}


// -------------------------------------------------------
// posiziona un'immagine secondaria come principale
// -------------------------------------------------------
/*
echo '<img id="placeholder" src="immagini/nrm/'.$main_image_name.'.jpg" alt="'.$main_image_alt.'" title="'.$main_image_alt.'"';

$photogallery=PrintSkGallery(
	//ID scheda corrente
	$id,
	//ruolo link
	LINKS_ROLE_GALLERY,
	//mostro il link x zoom immagine?
	false,
	//URL da sostituire
	'',//'index.php?page=zoom&amp;image_id=#IMG_ID#&amp;lang='.$lang,
	//il nome del file nel DB contiene l'estensione?
	false,
	//testo da stampare prima del record
	'<a onclick="return showPic(this,\'div_id\');" href="immagini/nrm/#IMG_FILE_NAME_TAG#.jpg">',
	//testo da stampare dopo del record
	'<img src="immagini/prw/#IMG_FILE_NAME_TAG#.jpg" alt="#IMG_DIDA#" title="#IMG_DIDA#" /></a>',
	//SQL x ordinamento
	'',
	//stampo il tag "<img>"?
	false,
	//tipologia della tabella master
	LINKS_SK_TYPE
);
*/

// -------------------------------------------------------
// switch etichette per allegati e photogalleryy
// -------------------------------------------------------


function switch_multimedia (e) {
		
	if(e.id== 'id_allegato'){
		
		document.getElementById('corpo_allegato').style.display="block";
		
		/* classe attivo link */
		document.getElementById('id_allegato').className="attivo";
		document.getElementById('id_link').className="noattivo";
		document.getElementById('id_video').className="noattivo";
		document.getElementById('id_foto').className="noattivo";
	
		corpoFoto = document.getElementById('corpo_foto'); 
		if(corpoFoto !== null)
			corpoFoto.style.display="none";
		
		corpoLink = document.getElementById('corpo_link'); 
		if(corpoLink !== null)
			corpoLink.style.display="none";
		
		corpoVideo = document.getElementById('corpo_video'); 
		if(corpoVideo !== null)
			corpoVideo.style.display="none";
		
		

			}
	
	if(e.id== 'id_link'){
		
		
		document.getElementById('corpo_link').style.display="block";
		
		/* classe attivo link */
		document.getElementById('id_allegato').className="noattivo";
		document.getElementById('id_link').className="attivo";
		document.getElementById('id_video').className="noattivo";
		document.getElementById('id_foto').className="noattivo";


		
		corpoFoto = document.getElementById('corpo_foto'); 
		if(corpoFoto !== null)
			corpoFoto.style.display="none";
		
		corpoAllegato = document.getElementById('corpo_allegato'); 
		if(corpoAllegato !== null)
			corpoAllegato.style.display="none";
		
		corpoVideo = document.getElementById('corpo_video'); 
		if(corpoVideo !== null)
			corpoVideo.style.display="none";
		
		
	
	}
	
	if(e.id== 'id_video'){
		
		document.getElementById('corpo_video').style.display="block";
		
	/* classe attivo link */
		document.getElementById('id_allegato').className="noattivo";
		document.getElementById('id_link').className="noattivo";
		document.getElementById('id_video').className="attivo";
		document.getElementById('id_foto').className="noattivo";


		
		corpoFoto = document.getElementById('corpo_foto'); 
		if(corpoFoto !== null)
			corpoFoto.style.display="none";
		
		corpoAllegato = document.getElementById('corpo_allegato'); 
		if(corpoAllegato !== null)
			corpoAllegato.style.display="none";
		
		corpoLink = document.getElementById('corpo_link'); 
		if(corpoLink !== null)
			corpoLink.style.display="none";
	}
	
	if(e.id== 'id_foto'){
		
		document.getElementById('corpo_foto').style.display="block";
		
		/* classe attivo link */
		document.getElementById('id_allegato').className="noattivo";
		document.getElementById('id_link').className="noattivo";
		document.getElementById('id_video').className="noattivo";
		document.getElementById('id_foto').className="attivo";

		
		corpoVideo = document.getElementById('corpo_video'); 
		if(corpoVideo !== null)
			corpoVideo.style.display="none";
		
		corpoAllegato = document.getElementById('corpo_allegato'); 
		if(corpoAllegato !== null)
			corpoAllegato.style.display="none";
		
		corpoLink = document.getElementById('corpo_link'); 
		if(corpoLink !== null)
			corpoLink.style.display="none";
	}
	
		
}

/* aumento il corpo del testo */


function zoomElemet (e){
	
	pZoom = document.getElementsByTagName('p'); 
	
	
	for (var i = pZoom.length - 1; i >= 0; i--){
	
		    if(e.id== 'zIn'){
		 		pZoom[i].style.fontSize="12px";
		 	}
		 	else if(e.id== 'zOut'){
		 		pZoom[i].style.fontSize="16px";
		 	}

    }
	
	
}

function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        var lat = document.getElementById("lat").value;
        var lng = document.getElementById("lng").value;
        
        
        map.setCenter(new GLatLng(lat, lng), 13);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        // Create our "tiny" marker icon
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
		
		// Set up our GMarkerOptions object
		markerOptions = { icon:blueIcon };

        // Add 10 markers to the map at random locations
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        //for (var i = 0; i < 10; i++) {
        //alert(lat +" " + lng);
        var latlng = new GLatLng(lat, lng);
          map.addOverlay(new GMarker(latlng, markerOptions));
        //}
      }
    }


