function turnOn(which, level)
{
	document.images[which].src = buildPath(which,level,"on");
}
function turnOff(which, level)
{
	document.images[which].src = buildPath(which,level,"off");
}
function setSelButton(which, level, imgName)
{
	if(which != "" && document.images[which])
	{
		
		document.images[which].src = buildPath(imgName,level,"sel");
	}
}

function setPlanning(which,level)
{
	turnAllOff(level);
	initSubPage(which,level);
}
function turnAllOff(level)
{
	document.images['paper'].src = buildPath("b",level,null);
	document.images['flowers'].src = buildPath("b",level,null);
	document.images['beauty'].src = buildPath("b",level,null);
	document.images['favors'].src = buildPath("b",level,null);
	document.images['music'].src = buildPath("b",level,null);
	document.images['video'].src = buildPath("b",level,null);
	document.images['transport'].src = buildPath("b",level,null);
	document.images['guests'].src = buildPath("b",level,null);
	document.images['additional'].src = buildPath("b",level,null);
}
// set the photo at the top right and set the selected menu button
function initSubPage(which,level)
{
	document.images[which].src = buildPath("arrow",level,null);
}

function buildPath(imgName, level, setting)
{
	path = "";

	for(i=0;i<level;i++)
	{
		path += "../";
	}

	path +=	"images/" + imgName + 
		(setting==null?"":"_"+setting) +
		".gif";
	return(path);
}

function destroyPopup() {
	if (popWindow != null && popWindow.open) popWindow.close();
}

var popWindow;
//window.onfocus=destroyPopup;



function showPhoto(which,num,w,h)
{	
  
  var x = (screen.width - (w+50)) / 2;
  var y = (screen.height - (h+75)) / 2;

  var html = "";
  var imgsrc = "./images/common/photos/" + which + ".jpg";
  var winFeatures = "width=" + (w+50) + ",height=" + (h+75) + ",left="+ x + ",top=" + y;
  //alert(winFeatures);
  
  html = html + "<html>\r\n<head>\r\n  <title>Weddings at Villa San Crispolto - Photo Gallery</title>\r\n";
  html = html + "<link href='base.css' rel='stylesheet' type='text/css'>\r\n";
  html = html + "</head>\r\n<body>\r\n";
//  html = html + "<p align='center'><table border='0' width='" + w + "'><tr><td width='50%'align='left'>"+ caption + "</td><td width='50%'align='right'><a href='javascript:self.close();'>Close</a></td></tr></table>\r\n"; 
  html = html + "<p>&nbsp;</p><p align='center'><table border='0' width='" + w + "'><tr><td width='50%'align='left'>&nbsp;" + "</td><td width='50%'align='right'><a href='javascript:self.close();'>Close</a></td></tr></table>\r\n"; 
  html = html + "<img src='images/" + which + "/p" + which + num + ".jpg' width='" + w + "' height='" + h + "' class='tst'>\r\n</body>\r\n</html>\r\n";
  
  popWindow = open("","photos",winFeatures);
  popWindow.document.open();
  popWindow.document.writeln(html);
  popWindow.document.close();
  popWindow.opener = self;
  popWindow.focus();

}


function showPhotoN(which,num,w,h,commento)
{	
  
  var x = (screen.width - (w+45)) / 2;
  
   if (commento == "")
  {var y = (screen.height - (h+44)) / 2;}
else
  {var y = (screen.height - (h+49)) / 2;}
	
  var html = "";
 // var imgsrc = "./images/common/photos/" + which + ".jpg";
 
  if (commento == "")
{ var winFeatures = "width=" + (w+45) + ",height=" + (h+44) + ",left="+ x + ",top=" + y;}
 else
{ var winFeatures = "width=" + (w+45) + ",height=" + (h+49) + ",left="+ x + ",top=" + y;}

  //alert(winFeatures);
  
  html = html + "<html>\r\n<head>\r\n  <title>Weddings at Villa San Crispolto - Photo Gallery</title>\r\n";
  html = html + "<link href='base.css' rel='stylesheet' type='text/css'>\r\n";
  html = html + "</head>\r\n<body>\r\n";
//  html = html + "<p align='center'><table border='0' width='" + w + "'><tr><td width='50%'align='left'>"+ caption + "</td><td width='50%'align='right'><a href='javascript:self.close();'>Close</a></td></tr></table>\r\n"; 
  html = html + "<div align=center><table border='0' width='" + w + "'><tr><td width='50%'align='left'>&nbsp;" + "</td><td width='50%'align='right'><a href='javascript:self.close();void(0);'>Close</a></td></tr></table>\r\n"; 
  html = html + "<img  align=middle src='photogallery/photo" + which + "." + num + "' width='" + w + "' height='" + h + "' class='tst'>\r\n</body>\r\n</html>\r\n";
  
  if (commento != "")
  {
  html = html + "<table border='0' width='" + w + "'><tr><td width='90%'align='left'><b> - " + commento + "</b></td></tr></table>\r\n"; 
  }
  
  popWindow = open("","photospopup",winFeatures);
  popWindow.document.open();
  popWindow.document.writeln(html);
  popWindow.document.close();
  //popWindow.opener = self;
  popWindow.focus();

}


function showPhoto2(which,num,w,h,commento)
{	
  
  var x = (screen.width - (w+45)) / 2;
  
   if (commento == "")
  {var y = (screen.height - (h+44)) / 2;}
else
  {var y = (screen.height - (h+49)) / 2;}
	
  var html = "";
 // var imgsrc = "./images/common/photos/" + which + ".jpg";
 
  if (commento == "")
{ var winFeatures = "width=" + (w+45) + ",height=" + (h+44) + ",left="+ x + ",top=" + y;}
 else
{ var winFeatures = "width=" + (w+45) + ",height=" + (h+49) + ",left="+ x + ",top=" + y;}

  //alert(winFeatures);
  
  html = html + "<html>\r\n<head>\r\n  <title>Weddings at Villa San Crispolto - Photo Gallery</title>\r\n";
  html = html + "<link href='base.css' rel='stylesheet' type='text/css'>\r\n";
  html = html + "</head>\r\n<body>\r\n";
//  html = html + "<p align='center'><table border='0' width='" + w + "'><tr><td width='50%'align='left'>"+ caption + "</td><td width='50%'align='right'><a href='javascript:self.close();'>Close</a></td></tr></table>\r\n"; 
  html = html + "<div align=center><table border='0' width='" + w + "'><tr><td width='50%'align='left'>&nbsp;" + "</td><td width='50%'align='right'><a href='javascript:self.close();'>Close</a></td></tr></table>\r\n"; 
  html = html + "<img  align=middle src='photogallery/photo" + which + "." + num + "' width='" + w + "' height='" + h + "' class='tst'>\r\n</body>\r\n</html>\r\n";
  
  if (commento != "")
  {
  html = html + "<table border='0' width='" + w + "'><tr><td width='90%'align='left'><b> - " + commento + "</b></td></tr></table>\r\n"; 
  }
  
  popWindow = open("","photos",winFeatures);
  popWindow.document.open();
  popWindow.document.writeln(html);
  popWindow.document.close();
  popWindow.opener = self;
  popWindow.focus();

}



function checkForm(theForm)
{
	switch(theForm.name)
	{
		case "adduser":
			return(checkAddUser(theForm));
		case "step1":
			return(checkStep1(theForm));
		case "step2":
			return(checkStep2(theForm));
		case "step3":
			return(checkStep3(theForm));
		case "step4":
			return(checkStep4(theForm));
		case "step5":
			return(checkStep5(theForm));
		case "step6":
			return(checkStep6(theForm));
		case "step7":
			return(checkStep7(theForm));
		case "step8":
			return(checkStep8(theForm));

	}
}

function checkAddUser(theForm)
{
	if(theForm.couplename.value == "")
	{
		return(showErrorMessage(" the couple's name.", theForm.couplename));
	}	
	if(theForm.email1.value == "")
	{
		return(showErrorMessage(" at least one email address.", theForm.email1));
	}	
	if(theForm.username.value == "")
	{
		return(showErrorMessage(" the user name.", theForm.username));
	}	
	if(theForm.pwd.value == "")
	{
		return(showErrorMessage(" the password.", theForm.pwd));
	}	
	if(theForm.username.value.length > 32 || theForm.username.value.length < 3)
	{
		return(showErrorMessage(" a username that is between 3 and 32 characters.", theForm.username));
	}	
	if(theForm.pwd.value.length > 20 || theForm.pwd.value.length < 5)
	{
		return(showErrorMessage(" a password that is between 5 and 20 characters.", theForm.username));
	}	

	return(true);
}
function checkStep1(theForm)
{
	if(theForm.rentalperiod.value == "")
	{
		return(showErrorMessage(" your arrival and departure dates.", theForm.rentalperiod));
	}	
	if(theForm.numguests.value == "")
	{
		return(showErrorMessage(" the number of guests at the villa and the number expected at the reception. Note: you will have the opportunity to update these numbers in subsequent steps.", theForm.numguests));
	}	
	if(theForm.tel1.value == "")
	{
		return(showErrorMessage(" at least one telephone number where we can reach you.", theForm.tel1));
	}	

	return(checkReply(theForm));
}

function checkStep2(theForm)
{
	if(theForm.weddingday.value == "")
	{
		return(showErrorMessage(" the date of your wedding.", theForm.weddingday));
	}	
	if(theForm.weddingtime.value == "")
	{
		return(showErrorMessage(" the prefered time of day for your wedding.", theForm.weddingtime));
	}	
	if(!theForm.civil.checked && !theForm.civilrelig.checked && !theForm.symbolic.checked )
	{
		return(showErrorMessage(" the type of wedding, civil, civil & religious or symbolic.", theForm.civil));
	}	
	return(checkReply(theForm));
}

function checkStep3(theForm)
{
	if(theForm.menu.value == "")
	{
		return(showErrorMessage(" the location of the reception (villa or restaurant), the caterer and menu you prefer.", theForm.menu));
	}	
	if(theForm.numguests.value == "")
	{
		return(showErrorMessage(" the updated number of guests at the villa and the number expected at the reception. Note: you will have the opportunity to confirm these numbers in the last step.", theForm.numguests));
	}	

	return(checkReply(theForm));
}
function checkStep4(theForm)
{
	return(checkReply(theForm));
}
function checkStep5(theForm)
{
	return(checkReply(theForm));
}
function checkStep6(theForm)
{
	return(checkReply(theForm));
}
function checkStep7(theForm)
{
	return(checkReply(theForm));
}
function checkStep8(theForm)
{
	if(theForm.numguests.value == "")
	{
		return(showErrorMessage(" the final number of guests at the villa and the number expected at the reception.", theForm.numguests));
	}	

	return(checkReply(theForm));
}

function checkReply(theForm)
{
	if(isValidField(theForm.reply))
	{
		if(theForm.reply.value == "")
		{
			return(showErrorMessage(" your reply.", theForm.reply));
		}	

	}
	
	return(true);
}

function isValidField(formField) {
	if (null == formField) {
		return false;
	}
	if ("undefined" == typeof(formField) ) {
		return false;
	}
	return true;

}


function doSubmit()
{
	if(document.forms[0].nome.value == "")
	{
		return(showErrorMessage("your first name.", document.forms[0].nome));
	}	
	if(document.forms[0].cognome.value == "")
	{
		return(showErrorMessage("your last name.", document.forms[0].cognome));
	}
	if(document.forms[0].indirizzo.value == "")
	{
		return(showErrorMessage("your address.", document.forms[0].indirizzo));
	}
	if(document.forms[0].cap.value == "")
	{
		return(showErrorMessage("your postal code.", document.forms[0].cap));
	}
	if(document.forms[0].citta.value == "")
	{
		return(showErrorMessage("your city.", document.forms[0].citta));
	}
	if(document.forms[0].stato.value == "")
	{
		return(showErrorMessage("your country.", document.forms[0].stato));
	}
	if(document.forms[0].telefono.value == "")
	{
		return(showErrorMessage("your phone number.", document.forms[0].telefono));
	}
	if(document.forms[0].email.value == "")
	{
		return(showErrorMessage("your email address.", document.forms[0].email));
	}
	
	return(true);
	
}

function showErrorMessage(msg, obj)
{
	alert("Please insert " + msg);
	obj.focus();
	return(false);
	
}

function calcTotal2()
{
	var theForm = this.document.forms[0];
	var subtotal = 0;
	var total=0;
	if(theForm.orvieto.value!='')
		subtotal += eval(theForm.orvieto.value) * 9.0;
	if(theForm.pinotgrigio.value!='')
		subtotal += eval(theForm.pinotgrigio.value) * 10.0;
	if(theForm.sangiovese.value!='')
		subtotal += eval(theForm.sangiovese.value) * 9.0;
	if(theForm.rossobaroncino.value!='')
		subtotal += eval(theForm.rossobaroncino.value) * 11.0;
	if(theForm.montefalco.value!='')
		subtotal += eval(theForm.montefalco.value) * 12;
	if(theForm.sagrantino.value!='')
		subtotal += eval(theForm.sagrantino.value) * 23.00;
	if(theForm.chianti.value!='')
		subtotal += eval(theForm.chianti.value) * 12.50;
	if(theForm.montalcino.value!='')
		subtotal += eval(theForm.montalcino.value) * 19.00;
	if(theForm.brunello.value!='')
		subtotal += eval(theForm.brunello.value) * 42.00;
	if(theForm.prosecco.value!='')
		subtotal += eval(theForm.prosecco.value) * 11.50;
	if(theForm.moscato.value!='')
		subtotal += eval(theForm.moscato.value) * 11.50;

	theForm.subtotalWine.value=eval(subtotal);
	total += calcReception(theForm);
	theForm.subtotal2.value = total + eval(subtotal);
	
}

function calcTotalNew(){
	var total = 0;
	var theForm = this.document.forms[0];
	
	total += theForm.base.value;
	
	if(theForm.idMenu.checked)
		total += eval(theForm.idMenu.value) * eval(theForm.numberGuset.value);
	
}

function calcTotal()
{
	var theForm = this.document.forms[0];
	var total = 0;
	total += calcVillaRental(theForm);
	
	total += calcVillaBarRental(theForm);
	if(total==0){
		alert("The minimum rental period for the villa is one week. Please enter at least one week.");
		return
	}
	
	total += calcReception(theForm);
	total += calcFoto(theForm);
	total += calcFotoAdd(theForm);
	total += calcCeremony(theForm);
	
	if(theForm.paperwork.checked)
		total += eval(theForm.paperwork.value);
	if(theForm.video.checked)
		total += eval(theForm.video.value);
	if(theForm.makeup.checked)
		total += eval(theForm.makeup.value);
	
	total += calcFlowers(theForm);
	total += calcMusic(theForm);
	if(theForm.car.checked)
		total += eval(theForm.car.value);
	total += calcMarquee(theForm);
	/*
	if(theForm.chapel.checked)
		total += eval(theForm.chapel.value);
	*/
	if(theForm.planning.checked)
		total += eval(theForm.planning.value);

	this.parent.bottomFrame.document.forms[0].total.value=total;
	return(total);
	
}
function calcVillaRental(theForm)
{
	var subtotal = 0;

	selIdx=theForm.num_weeks_low.selectedIndex
	subtotal += eval(theForm.num_weeks_low.options[selIdx].text) * 6000;
	selIdx=theForm.num_weeks_mid.selectedIndex
	subtotal += eval(theForm.num_weeks_mid.options[selIdx].text) * 7600;
	selIdx=theForm.num_weeks_hi.selectedIndex
	subtotal += eval(theForm.num_weeks_hi.options[selIdx].text) * 7800;
	selIdx=theForm.num_weeks_top.selectedIndex
	subtotal += eval(theForm.num_weeks_top.options[selIdx].text) * 8000;
	
	theForm.subtotal1.value = subtotal;

	return subtotal;

}
function calcVillaBarRental(theForm)
{
	var subtotal = 0;

	selIdx=theForm.num_weeks_low_2.selectedIndex
	subtotal += eval(theForm.num_weeks_low_2.options[selIdx].text) * 6000;
	selIdx=theForm.num_weeks_mid_2.selectedIndex
	subtotal += eval(theForm.num_weeks_mid_2.options[selIdx].text) * 7600;
	selIdx=theForm.num_weeks_hi_2.selectedIndex
	subtotal += eval(theForm.num_weeks_hi_2.options[selIdx].text) * 7800;
	selIdx=theForm.num_weeks_top_2.selectedIndex
	subtotal += eval(theForm.num_weeks_top_2.options[selIdx].text) * 8000;
	
	theForm.subtotal1_2.value = subtotal;
	
	return subtotal;

}

function calcReception(theForm)
{
/*
	if (theForm.catering[6].checked && theForm.num_guests.value < 50)	{
		alert('The minimum number of guests for catering Tonino at the villa is 50. Please enter at least 50 or select another catering option.');
		theForm.subtotal2.value = 0;
		return 0;
	}
	*/
	if(theForm.num_guests.value == 0) {
		theForm.subtotal2.value = 0;		
		return 0;
	}

	for (var i=0; i<theForm.catering.length; i++) {
		if (theForm.catering[i].checked==true) {
			var subtotal = eval(theForm.catering[i].value) * eval(theForm.num_guests.value);
			theForm.subtotal2.value = subtotal;
			return subtotal;
		}
	}
	theForm.subtotal2.value = 0;
	return 0;
}
function calcFoto(theForm)
{
	for (var i=0; i<theForm.foto.length; i++) {
		if (theForm.foto[i].checked==true) {
			if(theForm.foto[i].value == "2301")
				return ( eval(theForm.foto[i].value) - 1);
			else
				return eval(theForm.foto[i].value);
		}
	}
	return 0;
}
function calcFotoAdd(theForm)
{
	for (var i=0; i<theForm.foto.length; i++) {
		if (theForm.foto[i].checked==true) {
			if( (theForm.foto[i].value == "920") || (theForm.foto[i].value == "1330") || (theForm.foto[i].value == "1550") || (theForm.foto[i].value == "1850") || (theForm.foto[i].value == "2300") ){
				for (var c=0; c<theForm.foto_add.length; c++) {
					if (theForm.foto_add[c].checked==true) {
						return eval(theForm.foto_add[c].value);
					}
				}
			}
			else{
				for (var c=0; c<theForm.foto_add.length; c++) {
					if (theForm.foto_add[c].checked==true) {
						theForm.foto_add[c].checked = false;
					}
				}
			}
		}
	}
	return 0;
}
function calcCeremony(theForm)
{
	for (var i=0; i<theForm.ceremony.length; i++) {
		if (theForm.ceremony[i].checked==true) {
			return eval(theForm.ceremony[i].value);
			
		}
	}
	return 0;
}
function calcFlowers(theForm)
{
	for (var i=0; i<theForm.flowers.length; i++) {
		if (theForm.flowers[i].checked==true) {
			return eval(theForm.flowers[i].value);
			
		}
	}
	return 0;
}
function calcMarquee(theForm)
{
	for (var i=0; i<theForm.marquee.length; i++) {
		if (theForm.marquee[i].checked==true) {
			return eval(theForm.marquee[i].value);
		}
	}
	return 0;
}

function calcMusic(theForm)
{
	var subtotal = 0;
	if(theForm.dj.checked)
		subtotal += eval(theForm.dj.value);

	for (var i=0; i<theForm.music.length; i++) {
		if (theForm.music[i].checked==true) {
			subtotal += eval(theForm.music[i].value);
		}
	}
	return subtotal;
}


function eseguiAzione(file, azione, id, method, start){
	var nomeForm=document.navigator;
	nomeForm.action=file+'.php';
	nomeForm.method=method;
	nomeForm.azione.value=azione;
	nomeForm.start.value=start;
	nomeForm.id.value=id;
	nomeForm.submit();
}

function openBarlist(page){
	winFeatures = "width=450 ,height=400 ,left=50,top=20, scrollbars=yes";
	popWindow = open("../"+page+".html","barlist",winFeatures);
	popWindow.focus();
}

function controlBarD(){
	thisForm = document.bard;
	for(var i=0; i<thisForm.elements.length; i++){
		nomecampo = thisForm.elements[i].name;
		if(nomecampo.search('quantita')!=-1){
			if(thisForm.elements[i].value == '') thisForm.elements[i].value=0;
		}
	}
	
	if(thisForm.nome.value==''){
		alert("Insert weddings couple");
		thisForm.nome.focus();
		return;
	}
	thisForm.submit();
}
