// JavaScript Document

function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable=no'
Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
}

function redirect(selectItem) {
	if(selectItem.value !=0) {
	document.location.href = selectItem.value;
	}
}


function checkFormCard(objForm) {
var errState = false;
var msg = "";

	if(objForm.nom.value == "") {
	errState = true;
	msg += "\nName field is mandatory";
	}
	if(objForm.prenom.value == "") {
	errState = true;
	msg += "\nSurame field is mandatory";
	}
	if(objForm.email.value == "") {
	errState = true;
	msg += "\nEmail field is mandatory";
	}
	
	if(!checkEmail(objForm.email)) {
	errState = true;
	msg += "\nWrong email syntax";
	}
	
	if(objForm.nom_dest.value == "") {
	errState = true;
	msg += "\nYou must provide a recipient name";
	}
	if(objForm.prenom_dest.value == "") {
	errState = true;
	msg += "\nYou must provide a recipient surname";
	}
	
	if(objForm.email_dest.value == "") {
	errState = true;
	msg += "\nYou must provide a recipient email";
	}
	if(!checkEmail(objForm.email_dest)) {
	errState = true;
	msg += "\nWrong recipient email syntax";
	}
	if(objForm.message.value == "") {
	errState = true;
	msg += "\nYou must provide a message";
	}
	
	if(!errState) {
	objForm.submit();
	} else {
	alert(msg);
	}
}


function checkFormContact(objForm)
{
var errState = false;
var msg = "";

	if(objForm.nom.value == "") {
	errState = true;
	msg = "\nName field is mandatory";
	}
	if(objForm.prenom.value == "") {
	errState = true;
	msg += "\Surname field is mandatory";
	}
	if(objForm.email.value == "") {
	errState = true;
	msg += "\nEmail field is mandatory";
	}
	else if(!checkEmail(objForm.email)) {
	errState = true;
	msg += "\nWorng email syntax";
	}
	if(objForm.message.value == "") {
	errState = true;
	msg += "\nMessage field is mandatory";
	}
	
	if(!errState) {
	objForm.submit();
	} else {
	alert(msg);
	}
}

function checkPlanningForm(objForm)
{
var errState = false;
var msg = "";

	if(objForm.date_d.value == "") {
	errState = true;
	msg = "\nYou must provide an arrival date";
	}
	if(objForm.date_f.value == "") {
	errState = true;
	msg += "\nYou must provide a departure date";
	}
	
	if(!errState) {
	objForm.submit();
	} else {
	alert(msg);
	}
}


function newLang() {
	var strNewLang = document.lang.langage[document.lang.langage.selectedIndex].value;
	document.location.href = "/"+strNewLang;
}

function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.value)){
return (true)
}
return (false)
}

function checkLoginForm()
{
var errState = false;
var msg = "";

	if(document.client_login.email.value == "") {
	errState = true;
	msg = "\nEmail field is mandatory";
	}
	if(document.client_login.pass.value == "") {
	errState = true;
	msg += "\nPassword is mandatory";
	}
	else if(!checkEmail(document.client_login.email)) {
	errState = true;
	msg += "\nWrong email syntax !";
	}
	
	if(!errState) {
	document.client_login.submit();
	} else {
	alert(msg);
	}
}

function checkPassworForm()
{
var errState = false;
var msg = "";

	if(document.client_password.email.value == "") {
		errState = true;
		msg = "\nEmail field is mandatory";
	}
	if(!checkEmail(document.client_password)) {
		errState = true;
		msg += "\nWrong email syntax !";
	}
	
	if(!errState) {
		document.client_password.submit();
	} else {
		alert(msg);
	}
}

function initMenus(current) {
	
	var htmlMenuGites = '<div class="sep"></div><a href="/UK/gites/cerisier.html"><div>Cerisier</div></a><div class="sep"></div><a href="/UK/gites/olivier.html"><div>Olivier</div></a><div class="sep"></div><a href="/UK/gites/acacia.html"><div>Acacia</div></a><div class="sep"></div><a href="/UK/gites/lavander.html"><div>Lavander</div></a><div class="sep"></div><a href="/UK/gites/orchid.html"><div>Orchid</div></a><div class="sep"></div>';
	var htmlMenuServices = '<div class="sep"></div><a href="/UK/services/well-being.html"><div>Well-being</div></a><div class="sep"></div><a href="/UK/services/leisure.html"><div>Leisure</div></a><div class="sep"></div><a href="/UK/services/seminars-workshops-receptions.html"><div>Seminars, workshops, receptions</div></a><div class="sep"></div><a href="/UK/services/postcards.html"><div>Postcards</div></a><div class="sep"></div>';

	var mySlide = new Fx.Slide('sousmenuContent', {fps:30, duration:500, transition: Fx.Transitions.Sine.easeInOut}).hide();
	
	$('gites').addEvent('mouseenter',function(o3dEvent){
	$('sousmenuContent').set('html', htmlMenuGites);
	mySlide.slideIn();
	})
	
	$('services').addEvent('mouseenter',function(o3dEvent){

	$('sousmenuContent').set('html', htmlMenuServices);
	mySlide.slideIn();
	})
	
	$('sousmenuContent').addEvent('mouseleave',function(o3dEvent){
	mySlide.slideOut();
	})
	
	$('presentation').addEvent('mouseenter',function(o3dEvent){
	mySlide.slideOut();
	})
	
	$('claim').addEvent('mouseenter',function(o3dEvent){
	mySlide.slideOut();
	})
	
	$('perigord').addEvent('mouseenter',function(o3dEvent){
	mySlide.slideOut();
	})
	
	$('chambres').addEvent('mouseenter',function(o3dEvent){
	mySlide.slideOut();
	})
	
	$('liens').addEvent('mouseenter',function(o3dEvent){
	mySlide.SlideOut();
	})
	
	if(current==4) { $('sousmenuContent').set('html', htmlMenuGites); mySlide.slideIn();} // Gîtes
	if(current==6) { $('sousmenuContent').set('html', htmlMenuServices); mySlide.slideIn();} // Services

}

// 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 == "sel1" || cal.sel.id == "sel2"))
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}


// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
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(1900, 2070);        // 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

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _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;


