if (typeof GFC=="undefined") {var GFC=new Object();}

function gfc_hide(elem){ elem.style.display = 'none'; }
function gfc_show(elem) { elem.style.display = ''; }
function gfc_visible(elem){ return elem.style.display != 'none'; }
function gfc_toggle(elem){ (gfc_visible(elem)) ? gfc_hide(elem) : gfc_show(elem); }
function togglecomments (postid) { var whichpost = document.getElementById(postid); if (whichpost.className=="commentshown") { whichpost.className="commenthidden"; } else { whichpost.className="commentshown"; } } 

var zg_toggleWhat = function() {
  document.getElementById('zg_whatdiv').style.display = (document.getElementById('zg_whatdiv').style.display != 'none') ? 'none' : '';
  document.getElementById('zg_whatlink').style.display = (document.getElementById('zg_whatdiv').style.display != 'none') ? 'none' : '';
  return false;
}

function forAllLinks(filterFunc,processFunc)
{
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  var urlString = '';
  for (var i=0; i < links.length; i++) {
    urlString = (links[i].href==undefined) ? '' : links[i].href.toLowerCase();
    if ( filterFunc(urlString,links[i]) ) 
    {
      processFunc(urlString,links[i]);
    }
  }
}

function isExternalLink(urlString,linkElement)
{
  return urlString != '' && urlString != '#' && linkElement.onclick == undefined 
	&& !( urlString.match("gastronomicfightclub") || urlString.match("javascript")  ) ;
}

function addTrackingOnClick(urlString,linkElement)
{
   var linkTitle = (linkElement.title == undefined) ? '' : linkElement.title ;
   linkTitle = escape(linkTitle);
   linkElement.observe
   (
   		'click',   
		function(event)
	   {
	        urchinTracker('/out/gfc/'+linkTitle+'/'+escape(linkElement.href));
	   }
   );
}

function addTrackingForAllExternalLinks() 
{
  forAllLinks(isExternalLink,addTrackingOnClick);
}

function check() { 
	forAllLinks( isExternalLink, function(urlString,linkElement){alert(linkElement.title + ' @ ' +linkElement.href);} ); 
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/** Code borrowed from yelp.com  These are not used, but are here for reference **/

// chain more than one function to the onload/onunload handler
function chainOnload(f) {
	var prev = window.onload;
	window.onload = function() {
		if (prev) {
			prev();
		}
		f();
	}
}

function chainOnunload(f) {
	var prev = window.onunload;
	window.onunload = function() {
		if (prev) {
			prev();
		}
		f();
	}
}

//Character counting for textareas which cannot take maxlength
function countChars(fieldname,limit) {
	var num = fieldname.value.length;
	if (num > limit) {
		alert('We\'re sorry, you may only write up to ' + limit + ' characters in this field.');
		fieldname.value = fieldname.value.substring(0, limit-1);
	} else {
		//be idle
	}
	return;
}

// Sets the browser's location
function set_location(url) {
	document.location.href = url;
}

// Cross-browser event target finder. works better than prototype's for safari.
function findEventTarget(evt){
	var e=evt?evt:window.event?window.event:null; 
	var target=e.target?e.target:e.srcElement?e.srcElement:null; 
	if(target.nodeType==3) target=target.parentNode;// handle Safari bug 
	return target;
}

// insert element as the first child of target
function insertAsFirstChild(toInsert, target){
	if(target && toInsert){
		if(target.childNodes.length == 0)
			target.appendChild(toInsert)
		else
			target.insertBefore(toInsert, target.childNodes[0])
	}
}

// insert element after a target element
function insertAfter(toInsert, target){
	if(target && toInsert){
		target.parentNode.insertBefore(toInsert, target.nextSibling)
	}
}

function encode_utf8(s)
{
  return unescape( encodeURIComponent(s) );
}

function decode_utf8(s)
{
  return decodeURIComponent( escape(s) );
}