

$(document).ready(function(){
		
//$.modalshow();

// корзина

$(".basket_input").keypress(function (e)  
	{ 
	  if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
	    return false;       	
	});
	


 if ( ($.browser.msie && $.browser.version.substr(0,1)<7))
           { 
           		//if ($("#middle").width()>1054)
           		  //$("#middle").csstext('width:1050px;')	
           		$(".sl").css("margin-left","-100%");
           		//alert('11');
           		//sidebar sl	
       	   }

$(".basket_input").change(function (e)  
	{ 
		var value=parseInt(this.value);
		if (value<1 || !parseInt(this.value))  { $('#'+this.id).val('1');}
		//alert(this.id);
		//this.value=1;
		
	});	

	
$(".basket_input").keyup(function (e)  
	{ 
		//var id=this.id.split('i_cnt').join('');
		var value=parseInt(this.value);
		//parseInt($('#'+this.id).val());	 
		if (parseInt(value)) 
		  	 update_basket(this.id,value);
		else
		 	update_basket(this.id,1);
		 
		
	});

});
	

function update_basket(id,value) {
  		$.get('/ajax_basket.php?id='+id+'&value='+value, function (responseText, textStatus, XMLHttpRequest) {
											eval(responseText);
								});
  
}	
function delete_from_basket(id,language) {
	  $('#basket_i'+id).fadeOut();
  		$.get('/ajax_basket.php?id='+id+'&delete_item=1&lang='+language, function (responseText, textStatus, XMLHttpRequest) {
											eval(responseText);
								});
  
}

	
(function($) {
    $.extend({
        doGet: function(url, params) {
            document.location = url + '?' + $.param(params);
        },
        doPost: function(url, params) {
   
     	 	
        	 
        if ($.browser.msie) { 
        	var div = document.createElement("div");
            div.id = "myDiv"; 
            var frm='<form name="lgt_frm" id="lgt_frm" method="post" action="'+url+'">'; 
            $.each(params, function(name, value) {
            	frm=frm+'<input type="hidden" name="'+name+'" value="'+value+'" /> ';
             });
            frm+=" </form>";
            div.innerHTML=frm;
            div.className = "original";
            document.body.appendChild(div);
        	document.forms['lgt_frm'].submit(); 	
        	}	
        	
        else	
        	{
	            var $form = $("<form method='POST' name='dd'>").attr("action", url);
	            $.each(params, function(name, value) {
	                $("<input type='hidden'>")
	                    .attr("name", name)
	                    .attr("value", value)
	                    .appendTo($form);
	            });
	            $form.appendTo("body");
	            $form.submit();
            }
        	
        	
        }
    });
})(jQuery);





function check_email_form(lang) {
   $('.fill_form').hide();
	var mesage='';
	
	
	if (lang=='ru')
		{
			if ($('#name').val().length <1)
				{
					mesage=mesage+'<li>Ваше имя</li>';			
				}	
		
			if ($('#email').val().length <1)
				{
					mesage=mesage+'<li>Электронная почта</li>';			
				}
			if ($('#phone_').val().length <1)
				{
					mesage=mesage+'<li>Телефон</li>';			
				}
		   if ($('#message').val().length <1)
				{
					mesage=mesage+'<li>Сообщение</li>';			
				}		
		}
	else
		{
			if ($('#name').val().length <1)
				{
					mesage=mesage+'<li>Your name</li>';			
				}	
		
			if ($('#email').val().length <1)
				{
					mesage=mesage+'<li>E-mail</li>';			
				}
			if ($('#phone_').val().length <1)
				{
					mesage=mesage+'<li>Phone</li>';			
				}
		   if ($('#message').val().length <1)
				{
					mesage=mesage+'<li>Message</li>';			
				}			
			
		}	
	
	

									
	
	if (mesage!='')	
	  {		
	  	$('.fill_form').show();
	  	$('#fill_form').html(mesage);								
		return false;
	  }
	else
	  return true; 
}



function add_basket(id) {
	
	$.doPost(document.location, {
    						add_to_basket: id
							});
	
	//$.modalshow(id);
	//$.cookie('the_cookie', 'the_value', { expires: 7, path: '/'});
	/* 
	$.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
	*/
}

function basket_delete(id) {
	$('#basket_item'+id).fadeOut(200);
	$.get('/ajax_basket.php?id='+id+'&delete_item=1', function (responseText, textStatus, XMLHttpRequest) {
											eval(responseText);
								});
}


/* КУКИ
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};



/* меню */
function activate_del(){
	$("#menu-auto-index a, #menu-auto-index-en a").css("backgroundPosition","0px 0px");
	$("#menu-del-index a, #menu-del-index-en a").css("backgroundPosition","-247px -69px");
	$("#ma").hide();
	$("#md").show();
	return false;
}
function activate_auto(){
	$("#menu-del-index a, #menu-del-index-en a").css("backgroundPosition","-247px 0px");
	$("#menu-auto-index a, #menu-auto-index-en a").css("backgroundPosition","0px -69px");
	$("#md").hide();
	$("#ma").show();
	return false;
}

  	
  	function __getPageSize() {
			var xScroll, yScroll;
		  // alert(document.body.clientHeight);
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			//alert(document.body.scrollHeight);
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} 
			
			else { 
			    pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			if($.browser.opera){ pageHeight+=500;}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
