// JavaScript Document
/*--Функция открытия подменю НАЧАЛО--*/
function submenu(mbut) {
	var menubutton = document.getElementById(mbut);				// получение имени кнопки вызова подменю
	var menulist = document.getElementById(mbut + "-dropmenu");	// получение имени самого подменю
	var x = 0, y = 0;											// установка начальной координаты верхнего левого угла подменю
	do {														// начало цикла определения новых координат подменю
        x += menubutton.offsetLeft;								// получение кординаты по оси X
        y += menubutton.offsetTop;								// получение кординаты по оси Y
    } 
	while (menubutton = menubutton.offsetParent);				// окончание цикла определения новых координат
	if (navigator.appName=='Netscape' || navigator.appName=='Opera' || navigator.appVersion.match('MSIE 8.0')=='MSIE 8.0') {
		menulist.style.top = y + 26 + 'px';							// присваивание новой коодинаты по оси Y подменю 
		menulist.style.left = x + 'px';								// присваивание новой коодинаты по оси X подменю
	}
	else {
		menulist.style.top = y + 26 + 'px';	
		menulist.style.left = x - 16 + 'px';
	}
	
	
	if (menulist.style.visibility == 'visible') {				// проверка подменю на отображение на сайте; если скрыто,
		menulist.style.visibility = 'hidden';					// то показать.
	}
	else {														// иначе
		menulist.style.visibility = 'visible';					// скрыть
	}
}
/*--Функция открытия подменю КОНЕЦ--*/

/*--Функция изменения размера основных слоев НАЧАЛО--*/
function main_div() {
	var photo_div = document.getElementById("d_photo");
	var content_div = document.getElementById("d_content");
	var text_div = document.getElementById("text_div");
	var way = document.getElementById("d_way");
	var weather_div = document.getElementById("d_weather");
	var information_div = document.getElementById("d_inform");
	//var weather_div_height = weather_div.offsetHeight;
	var photo_div_height = photo_div.offsetHeight;
	content_div.style.minHeight = /*weather_div_height +*/ photo_div_height - 10 + "px";
	information_div.style.minHeight = /*weather_div_height +*/ photo_div_height + "px";
	var h = way.offsetHeight;
	text_div.style.minHeight = weather_div_height + photo_div_height - h - 30 + "px";
	if (document.URL == 'http://hotel-odeon.ru/index.php?section=specials&subsection=ski_tour_at_krasnaya_polyana' || document.URL == 'http://www.hotel-odeon.ru/index.php?section=specials&subsection=ski_tour_at_krasnaya_polyana' || document.URL == 'http://hotel-odeon.ru/index.php?section=specials&subsection=new_year_and_christmas_in_sochi' || document.URL == 'http://www.hotel-odeon.ru/index.php?section=specials&subsection=new_year_and_christmas_in_sochi') {
		information_div.style.background = 'url(images/bgskiinform.png) no-repeat left bottom #EAB576';
		content_div.style.background ='url(images/bgskicontent.png) no-repeat left bottom #EAB576';
	}
}
/*--Функция изменения размера основных слоев КОНЕЦ--*/

/*--Функция работы с формой НАЧАЛО--*/
function check_field_booking() {
	var user_name = document.getElementById("user_name");
	var phone = document.getElementById("phone");
	var mail = document.getElementById("e-mail");
	var number_of_adults = document.getElementById("number_of_adults");
	var from_date = document.getElementById("from_date");
	var to_date = document.getElementById("to_date");
	result = ["false", "false", "false", "false", "false", "false"];
	//check for user name
	if (user_name.value!=0) {
		var check_name = /^[А-ЯA-Z]{1}[а-яa-z]{2,12}\s[А-ЯA-Z]{1}[а-яa-z]{2,12}\s[А-ЯA-Z]{1}[а-яa-z]{2,12}$/;
		if (!check_name.test(user_name.value)) {
			user_name.style.backgroundColor = "#FFE4E1";
		}
		else {
			result[0] = "true";
		}
	}
	else {
		user_name.style.backgroundColor = "#FFE4E1";	
	}
	//check for phone number
	if (phone.value!=0) {
		var check_phone = /^\+[0-9\-]{1,4}\s[0-9]{3,6}\s[0-9]{5,11}$/;
		if (!check_phone.test(phone.value)) {
			phone.style.backgroundColor = "#FFE4E1";
		}
		else {
			result[1] = "true";
		}
	}
	else {
		phone.style.backgroundColor = "#FFE4E1";
	}
	//check for mail
	if (mail.value!=0) {
		var check_mail = /^[a-z0-9_\.\-]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/;
		if (!check_mail.test(mail.value)) {
			mail.style.backgroundColor = "#FFE4E1";
		}
		else {
			result[2] = "true";
		}
	}
	else {
		mail.style.backgroundColor = "#FFE4E1";
	}
	//check for number of adults and dates
	if (number_of_adults.value==0) {
		number_of_adults.style.backgroundColor = "#FFE4E1";
	}
	else {
		result[3] = "true";
	}
	if (from_date.value==0) {
		from_date.style.backgroundColor = "#FFE4E1";
	}
	else {
		result[4] = "true";
	}
	if (to_date.value==0) {
		to_date.style.backgroundColor = "#FFE4E1";
	}
	else {
		result[5] = "true";
	}
	//final check
	if (result[0]!="true" || result[1]!="true" || result[2]!="true" || result[3]!="true" || result[4]!="true" || result[5]!="true") {
		window.alert("Введенные данные не верны, либо поля для обязательного ввода пусты. Пожалуйста, проверьте правильность заполнения подсвеченных полей");
		return false;
	}
	else {
		if (window.confirm("Вы уверены, что введенные данные верны?")) {
			return true;
		}
		else {
			return false;
		}
	}	
}
function check_field_reviews() {
	var user_name = document.getElementById("user_name");
	var mail = document.getElementById("e-mail");
	var text = document.getElementById("message");
	var check = document.getElementById("check");
	var capcha_check = document.getElementById("capcha_check");
	result = ["false", "false", "false", "false"];
	//check for user name
	if (user_name.value!=0) {
		var check_name = /^[А-ЯA-Z]{1}[а-яa-z]{2,12}$/;
		if (!check_name.test(user_name.value)) {
			user_name.style.backgroundColor = "#FFE4E1";
		}
		else {
			result[0] = "true";
		}
	}
	else {
		user_name.style.backgroundColor = "#FFE4E1";	
	}
	//check for mail
	if (mail.value!=0) {
		var check_mail = /^[a-z0-9_\.\-]+@([a-z0-9\-]+\.)+[a-z]{2,4}$/;
		if (!check_mail.test(mail.value)) {
			mail.style.backgroundColor = "#FFE4E1";
		}
		else {
			result[1] = "true";
		}
	}
	else {
		mail.style.backgroundColor = "#FFE4E1";
	}
	//check for text area
	if (text.value==0) {
		text.style.backgroundColor = "#FFE4E1";
	}
	else {
		result[2] = "true";
	}
	//check for capcha
	if (check.value==0 || check.value!=capcha_check.value) {
		check.style.backgroundColor = "#FFE4E1";
	}
	else {
		result[3] = "true";
	}
	//final check
	if (result[0]!="true" || result[1]!="true" || result[2]!="true" || result[3]!="true") {
		window.alert("Введенные данные не верны, либо поля для обязательного ввода пусты. Пожалуйста, проверьте правильность заполнения подсвеченных полей");
		return false;
	}
	else {
		if (window.confirm("Вы уверены, что введенные данные верны?")) {
			return true;
		}
		else {
			return false;
		}
	}	
}
function check_reset() {
		if (window.confirm("Вы уверены, что хотите очистить поля?")) {
			return true;
		}
		else {
			return false;
		}

}
/*--Функция работы с формой КОНЕЦ--*/