//<script type="text/javascript">
var indicator = jQuery('.indicator_ajax');
	if (next_menu_for_key_enter){
		$.each(next_menu_for_key_enter, function(_title,_value){

		});
	}
	var next_menu_for_key_enter='address';
	var block_menu2 = ['login', 'account', 'address', 'shipping', 'payment_ooo', 'payment_fiz', 'book', 'order-ok'];
	var form_href = {
		'login': "/shop/login_jquery.php?action=process&osCsid=" + flag["oscsid"],
		'address': "/shop/address_book_process_jquery.php" + "?osCsid=" + flag["oscsid"],
		'address_add': "/shop/address_book_process_jquery.php?add&" + "osCsid=" + flag["oscsid"],
		'registration_need': "/shop/create_account_jquery.php" + "?osCsid=" + flag["oscsid"],
		'shipping': "/shop/checkout_shipping_jquery.php" + "?osCsid=" + flag["oscsid"],
		'shipping_noid': "/shop/checkout_shipping_jquery.php",
		'payment_fiz_noid': "/shop/checkout_payment_jquery.php",
		'payment_fiz': "/shop/checkout_payment_jquery.php" + "?osCsid=" + flag["oscsid"],
		'confirmation': "/shop/checkout_confirmation_jquery.php" + "?osCsid=" + flag["oscsid"],
		'confirmation_noid': "/shop/checkout_confirmation_jquery.php",
		'submit': "/shop/checkout_process_jquery.php" + "?osCsid=" + flag["oscsid"],
		'book': "/shop/address_book_jquery.php" + "?osCsid=" + flag["oscsid"]
	};

	var $block_menu_div = {};
	jQuery.each(block_menu2, function (_title, _value) {
		$block_menu_div[_value] = jQuery("#block-menu-" + _value);
	});
	/*For errors*/
	var errors = {
		"0": {
			"lastname": "В вашей корзине нет товаров",
			"email_new": "В вашей корзине нет товаров"
		},
		"2": {
			"email_new": "Не верный пароль или email. Попробуйте еще раз"
		},
		"3": {
			"email_new": "Такой email'a уже зарегистрирован"
		},
		"4": {
			"email_new": "Неправильный формат email'a"
		}
	};
	function ShowError(code) {
		ErrorToDivInput(errors[code]);
	}
	function ErrorToDivInput(data) {
		/*IE FIX*/
		but_next_light('off');
		jQuery.each(data, function (i, n) {
			var $tmp_div_data = jQuery('#' + i);
			jQuery('#error_' + i).remove();
			$tmp_div_data.before('<div id="error_' + i + '"><a href="#error_' + i + '">' + n + '</a></div>');
			jQuery("#error_" + i).click(function () {
				var click_href = jQuery(this).children().attr("href");
				jQuery(click_href).remove();
				jQuery(click_href.replace(/error_/ig, "")).show();
				return false;
			});
			$tmp_div_data.hide();
		});
		return false;
	}


jQuery(document).ready(function () {
	/*input*/
	jQuery("#basket input").click(function () {
		if (jQuery(this).val() === 'Введите E-Mail' || 
jQuery(this).val() === '* * * * * * * *' || 
jQuery(this).val() === flag['pass'] || 
jQuery(this).val() === 'Имя и Фамилия получателя' || 
jQuery(this).val() === 'Адрес' || 
jQuery(this).val() === 'Телефон для связи с кодом города' || 
jQuery(this).val() === 'Индекс') {
			jQuery(this).data("save", jQuery(this).attr('value'));
			jQuery(this).attr("value", "");
			return false;
		}
	});

	jQuery("#basket input").keyup(function (event) {
		if (jQuery(this).attr('name') === 'street_address' || 
			jQuery(this).attr('name') === 'password' || 
			jQuery(this).attr('name') === 'email_address') {
			if (jQuery(this).val().length > 6) {
				but_next_light('on');
			} else {
				but_next_light('off');
			}
		}

	});

	jQuery("#basket").keyup(function (event) {
		var keycode = parseInt(parseFloat(event.keyCode),'10');
		if ('13'==keycode){
			load_and_check_status(next_menu_for_key_enter);
		}
	});

	jQuery("#basket input").blur(function () {
		if (jQuery(this).val() === '') jQuery(this).attr("value", jQuery(this).data("save"));
		return false;
	});

		jQuery("#basket :radio").click(function () {

		if ('radio_rus' === this.id) {
			jQuery("#basket input#radio_rus").hide();
			jQuery("#basket span.radio_rus").hide();
			jQuery("#basket input#postcode").show();
			jQuery("#basket input#postcode").attr('value', 'Индекс');
		}
		if ('moscow' === this.id) {
			jQuery("#basket input#radio_rus").show();
			jQuery("#basket span.radio_rus").show();
			jQuery("#basket input#postcode").attr('value', '');
			jQuery("#basket input#postcode").hide();
		}
		if ('piter' === this.id) {
			jQuery("#basket input#radio_rus").show();
			jQuery("#basket span.radio_rus").show();
			jQuery("#basket input#postcode").attr('value', '');
			jQuery("#basket input#postcode").hide();
		}
	});

	jQuery("#basket a").click(function () {
		var click_href = jQuery(this).attr("href");
		if (click_href == '#book') {
			load_and_check_status('book');
			next_menu_for_key_enter='shipping';
			return false;
		}
		if (click_href == '#close-menu-book') {
			$block_menu_div['book'].hide();
			return false;
		}

		if (click_href == '#add_address') {
			next_menu_for_key_enter='shipping';
			load_data(form_href['address_add'], 'address', 'process');
			return false;
		}

		if (click_href == '#close') {
			next_menu_for_key_enter='address';
			if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) === "6"){
				next_menu_for_key_enter='address';
			}else {
				jQuery('#basket').togglePopup();
			}
			jQuery("#basket").hide();
			jQuery('#banner').html('<a href="http://www.hailait.ru/shop/mouse-roccat-kone-gaming-mouse-roc-11-500-p-134.html">		<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="728" height="90" id="ROCCAT-Kone_Flashbanner_728x90_12-06-2009_interactivemedia" align="middle">		<param name="allowScriptAccess" value="sameDomain" />		<param name="allowFullScreen" value="false" />		<param name="flashvars" value="clicktarget=_blank" />		<param name="flashvars" value="clicktag=http://www.hailait.ru/shop/mouse-roccat-kone-gaming-mouse-roc-11-500-p-134.html" />			<param name="quality" value="high" />		<param name="bgcolor" value="#999999" />			<param name="movie" value="ROCCAT-Kone_Flashbanner_728x90_12-06-2009_interactivemedia.swf?clicktag=http://www.hailait.ru/shop/mouse-roccat-kone-gaming-mouse-roc-11-500-p-134.html" /><param name="quality" value="high" /><param name="bgcolor" value="#999999" />			<embed src="ROCCAT-Kone_Flashbanner_728x90_12-06-2009_interactivemedia.swf?clicktag=http://www.hailait.ru/shop/mouse-roccat-kone-gaming-mouse-roc-11-500-p-134.html" quality="high" bgcolor="#999999" width="728" height="90" name="ROCCAT-Kone_Flashbanner_728x90_12-06-2009_interactivemedia" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />		</object></div>');
			return false;
		}

		if (click_href == '#account') {
			next_menu_for_key_enter='address';
			flag['old_user'] = 'no';
			load_and_check_status('account');
			return false;
		}

		if (click_href == '#login') {
			next_menu_for_key_enter='address';
			flag['old_user'] = 'yes';
			show_only_one_menu('login');
			return false;
		}

		if (click_href == '#address') {
			next_menu_for_key_enter='shipping';
			load_and_check_status('address');
			return false;
		}

		if (click_href == '#login_prev') {
			if ('no' == flag['login']) {
				show_only_one_menu('login');
				next_menu_for_key_enter='address';
			}
			return false;
		}

		if (click_href == '#address_prev') {
			next_menu_for_key_enter='shipping';
			send_data(form_href['shipping'], 'address', 'process');
			but_prev_light('off');
			but_next_light('on');
			return false;
		}

		if (!cart_empty_check()) return false;

		if (click_href == '#shipping') {
			next_menu_for_key_enter='payment_fiz';
			load_and_check_status('shipping');
			return false;
		}

		if (click_href == '#payment_fiz') {
			next_menu_for_key_enter='order-ok';
			load_and_check_status('payment_fiz');
			return false;
		}

		if (click_href == '#payment_ooo') {
			next_menu_for_key_enter='order-ok';
			load_and_check_status('payment_ooo');
			return false;
		}
		if (click_href == '#order-ok') {
			next_menu_for_key_enter='close';
			but_prev_light('on');
			but_next_light('on');
			load_and_check_status('order-ok');
			return false;
		}
		if (click_href == '#account_prev') {

			if ('no' == flag['login']) {
				show_only_one_menu('account');
				next_menu_for_key_enter='address';
				
			}
			return false;
		}

		if (click_href == '#shipping_prev') {
			but_prev_light('on');
			but_next_light('on');
			next_menu_for_key_enter='payment_fiz';
			send_data(form_href['confirmation'], 'shipping', 'process');
			return false;
		}

	});


	jQuery("#header_login").click(function () {
		if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) === "6") {
			return true;
		} else {
			cart_empty_check();
			jQuery("#basket").show();
			jQuery('#basket').togglePopup();
			if ('no' === flag['login']) {
				flag['old_user'] = 'no';
				show_only_one_menu('login');
			} else {
				jQuery("#block-menu-account").remove();
				flag['old_user'] = 'yes';
				load_and_check_status('address');
			}
			return false;
		}
	});

	jQuery(".but_oform").click(function () {	
		basket_show();
		return false;
		
	});


	if (flag.start==='show'){
		basket_show();
		return false;
	}
});

	function basket_show()
	{
		jQuery("#logindiv").hide();
		jQuery("#mydiv").hide();
//		if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) === "6") {
//			return true;
//		} else {
			cart_empty_check();
			//			       if(!jQuery.browser.msie){

			if (jQuery.browser.msie && parseInt(parseFloat(jQuery.browser.version.substr(0, 1)), "10") < "8")
			{
				true;
				location.replace("http://www.hailait.ru/shop/checkout_shipping.php");

				jQuery(".but_oform").attr('onclick','');
				return true;

									//alert('IE');
				//jQuery("#basket").show();
				//jQuery("#popup").show();
//				jQuery("#popup").removeClass('');
//				//class="hidden"
				//jQuery("#basket").show();
			} else {

				jQuery('#banner').html('');
				jQuery("#basket").show();
				jQuery('#basket').togglePopup();
			}
			//					}
			if ('no' === flag['login']) {
				flag['old_user'] = 'no';
				next_menu_for_key_enter='address';
				show_only_one_menu('account');
			} else {
				jQuery("#block-menu-account").remove();
				flag['old_user'] = 'yes';
				next_menu_for_key_enter='shipping';
				load_and_check_status('address');
			}
			return false;
//		}
	}


function show_only_one_menu(div_for_show) {
		jQuery.each(block_menu2, function (title, _value) {
			if (div_for_show !== _value) $block_menu_div[_value].hide();
		});
		if (div_for_show.length > 0) $block_menu_div[div_for_show].show();
	}

	function load_html_data(form_data_for_function, next_menu_show) {
		indicator.show();
		jQuery.ajax({
			type: "GET",
			url: form_data_for_function,
			datatype: "html",
			data: {
				osCsid: flag["oscsid"],
				html: "yes"
			},
			success: function (data) {
				but_prev_light('on');
				but_next_light('off');
				if (jQuery(".c-cont-" + next_menu_show + " :radio").filter(':checked')) {
					but_next_light('on');
				}
				jQuery(".c-cont-" + next_menu_show).html(data, function () {
					show_only_one_menu(next_menu_show);
				});
				indicator.hide();
				if ('shipping' === next_menu_show) {

					jQuery(".c-cont-" + next_menu_show + " :radio").click(function () {
						but_next_light('on');
						var add_price = parseInt(parseFloat(jQuery('.price_' + jQuery(this).attr('value')).html(), "10"), "10");
						var add_price_cart = parseInt(parseFloat(flag.price, "10"), "10");
						jQuery(".full_price").html(add_price_cart + add_price);
					});
					if (parseInt(parseFloat(data.length), 10) < 200) {
						jQuery("#skip_shipping").attr('href', '#address_prev');
						send_data(form_href['shipping'], 'payment_fiz', 'process');
					}

				}
				if ('payment_fiz' === next_menu_show) {
					jQuery(".c-cont-" + next_menu_show + " :radio").click(function () {
						but_next_light('on');
						var show_id = jQuery(this).attr('value');
						jQuery("#moneyorder").slideUp("slow");
						jQuery("#eubanktransfer").slideUp("slow");
						jQuery("#" + show_id).slideDown("slow");

					});

					jQuery("#basket input#file_ooo").change(function () {
						jQuery('#ajax-upload-file').show();
						var options2 = {
							//target:        '#uploadForm',   // target element to update
							beforeSubmit: showRequest,
							// pre-submit callback
							url: form_href.confirmation,
							// override for form's 'action' attribute 
							dataType: 'json',
							success: showResponse,
							// post-submit callback
							error: showResponse // post-submit callback
						};
						jQuery('#ajax-upload-file').show();
						jQuery('#basket_form').ajaxSubmit(options2);

						function showRequest(formData, jqForm) {

}
						function showResponse(responseText, statusText) {
							jQuery('#ajax-upload-file').hide();

						}
					});

					jQuery("#basket input").click(function () {
						if (jQuery(this).val() === 'Наименование организации' || jQuery(this).val() === 'ИНН') {
							jQuery(this).data("save", jQuery(this).attr('value'));
							jQuery(this).attr("value", "");
							return false;
						}
					});
				}

			},
			error: function (xhr, ajaxOptions, thrownError) {
				indicator.hide();
			}
		});
	}

	function load_data(form_data_for_function, next_menu_show) {
		indicator.show();
		jQuery.post(form_data_for_function, '', function (data) {
			if ('ok' == data.status) {
				jQuery.each(data, function (id, value) {
					jQuery("#" + id).attr('value', value);
				});
				if ('address' == next_menu_show) {
					if ('261' === jQuery('#zone_id').attr('value')) {
						jQuery("#basket input#piter").attr('checked', 'checked');
						jQuery("#basket input#postcode").attr('value', '');
						jQuery("#basket input#postcode").hide();
						jQuery("#basket input#radio_rus").show();
						jQuery("#basket span.radio_rus").show();
					}
					if ('260' === jQuery('#zone_id').attr('value')) {
						jQuery("#basket input#postcode").attr('value', '');
						jQuery("#basket input#moscow").attr('checked', 'checked');
						jQuery("#basket input#postcode").hide();
						jQuery("#basket input#radio_rus").show();
						jQuery("#basket span.radio_rus").show();
					}
					if (jQuery('#postcode').attr('value').length >= 6) {
						jQuery("#basket input#moscow").attr('checked', '');
						jQuery("#basket input#piter").attr('checked', '');
						jQuery("#basket input#postcode").show();
						jQuery("#basket input#radio_rus").hide();
						jQuery("#basket span.radio_rus").hide();
					}

				}

				/*Load*/
				if ('shipping' == next_menu_show) {
					load_html_data(form_href['shipping_noid'], 'shipping');
				}
				if ('payment_fiz' == next_menu_show) {
					load_html_data(form_href['shipping_noid'], 'payment_fiz');
				}

				var height = 100 * data.count;
				if ('book' == next_menu_show) {
					$block_menu_div['book'].show();
					var address_book_html = '';
					jQuery("#menu-book-cont").html('');
					if (parseInt(parseFloat(data.count), '10') >= 3) {
						jQuery("#add_address").hide();
					} else {
						height += 25;
					}
					jQuery(".block-address").height(height + 'px');
					jQuery.each(data, function (id_data, value_data_tmp) {
						if ('ok' === value_data_tmp.status) {
							address_book_html = '<div class="adr-1"><p class="adr-2">' + value_data_tmp.lastname_book + '</p><p>' + value_data_tmp.city_book + '</p><p>' + value_data_tmp.street_address_book + '</p><a href="#select_' + value_data_tmp.address_book_id_book + '" class="adr-3">Выбрать</a><a href="#del_' + value_data_tmp.address_book_id_book + '" class="adr-4">Удалить</a></div><br/><br/>';
							jQuery("#menu-book-cont").html(jQuery("#menu-book-cont").html() + address_book_html);
						}
					});

					jQuery(".adr-3").click(function () {
						/*Select address*/
						var click_href = jQuery(this).attr("href").replace(/\#select_/ig, "");

						load_data(form_href['address'] + '&edit=' + click_href, 'address', 'process');
						return false;
					});
					jQuery(".adr-4").click(function () {
						var click_href = jQuery(this).attr("href").replace(/\#del_/ig, "");

						load_data(form_href['address'] + '&delete=' + click_href, 'address', 'process');
						return false;
					});
				}

				/*Load*/
				if ('' !== next_menu_show && 'book' !== next_menu_show) show_only_one_menu(next_menu_show);
				indicator.hide();
				return true;
			} else { if ('no' === flag['registration_need']) {
					if ('address' == next_menu_show) {
						ErrorToDivInput(data.error);
						but_prev_light('off');
						show_only_one_menu(next_menu_show);
					}
				}
				indicator.hide();
				return false;
			}
		},
		'json');
		return false;
	}

	function send_data(form_data_for_function, next_menu_show, form_type) {
		indicator.show();
		jQuery("#action").attr('value', form_type);
		serialize = jQuery("#basket_form").serialize();
		jQuery.post(form_data_for_function, serialize, function (data) {
			if ('ok' == data.status) {
				/*send_data*/
				if ('yes' === flag['registration_need']) {
					if ('yes'===flag.old_user&&'address' == next_menu_show){
						flag['registration_need'] = 'no';
					}
					if ('shipping' == next_menu_show) {
						flag['registration_need'] = 'no';
						flag['login'] = 'yes';
						load_html_data(form_href['shipping_noid'], 'shipping');
					} else {
						but_prev_light('on');
					}
				}

				if ('no' === flag['registration_need']) {
					if ('address' == next_menu_show) {
						but_prev_light('off');
						flag['login'] = 'yes';
						load_data(form_href['address'], 'address', 'process');
					}
					if ('shipping' == next_menu_show) {
						but_prev_light('on');
						load_html_data(form_href['shipping_noid'], 'shipping');
					}
					if ('payment_fiz' == next_menu_show) {
						but_prev_light('on');
						load_html_data(form_href['payment_fiz_noid'], 'payment_fiz');
					}
					if ('order-ok' == next_menu_show) {
						jQuery(".bin_module").html('<table cellpadding="0" cellspacing="0" ><tr><td><span>В вашей <a href="http://www.hailait.ru/shop/shopping_cart.php"><u><b>корзине</b></u></a></span></td><td class="bin_content"><span>0 товар(ов)</span></td></tr><tr><td><span>На сумму</span></td><td class="bin_content"><span><b>0 </b>&nbsp;<a href="http://www.hailait.ru/shop/checkout_shipping.php"><u><b> <img src="i/rub_red.gif" alt="руб." /></span></td></tr></table>');
						send_data(form_href['submit'], 'submit', 'process');
					}
					if ('submit' == next_menu_show) {
						jQuery("#order_num").html('Ваш заказ №' + data.order_id);
					}
				}
				if ('submit' !== next_menu_show) show_only_one_menu(next_menu_show);
				indicator.hide();
				return true;
			} else { if ('no' === flag['registration_need']) {
					if ('address' == next_menu_show) {
						show_only_one_menu('account');
					}
				}
				ErrorToDivInput(data.error);
				indicator.hide();
				return false;
			}
		},
		'json');
		return false;
	}

	function load_and_check_status(menu) {
		if ('no' == flag['registration_need']) {
			if ('book' == menu) {
				load_data(form_href['book'], 'book', 'process');
			}
		}
		if ('yes' == flag['registration_need']) {
			if ('address' == menu) {
				but_next_light('off');
				send_data(form_href['login'] + "&old_user=" + flag['old_user'], 'address', 'process');
				return false;
			}

			if ('shipping' == menu) {
				send_data(form_href['registration_need'], 'shipping', 'process');
				return false;
			}
			if ('payment_fiz' == menu) {
				return false;
			}
		}
		if ('no' == flag['registration_need']) {

			if ('address' == menu) {
				if ('no' === flag['login']) {
					send_data(form_href['login'] + "&old_user=" + flag['old_user'], 'address', 'process');
				} else {
					load_data(form_href['address'], 'address', 'process');
				}
				but_prev_light('off');
				but_next_light('on');
				return false;
			}

			if ('shipping' == menu) {
				send_data(form_href['address'], 'shipping', 'update');
				return false;
			}
			if ('payment_fiz' == menu) {
				send_data(form_href['shipping'], 'payment_fiz', 'process');
				return false;
			}
			if ('order-ok' == menu) {
				send_data(form_href['confirmation'], 'order-ok', 'process');
				return false;
			}
		}
	}

	function cart_empty_check() {
		if ('no' === flag['user_cart']) {
			ShowError(0);
			jQuery("#login_cart").hide();
			return false;
		} else {
			jQuery("#login_cart").show();
			return true;
		}
		return true;
	}

	function but_next_light(switch_light) {
		if ('off' === switch_light) {
			jQuery('.but-next').css('background', 'url("images/next-prev.png") 0 -26px no-repeat');
		} else {
			jQuery('.but-next').css('background', 'url("images/next-prev.png") 0 0 no-repeat');
		}
		return false;
	}
	function but_prev_light(switch_light) {
		if ('off' === switch_light) {
			jQuery('.but-next-prev').css('background', 'url("images/next-prev.png") 0 -26px no-repeat');
		} else {
			jQuery('.but-next-prev').css('background', 'url("images/next-prev.png") 0 0 no-repeat');
		}
		return false;
	}


	//additional properties for jQuery object
	//align element in the middle of the screen
	jQuery.fn.alignCenter = function () {
		//get margin left
		var marginLeft = -jQuery(this).width() / 2 + 'px';
		//get margin top
		var marginTop = -jQuery(this).height() / 2 + 'px';
		//return updated element
		return jQuery(this).css({
			'margin-left': marginLeft,
			'margin-top': marginTop
		});
	};

	jQuery.fn.togglePopup = function () {
		//detect whether popup is visible or not
		if (jQuery('#popup').hasClass('hidden')) {
			//hidden - then display
			//when IE - fade immediately
			if (jQuery.browser.msie) {
				jQuery('#opaco').height(jQuery(document).height()).toggleClass('hidden');
			}
			else
			//in all the rest browsers - fade slowly
			{
				jQuery('#opaco').height(jQuery(document).height()).toggleClass('hidden');
			}

			jQuery('#popup').alignCenter().toggleClass('hidden');
		}
		else {
			//visible - then hide
			jQuery('#opaco').toggleClass('hidden').removeAttr('style');
			jQuery('#popup').toggleClass('hidden');
		}
	};
	
	if(jQuery.browser.safari) 
			jQuery('#popup').css('left','25%');

//</script>
