

function getCountryCenter(country_code) {
  
  lat_array=new Array(4);
  lat_array['FR']=48.862682;
  lat_array['BE']=50.855809;
  lat_array['LU']=49.60537;
  lat_array['US']=39.249271;

  lng_array=new Array(4);
  lng_array['FR']=2.351074;
  lng_array['BE']=4.367752;
  lng_array['LU']=6.146851;
  lng_array['US']=94.584045;
  
  return new GLatLng(lat_array[country_code],lng_array[country_code]);
}

function getCountryZoom(country_code) {
  
  zoom_array=new Array(4);
  zoom_array['FR']=6;
  zoom_array['BE']=7;
  zoom_array['LU']=8;
  zoom_array['US']=5;

  return zoom_array[country_code];
}

function createMarker(map,point,position) {



     var icon = new GIcon();
     icon.image = imageDirectory+"marker/marker_"+position+".png";

     icon.iconSize = new GSize(25,29);
     icon.iconAnchor = new GPoint(13.5, 40);
     icon.infoWindowAnchor = new GPoint(13.5, 10);

     var hicon = new GIcon();
     hicon.image = imageDirectory+"marker/marker_"+position+"_h.png";
     hicon.iconSize = new GSize(25,29);
     hicon.iconAnchor = new GPoint(13.5, 40);


    var marker = new GMarker(point,{icon:icon,zIndexProcess:inverseOrder});
    var hmarker = new GMarker(point,{icon:hicon,zIndexProcess:firstOrder});

    
    map.addOverlay(marker);
    
    return marker;
}


function addEventObserver(map,zoom,center) {
       
       /* Event.observe($('map_up'), "click", function() {map.panDirection(0,1);});
        Event.observe($('map_down'), "click", function() {map.panDirection(0,-1);});
        Event.observe($('map_left'), "click", function() {map.panDirection(1,0);});
        Event.observe($('map_right'), "click", function() {map.panDirection(-1,0);});*/
        Event.observe($('map_in'), "click", function() {map.zoomIn();zoom=map.getZoom();map_slider.setValue(zoom);});
        Event.observe($('map_out'), "click", function() {map.zoomOut();zoom=map.getZoom();map_slider.setValue(zoom);});
        Event.observe($('map_center'), "click", function() {map.setCenter(center);});
        
        Event.observe($('map_satelitte'), "click", function() {
          map.setMapType(G_SATELLITE_MAP);
          $('map_satelitte').addClassName("active");
          $('map_hybrid').removeClassName("active");
          $('map_normal').removeClassName("active");
        });
    
        Event.observe($('map_hybrid'), "click", function() {
          map.setMapType(G_HYBRID_MAP);
          $('map_hybrid').addClassName("active");
          $('map_satelitte').removeClassName("active");
          $('map_normal').removeClassName("active");
          });

        Event.observe($('map_normal'), "click", function() {
          map.setMapType(G_NORMAL_MAP);
          $('map_normal').addClassName("active");
          $('map_satelitte').removeClassName("active");
          $('map_hybrid').removeClassName("active");

          });
       
        $('map_reduce').hide();
        $('map_normal').addClassName("active");

        Event.observe($('map_enlarge'), "click", function() {
        $('map').style.height=600+"px";
        $('map_reduce').show();
        $('map_enlarge').hide();
        map.checkResize();
        map.panDirection(0,+1)
        });

        Event.observe($('map_reduce'), "click", function() {
        $('map').style.height=300+"px";
        $('map_enlarge').show();
        $('map_reduce').hide();
        map.checkResize();
        map.panDirection(0,-1)
        });

        var map_slider=new Control.Slider('map_slider_handle','map_slider_track',{
        axis: 'vertical',
        sliderValue: zoom,
        range:$R(17,4),
        values:[17,16,15,14,13,12,11,10,9,8,7,6,5,4],
        onChange:function(v){
        zoom=v;
        map.setZoom(v);
          }});

}


function inverseOrder(marker,b) {
  return GOverlay.getZIndex(marker.getPoint().lat());
}

       function firstOrder(marker,b) {
  return -1000;
}


function displayInfoWindow(position) {
	
	var obj = document.getElementById("info_"+position);
	var obj1 = document.getElementById("user_"+position);
	var shop1 = document.getElementById("shop_"+position);
	
	if(obj!=undefined) var html='<div class="infowindow" >'+obj.innerHTML+'</div>';
	if(obj1!=undefined) var html1='<div class="infowindow" >'+obj1.innerHTML+'</div>';
	if(shop1!=undefined) var html2='<div class="infowindow" >'+shop1.innerHTML+'</div>';
	
	if(obj!=undefined) {
		var infoTabs = [
		    new GInfoWindowTab(itemTxt,html),
		    new GInfoWindowTab(memberTxt,html1)
		];
	}
	else if(shop1!=undefined) {
		var infoTabs = [
		    new GInfoWindowTab(shopTxt,html2),
		    new GInfoWindowTab(memberTxt,html1)
		];
	}
	
	
	markers[position].openInfoWindowTabsHtml(infoTabs);

}

function inverseOrder(marker,b) {
  return GOverlay.getZIndex(marker.getPoint().lat());
}

       function firstOrder(marker,b) {
  return -1000;
}

function drawCircle(center, radius, color, thickness, opacity) {
	//Function created by Chris Haas
	var circleQuality = 1;			//1 is best but more points, 5 looks pretty good, too
	var M = Math.PI / 180;			//Create Radian conversion constant
	var L = map.getBounds();		//Holds copy of map bounds for use below
	var sw = L.getSouthWest();
	var ne = L.getNorthEast();

	//The map is not completely square so this calculates the lat/lon ratio
	// this works because we create a square map
	var circleSquish = (ne.lng() - sw.lng()) / (ne.lat() - sw.lat());
        circleSquish=1.5;
	var points = [];							//Init Point Array
	//Loop through all degrees from 0 to 360
	for(var i=0; i<360; i+=circleQuality){
		var P = new GLatLng(
			center.lat() + (radius * Math.sin(i * M)),
			center.lng() + (radius * Math.cos(i * M)) * circleSquish
			);
		points.push(P);
	}
	points.push(points[0]);	// close the circle
	var p = new GPolyline(points, color,300, 0.3)
	map.addOverlay(p);
	oldPoly.push(p);
}



function formatRating(rating) {
    //if (rating>0)
    return '<img src="'+imageDirectory+'rating/'+Math.ceil(rating)+'.png" width="80" height="14" alt="'+sprintf(ratingTxt,Math.ceil(rating))+'" title="'+sprintf(ratingTxt,Math.ceil(rating))+'"/>';
    //else return noratingTxt;
}

function formatEvaluationNumber(number) {
    if (number==1) return sprintf(evaluationTxt,number);
    else if (number>1) return sprintf(evaluationsTxt,number);
    else return  noevaluationTxt;
}


function formatPrice(local_currency_position,price,currency) {

   if(price==0) return '-';	
   price=number_format(price, currencyDecimals, currencyDecimalSeperator, currencyThousandsSeperator);
   currency=iso4217ToSymbol(currency);
   
   if (local_currency_position=='right')return sprintf("<b>%s</b> %s",price,currency);
   else if (local_currency_position=='left')return sprintf("%s <b>%s</b>",currency,price);
   else return price;
}

function formatDistance(distance,distanceUnitValue,distanceUnit) {

   return sprintf("%s %s",Math.round(100*distance/distanceUnitValue)/100,distanceUnit);

}


function formatUserState(userState) {

  if (userState==30) return '<a class="inform" title="'+verifiedTitleTxt+'"><b>'+verifiedTxt+'</b></a>';
  else return normalTxt;
}

function formatLocation(postal_code,locality,admin_area,country_code,title) {

     xlocation='<li>'+postal_code+'</li>';
     xlocation+='<li>'+locality+'</li>';
     if (formStateFieldVisible==1) xlocation+='<li>'+admin_area+'</li>';
     if (formCountryFieldVisible==1) xlocation+='<li>'+country_code+'</li>';
     
     return xlocation;
   }
   

function qs(url,p,v){

  if(window.RegExp&&window.encodeURIComponent){

      if(url.indexOf(p+"=")!=-1){
          var regex=p+"=[^&$]*";
          var url1=url.replace(new RegExp(regex),p+"="+v);
      }
      else {var url1=url+"&"+p+"="+v;}
  }
  return url1;

}

function qs_2(url,p,v,deletep){   

  if(window.RegExp&&window.encodeURIComponent){
     if(deletep==true){
        if(url.indexOf("&"+p+"="+v)!=-1){
          var url1=url.replace('&'+p+'='+v,'');
        }else if(url.indexOf(p+"="+v+"&")!=-1){
          var url1=url.replace(p+'='+v+'&','');
        }else{
          var url1=url.replace(p+'='+v,'');
        }
        
     }else{        
      if(url.indexOf(p+"="+v)!=-1){       
          var url1=url.replace(p+'='+v,p+'='+v);
      }
      else {var url1=url+"&"+p+"="+v;}
     }
  }
  return url1;

}


           
//http://fr.local.zilok.com/search/?what=wii&where=&country=Europe&lat=&acc=&lng=&x=0&y=0