/*===========================================================================
	global.js

	This JavaScript executes dynamic behaviors:
	- Patch missing JavaScript features for certain browser versions
	- Define commonly used functions and variables
	- Preload images
	- Flash Replacements (i.e. sIFR, UFO, SWFObject, etc.)
	- Decorate the DOM with presentational elements
	- Collapse/expand/animate sections
	- Validate forms
	- Pop-up windows
===========================================================================*/

$j = jQuery.noConflict();

$j(document).ready(function() {
	
	// If visiting coupon page when ME privacy laws failed:
	/*if ($j("div#email-form-wrapper").length == 1 && $j.cookie("onecareAgeVerification") == 1) {
		$j("div#contentLeftColWrapper div.content").html('<p>We&rsquo;re sorry but we can&rsquo;t accept your messages or personal information because you do not meet our eligibility requirements. But that doesn&rsquo;t mean you can&rsquo;t explore the rest of our site and learn more about us! <a href="/">Click here</a> to return to the homepage.</p>');
	}*/
	
	$j("input.newsletterEmail").focus(function() {
		$j(this).attr("value", "");
	});
	
	// Show/hide coupon form controls
	var emailForm = $j("div#email-form-wrapper");
	var regMailForm = $j("div#regular-mail-form-wrapper");
	//var ageVerifyFields = $j("#powermaildiv_uid12, #powermaildiv_uid27");

	// If confirmation page, unhide the appropriate wrapper
	$j(".tx-powermail-pi1_thx").closest("div[id$='wrapper']").show();

	$j("a#show-email-form").click(function() {
		emailForm.show();
		regMailForm.hide();
		//ageVerifyFields.hide();

		return false;
	});

	$j("a#show-mail-form").click(function() {
		regMailForm.show();
		emailForm.hide();
		//ageVerifyFields.hide();

		return false;
	});
	
	//Additional form fields for ME privacy laws
	//User must be 18 years of age or older if a ME resident
	//uid11 -> div#powermaildiv_uid12 (email), uid22 -> div#powermaildiv_uid27 (reg mail)
});

/*===========================================================================
	Utilities
===========================================================================*/

// Enable console logging
function log(msg) {
	if (window.console && window.console.log)
		console.log(msg);
}

// Prevent IE6 background flicker
try { document.execCommand("BackgroundImageCache", false, true); } catch(e) {}

// Allow application of CSS rules to IE6's unknown elements
document.createElement("abbr");