$(document).ready(function() {


	//alert($('.price-table td:has(span[class="price_item"])').length);
	$('#convert_currency').change(function() {
		var url = window.location.href;
	    var pattern = /\/\/([a-z.\-_]+)/i;
	    url = (url.match(pattern)[1]);
	    url = url || null;
		if(url == null) return false;

		if($(this).attr('class') == 'avia_special')
			{
			target_div = $("#avia_special_list");
			target_div.html('<img src="http://'+url+'/user/loader.gif">');
			var cat = '';
			var cat_type = '';
			if($(this).attr('cat') != undefined)
				{
				cat = $(this).attr('cat');
				}
			if($(this).attr('cat_type') != undefined)
				{
				cat_type = $(this).attr('cat_type');
				}
			//alert(cat+'\n'+cat_type);
			//return false;

			$.ajax({
			   type: "POST",
			   url: "http://"+url+"/index.php",
			   data:
			   		{
			   		'query_type': 'ajax_query',
			   		'action': 'convert_avia_special',
			   		'currency': this.value,
			   		'cat': cat,
			   		'cat_type': cat_type
			   		},
			   success: function(response){
			     //alert( response );
			     target_div.html(response);
			   }
			 });
			return false;
			}

		var currency = $(this).val();
		var postId = $(this).attr('class');
		var getvars = getQueryVariable();
		//alert(postId); return false;
		$('#price_tbl').html('<img src="http://'+url+'/user/loader.gif">');
		$.ajax({
		   type: "POST",
		   url: "http://"+url+"/user/pricelist.php",
		   data:
		   		{
		   		'convert':true,
		   		'currency':currency,
		   		'post_id':postId
		   		},
		   success: function(msg){
		     //alert( "Сервер вернул: " + msg );
		     $('#price_tbl').html(msg);
		   }
		 });
	});



});

function SetItemNow(link, selector, item_id, text)
	{
	//alert(link+'\n'+selector+'\n'+item_id+'\n'+text);
	dialog.dialog('close');
	$('#hidden_'+selector).val(item_id);
	$('#item_'+selector).html('<a href="'+link+'">'+text+'</a>');
	}

function getQueryVariable()
	{
	//получаем строку запроса (?a=123&b=qwe) и удаляем знак ?
	var query = window.location.search.substring(1);
	//получаем массив значений из строки запроса вида vars[0] = ‘a=123’;
	var vars = query.split("&");
	var arr = new Array();
	//переводим массив vars в обычный ассоциативный массив
	for (var i=0;i<vars.length;i++)
		{
		var pair = vars[i].split("=");
		arr[pair[0]] = pair[1];
		}
	return arr;
	}