﻿// TOPNAV HOVER FOR IE
tnHover = function() {
	var topNav = document.getElementById("topnav");
	if (topNav == null) return;
	
	var tnEls = topNav.getElementsByTagName("LI");
	if (tnEls == null) return;
	
	for (var i=0; i<tnEls.length; i++) {
		tnEls[i].onmouseover=function() {
			this.className+=" tnhover";
		}
		tnEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" tnhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", tnHover);
// SIMPLE HIDE/SHOW DIV FUNCTION
function hidediv(div_id) { var objDiv = document.getElementById(div_id);if(objDiv != null){objDiv.style.display = 'none';}return false;}
function showdiv(div_id) { var objDiv = document.getElementById(div_id);if(objDiv != null){objDiv.style.display = 'block'; }return false;}

// DATE FUNCTION
function displayCurrentTime(divElement){ var timeDiv = document.getElementById(divElement); if(timeDiv != null) { var dTime = new Date(); timeDiv.innerHTML = getDisplayMonth(dTime.getMonth()) + ' ' + dTime.getDate() + ', ' + dTime.getFullYear(); } }
function getDisplayMonth(iMonth){ if(iMonth == 0){ return "January";} else if (iMonth == 1){ return "February";} else if (iMonth == 2){ return "March";} else if (iMonth == 3){ return "April";} else if (iMonth == 4){ return "May";} else if (iMonth == 5){ return "June";} else if (iMonth == 6){ return "July";} else if (iMonth == 7){ return "August";} else if (iMonth == 8){ return "September";} else if (iMonth == 9){ return "October";} else if (iMonth == 10){ return "November";}else if (iMonth == 11){ return "December";} }

//IE VERSION CHECKER
function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}

function popupMachineManual(url)
{
	return popupWindow(url);
}

function popupBumper(url)
{
	popupOffSiteUrl(url);
	history.back();
	return false;
}

function popupBuyOnline(productUrl)
{
    if (!productUrl || productUrl == "")
        productUrl = "http://www.dolcegustostore.com/";

    popupwin = window.open(productUrl, "OffsiteUrl", "height=600,width=1200,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes");
    popupwin.focus();
	return false;
}
function popupOffSiteUrl(url)
{
	return popupWindow(url, 'OffsiteUrl', 600, 400, true, true, true, true);
}

function popupSubmitReview(url)
{
	return popupWindow(url, 'SubmitReview', 600, 400, false, true, false, false);
}

// FUNCTION: function to pop up a small window. 
// AUTHOR: christopher galvan
// EXAMPLE: popup('page.html', 'name', width, height, false, true, true, false);
function popupWindow(url, windowName, width, height, hasToolBars, hasScrollBars, isResizable, hasMenuBar) {
	var scr_x = screen.width;
	var scr_y = screen.height;
	var leftOffset = (scr_x/2)-(width/2);
	var topOffset = (scr_y/2)-(height/2);
	
	var sToolBars = (hasToolBars) ? "yes" : "no";
	var sScrollBars = (hasScrollBars) ? "yes" : "no";
	var sMenuBar = (hasMenuBar) ? "yes" : "no";
	var sResizable = (isResizable) ? "yes" : "no";

	popupwin = window.open(url, windowName, "toolbar="+sToolBars+",location=no,directories=no,status=no,menubar="+sMenuBar+",scrollbars="+sScrollBars+",resizable=" + sResizable + ",width="+width+",height="+height+",left="+leftOffset+",top="+topOffset);
	popupwin.focus();
	return false;
}

//funtion: toggle the showing and hiding of the specified div
function toggleDiv(divName)
{
    if(divName != "")
    {
        var objDivToOpen = document.getElementById(divName);
        if(objDivToOpen != null)
        {
            if(objDivToOpen.style.display == "none")
                objDivToOpen.style.display = "block";
            else(objDivToOpen.style.display == "block")
                objDivToOpen.style.display = "none";
        }
    }
    return false;
}


//function: hides all divs within the specified div except the specified div
function hideDivsExcept(divWithin, divExcept)
{
    var objDivWithin = document.getElementById(divWithin);
    var objDivs = objDivWithin.getElementsByTagName("div");
    if(objDivs == null)
        return;
    
    for(var i = 0; i < objDivs.length; i++)
    {
        if(objDivs[i].id != "" && objDivs[i].id != divExcept)
        {
            objDivs[i].style.display = "none";
        }
    }
}

//Invokes the browser's bookmark dialog using the specified url and title
function bookmark(url, title, bookmarkingNotSupportedUrl)
{
	if (url == null)
		url = location.href;
	if (window.sidebar) //Firefox
		window.sidebar.addPanel(title,url,"");
	else if (window.external) //IE
		window.external.AddFavorite(url,title);
	else if (window.opera) //Opera
	{
		//this.rel = "sidebar";
		/*
		this.click();
		var a = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = title;
		a.href = url;
		a.click();
		*/
	}
	else //all others
	{
		if (bookmarkingNotSupportedUrl != null && bookmarkingNotSupportedUrl != "")
			popupWindow(bookmarkingNotSupportedUrl, "BookmarkingNotSupported", 200, 200, false, true, true, false);
		else
			alert("We're sorry! Your browser doesn't support this functionality. Please use your browser's bookmark command to bookmark this page.");
	}
/*
  if ((navigator != null && navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
  {
	alert('here3');
  
	window.external.AddFavorite(url,title);
  } 
  else if (navigator != null && navigator.appName == "Netscape") 
  {
	alert('here4');
    window.sidebar.addPanel(title,url,"");
    alert ('here6');
  } 
  else 
  {
	alert('here2');
  
	if (bookmarkingNotSupportedUrl != null && bookmarkingNotSupportedUrl != "")
		popupWindow(bookmarkingNotSupportedUrl, "BookmarkingNotSupported", 200, 200, false, true, true, false);
	else
		alert("We're sorry! Your browser doesn't support this functionality. Please use your browser's bookmark command to bookmark this page.");
  }
  */
}

function DownloadAndTrackPDF(sPDFId)
{
	var objPdf = DolceGusto.Web.NonAkamai.DownloadPDF1.GetPDF(sPDFId, DownloadAndTrackPDFResult);
	return false;
}

function DownloadAndTrackPDFResult(objPdf)
{
	if (objPdf != null)
	{
		//Track in hitbox
		_hbPageView(objPdf.HBXPageName, objPdf.MultiLevelContent)
		
		//Download to browser
		var sAppPath;
		if (location.hostname.toLowerCase() != "localhost")
			sAppPath = "/";
		else
			sAppPath = "/dolcegusto.web/";
		location.href = sAppPath + "NonAkamai/DownloadPDF.aspx?pdfid=" + objPdf.Id;
	}
}

function SetupFAQs(sQuestionsCssClass, sAnswersCssClass, sExpandCollapseAllLinkId, sExpandImageUrl, sCollapseImageUrl)
{

    $(sAnswersCssClass).attr("style", "display:none;");
    
	var expandCollapse = $(sExpandCollapseAllLinkId)
	var sExpandAllText = "Expand All";
	var sCollapseAllText = "Collapse All";
	
	//Individual question toggle
	$(sQuestionsCssClass).click(function()
		{
			var image = $(this).children("img:first");
			if (image.attr("src") == sCollapseImageUrl)
			{
				image.attr("src", sExpandImageUrl).attr("alt", "+");
				$(this).next(sAnswersCssClass).slideUp(200);
			}
			else
			{
				image.attr("src", sCollapseImageUrl).attr("alt", "-");
				$(this).next(sAnswersCssClass).slideDown(200);				
			}
			
			//If all questions hidden
			if (($(sAnswersCssClass + ":visible").length == 1 && expandCollapse.text() == sCollapseAllText) 
				|| $(sAnswersCssClass + ":hidden").length == 0 && expandCollapse.text() == sExpandAllText)
				expandCollapse.triggerHandler("click");
		});
	
	//Expand All/Collapse All toggle
	expandCollapse.toggle
	(
		function()
		{
			$(sQuestionsCssClass).children("img").attr("src", sCollapseImageUrl).attr("alt", "-");
			$(sAnswersCssClass).show();
			this.innerHTML = sCollapseAllText;
		},
		function()
		{
			$(sQuestionsCssClass).children("img").attr("src", sExpandImageUrl).attr("alt", "+");
			$(sAnswersCssClass).hide();
			this.innerHTML = sExpandAllText;
		}
	);
}

//function to set a cookie
function set_cookie(name, value, exp_y, exp_m, exp_d, path, domain, secure) {
    var cookie_string = name + "=" + escape(value);

    if (exp_y) {
        var expires = new Date(exp_y, exp_m, exp_d);
        cookie_string += "; expires=" + expires.toGMTString();
    }

    if (path)
        cookie_string += "; path=" + escape(path);

    if (domain)
        cookie_string += "; domain=" + escape(domain);

    if (secure)
        cookie_string += "; secure";

    document.cookie = cookie_string;
}

//function to delete a cookie by name
function delete_cookie(cookie_name) {
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

//function to get a cookie by name
function get_cookie(cookie_name) {
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
}

