﻿var dtObject = new Date();
var tarMonth = dtObject.getMonth() + 1;
var tarYear = dtObject.getYear();
if (tarYear > 100 && tarYear < 1900) {
    tarYear += 1900;
}

var textSize = 100;

function nextMonth(evt) {
    tarMonth += 1;
    if (tarMonth > 12) {
        tarMonth = 1;
        tarYear += 1;
    }
    getCalendar();
    evt.preventDefault();
}
function prevMonth(evt) {
    tarMonth -= 1;
    if (tarMonth == 0) {
        tarMonth = 12;
        tarYear -= 1;
    }
    getCalendar();
    evt.preventDefault();
};

function getCalendar() {
    $.get('/action/ajax.ashx', { action: 'calendar', month: tarMonth, year: tarYear },
	        function(data) {
	            $('#sideCalendar').html(data);	           
	        }
	);
}

function increaseSize(evt) {
    evt.preventDefault();
    textSize += 10;
    $(".body_center p, .body_right p").css("font-size", textSize + "%");
}

function decreaseSize(evt) {
    evt.preventDefault();
    textSize -= 10;
    $(".body_center p, .body_right p").css("font-size", textSize + "%");
}

$(function() {
    $("#fontIncrease").click(increaseSize);
    $("#fontDecrease").click(decreaseSize);
    $("#nextMonth").live('click', nextMonth);
    $("#prevMonth").live('click', prevMonth);
    $(".erase").live('focus', function(evt) {
        $(this).val('');
    });
    $('#logout_tag').click(function(evt) {
        evt.preventDefault();
        window.location.href = '/action/logout.aspx';
    });
    $("#header_login").submit(function(evt) {
        evt.preventDefault();
        $.post("/action/login.ashx", { action: 'login', username: $("#header_uname").val(), password: $("#header_pword").val() },
	                function(data) {
	                    if (data == 1) {
	                        window.location.reload();
	                    } else {
	                        alert("Incorrect Password / Username Combination");
	                    }
	                }
	            );
    });
    $('#pollCast').click(function(evt) {
        evt.preventDefault();
        var chosen = parseInt($('#pollArea input:checked').val());
        var question = parseInt($('#pollQuestion').val());
        $.get('/action/ajax.ashx', { action: 'pollSubmit', question: question, answer: chosen },
	        function(data) {
	            $('#pollArea').html(data);
	        }
	    );
	    $.cookie('pollVote', question, { expires: 7, path: '/', domain: '.marcoisland.com' });
	});
	$('#searchSelect').change(function() {
	    if ($("option:selected", $(this)).val() == 0) {
	        $("#cse-search-box").attr("action", "http://www.google.com/search").attr("target", "_blank");
	        $("#cx").val('');
	        $("#cof").val('');
	    } else {
	        $("#cse-search-box").attr("action", "/search/").attr("target", "_self");
	        $("#cx").val('006353326733548841581:exyolft4_fi');
	        $("#cof").val('FORID:11');
	    }
	});
});
