
var lang='';

function confirm_delete() {
	return (window.confirm('Вы действительно хотите удалить этот товар?'));
	}


//скрипт изменения цвета
/*
var ccol=1;

function ch_col() {
	
	obj=document.getElementById('corp_cl');
	
	if (obj) {
		if (ccol) {
			obj.style.color='#FFFFFF';
			ccol=0;
			setTimeout("ch_col()", 500);
		}
		else {
			obj.style.color='#790000';
			ccol=1;
			setTimeout("ch_col()", 200);
		}
	}
	

}

*/

function show_contact_window(lang) {
	if (lang=='ru' || lang=='ua') {
		$('#bottom_call').html('Все заказы принимаются через вебсайт.<br />Воспользуйтесь альтернативными контактам:<br />(044) 561 80 50<br />(093) 827 73 27<br /><br /><a href="http://www.providesupport.com?messenger=uaflowers"><img src="http://image.providesupport.com/image/uaflowers/online-1214617822.gif" /></a><br /><br /><a href="/ru/41/4">написать директору</a><br />');
	} else {
		$('#bottom_call').html('Use alternate phones:<br />(044) 561 80 50<br />(093) 827 73 27<br /><br /><a href="http://www.providesupport.com?messenger=uaflowers"><img src="http://image.providesupport.com/image/uaflowers/online-1214617822.gif" /></a><br /><br /><a href="/en/41/4">contact director</a><br />');
	}

	
/*	myWin= open("", "displayWindow", 
	"width=500,height=230,status=no,toolbar=no,menubar=no");
	
	myWin.document.open();
	
	myWin.document.write("<html><head><title>Не можете дозвониться?");
	myWin.document.write('</title><link href="http://www.ufl.ua/style.css" rel="stylesheet" type="text/css" /></head>');
	myWin.document.write('<body style="color:#555555; font-family:Tahoma,Verdana,Arial,sans-serif; font-size:12px;">');
	myWin.document.write("Все заказы принимаются через вебсайт.<br />Воспользуйтесь альтернативными контактам:<br /><br />(044) 561 80 50<br />(093) 827 73 27<br /><br />");
	myWin.document.write('<!-- BEGIN ProvideSupport.com Graphics Chat Button Code --><div id="ciBvBh" style="z-index:100;position:absolute"></div><div id="scBvBh" style="display:inline"></div><div id="sdBvBh" style="display:none"></div><script type="text/javascript">var seBvBh=document.createElement("script");seBvBh.type="text/javascript";seBvBh.defer=true;seBvBh.src=(location.protocol.indexOf("https")==0?"https://secure.providesupport.com/image":"http://image.providesupport.com")+"/js/uaflowers/safe-standard.js?ps_h=BvBh\u0026ps_t="+new Date().getTime();document.getElementById("sdBvBh").appendChild(seBvBh)</script><noscript><div style="display:inline"><a href="http://www.providesupport.com?messenger=uaflowers">Live Support</a></div></noscript><!-- END ProvideSupport.com Graphics Chat Button Code --><br /><br />');
	myWin.document.write('<a href="http://web.icq.com/whitepages/message_me/1,,,00.icq?uin=135355135&action=message"><img src="http://www.ufl.ua/images_new/icq_ico.gif" alt="" height="15" width="15" /></a> 135-355-135<br /><br />');
	myWin.document.write('<a href="skype:ufl.ua?call" title="Позвонить" style="text-decoration: none"><img vspace=2 src="http://www.ufl.ua/images_new/skype_ico.gif" alt="" height="16" width="16" /></a> ufl.ua<br /><br />');
	myWin.document.write("");
	myWin.document.write("</body></html>");

	myWin.document.close();  */

}

function showMess (text) {
	
	document.getElementById('mess_block').innerHTML=text;
	
	setOpacity();
}

var value = 0;
var posed = 0;
var messVisible=false;

function watchScroll() {
	if (messVisible) {
		var wdiv=document.getElementById('warning');
		
		var top=window.scrollY+(window.innerHeight/2)-30;
		top=parseInt(top);
		wdiv.style.top=top+'px';
		
		setTimeout("watchScroll()", 200);
	}
}

function setOpacity() {

	document.getElementById('message_block').style.display = "block";
	
	if (!posed) {
		var wdiv=document.getElementById("message_block");
		
		var pos_left=document.body.clientWidth/2;

		pos_left =pos_left - 250;

		pos_left=parseInt(pos_left);
		
		pos_left=pos_left+'px';
		wdiv.style.left=pos_left;

		var busyLayer = document.getElementById("shadow");

		if (window.innerHeight && window.scrollMaxY) {
			yScroll = window.innerHeight + window.scrollMaxY;
			var deff = document.documentElement;
			var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
			yScroll -= (window.innerHeight - hff);
		} else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){
			yScroll = document.body.scrollHeight;
		} else {
			yScroll = document.body.offsetHeight;
		}

		if (busyLayer != null) {
			busyLayer.style.visibility = "visible";
			busyLayer.style.height = yScroll+'px';
		}
		alert(document.body.scrollHeight);
		var top=window.scrollY+(document.body.clientHeight/2)-30;
		top=parseInt(top);
		alert (top);
		wdiv.style.top=top+'px';

		posed=1;
		messVisible=true;
	}

	value += 1;
	var testObj = document.getElementById('shadow');

	testObj.style.width = "100%";
	//testObj.style.height = "100%";
	testObj.style.display = "block";
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
	myTimeout = setTimeout("setOpacity()", 50);

	if (value >= 5) {
		clearTimeout(myTimeout);
	}
	
	
	watchScroll();
}

function removeOpacity() {
	value -= 1;
	var testObj = document.getElementById('shadow');

	myTimeout2 = setTimeout("removeOpacity()", 50);
	testObj.style.opacity = value/10;
	testObj.style.filter = 'alpha(opacity=' + value*10 + ')';

	if ((value/10) <= 0) {
		testObj.style.display = "none";
		clearTimeout(myTimeout2);
	}
	document.getElementById('message_block').style.display = "none";
	
	posed=0;
	messVisible=false;
}

function get_cities(country_id, city_id, selected_city, lang) {
	
	
    JsHttpRequest.query(
        'http://www.ufl.ua/ajax.php', // backend
        {
            'country_id': document.getElementById(country_id).value,
            'func' : 'get_cities',
            'lang' : lang
        },
        // Function is called when an answer arrives. 
        function(result, errors) {
            // Write the answer.
            
            if (result) {
            	
				var cities=result["cities"];
				
				var city_field_obj=document.getElementById(city_id);
				
				for (i = city_field_obj.options.length; i >= 0; i--) {
					city_field_obj.options[i] = null; 
				}
				
				var i=0;
				
				for (key in cities) {
					if (selected_city==cities[key]['id']) city_field_obj.options[i] = new Option(cities[key]['name'], cities[key]['id'], true, true);
					else city_field_obj.options[i] = new Option(cities[key]['name'], cities[key]['id']);
					i++;
				}
            }
        },
        false  // do not disable caching
    );
}

function bottomGetAllCities(country_id, country_nick, act_city, lang, domain, country_name, country_link) {
    JsHttpRequest.query(
        'http://www.ufl.ua/ajax.php', // backend
        {
            'country_id': country_id,
            'func' : 'get_cities',
            'only_main' : '1',
            'lang' : lang
        },
        // Function is called when an answer arrives. 
        function(result, errors) {
            // Write the answer.
            
            if (result) {
            	
				var cities=result["cities"];
				
				var cities_div=document.getElementById('bottom_cities');
				var cont='';
				
				for (key in cities) {
					if (act_city==cities[key]['nick']) cont=cont+'<font color="Red">'+cities[key]['name']+'</font> | ';
					else {
						if (cities[key]['nick']=='other') cont=cont+'<a href="'+domain+lang+'/cveti-'+cities[key]['nick']+'-'+country_nick+'" title="'+cities[key]['name']+'">'+cities[key]['name']+'</a> | ';
						else cont=cont+'<a href="'+domain+lang+'/cveti-'+cities[key]['nick']+'" title="'+cities[key]['name']+'">'+cities[key]['name']+'</a> | ';
					}
				}
				
				if (lang=='ru') cont=cont+'<br /><a href="'+domain+lang+'/regions/'+country_link+'" style="color:red;"><b>Показать все города доставки в '+country_name+'...</b></a>';
				if (lang=='ua') cont=cont+'<br /><a href="'+domain+lang+'/regions/'+country_link+'" style="color:red;"><b>Показати усі міста доставки у '+country_name+'...</b></a>';
				if (lang=='en') cont=cont+'<br /><a href="'+domain+lang+'/regions/'+country_link+'" style="color:red;"><b>Show all delivery cities to '+country_name+'...</b></a>';
				
				cities_div.innerHTML=cont;
            }
        },
        false  // do not disable caching
    );
}

// функции для хоткиев

function hotkeys(e) {
  if (!e) e = window.event;
  var k = e.keyCode;
  
  if (e.ctrlKey) {
    if (k == 13) {
    	
		$(function(){

			document.getElementById('pframe').src='http://www.ufl.ua/call_confirmation.html';

			// Dialog			
			$('#dialog').dialog({
				autoOpen: false,
				width: 300,
				buttons: {
					"Закрыть": function() { 
						$(this).dialog("close"); 
					}
				}
			});
			
			
			$('#dialog').dialog("open"); 
			
			alert(div);
		});

    	
    }
  }
}

function init() {
  document.onkeyup = hotkeys;
}

// обработка текстов для подмены Читать полностью

function init_read_full(id) {
	var obj=document.getElementById(id);
	obj.style.display = "none";
}

function replace_text(id) {
	var obj=document.getElementById(id);
	var obj2=document.getElementById(id+'_text');
	obj.innerHTML=obj2.innerHTML;
}

function show_other_prod(cat_id, lang) {
    JsHttpRequest.query(
        'http://www.ufl.ua/ajax.php', // backend
        {
            'func' : 'show_other_prod',
            'cat_id' : cat_id,
            'lang' : lang
        },
        // Function is called when an answer arrives. 
        function(result, errors) {
            // Write the answer.
            
            if (result) {
            	
				var cities=result["cities"];
				
				var cities_div=document.getElementById('bottom_cities');
				var cont='';
				
				for (key in cities) {
					if (act_city==cities[key]['nick']) cont=cont+'<font color="Red">'+cities[key]['name']+'</font> | ';
					else {
						if (cities[key]['nick']=='other') cont=cont+'<a href="'+domain+lang+'/cveti-'+cities[key]['nick']+'-'+country_nick+'" title="'+cities[key]['name']+'">'+cities[key]['name']+'</a> | ';
						else cont=cont+'<a href="'+domain+lang+'/cveti-'+cities[key]['nick']+'" title="'+cities[key]['name']+'">'+cities[key]['name']+'</a> | ';
					}
				}
				
				if (lang=='ru') cont=cont+'<br /><a href="'+domain+lang+'/regions/'+country_link+'" style="color:red;"><b>Показать все города доставки в '+country_name+'...</b></a>';
				if (lang=='ua') cont=cont+'<br /><a href="'+domain+lang+'/regions/'+country_link+'" style="color:red;"><b>Показати усі міста доставки у '+country_name+'...</b></a>';
				if (lang=='en') cont=cont+'<br /><a href="'+domain+lang+'/regions/'+country_link+'" style="color:red;"><b>Show all delivery cities to '+country_name+'...</b></a>';
				
				cities_div.innerHTML=cont;
            }
        },
        false  // do not disable caching
    );
}

/**
	
	Функции офф заказа

*/

// аякс отправка email

function ch_submit_email (email, lang, chpwd, password, remind_pwd) {
	
	if (document.location.href.indexOf("individual_order")==-1) {
		var ind_order=false;
	}
	else {
		var ind_order=true;
	}
	
    JsHttpRequest.query(
        '/ajax.php', // backend
        {
            'func' : 'submit_email',
            'email' : email,
            'lang' : lang,
            'chpwd' : chpwd,
            'password' : password,
            'remind_pwd' : remind_pwd,
            'ind_order' : ind_order
        },
        // Function is called when an answer arrives. 
        function(result, cont) {
            // Write the answer.
            
            if (result) {
            	document.location.href=result['redirect'];
            }
            else {
            	document.getElementById('checkout_container').innerHTML=cont;
            }
            
        },
        false  // do not disable caching
    );
}

// показываем подсказки

var timeoutId=false;

function showHelp (obj, show, text) {
	
	if (timeoutId) clearTimeout(timeoutId);
	
	if (show) {
		if (text!=false) {
			$("#help_block_cont").html(text);
		
			$("#help_block").css("left", $(obj).offset().left + $(obj).width()-5 );
			$("#help_block").css("top", $(obj).offset().top - 3);
		}
		
		$("#help_block").css("display", 'block');
		
		return true;
	}
	else {
		$("#help_block_cont").html('');
		$("#help_block").css("display", 'none');
		
		return true;
	}
}

// Мигающее предупреждение на главной

function blink(obj) {
    if (obj.style.color=='red') {
        obj.style.color='#376C17';
    }
    else {
        obj.style.color='red';
    } 
    setTimeout("blink(document.getElementById('beware'));", 500);
}

// привью букетов

var hideTimeOut=0;

function show_preview (obj, img_src, lang, item_id, cat_id, toleft) {

	if (!img_src) return false;

	if (hideTimeOut) {
		clearTimeout(hideTimeOut);
	}
	$("#preview").hide();
	
	//document.getElementById('preview_img').src=img_src;
	$("#preview_img").attr('src', img_src);
	$('#preview_img').click(function() {
		document.location.href='/'+lang+'/'+cat_id+'/'+item_id;
	});
	
	$('#fast_order_button').click(function() {
		document.location.href='/'+lang+'/checkout/fast/item/'+item_id;
	});
	
	$("#preview_img").load(function(){
		
		if (toleft) {
			$("#preview").css("top", $(obj).offset().top);
			$("#preview").css("left", $(obj).offset().left - $("#preview_img").width() - 10);
		}
		else {
			$("#preview").css("top", $(obj).offset().top);
			$("#preview").css("left", $(obj).offset().left + $(obj).width());
		}
		$("#preview").fadeIn();
		
	});
	
}

function hide_preview () {
	hideTimeOut=setTimeout('$("#preview").hide()', 300);
}

// показваем видео

function showVideo() {

	// Dialog			
	$('#video').dialog({
		autoOpen: false,
		width: 665,
		buttons: {
			"Закрыть": function() { 
				$(this).dialog("close"); 
			}
		}
	});
	
	
	$('#video').dialog("open");
}


// быстрый заказ

function fastOrder (item_id, lang) {
	
	hide_preview ();
	
	if (lang=='ru') {
		$('#fast_order').dialog({
			autoOpen: false,
			width: 350,
			buttons: {
				"Закрыть": function() { 
					$(this).dialog("close");
				},
				"Оформить быстрый заказ": function() { 
					makeFastOrder(item_id, lang);
				}
			}
		});
	}
	else if (lang=='ua') {
		$('#fast_order').dialog({
			autoOpen: false,
			width: 350,
			buttons: {
				"Закрити": function() { 
					$(this).dialog("close");
				},
				"Оформити швидке замовдення": function() { 
					makeFastOrder(item_id, lang);
				}
			}
		});
	}
	else if (lang=='en') {
		$('#fast_order').dialog({
			autoOpen: false,
			width: 350,
			buttons: {
				"Close": function() { 
					$(this).dialog("close");
				},
				"Proceed fast order": function() { 
					makeFastOrder(item_id, lang);
				}
			}
		});
	}
	
	$('#fast_order').dialog("open");
	
}

function makeFastOrder (item_id, lang) {
	
	var bValid = true;
	var allFields = $([]).add($("#fo_fio")).add($("#fo_phone")).add($("#fo_region")).add($("#fo_city")).add($("#fo_email"));
	var tips = $(".validateTips");
	
	allFields.removeClass('ui-state-error');
	
	function updateTips(t) {
		tips
			.text(t)
			.addClass('ui-state-highlight');
		setTimeout(function() {
			tips.removeClass('ui-state-highlight', 1500);
		}, 500);
	}
	
	function checkLength(o,n,min,max) {

		if ( o.val().length > max || o.val().length < min ) {
			o.addClass('ui-state-error');
			if (lang=='ru') updateTips("Это поле должно содержать от "+min+" до "+max+" знаков.");
			else if ($lang=='ua') updateTips("Це поле повинно бути від "+min+" до "+max+" знаків.");
			else if ($lang=='en') updateTips("Length must be between "+min+" and "+max+".");
 			return false;
		} else {
			return true;
		}

	}
	
	function checkRegexp(o,regexp,n) {

		if ( !( regexp.test( o.val() ) ) ) {
			o.addClass('ui-state-error');
			updateTips(n);
			return false;
		} else {
			return true;
		}

	}
	
	bValid = bValid && checkLength($("#fo_fio"),"fo_fio",3,16);
	bValid = bValid && checkLength($("#fo_city"),"fo_city",2,80);
	bValid = bValid && checkLength($("#fo_phone"),"fo_phone",6,80);
	bValid = bValid && checkLength($("#fo_email"),"fo_email",2,80);
	
	bValid = bValid && checkRegexp($("#fo_email"),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Введите правильный E-mail");
	
	
	if (bValid) {
	
	    JsHttpRequest.query(
	        '/ajax.php', // backend
	        {
	            'func' : 'fast_order',
	            'item_id' : item_id,
	            'fio' : $("#fo_fio").val(),
	            'region' : $("#fo_region").val(),
	            'city' : $("#fo_city").val(),
	            'phone' : $("#fo_phone").val(),
	            'email' : $("#fo_email").val(),
	            'lang' : lang
	        },
	        // Function is called when an answer arrives. 
	        function(result, cont) {
	            // Write the answer.
	            
	            if (result) {
            		if (result['error']) {
            			tips.text(result['error']);
            		}
            		else {
            			$("#fast_order").html(cont);
            		}
	            }
	            else {
            		$("#fast_order").html(cont);
	            }
	            
	        },
	        false  // do not disable caching
	    );
	}
	
}

// выбор региона доставки

var global_region_id=0;
var global_country_id=0;

function show_region_select (what, obj, lang) {
	if ($("#region_block2")) {
		$("#region_block2").css("top", $(obj).offset().top - 3);
		$("#region_block2").css("left", $(obj).offset().left - 11);
		
		$("#rb_header_text").html($(obj).html());
		$("#region_block_text").html('<br /><br /><center><img src="/images/ajax-loader.gif" width="32" height="32" align="center" /></center><br /><br />');
		$("#region_block2").fadeIn();
		
		if (what=='region') {
		    JsHttpRequest.query(
		        '/ajax.php', // backend
		        {
		            'func' : 'get_regions',
		            'lang' : lang
		        },
		        // Function is called when an answer arrives. 
		        function(result, cont) {
		            // Write the answer.
		            
		            if (result) {
            			if (result['error']) {
            				alert(result['error']);
            			}
            			else {
            				var regions=result['regions'];
            				var html_cont='';
            				
            				$('#region_block_text').css('width', '150px');
            				
            				for (var i=0; i<regions.length; i++) {
            					html_cont=html_cont+'<a href="javascript:void(0);" onclick="choose_region('+regions[i][0]+', \''+regions[i][1]+'\', \''+lang+'\')">'+regions[i][1]+'</a><br />';
            				}
            				
            				$("#region_block_text").html(html_cont);
            				
            			}
		            }
		            else {
            			$("#region_block_text").html(cont);
		            }
		            
		        },
		        false  // do not disable caching
		    );
		}
		
		if (what=='country') {
		    JsHttpRequest.query(
		        '/ajax.php', // backend
		        {
		            'func' : 'get_countries',
		            'region_id' : global_region_id,
		            'lang' : lang
		        },
		        // Function is called when an answer arrives. 
		        function(result, cont) {
		            // Write the answer.
		            
		            if (result) {
            			if (result['error']) {
            				alert(result['error']);
            			}
            			else {
            				var countries=result['countries'];
            				var html_cont='';
            				
            				$('#region_block_text').css('width', '400px');
            				
            				for (var i=0; i<countries.length; i++) {
            					html_cont=html_cont+'<div style="float: left; width: 33%;"><a href="javascript:void(0);" onclick="choose_country('+countries[i][0]+', \''+countries[i][1]+'\', \''+lang+'\')">'+countries[i][1]+'</a></div>';
            				}
            				
            				$("#region_block_text").html(html_cont+'<div style="clear: both;"></div>');
            				
            			}
		            }
		            else {
            			$("#region_block_text").html(cont);
		            }
		            
		        },
		        false  // do not disable caching
		    );
		}
		
		if (what=='city') {
		    JsHttpRequest.query(
		        '/ajax.php', // backend
		        {
		            'func' : 'get_cities_for_region',
		            'country_id' : global_country_id,
		            'lang' : lang
		        },
		        // Function is called when an answer arrives. 
		        function(result, cont) {
		            // Write the answer.
		            
		            if (result) {
            			if (result['error']) {
            				alert(result['error']);
            			}
            			else {
            				var cities=result['cities'];
            				var html_cont='';
            				
            				$('#region_block_text').css('width', '500px');
            				
            				for (var i=0; i<cities.length; i++) {
            					if (cities[i][4]==1) {
            						// область
            						html_cont=html_cont+'<div style="float: left; width: 25%;"><a href="javascript:void(0);" onclick="get_cities_for_region('+cities[i][0]+', \''+cities[i][1]+'\', \''+lang+'\')">'+cities[i][1]+'</a></div>';
            						
            					}
            					else {
            						// простой город
            						if (cities[i][3]!='other') html_cont=html_cont+'<div style="float: left; width: 25%;"><a href="/'+lang+'/cveti-'+cities[i][3]+'">'+cities[i][1]+'</a></div>';
            						else html_cont=html_cont+'<div style="float: left; width: 25%;"><a href="/'+lang+'/cveti-'+cities[i][3]+'-'+cities[i][2]+'">'+cities[i][1]+'</a></div>';
								}
            				}
            				
            				html_cont=html_cont+'<div style="clear: both;"></div>'+cont
            				
            				if (global_country_id==5) {
            					if (lang=='ru') html_cont=html_cont+'<br /><br /><a href="/'+lang+'/regions/ukraine/ukraine"><b>Все города Украины</b></a>';
            					if (lang=='ua') html_cont=html_cont+'<br /><br /><a href="/'+lang+'/regions/ukraine/ukraine"><b>Усі міста України</b></a>';
            					if (lang=='en') html_cont=html_cont+'<br /><br /><a href="/'+lang+'/regions/ukraine/ukraine"><b>All cities of Ukraine</b></a>';
            				}
            				
            				$("#region_block_text").html(html_cont);
            				
            			}
		            }
		            else {
            			$("#region_block_text").html(cont);
		            }
		            
		        },
		        false  // do not disable caching
		    );
		}
		
	}
	
}

function choose_region (id, name, lang) {
	
	global_region_id=id;
	
	$('#city_choose').css('display', 'none');
	if (id==4) {
		$("#region_choose").html('<b>'+name+'</b> <img src="/images/green_arrow.gif" />');
		$("#country_choose").html('<b>'+name+'</b> <img src="/images/green_arrow.gif" />');
		
		$('#region_block2').css('display', 'none');
		$("#country_choose").fadeIn();
		
		global_country_id=5;
		
		if (lang=='ru') $("#city_choose").html('<b>Выберите город</b> <img src="/images/green_arrow.gif" />');
		if (lang=='ua') $("#city_choose").html('<b>Виберіть місто</b> <img src="/images/green_arrow.gif" />');
		if (lang=='en') $("#city_choose").html('<b>Choose city</b> <img src="/images/green_arrow.gif" />');
		
		//$("#city_choose").fadeIn();
		$('#city_choose').css('display', 'inline');
		
	}
	else {
		$("#region_choose").html('<b>'+name+'</b> <img src="/images/green_arrow.gif" />');
		if (lang=='ru') $("#country_choose").html('<b>Выберите страну</b> <img src="/images/green_arrow.gif" />');
		if (lang=='ua') $("#country_choose").html('<b>Виберіть країну</b> <img src="/images/green_arrow.gif" />');
		if (lang=='en') $("#country_choose").html('<b>Select country</b> <img src="/images/green_arrow.gif" />');
		
		$('#region_block2').css('display', 'none');
		$("#country_choose").fadeIn();
	}
}

function choose_country (id, name, lang) {
	
	global_country_id=id;
	
	$("#country_choose").html('<b>'+name+'</b> <img src="/images/green_arrow.gif" />');
	if (lang=='ru') $("#city_choose").html('<b>Выберите город</b> <img src="/images/green_arrow.gif" />');
	if (lang=='ua') $("#city_choose").html('<b>Виберіть місто</b> <img src="/images/green_arrow.gif" />');
	if (lang=='en') $("#city_choose").html('<b>Select city</b> <img src="/images/green_arrow.gif" />');
	
	$('#region_block2').css('display', 'none');
	//$("#city_choose").fadeIn();
	$('#city_choose').css('display', 'inline');
}

function get_cities_for_region (id, name, lang) {
	if (lang=='ru') var html_cont='<b>'+name+'</b> <a href="javascript:void(0);" onclick="show_region_select(\'city\', $(\'#city_choose\'), \''+lang+'\')">Назад к областям</a><br /><br />';
	if (lang=='ua') var html_cont='<b>'+name+'</b> <a href="javascript:void(0);" onclick="show_region_select(\'city\', $(\'#city_choose\'), \''+lang+'\')">Назад до районів</a><br /><br />';
	if (lang=='en') var html_cont='<b>'+name+'</b> <a href="javascript:void(0);" onclick="show_region_select(\'city\', $(\'#city_choose\'), \''+lang+'\')">Back to regions</a><br /><br />';
	
	JsHttpRequest.query(
		'/ajax.php', // backend
		{
		    'func' : 'get_cities_for_region',
		    'country_id' : global_country_id,
		    'region_id' : id,
		    'lang' : lang
		},
		// Function is called when an answer arrives. 
		function(result, cont) {
		    // Write the answer.
		    
		    if (result) {
            	if (result['error']) {
            		alert(result['error']);
            	}
            	else {
            		var cities=result['cities'];
            		
            		$('#region_block_text').css('width', '500px');
            		
            		for (var i=0; i<cities.length; i++) {
            			// html_cont=html_cont+'<div style="float: left; width: 25%;"><a href="/'+lang+'/cveti-'+cities[i][3]+'">'+cities[i][1]+'</a></div>';
            			if (cities[i][3]!='other') html_cont=html_cont+'<div style="float: left; width: 25%;"><a href="/'+lang+'/cveti-'+cities[i][3]+'">'+cities[i][1]+'</a></div>';
            			else html_cont=html_cont+'<div style="float: left; width: 25%;"><a href="/'+lang+'/cveti-'+cities[i][3]+'-'+cities[i][2]+'">'+cities[i][1]+'</a></div>';
            		}
            		
            		$("#region_block_text").html(html_cont+'<div style="clear: both;"></div>'+cont);
            		
            	}
		    }
		    else {
            	$("#region_block_text").html(cont);
		    }
		    
		    $("#region_block2").fadeIn();
		},
		false  // do not disable caching
	);
}

// функция смены региона доставки на странице товара

function prodChangeRegion (prod_id) {
	
	JsHttpRequest.query(
		'/ajax.php', // backend
		{
		    'func' : 'get_price4region',
		    'prod_id' : prod_id,
		    'region' : $("#region").val(),
		    'lang' : lang
		},
		// Function is called when an answer arrives. 
		function(result, cont) {
		    // Write the answer.
		    
		    if (result) {
            	if (result['error']) {
            		alert(result['error']);
            	}
            	else {
            		
            		if (result['price']==0) {
            			if (lang=='ru') alert('Вы не можете заказать этот товар для выбранного региона, пожалуйста, выберите другой товар');
            			if (lang=='ua') alert('Ви не  можете замовити цей товар  для вибраного регіону, будь  ласка, виберіть інший товар');
            			if (lang=='en') alert('You can`t order this product for this region');
            		}
            	
            		$("#price").html(result['price']);
            		
            		if ($("#price_premium")) {
            			$("#price_premium").html(result['price_premium']);
            		}
            		
            		$('#region_block_text').css('width', '500px');
            		if (cont) alert(cont);
            	}
		    }
		    else {
            	alert(cont);
		    }
		},
		false  // do not disable caching
	);
}