﻿// variables globales -------------------
//var urlconcepteur="http://ddprod-serveur/minigao/widget/";
var urlconcepteur="http://www.minigao.com/widget/";
// --------------------------------------

// normé ----------------------
function ouvrirPopup(pUrl){
	mediaWindow=window.open(pUrl,"","top=0,left=0,toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width=660,height=500");
}

function ouvrirPopupTaille(pUrl,largeur,hauteur){
	mediaWindow=window.open(pUrl,"","top=0,left=0,toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=no,width="+largeur+",height="+hauteur);
}

function confirmer(url, mess) {
	var rep=confirm(mess);
	if (rep) {
		window.location.href=url;
	}
}

function changerImage(pImage,pSource) {
	if (document.getElementById)
		document.getElementById(pImage).src=pSource;
}

function selectionnerAide() {
	$('#aide').removeClass("aide");
	$('#aide').addClass("aide_on");
}
function deselectionnerAide() {
	$('#aide').removeClass("aide_on");
	$('#aide').addClass("aide");
}

function majExplication(pIndice) {
	$('.divexplic').hide();
	$('.divmarge').hide();
	$('#divexplic'+pIndice).show();
	$('#divmarge'+pIndice).show();
	$('#divmarge'+pIndice).css("height",60-document.getElementById('divexplic'+pIndice).offsetHeight);
}

// affichage des div box
function afficherBox(pLargeur, pHauteur, pTitre, pLibelle, pAjax, pCode, pValeur, pAnnuler, pEnregistrer, pCallback) {
	var lecontenu='';
	lecontenu +=pLibelle;
	lecontenu +='<input name="valeur" type="text" id="valeur" value="'+pValeur+'" size="15" maxlength="20"><br>';
	lecontenu +='<div class="boutondiv" style="float:left"><span class="bouton_gauche"></span><input name="btnannuler" type="reset" id="btnannuler" value="'+pAnnuler+'" class="bouton_legende" style="width:120px" /><span class="bouton_droite"></span></div>';
	lecontenu +='<div class="boutondiv" style="float:right"><span class="bouton_gauche"></span><input name="btnenregistrer" type="submit" id="btnenregistrer" value="'+pEnregistrer+'" class="bouton_legende" style="width:120px" /><span class="bouton_droite"></span></div>';
		
	var lehtml=mefBox(pTitre,lecontenu,pLargeur,pHauteur);
	$('#divvide').html(lehtml);
//	alert(lehtml);
	centrerBox(pLargeur,pHauteur);
	$("#valeur").focus();
	$("#btnannuler").click(function() {
		$('#divvide').html('');
	}); 
	$("#btnenregistrer").click(function() {
		if (pAjax!='') {
			$.post(pAjax, {code:pCode, valeur:$('#valeur').val()}, function() {
				// lancer la fonction de callback si elle existe
				if (pCallback) {
					pCallback(data);
					$('#divvide').html('');
				} else
					$('#divvide').html('');
			});
		} else {
			// lancer la fonction de callback si elle existe
			if (pCallback) {
				pCallback($('#valeur').val());
				$('#divvide').html('');
			} else
				$('#divvide').html('');
		}
	});
}
function mefBox(pTitre, pContenu, pLargeur, pHauteur) {
	var lehtml;
	lehtml = '<div id="divbox">';
	lehtml +='<div id="h"><div id="hg"></div><div id="hm" style="width : '+pLargeur+'px;"></div><div id="hd"></div></div>';
	lehtml +='<div id="m"><div id="mg" style="height: '+pHauteur+'px;"></div><div id="mm" style="height: '+(pHauteur-30)+'px ;width: '+(pLargeur-28)+'px;">';
	lehtml +='<span class="box_titre">'+pTitre+'</span>';
	lehtml +=pContenu;
	lehtml +='</div><div id="md" style="height: '+pHauteur+'px;"></div></div>';
	lehtml +='<div id="b"><div id="bg"> </div><div id="bm" style="width: '+pLargeur+'px;"> </div><div id="bd"> </div></div>';
	lehtml +='</div>'; 
	return lehtml;
}
function getBrowserSize () {
	var bodyWidth = document.documentElement.clientWidth;
	var bodyHeight = document.documentElement.clientHeight;
	
	var bodyWidth, bodyHeight; 
	if (self.innerHeight){ // all except Explorer 
	 
	   bodyWidth = self.innerWidth; 
	   bodyHeight = self.innerHeight; 
	}  else if (document.documentElement && document.documentElement.clientHeight) {
	   // Explorer 6 Strict Mode 		 
	   bodyWidth = document.documentElement.clientWidth; 
	   bodyHeight = document.documentElement.clientHeight; 
	} else if (document.body) {// other Explorers 		 
	   bodyWidth = document.body.clientWidth; 
	   bodyHeight = document.body.clientHeight; 
	} 
	return [bodyWidth,bodyHeight];		
}
function centrerBox(plargeur, pHauteur) {
	var topOffset = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	var brSize = getBrowserSize();
	var bodyWidth = brSize[0];
	var bodyHeight = brSize[1];
	$('#divvide').css("left", Math.ceil((bodyWidth - plargeur) / 2) + 'px');
	$('#divvide').css("top", (Math.ceil((bodyHeight - pHauteur) / 2) +  topOffset) + 'px'); 
}
	
function ouvrirConcepteurGao(pGao) {
	var minigao_concepteur=urlconcepteur+'concepteur.aspx?gaoCode='+pGao;
	window.open(minigao_concepteur,"","top=0,left=0,toolbar=no,directories=no,menubar=no,scrollbars=no,resizable=no,width=640,height=570");	
}
function ouvrirConcepteurGaoNom(pGao,pNom) {
	var minigao_concepteur=urlconcepteur+'concepteur.aspx?gaoCode='+pGao+'&nom='+pNom;
	window.open(minigao_concepteur,"","top=0,left=0,toolbar=no,directories=no,menubar=no,scrollbars=no,resizable=no,width=640,height=570");	
}

function atteindreFlash(pNom) {
	var ret;
	if (document.embeds[pNom]==undefined)
		ret=document.getElementById(pNom);
	else
		ret=document.embeds[pNom];
	return ret;
}

function majCredits(pSolde) {
	$('#solde').html(pSolde);
}

function remplacer(pValeur, pRemplacement) {
	return pValeur.replace("@1",pRemplacement);
}

