﻿$(document).ready(function () {

    $('form#mainForm').bind('submit', function (e) {
        e.preventDefault();
        checkForm();
    });

    $('input#hostName').focus();


    function lastPostFunc() {

        if ($(".wrdLatest:last").attr("id") < 9999999) {
            $('div#lastPostsLoader').html('<div style="width:100%; text-align:center">Loading...<img src="/images/bigLoader.gif" height="66" width="66" title="Loading" alt="Loading"></div>');
            $.post("searchresults-loader.asp?action=getLastPosts&lastID=" + $(".wrdLatest:last").attr("id") + "&startPage=" + $(".LoadPage:last").attr("title"),

			function (data) {
			    if (data != "") {
			        $(".wrdLatest:last").after(data);
			    }
			    $('div#lastPostsLoader').empty();
			    $('div.xboxcontentnew').hide().fadeIn(1000);
			    $('div.LoadPage').remove();
			    $('div.NextPage').attr("class", "LoadPage");
			});

        };
    };

    function isApple() {
        return (
                    (navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.platform.indexOf("iPad") != -1)
                );
    }

    function isAndroid() {
        return (
                    (navigator.platform.indexOf("android") != -1)
                );
    }


    $(window).scroll(function () {
        var win_height = $(document).height() - $(window).height();
        if (isApple()) { win_height = win_height - 400; }
        if (isAndroid()) { win_height = win_height - 75; }
        if ($(window).scrollTop() >= win_height) {
            lastPostFunc();
            $("div.xboxcontentnew").attr("class", "xboxcontent1");

        }
    });

});
