var a = 0;
var loading = 0;
$(window).scroll(function(){
	if (loading == 0 && ($(window).scrollTop() > ($(document).height() - $(window).height() - 2500))) {
	    loading = 1;
	    a = a+10;
	    $('#'+a).load('blog_scroll.php?a='+a, '', function(response){ loading = 0; if(response==""){ $('#vent').hide(); }});
	}
});

var pressed = 0;

function checkinput(id) {
    if (pressed == 0) {
        if ($("#navn"+id).val() == "" || $("#navn"+id).val() == "Your name" || $("#comment"+id).val() == "") { $("#button"+id).hide("slow"); }
        else { $("#button"+id).show("slow"); }
    }    
}

function comment(id, cool) {
    pressed = 1;
    $("#navn"+id).addClass("comment_wait");
    $("#comment"+id).addClass("comment_wait");
    $("#button"+id).hide("slow");
    $("#blog_wait"+id).show("slow");
    $("#blog_comments"+id).load("blog_com.php", { navn: $("#navn"+id).val(), com: $("#comment"+id).val(), iden: id }, function(){
    	$("#navn"+id).removeClass("comment_wait");
    	$("#comment"+id).removeClass("comment_wait");
    	$("#comment"+id).val("");
    	$("#blog_wait"+id).hide("slow");
    	$("#blog_com_title"+id).html('Thank you, '+$("#navn"+id).val()+', for that comment. You\'re '+cool+'!');
        pressed = 0;
    });
}

function checktag() {
    if (mail($("#tag_mail").val())) { $("#tag_knapp").show("10"); }
    else { $("#tag_knapp").hide("10"); }
}

function tagmail() {
    $("#tag_form").hide("slow");
    $("#tag_wait").show("slow");
    $("#tag_mail").load("blog_tag.php?m="+$("#tag_mail").val(), "", function(){
    	$("#tag_thank").show("slow");
    	$("#tag_wait").hide("slow");
    	$("#tag_title").hide("slow");
    	$("#tag_boxes").hide("slow");
    });
}

function checksug() {
    if ($("#sug_text").val()!= "" && $("#sug_text").val()!= "Your suggestion") { $("#sug_knapp").show("10"); }
    else { $("#sug_knapp").hide("10"); }
}

function sugmail() {
    $("#sug_form").hide("slow");
    $("#sug_wait").show("slow");
    $("#sug_mail").load("blog_suggest.php", { mail: $("#sug_mail").val(), com: $("#sug_text").val() }, function(){
    	$("#sug_thank").show("slow");
    	$("#sug_wait").hide("slow");
    	$("#sug_title").hide("slow");
    	$("#sug_boxes").hide("slow");
    });
}

function checktip() {
    if (mail($("#tipp_mail").val()) && $("#year").val() != 0 && $("#month").val() != 0 && $("#day").val() != 0) { $("#tipp_knapp").show("10"); }
    else { $("#tipp_knapp").hide("10"); }
}

function tipmail() {
    $("#tipp_form").hide("slow");
    $("#tipp_wait").show("slow");
    $("#tipp_mail").load("blog_tipp.php?mail="+$("#tipp_mail").val()+"&y="+$("#year").val()+"&m="+$("#month").val()+"&d="+$("#day").val(), "", function(){
    	$("#tipp_thank").show("slow");
    	$("#tipp_wait").hide("slow");
    	$("#tipp_title").hide("slow");
    	$("#tipp_boxes").hide("slow");
    });
}    

function mail(mailen) {
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(mailen)) {return true;}
    else {return false;}
}
