function checkFormUploadFoto(form)
{
	if(form.paesiFoto.selectedIndex == 0)
	{
      	alert('Inserire il paese');
    	form.paesiFoto.focus();
    	return false ;
  	}
  	else if(form.didaFoto.value == "")
  	{
    	alert('Inserire la didascalia');
  		form.didaFoto.focus();
    	return false ;
	}
 	return true ;
}

function doNothing(loginForm)
{
	document.onkeyup = keyCheck;
	
	function keyCheck()
	{
		var key_id = event.keyCode;
		if(key_id == "13")
		{
			getLoginPOST(loginForm);
		}
	}

}

function textCounter(field,cntfield,maxlimit)
{
	if(field.value.length > maxlimit) field.value = field.value.substring(0,maxlimit);
	else cntfield.value = maxlimit - field.value.length;
}

function checkFormItinerari(myForm)
{
	if(myForm.titolo.value.length == 0)
	{
		titolo.focus();
		return false;
	}
	return true;
}

function checkFormRisposta(fieldID)
{

	if(fieldID.value.length == 0)
	{
		fieldID.focus();
		return false;
	}
	return true;
}

function checkFormTappe(myForm)
{
	if(myForm.date.value.length == 0)
	{
		myForm.date.focus();
		return false;
	}
	else if(myForm.paese.selectedIndex <= 0)
	{
		myForm.paese.focus();
		return false;
	}
	else if(myForm.luogo.value.length == 0)
	{
		myForm.luogo.focus();
		return false;
	}
	else if(myForm.t1.value.length == 0)
	{
		myForm.t1.focus();
		return false;
	}
	else if(myForm.t2.value.length == 0)
	{
		myForm.t2.focus();
		return false;
	}
	else return true;
}

function checkFormPartecipa(myForm)
{
	if(myForm.nome.value.length == 0)
	{
		alert('Inserisci il tuo nome');
		myForm.nome.focus();
		return false;
	}
	else if(myForm.cognome.value.length == 0)
	{
		alert('Inserisci il tuo cognome');
		myForm.cognome.focus();
		return false;
	}
	else if((myForm.email.value==null)||(myForm.email.value==""))
	{
		alert('Inseriesci la tua email');
		myForm.email.focus();
		return false;
	}
	else if(echeck(myForm.email.value)==false)
	{
		alert('Indirizzo email non valido');
		myForm.email.focus();
		return false;
	}
	else if(myForm.c1.checked==false && myForm.c2.checked==false && myForm.c3.checked==false && myForm.c4.checked==false && myForm.c5.checked==false && myForm.c6.checked==false && myForm.c7.checked==false && myForm.c8.checked==false)
	{
		alert('Selezionare almeno 1 tappa');
		return false;
	}
	else if(myForm.privacy.checked==false)
	{
		alert('Accetta i termini per partecipare al bikeparty');
		myForm.privacy.focus();
		return false;
	}
	else return true;
}

function echeck(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false; 
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;				
}

function launch_popup(windowWidth,windowHeight,windowUri)
{
	windowName = 'Pop-up';
	var centerWidth = (window.screen.width - windowWidth) / 2;
	var centerHeight = (window.screen.height - windowHeight) / 2;
	newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + ',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight);
    newWindow.focus();
	return newWindow.name;
}

function show_map(n)
{
	for(i=1;i<=8;i++)
	{
		if(i!=n)
		{
			document.getElementById("map_alpha"+i).style.display = "none";
		}
	}
	document.getElementById("map_alpha").style.display = "none";
	document.getElementById("map_alpha"+n).style.display = "block";
}

function hide_map(n)
{
	document.getElementById("map_alpha").style.display = "block";
	document.getElementById("map_alpha"+n).style.display = "none";
}

function NewWindow(mypage,myname,w,h,scroll,pos)
{
    var win=null;
    LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=0,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=0';
    win=window.open(mypage,myname,settings);
}

function popupCommenti()
{
   	window.open('http://www.lonelyplanetitalia.it/bici/tappe/insert.php',null,'directories=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=0');
}

function resizeMe()
{
    window.focus();
	windowWidth = 440;
	windowHeight = 550;
	var centerWidth = (window.screen.width - windowWidth) / 2;
	var centerHeight = (window.screen.height - windowHeight) / 2;
	window.moveTo(centerWidth,centerHeight);
	window.resizeTo(windowWidth,windowHeight);
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try { xmlHttp=new XMLHttpRequest(); }
	catch (e)
	{
		try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e)
		{
			try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) { return false; }
		}
	}
	return xmlHttp;
}
