var screenWidth = 0;
var screenHeight = 0;
var backgroundWidth = 0;
var backgroundHeight = 0;

function placeImageOnStage(idImage, width, height)
{
	backgroundImage = document.getElementById(idImage);
	backgroundWidth = width;
	backgroundHeight = height;
	if((backgroundWidth/screenWidth)<(backgroundHeight/screenHeight))
	{
		ratio = screenWidth/backgroundWidth;
		backgroundImage.width = screenWidth;
		backgroundImage.height = backgroundHeight * ratio;
	}
	else
	{
		ratio = screenHeight/backgroundHeight;
		backgroundImage.height= screenHeight;
		backgroundImage.width = backgroundWidth * ratio;	
	}
	backgroundImage.style.marginLeft = -1 * (backgroundImage.width/2) + "px";
	backgroundImage.style.marginTop = -1 * (backgroundImage.height/2) + "px";
	//backgroundImage.src = backgroundPath;
}

function getDrawableSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  screenWidth = myWidth;
  screenHeight = myHeight;
}

function resetForm(form)
{
	form.reset();
}

function submitForm(form)
{
	if(form.nome.value=="" || form.cognome.value=="" || form.email.value=="" || form.telefono.value=="" || form.checkin.value=="" || form.checkout.value=="" || form.tipologia.value=="" || form.adulti.value=="" || form.bambini1.value=="" || form.bambini2.value=="")
	{
		if(form.language.value=="it")
			alert("Inserire i seguenti campi obbligatori:\n-Nome \n-Cognome \n-Email \n-Telefono \n-Inizio Soggiorno \n-Fine Soggiorno \n-Tipologia sistemazione \n-Numero di persone ");	
		else if(form.language.value=="en")
			alert("The field with an (*) are obligatory.");
		else if(form.language.value=="fr")
			alert("Il est obligatoire de compiler les places avec (*).");
		else if(form.language.value=="de")
			alert("Die Infos mit (*) gezeichnet sind pflichtig.");
	}
	else
	{
		if(form.adulti.value==0)
		{
			alert("Il numero di persone selezionate deve essere maggiore di zero");
		}
		else if(confirm('Il Mittente prende atto che il trattamento dei propri dati personali sotto indicati è necessario per evadere la sua richiesta. Tali dati non saranno comunicati o diffusi a terzi, senza il consenso del mittente. Titolare del trattamento di trasmissione dei dati personali del mittente è Baia Blu Residence RTA.\rIl trattamento dei dati del mittente è effettuato nel rispetto della Legge 31.12.1996 N. 675 e delle altre norme vigenti in materia di protezione dei dati personali. Al mittente sono attribuiti i diritti di cui all\'art.13 della legge citata. Baia Blu Residence RTA non assume responsabilità in merito al contenuto della richiesta così come formata dal mittente.'))
		{
			$('#mail_request').load("include/mail_contact.php",
			{
				email:form.email.value,
				nome:form.nome.value,
				cognome:form.cognome.value,
				telefono:form.telefono.value,
				nazione:form.nazione.value,
				citta:form.citta.value,
				cap:form.cap.value,
				indirizzo:form.indirizzo.value,
				checkin:form.checkin.value,
				checkout:form.checkout.value,
				tipologia:form.tipologia.value,
				adulti:form.adulti.value,
				bambini1:form.bambini1.value,
				bambini2:form.bambini2.value,
				note:form.note.value
			});
		}
	}
}

var delay = (function(){   var timer = 0;   return function(callback, ms){     clearTimeout (timer);     timer = setTimeout(callback, ms);   }; })();
