//СОБЫТИЯ
$(function(){
	$.datepicker.setDefaults({
		firstDay: 1,
		dateFormat: 'yy-mm-dd',
		dayNames: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
		dayNamesMin: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
		monthNames: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
		duration: 'fast',
		changeYear: true
		
	});
	
	// FEEDBACK
	$("#feedback").fancybox({
		'scrolling'  : 'no',
		'titleShow'  : false
	});
	
	//SUBSCRIBE
	$('#subscribe-add').click(function(){
		var vars = {
			ru : {
				errors : {
					emptyMail : 'Введите e-mail',
					wrongMail : 'E-mail некорректен'
				},
				loading : 'Загрузка',
				enter : 'Подписаться'
			},
			en : {
				errors : {
					emptyMail : 'Enter e-mail',
					wrongMail : 'E-mail is incorrect'
				},
				loading : 'Loading',
				enter : 'Subscribe'
			}
		};
		var that = this;
		var el = $('#subscribe-mail');
		var val = el.val();
		var msg = [];
		if( val=='' || val==el.attr('title') ) msg.push(vars[_LANG_].errors.emptyMail);
		else if( !val.match(/^[\d\w\.-]+@([\d\w-]+)((\.[\w\d-]+)+)?\.\w{2,6}$/) ) msg.push(vars[_LANG_].errors.wrongMail);
		
		if(msg.length>0){
			alert(msg.join("\n"));
			return false;
		}
		$(this).text(vars[_LANG_].loading).attr('disabled', 'disabled');
		$.get(ajaxFile, {go:'subscribe_add', mail:val}, function(html){
			$(that).text(vars[_LANG_].enter).removeAttr('disabled');
			alert(html);
		});
	});
	
	if (window.PIE) {
        $('.pie').each(function() {
            PIE.attach(this);
        });
    }
	jQuery('#acc-menu2').AccordionImageMenu({
		'border' : 0,
		'duration': 800,
		'openDim': 415,
		'closeDim': 240,
		'height': 274,
		'width': 960
	});	
	
	$('#subs').click(
		function() {
			$('#subs_main').is(':hidden') ? $('#subs_main').fadeIn('fast') : $('#subs_main').fadeOut('fast');
			return false;
		}
	);
});

$(function(){
	$('.needClear')
		 .focus(function(){
			  if(this.value==this.title) this.value='';
		 })
		 .blur(function(){
			  if(this.value=='') this.value=this.title;
		 });
});

function checkSearchForm(f){
	var msg = [];
	
	if(f['what'].value=='Поиск по сайту' || f['what'].value=='') msg.push('Введите слово для поиска');
	else if(f['what'].value.length<3) msg.push('Слово для поиска должно быть длиннее 3-х символов');
	
	if(msg.length>0){
		alert(msg.join("\n"));
		return false;
	}
	return true;
}

function newCaptcha(img){
	var randDig=(Math.random()*10)+1|0;
	img.attr('src', '/cms/files/appends/kcaptcha/index.php?rand='+randDig);
	return false;
}

function showteztourSearch() {
	var path = 'http://json.teztour.com/static/ats/';
	var now = new Date();
	var dateTo = new Date();
	dateTo.setDate(now.getDate()+7);
	var monthes = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
	var site=location.hostname;
	var teztourSearchSettings = {
		"fromCountryId":[1102],
		"fromCityId":[345],
		"toCountryId":1104,
		"departureDateMin":( now.getDate() < 10 ? "0"+now.getDate() : now.getDate() )+"."+monthes[now.getMonth()]+"."+now.getFullYear(),
		"departureDateMax":( dateTo.getDate() < 10 ? "0"+dateTo.getDate() : dateTo.getDate() )+"."+monthes[dateTo.getMonth()]+"."+dateTo.getFullYear(),
		"nightsMin":7,
		"nightsMax":15,
		"nightsLimits":[2,20],
		"adults":2,
		"adultsLimits":[1,12],
		"children":0,
		"childrenLimits":[0,12],
		"childrenBirthday":[],
		"priceMin":0,
		"priceMax":9999,
		"currency":5561,
		"findByPrice":true,
		"tourId":[1285],
		"hotelClassId":[9006279, 9006280, 9006281],
		"feedId":[9006288, 9006289],
		"hotelId":[0],
		"hotelInStop":false,
		"noTicketsTo":false,
		"noTicketsFrom":false,
		"locale":"ru",
		"partnerLink":"http://"+site+"/send_order.php"
	}
	var JSON=window.JSON||{};JSON.stringify=JSON.stringify||function(obj){var t=typeof(obj);if(t!="object"||obj===null){if(t=="string")obj='"'+obj+'"';return String(obj);}else{var n,v,json=[],arr=(obj&&obj.constructor==Array);for(n in obj){v=obj[n];t=typeof(v);if(t=="string")v='"'+v+'"';else if(t=="object"&&v!==null)v=JSON.stringify(v);json.push((arr?"":'"'+n+'":')+String(v));}return(arr?"[":"{")+String(json)+(arr?"]":"}");}};var url=path+'search_'+teztourSearchSettings.locale+'.html';return('<iframe id="teztourSearchFrame" width="908" height="464" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" name='+JSON.stringify(teztourSearchSettings)+' src="'+url+'"></iframe>');
};


