

var iPOS_WIDTH = 0;
var iPOS_HEIGHT = 1;

function onLoadBody(a_sNomDirImgAnn){

  var oSelBxDirMiniPict = document.getElementById('idSelBoxRepBasePhoto');
  var bContinuer = true;
  var regExpSelOpt = new RegExp(/classeA/i);//a_sNomDirImgAnn);
  // selectionner le repertoire par default dans le liste box
  for(var iIndex =0; iIndex < oSelBxDirMiniPict.options.length && bContinuer == true ; iIndex++ ){
    
		if(regExpSelOpt.test(oSelBxDirMiniPict.options[iIndex].value) ){
      bContinuer = false;
			oSelBxDirMiniPict.options[iIndex].selected = true;
		}
  }
  onChangeDirMiniPict(oSelBxDirMiniPict);
  var oSelBxDirMiniPict_diap = document.getElementById('idSelBoxRepBasePhoto_diap');
  bContinuer = true;
 // var regExpSelOpt2 = new RegExp('images/voiture');
  // selectionner le repertoire par default dans le liste box
  for(var iIndex =0; iIndex < oSelBxDirMiniPict_diap.options.length && bContinuer == true ; iIndex++ ){
   
		if(regExpSelOpt.test(oSelBxDirMiniPict_diap.options[iIndex].value) ){
      bContinuer = false;
			oSelBxDirMiniPict_diap.options[iIndex].selected = true;
		}
  }
  onChangeDirMiniPict_diap(oSelBxDirMiniPict_diap);
  updateViewTabResAnn();
  // ajouter des options
  for(var iNbOption = 0 ;  iNbOption < 6 ; iNbOption++ ){
     onBtnAddOption(document.getElementById('idBtnAddLnTabAddOpt_add_1') , 'idTabOpt_add', 'add'   );
  }
 

}

/*
 * appeler lorsque le body de la page de modification d une annonce a fini de loader
 * */
function onLoadBodyModAnn(a_sNomDirImgAnn, a_sIdAnn){

  var oSelBxDirMiniPict = document.getElementById('idSelBoxRepBasePhoto');
  var bContinuer = true;
  var regExpSelOpt = new RegExp(/classeA/i);//a_sNomDirImgAnn);
  // selectionner le repertoire par default dans le liste box
  for(var iIndex =0; iIndex < oSelBxDirMiniPict.options.length && bContinuer == true ; iIndex++ ){
		if(regExpSelOpt.test(oSelBxDirMiniPict.options[iIndex].value) ){
      bContinuer = false;
			oSelBxDirMiniPict.options[iIndex].selected = true;
		}
  }
  onChangeDirMiniPict(oSelBxDirMiniPict);
  var oSelBxDirMiniPict_diap = document.getElementById('idSelBoxRepBasePhoto_diap');
  bContinuer = true;
  // selectionner le repertoire par default dans le liste box
  for(var iIndex =0; iIndex < oSelBxDirMiniPict_diap.options.length && bContinuer == true ; iIndex++ ){
		if(regExpSelOpt.test(oSelBxDirMiniPict_diap.options[iIndex].value) ){
      bContinuer = false;
			oSelBxDirMiniPict_diap.options[iIndex].selected = true;
		}
  }
  onChangeDirMiniPict_diap(oSelBxDirMiniPict_diap);
  // ajouter des options
  for(var iNbOption = 0 ;  iNbOption < 1 ; iNbOption++ ){
     onBtnAddOption(document.getElementById('idBtnAddLnTabAddOpt_add_0') , 'idTabOpt_'+a_sIdAnn, a_sIdAnn   );
  }
}

// quand le div est en focus ou mouse over sur une annonce 
function onMouseOverAnn(a_eCaller){
  a_eCaller.className = a_eCaller.className + " cDivAnn_Over";// ajouter la classe d'over 
} 

// quand la souris quitte le div d'une annonce 
function onMouseOutAnn(a_eCaller){
  a_eCaller.className = "cDivAnn";// remettre seulement la classe intiale 
}

function scrollHElem(a_oElement, a_iLongueur, a_sDir ){
	if(a_sDir == 'left'){
    if( a_oElement.scrollLeft % a_iLongueur  != 0 ){
  	  a_oElement.scrollLeft = a_oElement.scrollLeft - (a_oElement.scrollLeft % a_iLongueur );
    }else{
  	  a_oElement.scrollLeft = a_oElement.scrollLeft - a_iLongueur;
    }
	}else{
  	if( a_oElement.scrollLeft % a_iLongueur  != 0 ){
  		a_oElement.scrollLeft = a_oElement.scrollLeft + (a_iLongueur - ( a_oElement.scrollLeft % a_iLongueur ) );
    }else{
  	  a_oElement.scrollLeft = a_oElement.scrollLeft + a_iLongueur;
    }
	}
}

function scrollMiniLeft(a_oElem  , a_iLong ){
	scrollHElem(a_oElem , a_iLong , 'left');
}

function scrollMiniRight(a_oElem  , a_iLong ){
	scrollHElem(a_oElem , a_iLong , 'right');
}

function onMouseOverMinDiap(a_oAppelent, a_sIdImgBigPict, a_sIdDivBigPict, a_sIdPSrcBigPict , a_iHeightBigDiv, a_iWidthBigDiv ){
		var eImgBig = document.createElement('img');
    var eDivBigPic = document.getElementById(a_sIdDivBigPict);
		eImgBig.src = a_oAppelent.src ;
		
    var aSize = get_aiPropSize( a_oAppelent.width, a_oAppelent.height, a_iHeightBigDiv, a_iWidthBigDiv );
		eImgBig.width = aSize[iPOS_WIDTH];
		eImgBig.height = aSize[iPOS_HEIGHT];
    var iDivMargeVTotal = 20 ; 
    // trouver les marges horizontale/verticale a ajouter a l'image
    var iMargeH = ( a_iWidthBigDiv  - ( aSize[iPOS_WIDTH] ) )/2 ;
  	var iMargeV = ( a_iHeightBigDiv+iDivMargeVTotal - ( aSize[iPOS_HEIGHT]) )/2 ;

    eImgBig.style.margin =  Math.floor(iMargeV)+"px "+ Math.floor(iMargeH)+"px ";
    eDivBigPic.innerHTML = "";
    eDivBigPic.appendChild(eImgBig);
    // afficher la source de l'image
		//document.getElementById(a_sIdPSrcBigPict).innerHTML = a_oAppelent.src ; 
}

function onErrorLoadImg(a_oThem){
	a_oThem.parentNode.removeChild(a_oThem);
}


/**
 * retourne un array contenant 2 dimension proportionnel aux dimension original
 * @param a_iWidth_orig
 * @param a_iHeight_orig
 * @param a_iMaxHeight
 * @param a_iMaxWidth
 * @return array[2] int 
 */
function get_aiPropSize(a_iWidth_orig, a_iHeight_orig ,a_iMaxHeight, a_iMaxWidth ){
	if(a_iHeight_orig != 0 && a_iWidth_orig != 0 ){
		var iRatio_orig = a_iWidth_orig/a_iHeight_orig;
		var iRatio_max = a_iMaxWidth/a_iMaxHeight;
		if ( iRatio_max  >= iRatio_orig) {
		   a_iMaxWidth = a_iMaxHeight*iRatio_orig;
		   a_iMaxHeight = a_iMaxWidth/iRatio_orig;
		}
		else{
		   a_iMaxHeight = a_iMaxWidth/iRatio_orig;
		   a_iMaxWidth = a_iMaxHeight*iRatio_orig;
		}
    var aiNewSize = new Array();
		aiNewSize[iPOS_HEIGHT] = a_iMaxHeight;
		aiNewSize[iPOS_WIDTH] = a_iMaxWidth;
	}
	return aiNewSize;
}


function generer_page_detail_ann(a_sIdAnn){
  params = "toolbar=1,menubar=1,resizable=1,scrollbars=1,width=1100,height=900,left=10,top=10";
  var url = "do_generer_page_detail_ann.php?id="+a_sIdAnn;
  window.open(url,'_BLANK',params,false); 
  //appelAjax('POST', 'id='+encodeURIComponent(a_sIdAnn)  , "do_generer_page_detail_ann.php" ,true, updateDetailAnn );
}

