/*##############################################################################################
############ JS DES FONCTIONS DE GESTION D'AFFICHAGE DE LA PAGE DE CONNEXION AU MAGASIN #########
/*############################################################################################## */
// Variable GLOBALE
var DocRef;
var AfficheFiltre = false;
var X_navigateur = navigator.appName.toLowerCase();
var X_Platform = navigator.platform.toLowerCase();
var X_version = navigator.appVersion.toLowerCase();
var DocParent;
// Version de Internet Explorer
if (X_navigateur == 'microsoft internet explorer') {
	X_version_deb = X_version.indexOf('(') + 1;
	X_version_fin = X_version.indexOf(')');
	X_version = X_version.substring(X_version_deb, X_version_fin);
	XtabTmp = X_version.split(';');
	for (i in XtabTmp) {
		if (XtabTmp[i].indexOf('msie') > - 1) {
			X_version = parseInt(XtabTmp[i].replace('msie', ''));
			break;
		}
	}
}
/** #########################################
* Permet de cacher les elements suivant lorsqu'un calque filter est ouvert
*/
function hideElement() {
	var playerVideoObj = getElement("player-video", true, "")
	if (playerVideoObj) {
		playerVideoObj.style.visibility = "hidden";
	}
	var flash = null;
	var flashs = document.getElementsByTagName('embed');
	if (flashs.length == 0) flashs = document.getElementsByTagName('object');
	for (var i = 0; i < flashs.length; i++) {
		if (flashs[i].id = 'body-flash-hp') flash = flashs[i];
	}
	if (document.getElementById('div-main-3d')) {
		document.getElementById('div-main-3d').style.display = 'none';
		if (document.getElementById('div-main-picture')) {
			document.getElementById('div-main-picture').style.display = 'block';
		}
	}
	var listeFamille = document.getElementById('liste-familles');
	if (listeFamille) listeFamille.style.display = 'none';
	var noflash = document.getElementById('noflash');
	if (flash) {
		flash.style.display = 'none';
		if (noflash) noflash.style.display = 'block';
	}
}
/** #########################################
* Permet d'afficher les elements suivant lorsqu'un calque filter est ferme
*/
function displayElement() {
	var flash = null;
	var flashs = document.getElementsByTagName('embed');
	if (! flashs) {
		flashs = parent.document.getElementsByTagName('embed');
	}
	if (! flashs) {
		flashs = parent.parent.document.getElementsByTagName('embed');
	}
	if (flashs.length == 0) {
		flashs = document.getElementsByTagName('object');
		if (! flashs) {
			flashs = parent.document.getElementsByTagName('object');
		}
		if (! flashs) {
			flashs = parent.parent.document.getElementsByTagName('object');
		}
	}
	for (var i = 0; i < flashs.length; i++) {
		if (flashs[i].id = 'body-flash-hp') flash = flashs[i];
	}
	var listeFamille = getElement('liste-familles', false, "");
	if (listeFamille) listeFamille.style.display = 'block';
	var noflash = document.getElementById('noflash');
	if (! noflash) noflash = parent.document.getElementById('noflash');
	if (flash) {
		flash.style.display = 'block';
		if (noflash) noflash.style.display = 'none';
	}
	var playerVideoObj = getElement("player-video", false, "")
	if (playerVideoObj) {
		playerVideoObj.style.visibility = "visible";
	}
	if (document.getElementById('div-main-3d')) {
		document.getElementById('div-main-3d').style.display = 'block';
		if (document.getElementById('div-main-picture')) {
			document.getElementById('div-main-picture').style.display = 'none';
		}
	}
}
/** #########################################
* Permet d'ouvrir une popup filter
*/
function displayPopupFilter(idObj, idObjContainer, urlContent, width, height, iframeName, dofilter, doScroll, isImage) {
	if (dofilter == null || dofilter) {
		show_filter(idObj);
	}

	if (idObjContainer) {
		getElement(idObjContainer, true, "").innerHTML = "";
		var position = urlContent.indexOf("?urlphoto=/products-pictures/", 0);
		var path = urlContent.substr(position+29,urlContent.length-position-29);
		//urlContent = "/products-pictures/h1-"+path;
		show_popup("calque", urlContent, width, height, iframeName, idObjContainer, doScroll, isImage);
	}
	hideElement();
}
/** #########################################
* Permet d'ouvrir une popup filter video
*/
function displayPopupFilterVideo(_objFilter, _divId, _divVideoId, _idVideo, _titreVideo, _urlVideo, _descVideo, _flashPlayerPath, _width, _height, _isAutostart, _doFilter) {
	if (_doFilter == null || _doFilter) {
		show_filter(_objFilter);
	}
	if (_divId) {
		showPopupVideo("calque", _divId, _divVideoId, _idVideo, _titreVideo, _urlVideo, _descVideo, _flashPlayerPath, _width, _height, _isAutostart);
	}
}
/** #########################################
* Permet d'ouvrir une popup filter contenant la liste des familles d'un sous-rayon
*/
function displayPopupFamilleFilter(idObjFilter, idObjContainer, width, height) {
	show_filter(idObjFilter);
	show_popup(idObjContainer, "", width, height, "", "");
}
/** #########################################
* Permet de fermer la popup filter
*/
function hidePopupFamilleFilter(idObjFilter, idObjContainer) {
	hide_filter(idObjFilter);
	hide_filter(idObjContainer);
}
/** #########################################
* Permet de fermer une popup filter pour le produit
*/
function hidePopup() {
	var heightcalquedefault = "577px";
	var widthcalquedefault = "560px";
	var calquecontainer = document.getElementById("calquecontainer");
	if (! calquecontainer) calquecontainer = parent.document.getElementById("calquecontainer");
	var calquecontainervideo = document.getElementById("calqueContainerVideo");
	//on retire tout le contenu de calquecontainer avant
	if (calquecontainer) {
		$j(calquecontainer).html("");
	}
	//on cache le calque video
	if (calquecontainervideo) {
		$j(calquecontainervideo).hide();
	}
	var calque = document.getElementById("calque");
	if (! calque) calque = parent.document.getElementById("calque");
	if (calque && calquecontainer) {
		hide_all(calque.id);
		if (heightcalquedefault) {
			calque.style.height = heightcalquedefault;
		}
		if (widthcalquedefault) {
			calque.style.width = widthcalquedefault;
		}
	}
	displayElement();
	if (getElement('div-main-3d', true, "")) {
		getElement('div-main-3d', true, "").style.display = 'block';
		if (getElement('div-main-picture', true, "")) {
			getElement('div-main-picture', true, "").style.display = 'none';
		}
	}
}
/* pour la video produit */
function hidePopupVideo() {
	var heightcalquedefault = "577px";
	var widthcalquedefault = "560px";
	var calquecontainer = document.getElementById("calquecontainer");
	if (! calquecontainer) calquecontainer = parent.document.getElementById("calquecontainer");
	var calque = document.getElementById("calque");
	if (! calque) calque = parent.document.getElementById("calque");
	if (calque && calquecontainer) {
		hide_all(calque.id);
		if (heightcalquedefault) {
			calque.style.height = heightcalquedefault;
		}
		if (widthcalquedefault) {
			calque.style.width = widthcalquedefault;
		}
	}
	displayElement();
	var blockVideoProduit = getElement("blocVideo", true, "");
	if (blockVideoProduit) {
		blockVideoProduit.style.display = "none";
	}
}
/*############################################################################################## */
// Document en cours
function MonDocument() {
	if (DocRef == null) {
		if (parent.document.documentElement && parent.document.documentElement.clientWidth) {
			DocRef = parent.document.documentElement;
		} else {
			DocRef = document.body;
		}
	}
}
/*############################################################################################## */
function MonParent() {
	if (parent) {
		// It is an iframe and there is a parent window
		if (parent.document.documentElement && parent.document.documentElement.clientHeight) {
			return parent.document.documentElement;
		} else {
			return parent.document.body;
		}
	} else {
		if (! DocRef) {
			MonDocument();
		}
		return DocRef;
	}
}
/*############################################################################################## */
// Action de resize sur le filter
function gestion_filtre(objName) {
	var X_block = document.getElementById(objName);
}
/*############################################################################################## */
// Affiche le filtre d'opacite
function show_filter(objName) {
	var filtre = document.getElementById(objName);
	if (! filtre) {
		filtre = parent.document.getElementById(objName);
	}
	if (! filtre) {
		filtre = parent.parent.document.getElementById(objName);
	}
	if (filtre) {
		filtre.style.display = 'block';
		if (! DocRef) {
			MonDocument();
		}
		/*var X_largeur = parseInt(DocRef.clientWidth) + parseInt(DocRef.scrollLeft);
		var X_hauteur = parseInt(DocRef.clientHeight) + parseInt(DocRef.scrollTop);*/
		var X_largeur = DocRef.scrollWidth;
		var X_hauteur = DocRef.scrollHeight;
		filtre.style.width = X_largeur + 'px';
		filtre.style.height = X_hauteur + 'px';
		filtre.style.marginTop = '0';
		//Change opacite
		changeOpac(70, objName);
	}
}
/*############################################################################################## */
//Change opacite
function changeOpac(opacity, id) {
	var object = parent.document.getElementById(id);
	if (! object) {
		return false;
	}
	object = object.style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}
/*############################################################################################## */
//Desactivation de l'opacite
function hideOpac(id) {
	var object = parent.document.getElementById(id);
	if (! object) {
		return false;
	}
	object = object.style;
	object.opacity = "";
	object.MozOpacity = "";
	object.KhtmlOpacity = "";
	object.filter = "";
}
/*############################################################################################## */
// Cache le filtre d'opacite
function hide_filter(objName) {
	var X_block = parent.document.getElementById(objName);
	if (! X_block) {
		X_block = parent.parent.document.getElementById(objName);
	}
	if (! X_block) {
		X_block = document.getElementById(objName);
	}
	if (X_block) {
		//hideOpac(objName);
		X_block.style.display = "none";
	}
}
/*############################################################################################## */
// Affiche la popup/Iframe
function show_popup(objName, urlContent, width, height, iframeName, idCalqueContainer, doScroll, isImage) {
	var X_block = parent.document.getElementById(objName);
	if (! X_block) {
		X_block = parent.parent.document.getElementById(objName);
	}
	if (! X_block) {
		X_block = document.getElementById(objName);
	}
	if (X_block) {
		X_block.style.visibility = 'hidden';
		X_block.style.display = 'block';
		PositionPopup(objName, width, height);
		X_block.style.visibility = 'visible';
		if (width != "") {
			X_block.style.width = width + "px";
		}
		if (height != "") {
			X_block.style.height = height + "px";
		}
		var scroll = true;
		if (typeof doScroll != "undefined") {
			scroll = doScroll;
		}
		
		if (iframeName && iframeName != '') {
			var calqueContainerObj = getElement(idCalqueContainer, true, "");
			if (calqueContainerObj) {
				if (iframeName == 'iframe-sondage') {
					calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup();""><img src="/FR/images/static/1101-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div>' +
					'<iframe id="' + iframeName + '" scrolling="' + scroll + '" frameborder="0" marginheight="0" marginwidth="0" src="' + urlContent + '" width="' +(width) + '" height="' + height + '"></iframe>';
				} 
				else if (iframeName == 'iframehd') {
					calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup();""><img src="/FR/images/static/1101-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div>' +'<iframe id="' + iframeName + '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="' + urlContent + '" width="800" height="800"></iframe>';
				} 
				else {
					calqueContainerObj.innerHTML = '<iframe id="' + iframeName + '" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="' + urlContent + '" width="' + width + '" height="' + height + '">';
				}
				X_block.style.display = "block";
			}
		} 
		else {
			var isLoadImage = false ;
			if(typeof isImage != "undefined" && isImage){
				isLoadImage = true ;
			}
			
			if(!isLoadImage){
				var calqueContainerObj = getElement(idCalqueContainer, true, "");
				if (calqueContainerObj) {
					loadContentPage(urlContent, calqueContainerObj);
				}
			}
			else{
				var jQElt = getElt("#"+idCalqueContainer) ;
				var currentMainPicture = getElt("#imgmain-picture") ;
				var currentMainPictureSrc = currentMainPicture.attr("src")
	
				if(jQElt){
					var currentMainPictureSrcHd = currentMainPictureSrc.replace("asset_", "h1-asset_") ;
					
					var blocImageZoom = '<div class="fullzoom" style="background:url('+currentMainPictureSrcHd+') no-repeat top left"><a class="close" href="javascript:hidePopup();"><img src="/FR/images/static/1101-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div>'
					jQElt.html(blocImageZoom) ;
					
					//on va repositionner le calque
					var calqueObj = getElement("calque") ;
					if(calqueObj){
						calqueObj.style.top = "20px" ;
					}
				}
			}
		}
	} else {
		return false;
	}
}
// Affiche la popup/Iframe
function showPopupVideo(_objCalque, _divId, _divVideoId, _idVideo, _titreVideo, _urlVideo, _descVideo, _flashPlayerPath, _width, _height, _isAutostart) {
	var X_block = parent.document.getElementById(_divId);
	if (! X_block) {
		X_block = parent.parent.document.getElementById(_divId);
	}
	if (! X_block) {
		X_block = getElement(_divId);
	}
	if (X_block) {
		X_block.style.visibility = 'hidden';
		X_block.style.display = 'block';
		PositionPopup(_objCalque, _width, _height);
		X_block.style.visibility = 'visible';
		if (_width != "") {
			X_block.style.width = _width + "px";
		}
		//Faire cette fonction en dynamique
		chargeVideo(_divVideoId, _idVideo, _titreVideo, _urlVideo, _descVideo, _flashPlayerPath, _width, _height, _isAutostart);
		//on affiche le bloc objName
		displayBlocId(_objCalque);
	}
}
/*############################################################################################## */
// Cache le Filtre et popup/iframe
function hide_all(TsPopup) {
	hide_popup(TsPopup);
	//on va verifier que la fiche produit n'est plus affiche
	var objCalqueProduit = parent.document.getElementById("calqueproduit");
	if (! objCalqueProduit) {
		objCalqueProduit = parent.parent.document.getElementById("calqueproduit");
	}
	if (! objCalqueProduit) {
		objCalqueProduit = document.getElementById("calqueproduit");
	}
	if (! objCalqueProduit || (objCalqueProduit && objCalqueProduit.style.display == "none")) {
		hide_filter('filtre');
	}
}
/*############################################################################################## */
// Cache la popup/Iframe
function hide_popup(objName) {
	var X_block = parent.document.getElementById(objName);
	if (! X_block) {
		X_block = parent.parent.document.getElementById(objName);
	}
	if (! X_block) {
		X_block = document.getElementById(objName);
	}
	if (X_block) {
		X_block.style.display = 'none';
	} else {
		return false;
	}
}
/*############################################################################################## */
// Calcule la position de la popup/iframe
function PositionPopup(X_obj, width, height) {
	var X_block = parent.document.getElementById(X_obj);
	if (! X_block) {
		X_block = parent.parent.document.getElementById(X_obj);
	}
	if (! X_block) {
		X_block = document.getElementById(X_obj);
	}
	var heightBloc = X_block.offsetHeight;
	if (height && height != '') {
		heightBloc = parseInt(height) + 2;
	}
	var widthBloc = X_block.offsetWidth;
	if (width && width != '') {
		widthBloc = parseInt(width) + 2;
	}
	if (! X_block) {
		return false;
	}
	if (! DocRef) {
		MonDocument();
	}
	var X_blockTop = (parseInt(DocRef.clientHeight) - parseInt(heightBloc)) /2;
	X_block.style.top = parseInt(DocRef.scrollTop) + parseInt(X_blockTop) + 'px';
	var X_blockLeft = (parseInt(DocRef.clientWidth) - parseInt(widthBloc)) / 2;
	var leftPosition = parseInt(DocRef.scrollLeft) + parseInt(X_blockLeft);
	X_block.style.left = parseInt(leftPosition) + 'px';
}
/*############################################################################################## */
// Affiche ou Cache les SELECT de la page
function gestion_select(X_option) {
	var X_balises = document.getElementsByTagName('select');
	for (i = 0; i < X_balises.length; i++) {
		X_balises[i].style.visibility = X_option;
	}
	if (window.frames[ 'basketContent']) {
		var X_balisesFrame = window.frames[ 'basketContent'].document.getElementsByTagName('select');
		for (i = 0; i < X_balisesFrame.length; i++) {
			X_balisesFrame[i].style.visibility = X_option;
		}
	}
	// Cela cache egalement les select de la popup recherche.
	// Il faut donc reafficher ces select
	if (document.getElementById("popuprecherche")) {
		X_balises = document.getElementById("popuprecherche").getElementsByTagName('select');
		for (i = 0; i < X_balises.length; i++) {
			X_balises[i].style.visibility = 'visible';
		}
	}
	if (document.getElementById("localprice-resa")) {
		X_balises = document.getElementById("localprice-resa").getElementsByTagName('select');
		for (i = 0; i < X_balises.length; i++) {
			X_balises[i].style.visibility = 'visible';
		}
	}
}
/*############################################################################################## */
// Gestion du filtre au onresize et onscroll
window.onscroll = window.onresize = function () {
	gestion_filtre();
}
/*############################################################################################## */
// Affiche ou Cache le bloc reconnaitre du formulaire de connexion magasin en fonction de la case cochee ou non
function gestion_checkbox() {
	if (isCheck('checkb')) {
		showBloc('reconnaitre');
		window.parent.document.getElementById('filter_frame').style.height = 475;
		changeHeight('contenuquestion', 180);
		checkOrUncheck('checkb', true);
	} else {
		checkOrUncheck('checkb', false);
		hideBloc('reconnaitre');
	}
}
/*############################################################################################## */
var _blocContainer = null;
var POST_LOAD_CONTENT_PAGE_FUNC = function postILoadContentPage(xmlHttp, httpstatus) {
	if (httpstatus == 200) {
		var oXmlDoc = xmlHttp.responseText;
		_blocContainer.innerHTML = oXmlDoc;
		_blocContainer.style.display = "block";
	} else {
	}
}
// Charge le contenu dans la popup
function loadContentPage(urlContent, blocContainer) {
	_blocContainer = blocContainer;
	var ajaxProc = new IAjaxProcess(urlContent, POST_LOAD_CONTENT_PAGE_FUNC);
	ajaxProc.run();
}

