function $RF(el, radioGroup) 
{
	if($(el).type && $(el).type.toLowerCase() == 'radio') 
	{
		var radioGroup = $(el).name;
		var el = $(el).form;
	}
	else if ($(el).tagName.toLowerCase() != 'form')
	{
		return false;
	}
	
	var checked = $(el).getInputs('radio', radioGroup).find(
			function(re) {return re.checked;}
	);
	return (checked) ? $F(checked) : null;
}

function clear_feedback()
{
	if ($('feedback'))
	{
		$('feedback').style.display = 'none';
	}
	return false;
}

function selected_value(selBox) 
{
	return selBox.options[selBox.selectedIndex].value;
}

/* privacy policy */
function showPrivacyPop(event) {
	Event.stop(event);
	Lightview.show({
		href: '/index/privacy-policy',
		rel: 'iframe',
		options: {
			autosize: true,
			closebutton:false,
			menubar: false,
			topclose:true,
			width:650,
			height:650
		}
	});
	return false;
}

function is_integer(s) {
	if (! s == undefined)
	{
		return (s.toString().search(/^-?[0-9]+$/) == 0);
	}
	return false;
}

function findPos(obj) {
	var curtop = 0;
	if (! obj)
	{
		return 0;
	}
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curtop];
	}
	return 0;
}


/* -------------------- */
/* ajax button behavior */
function toggle_button(btn,state){
	
	if(state == 'work'){ // ajax working
		if($('process-'+btn)){
			//$('process-'+btn).style.display="inline";
			//$(btn).style.display="none";
			$(btn).innerHTML = '<img src="/images/menu/btn-loader.gif" alt="Processing" style="padding-top: 10px"/>';
		}
	}else{ // clicakle --  CLICKALE!!!!111oneoneone
		if($('process-'+btn)){
			//$(btn).style.display="block";
			//$('process-'+btn).style.display="none";
			$(btn).innerHTML = 'Add to Cart';
		}
	}
}
/* end ajax button behavior*/

function checkURL()
{
	if (window.location.hash != "")
	{
		window.location = "/user/invitefriends";
	}
	return true;
}

function show_error(msg, level)
{
	$('feedback').down('p').innerHTML = msg;
	$('feedback').className = level;
	$('feedback').appear();
}

/* -----------------------*/
/* Search : city drop down*/
// perform page and element update on click on a select like tooltip.
function do_select(elem,evt){
	Event.stop(evt); // stop navigation
	// get values
	var arr = (elem.href).split('#'); // get element
	svalue = arr[1].toLowerCase(); // get value for form 
	stxt = elem.innerHTML;  // get value for display
	sdivid = ((elem.up('div')).id).split('-'); // get wrapper div ID
	sdivid = sdivid[0];
	//set values
	$(sdivid).down('span').update(stxt);// set display
	$(sdivid).down('input').value=svalue; // set value of hidden input
	Tips.hideAll(); // hide all tooltips
}
function init_drop_like(){
	// create drop down like element : create Tip obj
	$A($$('#searchbox .select-like-dg')).each(function(s) {new Tip(s.id, $(s.id+'-values'),{style: 'searchdl'});});
	// observe all links (a) within a droplevel (.droplevel) class element in the searchbox (#searchbox)
	$A($$('#searchbox .droplevel a')).each(function(s) {Event.observe(s,'click',function(event){do_select(s,event);});});
}
document.observe("dom:loaded", init_drop_like);
/*End Search : city drop down*/


/*-----------------------*/
/* Google maps features */
function doGmap() {
if (GBrowserIsCompatible()) {
	/* vars */
	var gmarkers = []; var glist = [];
	var px=0; var py=0;
	var geocoder = new GClientGeocoder();
	var total=0;
	// generate custom icons
    var myIcons = [];	
	var custIcon = new GIcon(G_DEFAULT_ICON);
	custIcon.iconSize = new GSize(17, 25);
	custIcon.shadowSize = new GSize(25, 25);
	for(var i=1; i<11;i++){
  	  myIcons[i] = new GIcon(custIcon, "/images/menu/pins/ico-pin"+i+".png");
	}
	/* function createMarker(point,name)
		create marker & attach behaviors
		point : LatLng Gmap2 obj, locdata (Array) data from page html with infoWindow content
	*/
	function createMarker(point,locdata) {
		var marker = new GMarker(point,{ icon : myIcons[locdata["gmp_ord"]]}); //Create marker
		// tooltip content		
        marker.gmaptip = '<div class="gmaptip"><p><b>'+locdata["gmp_nme"]+'</b><br/>'
        marker.gmaptip += locdata["gmp_rnk"]+'<br/>';
        marker.gmaptip += locdata["gmp_tel"]+'<br/>';
        marker.gmaptip += locdata["gmp_adr"]+'<br/>';		
		marker.gmaptip += '</p></div>';
		
		gmarkers.push(marker);//store in global marker array 
		glist.push(point); // add point to point list. (not used)
		map.addOverlay(marker);// append marker to map

		// behaviors
        GEvent.addListener(marker, "click", function(){});
        GEvent.addListener(marker,"mouseover", function(Event) {
			px = px + marker.getIcon().iconSize.width-310;
			py = py - marker.getIcon().iconSize.height-10;
			$('mapinfo').innerHTML = marker.gmaptip;
			$('mapinfo').setStyle({'top':py+'px', 'left':px+'px','display':'block'}) ;
        });
        GEvent.addListener(marker,"mouseout", function() {
			$('mapinfo').setStyle({'display':'none'}) ;
        });
		// multiple, onlick, navigate to Restaurant page
		if(total>1){
			GEvent.addListener(marker,"click", function() {
				alert("do somtething : go restaurant profile ?");
			});
		}
      }
	  /* end  createMarker()*/

	/* gather all adresses on page & createMarker for each 
		adr_class : css class of element containing address
	*/
	function LocationList(adr_class){
		$A($$(adr_class)).each(function(s){ total++;
									var locdata=[]; // form page HTML : location :(address, order (in search res), name, overall rank, telephone,
									locdata["gmp_adr"] = s.down('span.gmp_adr').innerHTML;
									locdata["gmp_ord"] = s.down('span.gmp_ord').innerHTML;
									locdata["gmp_nme"] = s.down('span.gmp_nme').innerHTML;
									locdata["gmp_rnk"] = s.down('span.gmp_rnk').innerHTML;
									locdata["gmp_tel"] = s.down('span.gmp_tel').innerHTML;
										geocoder.getLatLng(locdata["gmp_adr"],// geocode address callback on returned value(=point)
														   function(point){													   
															 //  var label = s.innerHTML; // tooltip content = adress
															   var marker = createMarker(point,locdata); //create marker
										});	
								}
			);
		}

	// listent to mousemove over map & update abs cursor pos
	Event.observe('map_canvas', 'mousemove', function(event) {px = Event.pointerX(event); py = Event.pointerY(event);});
    // create the map
	var map = new GMap2(document.getElementById("map_canvas"),  { size: new GSize(250,250) } );
	map.addControl(new GSmallMapControl());
//	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(43.707097,-79.395103), 10);//Toronto Wide
	// build markers
	LocationList('.api_address');
	//recenter & zoom if case unique address
	if(total<2){
		$A($$('.api_address')).each(function(s){
			geocoder.getLatLng(s.down('span.gmp_adr').innerHTML, function(point){map.setCenter(point, 15);});
		});
	}
} // GBrowserIsCompatible
}
//Event.observe(window, 'load', function() { doGmap();});
//document.observe("dom:loaded", function() { doGmap();});
//Event.observe(window, 'resize', function() { doGmap();});
/* End Google maps features */
/*--------------------------*/


