if( typeof( gestionFilleuls ) != 'undefined' ){
	var extended = gestionFilleuls;
}else if( typeof( modifTailles ) != 'undefined' ){
	var extended = modifTailles;
}else if( typeof( gestionCoupons ) != 'undefined' ){
	var extended = gestionCoupons;
}else if( typeof( gestionTailles ) != 'undefined' ){
	var extended = gestionTailles;
}else if( typeof( _DetailController ) != 'undefined' )
	var extended = _DetailController;
else
	var extended = _AjaxElements;

var launcher = Class.create( extended , {
	
	initialize:function($super){
		this.shopid = null;
		this.shoptype = null;
		this.clientid = null;
		this.urlimg = null;
		this.param = new Object();
		this.onTheLoad();
		$super();
	},
	
	setParams:function( tabParam ){
		 var x = tabParam.toString();
	     var mesParam = x.split(";");
	     for( var i = 0 ; i < mesParam.length ; i++ ){
			var x = mesParam[i].toString();
			var monParam = x.split(":");
			this.param[monParam[0]] = monParam[1];
		}
	},
	
	_ajaxRedirect:function(){
		if( this.json.comeAgainLater == 'false'){
			this.neededForCommonInformations();
		}else
			location.replace('/maintenance.php');
	},
	
	onTheLoad:function(){
		
		var expression = /(v3|localhost|dev|preprod|newhome|.+-Rayon|FSRayon)/;
		
		if( expression.test( window.location ) ){
			this.neededForCommonInformations();
		}else{
			var jsonElements = { 
		 			'url':'/ajaxRedirectFile.php',
		 			'myClass' : this,
		 			'myMethod':'_ajaxRedirect()'
		 		};
		 
				ajaxReq = new _AjaxElements( jsonElements );
				ajaxReq.getAjaxInformations();
		}
		
		
		if( isSet( $('partners') ) ){
			var cookie = getCookie( 'Origine' );
			if( cookie == 47 || cookie == 81 )
				$('partners').style.display = 'block';
		}
		
       /* if ( typeof( coolManager ) != 'undefined' ) {
            coolManager.display();
        }*/

		if ( $('submit2') ) {
			$('submit2').focus();
		}
	    if ( $('submit_ogone2') != null ) {
			$('submit_ogone2').focus();
	    }
	    if ( $('submit_ogone3') != null ) {
	        $('submit_ogone3').focus();
	    }
	    
	    if (window.ActiveXObject) {
	        sfHover();
	        sfHover2();
	    }
	    
	    var int = /(Origine)(\.|=)(\d+|\w+)/;
		var url = int.exec( document.location.pathname );

		if ( RegExp.$1 == 'Origine') {
			var expires = new Date();
			var oneMonth = expires.getTime() + (31 * 24 * 60 * 60 * 1000);
			expires.setTime( oneMonth );
			document.cookie = "Origine="+RegExp.$3+";path=/;expires=" + expires.toGMTString();
		}
	    
	    var site = /(v3|brandalley.fr)/;
		if ( site.test( window.location ) ) {
			var exctest = /(test.brandalley.fr)/;
			if( !exctest.test( window.location ) ) {
				var exc = /(Id.954|Id-954|Id.875|Id-875)/;
				if( !exc.test( window.location.pathname ) ) {
					var vp = /(FSIndex|FSMarque|FSRayon)/;
					if( vp.test( window.location.pathname ) ) {
						if ( !getCookie( 'AccessPrivateSale' ) )
							firstVP( null );
					}
				}
				if( document.location.pathname == '/ventes-privees/' ){
					if ( !getCookie( 'AccessPrivateSale' ) && isSet( $('newsletter') ) ){
						$('newsletter').style.display = 'block';
					}
				}
			}
		}
		
		return true;
	},
	
	onTheGoFunctions:function(){
		if( typeof( idRayonPourFiche ) != 'undefined' ){
			this.neededForGetTaillesFiche( idRayonPourFiche , Pt );
		}
		
		if( typeof( tableauId ) != 'undefined' ){
			this.neededForGetTailles( tableauId , productTypeForAjax );
		}
		if ( isSet( $('allVF') ) ){
			var allVF = new forVF();
			allVF.neeededForAllVF( '/AffichageAjax=getAllVF' , 'getAllVF()' , 'allVF' );
		}
		if ( isSet( $('shape') ) ){
			var allVF = new forVF();
			allVF.neeededForAllVF( '/AffichageAjax=getAllVF' , 'getAllVF()' , 'shape' );
		}
		
		if( this.shopid == 43 && isSet( $('jumpToAnotherSale') ) ){
			var allVF = new forVF();
			allVF.neeededForAllVF( '/AffichageAjax=currentFlashSales' , 'getCurrentFlashSales()' , null );
		}
		
		/*if( isSet( $('couponpopup') ) ){
			this.getTab();
		}*/
	},
	
	neededForCommonInformations:function(){
		var send = {};
		if( typeof( checkIfConnectedId ) != 'undefined' && checkIfConnectedId != 'check' ){
			send.id = checkIfConnectedId;
			//var send = 'id='+checkIfConnectedId;
		}else if( typeof( checkIfConnected2Id ) != 'undefined'  ){
			send.pageId = 1;
			//var send = 'pageId=1';
		}

	    if( typeof( zeFsId ) != 'undefined' && zeFsId != '' ){
	    	send.fsid = zeFsId;
	    }
					
		var jsonElements = { 
 			'url':'/Ajax=_getClientStatusConnexion/',
 			'myClass' : this,
 			'myMethod':'commonInformations()',
 			'parametres' : send
 		};
 
		ajaxReq = new _AjaxElements( jsonElements );
		ajaxReq.getAjaxInformations();
		
	},
	
	commonInformations:function(){
		var pere = this.json;
		var deconnexion = $('deconnexion');
		var deconnexionParigo = $('deconnexionParigo');
		this.shopid = pere.shopid;
		this.shoptype = pere.shoptype;
		this.urlimg = pere.urlimg;
		this.clientid = pere.clientId;
		this.encartHeader = pere.encartHeader; 
		this.encartPopup = pere.encartPopup; 
		this.encartListing = pere.encartListing; 
		
		this.onTheGoFunctions();
		
		if ( this.shopid == 42 && isSet( $('logononvip') ) ){
			if( $('logononvip').src != this.urlimg+'annasandvip_logo.gif'){
				var origine = getCookie('Origine');
		        var x = pere.mesorignesVIP.toString();
		        var mesoriginesvip = x.split(";");
		        var ok = 0;
		        
		        if( pere.vip == 1 ){
		            $('logononvip').src = this.urlimg+'annasandvip_logo.gif';
		        }else if( pere.vip == 0 && !origine){
		             $('logononvip').src = this.urlimg+'annasand_logo2.gif';
		        }else {
		            for (var i=0; i < mesoriginesvip.length ; i++){
		            	if( mesoriginesvip[i] == origine ){
		            		$('logononvip').src = this.urlimg+'annasandvip_logo.gif';
		            		ok = 1;
		            		break;
		            	}
		            }
		            if( ok == 0 )
		            	$('logononvip').src = this.urlimg+'annasand_logo2.gif';
		        }
			}
		}
	
		if( this.shopid == 43 && isSet( $('customer_first_name') ) ){
			fname = pere.fname;
			$('customer_first_name').update( fname );
		}

		if( this.shopid == 43 && isSet( $('customHeader') ) && this.encartHeader != '' ){			 
			$('customHeader').update(this.encartHeader );
		}
		
		if( this.shopid == 43 && isSet( $('customHeader2') ) && this.encartHeader != '' ){			 
			$('customHeader2').update(this.encartHeader );
		}
		
		if( this.shopid == 43 && isSet( $('encartPopup') ) && this.encartPopup != '' ){			 
			$('encartPopup').update(this.encartPopup );
		}
		
		if( this.shopid == 43 && isSet( $('encartListing') ) && this.encartListing != '' ){			 
			$('encartListing').update(this.encartListing);
		}
		if( pere.redirect != 'ok' && ( typeof( checkIfConnectedId ) != 'undefined' || typeof( checkIfConnected2Id ) != 'undefined' ) ){
			$('page-content').style.visibility='hidden';
			location.replace( pere.redirect );
		}else if( pere.lien != 'n' ){
			if (isSet( deconnexion ) ) {
				var elemntsFrame = {
						'htmlelmt' : 'img',
						'attributes' : { 'src' : this.urlimg+pere.imageDeconnect }
					   };
				var imageLien = deconnexion.createFrame( elemntsFrame );
				deconnexion.writeAttribute( { 'href' : pere.lien[0] , 'style' : 'display:inline;' } );
				
				if( isSet( $('yourIn') ) ){
					$('yourIn').update( pere.fname+' you\'re in!<br /><a class="notYou" href="/MonCompte~Deconnexion">Not you?</a>' );
					$('decon').style.height = '30px';
					imageLien.observe( 'mouseover' , function(){ imageLien.style.top = '-30px'; } );
					imageLien.observe( 'mouseout' , function(){ imageLien.style.top = '0px'; } );
				}
				
			}else if( isSet( deconnexionParigo ) ) {
				deconnexionParigo.style.visibility='visible';
			}
		}
		if( pere.dateAnnaSand != 'n' ){
			var dateAnnaSand = $('zedates');
			
			if( isSet( dateAnnaSand ) ){
				if( pere.vip == 1 )
					dateAnnaSand.firstChild.style.display = 'block';
				else {
					dateAnnaSand.removeChild( dateAnnaSand.firstChild );
					dateAnnaSand.firstChild.style.display = 'block';
				}
			}
		}

		if( pere.deleteVF >= 0 ){
			var showimg = $('main'+pere.deleteVF);
			if( isSet( showimg ) ){
				showimg.style.display = 'block';
			}else {
				var parent = $('salesSkin');
				if( isSet( parent ) )
					parent.update( '<img class="later" src="http://media2.brandalley.com/shops/42/encarts/annasand_accueil.gif" />' );
			}
		}

		if( pere.afficheButton != 'ok' ){
			var ids = new Array();
			if( pere.afficheButton != 'n' ){
				ids = pere.afficheButton.toString().split('_');
			}
			var count2 = document.getElementsByClassName('vpGoTo');
			for( var n = 0 ; n < count2.length ; n++ ){
				if( pere.afficheButton == 'n' || ids.indexOf( count2[n].firstChild.id ) >= 0 ){
					count2[n].removeChild( count2[n].firstChild );
				}
			}
			var count1 = document.getElementsByClassName('saleVIP2');
	
			for ( var i =0 ; i < count1.length ; i++ ) {
				if ( pere.afficheButton == 'n' || ids.indexOf( count1[i].id ) >= 0 ){
					var src = count1[i].getElementsByTagName('img')[0].src;
					var papaNoeud = count1[i].parentNode;
					var elemntsFrame = {
							'htmlelmt' : 'img',
							'attributes' : { 'src' : src }
						   };
					papaNoeud.createFrame( elemntsFrame );
					count1[i].removeChild(count1[i].firstChild);
				}
			}
		}

		if( this.shopid != 43 ){
			if( pere.caddyElements[0].numitemsincaddie > 0 ){
				caddyElements = pere.caddyElements[0];
				var ppProducts = new popupProducts( caddyElements , this.shopid );
			}else{
				$('item_count').update( '('+pere.caddyElements[0].numitemsincaddie+')' );
				if( this.shopid == 42 ){
					
					$('boutonPanier').observe( 'mouseover' , function(){
																			//$('boutonPanier').firstChild.style.backgroundPosition = 'top left';
																			$('item_count').style.backgroundColor = 'white';
																			$('item_count').style.color = '#000';
																			$('item_count').style.borderTop = '#000 solid 1px';
																			$('item_count').style.borderRight = '#000 solid 1px';
																		} );
					$('boutonPanier').observe( 'mouseout' , function(){
																		$('item_count').style.backgroundColor = 'transparent';
																		$('item_count').style.color = '#fff';
																		$('item_count').style.border='none';
																	} );
					
				}
			}
		}else
			$('item_count').update( '('+pere.numitemsincaddie+')' );
		
		if( this.shopid == 3 && pere.caddyElements[0].numitemsincaddie == 0 )
			this.getOptOut();
		
		if( isSet( $('takeAndDestroy') ) ){
			cutAndPaste( $('takeAndDestroy') );
		}
		
	},
	
	getOptOut:function(){

		var value;
		if( value = getCookie( 'optNews' ) ){
			var exp = value.split("_");
			if ( exp[0] == 'optout') {
				if( this.json.today >= exp[1] ){
					
					$('opacDiv').style.display = 'block';
					var expires = new Date();
					var time = expires.getTime() + (100 * 24 * 60 * 60 * 1000);
					expires.setTime( time );

					document.cookie = "optNews=optout_"+this.json.todayQuinze+"_"+exp[2]+";path=/;expires=" + expires.toGMTString();
					
					var elemntsFrame = {
							'htmlelmt' : 'div',
							'attributes' : { 'id' : 'optout' }
						   };
					var content = $('page-content').createFrame( elemntsFrame );
					
					var elemntsFrame = {
							'htmlelmt' : 'div',
							'attributes' : { 'class' : 'leftOp' }
						   };
					content.createFrame( elemntsFrame );
					
					var elemntsFrame = {
							'htmlelmt' : 'div',
							'attributes' : { 'class' : 'rightOp' }
						   };
					var right = content.createFrame( elemntsFrame );
					
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : 'Vos emails sur-mesure... <span class="fermerOpt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fermer&nbsp;<img src="/pix/arrows/sup_article.png"></span>',
							'attributes' : { 'class' : 'titleMes' }
						   };
					var fermer = right.createFrame( elemntsFrame );
					fermer.observe( 'click' , function(){ $('optout').remove();$('opacDiv').hide(); } );
					
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : '<img src="/pix/fleche.gif"> Recevez les lettres d\'informations, offres et avantages en fonction de vos <b>centres d\'int&eacute;r&ecirc;ts.</b> <span class="cocher"><br>(cocher pour recevoir la newsletter)</span>',
							'attributes' : { 'class' : 'first' }
						   };
					right.createFrame( elemntsFrame );
					
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : 'Merci de cocher un ou plusieurs choix pour valider votre selection.',
							'attributes' : { 'id' : 'pError' }
						   };
					right.createFrame( elemntsFrame );
					
					var elemntsFrame = {
							'htmlelmt' : 'fieldset',
							'attributes' : { 'class' : 'fieldset' }
						   };
					var fields = right.createFrame( elemntsFrame );

					var elemntsFrame = {
							'htmlelmt' : 'div',
							'attributes' : { 'class' : 'choiseOne' }
						   };
					var choiseOne = fields.createFrame( elemntsFrame );      
	                
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : '<label>Femme</label><input id="femmeOptin" type="checkBox" name="alerte_1">',
							'attributes' : { 'class' : 'femEnf' }
						   };
					choiseOne.createFrame( elemntsFrame );
					
					$('femmeOptin').observe( 'click' , this.checkOrNot.bind( this , 0 ) );
					
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : '<label>Enfant</label><input id="enfantOptin" type="checkBox" name="alerte_3">',
							'attributes' : { 'class' : 'femEnf' }
						   };
					choiseOne.createFrame( elemntsFrame );
					$('enfantOptin').observe( 'click' , this.checkOrNot.bind( this , 0 ) );
					
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : '<label>Homme</label><input id="hommeOptin" type="checkBox" name="alerte_2">',
							'attributes' : { 'class' : 'femEnf' }
						   };
					choiseOne.createFrame( elemntsFrame );
					$('hommeOptin').observe( 'click' , this.checkOrNot.bind( this , 0 ) );
	                
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : '<label>D&eacute;coration</label><input id="decoOptin" type="checkBox" name="alerte_4">',
							'attributes' : { 'class' : 'femEnf' }
						   };
					choiseOne.createFrame( elemntsFrame );
					$('decoOptin').observe( 'click' , this.checkOrNot.bind( this , 0 ) );
	                
					var txtContent = '<img src="/pix/fleche.gif"> Ou Choisissez votre <b>fr&eacute;quence</b> d&acute;envoi en recevant uniquement la meilleure offre de la semaine.';
					txtContent += '<p class="onlyWeek"><input id="bowOpt" type="checkBox" name="alerte_5"> Oui, je souhaite recevoir uniquement un email par semaine.';
					txtContent += 'Et b&eacute;n&eacute;ficiez des avantages qui vous seront r&eacute;serv&eacute;s personnellement.</p>';
					
					var elemntsFrame = {
							'htmlelmt' : 'div',
							'txtContent' : txtContent, 
							'attributes' : { 'class' : 'second' }
						   };
					right.createFrame( elemntsFrame );
					
					$('bowOpt').observe( 'click' , this.checkOrNot.bind( this , 1 ) );
					
					var elemntsFrame = {
							'htmlelmt' : 'p',
							'txtContent' : '<img src="/pix/btValiderOpt.jpg">', 
							'attributes' : { 'class' : 'bSubmit' }
						   };
					var bSubmit = right.createFrame( elemntsFrame );
					bSubmit.observe( 'click' , this.checkOpt.bind( this , exp[2] ) );

				}
			}
		}
	},

	checkOrNot:function( which ) {
		if( which == 1 ){
			for( var i = 1 ; i < 5 ; i++ ) {
				alerte = document.getElementsByName('alerte_'+i);
				alerte[0].checked = false;
			}

			$('pError').hide();
		}else if( which == 0 ){
			$('bowOpt').checked = false;
			$('pError').hide();
		}
	},

	checkOpt:function( idClient ) {

		if( !$('femmeOptin').checked && !$('enfantOptin').checked && !$('hommeOptin').checked && !$('decoOptin').checked && !$('bowOpt').checked )
			$('pError').show();
		else{
			if( $('bowOpt').checked ){
				var bow = 'on';
				var f = 'off';
				var e = 'off';
				var h = 'off';
				var d = 'off';
			}else{
				var bow = 'off';
				var f = 'off';
				var e = 'off';
				var h = 'off';
				var d = 'off';

				if( $('femmeOptin').checked )
					f = 'on';
				if ( $('enfantOptin').checked )
					e = 'on';
				if ( $('hommeOptin').checked )
					h = 'on';
				if ( $('decoOptin').checked )
					d = 'on';
			}

			url = '/MonCompte~GetBackDes/';
			pars = 'idClient=' +idClient+ '&femme=' +f+ '&enfant=' +e+ '&homme=' +h+ '&deco=' +d+ '&bow=' +bow+ '&ajaxReq=1';
			
			var jsonElements = { 
		 			'url':url,
		 			'myClass' : this,
		 			'myMethod':'MesgSuccess()',
		 			'parametres' : pars
		 		};
		 
				ajaxReq = new _AjaxElements( jsonElements );
				ajaxReq.getAjaxInformations();
		}
	},

	MesgSuccess:function() {

		var parent = $('optout');

		var elemntsFrame = {
				'htmlelmt' : 'div',
				'txtContent' : '<span class="fermerOptBis">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fermer&nbsp;<img src="/pix/arrows/sup_article.png"></span>', 
				'attributes' : { 'class' : 'pSuccess' }
			   };
		var fermer = $('optout').updateFrame( elemntsFrame );
		fermer.observe( 'click' , function(){ $('optout').remove();$('opacDiv').hide(); } );
		
		$('optout').insert( '<p><img src="/pix/felicitation.jpg"></p>' );

		setTimeout( function(){ $('optout').remove();$('opacDiv').hide(); },'5000');
	}
	
});