
//======================================================================================
//Charge un menu déroulant des super famillen, familles et sous famille
function loadFamilleFiltre(path,idSupFam,idFam,idSsFam, idSsSsFam)
{
		var URIpath = path ;
		if (idSupFam!='') 
		{
			URIpath += "&Idsupfam=" + idSupFam;
		}		
		if (idFam!='') 
		{
			URIpath +="&idFam=" + idFam;
		}
		if (idSsFam!='')
		{
			URIpath +="&idSsFam=" + idSsFam;
		}	
		if (idSsSsFam!='') 
		{
			URIpath +="&idSsSsFam=" + idSsSsFam;
		}		
		document.location.href=URIpath;

}


//======================================================================================
function reload_tBody(path, idSupFam,idFam,idSsFam, idSsSsFam)
{
	var curTr = document.getElementById('td_famille');
 	var URIpath = curTr.getAttribute('src_noattr') ;

	if (idSupFam!='') 
	{
		URIpath += "&Idsupfam=" + idSupFam;
	}		
	if (idFam!='') 
	{
		URIpath +="&idFam=" + idFam;
	}
	if (idSsFam!='')
	{
		URIpath +="&idSsFam=" + idSsFam;
	}	
	if (idSsSsFam!='') 
	{
		URIpath +="&idSsSsFam=" + idSsSsFam;
	}		
	
	myXHR = new httpRequest(URIpath, '', 'POST');
	myXHR.LoadContent('td_famille','','');
}


//======================================================================================
function SHowProgressBar(title,percent)
{
	// on recupere nos element utile pour la progresse bar.
	// Il peu y avoir jusqu'a deux Iframe, alors al solution est simple
	// on se balade !
	DivProgressSpan=document.getElementById("ProgressBar");
	DivProgress = document.getElementById("progressSpan");
	TitleProgress = document.getElementById("TitleSpan");
	iFrameCur = document.getElementById("iFramBook");
	
	if (!DivProgressSpan)
	{
		DivProgressSpan = iFrameCur.contentDocument.getElementById("ProgressBar");
		DivProgress =iFrameCur.contentDocument.getElementById("progressSpan");
		TitleProgress = iFrameCur.contentDocument.getElementById("TitleSpan");
		
	
	}
	
	

	DivProgressSpan.style.visibility='visible';
	DivProgressSpan.style.height='35px';

	DivProgress.style.height='25px';
	DivProgress.style.width = percent + "%";
			
	TitleProgress.innerHTML = title
	
		
	


	
}


//======================================================================================
function AddProgressBar(idNodeContenant,idNodeAfter)
{
	
}

//======================================================================================
//Charge une carte procure à partir d'un formulaire ajax
//Add le 22/03/2007 par Christophe Bonvallet
majEanInXmlFile = function(ean, toUp, toSuppr, idFam, fileType)
{

	if (toUp == false) {toUp = 0} else {toUp = 1}
	if (toSuppr == false) {toSuppr = 0} else {toSuppr = 1}
	
	
	var MyXhr = new httpRequest(docRoot + '/ajax/ajax_BO_request.aspx', 'idControl=0&ean=' + ean +'&toUp=' + toUp + '&toSuppr=' + toSuppr + '&idFam=' + idFam + '&fileType=' + fileType, 'POST');

	MyXhr.createRequestObject();
	MyXhr.sendPostReq();

	MyXhr.xmlHttp.onreadystatechange = function() 
	{	
		if(MyXhr.xmlHttp.readyState == 4 ) 
		{
		
			if (MyXhr.xmlHttp.status == 200)
			{
				
					
			}
			else
			{
				alert('a' + MyXhr.responseText)
			}
		}	
	}
}


//======================================================================================
//Charge un menu déroulant des super famillen, familles et sous famille
function deleteNouveaute(ean)
{

		var URIpath = window.location.href + "&delete=true&ean=" + ean;
		if (confirm("Etes-vous certain de vouloir supprimer cette nouveauté ?"))
		{
			document.location.href=URIpath;
		}

}

//======================================================================================

//======================================================================================
//Charge un menu déroulant des super famille, familles et sous famille
function loadRayonComboBo(path,idSupFam,idFam,idSsFam,idSsSsFam, javascript)
{
	var URIpath = ''; 
	var spanID = '';
	
	// nos petit bout d'url
	var pathOf_superF		= path + "&SupfamID=" + idSupFam;
	var pathOf_Fam			= pathOf_superF + "&famID=" + idFam;
	var pathOf_sousFam		= pathOf_Fam + "&SousFamID=" + idSsFam;
	var pathOf_sousSousFam	= pathOf_sousFam + "&SousSousFamID=" + idSsSsFam;
	
	// les elements qui vont être ré initialisé		
	var objFam = document.getElementById('ComboFam');
	var objSousFam = document.getElementById('CombossFam');
	var objSousSousFam = document.getElementById('ComboSssousFam');
	
	
	if (objSousSousFam && idSsSsFam.length > 1)
	{
		//URIpath = pathOf_sousSousFam;
		//spanID = "ComboSssousFam";
		
		
	}
	else if (objSousFam && idSsFam.length > 1)
	{
		URIpath = pathOf_sousFam;
		spanID = "ComboSssousFam";
		
		objSousSousFam.innerHTML = "";
	}
	else if (objFam && idFam.length > 1)
	{
		URIpath = pathOf_Fam;
		spanID = "CombossFam";
		
		objSousSousFam.innerHTML = "";
		objSousFam.innerHTML = "";
	}
	else if (objFam && idSupFam.length > 1)
	{
		URIpath = pathOf_superF;
		spanID = "ComboFam";
		
		objSousSousFam.innerHTML = "";
		objSousFam.innerHTML = "";
		objFam.innerHTML = ""
	}
	
	
	
	
	if (javascript!= '')
	{
		URIpath += "&javascript=" + javascript;
	}
	

	if (document.getElementById && URIpath.length > 0)
	{
		SpanCartObj = document.getElementById(spanID);
		SpanCartObj.innerHTML="loading ..."	;
		LoadContent(URIpath,spanID,"Chargement des rayons...");
			
				
	}	
}



//======================================================================================
function lstSel_disabledCheckBox(lstRay)
{
	if (lstRay.value.length >= 5)
	{
		document.getElementById('CheckFam').disabled = false;
		document.getElementById('CheckSupFam').disabled = false;
		document.getElementById('CheckGenre').disabled = false;
	}
	else if (lstRay.value.length == 4)
	{
		document.getElementById('CheckFam').disabled = true; document.getElementById('CheckFam').checked = false;
		document.getElementById('CheckSupFam').disabled = false;
		document.getElementById('CheckGenre').disabled = false;
	}
	else if (lstRay.value.length == 3)
	{
		document.getElementById('CheckFam').disabled = true; document.getElementById('CheckFam').checked = false;
		document.getElementById('CheckSupFam').disabled = true; document.getElementById('CheckSupFam').checked = false;
		document.getElementById('CheckGenre').disabled = false;
	}
	else if (lstRay.id == '')
	{
		document.getElementById('CheckFam').disabled = true; document.getElementById('CheckFam').checked = false;
		document.getElementById('CheckSupFam').disabled = true; document.getElementById('CheckSupFam').checked = false;
		document.getElementById('CheckGenre').disabled = true; document.getElementById('CheckGenre').checked = false;
	}
	else if (lstRay.id == 'famID')
	{

		document.getElementById('CheckFam').disabled = true; document.getElementById('CheckFam').checked = false;
	}

}


//======================================================================================
function ShowHideUploader(show)
{

	if (document.getElementById)
	{
		if (show)
		{
			setOpacity(document.getElementById("content"), 30);
			SpanCartObj = document.getElementById("boxUpload");
			SpanCartObj.style.visibility='visible';
			SpanCartObj.style.top =  yMousePos + "px";
			SpanCartObj.style.left =xMousePos + "px";	
			fadeIn("boxUpload",50)		
		}
		else
		{
		
			// MAJ de Chris
			SpanCartObj = parent.document.getElementById("boxUpload");
			SpanCartObj.style.visibility='hidden';	
			setOpacity(parent.document.getElementById("content"), 100);
			SpanCartObj = parent.document.getElementById("boxContent");
			SpanCartObj.style.visibility='hidden';	   	
		}

	}
}


//======================================================================================
var canFadeIn = true;


//======================================================================================
function LoadMenu(uri,MenudivID)
{
	canFadeIn = true;
	var pathToSelect;

	if (document.getElementById)
	{	
		if(top){top.document.onclick = function () {CloseOpenedMenu();};}
		else{document.onclick = function () {CloseOpenedMenu();};}
		
		setOpacity(document.getElementById("content"), 30);

		SpanCartObj = document.getElementById("IfrmUpload");
		SpanCartObj.src=uri;
		document.getElementById("boxUpload").style.visibility='visible';
		fadeIn(MenudivID,0)
	}
}


//======================================================================================
function LoadMenu_inTop(uri,MenudivID)
{
	canFadeIn = true;
	var pathToSelect;

	if (document.getElementById)
	{	
		document.getElementById("content").onclick = function () {CloseOpenedMenu();document.getElementById("content").onclick = function(){}};
		
		setOpacity(document.getElementById("content"), 30);

		SpanCartObj = document.getElementById("IfrmUpload");
		SpanCartObj.src=uri;
		document.getElementById("boxUpload").style.visibility='visible';
		fadeIn(MenudivID,0)
	}
}


//======================================================================================
//Place le DIV qui vient d'être rechargé par httpRequest
function ReplacerDiv(divName)
{
	
	if (document.getElementById)
	{
		divObj = document.getElementById(divName);
		divObj.style.top = yMousePos - (getDivHeight(divObj)/2) + "px";
		divObj.style.left =(xMousePos - (getDivWidth(divObj)/2)) + "px";		
	}
	
}


//======================================================================================
function LoadCMSform(formURL,MenudivID)
{
	var pathToSelect;
	var timeClose = 0;
	
	if (document.getElementById)
	{
		
		setOpacity(document.getElementById("content"), 30);
		SpanCartObj = document.getElementById(MenudivID);
		SpanCartObj.innerHTML="";
		strFunction = "ReplacerDiv('" + MenudivID + "')"; 
		LoadContent(formURL,MenudivID,"Ajout au panier...",strFunction);

	}
}


//======================================================================================
function ShowWaitingDiv()
{

	fadeOut("Maincontent", 80);
	fadeIn("WaitingDiv", 80)
}


//======================================================================================
function CloseOpenedMenu()
{
	canFadeIn = false;

	if (document.getElementById)
	{
			SpanCartObj = document.getElementById("boxUpload");
			SpanCartObj.style.visibility='hidden';	
			setOpacity(document.getElementById("content"), 100);
			SpanCartObj = document.getElementById("boxContent");
			SpanCartObj.style.visibility='hidden';				
			
			
			top.document.addEventListener("click", function () {}, false);
	}	
}


//======================================================================================
function showThisPageInIFRAME(url_toShow, widthOfFrame, heightOfFrame)
{
		setOpacity(document.getElementById("myContent"), 10);
		
		var tempNode = document.createElement("iFrame");
		var divNode = document.createElement("div");
		var curId_ofIframe = document.createAttribute("id");
		var curId_ofDiv = document.createAttribute("id");
		var curHeight_ofIframe = document.createAttribute("height");
		var curSRC_ofIframe = document.createAttribute("src");
		
		curId_ofIframe.value = "preVisu_IFRAME";
		curHeight_ofIframe.value = heightOfFrame;
		curSRC_ofIframe.value = url_toShow;
		curId_ofDiv.value = "preVisu_DIV";
		
		tempNode.setAttributeNode(curId_ofIframe);
		tempNode.setAttributeNode(curHeight_ofIframe);
		tempNode.setAttributeNode(curSRC_ofIframe);
		
		divNode.setAttributeNode(curId_ofDiv);
		divNode.innerHTML = "<a href='javascript:closeMenu();'>(X) Fermer l'apercu</a>"
		
		document.getElementById("curBody").appendChild(tempNode);
		document.getElementById("curBody").appendChild(divNode);
		
		
		
		
		document.onclick = function() 	{closeMenu()}
}


//======================================================================================
function closeMenu()
{
			document.onclick = function (){};
			setOpacity(document.getElementById("myContent"), 100);
			document.getElementById("curBody").removeChild(document.getElementById("preVisu_IFRAME"));
			document.getElementById("curBody").removeChild(document.getElementById("preVisu_DIV"));
}


//======================================================================================
function bo_selecContent(typeContent, idNewsContent, forThisId_inContent)
{


		
	if (typeContent == 1)
	{curObj_rdb = document.getElementById("rdbChoice_dossier");}
	else if (typeContent == 2)
	{curObj_rdb = document.getElementById("rdbChoice_selection");}
	else if (typeContent == 3)
	{curObj_rdb = document.getElementById("rdbChoice_push");}
	else if (typeContent == 4)
	{curObj_rdb = document.getElementById("rdbChoice_edito");}
	else if (typeContent == 5)
	{curObj_rdb = document.getElementById("rdbChoice_SsSsFam");}
	else if (typeContent == 6 && forThisId_inContent > 0)
	{curObj_rdb = document.getElementById("rdbChoice_oneEvent");}
	else if (typeContent == 6)
	{curObj_rdb = document.getElementById("rdbChoice_agenda");}
	else if (typeContent == 8)
	{curObj_rdb = document.getElementById("rdbChoice_autoPromo")}
	else if (typeContent == 9)
	{curObj_rdb = document.getElementById("rdbChoice_complement");}
	

	curObj_rdb.checked = true;
	
	var waitMsg = 'Chargement de la page en cours...<br>Veuillez patienter';
	var moreAction = '';
	
	if(curObj_rdb.getAttribute("message"))
	{waitMsg= curObj_rdb.getAttribute("message")};
	
	if(curObj_rdb.getAttribute("moreaction"))
	{moreAction = curObj_rdb.getAttribute("moreaction");};
		
	if(curObj_rdb.getAttribute("target"))
	{XHRTarget=curObj_rdb.getAttribute("target")}
	else
	{XHRTarget="content"}

	
	myXHR = new httpRequest(curObj_rdb.getAttribute("src") + '&idContent=' + forThisId_inContent, '','POST');
	myXHR.LoadContent(XHRTarget,waitMsg,moreAction);
}

//======================================================================================	
//Valide le paiement d'une commande, puis ferme la popup ajax
function Valide_this_commande(cmd_id,page,sel_statut,sel_etat,txt_nom,txt_numero,date_deb_day,date_deb_month,date_deb_year,date_fin_day,date_fin_month,date_fin_year)
{
	var MyXhr = new httpRequest(docRoot + '/admin/cheques/modif.aspx', 'sub=validate_commande&cmd_id=' + cmd_id, 'POST');
				
	MyXhr.createRequestObject();
	MyXhr.sendPostReq();
	
	MyXhr.xmlHttp.onreadystatechange = function() 
	{	
		if(MyXhr.xmlHttp.readyState == 4 ) 
		{
		
			if (MyXhr.xmlHttp.status == 200)
			{
				close_pseudoPopUp();
				window.location.replace("/admin/cheques/index.aspx" + '?page=' + page + '&sel_statut=' + sel_statut + '&sel_etat=' + sel_etat + '&txt_nom=' + txt_nom + '&txt_numero=' + txt_numero + '&date_deb_day=' + date_deb_day + '&date_deb_month=' + date_deb_month + '&date_deb_year=' + date_deb_year + '&date_fin_day=' + date_fin_day + '&date_fin_month=' + date_fin_month + '&date_fin_year=' + date_fin_year);
			}
		}	
	}
}


//======================================================================================	
//Coche ou décoche une commande pour la relance
function Valide_check_cmdRelance(ischeck,cmd_id)
{
	var ajaxSub = '';
	if(ischeck==true)
	{
		ajaxSub='coche_cmd';
	}else{
		ajaxSub='decoche_cmd';
	}
	
	var MyXhrRelance = new httpRequest(docRoot + '/admin/cheques/ajax.aspx', 'ajax=' + ajaxSub + '&id_cmd=' + cmd_id, 'POST');
				
	MyXhrRelance.createRequestObject();
	MyXhrRelance.sendPostReq();
	
	MyXhrRelance.xmlHttp.onreadystatechange = function() 
	{	
		if(MyXhrRelance.xmlHttp.readyState == 4 )
		{
			if (MyXhrRelance.xmlHttp.status == 200)
			{
			}
		}	
	}
}

//======================================================================================	
//Lance les relances
function Send_Relance(page,sel_statut,sel_etat,txt_nom,txt_numero,date_deb_day,date_deb_month,date_deb_year,date_fin_day,date_fin_month,date_fin_year)
{
	document.getElementById('etat-envoi').innerHTML = '<img src="/i/loading.gif" style="border:none;margin-left:25px;margin-right:5px;"/> Relance en cours...';
	
	var MyXhrRelance = new httpRequest(docRoot + '/admin/cheques/ajax.aspx', 'ajax=sendRelance&id_cmd=0', 'POST');
				
	MyXhrRelance.createRequestObject();
	MyXhrRelance.sendPostReq();
	
	MyXhrRelance.xmlHttp.onreadystatechange = function() 
	{	
		if(MyXhrRelance.xmlHttp.readyState == 4 )
		{
			 
				if (MyXhrRelance.xmlHttp.responseText == "1")
				{
					document.getElementById('etat-envoi').innerHTML = '<img src="/i/back/upload_16.png" style="border:none;margin-left:25px;"/><a href="javascript:Send_Relance();">[envoyer une relance]</a>';
					window.location.replace("/admin/cheques/index.aspx" + '?page=' + page + '&sel_statut=' + sel_statut + '&sel_etat=' + sel_etat + '&txt_nom=' + txt_nom + '&txt_numero=' + txt_numero + '&date_deb_day=' + date_deb_day + '&date_deb_month=' + date_deb_month + '&date_deb_year=' + date_deb_year + '&date_fin_day=' + date_fin_day + '&date_fin_month=' + date_fin_month + '&date_fin_year=' + date_fin_year);
					alert('Les relances ont bien \351t\351 envoy\351es.');
				}else{
					document.getElementById('etat-envoi').innerHTML = '<img src="/i/back/upload_16.png" style="border:none;margin-left:25px;"/><a href="javascript:Send_Relance();">[envoyer une relance]</a>';
					alert('Veuillez s\351lectionner au minimum une commande.');
				}
 
		}	
	}
}


//======================================================================================	
//Annule une commande
function annul_cmd(cmd_id,page,sel_statut,sel_etat,txt_nom,txt_numero,date_deb_day,date_deb_month,date_deb_year,date_fin_day,date_fin_month,date_fin_year)
{
	if (window.confirm('\312tes-vous certain de vouloir annuler la commande ' + cmd_id + ' ?'))
	{
		var MyXhrRelance = new httpRequest(docRoot + '/admin/cheques/ajax.aspx', 'ajax=annul_cmd&id_cmd=' + cmd_id, 'POST');
					
		MyXhrRelance.createRequestObject();
		MyXhrRelance.sendPostReq();
		
		MyXhrRelance.xmlHttp.onreadystatechange = function() 
		{	
			if(MyXhrRelance.xmlHttp.readyState == 4 )
			{
				if (MyXhrRelance.xmlHttp.status == 200)
				{
					window.location.replace("/admin/cheques/index.aspx" + '?page=' + page + '&sel_statut=' + sel_statut + '&sel_etat=' + sel_etat + '&txt_nom=' + txt_nom + '&txt_numero=' + txt_numero + '&date_deb_day=' + date_deb_day + '&date_deb_month=' + date_deb_month + '&date_deb_year=' + date_deb_year + '&date_fin_day=' + date_fin_day + '&date_fin_month=' + date_fin_month + '&date_fin_year=' + date_fin_year);
					alert('La commande ' + cmd_id + ' a bien \351t\351 annul\351e.');
				}
			}	
		}		
	}
}


//======================================================================================
// Tristan - 21/09/2011 
// BO Partenaires Nouveautés / Meilleurres Ventes 
// Si on coche la case "Up" alors que la case "Suppr" est cochée, 
// alors on décoche la case "Suppr" 
function checkUp_partnerNouvMv(isChecked, idSuppr) 
{
	//alert("checkUp_partnerNouvMv...\n isChecked="+isChecked+"\n idSuppr="+idSuppr);
	if (document.getElementById(idSuppr))
	{
		if (isChecked && document.getElementById(idSuppr).checked) 
		{
			//alert('on décoche la case "Suppr"');
			document.getElementById(idSuppr).checked = false;
		}
	}
}

//======================================================================================
// Tristan - 21/09/2011 
// BO Partenaires Nouveautés / Meilleurres Ventes 
// Si on coche la case "Suppr" alors que la case "Up" est cochée, 
// alors on décoche la case "Up" 
function checkSuppr_partnerNouvMv(isChecked, idUp) 
{
	//alert("checkSuppr_partnerNouvMv...\n isChecked="+isChecked+"\n idUp="+idUp);
	if (document.getElementById(idUp))
	{
		if (isChecked && document.getElementById(idUp).checked) 
		{
			//alert('on décoche la case "Up"');
			document.getElementById(idUp).checked = false;
		}
	}
}

