function checkForm(form) {
	// Заранее объявим необходимые переменные
	var el, // Сам элемент
	elName, // Имя элемента формы
	value, // Значение
	type; // Атрибут type для input-ов
	// Массив списка ошибок, по дефолту пустой
	var errorList = [];
	// Хэш с текстом ошибок (ключ - ID ошибки)
	var errorText = {
	1 : "Не заполнено поле 'Имя'",
	2 : "Не заполнено поле 'E-mail'",
	3 : "Не заполнено поле 'Телефон'",
	4 : "Неизвестная ошибка"
	}
	// Получаем семейство всех элементов формы
	// Проходимся по ним в цикле
	//form = document.getElementById(frm);
	for (var i = 0; i < form.elements.length; i++) {
	el = form.elements[i];
	elName = el.nodeName.toLowerCase();
	value = el.value;
	if (elName == "input") { // INPUT
	// Определяем тип input-а
	type = el.type.toLowerCase();
	// Разбираем все инпуты по типам и обрабатываем содержимое
	switch (type) {
	case "text" :
	if (el.title != "" && value == "") errorList.push("Не заполнено поле '"+el.title+"'");
	break;
	case "file" :
	//if (value == "") errorList.push(3);
	break;
	case "checkbox" :
	// Ничего не делаем, хотя можем
	break;
	case "radio" :
	// Ничего не делаем, хотя можем
	break;
	default :
	// Сюда попадают input-ы, которые не требуют обработки
	// type = hidden, submit, button, image
	break;
	}
	} else if (el.title != "" && elName == "textarea") { // TEXTAREA
	if (value == "") errorList.push("Не заполнено поле '"+el.title+"'");
	} else if (el.title != "" && elName == "select") { // SELECT
	if (value == 0) errorList.push("Не выбран элемент в поле '"+el.title+"'");
	} else {
	// Обнаружен неизвестный элемент ;)
	}
	}
	// Финальная стадия
	// Если массив ошибок пуст - возвращаем true
	if (!errorList.length) {
		return true;
	}
	// Если есть ошибки - формируем сообщение, выовдим alert
	// и возвращаем false
	var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";
	for (i = 0; i < errorList.length; i++) {
	errorMsg += errorList[i] + "\n";
	}
	alert(errorMsg);
	return false;
}

function switc(obj){
 if(document.getElementById){
 var el = document.getElementById(obj);
  if(el.style.display != "block"){
   el.style.display = "block";
  }else{
   el.style.display = "none";
  }
 }
}

function popUp() {
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
		// IE 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
		// Остальные версии IE
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	var top = document.body.scrollTop;
	var left = document.body.scrollLeft;

	var width = $("#pop_up").width();
	var height = $("#pop_up").height();
	
	var halfX = x /2;
	var halfWidth = width / 2;
	var leftPad = (left + halfX) - halfWidth;

	var halfY = y /2;
	var halfHeight = height / 2;
	var topPad = (top + halfY) - halfHeight;
	//alert(width+'_'+height);
	$("#pop_up").css('top', topPad);
	$("#pop_up").css('left', leftPad);

	//$("div.main").fadeTo("slow", 0.33);
	//$("#pop_up").fadeIn('slow');
	$.dimScreen(500, 0.7, function() {$('#pop_up').fadeIn('fast')});
	return false;
}

var closePopupTimer;
var mdelay = 2000;

function closePopUpTime() {
	closePopupTimer = setTimeout('closePopUp()', mdelay);
}

function closePopUp() {
	clearTimeout(closePopupTimer);
	//$("div.main").fadeTo("normal", 1);
	$('#pop_up').css('display', 'none');
	//$('#pop_up').Puff(500);
    //$('#pop_up').remove();
	$.dimScreenStop();
	return false;
}

function onDimResize() {
	if (self.innerHeight) {
		x = self.innerWidth;
		y = self.innerHeight;
		// IE 6 Strict Mode
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
		// Остальные версии IE
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	var top = document.body.scrollTop;
	var left = document.body.scrollLeft;

	var width = $("#pop_up").width();
	var height = $("#pop_up").height();
	
	var halfX = x /2;
	var halfWidth = width / 2;
	var leftPad = (left + halfX) - halfWidth;

	var halfY = y /2;
	var halfHeight = height / 2;
	var topPad = (top + halfY) - halfHeight;
	//alert(width+'_'+height);
	$("#pop_up").css('top', topPad);
	$("#pop_up").css('left', leftPad);
	jQuery('#__dimScreen').css({
            height: $(document).height() + 'px' //$(document).height()
            ,width: $(document).width() + 'px' //$(document).width()
    });
}

function popup_window(url) 
{
 var width  = 680;
 var height = 800;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

var xajaxRequestUri="/procajax.php";
var xajaxDebug=false;
var xajaxStatusMessages=false;
var xajaxWaitCursor=true;
var xajaxDefinedGet=0;
var xajaxDefinedPost=1;

function processTourForm(){
	var cat = 0;
	var cou = 0;
	iCountry = document.getElementById('chCountry');
	iCategory = document.getElementById('chCategory');
	if (iCountry) {
		cou = iCountry.value;
	}
	if (iCategory) {
		cat = iCategory.value;
	}
	xajax_showTourForm('tourform', cou, cat);
}
function processTourButton(ifrm) {
	if (ifrm.options.selectedIndex != 0) {
		tb = document.getElementById('tourButton');
		tb.disabled = false;
	} else {
		tb = document.getElementById('tourButton');
		tb.disabled = true;
	}
}
function xajax_showTourForm(){
	var xajaxRequestUri="/procajax.php";
	return xajax.call("showTourForm", arguments, 1);
}

function xajax_openOrderTourForm(){
	var xajaxRequestUri="/procajax.php";
	return xajax.call("openOrderTourForm", arguments, 1);
}

function xajax_sendOrderTour(){
	var xajaxRequestUri="/procajax.php";
	return xajax.call("sendOrderTour", arguments, 1);
}

function xajax_updateType(){
	var xajaxRequestUri="/procajax.php";
	return xajax.call("updateType", arguments, 1);
}

function xajax_updateTour(){
	var xajaxRequestUri="/procajax.php";
	return xajax.call("updateTour", arguments, 1);
}

var cur_country = 0;
var cur_type = 0;

function updateType(ob){
	cur_country = ob.options[ob.selectedIndex].value;
	cur_type = 0;
	xajax_updateType(cur_country);
}

function updateTour(ob){
	cur_type = ob.options[ob.selectedIndex].value;
	xajax_updateTour(cur_country, cur_type);
}

//  ------- END XAJAX ---------

