function getRadioGroupValue(radioGroupObj)
{
  for (var i=0; i < radioGroupObj.length; i++)
    if (radioGroupObj[i].checked) return radioGroupObj[i].value;

  return null;
}
$(document).ready(
  function()
  {
		$("td.ed table.a_table tr td:first-child").addClass("nobg");

		// добавляем тень под таблицей
		$("td.ed table.a_table").append('<tr><td colspan="'+$("td.ed table.a_table tr").size()+'" class="b">&nbsp;</td></tr>');

		// добавляем вызов скрипта highslide для ссылок определенного класса
		$("a.add_hs").bind("click", function(){
				hs.expand(this);
				return false;
			}
		);

  }
);
var s;
$(document).ready(
  function()
  {
		// запускаем прокрутку строки на главной
		s = parseInt($("#scroll_line").width())+5;

		if(typeof(v_scroll)!='undefined')
			setTimeout(ScrollLine, t_hold_befor_scroll);
  }
);

function ScrollLine(){

		s_t = s + parseInt($("#scroll_line").css("marginLeft"));
		t = (s_t/v_scroll)*1000;
		$("#scroll_line").animate({ marginLeft: (s*(-1))+"px" }, t, "linear", function(){$(this).css("marginLeft","645px"); ScrollLine();});

}

function OpenAskForm() {
     var tmp = document.getElementById("send_form_cont");
     tmp.style.display = "block";
     return false;
}
function OpenClubForm() {
     var tmp = document.getElementById("club_form_cont");
     tmp.style.display = "block";
     return false;
}
function ScreenSize(){
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    myTop = window.pageYOffset;
    myLeft = window.pageXOffset;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    myTop = document.documentElement.scrollTop;
    myLeft = document.documentElement.scrollLeft;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    myTop = document.body.scrollTop;
    myLeft = document.body.scrollLeft;
  }
}
function CheckForm(mf) {
  var error=0;
  if (error==0 && mf.fio.value=='') {
    alert('Заполните, пожалуйста, поле \"ФИО\"');
		mf.fio.focus();
		error=1;
  }
	if (error==0 && (mf.phone.value=='' || mf.phone.value.match(/[^\d \-()\+]+/i))) {
    alert('Введите, пожалуйста, корректный номер телефона');
	  mf.phone.select();
		mf.phone.focus();
	  error=1;
  }
	if (error==0 && !mf.email.value.match(/^\s*[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
    alert('Заполните, пожалуйста, поле \"e-mail\" корректным e-mail адресом');
		mf.email.select();
		mf.email.focus();
		error=1;
  }
	if (error==0 && mf.about.value=='') {
		alert('Введите, пожалуйста, ваше сообщение');
		mf.about.focus();
		error=1;
  }
	if (error==0 && !mf.code.value.match(/^\d{4}$/)) {
    alert('Введите, пожалуйста, четыре цифры кода');
	  mf.code.select();
		mf.code.focus();
	  error=1;
  }
  if (error==0) {
    //mf.submit();
		script = document.createElement("script");
		script.src = "/sendmail.phtml?fio="+mf.fio.value+"&email="+mf.email.value+"&phone="+mf.phone.value+"&about="+mf.about.value+"&code="+mf.code.value+"&ref="+escape(location.href);
		document.body.appendChild(script);
  }
	return false;
}
function CloseForm() {
	document.getElementById('send_form_cont').style.display = 'none';
	document.zakaz.reset();
	document.getElementById('captcha').src='/captcha.php?id='+(Math.round(10000*Math.random()));
}
function CheckClubForm(mf) {
card = getRadioGroupValue(mf.card);
  var error=0;
  if (error==0 && mf.fio.value=='') {
    alert('Заполните, пожалуйста, поле \"ФИО\"');
		mf.fio.focus();
		error=1;
  }
	if (error==0 && (mf.phone.value=='' || mf.phone.value.match(/[^\d \-()\+]+/i))) {
    alert('Введите, пожалуйста, корректный номер телефона');
	  mf.phone.select();
		mf.phone.focus();
	  error=1;
  }
	if (error==0 && !mf.email.value.match(/^\s*[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
    alert('Заполните, пожалуйста, поле \"e-mail\" корректным e-mail адресом');
		mf.email.select();
		mf.email.focus();
		error=1;
  }
	if (error==0 && mf.about.value=='') {
		alert('Введите, пожалуйста, ваше сообщение');
		mf.about.focus();
		error=1;
  }
	if (error==0 && !mf.code.value.match(/^\d{4}$/)) {
    alert('Введите, пожалуйста, четыре цифры кода');
	  mf.code.select();
		mf.code.focus();
	  error=1;
  }
  if (error==0) {
    //mf.submit();
		script = document.createElement("script");
		script.src = "/sendmail2.phtml?fio="+mf.fio.value+"&email="+mf.email.value+"&phone="+mf.phone.value+"&about="+mf.about.value+"&card="+card+"&code="+mf.code.value+"&ref="+escape(location.href);
		document.body.appendChild(script);
  }
	return false;
}
function CloseClubForm() {
	document.getElementById('club_form_cont').style.display = 'none';
	document.getElementById('club_form_cont_iframe').style.display = 'none';
	document.zakaz.reset();
	document.getElementById('captcha2').src='/captcha.php?id='+(Math.round(10000*Math.random()));
}

var j=0;
function OpenCitiesPhAlbum() {
	var tmp = document.getElementById("pc");
//	ScreenSize();
//	if(myHeight>577)
//		tmp.style.top = (myHeight/2+myTop-290) + "px";
//	else
//		tmp.style.top = myTop + "px";
		tmp.style.top =0;
		tmp.style.left =0;
	j=0;
	ChangePhoto(j);
	tmp.style.display = "block";

	// привязываем событие - закрытие окна по Escape
	$("body").bind('keydown', CloseOnEsc);

	return false;
}
function CloseOnEsc(event) {
	if(event.keyCode==27)
		CloseCitiesPhAlbum();
	else if(event.keyCode==39)
		NextPhoto();
	else if(event.keyCode==37)
		PrevPhoto();

	return false;
}
function CloseCitiesPhAlbum() {
	document.getElementById('pc').style.display = 'none';
	// удаляем событие - закрытие окна по Escape
	$("body").unbind('keydown', CloseOnEsc);
	return false;
}

function NextPhoto() {
	j++;
	if(j<photosList.length) {
		ChangePhoto(j);
	}
	else
		j=photosList.length-1;

	return false;
}
function PrevPhoto() {
	j--;
	if(j>=0) {
		ChangePhoto(j);
	}
	else
		j=1;
	return false;
}
function FirstPhoto() {
		ChangePhoto(0);
		j=0;
		return false;
}
function LastPhoto() {
		ChangePhoto(photosList.length-1);
		j=photosList.length-1;
		return false;
}
function ChangePhoto(index) {
document.getElementById("cc").src=photosList[index][1];
if(photosList[index][2]>'560px')document.getElementById("cc").style.width='560px';else document.getElementById("cc").style.width='';
$("#fnt").empty();
$("#fnt").text('Фото '+(index+1)+' из '+photosList.length);
}

function CheckUserQuestionForm(mf) {
  var error=0;
  if (mf.fio.value=='' && error==0) {
    alert('Введите, пожалуйста, Ваше имя');
		mf.fio.focus();
		error=1;
  }
	if (error==0 && mf.email.value!='' && !mf.email.value.match(/^\s*[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
    alert('Заполните, пожалуйста, поле \"e-mail\" корректным e-mail адресом');
		mf.email.select();
		mf.email.focus();
		error=1;
  }
	if (error==0 && mf.about.value=='') {
		alert('Введите, пожалуйста, ваше сообщение');
		mf.about.focus();
		error=1;
  }
	if (error==0 && !mf.code2.value.match(/^\d{4}$/)) {
    alert('Введите, пожалуйста, четыре цифры кода');
	  mf.code2.select();
		mf.code2.focus();
	  error=1;
  }
  if (error==0) {
		//mf.submit();
		script = document.createElement("script");
		script.src = "/user_question.phtml?fio="+mf.fio.value+"&email="+mf.email.value+"&city="+mf.city.value+"&about="+mf.about.value+"&code="+mf.code2.value;
		document.body.appendChild(script);

  }
	return false;
}

function AddRow() {  
  c++;
	tr = '<tr><td><input class="input_text" name="pass_fio[]" value="" /></td><td><input class="input_text" style="width: 80px;" name="pass_birthday[]" value="" /></td><td><a href="#" onClick="RemoveRow(this); return false;"><img align="absmiddle" src="/i/remove_row.gif" width="19px" height="18px" alt="удалить" /></a></td></tr>';
  $("table#passengers").append(tr);
  
}

function RemoveRow(obj) {
  
	if (c == 0) {
		$("table#passengers td input[type='text']").attr("value","");
    return false;
  }
	else c--;
  
  document.getElementById("passengers").getElementsByTagName('TBODY')[0].deleteRow(obj.parentNode.parentNode.sectionRowIndex);
  
  return false;
}

function CheckAviaForm(mf) {
  var error=0;  
  if (error==0 && mf.fio.value=='') {
    alert('Введите, пожалуйста, имя контактного лица');
		mf.fio.focus();
		error=1;
  }
	if (error==0 && (mf.phone.value=='' || mf.phone.value.match(/[^\d \-()\+]+/i))) {
    alert('Введите, пожалуйста, корректный номер телефона');
	  mf.phone.select();
		mf.phone.focus();
	  error=1;
  }	
	if (error==0 && !mf.email.value.match(/^\s*[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
    alert('Заполните, пожалуйста, поле \"e-mail\" корректным e-mail адресом');
		mf.email.select();
		mf.email.focus();
		error=1;
  }
	if (error==0 && mf.route.value=='') {
		alert('Введите, пожалуйста, маршрут');
		mf.route.focus();
		error=1;
  }
	if (error==0 && mf.date_departure.value=='') {
		alert('Введите, пожалуйста, дату отправления');
		mf.date_departure.focus();
		error=1;
  }
	if (error==0 && !mf.code3.value.match(/^\d{4}$/)) {
    alert('Введите, пожалуйста, четыре цифры кода');
	  mf.code3.select();
		mf.code3.focus();
	  error=1;
  }
  if (error==0) {		
		return true;		
  }
	return false;
}

function CheckAviaCharterForm(mf) {
  
	var error=0;
  if (error==0) {
		for(i=0;i<2;i++) {
			if(mf['departure_from['+i+']'].value=='') {
				alert('Введите, пожалуйста, город/аэропорт вылета');
				mf['departure_from['+i+']'].focus();
				error=1;
				break;
			}
			if(mf['arrival_to['+i+']'].value=='') {
				alert('Введите, пожалуйста, город/аэропорт назначения');
				mf['arrival_to['+i+']'].focus();
				error=1;
				break;
			}
			if(mf['date_departure1['+i+']'].value=='') {
				alert('Введите, пожалуйста, начальную предполагаемую дату вылета');
				mf['date_departure1['+i+']'].focus();
				error=1;
				break;
			}
			if(mf['date_departure2['+i+']'].value=='') {
				alert('Введите, пожалуйста, конечную предполагаемую дату вылета');
				mf['date_departure2['+i+']'].focus();
				error=1;
				break;
			}			
		}
	}
	if (error==0 && mf.num_passenger.value=='') {
		alert('Введите, пожалуйста, количество пассажиров');
		mf.num_passenger.focus();
		error=1;
  }
	if (error==0 && mf.fio.value=='') {
    alert('Введите, пожалуйста, имя контактного лица');
		mf.fio.focus();
		error=1;
  }
	if (error==0 && (mf.phone.value=='' || mf.phone.value.match(/[^\d \-()\+]+/i))) {
    alert('Введите, пожалуйста, корректный номер телефона');
	  mf.phone.select();
		mf.phone.focus();
	  error=1;
  }	
	if (error==0 && !mf.email.value.match(/^\s*[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
    alert('Заполните, пожалуйста, поле \"e-mail\" корректным e-mail адресом');
		mf.email.select();
		mf.email.focus();
		error=1;
  }
	if (error==0 && !mf.code3.value.match(/^\d{4}$/)) {
    alert('Введите, пожалуйста, четыре цифры кода');
	  mf.code3.select();
		mf.code3.focus();
	  error=1;
  }
  if (error==0) {		
		return true;		
  }
	return false;
}

function CheckIncentiveForm(mf) {	
	var error=0;  
  if (error==0 && mf.company.value=='') {
		alert('Введите, пожалуйста, название компании');
		mf.company.focus();
		error=1;
  }
  if (error==0 && mf.fio.value=='') {
    alert('Введите, пожалуйста, имя контактного лица');
		mf.fio.focus();
		error=1;
  }
	if (error==0 && (mf.phone.value=='' || mf.phone.value.match(/[^\d \-()\+]+/i))) {
    alert('Введите, пожалуйста, корректный номер телефона');
	  mf.phone.select();
		mf.phone.focus();
	  error=1;
  }	
	if (error==0 && (mf.fax.value=='' || mf.fax.value.match(/[^\d \-()\+]+/i))) {
    alert('Введите, пожалуйста, корректный номер факса');
	  mf.fax.select();
		mf.fax.focus();
	  error=1;
  }	
	if (error==0 && !mf.email.value.match(/^\s*[a-zA-Z0-9._-]+\@[^\s:,]+\.[^\s:,]+$/i)) {
    alert('Заполните, пожалуйста, поле \"e-mail\" корректным e-mail адресом');
		mf.email.select();
		mf.email.focus();
		error=1;
  }
  if (error==0 && mf.country.value=='') {
		alert('Введите, пожалуйста, страну проведения мероприятия');
		mf.country.focus();
		error=1;
  }
  if (error==0 && mf.members_num.value=='') {
		alert('Введите, пожалуйста, количество участников');
		mf.members_num.focus();
		error=1;
  }
  if (error==0 && mf.budget_total.value=='') {
		alert('Введите, пожалуйста, общий бюджет');
		mf.budget_total.focus();
		error=1;
  }

	if (error==0 && !mf.code4.value.match(/^\d{4}$/)) {
    alert('Введите, пожалуйста, четыре цифры кода');
	  mf.code3.select();
		mf.code3.focus();
	  error=1;
  }
  if (error==0) {		
		return true;		
  }
	return false;
}

		//  to hide script contents from old browsers
		var startDate;
		var endDate;

		function resetDates() {
			startDate = endDate = null;
		}


		function filterDates2(cal) {
			var date = cal.date;
			endDate = new Date(cal.date)
			endDate.setHours(0,0,0,0)	// used for compares without TIME
		}

		/*
		* This functions return true to disallow a date
		* and false to allow it.
		*/


		/* 
		* Check-Out calendar allowed dates
		* Check-Out date can not be BEFORE Check-In date
		* Check-Out date can not be before today
		*/
		function disallowDateBefore(dateCheckOut) {
			dateCheckOut.setHours(0,0,0,0)
			if ((startDate != null) && startDate > dateCheckOut)
				// startDate is defined, make sure cal date is NOT before start date
				return true; 
			
			var now = new Date()
			now.setHours(0,0,0,0)
			if (dateCheckOut < now) 
				// check out date can not be befor today if startDate NOT defined
				return true;

			return false;
		}

		/* 
		* Check-In date checking
		* Check-In date can not be AFTER Check-Out date
		* Check-In date can not be before today
		*/
		function disallowDateAfter(dateCheckIn) {
			dateCheckIn.setHours(0,0,0,0)
			if ((endDate != null) && dateCheckIn > endDate)
				// endDate defined, calendar date can NOT be after endDate
				return true;

			var now = new Date()
			now.setHours(0,0,0,0)

			if (dateCheckIn < now)
				// endDate NOT defined, calendar date can not be before today
				return true;

			return false;
		}

		// end hiding contents from old browsers  -->
		

function reg_event(event) {//обработка события
	alert(event.keyCode); // стрелка в лево     
  event.preventDefault(); //запрет на дальнейшее распространение
  return false; //возвращаем false
}
/*
//Установка обработчика события (http://netfaq.ru/java/get_key_controll_Java_Script)
if (document.addEventListener) { // FF и другие
        document.addEventListener('keydown', reg_event,false);
}
if (htmlElement.attachEvent) { // специально для MSIE 
        htmlElement.attachEvent('keydown',reg_event);
}*/
