function conf()
{
  if( confirm( 'Are you sure?' ) ) return true
  else return false;
}

function conf_studio()
{
  if( confirm( 'You are attempting to leave the tab without saving your work. If you would like to save your changes please click \'Save and Continue\' or click \'OK\' to proceed without saving your changes.' ) ) return true
  else return false;
}


function openAWindow2( pageToLoad, winName, width, height, center){

xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 ) &&(center)){
 xposition = (screen.width - width) / 8;
 yposition = (screen.height - height) / 3;
}

args = "width=" + width + ","
+ "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "resizable=0,"
+ "scrollbars=1,"
+ "status=0,"
+ "titlebar=0,"
+ "toolbar=0,"
+ "hotkeys=0,"
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only

window.open( pageToLoad, winName, args );

}

function openAWindow( pageToLoad, winName, width, height, center){

xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 ) &&(center)){
 xposition = (screen.width - width) / 8;
 yposition = (screen.height - height) / 3;
}

args = "width=" + width + ","
+ "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "resizable=0,"
+ "scrollbars=0,"
+ "status=0,"
+ "titlebar=0,"
+ "toolbar=0,"
+ "hotkeys=0,"
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only

window.open( pageToLoad, winName, args );

}

function void_() {
}

function xget(id) {
	if(document.getElementById) return document.getElementById(id);
	if(document.all) return document.all[id];
	return null;
}

if (navigator.userAgent.toLowerCase().indexOf('gecko') != -1) {
     window.attachEvent = function(eventName, delegate) {
         this.addEventListener(eventName.substring(2), delegate, false);
     }
}

function makeHttpRequest(url, callback_function, return_xml) {
  var http_request = false;

  if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType && return_xml == 'xml') {
			 http_request.overrideMimeType('text/xml');
		}
  } else if (window.ActiveXObject) { // IE
		try {
			 http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			 try {
				  http_request = new ActiveXObject("Microsoft.XMLHTTP");
			 } catch (e) {}
		}
  }

  if (!http_request) {
		alert('Unfortunately your browser doesn\'t support this feature.');
		return false;
  }

  http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			 if (http_request.status == 200) {
				  if (return_xml == 'xml') {
						eval(callback_function + '(http_request.responseXML)');
				  } else {
						eval(callback_function + '(http_request.responseText)');
				  }
			 } else {
//				  alert('There was a problem with the request. (Code: ' + http_request.status + ')');
			 }
		}
  }
  http_request.open('GET', url, true);
  http_request.send(null);
}

function SetCookie (name, value) {
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) +
                ((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                        if (i == 0)
                                break;
                }
   return null;
}

function detect_user_agent(){
	navigator.DOM=!!(document.getElementById?1:0);
	navigator.OPERA=!!(window.opera);
	navigator.OPERA5=!!(navigator.OPERA&&navigator.userAgent.indexOf("pera 5")>0);
	navigator.OPERA6=	!!(navigator.OPERA&&navigator.userAgent.indexOf("pera 6")>0);
	navigator.IE9=		!!(navigator.appVersion.indexOf("IE 9")>0&&navigator.DOM&&!navigator.OPERA?1:0);
	navigator.IE8=		!!(navigator.appVersion.indexOf("IE 8")>0&&navigator.DOM&&!navigator.OPERA?1:0);
	navigator.IE7=		!!(navigator.appVersion.indexOf("IE 7")>0&&navigator.DOM&&!navigator.OPERA?1:0);
	navigator.IE6=		!!(navigator.appVersion.indexOf("IE 6")>0&&!navigator.IE7&&!navigator.IE8&&navigator.DOM&&!navigator.OPERA?1:0);
	navigator.IE5=		!!(navigator.appVersion.indexOf("IE 5")>0&&navigator.DOM&&!navigator.OPERA?1:0);
	navigator.IE4=		!!(document.all&&!navigator.DOM?1:0);
	navigator.IE=		!!(navigator.IE4||navigator.IE5||navigator.IE6||navigator.IE7||navigator.IE8||navigator.IE9);
	navigator.MAC=		!!(navigator.userAgent.indexOf("Mac")>0);
	navigator.Mozilla=		!!(navigator.userAgent.indexOf("Mozilla")>0);
	navigator.NS6=		!!(navigator.DOM && parseInt(navigator.appVersion)>4?1:0);
	navigator.NS4=		!!(document.layers && !navigator.DOM?1:0);
	navigator.DOMCORE1=	!!(typeof(document.getElementsByTagName)!='undefined' && typeof(document.createElement)!='undefined');
	navigator.DOMCORE2=	!!(navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
	navigator.DOMHTML=	!!(navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
	navigator.DOMCSS1=	!!(navigator.NS6||navigator.IE)	;
	if(navigator.DOMCORE1&&!navigator.OPERA)
	{	var check_element=document.createElement('p');
		navigator.DOMCSS2=!!(typeof(check_element)=='object');
	} else	navigator.DOMCSS2=!!(false)	
	navigator.DETECTED=	(	navigator.OPERA||navigator.OPERA6||navigator.OPERA5||navigator.IE||navigator.IE6||navigator.IE5||navigator.IE4||navigator.MAC||navigator.NS6||navigator.NS4||navigator.DOM||navigator.DOMHTML||navigator.DOMCORE1||navigator.DOMCORE2||navigator.DOMCSS1||navigator.DOMCSS2	);
	}

function getOffsetx (element) {
   var x=0, y=0;
   if (element.getBoundingClientRect) {
     var offset = element.getBoundingClientRect();
     x = offset.left;
     y = offset.top;
   } else {
     while (element !== null && element !== parent)  {
       x += element.offsetLeft || 0;
       y += element.offsetTop || 0;
       element = element.offsetParent;
     }
   }
   return x
 }
 function getOffsety (element) {
   var x=0, y=0;
   if (element.getBoundingClientRect) {
     var offset = element.getBoundingClientRect();
     x = offset.left;
     y = offset.top;
   } else {
     while (element !== null && element !== parent)  {
       x += element.offsetLeft || 0;
       y += element.offsetTop || 0;
       element = element.offsetParent;
     }
   }
   return y
 }
 
function isNumber(x) {
   return ! isNaN(x * 1);
}

var ua = navigator.userAgent.toLowerCase(); 
var isOpera = (ua.indexOf('opera')  > -1); 
var isIE = (!isOpera && ua.indexOf('msie') > -1); 
  
function getDocumentHeight() { 
return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight()); 
} 
function getDocumentWidth() { 
return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollWidth : document.documentElement.scrollWidth, getViewportWidth()); 
} 
function getViewportHeight() { 
	return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight; 
}
function getViewportWidth() { 
	return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth; 
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}


function touchHandler(event) {
    var touches = event.changedTouches,
        first = touches[0],
        type = "",
        callee = arguments.callee;
    if (touches.length === 1) {
        switch (event.type) {
        case "touchstart":
            type = "mousedown";
            break;
            callee._previousTarget = null;
        case "touchmove":
            type = "mousemove";
            break;
        case "touchend":
            type = "mouseup";
            break;
        default:
            return;
        }
        var simulatedEvent = document.createEvent("MouseEvent");
        simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0, null);
        first.target.dispatchEvent(simulatedEvent);
        if (simulatedEvent.defaultPrevented) {
            event.preventDefault();
        }
        if (callee._previousEvent && callee._previousEvent.touches) {}
        if (event.type === "touchend" && !simulatedEvent.defaultPrevented && callee._previousEvent && callee._previousEvent.touches && callee._previousEvent.touches[0].target === first.target && callee._previousEvent.type !== "touchmove") {
            event.preventDefault();
            simulatedEvent = document.createEvent("MouseEvent");
            simulatedEvent.initMouseEvent("click", true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0, null);
            first.target.dispatchEvent(simulatedEvent);
            if (simulatedEvent.defaultPrevented) {
                event.preventDefault();
            }
        }
        callee._previousEvent = first;
    }
}
if (typeof Touch !== "undefined") {
    document.addEventListener('touchstart', touchHandler, true);
    document.addEventListener('touchmove', touchHandler, true);
    document.addEventListener('touchend', touchHandler, true);
    document.addEventListener('touchcancel', touchHandler, true);
}


function showBanner(id)
{
	for(i=1;i<=10;i++)
	{
		if (xget('banner'+i)) xget('banner'+i).style.display='none';
		if (xget('bn'+i)) xget('bn'+i).className='';
	}
	
	if (xget('banner'+id)) xget('banner'+id).style.display='block';
	if (xget('bn'+id)) xget('bn'+id).className='active';	
	
  return false;
}

function popuptableBGclose() {	
	xget('popuptableBG').style.display='none';
}

function showRecipeHash()
{
showRecipe(window.location.hash);
}

function showRecipe(id) {		
	id=id.replace('#','')
	try {

//		xget("title").innerHTML="";
//		xget("recipe_left").innerHTML="";
//		xget("recipe_right").innerHTML="";
//		xget("more").innerHTML="";
//		xget("more").className="more display_none";
	
		xget('popuptableBG').onclick=function(){popuptableBGclose();};
		xget('popuptableBG').style.height=getDocumentHeight()+'px';
		xget('loaderimg').style.marginTop=(parseInt(getViewportHeight()/2)-30)+'px';;		
		
		xget('popuptableBG').style.display='block';	
		window.scrollTo(0,0);
		
		window.location.hash="#"+id;
		previousUrl = "#"+id;				
		
		makeHttpRequest('getRecipe.aspx?ID='+id+'&rand='+Math.random(), 'displayRecipe', 'text');
		return true;
    }
    catch(e) {
		return true;
	}		
}

function displayRecipe(text) { 
	eval(text);		
	popuptableBGclose();
}

previousUrl='#754828723$';
function initUrl(url) {
	if (url == previousUrl) return;
	if (url =="" && previousUrl=='#754828723$') return;
	previousUrl = url;
	if (url.length>0)
	{
		var re = /\d+/i;			
		if (url.search(re)>=0)
		{
			showRecipe(url)
		}				
	}
};
	 
function urlCheckDaemon() {
	initUrl(window.location.hash);
    setTimeout("urlCheckDaemon()", 250);
}
	 
function myload() {
	setTimeout("urlCheckDaemon()", 250);	

}


function GetPrint() {
	var axel = Math.random() + ""; 
	var a = axel * 10000000000000; 
try{
	xget("popup-table").innerHTML='<iframe src="http://fls.doubleclick.net/activityi;src=1649152;type=jello843;cat=recip921;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>';
}
catch(e) {
}
	window.print();
	return false;
}

function extractParamFromUri(uri, paramName) {
  if (!uri) {
    return;
  }
  var uri = uri.split('#')[0];  // Remove anchor.
  var parts = uri.split('?');  // Check for query params.
  if (parts.length == 1) {
    return;
  }
  var query = decodeURI(parts[1]);

  // Find url param.
  paramName += '=';
  var params = query.split('&');
  for (var i = 0, param; param = params[i]; ++i) {
    if (param.indexOf(paramName) === 0) {
      return unescape(param.split('=')[1]);
    }
  }
}

function closeVideo() {
	if (xget('video')){
		jwplayer('mediaplayer').stop();
		xget('popuptableBG').style.display='none';	
		xget('video').style.display='none';
		xget('mediaplayer').style.display='none';
		var coll = document.getElementsByTagName('IFRAME');	
		if (coll!=null) {
			for (i=0; i<coll.length; i++)
			{
				coll[i].style.display='block';
			}
		 } 
	}
    return false;
}
function showVideo(v) {
	if (xget('video')){
		xget('popuptableBG').onclick=function(){closeVideo();};
		xget('popuptableBG').style.height=getDocumentHeight()+'px';
		xget('video').style.left=(parseInt(getViewportWidth()/2)-292)+'px';;		
		xget('video').style.top=(parseInt(getViewportHeight()/2)-190)+getBodyScrollTop()+'px';;		
		xget('popuptableBG').style.display='block';	
		xget('video').style.display='block';
		xget('mediaplayer').style.display='block';
		var coll = document.getElementsByTagName('IFRAME');	
		if (coll!=null) {
			for (i=0; i<coll.length; i++)
			{
				coll[i].style.display='none';
			}
		 } 	

jwplayer('mediaplayer').setup({
'controlbar': 'bottom',
'height': '287',
'width': '526',
'flashplayer': 'images/player.swf',
'file': ''+v+'',
'plugins': 'gapro-1',
'gapro.accountid': 'UA-22051936-7'
});

	}
    return false;
}


function getNutritionInfo(url) {
	var features = "width=583,height=550,status=0,toolbar=0,scrollbars=1,resizable=0";
	window.open(url, "NutritionalInfo", features);
}
