function OpenPopUpDiv(url,width){
    $("#popupdiv").html("chargement en cours ...");
    /////////////////////////centrer le contenu /////////
    var largeur = 0, hauteur = 0;
 
    hauteur=$(window).height();
    largeur=$(window).width(); 
    /*----------------------------------------------------------------------*/
    var pos=0;
    if (window.innerHeight) {
        pos = window.pageYOffset
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        pos = document.documentElement.scrollTop
    }
    else if (document.body) {
        pos = document.body.scrollTop
    }
    dx=((largeur-width > 0)? parseInt((largeur-width)/2) :100);
    dy=((hauteur-600 > 0)? parseInt((hauteur-600)/2) :100);
    /////////////////////////////////////////////
 
    $('#popupdiv').show();
    $('#popupdiv').css("width", width+"px");
    $('#popupdiv').css("left",(document.body.scrollLeft+dx));
    $('#popupdiv').css("top",(pos+dy));	
    $.ajax({
        url: web_root+url,
        cache: false,
        success: function(html){
            //alert(html);
            $("#popupdiv").html(html);
        }
    });  
	
    return false;
	
}

//////////////////////////////////////////////
function openPopUpRepondeMessage(iMessageId){
    OpenPopUpDiv('/contact/repondreMessageAnnonce/'+iMessageId,500);
    return false;
}
////////////////////////////////////////////
function OpenPopUpSendToFriends(objRef,annonceId){
    OpenPopUpDiv('/contact/sendToFriends/'+annonceId,450,450);
    return false;
	

}
////////////////////////////////////////////
function OpenPopUpAnnonceMap(annonceId){
    OpenPopUpDiv('/immobilier/annonceGmap/'+annonceId,600);
    return false;
}
////////////////////////////////////////////
function OpenPopUpListMap(page){
    OpenPopUpDiv('/immobilier/annonceListMap/'+page,800);
    return false;
}
////////////////////////////////////////////
function OpenPopUpNousContacter(){
    OpenPopUpDiv('/contact/nousContacter/',700);
    return false;
}

////////////////////////////////////////////
function addAnnonceHome(iAnnonceId){
    var url = web_root+'/userSelection/addHomeAnnonce/'+iAnnonceId;
    var spanid='#span_homeimage_'+iAnnonceId;
    loading(spanid);
	$.ajax({
        url: url,
        cache: false,
        success: function(html){
            //alert(html);
            $(spanid).html(html);
        }
    });  
    return false;
}
////////////////////////////////////////////
function deleteAnnonceHome(iAnnonceId){
	
    var url = web_root+'/userSelection/deleteHomeAnnonce/'+iAnnonceId;
    var spanid='#span_homeimage_'+iAnnonceId;
    loading(spanid);
		$.ajax({
        url: url,
        cache: false,
        success: function(html){
            //alert(html);
            $(spanid).html(html);
        }
    });  
    return false;
}

////////////////////////////////////////////
function addToSelection (iAnnonceId){
    //alert (web_root);
    var spanid='#spanselection_'+iAnnonceId;
    var url = web_root+'/userSelection/add/'+iAnnonceId;
    // notice the use of a proxy to circumvent the Same Origin Policy. 
    loading(spanid);
	$.ajax({
        url: url,
        cache: false,
        success: function(html){
            //alert(html);
            $(spanid).html(html);
        }
    });  
    return false;
}
////////////////////////////////////////////
function loading(id){
    $(id).html("loading...");
}
//////////////////GMAP//////////////////////////

function HomeControl(controlDiv, mymap) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';
  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '2px';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Center la carte sur le marqueur ';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = 'Center la carte sur le marqueur';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to Chicago
  google.maps.event.addDomListener(controlUI, 'click', function() {
    mymap.setCenter(mypoi)
  });
  
}
