$(function() {
	$('a[href*=_big]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageBlank: '/img/lightbox-blank.gif',
		imageLoading: '/img/lightbox-loading.gif',
		imageBtnClose: '/img/lightbox-close.gif',
		imageBtnPrev: '/img/lightbox-prev.gif',
		imageBtnNext: '/img/lightbox-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Изображение',
		txtOf: 'из'
	});
});

function printDay (entryTurnout)
{
	Days = new Array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	reservationForm = document.getElementById("reservation");
	if (entryTurnout)
	{
		valueMonth = reservationForm.turnout_month.options[reservationForm.turnout_month.selectedIndex].value;
		valueDay = reservationForm.turnout_day.options[reservationForm.turnout_day.selectedIndex].value;
		valueYear = reservationForm.turnout_year.options[reservationForm.turnout_year.selectedIndex].value;
		if (!(valueYear % 4) && (valueYear % 100))
			Days[2] = 29;
	}
	else
	{
		valueMonth = reservationForm.entry_month.options[reservationForm.entry_month.selectedIndex].value;
		valueDay = reservationForm.entry_day.options[reservationForm.entry_day.selectedIndex].value;
		valueYear = reservationForm.entry_year.options[reservationForm.entry_year.selectedIndex].value;
		if (!(valueYear % 4) && (valueYear % 100))
			Days[2] = 29;

		if (reservationForm.entry_day.options.length > Days[valueMonth] + 1)
		{
			till = reservationForm.entry_day.options.length;
			for (i = Days[valueMonth] + 1; i < till; i ++)
			{
				element = reservationForm.entry_day.options[Days[valueMonth] + 1];
				element.parentNode.removeChild(element);
			}
		}
		else if (reservationForm.entry_day.options.length < Days[valueMonth] + 1)
		{
			for (i = reservationForm.entry_day.options.length; i < Days[valueMonth] + 1; i ++)
			{
				newElement = document.createElement ("option");
				newElement.value = i;
				newText = document.createTextNode (i);
				newElement.appendChild (newText);
				reservationForm.entry_day.appendChild (newElement);
			}
		}
	}
}

function checkReservation (reservationForm)
{
	var valueSurname = reservationForm.surname.value;
	var valueEmail = reservationForm.email.value;
	var valueTel = reservationForm.tel.value;
	var valueClients = reservationForm.clients.value;
	var valueType = reservationForm.type.options[reservationForm.type.selectedIndex].value;
	var valueEntryMonth = reservationForm.entry_month.options[reservationForm.entry_month.selectedIndex].value;
	var valueEntryDay = reservationForm.entry_day.options[reservationForm.entry_day.selectedIndex].value;
	var valueEntryYear = reservationForm.entry_year.options[reservationForm.entry_year.selectedIndex].value;
	var valueEntryTime = reservationForm.entry_time.options[reservationForm.entry_time.selectedIndex].value;
	var valueTurnoutMonth = reservationForm.turnout_month.options[reservationForm.turnout_month.selectedIndex].value;
	var valueTurnoutDay = reservationForm.turnout_day.options[reservationForm.turnout_day.selectedIndex].value;
	var valueTurnoutYear = reservationForm.turnout_year.options[reservationForm.turnout_year.selectedIndex].value;
	var valueTurnoutTime = reservationForm.turnout_time.options[reservationForm.turnout_time.selectedIndex].value;
	
	var Edays = new Array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var Tdays = new Array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	Tdays[2] = Edays[2] = 28;
	if (!(valueEntryYear % 4) && (valueEntryYear % 100))
		Edays[2] = 29;
	if (!(valueTurnoutYear % 4) && (valueTurnoutYear % 100))
		Tdays[2] = 29;
	var Edate = new Date (Date.UTC (valueEntryYear, valueEntryMonth, valueEntryDay, valueEntryTime, 0, 0));
	var Tdate = new Date (Date.UTC (valueTurnoutYear, valueTurnoutMonth, valueTurnoutDay, valueTurnoutTime, 0, 0));

	var labelSurname = document.getElementById ("surname");
	var labelEmail = document.getElementById ("email");
	var labelClients = document.getElementById ("clients");
	var labelType = document.getElementById ("type");
	var labelEntry = document.getElementById ("entry");
	var labelTurnout = document.getElementById ("turnout");
	var labelError = document.getElementById ("error")

	var fix = 0;

	if (valueSurname == "" || valueSurname == "Введите Вашу фамилию" || valueSurname == "Enter your last name" || valueSurname == "Bitte geben Sie Ihren Nachnamen an" || valueSurname == "Введіть Ваше прізвище" || valueSurname == "Prosze wprowadzic nazwisko")
	{
		labelSurname.style.color = "#ff0000";
		labelSurname.style.fontWeight = "bold";
		fix = 1;
	}
	else
	{
		labelSurname.style.color = "";
		labelSurname.style.fontWeight = "";
	}
	if (!valueEmail.match (/[0-9a-zA-Z._-]+@[0-9a-zA-Z._-]+\.[a-zA-Z]{2,5}/))
	{
		labelEmail.style.color = "#ff0000";
		labelEmail.style.fontWeight = "bold";
		fix = 1;
	}
	else
	{
		labelEmail.style.color = "";
		labelEmail.style.fontWeight = "";
	}
	if (valueClients == "" || valueClients < 1 || valueClients > 50)
	{
		labelClients.style.color = "#ff0000";
		labelClients.style.fontWeight = "bold";
		fix = 1;
	}
	else
	{
		labelClients.style.color = "";
		labelClients.style.fontWeight = "";
	}
	if (valueType == 0)
	{
		labelType.style.color = "#ff0000";
		labelType.style.fontWeight = "bold";
		fix = 1;
	}
	else
	{
		labelType.style.color = "";
		labelType.style.fontWeight = "";
	}
	if (valueEntryDay == valueTurnoutDay && valueEntryMonth == valueTurnoutMonth && valueEntryYear == valueTurnoutYear && valueEntryTime == valueTurnoutTime || Edate > Tdate)
	{
		labelEntry.style.color = "#ff0000";
		labelEntry.style.fontWeight = "bold";
		labelTurnout.style.color = "#ff0000";
		labelTurnout.style.fontWeight = "bold";
		fix = 1;
	}
	else
	{
		if (valueEntryDay == "" || valueEntryDay == "-" || valueEntryDay < 1 || valueEntryDay > Edays[valueEntryMonth] ||
			valueEntryMonth == "" || valueEntryMonth == "-" || valueEntryMonth < 1 || valueEntryMonth > 12 ||
			valueEntryYear == "" || valueEntryYear == "-" || valueEntryYear < 2008 || valueEntryYear > 2010 ||
			valueEntryTime == "" || valueEntryTime == "-" || valueEntryTime < 0 || valueEntryTime > 23)
		{
			labelEntry.style.color = "#ff0000";
			labelEntry.style.fontWeight = "bold";
			fix = 1;
		}
		else
		{
			labelEntry.style.color = "";
			labelEntry.style.fontWeight = "";
		}
		if (valueTurnoutDay == "" || valueTurnoutDay == "-" || valueTurnoutDay < 1 || valueTurnoutDay > Tdays[valueEntryMonth] ||
			valueTurnoutMonth == "" || valueTurnoutMonth == "-" || valueTurnoutMonth < 1 || valueTurnoutMonth > 12 ||
			valueTurnoutYear == "" || valueTurnoutYear == "-" || valueTurnoutYear < 2008 || valueTurnoutYear > 2010 ||
			valueTurnoutTime == "" || valueTurnoutTime == "-" || valueTurnoutTime < 0 || valueTurnoutTime > 23)
		{
			labelTurnout.style.color = "#ff0000";
			labelTurnout.style.fontWeight = "bold";
			fix = 1;
		}
		else
		{
			labelTurnout.style.color = "";
			labelTurnout.style.fontWeight = "";
		}
	}
	
	if (fix)
	{
		labelError.innerHTML = "<b>!!! заполните, пожалуйста, все необходимые поля !!!</b>";
		labelError.style.color = "#ff0000";
		window.scrollTo(0, 0);
		return false;
	}
	else
	{
		labelSurname.style.color = "";
		labelSurname.style.fontWeight = "";
		labelEmail.style.color = "";
		labelEmail.style.fontWeight = "";
		labelType.style.color = "";
		labelType.style.fontWeight = "";
		labelEntry.style.color = "";
		labelEntry.style.fontWeight = "";
		labelTurnout.style.color = "";
		labelTurnout.style.fontWeight = "";
		labelError.innerHTML = "";
		return true;
	}
}

function changeInput (item, string)
{
	if (item.value == "")
	{
		item.value = string;
		item.style.color = "#999999";
	}
	else if (item.value == string)
	{
		item.value = "";
		item.style.color = "#000000";
	}
}

function printlocation (location)
{
	document.getElementById ("locationGalicino").style.display = 'none';
	document.getElementById ("locationVilla").style.display = 'none';
	document.getElementById ("locationPristan").style.display = 'none';
		
	if (location.options[location.selectedIndex].value == "galicino")
		{
			document.getElementById ("locationGalicino").style.display = 'block';
		}
	if (location.options[location.selectedIndex].value == "villa")
		{
			document.getElementById ("locationVilla").style.display = 'block';
		}
	if (location.options[location.selectedIndex].value == "pristan")
		{
			document.getElementById ("locationPristan").style.display = 'block';
		}
}
