function hideFormText() {
	return;
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);
var _selectHeight = 29;

var _forms = document.getElementsByTagName('form');
var inputs = new Array();
var selects = new Array();
var labels = new Array();
var radios = new Array();
var radioLabels = new Array();
var checkboxes = new Array();
var checkboxLabels = new Array();
var buttons = new Array();
var selects = new Array();
var all_selects = false;
var active_select = null;
var agt = navigator.userAgent.toLowerCase();
var selectText = "please select";
var IN_CFORMS = true;

var fullSearchIterNum = 0; // Для расширенного поиска количество итераций
var fullSearchLastCount = 0; // Последнее найденное количество туров
var fullSearchLastSession = '';
var fullsearchResult = false;


var searchHotelIterNum = 0; // Для обычного поиска количество итераций
var searchHotelLastCount = 0; // Последнее найденное количество туров
var searchHotelLastSession = '';
var searchHotelResult = false;

var searchIterNum = 0; // Для обычного поиска количество итераций
var searchLastCount = 0; // Последнее найденное количество туров
var searchLastSession = '';
var searchResult = false;
var searchStop = false;
var slider_runner  = false;
var is_search = false;

function initCustomForms() {
	if(!document.getElementById) {return false;}
	getElements();
	separateElements();
	replaceRadios();
	replaceCheckboxes();
	replaceSelects();

	var _selects = document.getElementsByTagName('select');
	var _SelctClassName = [];
	if (_selects) {
		for (var i = 0; i < _selects.length; i++) {
			if (_selects[i].className != '' && _selects[i].className != 'outtaHere')
				_SelctClassName[i] = ' drop-'+_selects[i].className;
		}
		for (var i = 0; i < _SelctClassName.length; i++) {
			var _selectDrop = document.getElementById('optionsDiv'+i);
			if (_selectDrop) {
				if (_SelctClassName[i]) 
					_selectDrop.className += _SelctClassName[i];
			}
		}
	}
}


// getting all the required elements
function getElements() {
	for (var nf = 0; nf < document.getElementsByTagName("form").length; nf++) {
		for(var nfi = 0; nfi < document.forms[nf].getElementsByTagName("input").length; nfi++) {inputs.push(document.forms[nf].getElementsByTagName("input")[nfi]);}
		for(var nfl = 0; nfl < document.forms[nf].getElementsByTagName("label").length; nfl++) {labels.push(document.forms[nf].getElementsByTagName("label")[nfl]);}
		for(var nfs = 0; nfs < document.forms[nf].getElementsByTagName("select").length; nfs++) {selects.push(document.forms[nf].getElementsByTagName("select")[nfs]);}
	}
}

// separating all the elements in their respective arrays
function separateElements() {
	var r = 0; var c = 0; var t = 0; var rl = 0; var cl = 0; var tl = 0; var b = 0;
	for (var q = 0; q < inputs.length; q++) {
		if(inputs[q].type == "radio") {
			radios[r] = inputs[q]; ++r;
			for(var w = 0; w < labels.length; w++) {
				if((inputs[q].id) && labels[w].htmlFor == inputs[q].id)
				{
					radioLabels[rl] = labels[w];
					++rl;
				}
			}
		}
		if(inputs[q].type == "checkbox") {
			checkboxes[c] = inputs[q]; ++c;
			for(var w = 0; w < labels.length; w++) {
				if((inputs[q].id) && (labels[w].htmlFor == inputs[q].id))
				{
					checkboxLabels[cl] = labels[w];
					++cl;
				}
			}
		}
		if((inputs[q].type == "submit") || (inputs[q].type == "button")) {
			buttons[b] = inputs[q]; ++b;
		}
	}
}

//replacing radio buttons
function replaceRadios() {
	for (var q = 0; q < radios.length; q++) {
		radios[q].className += " outtaHere";
		var radioArea = document.createElement("div");
		if(radios[q].checked) {
			radioArea.className = "radioAreaChecked";
		}
		else
		{
			radioArea.className = "radioArea";
		}
		radioArea.id = "myRadio" + q;
		radios[q].parentNode.insertBefore(radioArea, radios[q]);
		radios[q]._ra = radioArea;

		radioArea.onclick = new Function('rechangeRadios('+q+')');
		if (radioLabels[q])
		{
			radioLabels[q].onclick = new Function('rechangeRadios('+q+')');
		}
	}
	return true;
}

//checking radios
function checkRadios(who) {
	var what = radios[who]._ra;
	for(var q = 0; q < radios.length; q++) {
		if((radios[q]._ra.className == "radioAreaChecked")&&(radios[q]._ra.nextSibling.name == radios[who].name))
		{
			radios[q]._ra.className = "radioArea";
		}
	}
	what.className = "radioAreaChecked";
}

//changing radios
function changeRadios(who) {
	if(radios[who].checked) {
		for(var q = 0; q < radios.length; q++) {
			if(radios[q].name == radios[who].name) {
				radios[q].checked = false;
			} 
			radios[who].checked = true; 
			checkRadios(who);
		}
	}
}

//rechanging radios
function rechangeRadios(who) {
	if(!radios[who].checked) {
		for(var q = 0; q < radios.length; q++) {
			if(radios[q].name == radios[who].name)	{
				radios[q].checked = false; 
			}
			radios[who].checked = true; 
			checkRadios(who);
		}
	}
}

//replacing checkboxes
function replaceCheckboxes() {
	for (var q = 0; q < checkboxes.length; q++) {
		checkboxes[q].className += " outtaHere";
		var checkboxArea = document.createElement("div");
		if(checkboxes[q].checked) {
			checkboxArea.className = "checkboxAreaChecked";
		}
		else {
			checkboxArea.className = "checkboxArea";
		}
		checkboxArea.id = "myCheckbox" + q;
		checkboxes[q].parentNode.insertBefore(checkboxArea, checkboxes[q]);
		checkboxes[q]._ca = checkboxArea;
		checkboxArea.onclick = checkboxArea.onclick2 = new Function('rechangeCheckboxes('+q+')');
		if (checkboxLabels[q])
		{
			checkboxLabels[q].onclick = new Function('changeCheckboxes('+q+')');
		}
		
		checkboxes[q].onkeydown = checkEvent;
	}
	return true;
}
//checking checkboxes
function checkCheckboxes(who, action) {
	var what = checkboxes[who]._ca;
	if(action == true) {
		what.className = "checkboxAreaChecked";
		what.checked = true;
	}
	if(action == false) {
		what.className = "checkboxArea";
		what.checked = false;
	}
}

//changing checkboxes
function changeCheckboxes(who) {
	if(checkboxes[who].checked) {
		checkCheckboxes(who, false);
	}
	else {
		checkCheckboxes(who, true);
	} 
}

//rechanging checkboxes
function rechangeCheckboxes(who) {
	var tester = false;
	if(checkboxes[who].checked == true) {
		tester = false;
	}
	else {
		tester = true;
	}
	checkboxes[who].checked = tester;
	checkCheckboxes(who, tester);
}
//check event
function checkEvent(e) {
	if (!e) var e = window.event;
	if(e.keyCode == 32) {for (var q = 0; q < checkboxes.length; q++) {if(this == checkboxes[q]) {changeCheckboxes(q);}}} //check if space is pressed
}


function replaceSelects() {
	for(var q = 0; q < selects.length; q++) {
	if (!selects[q].replaced && selects[q].offsetWidth)
	{
		selects[q]._number = q;
		//create and build div structure
		var selectArea = document.createElement("div");
		var left = document.createElement("span");
		left.className = "left";
		selectArea.appendChild(left);
		
		var disabled = document.createElement("span");
		disabled.className = "disabled";
		selectArea.appendChild(disabled);
		
		selects[q]._disabled = disabled;
		var center = document.createElement("span");
		var button = document.createElement("a");
		var text = document.createTextNode(selectText);
		center.id = "mySelectText"+q;
		
		var stWidth = selects[q].offsetWidth;
		selectArea.style.width = stWidth + "px";
		if (selects[q].parentNode.className.indexOf("type2") != -1){
			button.href = "javascript:showOptions("+q+",true)";
		} else {
			button.href = "javascript:showOptions("+q+",false)";
		}
		button.className = "selectButton";
		selectArea.className = "selectArea";

		selectArea.className += " " + selects[q].className;
		selectArea.id = "sarea"+q;
		center.className = "center";
		center.appendChild(text);
		selectArea.appendChild(center);
		selectArea.appendChild(button);
		
		//hide the select field
		selects[q].className += " outtaHere";
		//insert select div
		selects[q].parentNode.insertBefore(selectArea, selects[q]);
		//build & place options div

		var optionsDiv = document.createElement("div");
		
		var optionsList = document.createElement("ul");
		optionsDiv.innerHTML += "<div class='select-top'><div></div></div>";
		optionsDiv.appendChild(optionsList);
		
		selects[q]._options = optionsList;
		
		optionsDiv.style.width = stWidth + "px";
		optionsDiv._parent = selectArea;
		
		optionsDiv.className = "optionsDivInvisible";
		optionsDiv.id = "optionsDiv"+q;
		
	
		populateSelectOptions(selects[q]);
		optionsDiv.innerHTML += "<div class='select-bottom'><div class='select-bottom-left'></div><div class='select-bottom-right'></div></div>";
		document.getElementsByTagName("body")[0].appendChild(optionsDiv);
		selects[q].replaced = true;
		}
	all_selects = true;
	}
}

//collecting select options
function populateSelectOptions(me) {
	me._options.innerHTML = "";
	
	for(var w = 0; w < me.options.length; w++) {
		
		var optionHolder = document.createElement('li');
		var optionLink = document.createElement('a');
		var optionTxt;
		if (me.options[w].title.indexOf('image') != -1) {
			optionTxt = document.createElement('img');
			optionSpan = document.createElement('span');
			optionTxt.src = me.options[w].title;
			optionSpan = document.createTextNode(me.options[w].text);
		} else {
			optionTxt = document.createTextNode(me.options[w].text);
		}
		
		optionLink.href = "javascript:showOptions("+me._number+"); selectMe('"+me.id+"',"+w+","+me._number+");";
		if (me.options[w].title.indexOf('image') != -1) {
			optionLink.appendChild(optionTxt);
			optionLink.appendChild(optionSpan);
		} else {
			optionLink.appendChild(optionTxt);
		}
		optionHolder.appendChild(optionLink);
		me._options.appendChild(optionHolder);
		//check for pre-selected items
		if(me.options[w].selected) {
			selectMe(me.id,w,me._number);
		}
	}
	if (me.disabled) {
		me._disabled.style.display = "block";
	}
	else {
		me._disabled.style.display = "none";
	}
}
//selecting me
function selectMe(selectFieldId,linkNo,selectNo) {
    
	if(selectFieldId == 'city-holder-select')
    {
        if(linkNo == '0')
        {
            document.getElementById('linkMetro').style.display = "block";
            document.getElementById('linkMetroPiter').style.display = "none";
        }
            
        if(linkNo == '1')
        {
            document.getElementById('linkMetro').style.display = "none";
            document.getElementById('linkMetroPiter').style.display = "block";
        }
                    
    }
    
	selectField = selects[selectNo];
	for(var k = 0; k < selectField.options.length; k++) {
		if(k==linkNo) {
			selectField.options[k].selected = true;
		}
		else {
			selectField.options[k].selected = false;
		}
	}

	if($(selectField).change) {
		$(selectField).change();
	} else if ($(selectField).onchange) {
		$(selectField).onchange();
	}
	if (selectFieldId == 'country_id')
	{
		//curval = $('#country_id :selected').val();
		if ($('#country_id :selected').val() == 'all')
			showCountries();
		
		
	}
	if (selectFieldId == 'city-holder-select')
	{
		//curval = $('#country_id :selected').val();
		if ($('#city-holder-select :selected').val() != 'all')
			updateDefaultCity($('#city-holder-select :selected').val());	
	}
    
    	
	//show selected option
	textVar = document.getElementById("mySelectText"+selectNo);
	var newText;
	var optionSpan;
	if (selectField.options[linkNo].title.indexOf('image') != -1) {
		newText = document.createElement('img');
		newText.src = selectField.options[linkNo].title;
		optionSpan = document.createElement('span');
		optionSpan = document.createTextNode(selectField.options[linkNo].text);
	} else {
		newText = document.createTextNode(selectField.options[linkNo].text);
	}
	if (selectField.options[linkNo].title.indexOf('image') != -1) {
		if (textVar.childNodes.length > 1) textVar.removeChild(textVar.childNodes[0]);
		textVar.replaceChild(newText, textVar.childNodes[0]);	
		textVar.appendChild(optionSpan);	
	} else {
		if (textVar.childNodes.length > 1) textVar.removeChild(textVar.childNodes[0]);
		textVar.replaceChild(newText, textVar.childNodes[0]);	
	}
	if (selectField.onchange && all_selects)
		{
			eval(selectField.onchange());
		}
}

function showCountries()
{
        $.fancybox.showActivity();
        $.get(baseUrl + '/index/allcountries', function(data) {
          $.fancybox({content:data});
        });
        
        return false;
        /*    
		width = 600;
		height = 400;
		$.fancybox(
		{
			'width': width,
			'type':'inline',
			'height': height,
			'autoScale': false,
			'content':'index/allcountries',
			'onComplete': function()
			{
				//alert('df');
			}
		});*/
	
}


function updateDefaultCity(city) {
	
	$.ajax({
			url:	 '/search/setcity', 
			type:	 'POST',
			data: {city_id : city},
			dataType: "json",
			complete: function(jq, status){
				
			},
			success: function(response){
				
			}
	});  
	
}
//showing options
function showOptions(g) {
		_elem = document.getElementById("optionsDiv"+g);
		var divArea = document.getElementById("sarea"+g);
		if (active_select && active_select != _elem) {
			active_select.className = active_select.className.replace('optionsDivVisible',' optionsDivInvisible');
			active_select.style.height = "auto";
		}
		if(_elem.className.indexOf("optionsDivInvisible") != -1) {
			_elem.style.left = "-9999px";
			_elem.style.top = findPosY(divArea) + _selectHeight + 'px';
			_elem.className = _elem.className.replace('optionsDivInvisible','');
			_elem.className += " optionsDivVisible";
			/*if (_elem.offsetHeight > 200)
			{
				_elem.style.height = "200px";
			}*/
			_elem.style.left = findPosX(divArea) + 'px';
			
			active_select = _elem;
			if(document.documentElement)
			{
				document.documentElement.onclick = hideSelectOptions;
			}
			else
			{
				window.onclick = hideSelectOptions;
			}
		}
		else if(_elem.className.indexOf("optionsDivVisible") != -1) {
			_elem.style.height = "auto";
			_elem.className = _elem.className.replace('optionsDivVisible','');
			_elem.className += " optionsDivInvisible";
		}
		
		// for mouseout
		/*_elem.timer = false;
		_elem.onmouseover = function() {
			if (this.timer) clearTimeout(this.timer);
		}
		_elem.onmouseout = function() {
			var _this = this;
			this.timer = setTimeout(function(){
				_this.style.height = "auto";
				_this.className = _this.className.replace('optionsDivVisible','');
				if (_elem.className.indexOf('optionsDivInvisible') == -1)
					_this.className += " optionsDivInvisible";
			},200);
		}*/
}

function isElementBefore(_el,_class)
{
	var _parent = _el;	
	do
	{
		_parent = _parent.parentNode;
	}
	while(_parent && _parent.className != null && _parent.className.indexOf(_class) == -1)
	
	if(_parent.className && _parent.className.indexOf(_class) != -1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function BuyNow() {
	$('#buynow').val(1);
	$('#ordertour').submit();	
}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}

function hideSelectOptions(e)
{
	if(active_select)
	{
		if(!e) e = window.event;
		var _target = (e.target || e.srcElement);
		if(isElementBefore(_target,'selectArea') == 0 && isElementBefore(_target,'optionsDiv') == 0)
		{
			active_select.className = active_select.className.replace('optionsDivVisible', '');
			active_select.className = active_select.className.replace('optionsDivInvisible', '');
			active_select.className += " optionsDivInvisible";
			active_select = false;

			if(document.documentElement)
			{
				document.documentElement.onclick = function(){};
			}
			else
			{
				window.onclick = null;
			}
		}
	}
}

function addZero(i) {
return (i < 10)? "0" + i: i;
}

function SearchTour() {
	var data=$('#searchtourform').serialize();
	if(!document.getElementById('fFullsearch'))  {
		$('#searchingtours_rsp').toggle();
		$('#searchtourform-submit').attr('disabled','disabled');
		if (searchResult) 
			searchResult.abort();
		searchResult = $.ajax({
			type: 'POST',
			data: data,
			url: baseUrl+'/search/search-tours',
			dataType:'json',
			//context: document.body,
			complete: function(jq, status){
				$('#searchingtours_rsp').toggle();
				$('#searchtourform-submit').attr('disabled','');
				searchResult = false;
			},
			success: function(data){
				if (data) {
					if (data['result'])
						$('#searchtourform-result').html(data['result']);
					if (data['session'] != searchLastSession || !data['session'])
					{
						searchLastCount = 0;
						searchIterNum = 0;
					}
					
					if (data['state']=='search' || (data['session'] && data['state']!='finished')) {
						
						if (searchLastCount == data['count'])
							searchIterNum++;
								
						searchLastCount = data['count'];
						
						searchLastSession = data['session'];
						if(data['count'])
							$('#findtours').html(data['count']);
						if ( (searchIterNum < 4 && searchLastCount) || (searchIterNum < 8 && !searchLastCount))
						{	
							$('#sf_session').val(data['session']);
							searchResult = false;
							SearchTour();
						}
						else if(!searchLastCount) {
							$('#searchtourform-result').html('<p style="text-align:center;font-weight: bold;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
						}
					}
	
				}else {
					if (searchStop) {
						//$('#searchingtours_rsp').toggle();
					}
					else
						$('#searchtourform-result').html('<p style="text-align:center;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
				}
			}
		});
	}
	else {
		var data2 = $('#fullsearchoptionsform').serialize();
		$('#fullsearchprogress').toggle();
		$('#fancybox-overlay').toggle();
		$('#searchtourform-submit').attr('disabled','disabled');
		if (fullsearchResult) 
			fullsearchResult.abort();
		fullsearchResult = $.ajax({
			type: 'POST',
			data: data+'&'+data2,
			url: baseUrl+'/search/full-search-tours',
			dataType:'json',
			//context: document.body,
			complete: function(jq, status){
				$('#fullsearchprogress').toggle();
				$('#searchtourform-submit').attr('disabled','');
				$('#fancybox-overlay').toggle();
				fullsearchResult = false;
			},
			success: function(res){
				if (res) {
					if (res['result'])
						$('#content').html(res['result']);
						
					if (res['session'] != fullSearchLastSession || !res['session'])
					{
						fullSearchLastCount = 0;
						fullSearchIterNum = 0;
					}
						
					if (res['state']=='search' || (res['session'] && res['state']!='finished')) {
						
						if (fullSearchLastCount == res['count'])
							fullSearchIterNum++;
								
						fullSearchLastCount = res['count'];
						
						fullSearchLastSession = res['session'];
						if ( (fullSearchIterNum < 4 && fullSearchLastCount) || (fullSearchIterNum < 8 && !fullSearchLastCount))
						{	
							$('#sf_session').val(res['session']);
							fullsearchResult = false;
							SearchTour();
						}
						else if(!fullSearchLastCount) {
							$('#content').html('<p style="text-align:center;font-weight: bold;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
						}
					}
				}else
					$('#content').html('<p style="text-align:center;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
			}
		});
	}
	
	return false;
}
function SearchHotelPrices() {
	var searchdata=$('#search-hotel-prices').serialize();
	$('#searching_rsp').toggle();
	$('#planner-submit').attr('disabled','disabled');
	if (searchHotelResult) 
		searchHotelResult.abort();
	$.ajax({
		type: 'POST',
		data: searchdata,
		timeout: 240000,
		dataType:'json',
		url: baseUrl+'/search/hotel-prices',
		//context: document.body,
		complete: function(jq, status){
			$('#searching_rsp').toggle();
			$('#planner-submit').attr('disabled','');
		},
		success: function(data){
			if (data) {
					if (data['result'])
						$('#searchhotelprices').html(data['result']);
					if (data['session'] != searchHotelLastSession || !data['session'])
					{
						searchHotelLastCount = 0;
						searchHotelIterNum = 0;
					}
					
					if (data['state']=='search' || (data['session'] && data['state']!='finished')) {
						
						if (searchHotelLastCount == data['count'])
							searchHotelIterNum++;
								
						searchHotelLastCount = data['count'];
						
						searchHotelLastSession = data['session'];
						if(data['count'])
							$('#findtours').html(data['count']);
						if ( (searchHotelIterNum < 4 && searchHotelLastCount) || (searchHotelIterNum < 40 && !searchHotelLastCount))
						{	
							$('#shp_session').val(data['session']);
							searchHotelResult = false;
							SearchHotelPrices();
						}
						else if(!searchHotelLastCount) {
							$('#searchhotelprices').html('<p style="text-align:center;font-weight: bold;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
						}
					}
	
				}else
					$('#searchhotelprices').html('<p style="text-align:center;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
					
			/*if (data) {
				if (data['result'])
					$('#searchhotelprices').html(data['result']);			
				if (data['state']=='search' || (data['session'] && data['state']!='finished')) {
					$('#shp_session').val(data['session']);
					SearchHotelPrices();
				}
			}
			else
				$('#searchhotelprices').html('<p style="text-align:center;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');*/
		},
		error: function(jq, status, err){
			$('#searchhotelprices').html('<p style="text-align:center;">Извините, по вашему запросу ничего не найдено, попробуйте повторить поиск позже</p>');
		}
	});
	
	
	
	return false;
}
function toPricesHotel() {
	            
     // Figure out current list via CSS class
	 el = $("div#main");
     var curList = el.find("a.current").attr("href").substring(1);
     $newList = $('a[href=#tab-2]');
                    
     
     listID = $newList.attr("href").substring(1),
                
     
     $allListWrap = el.find(".list-wrap"),
     curListHeight = $allListWrap.height();
     $allListWrap.height(curListHeight);
                                        
     if ((listID != curList) && ( el.find(":animated").length == 0)) {
                                            
                    // Fade out current list
                    el.find("#"+curList).fadeOut(50, function() {
                        
                        // Fade in new list on callback
                        el.find("#"+listID).fadeIn(50);
                        
                        // Adjust outer wrapper to fit new list snuggly
                        var newHeight = el.find("#"+listID).height();
                        $allListWrap.animate({
                            height: newHeight
                        });
                        
                        // Remove highlighting - Add to just-clicked tab
                        el.find(".nav-tab li a").removeClass("current");
                        $newList.addClass("current");
                            
                    });
                    
     }            
     $('#dates-price').val(date_for_prices);     
	 $('#planner-days_from').val('7');
	 $('#planner-days_to').val('7');
	 selectMe('planner-days_from',7,4);
	 selectMe('planner-days_to',7,4);
	 $('#shp_page').val(1);
	 $('#shp_session').val('');
	 SearchHotelPrices(); 
	
	
}
function addNewCountrie(id, name)
{
	$.ajax({
		url:	 '/index/addcountries', 
		type:	 'POST',
        data: {id : id, name : name},
        dataType: "json",
			success: function(response){
                 $('#country_id').html(response.country_id);
                 $('#optionsDiv1').html(response.optionsDiv1);
                 $('#sarea1').html(response.sarea1);
                 
                 
                 $.fancybox.close();
			}
	});    
}


var socials = {
  myWin : null,
  interval : '',
  socialBT :function (url, param){
   var features, w = 750, h = 770;
   var top = (screen.height - h)/2, left = (screen.width - w)/2;
   if(top < 0) top = 0;
   if(left < 0) left = 0;
   features = 'top=' + top + ',left=' +left;
   features += ',height=' + h + ',width=' + w + ',resizable=0, toolbar=0, scrollbars=yes';
  
    socials.myWin = window.open(url+param, 'displayWindow', features);

   }
}
function UncheckFoods() {
	var before = $('#fullsearchoptionsform').serialize();
	$("#foods-options .checkbox").removeAttr("checked");
	$("#foods-options .checkboxAreaChecked").removeClass("checkboxAreaChecked").addClass('checkboxArea');
	var after =  $('#fullsearchoptionsform').serialize();
	
	if (before == after) {
		;
	}else {
		$('#sf_session').val('');
		SearchTour();
	}
}
function UncheckResorts() {

	var before = $('#fullsearchoptionsform').serialize();
	$(".curorts-option .checkbox").removeAttr("checked");
	//$("#foods-options .checkboxAreaChecked").removeClass("checkboxAreaChecked").addClass('checkboxArea');
	var after =  $('#fullsearchoptionsform').serialize();
	
	if (before == after) {
		;
	}else{
		$('#sf_session').val('');
		SearchTour();
	}
}

function slideToggleSeoText(){
    var div=$('#seo-texts');
    var show=$('.seo-texts-show');
    var hide=$('.seo-texts-hide');
    
    if($(div).css('height').toLowerCase()=='auto'){
        $(div).css('height','124px');
        $(show).show();
        $(hide).hide();
    }else{
        $(div).css('height','auto');
        $(show).hide();
        $(hide).show();
    }
}

function theRotator() {
    if($('div#rotator ul li').size()<=1) return false;
	// Устанавливаем прозрачность всех картинок в 0
	$('div#rotator ul li').css({opacity: 0.0});

	// Берем первую картинку и показываем ее (по пути включаем полную видимость)
	$('div#rotator ul li:first').css({opacity: 1.0});

	// Вызываем функцию rotate для запуска слайдшоу, 5000 = смена картинок происходит раз в 5 секунд
	setInterval('rotate()',4000);
}

function rotate() {
	// Берем первую картинку
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	// Берем следующую картинку, когда дойдем до последней начинаем с начала
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));

	// Расскомментируйте, чтобы показвать картинки в случайном порядке
	// var sibs = current.siblings();
	// var rndNum = Math.floor(Math.random() * sibs.length );
	// var next = $( sibs[ rndNum ] );

	// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	// Прячем текущую картинку
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};

$(document).ready(function() {
	// Запускаем слайдшоу
	theRotator();
});

function applyMention(el,url){
    $.ajax({
        url:	 '/ajax/'+url,
        type:	 'POST',
        dataType: "json",
        complete: function(jq, status){
            
        },
        success: function(response){
            if (typeof (response) !== 'undefined' && response != null){
                if (response.result){
                    var vote=$(el).find('b').html();
                    vote++;
                    $(el).find('b').html(vote);
                }else{
                    jQuery.fancybox(response.message,{
                        'hideOnOverlayClick':false,
                        'hideOnContentClick': false,
                        'titleShow'  : false
                    });
                }
            }
        }
    }); 
}

function addPhotoInput(el){
    if ($('#review_photos p.photo_file').length<20){
        $('#review_photos').append('<p style="margin:0;" class="photo_file"><input type="image" src="'+baseUrl+'/images/redcross.png" onclick="$(this).parent().remove()"/><input type="file" name="photo[]" /></p>');
    }
    if ($('#review_photos p.photo_file').length==20){
        $(el).parent().hide();
    }
}
function js_trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
function popularTourValidate() {
	bError = false;
	elements = $('#populartour .wrap').find("div.err");
	elements.remove();
	if (js_trim($('#name').val())=='') {
		bError = true;
		$('#name').parents('.wrap').append('<div class="err">Введите имя</div>');
		$('#name').css("border","1px solid #ff0000");	
	}else
		$('#name').css("border","2px #AAD1DD solid");
	if (js_trim($('#phone').val())=='') {
		bError = true;
		$('#phone').parents('.wrap').append('<div class="err">Введите номер телефона</div>');
		$('#phone').css("border","1px solid #ff0000");	
	}else
		$('#phone').css("border","2px #AAD1DD solid");
	
	if (js_trim($('#email').val())=='') {
		bError = true;
		$('#email').parents('.wrap').append('<div class="err">Введите email</div>');
		$('#email').css("border","1px solid #ff0000");	
	}else
		$('#email').css("border","2px #AAD1DD solid");
	
	if (!bError)
		$('#populartour').submit();
	
}

