var oldLink = null;
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "arrivo" || cal.sel.id == "partenza"))
    cal.callCloseHandler();
}

function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(2000, 2080);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  var cal = new Calendar(0, null, flatSelected);

  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  cal.create(parent);

  cal.show();
}


// FORM VALIDATOR
String.prototype.trim = function() {
					return this.replace(/^\s+|\s+$/g,"");
}

function FrontPage_Form1_Validator(theForm) {
					var unchecked=true;
					var focused = 0;
					var info="I seguenti campi(*) non sono stati compilati o contengono informazioni incomplete:\n";
	   
					if (theForm.ORD01Appartamento.value.trim() == "") {
						if (focused==0) { 
							focused = 1;
						}
						unchecked=false;
						document.getElementById('asterAppartamento').style.color='red';
				    	info=info + "- inserire un valore per il campo \"Appartamento\"\n";
					} else { 
						document.getElementById("asterAppartamento").style.color="";
					} 

					if (theForm.ORD02Numero_di_Adulti.value.trim() == "") {
						if (focused==0) { 
							focused = 2;
						}
						unchecked=false;
						document.getElementById("asterAdulti").style.color='red';
						info=info + "- inserire un valore per il campo \"N. Adulti\"\n";
					} else {
						document.getElementById("asterAdulti").style.color='';
					}
				    if (theForm.ORD03Numero_di_Bambini.value.trim() == "") {
						if (focused==0) {
							focused = 3;
						}
					    unchecked=false;
					    document.getElementById("asterBambini").style.color='red';
	    				info=info + "- inserire un valore per il campo \"N. Bambini\"\n";
					} else {
						document.getElementById("asterBambini").style.color=''; 
					}
	   				if (theForm.ORD04Data_di_Arrivo.value.trim() =="") {
					    if (focused==0) {
						    focused=4;
						}
					    unchecked=false;
						document.getElementById("asterData_di_Arrivo").style.color='red';
					    info=info + "- inserire un valore per il campo \"data di arrivo\'\"\n";
					} else { 
						document.getElementById("asterData_di_Arrivo").style.color=''; 
					}
					if (theForm.ORD05Data_di_Partenza.value.trim() == "") {
						if (focused==0) {
							focused=5;
						}
					    unchecked=false;
					    document.getElementById("asterData_di_Partenza").style.color='red';
					    info=info + "- inserire un valore per il campo \"data di partenza\"\n";
					} else { 
						document.getElementById("asterData_di_Partenza").style.color=''; 
					}
					if (theForm.ORD06Nome_e_Cognome.value.trim() == "") {
						if (focused==0) {
							focused=6;
						}
	    				unchecked=false;
	    				document.getElementById("asterNome_e_Cognome").style.color='red';
						info=info + "- inserire un valore per il campo \"Nome e Cognome\"\n";
	  				} else { 
	  					document.getElementById("asterNome_e_Cognome").style.color=''; 
	  				}
					if (theForm.email.value.trim() == "") {
					    if (focused==0) {
					    	focused=9;
					    }
						unchecked=false;
						document.getElementById("asterEmail").style.color='red';;
						info=info + "- inserire un valore per il campo \"E-mail\"\n";
					} else {
						document.getElementById("asterEmail").style.color='';
					}
					stremail = theForm.email.value.trim();
					if (stremail.length < 5) {
						if (focused==0) { 
							focused=9; 
						}
						info=info+"- inserire almeno 5 caratteri nel campo \"E-mail\"\n";
						document.getElementById("asterEmail").style.color='red';
						unchecked=false;
					} else { 
						document.getElementById("asterEmail").style.color='';
	  					if (stremail.length > 50) {
							if (focused==0) {
								focused=9;
							}
							info=info+ "- inserire al massimo 50 caratteri nel campo \"E-mail\"\n";
							document.getElementById("asterEmail").style.color='red';
							unchecked=false;
						} else {
							document.getElementById("asterEmail").style.color='';
						}
	  				}
	  				if (theForm.ORD08Telefono.value.trim() == "") {
						if (focused==0) {
							focused=8;
						}
	    				unchecked=false;
	    				document.getElementById("asterTelefono").style.color='red';
	    				info=info + "- inserire un valore per il campo \"Telefono\"\n";
	  				} else {
	  					document.getElementById("asterTelefono").style.color='';
	  				} 
					if ( !theForm.ORD09Privacy[0].checked) {
					    if (focused==0) {
					    	focused=10;
					    }
					    unchecked=false;
						document.getElementById("asterPrivacy").style.color='red';
					    info=info + "- inserire un valore per il campo \"Privacy\"\n";
					} else {
						document.getElementById("asterPrivacy").style.color='';						
					}
					if (!unchecked) {					  	
					  	document.getElementById("infoErrore").innerHTML='<br />I campi contrassegnati da (*) in rosso non sono stati compilati oppure contengono informazioni incomplete.';
					  	alert(info)
					  	switch (focused) {
					  		case 1: theForm.ORD01Appartamento.focus();
									break;
  							case 2: theForm.ORD02Numero_di_Adulti.focus();
									break;
							case 3: theForm.ORD03Numero_di_Bambini.focus();
									break;
							case 4: theForm.ORD04Data_di_Arrivo.focus();
									break;
							case 5: theForm.ORD05Data_di_Partenza.focus();
									break;
							case 6: theForm.ORD06Nome_e_Cognome.focus();
  									break;
  							case 7: theForm.ORD07Indirizzo.focus();
									break;
							case 8: theForm.ORD08Telefono.focus();
									break;
							case 9: theForm.email.focus();
									break;
							case 10: theForm.ORD09Privacy[0].focus();  		
									break;
						}  		
  						return (false);
					} else {
						return (true);
					}
}

function FrontPage_Form1_Validator_EN(theForm) {
					var unchecked=true;
					var focused = 0;
					var info="The following fields(*) were not filled or contain incomplete information:\n";
	   
					if (theForm.ORD01Appartamento.value.trim() == "") {
						if (focused==0) { 
							focused = 1;
						}
						unchecked=false;
						document.getElementById('asterAppartamento').style.color='red';
				    	info=info + "- insert a value into \"Accomodation\" field\n";
					} else { 
						document.getElementById("asterAppartamento").style.color="";
					} 

					if (theForm.ORD02Numero_di_Adulti.value.trim() == "") {
						if (focused==0) { 
							focused = 2;
						}
						unchecked=false;
						document.getElementById("asterAdulti").style.color='red';
						info=info + "- insert a value into \"N. Adulti\"\n";
					} else {
						document.getElementById("asterAdulti").style.color='';
					}
				    if (theForm.ORD03Numero_di_Bambini.value.trim() == "") {
						if (focused==0) {
							focused = 3;
						}
					    unchecked=false;
					    document.getElementById("asterBambini").style.color='red';
	    				info=info + "- insert a value into \"N. Bambini\"\n";
					} else {
						document.getElementById("asterBambini").style.color=''; 
					}
	   				if (theForm.ORD04Data_di_Arrivo.value.trim() =="") {
					    if (focused==0) {
						    focused=4;
						}
					    unchecked=false;
						document.getElementById("asterData_di_Arrivo").style.color='red';
					    info=info + "- insert a value into \"data di arrivo\'\"\n";
					} else { 
						document.getElementById("asterData_di_Arrivo").style.color=''; 
					}
					if (theForm.ORD05Data_di_Partenza.value.trim() == "") {
						if (focused==0) {
							focused=5;
						}
					    unchecked=false;
					    document.getElementById("asterData_di_Partenza").style.color='red';
					    info=info + "- insert a value into \"data di partenza\"\n";
					} else { 
						document.getElementById("asterData_di_Partenza").style.color=''; 
					}
					if (theForm.ORD06Nome_e_Cognome.value.trim() == "") {
						if (focused==0) {
							focused=6;
						}
	    				unchecked=false;
	    				document.getElementById("asterNome_e_Cognome").style.color='red';
						info=info + "- insert a value into \"Nome e Cognome\"\n";
	  				} else { 
	  					document.getElementById("asterNome_e_Cognome").style.color=''; 
	  				}
					if (theForm.email.value.trim() == "") {
					    if (focused==0) {
					    	focused=9;
					    }
						unchecked=false;
						document.getElementById("asterEmail").style.color='red';;
						info=info + "- insert a value into \"E-mail\"\n";
					} else {
						document.getElementById("asterEmail").style.color='';
					}
					stremail = theForm.email.value.trim();
					if (stremail.length < 5) {
						if (focused==0) { 
							focused=9; 
						}
						info=info+"- inserire almeno 5 caratteri nel campo \"E-mail\"\n";
						document.getElementById("asterEmail").style.color='red';
						unchecked=false;
					} else { 
						document.getElementById("asterEmail").style.color='';
	  					if (stremail.length > 50) {
							if (focused==0) {
								focused=9;
							}
							info=info+ "- inserire al massimo 50 caratteri nel campo \"E-mail\"\n";
							document.getElementById("asterEmail").style.color='red';
							unchecked=false;
						} else {
							document.getElementById("asterEmail").style.color='';
						}
	  				}
	  				if (theForm.ORD08Telefono.value.trim() == "") {
						if (focused==0) {
							focused=8;
						}
	    				unchecked=false;
	    				document.getElementById("asterTelefono").style.color='red';
	    				info=info + "- insert a value into \"Telefono\"\n";
	  				} else {
	  					document.getElementById("asterTelefono").style.color='';
	  				} 
					if ( !theForm.ORD09Privacy[0].checked) {
					    if (focused==0) {
					    	focused=10;
					    }
					    unchecked=false;
						document.getElementById("asterPrivacy").style.color='red';
					    info=info + "- you must accept the \"Privacy policy details\" to contact us\n";
					} else {
						document.getElementById("asterPrivacy").style.color='';						
					}
					if (!unchecked) {					  	
					  	document.getElementById("infoErrore").innerHTML='<br />The fields have red (*) were not fill or contain incomplete information.';
					  	alert(info)
					  	switch (focused) {
					  		case 1: theForm.ORD01Appartamento.focus();
									break;
  							case 2: theForm.ORD02Numero_di_Adulti.focus();
									break;
							case 3: theForm.ORD03Numero_di_Bambini.focus();
									break;
							case 4: theForm.ORD04Data_di_Arrivo.focus();
									break;
							case 5: theForm.ORD05Data_di_Partenza.focus();
									break;
							case 6: theForm.ORD06Nome_e_Cognome.focus();
  									break;
  							case 7: theForm.ORD07Indirizzo.focus();
									break;
							case 8: theForm.ORD08Telefono.focus();
									break;
							case 9: theForm.email.focus();
									break;
							case 10: theForm.ORD09Privacy[0].focus();  		
									break;
						}  		
  						return (false);
					} else {
						return (true);
					}
				}
function pop(URL,nome,winWidth,winHeight,winLeft,winTop,SB,RSZ) {
	if (winLeft < 0)
		winLeft = screen.width - winWidth + winLeft
	if (winTop < 0)
		winTop = screen.height - winHeight + winTop
	if (winTop == "cen")
		winTop = (screen.height - winHeight)/2 - 20
	if (winLeft == "cen")
		winLeft = (screen.width - winWidth)/2
	if (winLeft>0 & winTop>0)
		window.open(URL, nome, 'width='+winWidth+',height='+winHeight+',fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars='+SB+',resizable='+RSZ+',directories=no,location=no,left='+winLeft+',top='+winTop+',screenX='+winLeft+',screenY='+winTop);
}

function booking(lang) {
	//lang=location.search.substr(1);
	var code;
	code='';
	switch(lang) {
		case 'IT':
		          	code = '<form method="post" action="http://www.wineuropa.it/info/wineuropa/conf_form4.asp" target="_self" onsubmit="return FrontPage_Form1_Validator(this)">'+
									'<h5>Richiesta Disponibilità</h5>'+
									'<table>'+
										'<tr>'+
											'<td style="padding-left:15px;">'+
												'<table id="campi">'+
                        							'<tr>'+
                        								'<td style="text-align:left; font-size:10px; font-weight: normal" colspan="4">(<span style="font-size:12px">*</span>) Campi obbligatori <span id="infoErrore"></span></td>'+
                        							'</tr>'+
													'<tr>'+
														'<td>Tipo di Alloggio<span id="asterAppartamento">*</span></td>'+
														'<td><select tabindex="1" name="ORD01Appartamento" style="width:175px">'+
																'<option selected="selected" value=""></option>'+
                                        						'<option value="Ala Riservata">Ala Riservata</option>'+
																'<option value="Bed & breakfast">Bed &amp; breakfast</option>'+
															'</select></td>'+
														'<td colspan="2">'+
															'<table>'+
																'<tr>'+
																	'<td>Nº Adulti<span id="asterAdulti">*</span></td>'+
																	'<td><input name="ORD02Numero_di_Adulti" tabindex="2" type="text" size="2" maxlength="2" /></td>'+
																	'<td>Nº Bambini<span id="asterBambini">*</span></td>'+
																	'<td><input tabindex="3" name="ORD03Numero_di_Bambini" type="text" size="2" maxlength="2" /></td>'+
																'</tr>'+
															'</table>'+
														'</td>'+
													'</tr>'+
													'<tr>'+
														'<td>Data di arrivo<span id="asterData_di_Arrivo">*</span></td>'+
														'<td><input tabindex="4" id="arrivo" name="ORD04Data_di_Arrivo" type="text" size="22" /><a href="#" onclick="return showCalendar(\'arrivo\', \'%d/%m/%Y\');"  ><img style="margin-left:-1px; margin-bottom:-2px" alt="Seleziona Data di Arrivo" src="http://www.iltrebbio.it/layout/util/immagini/calendario.png" width="20" height="17" /></a></td>'+
														'<td>Data di partenza<span id="asterData_di_Partenza">*</span></td>'+
														'<td><input tabindex="5" id="partenza" name="ORD05Data_di_Partenza" type="text" size="22" /><a href="#" onclick="return showCalendar(\'partenza\', \'%d/%m/%Y\');" ><img style="margin-left:-1px; margin-bottom:-2px" alt="Seleziona Data di Partenza" src="http://www.iltrebbio.it/layout/util/immagini/calendario.png" width="20" height="17" /></a></td>'+
													'</tr>'+
													'<tr>'+
														'<td>Nome e Cognome<span id="asterNome_e_Cognome">*</span></td>'+
														'<td><input tabindex="6" name="ORD06Nome_e_Cognome" type="text" size="25" /></td>'+
														'<td>Indirizzo</td>'+
														'<td><input tabindex="7" name="ORD07Indirizzo" type="text" size="25" /></td>'+
													'</tr>'+
													'<tr>'+
														'<td>Telefono<span id="asterTelefono">*</span></td>'+
														'<td><input tabindex="8" name="ORD08Telefono" type="text" size="25" /></td>'+
														'<td>E-mail<span id="asterEmail">*</span></td>'+
														'<td><input tabindex="9" name="email" type="text" size="25" /></td>'+
													'</tr>'+
													'<tr>'+
														'<td>Privacy<span id="asterPrivacy">*</span></td>'+
														'<td colspan="2"><input tabindex="10" name="ORD09Privacy" type="radio" value="Accetto" />Accetto '+
																		'<input tabindex="10" name="ORD09Privacy" type="radio" checked="checked" value="Non-Accetto" />Non '+ 
																		' Accetto - <a target="_top" href="privacy.html">Dettagli '+ 
																		'privacy policy</a></td>'+
														'<td id="pulsante"><input tabindex="11" type="submit" value="invia >>"/></td>'+
													'</tr>'+
												'</table>'+
												'<input type="hidden" name="Url_di_Arr3" value="" />'+
												'<input type="hidden" name="mailto" value="castellaccia@villalacastellaccia.com" />'+
												'<input type="hidden" name="subject" value="Richiesta di disponibilità dal sito: http://'+location.hostname+'" />'+
    											'<input type="hidden" name="redirect" value="http://'+location.hostname+'/ok.html" />'+
												'<input type="hidden" name="mailcc" value="" />'+
												'<input type="hidden" name="Nome_Computer_Remoto" value="" />'+
												'<input type="hidden" name="Url_di_Arr" value="'+location.hostname+'" />'+
												'<input type="hidden" name="Cliente" value="Villa La Castellaccia" />'+
												'<input type="hidden" name="Azienda" value="Villa La Castellaccia" />'+
												'<input type="hidden" name="E-mail" value="castellaccia@villalacastellaccia.com" />'+
												'<input type="hidden" name="conferma" value="NO" /></td>'+
										'</tr>'+
									'</table>'+
							'</form>';
					break;
		case 'EN' :	
		default :	code = '<form method="post" action="http://www.wineuropa.it/info/wineuropa/conf_form4.asp" target="_self" onsubmit="return FrontPage_Form1_Validator(this)">'+
									'<h5>Availability Request</h5>'+
									'<table>'+
										'<tr>'+
											'<td style="padding-left:15px;">'+
												'<table id="campi">'+
                        							'<tr>'+
                        								'<td style="text-align:left; font-size:10px; font-weight: normal" colspan="4">(<span style="font-size:12px">*</span>) Required fields <span id="infoErrore"></span></td>'+
                        							'</tr>'+
													'<tr>'+
														'<td>Accomodation<span id="asterAppartamento">*</span></td>'+
														'<td><select tabindex="1" name="ORD01Appartamento" style="width:175px">'+
																'<option selected="selected" value=""></option>'+
                                        						'<option value="Ala Riservata">Villa\'s Wing</option>'+
																'<option value="Bed & Breakfast">Bed &amp; Breakfast</option>'+
															'</select></td>'+
														'<td colspan="2">'+
															'<table>'+
																'<tr>'+
																	'<td>Nº Adults<span id="asterAdulti">*</span></td>'+
																	'<td><input name="ORD02Numero_di_Adulti" tabindex="2" type="text" size="2" maxlength="2" /></td>'+
																	'<td>Nº Children<span id="asterBambini">*</span></td>'+
																	'<td><input tabindex="3" name="ORD03Numero_di_Bambini" type="text" size="2" maxlength="2" /></td>'+
																'</tr>'+
															'</table>'+
														'</td>'+
													'</tr>'+
													'<tr>'+
														'<td>Date of arrive<span id="asterData_di_Arrivo">*</span></td>'+
														'<td><input tabindex="4" id="arrivo" name="ORD04Data_di_Arrivo" type="text" size="22" /><a href="#" onclick="return showCalendar(\'arrivo\', \'%d/%m/%Y\');"  ><img style="margin-left:-1px; margin-bottom:-2px" alt="Seleziona Data di Arrivo" src="http://www.iltrebbio.it/layout/util/immagini/calendario.png" width="20" height="17" /></a></td>'+
														'<td>Date of departure<span id="asterData_di_Partenza">*</span></td>'+
														'<td><input tabindex="5" id="partenza" name="ORD05Data_di_Partenza" type="text" size="22" /><a href="#" onclick="return showCalendar(\'partenza\', \'%d/%m/%Y\');" ><img style="margin-left:-1px; margin-bottom:-2px" alt="Seleziona Data di Partenza" src="http://www.iltrebbio.it/layout/util/immagini/calendario.png" width="20" height="17" /></a></td>'+
													'</tr>'+
													'<tr>'+
														'<td>Name and Surname<span id="asterNome_e_Cognome">*</span></td>'+
														'<td><input tabindex="6" name="ORD06Nome_e_Cognome" type="text" size="25" /></td>'+
														'<td>Address</td>'+
														'<td><input tabindex="7" name="ORD07Indirizzo" type="text" size="25" /></td>'+
													'</tr>'+
													'<tr>'+
														'<td>Telephone<span id="asterTelefono">*</span></td>'+
														'<td><input tabindex="8" name="ORD08Telefono" type="text" size="25" /></td>'+
														'<td>E-mail<span id="asterEmail">*</span></td>'+
														'<td><input tabindex="9" name="email" type="text" size="25" /></td>'+
													'</tr>'+
													'<tr>'+
														'<td>Privacy<span id="asterPrivacy">*</span></td>'+
														'<td colspan="2"><input tabindex="10" name="ORD09Privacy" type="radio" value="I-Accept" />I Accept '+
																		'<input tabindex="10" name="ORD09Privacy" type="radio" checked="checked" value="I-dont-Accetto" />I don\'t '+ 
																		'Accept - <a target="_top" href="privacy.html">Privacy policy details</a></td>'+
														'<td id="pulsante"><input tabindex="11" type="submit" value="send &gt;&gt;"/></td>'+
													'</tr>'+
												'</table>'+
												'<input type="hidden" name="Url_di_Arr3" value="" />'+
												'<input type="hidden" name="mailto" value="castellaccia@villalacastellaccia.com" />'+
												'<input type="hidden" name="subject" value="Richiesta di disponibilità dal sito: http://'+location.hostname+'" />'+
    											'<input type="hidden" name="redirect" value="http://'+location.hostname+'/ok.html" />'+
												'<input type="hidden" name="mailcc" value="" />'+
												'<input type="hidden" name="Nome_Computer_Remoto" value="" />'+
												'<input type="hidden" name="Url_di_Arr" value="'+location.hostname+'" />'+
												'<input type="hidden" name="Cliente" value="Villa La Castellaccia" />'+
												'<input type="hidden" name="Azienda" value="Villa La Castellaccia" />'+
												'<input type="hidden" name="E-mail" value="castellaccia@villalacastellaccia.com" />'+
												'<input type="hidden" name="conferma" value="NO" /></td>'+
										'</tr>'+
									'</table>'+
							'</form>';
					break;		
	}
	return code;
}		


