﻿$(document).ready(function() {

	$("#left .menu .cat .name").click(function() {
		$("#left .menu .cat .subcats").hide();
		$(this).parent().find(".subcats").show();
	});
	
	$("#center .prods").find(".prod:eq(0)").css("margin-left", "0px");

	$(".users .submit").click(function() {
	    if($("input[name='newsletter_email']").val() == '' || $("input[name='newsletter_name']").val() == '') {
		alert($(".users .error").html());
	    } else {
		if($("input[name='sub']").val() == 0) alert($(".users .un").html());
		else alert($(".users .sub").html());
		$(this).parent().submit();
	    }
	});
	
	$(".search_button").click(function() {
	    $(this).parent().submit();
	});
	
	$(".subcats .active").parent().parent().find(".name").click();
	
	$(".reg").click(function() {
	    var error = false;
	    $("#reg input").each(function() {
		if($(this).val() == '') error = true;
	    });
	    if(error) alert($(".users .error").html());
	    else $("#reg").submit();
	});
	
        $("#reg_same").click(function() {
            if($(this).attr("checked") != 'checked') {
                $("#reg_name2").val($("#reg_name").val());
                $("#reg_city2").val($("#reg_city").val());
                $("#reg_address2").val($("#reg_address").val());
                $("#reg_zip2").val($("#reg_zip").val());
            } else {
                $("#reg_name2").val(' ');
                $("#reg_city2").val(' ');
                $("#reg_address2").val(' ');
                $("#reg_zip2").val(' ');
            }
        });

        $("#order_same").click(function() {
            if($(this).attr("checked") != 'checked') {
                $("#order_name2").val($("#order_name").val());
                $("#order_city2").val($("#order_city").val());
                $("#order_address2").val($("#order_address").val());
                $("#order_zip2").val($("#order_zip").val());
            } else {
                $("#order_name2").val(' ');
                $("#order_city2").val(' ');
                $("#order_address2").val(' ');
                $("#order_zip2").val(' ');
            }
        });
	
	$("#login_box .login").click(function() {
	    $(this).parent().submit();
	});

	$(".regmod").click(function() {
	    $(this).parent().parent().parent().submit();
	});
	
	$("#reg_text").keyup(function() {
	    if($(this).val().length > 150) $(this).val($(this).val().substring(0, 149));
	});
	
	$("#reg_bfc").click(function() {
	    var error = false;
	    $("#bfcreg input").each(function() {
		if($(this).val() == '') error = true;
	    });
	    if(error) alert($(".users .error").html());
	    else $("#bfcreg").submit();
	});
	
	$("#product .basket a").click(function() {
	    $("#prod").submit();
	    return false;
	});


	

});
