  	//firefox fix

	if (!document.body.outerHTML){
		var _emptyTags = {
			"IMG":   true,
			"BR":    true,
			"INPUT": true,
			"META":  true,
			"LINK":  true,
			"PARAM": true,
			"HR":    true
		};
	
		HTMLElement.prototype.__defineGetter__("outerHTML", function () {
			var attrs = this.attributes;
			var str = "<" + this.tagName;
			for (var i = 0; i < attrs.length; i++)
				str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
	
			if (_emptyTags[this.tagName])
				return str + ">";
	
			return str + ">" + this.innerHTML + "</" + this.tagName + ">";
		});
	
		HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
			var r = this.ownerDocument.createRange();
			r.setStartBefore(this);
			var df = r.createContextualFragment(sHTML);
			this.parentNode.replaceChild(df, this);
		});
	}

	//firefox fix end
  	
  	var restarray = new Array();
  	var restaurants_list = getElementsByClassName("result");
  	for (i = 0; i < restaurants_list.length; i++){
		divs = restaurants_list[i].getElementsByTagName("div");
		distance = 0;
		for(j = 0; j < divs.length; j++){
			if (divs[j].className == "realdistance"){
				distance = divs[j].innerHTML;
				break;
			}
		}
		
		restname = restaurants_list[i].getElementsByTagName("a")[0].innerHTML.toLowerCase();
		if(restname.substring(0, 4) == 'the ') {
			restname = restname.substring(4);
		}

  		restarray[i] = Array(restaurants_list[i].outerHTML, restname, distance);	

  	}

  	function namesort(a, b){
		if (a[1] > b[1]) return 1;
		if (a[1] < b[1]) return -1;
		return 0; 
  	}

  	function distancesort(a, b){
  		if (b[2] == a[2]){
			return namesort(a, b);
		}else{
			return a[2] - b[2];
		}
  	}

  	function restSort(type){
  		
  		if (type == "name"){
  			restarray.sort(namesort);
  		}else if (type == "distance"){
  			restarray.sort(distancesort);
  		}

  		var restaurants_list = getElementsByClassName("result");
		for (i = 0; i < restaurants_list.length; i++){
			restaurants_list[i].outerHTML = restarray[i][0];
		}
  	}

	
	function filterCuisines() {
		var cuisines = document.getElementsByName("cuisinelist");
		var result_cuisines = getElementsByClassName("result_cuisines");
		var showall = true;
		var oochecked = false;
		if (oo = document.getElementById("oocheck")){
			if (oo.checked){
				oochecked = true;
			}
		}
		for (i = 0; i < cuisines.length; i++){
    		if (cuisines[i].checked){
    			showall = false;
    			break;    		
    		}
		}

		var result_prominent = getElementsByClassName("result_prominent");
		for (i = 0; i < result_prominent.length; i++){
			if (showall && !oochecked){
				result_prominent[i].style.display = 'block';
			}else{
				result_prominent[i].style.display = 'none';
			}
		}	
		
		for (i = 0; i < result_cuisines.length; i++){
			if (showall){
				if (oochecked){
					str = new RegExp(",1000000,", "i");
			    	if (result_cuisines[i].innerHTML.match(str)){
	    				document.getElementById('res' + result_cuisines[i].id).style.display = 'block';
	    			}else{
	    				document.getElementById('res' + result_cuisines[i].id).style.display = 'none';
	    			}
				}else{
					document.getElementById('res' + result_cuisines[i].id).style.display = 'block';
				}
			}else{
				document.getElementById('res' + result_cuisines[i].id).style.display = 'none';
				for (j = 0; j < cuisines.length; j++){
    				if (cuisines[j].checked){
    					str = new RegExp("," + cuisines[j].value + ",", "i");
    					if (result_cuisines[i].innerHTML.match(str)){
    						if (!oochecked){
    							document.getElementById('res' + result_cuisines[i].id).style.display = 'block';
			    				break;
			    			}else{
			    				str = new RegExp(",1000000,", "i");
			    				if (result_cuisines[i].innerHTML.match(str)){
	    							document.getElementById('res' + result_cuisines[i].id).style.display = 'block';
				    				break;
			    				}
		    				}
		    			}
    				}
				}
			}
		}
	}

	function filterFeatures() {
		var features = document.getElementsByName("featureslist");
		var result_features = getElementsByClassName("result_features");
		var showall = true;
		var ffchecked = false;
		if (ff = document.getElementById("ffcheck")){
			if (ff.checked){
				ffchecked = true;
			}
		}
		for (i = 0; i < features.length; i++){
    		if (features[i].checked){
    			showall = false;
    			break;    		
    		}
		}

		var result_prominent = getElementsByClassName("result_prominent");
		for (i = 0; i < result_prominent.length; i++){
			if (showall){
				result_prominent[i].style.display = 'block';
			}else{
				result_prominent[i].style.display = 'none';
			}
		}	
		
		for (i = 0; i < result_features.length; i++){
			if (showall){
				if (!ffchecked){
					str = new RegExp("f", "i");
			    	if (result_features[i].innerHTML.match(str)){
	    				document.getElementById('res' + result_features[i].id).style.display = 'none';
	    			}else{
	    				document.getElementById('res' + result_features[i].id).style.display = 'block';
	    			}
				}else{
					document.getElementById('res' + result_features[i].id).style.display = 'block';
				}
			}else{
				document.getElementById('res' + result_features[i].id).style.display = 'block';
				for (j = 0; j < features.length; j++){
    				if (features[j].checked){
    					str = new RegExp(features[j].value, "i");
    					if (!result_features[i].innerHTML.match(str)){
    						document.getElementById('res' + result_features[i].id).style.display = 'none';
    						break;
		    			}
    				}
				}
			}
		}
	}

	function getElementsByClassName(classname) {
	    var a = [];
    	var re = new RegExp('\\b' + classname + '\\b');
	    var els = document.getElementsByTagName("*");
    	for(var i=0,j=els.length; i<j; i++)
        	if(re.test(els[i].className))a.push(els[i]);
	    return a;
	}
	
	function list_likeIt(useLastCoordinates,serverName,custId,mlid,restaurantName,isFacebook){      
		var rewrite = '<div align="center"><strong>'+rest_name+'</strong> has been added to your <a href="/favorites/">Favorites</a> list.</div>';
        
		if (isFacebook == 1) {
            rewrite = rewrite + '<div id="pop_favorite_facebook">Would you like to share this on your <strong>Facebook</strong> wall?<div align="right"><a href="#" onclick="list_showFBDialog();return false;">Yes</a> | <a href="#" onclick="document.getElementById(&quot;pop_favorite_confirm&quot;).style.display=&quot;none&quot;;return false;">No, Thanks</a>&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
        } else {
            rewrite = rewrite + '<div id="pop_favorite_facebook" ><div align="right"><a href="#" onclick="document.getElementById(&quot;pop_favorite_confirm&quot;).style.display=&quot;none&quot;;return false;">Close Pop-up</a>&nbsp;&nbsp;&nbsp;&nbsp;</div></div>';
		}
		
		document.getElementById('pop_favorite_confirm').innerHTML =  rewrite;
		
        if (useLastCoordinates == true)
            show_pop('pop_favorite_confirm', false, event,-1,-1);
        else
            show_pop('pop_favorite_confirm', true, event,750,160);
            
		var xmlhttp;
		if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();}
		else if (window.ActiveXObject) {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		document.getElementById("likeIt"+mlid).innerHTML = "<img src=\"/img/results-divider.gif\"  alt=\"\" title=\"\" /><img src=\"http://i-allmenus.com/images/common/like_on.jpg\" />";
		xmlhttp.open("GET",serverName+'/likeit/?likeItFbId='+custId+'&likeItId='+mlid,true);
		xmlhttp.send(null);
	}
	
 	function list_showFBDialog() {
 		document.getElementById('pop_favorite_confirm').style.display='none';
  		FB.Connect.showFeedDialog('118585044921',{"restaurantName":rest_name,"restaurantUrl":rest_url},'','', null, FB.RequireConnect.require,function() { }, ("What do you think of " + rest_name + "?"), {value:''});
    }

    function toggle_cuisines(region){
    	var cuisines_region = document.getElementById("cuisines_" + region);
    	if (cuisines_region.style.display == "none"){
    		cuisines_region.style.display = "block";
    		document.getElementById("close_" + region).style.display = "inline";
    		document.getElementById("open_" + region).style.display = "none";
    	}else{
    		cuisines_region.style.display = "none";
    		document.getElementById("close_" + region).style.display = "none";
    		document.getElementById("open_" + region).style.display = "inline";
    	}
    }
    
    function updateList(fetchFrom) {
   		var xmlhttp;
		if (window.XMLHttpRequest) {xmlhttp=new XMLHttpRequest();}
		else if (window.ActiveXObject) {xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
		xmlhttp.onreadystatechange=function()
		{
			if(xmlhttp.readyState==4)
			{
				document.getElementById("std_results").innerHTML = xmlhttp.responseText
			}
		}
		xmlhttp.open("GET",fetchFrom+"?loginReload=loginReload",true);
		xmlhttp.send(null);
   }


