﻿$(document).ready(function(){	    
    var iW, iH, pageCenter;
    $('#imgPrintLaunch').css('position', 'absolute');
    iW = $('#imgPrintLaunch').attr('width');
    iH = $('#imgPrintLaunch').attr('height');
    pageCenter = getPageCenterCoords(iW,iH);
    $('#imgPrintLaunch').css('left', pageCenter[0]);
    $('#imgPrintLaunch').css('top', pageCenter[1]);
    $('#lnkPrint').fancybox({
            'hideOnContentClick'    : false,
            'frameHeight'           : 592,
            'frameWidth'            : 500,
	        'zoomOpacity'			: true,
		    'overlayShow'			: true,
		    'zoomSpeedIn'			: 500,
		    'zoomSpeedOut'			: 500
    });

    $('#imgContactLaunch').css('position', 'absolute');
    iW = $('#imgContactLaunch').attr('width');
    iH = $('#imgContactLaunch').attr('height');
    pageCenter = getPageCenterCoords(iW,iH);
    $('#imgContactLaunch').css('left', pageCenter[0]);
    $('#imgContactLaunch').css('top', pageCenter[1]);
    $('#lnkContact').fancybox({
            'hideOnContentClick'    : false,
            'frameHeight'           : 614,
            'frameWidth'            : 500,
	        'zoomOpacity'			: true,
		    'overlayShow'			: true,
		    'zoomSpeedIn'			: 500,
		    'zoomSpeedOut'			: 500
    });    
});

function selectAll() {
    $('input[type="checkbox"]').attr('checked', true);
}

function selectNone() {
    $('input[type="checkbox"]').attr('checked', false);
}

function getPageCenterCoords(iW,iH) {
	var de = document.documentElement;
	var pW = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var x = Math.round((pW/2) - (iW/2));
	var pH = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	var y = Math.round((pH/2) - (iH/2));
	var pageCenter = [x,y];
	return pageCenter;
}

function populatePrintPopup(html) {
    $('.printContent').append(html);
}

function showPrintSelections(){
    $('#lnkPrint').css('display', 'block');
    $('#lnkPrint').click();
}

function showPrintableContent() {
    if($('input[type="checkbox"]').is(':checked')) {
        $('.printSelections').css('display', 'none');
        var printUrl = 'Print.html?printList=';
        $('input[type="checkbox"]:checked').each(function () {
            printUrl += this.value + '|';
        });
        printUrl = printUrl.substr(0, printUrl.length - 1);
        $('#fancy_div .printPage').attr('src', printUrl);
        $('#fancy_div .printContent').css('display', 'block');
    }
    else {
        var errMsg = 'Please select at least one topic to print.';
        alert(errMsg);
    }
}

function resetPrintPopup() {
    $('input[type="checkbox"]').attr('checked', false);
    $('.printContent').css('display', 'none');
    $('.printSelections').css('display', 'block');
}

function backToSelections() {
    $('.printContent').css('display', 'none');
    $('.printSelections').css('display', 'block');
}

function showContactForm() {
    $('#lnkContact').css('display', 'block');
    $('a#lnkContact').click();
}