﻿// Common routines used by root site (not purchase)

//set start up values
$(document).ready(function() {

    //hide alert if the user has closed it.
    if (($.cookie('AlertStripVisible') != 'false')) {
        if (document.getElementById('AlertStripContainer') != null) {
            document.getElementById('AlertStripContainer').style.display = "block";
        }
    }

	// Change footer text for Life requests
	var lifeText = document.getElementById('FooterCopyRightLife');
	var otherText = document.getElementById('FooterCopyRight');
	// Look for "/life" in the url or the bvproductid querystring value for the Reviews submission page.
	if (isInLife()) {
    	lifeText.style.display = "block";
    	otherText.style.display = "none";
    } else {
    	lifeText.style.display = "none";
    	otherText.style.display = "block";
    }

	// Run the font size function 
    if ( ($.cookie('SessionFontSize') == null) ) {
		// If the cookie's not set, run function at 'Small'
    	setFontSize('Small');
    } else {
    	setFontSize($.cookie('SessionFontSize'));
    }

});

/* Do hover-over for Font size controls (as distinct from /scripts/pemco.com.common.js) */

$.fn.extend({
    addHoverFontSize: function() {
        this.hover(
        	// Hover ON
            function() {
                	$(this).css('background-position',
                	    '0 -' + parseInt($(this).css('height')) + 'px');
	        },
	        // Hover OFF
            function() {
            	// First letter of cookie (S, M or L)
    			var firstLetterCookie = $.cookie('SessionFontSize').charAt(0); 
    			// 12th character of img class (e.g., "btnFontSizeMedium"), set in FontSize.ascx
    			var firstLetterClass = $(this).attr('class').charAt(11); 
            	// Only turn off bg position if this is NOT the font size setting (cookie)
            	if (firstLetterCookie != firstLetterClass) {
	                $(this).css('background-position', '0 0px')
	            }
            })
        this.click(
            function() {
                $(this).css('background-position',
                    '0 -' + (parseInt($(this).css('height')) * 2) + 'px');
            });        
    }
});
$(function() {
    $('.btnHoverFontSize').addHoverFontSize();
});

/* SET FONT SIZE */
function setFontSize(fs) {
	//alert(fs);
    // ...set (or re-set) cookie
    $.cookie('SessionFontSize', fs, { path: '/'});

    // If GenericBodyContent exists...
    var gbContent = document.getElementById('GenericBodyContent');
    // ...size the text by adding a class (Classes are in /_css/layout.css)
    if (gbContent) {gbContent.className = 'FontResize'+fs;}

    // If GenericBodyContent exists...
    var prContent = document.getElementById('PressReleasesBodyContent');
    // ...size the text by adding a class (Classes are in /_css/layout.css)
    if (prContent) {prContent.className = 'FontResize'+fs;}

    // If the font size control is on the page...
    if ($('#GenericFontSizeContainer')) {
    	// Clear all indicators
	    $('.btnFontSizeSmall').css('background-position', '0 0')
	    $('.btnFontSizeMedium').css('background-position', '0 0')
	    $('.btnFontSizeLarge').css('background-position', '0 0')

        // Change specific indicator
	    $('.btnFontSize'+fs).css('background-position', '0 -21px') /* mozilla */
	    $('.btnFontSize'+fs).css('background-position-y', '-21px') /* ie */
	}
};

/* FUNCTIONS COPIED FROM "PEP.AppCode/BASE.CS" */
function popUpAgent(URL) {
    window.open(URL, (new Date()).getTime(), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900,height=717,left=143,top=18');
}
function popUp(URL) {
    window.open(URL, (new Date()).getTime(), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=699,height=717,left = 143,top = 18');
}
function popUpAlert(URL) {
    window.open(URL, (new Date()).getTime(), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=538,height=500,left = 143,top = 18');
}
function popUpPerspective(URL) {
    window.open(URL, (new Date()).getTime(), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=725,height=690,left = 143,top = 18');
}

$(document).ready(function(){
    if ($.browser.msie && $.browser.version.substr(0,1)<7) {
        var footer = $('#LayoutFooter');
        if ($(window).height() + footer.height() < $(this).height())
            footer.css('position', 'relative');
    }
});

function isInLife() {
    var dl = document.location.href;
    var dlci = /\/life/gi; // case-insensitive string "/Life"
    return (dl.match(dlci)
            || getQuerystringValue('bvproductid', '').toLowerCase() == 'life'
            || getQuerystringValue('lifeSearch', '').toLowerCase() == 'y');
};