$(function(){
	$("label.checkbox").click(function() { 
		$(this).toggleClass('checked');
		if($.browser.msie && (parseInt($.browser.version, 10) == 7 || parseInt($.browser.version, 10) == 8))
		{
			var id = $(this).attr('for');
			if($(this).hasClass('checked'))
				document.getElementById(id).checked = true;
			else
				document.getElementById(id).checked = false;
		}
	});

	$("form").submit(function(){
		var ok = true;
		var sel = false;
        var check = {
            exists : false,
            valid : false
        };
		$(this).children('input').each(function(c,e){
			e = $(e);

            if( ! e.val())
			{
				e.css({
					'border': '1px solid red',
					'box-shadow' : '0 0 4px red'
				});
				ok = 'Please fill out all of the forms';
			}
		});

		$(this).children('.checkbox').each(function(c,e){
            check.exists = true;
			e = $(e).children('input');

            if (e.is(':checked')) {
                check.valid = true;
            } 
		});

		if (ok != true)
		{
			alert(ok + '.');
			return false;
		}
        if (check.exists == true && check.valid == false) {
            alert("Please choose a product from our product range to contact us.");
            return false;
        }

        $("button", this).attr('disabled', 'disabled').css('background', 'url(/_files/images/css/buttons.png) no-repeat 0 0;');
	});
	$("input").keypress(function(e){
		$(this).css({
			'border' : '1px solid #ccc',
			'box-shadow' : 'none',
		});
	});
});
