/*================================================================================
	Espaviote - IRIS WebTools -  12/01/2006 - IRIS Interactive - SM)
	--- Librairie des fonctions JS communes
================================================================================*/

// ********* Ouverture Popup **************************************
function MM_openBrWindow(theURL,winName,features,intAW,intAH)
	{ //v2.0
	winpopup = window.open(theURL,winName,features);
	//alert (winpopup.width + ' ' + winpopup.height);
	winpopup.moveTo(Math.round((screen.availWidth-intAW)/2),Math.round((screen.availHeight-intAH)/2));
	}
// ****************************************************************

// ********* Ouverture Popup détail produit ***********************	
function funcPopupPdt(varUrl)
	{
	WinPopUpPdt = window.open(varUrl, "PopUpPdt", "height=650, width=800, toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no");
	WinPopUpPdt.focus();
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	WinPopUpPdt.moveTo((ScreenW-800)/2, (ScreenH-650)/2);
	}
// *****************************************************************

// ********** Ajout d'un article dans le panier *********************	
function funcAddPanier(varPdtId, varPdtQte, varMultiple)
	{
	var intQte = 0;
	var strPdtLnk = '';
	var strPdtQte = '';
	if (varMultiple)
		for (i=0;i<eval('document.formCmde.pdtQte'+varPdtId).length;i++)
			{
			strPdtLnk = strPdtLnk + eval('document.formCmde.pdtQte'+varPdtId + '[i].id').substring(eval('document.formCmde.pdtQte'+varPdtId + '[i].id').indexOf('_')+1,eval('document.formCmde.pdtQte'+varPdtId + '[i].id').length) + ':';
			strPdtQte = strPdtQte + eval('document.formCmde.pdtQte'+varPdtId + '[i].value') + ':';
			intQte = intQte + parseInt(eval('document.formCmde.pdtQte'+varPdtId + '[i].value'));
//			alert('strPdtLnk : ' + strPdtLnk + ' - strPdtQte : ' + strPdtQte + ' - intQte : ' + intQte);
			}
	else
		intQte = parseInt(eval('document.formCmde.pdtQte'+varPdtId + '.value'));

	if (varMultiple)		
		{
		if (intQte != varPdtQte )
			{
			alert('ATTENTION : vous devez choisir ' + varPdtQte + ' produit(s).');
			return;
			}
/*		if (intQte % varPdtQte != 0)
			{
			alert('ATTENTION : vous devez choisir les produits par multiple de ' + varPdtQte + '.');
			return;
			}*/
		intQte = (intQte/varPdtQte);
		}
	else
		if (intQte < varPdtQte )
			{
			alert('ATTENTION : vous devez choisir au moins ' + varPdtQte + ' produit(s).');
			return;
			}
	
	var strUrl = '../_inc/CPN_funcAddPanier.asp?strPdtId=' + varPdtId + '&strPdtLnk=' + strPdtLnk + '&strPdtQte=' + strPdtQte + '&PdtQte=' + intQte;
	WinPopUpPanier = window.open(strUrl, "PopupPanier", "modal=1,Width=330px,Height=110px,toolbar=no,menubar=0,scrollbars=no,resizable=no,location=no,directories=no,status=1");
//	WinPopUpPanier = window.open(strUrl, "PopupPanier", "modal=1,Width=330px,Height=190px,toolbar=no,menubar=0,scrollbars=no,resizable=no,location=no,directories=no,status=1");
	}
// *******************************************************************


function funcPaiement()
{
	window.open('','winPaiement','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=680,height=580,top=150,left=150');
}

function funcCtlQte(varPdtId, varPdtQte, varPdtLnkId)
	{
	var intQte = 0;
	for (i=0;i<eval('document.formCmde.pdtQte'+varPdtId).length;i++)
		{
		intQte = intQte + parseInt(eval('document.formCmde.pdtQte'+varPdtId + '[i].value'));
		if (intQte % varPdtQte != 0 )
			{
			alert('ATTENTION : vous ne pouvez pas choisir plus de ' + varPdtQte + ' produits.');
//			eval('document.formCmde.pdtQte'+varPdtId + '[i].value=0');
			document.getElementById('pdtQteLnk' + varPdtId + '_' + varPdtLnkId).value=0;
			return;
			}
		}
	}

// *****************************************************************************************
// Ouverture Popup Image
// *****************************************************************************************
function funcPopupImg(varId,varFileField,varTab,varLabel)
	{
	var strHtmlCode =	"<html>"
						+"<body bgColor=#OOOOOO leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
						+"<div><img title='" + varLabel + "' src='../_inc/IMG_DbImgView.asp?strTable="+varTab+"&strSelectField="+varTab+"Id&strSelectValue="
						+ varId +"&strFileField=" + varFileField + "&blnAffiche=oui&strImgNoFile=../images/_charte/NoFile2.gif"
						+ "' onload='window.opener.funcPopupResizeToImg();'>"
						+ "<br>"
						+ "<div align='center'><font color='#FFFFFF' style='font-family:Verdana, sans-serif;font-size:11;'>" + varLabel + '&nbsp;&nbsp;<a href="#" onClick="window.print();">[imprimer l\'image]</a></font></div>'
						+ "</div>"
						+"</body></html>";
	
	WinPopUpImg = window.open ("", "PopUpImg", "toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
	WinPopUpImg.document.write(strHtmlCode);
	WinPopUpImg.document.close();
	WinPopUpImg.document.title= "Zoom image";
	WinPopUpImg.focus();
	}
// *****************************************************************************************	

// *****************************************************************************************
// Redimensionnement popup image
// *****************************************************************************************

function funcPopupResizeToImg()
	{
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var ImgW = WinPopUpImg.document.images[0].width;
	var ImgH = WinPopUpImg.document.images[0].height;
	WinPopUpImg.resizeTo(ImgW, ImgH+100);
	WinPopUpImg.moveTo((ScreenW-ImgW)/2, (ScreenH-ImgH)/2);
	}
// *****************************************************************************************

	


