	
$(document).ready(function(){
	
	$.zoom_ext({
		piro_speed :700,
		bg_alpha : 0.5,
		piro_scroll : true,
		piro_drag :false,
		piro_nav_pos: 'bottom'
	});

	$('.route_header').click(function(){
		$(this).next().toggle();
	});
	

	
	$('#basket_img').click(function(){

		var ItemId = $('#order_button').attr('class');
		var name = $('h1').html();
		var price = $('.price').html();
		var main_id = $('#question_item').val();
		var TColorId = $('.color_a').attr('id');
		if(TColorId){
			var img_id = ''+main_id+'_c'+TColorId+'';
		}else{
			var img_id = main_id;
		}
		
		
		if(ItemId){
			var Size = $('.size_n').attr('id');
			if(typeof(Size) != 'undefined'){
				var SizeId = $('.size_a').attr('id');
			}else{
				var SizeId = '0';
			}
			
			var Color = $('.color_n').attr('id');
			if(typeof(Color) != 'undefined'){
				var ColorId = $('.color_a').attr('id');
			}else{
				var ColorId = '0';
			}
			if(typeof(ColorId && SizeId) !== 'undefined'){
				$('.slidingProduct').attr('id', 'slidingProduct' + ItemId + '|' + ColorId + '|' + SizeId + '');
				addToBasket( ''+ ItemId + '|' + ColorId + '|' + SizeId + '');
				$('#bs_content').html('<a href="/catalog/item/'+main_id+'/"><img src="/files/images/catalog/'+img_id+'.jpg" style="float:left; padding-right:10px;" /></a><h4><a href="/catalog/item/'+main_id+'/">'+name+'</a></h4><span class="price_mini">'+price+'</span>');
				$('.basket_slide_out').slideDown().delay(1000).slideUp();
			}else{
				$('#FormError').fadeIn().delay(500).fadeOut();
			}
		
		}else{
			$('#bs_content').html('<a href="/catalog/item/'+main_id+'/"><img src="/files/images/catalog/'+img_id+'.jpg" style="float:left; padding-right:10px;" /></a><h4><a href="/catalog/item/'+main_id+'/">'+name+'</a></h4><span class="price_mini">'+price+'</span>');
			$('.basket_slide_out').slideDown().delay(1000).slideUp();
		}

	});
	
	
	//офлайн-каталог
	$('#open_offlinecat_form').click(function(){
		$('#offlinecat_form').show();
		$('#view_offlinecat_sign').hide();
	});
	
	$('#close_offlinecat_form').click(function(){
		$('#offlinecat_form').hide();
		$('#view_offlinecat_sign').show();
	});
	
	$('#send_offlinecat_form').click(function(){
		if(checkOfflinecatForm()!=1)
		$('#offlinecat').submit();
		return false;
	});

	
	function checkOfflinecatForm(){
		var name = $('#post_clientname').val(); if(!name){
			$('#post_clientname').parent().children('span').attr('style', 'color:#b04444;'); var error=1;
		}else{
			$('#post_clientname').parent().children('span').attr('style', 'color:#6ba94f;');
		}
		var zip = $('#post_index').val(); if(!zip){
			$('#post_index').parent().children('span').attr('style', 'color:#b04444;'); var error=1;
		}else{
			$('#post_index').parent().children('span').attr('style', 'color:#6ba94f;');
		}
		var city = $('#post_city').val(); if(!city){
			$('#post_city').parent().children('span').attr('style', 'color:#b04444;'); var error=1;
		}else{
			$('#post_city').parent().children('span').attr('style', 'color:#6ba94f;');
		}
		var street = $('#post_street').val(); if(!street){
			$('#post_street').parent().children('span').attr('style', 'color:#b04444;'); var error=1;
		}else{
			$('#post_street').parent().children('span').attr('style', 'color:#6ba94f;');
		}		
		var email = $('#post_email').val(); if(!email){
			$('#post_email').parent().children('span').attr('style', 'color:#b04444;'); var error=1;
		}else{
			$('#post_email').parent().children('span').attr('style', 'color:#6ba94f;');
		}		
		var phone = $('#post_phone').val(); if(!phone){
			$('#post_phone').parent().children('span').attr('style', 'color:#b04444;'); var error=1;
		}else{
			$('#post_phone').parent().children('span').attr('style', 'color:#6ba94f;');
		}
		
		if(error) return 1;
		
		
		return 2;
	}
	
	$('.color_n').click(function(){
		var ItemId = $('#order_button').attr('class');
		var imgid = this.id;
		$('#largeImage').attr('src', '/files/images/catalog/' + ItemId + 'b_c' + imgid + '.jpg' );
		
		
		$(".color_n").each(function(){
			if(this.id==imgid)
			{ 
				$(this).toggleClass("color_a");
				$(this).children('img#color_frame').toggleClass("c_a");
			}
			else
			{ 
				$(this).removeClass("color_a");
				$(this).children('img#color_frame').removeClass("c_a");
			}
		});
	});
	
	
	$('div.size_n').click(function(){
		var sizeid = this.id;
		$(".size_n").each(function(){
			if(this.id==sizeid) $(this).toggleClass("size_a");
			else $(this).removeClass("size_a");
		});
		
		$('#slidingProduct1419').toggleClass($(this).attr('id'));
		$('a.asdasd').attr('onClick', + ItemId + $(this).attr('id'));
		//var SizeId = $(this)
		
	});
	
	$('.popup_close').click(function(){
		var closeId = this.id;
		$('.'+closeId+'').toggle();
		return false;
	});
	
	$('#login_link').click(function(){
		$('.login_form').toggle();
		
		var email = $('#email').val();
		var pass = $('#password').val();
		if(email && pass){
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:none;' );
		}else{
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:block;' );
		}

		return false;
		
	});
	
	$('#but_login').click(function(){
		$('.login_form').toggle();
		
		var email = $('#email').val();
		var pass = $('#password').val();
		if(email && pass){
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:none;' );
		}else{
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:block;' );
		}
		
		return false;
	});
	
	$('div.login_background').click(function(){
		$('.login_form').toggle();
		return false;
		
	});
	
	$('div.question_form_link').click(function(){
		$('.question_form').toggle();
		return false;
		
	});
	
	$('.sp_adress').click(function(){
		$('.sp_adress_pad').toggle();
		return false;
		
	});
	
	$('.starbar_w a').click(function(){
		var rating = $(this).attr('class');
		var item_id = $(this).attr('id');
		rating = Number(rating.replace(/\D+/g,""));
		item_id = Number(item_id.replace(/\D+/g,""));
		rating_w = 30*rating;
		var data = 'item_id='+item_id+'&item_rating='+rating+'';
		
		$('.starbar_w').addClass('user');
		$('.starbar_w').attr('style', 'width:'+rating_w+'px; display:block;');
		
		if(rating && item_id){

			$.ajax({
				type: "POST", url: '/inc/ajax/rating.php', data: data,
				success: function(html){
					
				}
			});
		}
	
		return false;
	});	

	$('#question_another').click(function(){
		$('#question_another').hide();
		$('#question_message').hide();
		$('#question_table').show();
	});
	
	$('#question_send_button').click(function() {
		var q_name = $('#question_name').val();
		var q_email = $('#question_email').val();
		var q_text = $('#question_text').val();
		var q_item = $('#question_item').val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;		
		if(reg.test(q_email) == false) {
			var email = '';
			$('#question_email').attr('style', 'border:2px solid #cc5959; width:255px; padding:3px;');
		}else{
			var email = q_email;
		}
		var data = 'question_email='+email+'&question_name='+q_name+'&question_item='+q_item+'&question_text='+q_text+'';
		
		if(!email){
			$('#question_email').attr('style', 'width:186px; padding:3px; border:2px solid #c02323;');
		}else{
			$('#question_email').attr('style', 'width:186px; padding:3px; border:1px solid #abadb3;');
		}
		if(!q_name){
			$('#question_name').attr('style', 'width:186px; padding:3px; border:2px solid #c02323;');
		}else{
			$('#question_name').attr('style', 'width:186px; padding:3px; border:1px solid #abadb3;');
		}
		if(!q_text){
			$('#question_text').attr('style', 'width:475px;height:198px; font-family:arial; padding:5px; border:2px solid #c02323;');
		}else{ 
			$('#question_text').attr('style', 'width:475px;height:198px; font-family:arial; padding:5px; border:1px solid #abadb3;');
		}
		if(q_name && email && q_text && q_item){
			$.ajax({
				type: "POST", url: '/inc/ajax/question.php', data: data,
				success: function(html){
					$('#question_message').html(html);
					$('#question_message').show();
					$('#question_text').val('');
					$('#question_table').hide();
					$('#question_another').show();
				}
			});
		}
		
		return false;
	});
	
	$('#message_another').click(function(){
		$('#message_another').hide();
		$('#ms_message').hide();
		$('#message_table').show();
	});
	
	$('#message_send_button').click(function() {
		var m_name = $('#message_send_name').val();
		var m_email = $('#message_send_email').val();
		var m_text = $('#message_send_text').val();
		var m_item = $('#message_send_item').val();
		var data = 'message_name='+m_name+'&message_item='+m_item+'&message_email='+m_email+'&message_text='+m_text+'';
		
		if(!m_text){
			$('#message_send_text').attr('style', 'width:475px;height:198px; font-family:arial; padding:5px; border:2px solid #c02323;');
		}else{ 
			$('#message_send_text').attr('style', 'width:475px;height:198px; font-family:arial; padding:5px; border:1px solid #abadb3;');
		}
		
		if(m_name && m_text && m_item){
		
			$.ajax({
				type: "POST", url: '/inc/ajax/message_send.php', data: data,
				success: function(html){
					$('#ms_message').html(html);
					$('#ms_message').show();
					$('#message_send_text').val('');
					$('#message_table').hide();
					$('#message_another').show();
					

				}
			});
		}
		
		return false;
	});
	
	$('.enter_site').click(checkaccess);
	
	$('#password').bind('keypress', function(e) {
		if(e.keyCode==13){
			checkaccess();
		}
	});
	
	$('#email').bind('keypress', function(e) {
		if(e.keyCode==13){
			checkaccess();
		}
	});
	
	$('div.login_background').hover(function(){
		$('#login_link').addClass('login_aa');
		}, function(){
		$('#login_link').removeClass('login_aa');
			
	});
	
	$('#email').keyup(function() {
		var email = $('#email').val();
		var pass = $('#password').val();
		if(email && pass){
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:none;' );
		}else{
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:block;' );
		}
		
	});
	
	$('#password').keyup(function() {
		var email = $('#email').val();
		var pass = $('#password').val();
		if(email && pass){
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:none;' );
		}else{
			$('img#enter_na').attr('style', 'position:absolute; z-index:30; display:block;' );
		}
	});
	
	$('#thumbs img').click(function(){
		var curImg = $(this).attr('title');
		$('#largeImage').attr('src', '/files/images/catalog/'+curImg+'.jpg' );
		
		//$(this).toggleClass("thumbs_a");
		
		$('.thumbs_n').each(function(){
			if($(this).attr('title')==curImg) $(this).addClass("thumbs_a");
			else $(this).removeClass("thumbs_a");
		});
		
		
	});
	
	$('input:radio[name=client_status]').click(function(){
		var ordClientStatus = $('input:radio[name=client_status]:checked').val();
		if(ordClientStatus==1) {
			$('#reg_form').attr('style', 'display:block');
			$('#auth_form').attr('style', 'display:none');
			
		}else{
			$('#reg_form').attr('style', 'display:none');
			$('#auth_form').attr('style', 'display:block');
		}
	});
	
	$('input:radio[name=client_auth_payment]').click(function(){
		var ordClientStatus = $('input:radio[name=client_auth_payment]:checked').val();
		if(ordClientStatus==2) {
			$('#client_auth_requisites').attr('disabled', '');
		}else{
			$('#client_auth_requisites').attr('disabled', 'disabled');
			$('#client_auth_requisites').val('');
		}
	});
	
	$('input:radio[name=client_reg_type]').click(function(){
		var ordClientType = $('input:radio[name=client_reg_type]:checked').val();
		if(ordClientType==1){
			$('#client_reg_requisites').val('');
			$('#client_reg_requisites').attr('disabled', 'disabled');
		}else{ 
			$('#client_reg_requisites').attr('disabled', '');
		}
	});

	$('#save_changes_a').click(function(){
		$('#basket_recount').submit();     
	});
	
	$('#submit_clients_auth').click(function(){
		if (checkAuth()!=1) {
			$('#client_auth_form').submit();
		}
		
		return false;
	});
	
	$('#submit_clients_order').click(function(){
		$('#client_send_order').submit();
		return false;
	});
	
	$('#leave_order').click(function(){
		$('#client_send_order').submit();
		return false;
	});
	
	$('#submit_clients_personal').click(function(){
		if (checkPersonalData()!=1) {
			$('#client_personal_data_form').submit();
		}
		
		return false;
	});
	
	$('#submit_clients_reg').click(function(){
		if (checkReg()!=1) $('#reg_form').submit(); 
		
		return false;
	});
	
	$('img.delete_item').hover(function(){
		$(this).attr('src', '/img/close_order_red.gif');
		}, function(){
		$(this).attr('src', '/img/close_order.gif');
		
	});
	
	function checkAuth(){
		var client_status = $('input:radio[name=client_status]:checked').val();
		var email=$('#client_auth_email').val();
		var email2=$('#client_reg_email').val();
		var pass = $('#client_auth_pass').val();
		var pass2 = $('#client_reg_pass').val();
		var mailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(client_status==1){
			if(!email){
				$('div#error_email_empty').attr('style', 'display:block;'); var error=1;
				$('div#error_email_wrong').attr('style', 'display:none;');
			}else if(mailreg.test(email) == false){ 
				$('div#error_email_wrong').attr('style', 'display:block;'); var error=1;
				$('div#error_email_empty').attr('style', 'display:none;');		
			}else{
				$('#client_auth_email').parent().next().html('<img src="/img/ok.gif">');
				$('div#error_email_empty').attr('style', 'display:none;');
				$('div#error_email_wrong').attr('style', 'display:none;');
			}
			if(!pass){
				$('#client_auth_pass').parent().children('div').attr('style', 'display:block;'); var error=1;
			}else{
				//$('#client_auth_pass').parent().children('div').attr('style', 'display:none;');
			}
				
		}else{
			if(!email2){
				$('div#error_email_empty').attr('style', 'display:block;'); var error=1;
				$('div#error_email_wrong').attr('style', 'display:none;');
			}else if(mailreg.test(email2) == false) { 
				$('div#error_email_wrong').attr('style', 'display:block;'); var error=1;
				$('div#error_email_empty').attr('style', 'display:none;');		
			}else{
				$('#client_reg_email').parent().next().html('<img src="/img/ok.gif">');
				$('div#error_email_empty').attr('style', 'display:none;');
				$('div#error_email_wrong').attr('style', 'display:none;');
			}

			var pass = $('#client_reg_pass').val();
			if(!pass){
				$('#client_reg_pass').parent().children('div').attr('style', 'display:block;'); var error=1;
			}else{
				//$('#client_reg_pass').parent().children('div').attr('style', 'display:none;');
			}

		}
		if(error) return 1;
		
		
		return 2;
	}
	
	function checkReg(){
		var client_add_personal = $('input:radio[name=add_personal_info]:checked').val();
		var email=$('#client_reg_email').val();
		checkEmail(email);
		var email_occupied=$('#email_occupied').val();
		var mailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var numreg = /^([\d\s\-()+])+$/;
		
		
		if(!email){
			$('div#error_email_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_email_wrong').attr('style', 'display:none;');
			$('div#error_email_occupied').attr('style', 'display:none;');
		}else if(mailreg.test(email) == false){
			$('div#error_email_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_email_empty').attr('style', 'display:none;');
			$('div#error_email_occupied').attr('style', 'display:none;');
		}else if(email_occupied==2){
			$('div#error_email_occupied').attr('style', 'display:block;'); var error=1;
			$('div#error_email_wrong').attr('style', 'display:none;');
			$('div#error_email_empty').attr('style', 'display:none;');	
		}else{
			$('#client_reg_email').parent().next().html('<img src="/img/ok.gif">');
			$('div#error_email_empty').attr('style', 'display:none;');
			$('div#error_email_wrong').attr('style', 'display:none;');
			$('div#error_email_occupied').attr('style', 'display:none;');
		}
		
		var pass = $('#client_reg_pass').val(); if(pass.length<5){
			$('#client_reg_pass').parent().children('div').attr('style', 'display:block;'); var error=1;
		}else{
			$('#client_reg_pass').parent().next().html('<img src="/img/ok.gif">');
			$('#client_reg_pass').parent().children('div').attr('style', 'display:none;');
		}
		if(client_add_personal==1){
			var surname = $('#client_reg_surname').val(); if(!surname){
				$('#client_reg_surname').parent().children('div').attr('style', 'display:block;'); var error=1;
			}else{
				$('#client_reg_surname').parent().next().html('<img src="/img/ok.gif">');
				$('#client_reg_surname').parent().children('div').attr('style', 'display:none;');
			}
			var fname = $('#client_reg_firstname').val(); if(!fname){
				$('#client_reg_firstname').parent().children('div').attr('style', 'display:block;'); var error=1;
			}else{
				$('#client_reg_firstname').parent().next().html('<img src="/img/ok.gif">');
				$('#client_reg_surname').parent().children('div').attr('style', 'display:none;');
			}
			/*
			var secondname = $('#client_reg_secondname').val(); if(!secondname){
				$('#client_reg_secondname').parent().children('div').attr('style', 'display:block;'); var error=1;
			}else{
				$('#client_reg_secondname').parent().next().html('<img src="/img/ok.gif">');
				$('#client_reg_surname').parent().children('div').attr('style', 'display:none;');
			}
			
		
			var phone = $('#client_reg_phone').val();
			if(!phone){
				$('div#error_phone_empty').attr('style', 'display:block;'); var error=1;
				$('div#error_phone_wrong').attr('style', 'display:none;');
			}else if(numreg.test(phone) == false) { 
				$('div#error_phone_wrong').attr('style', 'display:block;'); var error=1;
				$('div#error_phone_empty').attr('style', 'display:none;');		
			}else{
				$('#client_reg_phone').parent().next().html('<img src="/img/ok.gif">');
				$('div#error_phone_empty').attr('style', 'display:none;');
				$('div#error_phone_wrong').attr('style', 'display:none;');
			}
			*/
			
			var mphone = $('#client_reg_mphone').val(); 
			if(!mphone){
				$('div#error_mphone_empty').attr('style', 'display:block;'); var error=1;
				$('div#error_mphone_wrong').attr('style', 'display:none;');
			}else if(numreg.test(mphone) == false) { 
				$('div#error_mphone_wrong').attr('style', 'display:block;'); var error=1;
				$('div#error_mphone_empty').attr('style', 'display:none;');		
			}else{
				$('#client_reg_mphone').parent().next().html('<img src="/img/ok.gif">');
				$('div#error_mphone_empty').attr('style', 'display:none;');
				$('div#error_mphone_wrong').attr('style', 'display:none;');
			}
			
			var address = $('#client_reg_address').val(); if(!address){
				$('#client_reg_address').parent().children('div').attr('style', 'display:block;'); var error=1;
			}else{
				$('#client_reg_address').parent().next().html('<img src="/img/ok.gif">');
				$('#client_reg_address').parent().children('div').attr('style', 'display:none;');
			}
		}
		
		if(error) return 1;
		
		
		return 2;
	}
	
	function checkPersonalData(){
		var numreg = /^([\d\s\-()+])+$/;
		var surname = $('#client_auth_surname').val(); if(!surname){
			$('#client_auth_surname').parent().children('div').attr('style', 'display:block;'); var error=1;
		}else{
			$('#client_auth_surname').parent().next().html('<img src="/img/ok.gif">');
			$('#client_auth_surname').parent().children('div').attr('style', 'display:none;');
		}
		var fname = $('#client_auth_firstname').val(); if(!fname){
			$('#client_auth_firstname').parent().children('div').attr('style', 'display:block;'); var error=1;
		}else{
			$('#client_auth_firstname').parent().next().html('<img src="/img/ok.gif">');
			$('#client_auth_surname').parent().children('div').attr('style', 'display:none;');
		}
		
		/*
		var secondname = $('#client_auth_secondname').val(); if(!secondname){
			$('#client_auth_secondname').parent().children('div').attr('style', 'display:block;'); var error=1;
		}else{
			$('#client_auth_secondname').parent().next().html('<img src="/img/ok.gif">');
			$('#client_auth_surname').parent().children('div').attr('style', 'display:none;');
		}
		
		var phone = $('#client_auth_phone').val();
		if(!phone){
			$('div#error_phone_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_phone_wrong').attr('style', 'display:none;');
		}else if(numreg.test(phone) == false) { 
			$('div#error_phone_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_phone_empty').attr('style', 'display:none;');		
		}else{
			$('#client_reg_phone').parent().next().html('<img src="/img/ok.gif">');
			$('div#error_phone_empty').attr('style', 'display:none;');
			$('div#error_phone_wrong').attr('style', 'display:none;');
		}
		*/
		
		var mphone = $('#client_auth_mphone').val(); 
		if(!mphone){
			$('div#error_mphone_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_mphone_wrong').attr('style', 'display:none;');
		}else if(numreg.test(mphone) == false) { 
			$('div#error_mphone_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_mphone_empty').attr('style', 'display:none;');		
		}else{
			$('#client_reg_mphone').parent().next().html('<img src="/img/ok.gif">');
			$('div#error_mphone_empty').attr('style', 'display:none;');
			$('div#error_mphone_wrong').attr('style', 'display:none;');
		}
		
		var address = $('#client_auth_address').val(); if(!address){
			$('#client_auth_address').parent().children('div').attr('style', 'display:block;'); var error=1;
		}else{
			$('#client_auth_address').parent().next().html('<img src="/img/ok.gif">');
			$('#client_auth_address').parent().children('div').attr('style', 'display:none;');
		}

		
		if(error) return 1;
		
		
		return 2;
	}
	
	$('.form_auth_txt').focusout(function(){
		var curFieldVal = $(this).val();
		if(!curFieldVal){ 
			$(this).parent().next().html('');
			$(this).parent().children('div').attr('style', 'display:block;');
		}else{ 
			$(this).parent().next().html('<img src="/img/ok.gif">'); 
			$(this).parent().children('div').attr('style', 'display:none;');
		}
	});
	
	/*
	$('.form_auth_pass').focusout(function(){
		var curFieldVal = $(this).val();
		if(curFieldVal.length<1){ 
			$(this).parent().next().html('');
			$(this).parent().children('div').attr('style', 'display:block;');
		}else{ 
			$(this).parent().children('div').attr('style', 'display:none;');
		}
	});
	*/
	
	$('.form_auth_txta').focusout(function(){
		var curFieldVal = $(this).val();
		if(!curFieldVal){ 
			$(this).parent().next().html('');
			$(this).parent().children('div').attr('style', 'display:block;');
		}else{ 
			$(this).parent().next().html('<img src="/img/ok.gif">'); 
			$(this).parent().children('div').attr('style', 'display:none;');
		}
	});
	
	$('.form_auth_phone').focusout(function(){
		var tempfval = $(this).val();
		var numreg = /^([\d\s\-()+])+$/;
		if(!tempfval){
			$(this).parent().next().html('');
			$('div#error_phone_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_phone_wrong').attr('style', 'display:none;');
		}else if(numreg.test(tempfval) == false){
			$(this).parent().next().html('');
			$('div#error_phone_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_phone_empty').attr('style', 'display:none;');
		}else{
			$(this).parent().next().html('<img src="/img/ok.gif">'); 
			$('div#error_phone_empty').attr('style', 'display:none;');
			$('div#error_phone_wrong').attr('style', 'display:none;');
		}
	});
	
	$('.form_auth_mphone').focusout(function(){
		var tempfval = $(this).val();
		var numreg = /^([\d\s\-()+])+$/;
		if(!tempfval){
			$(this).parent().next().html('');
			$('div#error_mphone_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_mphone_wrong').attr('style', 'display:none;');
		}else if(numreg.test(tempfval) == false){
			$(this).parent().next().html('');
			$('div#error_mphone_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_mphone_empty').attr('style', 'display:none;');
		}else{
			$(this).parent().next().html('<img src="/img/ok.gif">'); 
			$('div#error_mphone_empty').attr('style', 'display:none;');
			$('div#error_mphone_wrong').attr('style', 'display:none;');
		}
	});
	
	$('.form_auth_mail').focusout(function(){
		var email=$(this).val();
		var mailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(!email){
			$(this).parent().next().html('');
			$('div#error_email_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_email_wrong').attr('style', 'display:none;');
		}else if(mailreg.test(email) == false){
			$(this).parent().next().html('');			
			$('div#error_email_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_email_empty').attr('style', 'display:none;');
						
		}else{
			$(this).parent().next().html('<img src="/img/ok.gif">');
			$('div#error_email_empty').attr('style', 'display:none;');
			$('div#error_email_wrong').attr('style', 'display:none;');
		}
		
		return false;
	});
	
	$('.form_registration_mail').focusout(function(){
		var email=$(this).val();
		checkEmail(email);
		var mailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var email_occupied=$('#email_occupied').val();
		

		if(!email){
			$(this).parent().next().html('');
			$('div#error_email_empty').attr('style', 'display:block;'); var error=1;
			$('div#error_email_wrong').attr('style', 'display:none;');
			$('div#error_email_occupied').attr('style', 'display:none;');
		}else if(mailreg.test(email) == false){
			$(this).parent().next().html('');			
			$('div#error_email_wrong').attr('style', 'display:block;'); var error=1;
			$('div#error_email_empty').attr('style', 'display:none;');
			$('div#error_email_occupied').attr('style', 'display:none;');
		}else if(email_occupied==2){
			$(this).parent().next().html('');			
			$('div#error_email_occupied').attr('style', 'display:block;'); var error=1;
			$('div#error_email_wrong').attr('style', 'display:none;');
			$('div#error_email_empty').attr('style', 'display:none;');	
		}else{
			$(this).parent().next().html('<img src="/img/ok.gif">');
			$('div#error_email_empty').attr('style', 'display:none;');
			$('div#error_email_wrong').attr('style', 'display:none;');
			$('div#error_email_occupied').attr('style', 'display:none;');
		}

		return false;
	});
	
	function checkEmail(email){
		var data = 'check_email='+email+'';
		if(email){
			$.ajax({
				type: "POST", url: '/inc/ajax/checkemail.php', data: data,
				success: function(html){
					if(html==1){
						$('#email_occupied').val('2'); 
					}else{
						$('#email_occupied').val('1');
					}
				}
			});
		}
	}
	
	function checkaccess(){
		var email = $('#email').val();
		var pass = $('#password').val();
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;		
		if(reg.test(email) == false) {
			var login = '';
			$('#email').attr('style', 'border:2px solid #cc5959; width:255px; padding:3px;');
		}else{
			var login = email;
		}
		var data = 'email='+login+'&password='+pass+'';
		
		if(!login){
			$('#email').attr('style', 'border:2px solid #cc5959; width:255px; padding:3px;');
		}
		else {
			$('#email').attr('style', 'width:255px; padding:3px;');
		}
		if(!pass){
			$('#password').attr('style', 'border:2px solid #cc5959; width:255px; padding:3px;');
		}
		else{ 
			$('#password').attr('style', 'width:255px; padding:3px;');
		}
		if(login && pass){
			$.ajax({
				type: "POST", url: '/inc/ajax/login.php', data: data,
				success: function(html){
					if(html==1) {
						$("#login_reply").html('<i><font color=red>Неверный логин или пароль</font></i>');
						$('#email').attr('style', 'border:2px solid #cc5959; width:255px; padding:3px;');
						$('#password').attr('style', 'border:2px solid #cc5959; width:255px; padding:3px;');
					}
					if(html==2) $('#login_form').submit();
				}
			});
		}
	}

});

/*
	$('input:radio[name=add_personal_info]').click(function(){
		var ordClientPI = $('input:radio[name=add_personal_info]:checked').val();
		if(ordClientPI==2) $('#client_personal_info').attr('style', 'display:none;');
		else $('#client_personal_info').attr('style', 'display:block;');
		
	});
*/

$(document).click(function(){
	var ordClientPI = $('input:radio[name=add_personal_info]:checked').val();
	if(ordClientPI==2) $('#client_personal_info').attr('style', 'display:none;');
	else $('#client_personal_info').attr('style', 'display:block;');
});

$(document).click(function(event) {
    if ($(event.target).closest(".login_form").length) return;
    $(".login_form").hide();
    event.stopPropagation();
});

$(document).click(function(event) {
    if ($(event.target).closest(".sp_adress_pad").length) return;
    $(".sp_adress_pad").hide();
    event.stopPropagation();
});



/*
$(document).ready(function(){
		SwitchImage();
});

function SwitchImage() {
	$("#banner_newyear2012").animate({opacity: "hide"},4000);
	$("#banner_newyear2012").animate({opacity: "show"},4000);
	setTimeout('SwitchImage()',4000);

}
*/
