﻿//**************************//
function switch_photo(element, dest) {
    var pic = element.title, id=element.id;
	var big = document.getElementById(dest);

	big.src = "./pics/img_preloader.gif";
	big.src = "./pics/medium/" + pic;
	$('#other_pics td').css({'border' : '1px solid #cdcecf'});
	$('#td_'+id).css({'border' : '1px solid #cdcecf'});
}
//**************************//
function add_to_cart() {
  $.post( 'index.php',
    {
	  'query': 'add_to_cart',
      'id' : $('#id').val(),
      'quant' : $('#quant').val(),
      'price' : $('#price').val()
	},
	function(data){ if ( data == "OK!" ){ get_cart_info(); cart_transfer('transfer_div', 'cart_info'); } else { alert("Ошибка добавления товара"); } }
  );
}
/***********************/
function cart_transfer(source, dest) {
  $("#"+source).effect("transfer", { to: "#"+dest }, 1000);
}
/***********************/
function get_cart_info() {
  $('#cart_info').html("Загрузка данных...");
  $.post('index.php', {'query': 'cart_info'}, function(data){$('#cart_info').html(data);});	
}
/***********************/
function to_cart_from_list(id) {
  $.post( 'index.php',
    {
	    'query': 'add_to_cart',
		  'id' : id,
		  'quant' : '1',
		  'price' : $('#price_'+id).val()
	  },
	  function(data){ if ( data == "OK!" ){ get_cart_info(); } else { alert("Ошибка добавления товара"); } }
		//function(data){ alert(data); }
  );
	  
}
/***********************/
function add_one(id) {
  $.post( 'index.php',
    {
	    'query': 'add_to_cart',
		  'id' : id,
		  'quant' : '1',
		  'price' : $('#price_'+id).val()
	  },
	  function(data){ if ( data == "OK!" ){ reload_cart(); } else { alert("Ошибка добавления товара"); } }
		//function(data){ alert(data); }
  );
	  
}
/***********************/
function del_one(id) {
  $.post( 'index.php',
    {
	    'query': 'del_one',
		  'id' : id,
		  'quant' : '1'
	  },
	  function(data){ if ( data == "OK!" ){ reload_cart(); } else { alert("Ошибка удаления товара"); } }
  );
	  
}
/***********************/
function reload_cart() {
  $('#cart').html("Загрузка данных...");
  $.post('index.php', {'query': 'reload_cart'}, function(data){$('#cart').html(data);});	
}
/***********************/
function send_message() {
  $.post( 'index.php',
    {
      'query' : 'send_message',
      'name' : $('#name').val(),
      'message' : $('#message').val(),
      'code' : $('#code').val(),
      'email' : $('#email').val()
    },
	  function(data){ if ( data == "OK!" ){ alert("Ваше сообщение отправлено") } else { alert(data); } }
  
  );
}
/***********************/
function load_map() {
  var map = new YMaps.Map(document.getElementById("map_holder"));
  var zoom = new YMaps.Zoom();
  map.addControl(zoom);

  var point = new YMaps.GeoPoint(36.226971,49.991021);
  var placemark = new YMaps.Placemark(point);
  map.addOverlay(placemark);

  map.setCenter(new YMaps.GeoPoint(36.226971, 49.991021), 16);
}
/***********************/
function checkout() {
  if ( !register() ) { return; }
  else {
    $.post('index.php', {'query': 'checkout', 'comment' : $('#comment').val()}, function(data){ if ( data=='OK!' ){window.location = 'index.php?page=static&pid=2'; } else { alert(data); }}
	  );	
  }
}
/***********************/
function register() {
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  if ( reg.test($('#email').val()) == false ){ alert("Неправильный формат почтового адреса");  return false; }
	$.post('index.php', 
    {
      'query': 'register', 
	    'id' : 'null',
      'email': $('#email').val(), 
		  'name': $('#name').val(),
		  'phone': $('#phone').val(),
		  'city': $('#city').val(),
		  'privileges' : 'user'
		}, function(data){ 
	        if ( data != 'OK!' ){ alert(data); return false;}
		}
	);
  return true;
}
/***********************/
function del_cart_item(id) {
  $.post('index.php', {'query': 'del_cart_item', 'id': id}, function(data){reload_cart();});	
}
/***********************/
function right_carousel() {
  $("#skv_carusel").jCarouselLite({
    btnNext: ".carusel_down",
    btnPrev: ".carusel_up",
    vertical: true
  }); 
}
/***********************/
function carousel() {
  $(".brands_list").jCarouselLite({
    btnNext: ".btnRight",
    btnPrev: ".btnLeft"
  }); 
}
