    
    function addEvent(elm, evType, fn, useCapture) {
    	if (elm.addEventListener) {
    		elm.addEventListener(evType, fn, useCapture);
    		return true;
    	}
    	else if (elm.attachEvent) {
    		var r = elm.attachEvent('on' + evType, fn);
    		return r;
    	}
    	else {
    		elm['on' + evType] = fn;
    	}
    }
        
    
    //
    // produktu katalogo skriptai
    //

	
				function commentSubmit() {
				
					var dd = document.getElementById("comment_form");
					var n=0;
				    var err="\n";
						
					var txt = Array();
					
					if (dd.author.value == "") {
					   txt[n]="Vardas";
					   n+=1;
					}
					
					if (dd.comment.value == "") {
					   txt[n]="Komentaras";
					   n+=1;
					}

					if (n >= 1) {
						for (i=0; i<txt.length; i++) {
						  if (txt[i]!="") {
								err += "Neužpildytas laukas ";
								err += '"' + txt[i] + '"';
								err += "\n";
							 } 
						 }
						alert (err);
						return false;
					} else {
						dd.scrt.value = "63985";
						return true;
					}
	
					

				}
	
	
	
	
	function order(a) {
		document.getElementById('ord').value = a;
		document.getElementById('fform').submit();
		return false;
	}
	
	function go_to_page(a) {
		document.getElementById('psl').value = a;
		document.getElementById('fform').submit();
        return false;
	}
	
	function addToCart(a) {
		document.getElementById('preke').value = a;
		document.getElementById('ff').submit();
	}
	
	function addToEqu(a) {
		document.getElementById('equ').value = a;
		document.getElementById('fform').submit();
	}

    function removeEqu(val){
		document.getElementById('dele').value=val;
		document.getElementById('fe').submit();
	}
	
	function insertEqu(val){
		document.getElementById('adde').value=val;
		document.getElementById('fe').submit();
	}

    //
    // popup lango atidarymas
    //
    function open_wnd(exp_bar,width,height,url,status_bar) {
        winName = "_blank";
        theURL = url;
        page_height = (height != '')?height:600;
        page_width = (height != '')?width:500;
        toolbar = (exp_bar == 1)?'yes':'no';
        statusbar = (status_bar == 1)?'yes':'no';
        page_top = Math.round((screen.height-page_height)/2);
        page_left = Math.round((screen.width-page_width)/2);
        size = "width="+page_width+",height="+page_height+",top="+page_top+",left="+page_left;
        features = 'status='+statusbar+',toolbar='+toolbar+',scrollbars=auto,resizable=yes,'+size;
        window.open(theURL,winName,features);
    }
	
	


	
	//
	// jQUERY kodas prasideda
	//
	$(document).ready(function() { 

		//
		// rodom animacija kai vykdomas ajax
		//
	    $("#ajax_status").bind("ajaxSend", function() {
	        $("#ajax_status").addClass("ajax-loading");
	    }).bind("ajaxComplete", function(){
	        $("#ajax_status").removeClass("ajax-loading");
	    });

		$(".imgzoom").fancybox();
			
		//
		// keiciam prekes kaina pasirenkant variantus
		//
		$("#price_id").change( function () { 

			price_id = $("#price_id").val();
		    $("#price_span").html(prices[price_id]+' Lt'); 
			
			if (action_prices[price_id] > 0) {
				$("#action_price_span").css("display","inline");
				$("#price_span").removeClass("product_price");
				$("#price_span").addClass("product_price_old_price");
				$("#action_price_span").html("Nauja kaina: " + action_prices[price_id]+' Lt'); 
			} else {
				$("#action_price_span").css("display","none");
				$("#price_span").removeClass("product_price_old_price");
				$("#price_span").addClass("product_price");
				
				
				
			}
		    
		});
		
		//
		// idedam preke i krepseli
		//
		
	    $("#product_form").submit(function() {
		
	        var post_data = $("#product_form").serialize();
			
	        $.post("index.php?page=cart&act=insert&ajax=1", post_data, function(data){
	                $("#log").fadeIn("slow", function(){});
	                $("#log").html(data);
					$("#cart_box").load("index.php?page=cart&act=show_box&ajax=1");
	            });

	        return false;

	    });
		
		

		
		
		
		//
		// siunciam uzsakymo forma
		//
		
	    $("#order").submit(function() {
		
	        var post_data = $("#order").serialize();
			
	        $.post("index.php?page=cart&act=proceed&ajax=1", post_data, function(order_data){
	                if ($.trim(order_data) == "") {
						$("#log").load("./lt/mod/cart/message.htm?ajax=1&cart_sent=1");
						$("#order").fadeOut("slow");
						$("#cart_box").load("index.php?page=cart&act=show_box&ajax=1");
					} else {
						$("#log").html(order_data);
					} 

	        });

	        return false;

	    });
		
		
		
		
		
		//
		// userio registracijos forma
		//
		
	    $("#registration").submit(function() {
		
	        var post_data = $("#registration").serialize();
			
	        $.post("index.php?page=users&act=check_registration&ajax=1", post_data, function(data){

	                if ($.trim(data) == "") {
					
						var is_new_reg = $("#is_new_registration").val();
						
						if (is_new_reg == 1) {
							$("#log").load("./lt/mod/users/message.htm?ajax=1&user_registration_ok=1");
						} else {
							$("#log").load("./lt/mod/users/message.htm?ajax=1&user_update_ok=1");
						}
						
						$("#registration").fadeOut("slow");
					} else {
						$("#log").html(data);
						
					} 

	        });

	        return false;

	    });
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		//
		// bandom prijungti naudotoja
		//
		
	    $("#login_form").submit(function() {
		
	        var post_data = $("#login_form").serialize();
			
	        $.post("index.php?page=users&act=check_login&ajax=1", post_data, function(data){

	                if ($.trim(data) == "") {
					
						$("#login_log").html(data);
						
						//$("#anonymous_box").load("index.php?page=users&act=login&ajax=1");
						
						var return_link = $("#currlink").val();
					
						//window.location = return_link;
						window.location.reload();
					} else {
						
						$("#login_log").html(data);
					}
	        
			});

	        return false;

	    });
		
		
		
		//
		// issiunciam slaptazodi
		//
		
	    $("#password_form").submit(function() {
		
	        var post_data = $("#password_form").serialize();
			
	        $.post("./lt/mod/users/recover_password.htm?ajax=1", post_data, function(data){

	                if ($.trim(data) == "") {
					
						$("#log").load("./lt/mod/users/message.htm?ajax=1&password_sent=1");
						$("#password_form_div").fadeOut("slow");
						
					} else {
						
						$("#log").html(data);
					}
	        
			});

	        return false;

	    });
		

		$.fn.image = function(src, f) { 

			return this.each(function(){ 
			
			var i = new Image(); 
			
			i.src = src; 
			
			i.onload = f;
			
			$(this).html(i);
			 
			}); 
		 
		} 
		
		
		
		if ($("#active_img")) {
			show_image($("#active_img").val())
		}
		
		var is_new_registration = $("#is_new_registration").val();
		if (is_new_registration != 1) hide_password_asterixes();
		
		var selected_buyer_type = $(".buyer_type_input").val();
		
		if (selected_buyer_type == 1) { show_asterixes_1(); }
		if (selected_buyer_type == 2) { show_asterixes_2(); }
	
	// jQUERY kodas baigiasi
	
	});

	//
	//
	//
	function agree(obj){
	
		var agreed = obj.checked;
		if (agreed) {
			$("#cart_submit_button").attr("disabled", "");
			$("#cart_submit_button").addClass("agreed");
			}
		else {
			$("#cart_submit_button").removeClass("agreed");
			$("#cart_submit_button").attr("disabled", "disabled");
		}
		
	}

	
	//
	// pasalinam preke is krepselio
	//
	function remove_cart_item(item_nr) {

		$("#cart_delete_id").val(item_nr);
		var delete_id = $("#cart_delete_id").val();
		var post_data = $("#cart_delete_form").serialize();;
		
		submit_url = "index.php?page=cart&act=remove_item";

	    $.post(submit_url, post_data, function(data){
			$("#cart_box").load("index.php?page=cart&act=show_box&ajax=1");
			$("#cart_contents").load("index.php?page=cart&ajax=1");
	    });

	}
	
	
	
	function show_image(no) {
		$(".main_img_tbl").css("display","none");
		$("#main_img_tbl_" + $("#active_img").val()).fadeOut("fast", function() {
			$("#main_img_tbl_" + no).fadeIn("slow");
			$("#active_img").val(no);
		}
		);

	}
	
	
	
	//
	// slepiam/rodom zvaigzdutes krepselio ir registracijos formose
	//
	
	function show_asterixes_1() {
	
		$("#z2").css('visibility', 'visible');
		$("#z3").css('visibility', 'visible');
	
		$("#z7").css('visibility', 'hidden');
		$("#z8").css('visibility', 'hidden');
		$("#z9").css('visibility', 'hidden');
		$("#z10").css('visibility', 'hidden');
	
	}
	
	function show_asterixes_2() {
	
		$("#z2").css('visibility', 'hidden');
		$("#z3").css('visibility', 'hidden');
		
		$("#z7").css('visibility', 'visible');
		$("#z8").css('visibility', 'visible');
		$("#z9").css('visibility', 'visible');
		$("#z10").css('visibility', 'hidden');

	}
	
	function hide_password_asterixes() {
	
		$("#zd").css('visibility', 'hidden');
		$("#zc").css('visibility', 'hidden');
		$("#zb").css('visibility', 'hidden');
	}