$(document).ready(function() {
        $(".hideableform").css("display","none");        
        $('#login').bind("click", login);
        $('#memberlogout').bind("click", logout);
    $('.hint').hint();

	$("#loginpanel input").keypress(function (e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			login();
			return false;
		} else {
            if ((e.which && e.which == 27) || (e.keyCode && e.keyCode == 27)) {
			    cancel();
			    return false;
		    } else {
			    return true;
		    }
		}
    });
    
    $('input.preventpaste').bind('cut copy paste', function(e) {e.preventDefault();});
            
    $('.ribblemap').bind("mouseover",function(){$('#mapimg').attr('src','/images/map-ribble.png');});
    $('.rossendalemap').bind("mouseover",function(){$('#mapimg').attr('src','/images/map-rossendale.png');});
    $('.burnleymap').bind("mouseover",function(){$('#mapimg').attr('src','/images/map-burnley.png');});
    $('.hyndburnmap').bind("mouseover",function(){$('#mapimg').attr('src','/images/map-hyndburn.png');});
    $('.pendlemap').bind("mouseover",function(){$('#mapimg').attr('src','/images/map-pendle.png');});
    $('.ribblemap, .rossendalemap, .burnleymap, .hyndburnmap, .pendlemap').bind("mouseout",function(){$('#mapimg').attr('src','/images/map.png');});
    
    $('#ctl00_ContentPanelPlaceHolder_searchterm').keypress(function(e) {if(e.keyCode == 13){$('#ctl00_ContentPanelPlaceHolder_submit').click();}});
    
$('#ctl00_searchtext').keypress(function(e) {if(e.keyCode == 13) {$('#searchbutton').click();}});});



(function ($) {
    $.fn.hint = function (blurClass) {
        if (!blurClass) {
            blurClass = 'blur'
        }
        return this.each(function () {
            var $input = $(this),
                title = $input.attr('title'),
                $form = $(this.form),
                $win = $(window);

            function remove() {
                if ($input.val() === title && $input.hasClass(blurClass)) {
                    $input.val('').removeClass(blurClass)
                }
            }
            if (title) {
                $input.blur(function () {
                    if (this.value === '' || this.value == title) {
                        $input.val(title).addClass(blurClass)
                    }
                }).focus(remove).blur();
                $form.submit(remove);
                $win.unload(remove)
            }
        })
    }
})(jQuery);
    
function login(event){
    err = false;
    pw = $.trim($("#password").val());
    un = $.trim($("#username").val());
    if (pw == "" || pw == "Password"){
        $("#msg").html("Please enter password");
        err = true;
        $("#password").focus();
    }
    if (un == "" || un == "Username"){
        $("#msg").html("Please enter username");
        err = true;
        $("#username").focus();
    }

    if (!err){
    $.ajax({
        type: "POST",
        data: "{id:'" + $("#username").val() + "',pw:'" + $("#password").val() + "'}",
        url: "/userlogin.aspx/loguserin",
        cache: false,
        global:false,
        dataType:"json",
        contentType: "application/json; charset=utf-8",
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $("#msg").html("Unable to log in:<br />A server error occured");
        },
        success: function(data){
            if (data.success == "True") {
                $('#msg').html("");
                window.location.reload();
            } else {
                $("#msg").html("Unable to log in: <br />" + data.errtext);
            }
        }
    });
    }
    return false;
}
function logout(event){
     $.cookies.del("ecm");
     window.location.reload();
     return false;
}
