//COMMON FUNCTIONS

function swapImage(num) {
	var imageSource = document.getElementById('topNavImage').src;	
	var imageDiv = document.getElementById('imageDiv');
	var newImageSource = "";
	
	if (num == 1) {
		newImageSource = imageSource.substring(0,imageSource.lastIndexOf("/")) + "/navNoneSelected.gif";				
		imageDiv.innerHTML = "<img id='topNavImage' src=" + newImageSource + " USEMAP='#topNav' border='0' /><br>";							
	}
	if (num == 2) {
		newImageSource = imageSource.substring(0,imageSource.lastIndexOf("/")) + "/navHowSelected.gif";				
		imageDiv.innerHTML = "<img id='topNavImage' src=" + newImageSource + " USEMAP='#topNav' border='0' /><br>";		
	}
	if (num == 3) {
		newImageSource = imageSource.substring(0,imageSource.lastIndexOf("/")) + "/navUnderstandngSelected.gif";				
		imageDiv.innerHTML = "<img id='topNavImage' src=" + newImageSource + " USEMAP='#topNav' border='0' /><br>";		
	}
	if (num == 4) {
		newImageSource = imageSource.substring(0,imageSource.lastIndexOf("/")) + "/navFAQsSelected.gif";				
		imageDiv.innerHTML = "<img id='topNavImage' src=" + newImageSource + " USEMAP='#topNav' border='0' /><br>";		
	}
}

function trackEvent(g,n,v){
    try{ pageTracker._trackEvent(g,n,v); window.console.log('pageTracker._trackEvent("'+g+'","'+n+'","'+v+'");')} catch(e){}
}


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};

jQuery.log=function(message){
	try{
		console.log(message);
	}catch(e){}
};

jQuery.attachSpotlightTag=function(src,type,cat){
	try{
		var axel = Math.random()+"";
		var a = axel * 10000000000000;
		$('body').append($('<IFRAME SRC="http://fls.doubleclick.net/activityi;src='+src+';type='+type+';cat='+cat+';ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>'));
		$.log('attachSpotlightTag(src='+src+',type='+type+',cat='+cat+')');
	}catch (e) {
		$.log('ERROR attachSpotlightTag:'+e);
	}
};

function survey(){
	SURVEY_COOKIE = 'exit_survey';
	var fancyboxOptions = {
			hideOnContentClick:false,
			hideOnOverlayClick:false,
			callbackOnStart:function(){$('#fancy_outer').addClass('survey');},
			callbackOnClose:function(){$('#fancy_outer').removeClass('survey');},
			frameWidth: 356,
			frameHeight: 338,
			overlayOpacity: 0.4
	};
	var cookie = $.cookie(SURVEY_COOKIE);
	if(!cookie){
		var date = new Date();
        date.setTime(date.getTime()+(364 * 24*60*60*1000));
        $.cookie(SURVEY_COOKIE, 'true', { path: '/', expires: date });
        var html = '<img id="surveyPrompt" src="/consumer/img/Common/survey-popup.png" alt="" usemap="#surveyMap" /><map name="surveyMap" id="surveyMap"><area shape="rect" coords="73,288,226,312" target="_blank" href="http://www.surveygizmo.com/s/280517/miralax-online-survey "onclick="window.open(this.href,\'survey_window\',\'location=1,status=0,scrollbars=1,width=620\'); $.fancybox.close(); setTimeout(\'window.focus && window.focus();\',500); trackEvent(\'Survey\',\'Take Survey\');return false;"/><area shape="rect" coords="247,292,327,312" href="javascript:(function(){trackEvent(\'Survey\',\'No Thanks\');$.fancybox.close();})();"/></map>';
        if ($.browser.msie && $.browser.version == 6)
            html = '<img id="surveyPrompt" src="/consumer/img/Common/survey-popup-ie6.gif" alt="" usemap="#surveyMap" /><map name="surveyMap" id="surveyMap"><area shape="rect" coords="31,236,185,261" target="_blank" href="http://www.surveygizmo.com/s/280517/miralax-online-survey " onclick="window.open(this.href,\'survey_window\',\'location=1,status=0,scrollbars=1,width=620\'); $.fancybox.close(); setTimeout(\'window.focus && window.focus();\',500); trackEvent(\'Survey\',\'Take Survey\'); return false;"/><area shape="rect" coords="203,238,284,259" href="javascript:(function(){trackEvent(\'Survey\',\'No Thanks\');$.fancybox.close();})();"/></map>';
		$.fancybox(
        		html,
        		{
                	'autoDimensions'	: false,
                	'width'             : 356,
                	'height'            : 338,
        			'transitionIn'		: 'none',
        			'transitionOut'		: 'none',
        			'overlayOpacity'    : 0.4,
        			'showCloseButton'	: false
        		}
        	);
        
	}
}

function couponTags(){
    $('MAP#save1Map AREA').click(function(){
        $.attachAtlas('cbnmir_CouponSave1Click_1');
        $.attachSpotlightTag('2077070','miral807','coupo143');
    });
    
    $('MAP#save3Map AREA').click(function(){
        $.attachAtlas('cbnmir_CouponSave3Click_1');
        $.attachSpotlightTag('2077070','miral807','coupo754');
    });
}

$(function(){
    survey(); 
    couponTags();   
});
