﻿var trackThisPage = true;

/* Browser Detection */
var isMac = false;
var isSafari = false;
var isFirefox = false;
var isMSIE = false;
var isMSIE6 = false;

if (navigator.userAgent.indexOf("Macintosh") != -1) {
    isMac = true;
}

if (navigator.userAgent.indexOf("Safari") != -1) {
    isSafari = true;
} else if (navigator.userAgent.indexOf("MSIE") != -1) {
    isMSIE = true;
    if (navigator.userAgent.indexOf("MSIE 6.0") != -1) {
        if (navigator.userAgent.indexOf("MSIE 8.0") == -1) {
            isMSIE6 = true;
        }
    }
} else if (navigator.userAgent.indexOf("Firefox") != -1) {
    isFirefox = true;
}


function showDIV(divID) {
    var divPop = document.getElementById(divID);
    divPop.style.display = "block";
}

function hideDIV(divID) {
    var divPop = document.getElementById(divID);
    divPop.style.display = "none";
}

function showhideTip(tipShow, tipClose) {

    var div1 = document.getElementById(tipShow);
    var div2 = document.getElementById(tipClose);

    div1.style.display = "block";
    div2.style.display = "none";

}



function changeMap(mapsrc) {
    map = document.getElementById('eventmap');
    divid = document.getElementById(mapsrc);
    map.src = "/images/citi_" + mapsrc + "_on.png";
    divid.className = "photogreen";
}

function resetMap(mapsrc) {
    map = document.getElementById('eventmap');
    divid = document.getElementById(mapsrc);
    map.src = "/images/citi_names.png";
    divid.className = "photo";
}

function clearOtherCheckBoxes(chkBox) {
    var theForm = document.forms[0];

    switch (chkBox) {
        case theForm.ReceiveMoreInformation:
            if (chkBox.checked) {
                if (theForm.form1 != null) {
                    theForm.form1.checked = false;
                }
                if (theForm.chkReceiveMoreInformation != null) {
                    theForm.chkReceiveMoreInformation.checked = false;
                }
            }
            break;
        case theForm.chkReceiveMoreInformation_BreyersOnly:
            if (chkBox.checked) {
                theForm.chkReceiveMoreInformation.checked = false;
            }
            break;
        case theForm.chkReceiveMoreInformation:
            if (chkBox.checked) {
                theForm.chkReceiveMoreInformation_BreyersOnly.checked = false;
            }

            break;
    }
}

/* TOP NAV FEATURED RECIPES ROLLOVER */
var tnavRecipeImages;
var tnavRecipeLinks;
var tnavRecipeCurrent = 0;

function initTopNavRecipes(){
    tnavRecipeImages = document.getElementById("tnavRecipeImages").getElementsByTagName("IMG");
    tnavRecipeLinks = document.getElementById("tnavRecipeLinks").getElementsByTagName("A");
    
    for (var i = 0; i < tnavRecipeLinks.length; i++){
        if (i != 0){
            tnavRecipeImages[i].style.display = "none";
        }
        
        tnavRecipeLinks[i].tnavRecipe = i;
        
        tnavRecipeLinks[i].onmouseover = function(){
            showTopNavRecipes(this.tnavRecipe);
        }
        
        tnavRecipeLinks[i].onmouseout = function(){
            showTopNavRecipes(0);
        }
    }
}

function showTopNavRecipes(recipeID){
    if (recipeID != tnavRecipeCurrent){
        tnavRecipeImages[tnavRecipeCurrent].style.display = "none";
        tnavRecipeImages[recipeID].style.display = "block";
        tnavRecipeCurrent = recipeID;
    }
}

/* HOMEPAGE COOKIE SEQUENCING */
function showHomePageSet(){
    if (document.getElementById("homeCopy1")){
        var maxSets = 1;
        var maxPromos = 3;
        var breyersCookie = "breyershp";
        var breyersCookieValue = $.readCookie(breyersCookie);
        var hpSetNum;
        
        if (breyersCookieValue){
            hpSetNum = parseInt(breyersCookieValue);
            hpSetNum++;
            if (hpSetNum > maxSets){
                hpSetNum = 1;
            }
        } else {
            hpSetNum = 1;
        }
        
        $.setCookie(breyersCookie, hpSetNum, new Object());
        
        $('#homeCopy' + hpSetNum).show();
        for (var i = 1; i <= maxPromos; i++){
            $(('#homepromo' + i) + hpSetNum).show();
        }
        document.getElementsByTagName('BODY')[0].className = "home" + hpSetNum;
        document.getElementsByTagName('BODY')[0].style.display = "block";
        pageTracker._trackPageview("/homepage_version" + hpSetNum);
    }
}


var addthis_config = {   

    ui_offset_top: 0,
    ui_offset_left: 0,
    services_compact: 'facebook, twitter, myspace, delicious, digg',
    //data_track_clickback: true,
    data_ga_tracker: "pageTracker"

}

var addthis_share = { 
    templates: { twitter: 'Now, you can love ice cream even more. Experience Pure Joy with Breyers®! Their site is so much fun to explore! http://www.breyers.com' }
    }

function onclickFix(theLink, trackName) {
    pageTracker._trackPageview(trackName);
    var linkTarget;
    if (theLink.target != null){
        linkTarget = theLink.target.toLowerCase();
    } else {
        linkTarget = "_self";
    }
    if (linkTarget == "_blank") {
        return true;
    } else {
        setTimeout("location.href = '" + theLink.href + "'", 500);
        return false;
    }
}

function onclickFixProduct(theLink) {
    var trackName = "/click/" + theLink.pathname.substring(0, theLink.pathname.indexOf(".aspx"));
    return onclickFix(theLink, trackName);
}

function getRecipeTrackName(){
    return location.pathname.substring(location.pathname.lastIndexOf("/") + 1, location.pathname.indexOf(".aspx"));
}

var digitsOnly = /[1234567890]/g;
var integerOnly = /[0-9\.]/g;
var alphaOnly = /[A-Z]/g;

function restrictCharacters(myfield, e, restrictionType) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);

	// if they pressed esc... remove focus from field...
	if (code==27) { this.blur(); return false; }
	
	// ignore if they are press other keys
	// strange because code: 39 is the down key AND ' key...
	// and DEL also equals .
	if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
		if (character.match(restrictionType)) {
			return true;
		} else {
			return false;
		}
	}
}

$.urlParam = function(name){ 
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); 
    if (!results) {
        return null;
    } 
    return results[1];
};


/*Popup Window Functions*/
var popUpWin;
var popDefWidth = 500;
var popDefHeight = 650;
var lastWidth;
var lastHeight;

//Open URL in new window with fixed dimensions
function openWin(url, winName, pixWidth, pixHeight, canScroll) {
    var winFeatures = "width=" + pixWidth + ",height=" + pixHeight + "," + getCentered(pixWidth, pixHeight) + ",resizable=no,scrollbars=";
    if (canScroll) {
        winFeatures += "yes";
    } else {
        winFeatures += "no";
    }
    popUpWin = window.open(url, winName, winFeatures);
    popUpWin.focus();
}

//Get coordinates for centering window
function getCentered(popupWidth, popupHeight) {
    var indentNetscapeWidth = 'screenX=' + getIndent(popupWidth, false);
    var indentNetscapeHeight = 'screenY=' + getIndent(popupHeight, true);
    var indentMSIEWidth = 'left=' + getIndent(popupWidth, false);
    var indentMSIEHeight = 'top=' + getIndent(popupHeight, true);
    var centerCoordinates = indentNetscapeWidth + ',' + indentNetscapeHeight + ',' + indentMSIEWidth + ',' + indentMSIEHeight;
    return centerCoordinates;
}

//Determine top and left margins for window
function getIndent(popupDimension, isHeight) {
    if (isHeight) {
        return ((screen.availHeight - popupDimension) / 2);
    } else {
        return ((screen.availWidth - popupDimension) / 2);
    }
}

function modifyFBlike(url, layout, faces, width, action, font, colorScheme) {
    var frame = $(".addthis_button_facebook_like iframe");
    var frameSrc = $(".addthis_button_facebook_like iframe").attr("src");

    // set iframe width
    $(".addthis_button_facebook_like iframe").css("width", width + "px");
    // set height for "faces"
    if (faces == "true")
        $(".addthis_button_facebook_like iframe").css("height", "80px");

    frameSrc = "//www.facebook.com/plugins/like.php?href=" + escape(url) + "&layout=" + layout + "&show_faces=" + faces + "&width=" + width + "&action=" + action + "&font=" + font + "&colorscheme=" + colorScheme;
    $(".addthis_button_facebook_like iframe").attr("src", frameSrc);
}

// <a href="#" onclick="return onclickFix(this, '/click/promopod1')">


