(function ($) {
    hideViewLarger = function () {
        $('#viewLargerFrame').hide();
        $('#alphaBG2').hide();
    }

    showViewLarger = function () {
        $('#viewLargerFrame').show();
        $('#viewLargerFrame').css({ 'top': ($('html').scrollTop() + ($(window).height() / 2) - ($('#viewLarger').height() / 2)) + 'px',
            'left': ($(window).width() / 2) - ($('#viewLarger').width() / 2) + 'px'
        });
        $('#alphaBG2').show();
        $('#alphaBG2').css({
            width: $(document).width(),
            height: $(document).height()
        });
        $('#viewLargerPanel').draggable();
    }

    shrinkViewLarger = function () {
        $('#imgViewLarger').attr('src', 'img/viewlargerOff.gif');
    }

    expandViewLarger = function () {
        $('#imgViewLarger').attr('src', 'img/viewlargerOn.gif');
    }

    adjustDate = function () {
        var $dd = $('#ddlDay');
        var $mm = $('#ddlMonth');
        var $yy = $('#ddlYear');
        var selectedDay = $dd.val();
        var j = 30;
        $('#errorMsg').html('');
        if ($mm.val() == '2') { //February
            if ($yy.val().length > 0) {
                j = checkLeapYear(parseInt($yy.val())) ? 29 : 28;
            }
            else {
                j = 28;
            }
        }
        else if ($mm.val() == '4' || $mm.val() == '6' || $mm.val() == '9' || $mm.val() == '11') { //these months have 30 days
            j = 30;
        }
        else {
            j = 31; 	//all other months have 31 days
        }

        //repopulate the day select box
        options = '<option value="">--</option>';
        for (var i = 1; i <= j; i++) {
            options += '<option value="' + i + '"' + ((i.toString() == selectedDay) ? ' selected="selected"' : '') + '>' + i + '</option>';
        }
        $dd.html(options);
    }

    checkLeapYear = function (year) {
        //check to see if the year is not a leap year
        return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? true : false;
    }

    openwin = function (url, opt) {

        var options = opt.split('|');

        var settings = {
            windowname: options[0] || 'popwin',
            left: options[1] || 0,
            top: options[2] || 0,
            width: options[3] || 800,
            height: options[4] || 600,
            scrollbars: ($.inArray('scrollbars', options) != -1) ? 1 : 0,
            resizable: ($.inArray('resizable', options) != -1) ? 1 : 1,
            toolbar: ($.inArray('toolbar', options) != -1) ? 1 : 0,
            status: ($.inArray('status', options) != -1) ? 1 : 0,
            location: ($.inArray('location', options) != -1) ? 1 : 0,
            menubar: ($.inArray('menubar', options) != -1) ? 1 : 0
        };
        if (typeof popupwin != 'undefined' && !popupwin.closed) popupwin.close();
        popupwin = window.open(url, settings.windowname, 'top=' + settings.top + ',left=' + settings.left + 'width=' + settings.width + ',height=' + settings.height + ',scrollbars=' + settings.scrollbars + ',toolbar=' + settings.toolbar + ',status=' + settings.status + ',resizable=' + settings.resizable + ',location=' + settings.location + ',menubar=' + settings.menubar);
    }

    getCookie = function (c_name) {
        var retVal = '-1';
        var i, x, y, ARRcookies = document.cookie.split(";");
        for (i = 0; i < ARRcookies.length; i++) {
            x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
            y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
            x = x.replace(/^\s+|\s+$/g, "");
            if (x == c_name) {
                retVal = unescape(y);
            }
        }
        return retVal;
    }

    setCookie = function (c_name, c_value) {
        document.cookie = c_name + '=' + c_value;
    }

    eraseCookie = function (c_name) {
        setCookie(c_name, "-1");
    }

    $(document).ready(function () {
		$('#formBday').submit(function () {
			$('#errorMsg').html('');
			if ($('#ddlDay').val().length > 0 && $('#ddlMonth').val().length > 0 && $('#ddlYear').val().length > 0) {
				return true;
			} else {
				$('#errorMsg').html('Plesae choose a month, date and year');
				return false;
			}
		});

		$('a[wt8track]').click(function (e) {
			var $link = $(this);
			var params = $link.attr('wt8track').split('|');

			var settings = {
				name: params[0] || 'NONE',
				campaign: params[1] || 'NONE',
				channel: params[2] || 'NONE',
				contenttype: params[3] || 'NONE',
				action: params[4] || 'NONE'
			};

			if (typeof Tracker != 'undefined') {
				if ((typeof WT == 'undefined') || (!WT.wt8trackCalled)) {
					var scriptCall = 'Tracker.track(' + '{name:\'' + settings.name.replace(/\\/g, "\\\\").replace(/\'/g, "\\\'") +
							'\',campaign:CAMPAIGN.' + settings.campaign.toUpperCase() +
							',channel:CHANNEL.' + settings.channel.toUpperCase() +
							',contenttype:CONTENTTYPE.' + settings.contenttype.toUpperCase() +
							',action:ACTION.' + settings.action.toUpperCase() + '})';
					eval(scriptCall);
				}
			}
		});
    });

//	$(document).ready(function () {

//		$('#submit', $('form#formBday')).click(function (e) {
//			e.preventDefault();
//			if ($('#ddlDay').val().length > 0 && $('#ddlMonth').val().length > 0 && $('#ddlYear').val().length > 0) {
//				// submit to same page
//       			$.ajax({
//       				url: 'ageGate.aspx',
//       				dataType: 'html',
//       				data: {
//       					ddlYear: $('#ddlYear').val(),
//       					ddlMonth: $('#ddlMonth').val(),
//       					ddlDay: $('#ddlDay').val()
//       				}
//       			});
//			} else {
//       			$('#errorMsg').html('Plesae choose a month, date and year');
//			}
//			return false;
//		});

//        $('#formBday').submit(function () {
//            $('#errorMsg').html('');
//            if ($('#ddlDay').val().length > 0 && $('#ddlMonth').val().length > 0 && $('#ddlYear').val().length > 0) {
//            	$.ajax({
//            		url: 'ageGate.aspx',
//            		dataType: 'html',
//            		data: {
//            			ddlYear: $('#ddlYear').val(),
//            			ddlMonth: $('#ddlMonth').val(),
//            			ddlDay: $('#ddlDay').val()
//            		}
//            	});
//            } else {
//                $('#errorMsg').html('Plesae choose a month, date and year');
//                return false;
//            }
//        });
//    });
	
})(jQuery);

