	$(function() {
	  var hoverTimeout = null;
	  
	  $(".clickable").click(function() {
	    var link = $(this).attr("link");
	    if ( link.indexOf("javascript:") == 0 ) {
	      try {
	        eval(link.substring(11));
	      } catch (ignored) {}
	    } else {
  	    location.href = link;
	    }
	  }).find("a").click(function(e) {
	    e.stopPropagation();
	  });
    $(".gh-lang-change").click(function() {
      $("#ghLanguageSelect").show()
          .position({my: "right top", at: "right bottom", of: $(this)})
          .hover(function(e) {
            if ( hoverTimeout ) clearTimeout(hoverTimeout);
          },function(e) {
            hoverTimeout = setTimeout(function() { $("#ghLanguageSelect").hide(); }, 500);
          });
	  }).hover(function(e) {
      if ( hoverTimeout ) clearTimeout(hoverTimeout);
    },function(e) {
      hoverTimeout = setTimeout(function() { $("#ghLanguageSelect").hide(); }, 500);
    });
		$("input[type=text][default]").each(function() {
		  $(this).bind("blur",function() {
		    var defaultValue = $(this).attr("default");
		    if ( $(this).val() == "" && defaultValue.length > 0 ) {
		      $(this).addClass("defaultInput");
		      $(this).val(defaultValue);
		    }
		  }).bind("focus",function() {
		    var defaultValue = $(this).attr("default");
		    if ( $(this).val() == defaultValue ) {
		      $(this).val("");
		      $(this).removeClass("defaultInput");
		    }
		  });
	    var defaultValue = $(this).attr("default");
	    if ( $(this).val() == "" && defaultValue.length > 0 ) {
	      $(this).addClass("defaultInput");
	      $(this).val(defaultValue);
	    }
	    if ( $(this).val() == defaultValue ) {
	      $(this).addClass("defaultInput");
	    }
    });		
		$("#fader").css("height", $(document).height()).css("width", $(document).width())
	  $("form.companysearchform").bind("submit", function(e) {
	    var search = $(this).find("input.companysearch");
	    if ( search.val() == "" || search.val() == "Type a Company, Product, or Organization" ) {
	      location.href = "/customer-service.html";
  	    e.preventDefault();
	    }
	  });
	  $("input.companysearch").autocomplete({
	    delay: 200,
	    source: "/axj/?action=quickSearch",
	    select: function(event, ui) {
	      if ( ui.item.id == 0 ) {
	        $(this).autocomplete("close");
	        $(this).focus();
	        return false;
	      } else {
  	      location.href = ui.item.biz;
	        return false;
	      }
	    },
	    focus: function(event, ui) {
	      return false;
	    }
	  });
	});

	function dummy() {
		// do nothing
	}
	
	function doUseful(id, use, type) {
		sendUseful(id,use,type);
	}
	
	function sendUseful(id,use,type) {
		$.post(
			"/axj/",
			{
				action: "isUseful",
				type: type,
				id: id, 
				use: use
			},
			function (data) {
        location.href = location.href;
			},
			"json"
		);
	}

	function isUseful(id, use) {
		doUseful(id, use, "alt");
	}

	function isItUseful(id, use) {
		doUseful(id, use, "biz");
	}

	function showFader() {
		$("#fader").show();
	}
	
	function hideAll(suppressReload) {
		$("#fader").hide();
		$("div.popin").hide();
		if ( !suppressReload ) location.href = location.href;
	}

	function hideOne(o) {
		$("#" + o).hide();
	}

	function doAnchor(item, anchor, orient) {
	  var anchor = anchor || window;
	  var orient = orient || "center";
	  if ( orient == "right" || orient == "leftunder" ) {
      $("#" + item).position({my: "left top", at: "right top", of: $("#" + anchor)});
	  } else if ( orient == "middle" ) {
      $("#" + item).position({my: "center", at: "center", of: window});
	  } else if ( orient == "left" ) {
      $("#" + item).position({my: "right top", at: "left top", of: $("#" + anchor)});
	  } else {
      $("#" + item).position({my: orient, at: orient, of: anchor});
	  }
  }

	function showLoading() {
		var ani = "";
		return ani;
	}

	function startPop(anchor, orient) {
		showFader();
		$("#gpop").show();
		doAnchor("gpop",anchor,orient);
	}
	
	function formLoaded() {
		$("#gpop input:first").focus();
		$("#gpop .focus:first").focus();
		$("#gpop .bad:first").focus();
		
		$("div.dialog .ghbtn").button();
	}
	
	function addRecaptcha() {
		Recaptcha.create("6LdhiQgAAAAAAB-2PKvUI_YTKzmgeVMOyMZ9PtC_",
			"recap",
			{
				theme: "custom",
				callback: showRecaptcha
			}
		);
	}
	
	function showRecaptcha() {
		$("tr.recaptcha").show();	
	}

	function addContact(anchor, bizId, altId, type, orient) {
		loadAddContact(bizId, altId, type, function() {
  		startPop(anchor,orient);
		});
	}

	function loadAddContact(bizId, altId, type, callback) {
		$("#gpop").load("/axj/addContact.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, callback);
	}
	
	function updateContact(anchor, bizId, altId, type, orient) {
		loadUpdateContact(bizId, altId, type, function() {
  		startPop(anchor,orient);
		});
	}
		
	function loadUpdateContact(bizId, altId, type, callback) {
		$("#gpop").load("/axj/updateContact.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, callback);
	}
	
	function doProblems(anchor, bizId, altId, type, orient) {
		$("#gpop").load("/axj/doProblems.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, function() {
  		startPop(anchor,orient);
		});
	}

	function doUseless(anchor, bizId, altId, type, orient) {
		sendUseful(altId, 'useless', 'alt');
		doProblems(anchor, bizId, altId, type, orient);
	}
	
	function addRating(anchor, bizId, altId, type, orient) {
		loadAddRating(bizId, altId, type, function () {
		  startPop(anchor,orient);
		});
	}

	function loadAddRating(bizId, altId, type, callback) {
		$("#gpop").load("/axj/addRating.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, callback);
	}
	
	function addTip(anchor, bizId, altId, type, orient) {
		loadAddTip(bizId, altId, type, function() {
  		startPop(anchor,orient);
		});
	}
	
	function loadAddTip(bizId, altId, type, callback) {
		$("#gpop").load("/axj/addTip.html", "bizId=" + bizId + "&altId=" + altId + "&type=" + type, callback);
	}

	function doCheckHuman(callback) {
		$("#gpop").load("/axj/checkHuman.html", "cb=" + callback, function() {
  		startPop("none","middle");
		});
	}
	
	function showCopyLink(link) {
		$("#linktopage").toggle();
		$("#currenturl").focus();
		$("#currenturl").select();
	}
	
	function setCookie(name,value,days) {
		setCookieWithTime(name,value,(days*24*60*60*1000));
	}

	function setCookieWithTime(name,value,time) {
		if (time) {
			var date = new Date();
			date.setTime(date.getTime()+time);
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/; domain=.gethuman.com";
	}

	function getCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function deleteCookie(name) {
		setCookie(name,"",-1);
	}

	function doBookmark(title, url) {
		if (window.sidebar) { 
			// Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { 
			// IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera && window.print) {
			// Opera
			return true; 
		}
	}

  function logLp(cid) {
    $.post("/axj/", {action: "logLp", cid: cid});
  }

	function ghSharingThanks(anchor, orient) {
		$("#gpop").load("/axj/thankyouForSharing.html", function() {
  		startPop(anchor,orient);
		});
	}
  
  function ghFbHandleResponse(response) {
    if (response && response.post_id) {
      // say thanks
      ghSharingThanks("window", "middle");
    } else {
      // do nothing; just be sad... :(
      location.href = location.href;
    }
  }
  
  function ghFbShare(e, cb, name, msg, caption, description, link, actions) {
    var cb = cb || ghFbHandleResponse;
    var name = name || "GetHuman.com";
    var msg = msg || 'Customer service shortcuts, phone numbers, ways for a company to call you back, live chat options, email addresses, reviews... GetHuman has it all.';
    var caption = caption || 'No More Waiting on Hold | The Ultimate Customer Service Tool';
    var description = description || 'GetHuman.com ranks the fastest & best phone numbers for companies, complete with shortcuts, a way to have companies call you instead, live chat options, emails, reviews and more for businesses worldwide.';
    var link = link || 'http://gethuman.com';
    var actions = actions || [{ name: 'GetHuman', link: 'http://gethuman.com' }];
    if ( e ) e.preventDefault();
    FB.ui({method: 'feed', message: msg, name: name, caption: caption,  description: description, link: link, picture: 'http://gethuman.com/images/gh-100.png', actions: actions}, cb);
  }
  
  function ghAddScript(d, src, id) {
    var js; if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true; js.type = "text/javascript"; js.src = src;
    d.getElementsByTagName('head')[0].appendChild(js);
  }
  
  function setLanguage(l) {
    var dom = "";
    if ( l != "en" ) dom = l + ".";
    var url = window.location;
    url = url.toString();
    url = url.replace(/.+gethuman.com/,"http://" + dom + "gethuman.com")
    setCookie("ghNativeTongue",l,1000);
    window.location = url;    
  }

