// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

var countImage = 1;
var bVisible = false;
var label = [["",""],["San Teodoro&nbsp;","la cinta"],["Budoni&nbsp;","la baia"],
		["Posada&nbsp;","chiesetta di San Giovanni"],["Porto Ottiolu&nbsp;","veduta da Punta li turchi"],
		["Porto Ottiolu&nbsp;","ingresso del porto"],["Porto Ottiolu&nbsp;","alba sul porto"],
		["Palau&nbsp;","roccia dell'orso"],
		["San Teodoro&nbsp;","Thaiti"],["Costa Smeralda&nbsp;","Capriccioli"],
		["Porto Ottiolu&nbsp;","spiaggia del porto"],["Tavolara&nbsp;","arcipelago"],
		["San Giovanni&nbsp;","torre medioevale"],["Orosei&nbsp;","il golfo"],
		["Rio Posada&nbsp;",""],["L'isola di Tavolara&nbsp;","veduta"],
		["Supramonte&nbsp;",""],["La Maddalena&nbsp;","l'arcipelago"],
		["Baia Sant'Anna&nbsp;","la spiaggia"],["Agrustos&nbsp;","la spiaggia"],
		["?????&nbsp;","la spiaggia"]];

var title = [[""],["LA COSTA SMERALDA"], ["CAPRERA E LA MADDALENA"], ["IL GOLFO DI OROSEI"],
			["NUORO E LA BARBAGIA"], ["MINICROCIERA IN COSTA"], ["CASTELSARDO"],
			["CORSICA: BONIFACIO"], ["TRENINO VERDE IN GALLURA"], ["SABBIE E TORRI DI BARONIA"],
			["CROCIERA IN BARCA A VELA"], ["BARBAGIA IN MOTO QUAD"], ["SARDEGNA ARCAICA"],
			["BARBAGIA IN LAND ROVER"], ["LA MADDALENA"], ["ARCIPELAGO DI TAVOLARA"],
			["TREKKING A TISCALI"], ["CODULA DI LUNA"]];

function openCenterWinNormal(name,theWidth,theHeight){
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",menubar=yes,scrollbars=yes,resizable=yes";
	var url = name;
	theWin=window.open(url,'',features);
}
function openCenterWin(name,theWidth,theHeight){
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",menubar=yes,scrollbars=yes,resizable=yes";
	var url = name+".php";
	theWin=window.open(url,'',features);
}
function openCenterWinPhp(name,theWidth,theHeight){
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",menubar=yes,scrollbars=yes,resizable=yes";
	var url = name+".php";
	theWin=window.open(url,'',features);
}
function openCenterWinNoScroll(name,theWidth,theHeight){
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",menubar=yes,scrollbars=no,resizable=yes,status=no";
	var url = name+".htm";
	theWin=window.open(url,'',features);
}
function openCenterWinNoExtra(name,theWidth,theHeight){
	var theTop=(screen.height/2)-(theHeight/2);
	var theLeft=(screen.width/2)-(theWidth/2);
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",menubar=no,scrollbars=no,resizable=no,status=no";
	var url = name+".htm";
	theWin=window.open(url,'',features);
}
function showLabel()
{
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj1 = document.getElementById("caption1");
	obj1.innerHTML = label[countImage][0];
	var obj2 = document.getElementById("caption2");
	obj2.innerHTML = label[countImage][1];
}
function hideLabel()
{
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj1 = document.getElementById("caption1");
	obj1.innerHTML = "";
	var obj2 = document.getElementById("caption2");
	obj2.innerHTML = "";
}
function showTitle()
{
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj = document.getElementById("title");
	obj.innerHTML = title[countImage];
}
function hideTitle()
{
	if(!bVisible){
		var DHTML = (document.getElementById || document.all || document.layers);
		if (!DHTML)  return;
		var obj = document.getElementById("title");
		obj.innerHTML = "";
	}
}
function setShowLayer(val){
	bVisible = val;
	hideTitle();
}
function hideLayer()
{
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById("testo");
	obj.style.visibility="hidden";
}
function showLayer(layerName)
{
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById(layerName);
	obj.style.visibility="visible";
}
function loadPage(){
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById("dx");
	obj.src = countImage + ".htm";
}
function change_image(source,bFlag,totImages){
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById("photo");

	(bFlag)?countImage +=1:countImage -=1;
	if (countImage < 1){
		countImage = 1;
		return;
	}
	if (countImage > totImages){
		countImage = totImages;
		return;
	}
	obj.src = source + countImage + ".jpg";
}
function call_image(numImages){
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById("photo");
	countImage = numImages;
	obj.src = "foto/" + countImage + ".jpg";
}
function setNumImage(numImages){
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById("numImage");
	obj.value = numImages;
}
function move_arrow(num){	
	var DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML)  return;
	var obj=document.getElementById("Layer31");
	obj.style.top= 183 + (20*num) +"px"; 
}

function isblank(e)
{
  if (e.value == null || e.value == "")
    return true;

  for(var i = 0; i < e.value.length; i++)
  {
     var c = e.value.charAt(i);
     if ((c != ' ') &&
         (c != '\n') &&
         (c != '\t'))
        return false;
  }
  return true;
}

// Checks if an optional field is blank

function checkblank(e)
{
  if (isblank(e))
  {
    alert("Il campo " + e.description + " deve essere riempito");
    return false;
  }
  return true;
}

// Checks if a field is numeric.
// If the optional min property is set, it checks it is greater than
// its value
// If the optional max property is set, it checks it is less than
// its value

function checknumber(e)
{
  var v = parseFloat(e.value);
  if (isNaN(v))
  {
    alert("Il campo " + e.description + " deve essere un numero");
    return false;
  }
  if ((e.minNumber != null) && (v < e.minNumber))
  {
    alert("The field " + e.description +
          " must be greater than or equal to " + e.minNumber);
    return false;
  }
  if (e.maxNumber != null && v > e.maxNumber)
  {
    alert("The field " + e.description +
          " must be less than or equal to " + e.maxNumber);
    return false;
  }
  return true;
}

// Checks if a field looks like a date in the 99/99/9999 format

function checkdate(e)
{
  var slashCount = 0;
  if (e.value.length > 10 && e.value.length < 9)
  {
    alert(" Il campo " + e.description +
          " deve avere il formato 99/99/9999" +
          " e lungo 10 caratteri");
    return false;
  }
  for(var j = 0; j < e.value.length; j++)
  {
    var c = e.value.charAt(j);
    if ((c == '/'))
       slashCount++;
    if (c != '/' && (c < '0' || c > '9'))
    {
      alert(" Il campo " + e.description +
            " puņ contenere solo numeri separati da slash");
      return false;
    }
  }
  
  if (slashCount != 2)
  {
    alert(" Il campo" + e.description +
          " deve avere il formato 99/99/9999");
    return false;
  }
  return true;
}

// Checks if a field contains any whitespace

function checkwhitespace(e)
{
  var seenAt = false;
  for(var j = 0; j < e.value.length; j++)
  {
     var c = e.value.charAt(j);
     if ((c == ' ') || (c == '\n') || (c == '\t'))
     {
       alert("Il campo " + e.description +
             " non deve contenere spazi vuoti");
       return false;
     }
  }
  return true;
}

// Now check for fields that are supposed to be emails.
// Only checks that there's one @ symbol and no whitespace

function checkemail(e)
{
  var seenAt = false;
  for(var j = 0; j < e.value.length; j++)
  {
    var c = e.value.charAt(j);
    if ((c == ' ') || (c == '\n') || (c == '\t'))
    {
      alert("Il campo " + e.description + 
            " non deve contenere spazi vuoti");
      return false;
    }
    if ((c == '@') && (seenAt == true))
    {
      alert("Il campo " + e.description + " deve contenere solo una @");
      return false;
    }
    if ((c == '@'))
      seenAt = true;
  }
  if (seenAt == false)
  {
    alert("Il campo " + e.description + " deve contenere una @");
    return false;
  }
  return true;
}

function checkRadioButton(f){ 
    for (counter = 0; counter < f.rdbPrivacy.length; counter++){ 
       if (f.rdbPrivacy[counter].checked && f.rdbPrivacy[counter].value == 'YES'){ 
		   return true; 
       } 
	   else
	   {
	   	   alert("Attenzione: Per inviare il modulo,\r\nselezionare il consenso al trattamento dei dati personali") 
	   	   return false;
	   }
	}
} 

// This is the function that performs <form> validation.
// It is invoked from the onSubmit( ) event handler.
// The handler should return whatever value this function
// returns.
function verify(f)
{
  // Loop through the elements of the form, looking for all
  // text and textarea elements. Report errors using a post validation,
  // field-by-field approach
  for(var i = 0; i < f.length; i++)
  {
     var e = f.elements[i];
		 if (((e.type == "text") || (e.type == "textarea") || (e.type == "password")))
		 {
			// first check if the field is empty and shouldn't be
			if (!e.isOptional && !checkblank(e))
			  return false;
			  
			// Now check for fields that are supposed to be numeric.
	
			if (!isblank(e) && e.isNumeric && !checknumber(e))
			  return false;
	
			// Now check for fields that are supposed to be dates
	
			if (!isblank(e) && e.isDate && !checkdate(e))
			  return false;
			// Now check for fields that are supposed to be emails
	
			if (!isblank(e) && e.isEmail && !checkemail(e))
			  return false;
	
			// Now check for fields that are supposed
			// not to have whitespace
	
			if (!isblank(e) && e.hasNospaces && !checkwhitespace(e))
			 return false;
	
		 } // if (type is text or textarea)
		 if(e.type == "radio"){
		 	if(!checkRadioButton(f)) return false;
		 }
	  } // for each character in field
  // There were no errors if we got this far
  return true;
}
