//<![CDATA[

/**
 * Template-specific subclass
 **/
var activeTabCount = 1;
var results = '';
var results2 = '';
var tabCount = 0;
var companyType1 = '';
var companyType2 = '';
var companyType3 = '';
var companyType4 = '';

    jQuery().ready(function(){
    	
    	
        $(".jeux-closed-top").click(
            function() {
                if ($(this).hasClass('jeux-closed-top')) {
	                $(".jeux-item-content").slideUp('slow');
                    $('.jeux-open-top').removeClass('jeux-open-top').addClass('jeux-closed-top');
                    
	                $(this).next().slideDown('slow');
	                $(this).removeClass('jeux-closed-top');
	                $(this).addClass('jeux-open-top');
	                $(this).addClass('jeux-open-top').css({paddingBottom: '10px'});
                }
                else if ($(this).hasClass('jeux-open-top')) {
                    $(this).next().slideUp('slow');
                    $(this).removeClass('jeux-open-top');
                    $(this).addClass('jeux-closed-top');
                    $(this).addClass('jeux-closed-top').css({paddingBottom: '2px'});
                }
            }
        );
    });

$(document).ready(function () {
	
/*	_sIFR.replace('#straplines', 'h2', 'center', 'upper', true);
	_sIFR.replace('div.panel600', 'h3');
	_sIFR.replace('div.mod-calculate', 'h3', 'left', 'normal', false, 'transparent');
	_sIFR.replace('div.module200-basic', 'h3', 'left', 'normal', false, 'transparent'); */
    
	var TemplateJ = Template.extend();
	
	TemplateJ.init = function() {
		$('#tip').hide();
		$(".form-holder .errormsg").hide();
		$(".tab-holder .errormsg").hide();
		this.renderStraplines();
		this.renderRightTitles('#column1-of-2 h3, .mod-calculate h3');		
    
		// show first tab
		showTab(1);
		
		for(var x = 1; x <= tabCount; x++) {
			$('#tablink' + x).click(function(){
				var tab = $(this).attr("href").substring(1,2);
				showTab(tab);
			});
		}
		
	}
	
	TemplateJ.init();	
	$('#dialog').jqm();
	
	$('.jqModal').click(function(){
//		$('#straplines').hide();
	});
	
});

function isInteger(key)
{ 
  if((key >= "0") && (key <= "9")) 
  	return true;
  
  return false;
}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }
   return true; 
}

function validateInt(element) {
	result = '';
	value = $(element).val();
	if(value.length > 0){
		for(i=0;i<value.length;i++){
			a = value.substring(i, i+1)
			if(isInteger(a)){
				result = result+a;
			}
		}
	}
	element.value = result;
	return false;
}

function validatePhone(element) {
	result = '';
	value = $(element).val();
	if(value.length > 0){
		for(i=0;i<value.length;i++){
			a = value.substring(i, i+1)
			if(isInteger(a) || a == '+' || a == ' ' || a == '(' || a == ')'){
				result = result+a;
			}
		}
	}
	element.value = result;
	return false;
}

function isValidEmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false)
		return false;
	return true;
}

function showTip() {
	$('#tip').show('fast');
}

function hideTip() {
	$('#tip').hide();
}

function clearForm() {
	for(i=1; i<6; i++) {
		$('#field_'+i).val("");
	}
}

function validateForm() {
	
	var errors = false;
	
	$(".form-holder .errormsg").hide();
	merchantID  = new String();
	merchantID = $('#field_1').val();
	
	if(($('#field_1').val() == '') || (merchantID.length != 7)) { 
	   errors = true; 
	   $('#merchantIdError').show();
	}
	if($('#field_2').val() == '') { 
	   errors = true; 
	   $('#companyNameError').show();
	}
	if($('#field_3').val() == '') { 
	   errors = true; 
	   $('#merchantNameError').show();
	}
	if($('#field_4').val() == '') { 
	   errors = true; 
	   $('#phoneError').show();
	}
	if(!isValidEmail($('#field_5').val())) { 
	   errors = true; 
	   $('#emailError').show();
	}
	
	if(!errors) {
		document.getElementById('main_form').submit();
    }
}

function validateTakeOneForm() {
	
	var errors = false;
	
	$(".form-holder .errormsg").hide();
	merchantID  = new String();
	merchantID = $('#field_1').val();
	
	if(($('#field_1').val() == '') || (merchantID.length != 7)) { 
	   errors = true; 
	   $('#merchantIdError').show();
	}
	if($('#field_2').val() == '') { 
	   errors = true; 
	   $('#companyNameError').show();
	}
	if($('#field_3').val() == '') { 
	   errors = true;
	   $('#companyAddressError').show();
	}
	if($('#field_4').val() == '') { 
	   errors = true; 
	   $('#companyZipError').show();
	}
	if($('#field_5').val() == '') { 
	   errors = true; 
	   $('#companyCityError').show();
	}
	if($('#field_6').val() == '') { 
	   errors = true; 
	   $('#merchantNameError').show();
	}
	if($('#field_7').val() == '') { 
	   errors = true; 
	   $('#phoneError').show();
	}
	if(!isValidEmail($('#field_8').val()) || $('#field_8').val() == '') { 
	   errors = true; 
	   $('#emailError').show();
	}
	
	if(!errors) {
		document.getElementById('main_form').submit();
	}
}

function validateNewToAmexForm() {

	var errors = false;
	
	$(".form-holder .errormsg").hide();
	
	if(($('#merchantId').val() == '') || ($('#merchantId').val().length != 7)) { 
	   errors = true; 
	   $('#merchantIdError').show();
	}
	if($('#companyName').val() == '') { 
	   errors = true; 
	   $('#companyNameError').show();
	}
	
	// if($('#date').val() == '') { errors = true; $('#dateError').show();} // not required
	
	if($('#companyType').val() == '') { 
	   errors = true; 
	   $('#companyTypeError').show();
	}
	if($('#companyAddress').val() == '') { 
	   errors = true; 
	   $('#companyAddressError').show();
	}
	if($('#companyZip').val() == '') { 
	   errors = true; 
	   $('#companyZipError').show();
	}
	if($('#companyCity').val() == '') { 
	   errors = true; 
	   $('#companyCityError').show();
	}
	if($('#merchantName').val() == '') { 
	   errors = true; 
	   $('#merchantNameError').show();
	}
	if($('#phone').val() == '') { 
	   errors = true; 
	   $('#phoneError').show();
	}
	
	// if($('#webSite').val() == '') { errors = true; $('#webSiteError').show();} // not required
	
	if($('#message').val() == '') { 
	   errors = true; 
	   $('#messageError').show();
	}
	if($('#filename').val() == '') { 
	   errors = true; 
	   $('#filenameError').show();
	}
	
	if(!errors) {
		document.getElementById('main_form').submit();
	}
}

function showTiragesAuSortConfirmation(){
	 
	 
	//$('#header3').html("Validation de votre participation");
	//$('#confirmation-text').html("Merci de votre participation. Elle a bien été prise en compte.<br /><br />Retrouvez la liste complète des gagnants sur resoclub.fr à compter du 28 Septembre 2009.<br /><br />Bonne chance !<br /><br /><a href='/home.html'>Accédez aux autres sections de resoclub.fr</a>");
	$('.list').hide();
	$('.hidden').hide();
}

function showEtablissementsConfirmation(){
	$('#header3').html("Confirmation");
	$('#confirmation-text').html("Merci pour votre confiance ! <br /> Votre offre sera publiée sous 4 semaines maximum, et vous serez informé de sa mise en ligne à l'adresse email que <br /> vous avez indiquée.");
	$('.list').hide();
	$('.hidden').hide();
}

function showNewToAmexConfirmation(){
	$('#header3').html("Confirmation");
	$('#confirmation-text').html("Merci pour votre confiance ! Votre demande de parution a bien été enregistrée et votre message sera visible en ligne sous 8 semaines environ, après validation par notre comité de relecture.");
	$('.list').hide();
	$('.hidden').hide();
}

function showTakeOneConfirmation(){
return;
// obsolete all management done in php template
	$('#confirmation-title').html("Confirmation");
	$('#confirmation-text').html("Merci pour votre confiance ! Vous recevrez 50 exemplaires de demande de Carte American Express, ainsi qu’un présentoir (si cet article a été inclus dans votre commande) dans un délai de xx semaines."); 
	$('.list').hide();
	$('.hidden').hide();
}


function showMerchantConfirmation() {
	$('#confirmation-title').html("Confirmation");
	$('#text-above-tabs').html("Merci pour votre confiance ! Votre filleul sera contacté par nos équipes commerciales, et vous recevrez votre chèque cadeaux dans les meilleurs délais après son affiliation.");
	$('.list').hide();
	$('.hidden').hide();
}

function showTemoignageConfirmation() {
    $('#confirmation-title').html("Merci !");
    $('#text-above-tabs').html("Nous vous remercions d’avoir pris le temps de nous donner votre avis. Ainsi, nous pourrons améliorer la qualité des services que nous vous fournissons et, si vous le souhaitez, partager votre expérience <a href='http://www.resoclub.fr/'>resoclub.fr</a> avec d’autres commerçants du réseau American Express, debouche à oreille !<br /><br /><a href='http://www.resoclub.fr'> Accèdez à tous les avantages de resoclub.fr !</a>");
    $('.list').hide();
    $('.hidden').hide();
}

/**
 * Show tab 
 */
function showTab(id) {
	if(activeTabCount >= id) {			
		for (var x = 1; x <= tabCount; x++) {				
			$('#tablink' + x).removeClass('active');				
			$('#tab' + x).hide();
		}		
		
		$('#tablink' + id).addClass('active');		
		$('#tab' + id).show("slow");
	}else
		return false;
}

/**
 * + De gains > parrainage
 * Validate form on tab 1
 */
function validateForm1_1() {
	
	var errors = '';
	
	$(".tab-holder .errormsg").hide();
	
	if($('#merchantId').val() == '') {
	   errors = true; $('#merchantIdError').show(); 
	} else {
		if($('#merchantId').val().length < 7) {
		  errors = true;
		  $('#merchantIdShortError').show(); 
        }
	}
	if($('#companyName').val() == '') { 
	   errors = true;
	   $('#companyNameError').show();
	}
	if($('#address').val() == '') { 
	   errors = true;
	   $('#addressError').show();
	}
	if($('#postCode').val() == '') { 
	   errors = true;
	   $('#postCodeError').show();
	}
	if($('#city').val() == '') { 
	   errors = true;
	   $('#cityError').show();};
	if($('#nameOfContact').val() == '') { 
	   errors = true;
	   $('#nameOfContactError').show();
	}
	if($('#phone').val() == '') { 
	   errors = true;
	   $('#phoneError').show();
	}
	
	if(!errors) {
		activeTabCount = 2;
		showTab(2);
		return false;
	}
	
}

/**
 * + De gains > parrainage
 * Validate form on tab 2
 */
function validateForm1_2() {
	
	var content;
	var errors = '';
	var gift = '';
	var comment = '';
	var godsonComment = '';
	
	$(".tab-holder .errormsg").hide();
	
	if($('#tradeName').val() == '') { 
	   errors = true; 
	   $('#tradeNameError').show(); 
	}
	if($('#personName').val() == '') { 
	   errors = true; 
	   $('#personNameError').show(); 
	}
	if($('#godsonAddress').val() == '') { 
	   errors = true; 
	   $('#godsonAddressError').show(); 
	}
	if($('#godsonZip').val() == '') { 
	   errors = true; 
	   $('#godsonZipError').show(); 
	}
	if($('#godsonCity').val() == '') { 
	   errors = true; 
	   $('#godsonCityError').show(); 
	}
	if($('#godsonPhone').val() == '') { 
	   errors = true; 
	   $('#godsonPhoneError').show(); 
	}
	
	if(!errors) {
		activeTabCount = 3;
		
		if($('#comment').val() != '') {
			comment = '<div class="formresult"><label>Commentaire</label>' + $('#comment').val() + '</div>';	
		}	
			
		if($('#godsonComment').val() != '') {
			godsonComment = '<div class="formresult"><label>Commentaire</label>' + $('#godsonComment').val() + '</div>';
		}
		
		$('#spanMerchantId').html($('#merchantId').val());
		$('#spanCompanyName').html($('#companyName').val());
		$('#spanAddress').html($('#address').val());
		$('#spanPostCode').html($('#postCode').val());
		$('#spanCity').html($('#city').val());
		$('#spanNameOfContact').html($('#nameOfContact').val());
		$('#spanPhone').html($('#phone').val());
		
        if($('#comment').val() != '') {
            $('#spanComment').html($('#comment').val()); 
        }
        
        $('#spanTradeName').html($('#tradeName').val());
        $('#spanPersonName').html($('#personName').val());
        $('#spanGodsonAddress').html($('#godsonAddress').val());
        $('#spanGodsonZip').html($('#godsonZip').val());
        $('#spanGodsonCity').html($('#godsonCity').val());
        $('#spanGodsonPhone').html($('#godsonPhone').val());
        
        if($('#godsonComment').val() != '') {
            $('#spanGodsonComment').html($('#godsonComment').val());
        }
		
		showTab(3);
		return false;
	}
	
}


function clearFormTakeOne() {
	for(i=1; i<9; i++) {
		$('#field_'+i).val("");
	}
}

function clearForm(tabId) {
	
	if(tabId == '0'){
		$('#form-holder .clearable').each(function() {
			var type = this.type;	
			if(type == 'text' || type == 'textarea')
				this.value = '';
			if(type == 'select-one')
				this.selectedIndex = 0;	
			}
		);
		
	}
		
		
	$('#tab'+tabId+' .clearable').each(function() {
			var type = this.type;	
			if(type == 'text' || type == 'textarea')
				this.value = '';
			if(type == 'select-one')
				this.selectedIndex = 0;	
		}
	);
}


/**
 * + De clients > Contactez d'autres etablissements
 * Validate form on tab 1
 */
function validateForm2_1(categories) {
	var errors = '';
	
	var categoryIds=categories.split(',');
    companyType1 = categoryIds[0];
    companyType2 = categoryIds[2];
    companyType3 = categoryIds[4];
    companyType4 = categoryIds[6];
        
	$(".tab-holder .errormsg").hide();
	
	if($('#merchantId').val() == '') { 
	   errors = true;
	   $('#merchantIdError').show();
	}
	else {
		if($('#merchantId').val().length < 7) { 
		  errors = true; 
		  $('#merchantIdShortError').show();
		}
	}
	if($('#companyName').val() == '') { 
	   errors = true;
	   $('#companyNameError').show();
    }
	if($('#companyType').val() == '') { 
	   errors = true;
	   $('#companyTypeError').show();
	}
	if($('#contactName').val() == '') { 
	   errors = true;
	   $('#contactNameError').show();
	}
	if($('#address').val() == '') { 
	   errors = true;
	   $('#addressError').show();
	}
	if($('#postCode').val() == '') { 
	   errors = true;
	   $('#postCodeError').show();
	}
	if($('#city').val() == '') { 
	   errors = true;
	   $('#cityError').show();
	}
	
	// ............
	// .. REGION ..
	// ............
	// $("input[@name='profitFromOffer']:checked").val() != 1;
	if($('#region').val() == 0) { 
	   errors = true;
	   $('#regionError').show();
	}
	// $('#region').val();
	
	if($('#phone').val() == '') { 
	   errors = true;
	   $('#phoneError').show();
	}
	if(!isValidEmail($('#email').val())) { 
	   errors = true; 
	   $('#emailError').show();
	}
	
	if(!errors) {
	    prepareTab2_2();
		activeTabCount = 2;
		showTab(2);
		return false;
	}
	
}

/**
 * + De clients > Contactez d'autres etablissements
 * Validate form on tab 2
 */
function validateForm2_2() {
	
	var errors = '';
	var companyDescription = $('#companyDescription').val();
	
	$(".tab-holder .errormsg").hide();
	if(companyDescription == '') { errors = true; $('#companyDescriptionErrorA').show(); };
	if(companyDescription.length > 80) { errors = true; $('#companyDescriptionErrorB').show(); };
	if($('#offerType1').val() == 0) { errors = true;$('#offerTypeError').show();};
	if($('#offerType1').val() == 1) {
		if($('#reductionAmount').val() == '') { errors = true;$('#reductionAmountError').show();};
		if($('#highTransaction').val() == '') { errors = true;$('#highTransactionError').show();};
	} else if($('#offerType1').val() == 2) {
		if($('#specify0').val() == '') { errors = true;$('#specify0Error').show();};
		// if($('#specify').val() == '') { errors = true;$('#specifyError').show();};
		if($('#highTransactionAtPublicPrice').val() == '') { errors = true;$('#highTransactionAtPublicPriceError').show();}; // not required
	}
	
	if($('#whereToProfitFromOffer').val() == '') { errors = true;$('#whereToProfitFromOfferError').show();};
	
	if(($("input[@name='profitFromOffer']:checked").val() != 1) && ($("input[@name='profitFromOffer']:checked").val() != 2)) {
		errors = true;
		$('#askToSpecifyError').show();
	} else {
		$('#askToSpecifyError').hide();
		if($("input[@name='profitFromOffer']:checked").val() == 2) {
			if($('#askToSpecify').val() == '') { errors = true; $('#askToSpecifyError').show();};
		}
	}
	
	if($('#dateFrom').val() == '') { errors = true;$('#dateFromError').show();};
	if($('#dateTo').val() == '') { errors = true;$('#dateToError').show();};
	
	$('#offerAddress1Error').hide();
	$('#offerAddress2Error').hide();
	
	if(($("input[@name='offerUse']:checked").val() != 1) && ($("input[@name='offerUse']:checked").val() != 2) && ($("input[@name='offerUse']:checked").val() != 3)) { errors = true; $('#offerUseError').show();}
	else {
		if((($("input[@name='offerUse']:checked").val() == 1) || ($("input[@name='offerUse']:checked").val() == 3)) && ($('#offerAddress1').val() == '')) { errors = true; $('#offerAddress1Error').show(); $('#offerAddress2Error').hide(); }
		if((($("input[@name='offerUse']:checked").val() == 1)  || ($("input[@name='offerUse']:checked").val() == 3))&& ($('#offerAddress1').val().length > 80)) { errors = true; $('#offerAddress12Error').show(); $('#offerAddress2Error').hide(); }
		else if((($("input[@name='offerUse']:checked").val() == 2) || ($("input[@name='offerUse']:checked").val() == 3)) && ($('#offerAddress2').val() == '')) { errors = true; $('#offerAddress2Error').show(); $('#offerAddress1Error').hide(); } 
	}
	
	if(!errors) {
		activeTabCount = 3;
		
		// get company type (select)
	    companyType = $('#companyType').text();
		
		// get offer type (select)
		switch( $('#offerType1').val() ) {
			case '0':
                offerType1 = 'Sèlectionnez une offre';
                break;
			case '1':
                offerType1 = 'Réduction de ' + $('#reductionAmount').val() + '% pour toute transaction supérieure à ' + $('#highTransaction').val() + ' euros'; 
                break;
			case '2':
                offerType1  = $('#specify0').val() + ', Pour toute transaction supérieure à :';
				if ($('#specify').val() == '') {
					offerType1 += '0 euro';
				} else {
					offerType1 += $('#specify').val() + ' euros';
				}
				offerType1 += '. Prix public du cadeau:' + $('#highTransactionAtPublicPrice').val() + ' euros'; // &euro
                break;
			default:
                offerType1 = '';
                break;
		}
		
		// get profit from offer (radio)
		switch( $("input[@name='profitFromOffer']:checked").val() ) {
			case '1':
                profitFromOffer = 'Sur présentation de cette page imprimée'; 
                break;
			case '2':
                profitFromOffer = 'Code promotionnel - ' + $('#askToSpecify').val(); 
                break;
			default:
                profitFromOffer = ''; 
                break;
		}

		// get offer use (radio)
		switch( $("input[@name='offerUse']:checked").val() ) {
			case '1': {
				offerUse = 'Dans votre établissement'; 
				offerUseValue = $('#offerAddress1').val();
				break;
			}
			case '2': {
				offerUse = 'Sur votre site Internet'; 
				offerUseValue = $('#offerAddress2').val();
				break;
			}
			case '3': {
				offerUse = 'Dans votre établissement et sur votre site Internet'; 
				offerUseValue = $('#offerAddress1').val();
				offerUseValue = offerUseValue + "<br />" + $('#offerAddress2').val();
				break;
			}
				
			default: {
				offerUse = ''; 
				offerUseValue = ''; 
				break;
			}
		}

		$('#spanMerchantId').html($('#merchantId').val());
		$('#spanCompanyName').html($('#companyName').val());
		$('#spanCompanyType').html($('#companyType option:selected').text());
		$('#spanRegion').html($('#region option:selected').text());
		$('#spanContactName').html($('#contactName').val());
		$('#spanAddress').html($('#address').val());
		$('#spanPostCode').html($('#postCode').val());
		$('#spanCity').html($('#city').val());
		$('#spanPhone').html($('#phone').val());
		$('#spanEmail').html($('#email').val());
        
		if($('#webSite').val() != '') {
		    $('#spanWebSite').html($('#webSite').val());
		}
        
		$('#spanCompanyDescription').html($('#companyDescription').val());
		$('#spanOfferType1').html(offerType1);
		$('#spanOfferUse').html(offerUse + ' - ' + offerUseValue);
		$('#spanProfitFromOffer').html(profitFromOffer);
		$('#spanDateFrom').html($('#dateFrom').val());
		$('#spanDateTo').html($('#dateTo').val());		
		
		showTab(3);
		return false;
	}
	
}

function validateForm2_3() {
	
	var errors = '';
	var content = '';
	var companyType = '';
	var offerType1 = '';
	var profitFromOffer = '';
	var offerUse = '';
	
	$(".tab-holder .errormsg").hide();
	
	if($('#intentionOf').val() == '') { 
	   errors = true; $('#intentionOfError').show(); 
	}
	if($('#addressInvoicing').val() == '') {
        errors = true; $('#addressInvoicingError').show(); 
    }
	if($('#facturationZip').val() == '') {
	   errors = true; $('#facturationZipError').show(); 
	}
	if($('#facturationCity').val() == '') { 
	   errors = true; $('#facturationCityError').show(); 
	}
	if(($('#facturationEmail').val() == '') || !isValidEmail($('#facturationEmail').val())) { 
	   errors = true; $('#facturationEmailError').show(); 
	}
	if($('#facturationPhone').val() == '') { 
	   errors = true; $('#facturationPhoneError').show(); 
	}
	if($('#intracomm').val() == '') { 
	   errors = true; $('#intracommError').show(); 
	}
	
	if(!errors) {
		
		activeTabCount = 4;
		
		// get company type (select)
		/*
		switch( $('#companyType').val() ) {
			case '1':
                companyType = 'Restaurant'; 
                break;
			case '2':
                companyType = 'Hôtel'; 
                break;
			case '3':
                companyType = 'Magasin'; 
                break;
			case '4':
                companyType = 'Autres'; 
                break;
			default:
                companyType = ''; 
                break;
		}
		*/
		// get offer type (select)
		switch( $('#offerType1').val() ) {
			case '0':
                offerType1 = 'Sèlectionnez une offre'; 
                break;
			case '1':
                offerType1 = 'Réduction de 10-'+$('#reductionAmount').val()+'% pour toute transaction supérieure à '+$('#highTransaction').val(); 
                break;
			case '2':
                offerType1 = $('#specify0').val() + ', Pour toute transaction supérieure à :';
				if ($('#specify').val() == '') {
					offerType1 += '0';
				} else {
					offerType1 += $('#specify').val();
				}
				offerType1 += '. Prix public du cadeau:' + $('#highTransactionAtPublicPrice').val() + ' euros'; // &euro
    			break;
			default:
                offerType1 = '';
                break;
		}
		
		// get profit from offer (radio)
		switch( $("input[@name='profitFromOffer']:checked").val() ) {
			case '1':
                profitFromOffer = 'Sur présentation de cette page imprimée';
                break;
			case '2':
                profitFromOffer = 'Code promotionnel - ' + $('#askToSpecify').val();
                break;
			default:
                profitFromOffer = '';
                break;
		}

		// get offer use (radio)
		switch( $("input[@name='offerUse']:checked").val() ) {
			case '1': {
				offerUse = 'Dans votre établissement'; 
				offerUseValue = $('#offerAddress1').val();
				break;
			}
			case '2': {
				offerUse = 'Sur votre site Internet'; 
				offerUseValue = $('#offerAddress2').val();
				break;
			}
			case '3': {
				offerUse = 'Dans votre établissement et sur votre site Internet'; 
				offerUseValue = $('#offerAddress1').val();
				offerUseValue = offerUseValue + "<br />" + $('#offerAddress2').val();
				break;
			}
				
			default: {
				offerUse = ''; 
				offerUseValue = ''; 
				break;
			}
		}
		
		$('#spanMerchantId').html($('#merchantId').val());
		$('#spanCompanyName').html($('#companyName').val());
		$('#spanCompanyType').html($('#companyType option[@selected]').text());
		$('#spanContactName').html($('#contactName').val());
		$('#spanAddress').html($('#address').val());
		$('#spanPostCode').html($('#postCode').val());
		$('#spanCity').html($('#city').val());
		$('#spanPhone').html($('#phone').val());
		$('#spanEmail').html($('#email').val());
		                
		if($('#webSite').val() != '') {
		    $('#spanWebSite').html($('#webSite').val());
		}
		
		$('#spanCompanyDescription').html($('#companyDescription').val());
		
		$('#spanOfferType1').html(offerType1);
		
		$('#spanOfferUse').html(offerUse + ' - ' + offerUseValue);
		$('#spanProfitFromOffer').html(profitFromOffer);
		
		$('#spanDateFrom').html($('#dateFrom').val()); 
		$('#spanDateTo').html($('#dateTo').val());
		
		$('#spanIntentionOf').html($('#intentionOf').val());
		$('#spanAddressInvoicing').html($('#addressInvoicing').val());
		$('#spanFacturationZip').html($('#facturationZip').val());
		$('#spanFacturationCity').html($('#facturationCity').val());
		$('#spanFacturationEmail').html($('#facturationEmail').val());
		$('#spanFacturationPhone').html($('#facturationPhone').val());
		$('#spanIntracomm').html($('#intracomm').val());
		
		showTab(4);
		return false;
	}
	
}

function selectOfferType2_2(id) {
	valueId = $('#offerType' + id).val();
	$('.child').hide();	
	$('#divOfferType' + id + '-' + valueId).slideDown("slow");	
	if(id == 2) {
		if(valueId == 2)
			$('#divOfferType2-2-1').slideDown();
		selectOfferType2_2_4();
	}
}

function prepareTab2_2() {
	selectedId = $('#companyType').val();
	$('#tab2 #div-offer2 .formline').hide();
	$('#tab2 #divDateFrom').show();
	$('#tab2 #divDateTo').show();
	$('#tab2 .divBtns').show();
	$('#divOfferAddress1').hide();
	$('#divOfferAddress2').hide();
	$('#divOfferType2').show();
	$('#divWhereToProfitFromOffer').show();
	$('#divProfitFromOffer').show();
	$('#divOfferExpiration1').show();
	$('#divOfferExpiration2').show();
	$('#divOfferUse').show();

	switch(selectedId) {
		case companyType1:					
			$('#offerType1').show();
			//$('#offerType2').show();
			//$('#offerType3').hide();
			$('#divCompanyDescription').show();
			$('#divOfferType').show();
			$('#divOfferDetails').show();
			$('#divValidPeriod').show();		
			$('#divValidate2').show();			
			selectOfferType2_2(1);
		break;
		
		case companyType2:    
		    $('#offerType1').show();
			//$('#offerType2').show();
			//$('#offerType3').hide();
			$('#divCompanyDescription').show();
			$('#divOfferType').show();
			$('#divOfferDetails').show();
			$('#divValidPeriod').show();
			$('#divValidate2').show();
			
			selectOfferType2_2(2);			
		break;
		
		case companyType3:   
		    $('#offerType1').show();
			//$('#offerType2').show();
			//$('#offerType3').show();
			$('#divCompanyDescription').show();
			$('#divOfferType').show();
			$('#divOfferDetails').show();
			$('#divValidPeriod').show();		
			$('#divValidate2').show();				
			selectOfferType2_2(3);					
		break;
		
        case companyType4: 
            $('#offerType1').show();
           // $('#offerType2').show();
           // $('#offerType3').show();
            $('#divCompanyDescription').show();
            $('#divOfferType').show();
            $('#divOfferDetails').show();
            $('#divValidPeriod').show();        
            $('#divValidate2').show();              
            selectOfferType2_2(3);                  
        break;  
	}	
}

function selectOfferType_2_2(id) {
	$('#reductionAmount').val('');
	$('#divReduce').slideUp("slow");
	$('#highTransaction').val('');
	$('#divHighTransaction').slideUp("slow");
	$('#specify').val('');
	$('#specify0').val('');
	$('#divSpecify').slideUp("slow");
	$('#divSpecify0').slideUp("slow");
	$('#highTransactionAtPublicPrice').val('');
	$('#divHighTransactionAtPublicPrice').slideUp("slow");
	
	if(id == 0) {
		// default value 
	} else if(id == 1) {
		// 
		$('#divReduce').slideDown("slow");
		$('#divHighTransaction').slideDown("slow");
	} else if(id == 2) {
		$('#divSpecify0').slideDown("slow");
		$('#divSpecify').slideDown("slow");
		$('#divHighTransactionAtPublicPrice').slideDown("slow");
	}
}

function selectOfferType_2_3(id) {
	
	$('#pfo').show();
	
	$('#divAskToSpecify').hide();
	$('#askToSpecify').val('');
	$('#divPleaseSpecify').hide();
	$('#pleaseSpecify').val('');
	
	$('#profitFromOffer').val('');
	$('#divProfitFromOffer').slideUp("slow");
	
	$('#divPleaseSpecify').slideUp("slow");
	$('#pleaseSpecify').val('');
	
	if(id == 0) {
		$('#divProfitFromOffer').slideDown("slow");
	} else if(id == 1) {
		$('#divPleaseSpecify').slideDown("slow");
	}
}

function selectOfferType2_2_4() {
	if($('#offerType2').val() == 4) {
		if($('#offerType2-4').val() == 3){
			$('#divOfferType2-4-3').slideDown("slow");			
		}else {
			$('#divOfferType2-4-3').slideUp("slow");
		}
	}
}

function showAskToSpecify(action) {
	$('#askToSpecify').val('');
	$('#askToSpecifyError').hide();
	if(action == 1) // show
		$('#divAskToSpecify').slideDown('slow');
	else if(action == 2) // hide
		$('#divAskToSpecify').slideUp('slow');
}

function showOfferUse(where_to_use) {
	$('#divOfferAddress1').slideUp('slow');
	$('#divOfferAddress2').slideUp('slow');
	if (where_to_use != 3){
		$('#divOfferAddress' + where_to_use).slideDown('slow');
	} else {
		$('#divOfferAddress1').slideDown('slow');
		$('#divOfferAddress2').slideDown('slow');
	}
}

function validateIntInterval(obj, beginInterval, endInterval) {
	if(obj.value < beginInterval || obj.value > endInterval) {
		obj.value = '';
		return false;
	}
	return true;
}

function validateIntWidthMin(obj, min) {
	if(obj.value < min) {
		obj.value = '';
		return false;
	}
	return true;
}

function clearFormProspect() {
	$('#merchantId').val('');
	$('#phone').val('');
	$('#nameOfCompany').val('');
	$('#addressOfCompany').val('');
	$('#city').val('');
	$('#postCode').val('');
	$('#pays').val('');
	$('#fax').val('');
	$('#email').val('');
	$('#site').val('');
	// type
}

function validateFormProspect() {
	
	var errors = false;
	
	$(".tab-holder .errormsg").hide();
	
	merchantID  = new String();
	merchantID = $('#merchantId').val();
	
	if(($('#merchantId').val() == '')) { 
		errors = true; 
		$('#merchantIdError').show();
	}
	if($('#phone').val() == '') { 
	   errors = true; 
	   $('#phoneError').show();
	}
	if($('#nameOfCompany').val() == '') { 
	   errors = true; 
	   $('#nameOfCompanyError').show();
	}
	if($('#addressOfCompany').val() == '') { 
	   errors = true;
	   $('#addressOfCompanyError').show();
	}
	if($('#city').val() == '') { 
	   errors = true; 
	   $('#cityError').show();
	}
	if($('#postCode').val() == '') { 
	   errors = true; 
	   $('#postCodeError').show();
	}
	if($('#pays').val() == '') { 
	   errors = true; 
	   $('#paysError').show();
	}
	if($('#email').val() == '') { 
	   errors = true; 
	   $('#emailError').show();
	}
	if(($("input[@name='type']:checked").val() != 1) && ($("input[@name='type']:checked").val() != 2) && ($("input[@name='type']:checked").val() != 3)) { 
	   errors = true;
	   $('#typeError').show();
	}
	
	if(!isValidEmail($('#email').val())) { 
	   errors = true;
	   $('#emailError').show();
	}
	
	if(!errors) {
		document.getElementById('main_form').submit();
	}
}

function showProspectConfirmation() {
	$('#header3').html("Confirmation");
	$('#confirmation-text').html("Merci pour votre confiance. Notre équipe commerciale prendra contact avec vous d'ici quelques jours afin de vous permettre de rejoindre le réseau American Express.");
	$('.hidden').hide();
}

function selectedRegion(obj, amount) {
	/*region = $('#region');
	for(i=0; i<=amount-1; i++) {
		$("option[@value='" + obj[i].value + "']").removeClass('selectedRegion');
	}
	$("option[@value='" + region.val() + "']").addClass('selectedRegion');*/
}

function validateFormTirageAuSort1() {
	
	var errors = '';
	
	$(".tab-holder .errormsg").hide();
	
	if(($("input[@name='question1']:checked").val() != 1) && ($("input[@name='question1']:checked").val() != 2) && ($("input[@name='question1']:checked").val() != 3)) { 
	   errors = true;
	   $('#question1Error').show();
	}
	if(($("input[@name='question2']:checked").val() != 1) && ($("input[@name='question2']:checked").val() != 2) && ($("input[@name='question2']:checked").val() != 3)) { 
	   errors = true;
	   $('#question2Error').show();
	}
	if(($("input[@name='question3']:checked").val() != 1) && ($("input[@name='question3']:checked").val() != 2) && ($("input[@name='question3']:checked").val() != 3)) { 
	   errors = true;
	   $('#question3Error').show();
	}
	
	if(!errors) {
		activeTabCount = 2;
		showTab(2);
		return false;
	}
	
}

function validateFormTirageAuSort2() {
	
	var errors = false;
	
	$(".tab-holder .errormsg").hide();
	
	merchantID  = new String();
	merchantID = $('#merchantId').val();
	
	if(($('#merchantId').val() == '')) { errors = true; $('#merchantIdError').show();}
	else {
		if(($('#merchantId').val().length < 7)) { errors = true; $('#merchantIdShortError').show();}
	}
	
	if($('#nameOfTrade').val() == '') { 
	   errors = true; 
	   $('#nameOfTradeError').show();
	}
	if($('#name').val() == '') { 
	   errors = true; 
	   $('#nameError').show();
	}
	if($('#firstName').val() == '') { 
	   errors = true; 
	   $('#firstNameError').show();
	}
	if($('#phone').val() == '') { 
	   errors = true; 
	   $('#phoneError').show();
	}
	if($('#email').val() == '') { 
	   errors = true; 
	   $('#emailError').show();
	}
	else if(!isValidEmail($('#email').val())) { 
	   errors = true; 
	   $('#emailError').show();
	}
	
	if(!errors) {
		document.getElementById('main_form').submit();
	}
}

function showTirageAuSortConfirmation() {
	$('#header3').html("Validation de votre participation");
	$('#confirmation-text').html("<br />Merci pour votre confiance ! Votre participation a bien été prise en compte.<br /><br />La liste des gagnants sera publiée sur resoclub.fr à partir du 1er août 2008.<br /><br />Bonne chance !");
	$('.list').hide();
	$('.hidden').hide();
}

/*function showTirageAuSortError() {
	$('#header3').html("Alerte");
	$('#confirmation-text').html("Vous avez déjà participé au tirage au sort.");
	$('.list').hide();
	$('.hidden').hide();
}*/

function clearFormTAS(tab) {
	
	$('#tab'+ tab + ' .clearable').each(function() {
		var type = this.type;
		if(type == 'text' || type == 'textarea')
			this.value = '';
		if(type == 'radio')
			this.checked = false;
		if(type == 'select-one')
			this.selectedIndex = 0;	
	}); 
}

function validateFormTirage() {
    var errors = false;
    
    if($('#merchantId').val() == '' || $('#merchantId').val().length < 10 || $('#merchantId').val().substring(0,3) != 949) {
        errors = true;
        $('#merchantIdError').show();
    }else {     	
        $('#merchantIdError').hide();
    }
    
    if($('#companyName').val() == '') {
        errors = true;
        $('#companyNameError').show();
    }else {
        $('#companyNameError').hide();
    }
    /*
    if($('#postCode').val() == '' || !$('#postCode').val().match(/^[a-zA-Z0-9]+$/) || $('#postCode').val().length > 10) {
        errors = true;
        $('#postCodeError').show();
    }else {
        $('#postCodeError').hide();
    }
    */
    
    if($('#lastName').val() == '') {
        errors = true;
        $('#lastNameError').show();
    }else {
        $('#lastNameError').hide();
    }
    
    if($('#firstName').val() == '') {
        errors = true;
        $('#firstNameError').show();
    }else {
        $('#firstNameError').hide();
    }
    
    if($('#phone').val() == '') {
        errors = true;
        $('#phoneError').show();
    }else {
        $('#phoneError').hide();
    }
    
    if(!validateEmail($('#email').val())) {
        errors = true;
        $('#emailError').show();
    }else {
        $('#emailError').hide();
    }
    
    if(!errors) {
    	//vérification de la non utilisation du num commerçant
    	$.get(
    			"/pages/validateTirageausortNumCom", 
    			{ merchantId: $('#merchantId').val(), email: $('#email').val() },
    			function(data){
    				if (data) {
    			    	 document.getElementById('main_form').submit();
    			    }
    			    else { 
    			    	$('#dualError').show();
    			     }
    			}
    	);
       
    }
}

function clearFormTirage() {
  	$('#merchantId').val('');
	$('#companyName').val('');
	$('#firstName').val('');
	$('#lastName').val('');
	$('#phone').val('');
	$('#email').val('');     
}

function tirageConfirmation() {
    $('#header3').html("Confirmation");
    $('#confirmationText').html("Votre participation a bien été prise en compte. La liste exhaustive des gagnants sera publiée sur Resoclub à compter du 19 décembre 2008. Bonne chance !");
    $('#confirmationText').show();
    $('.hidden').hide();
    $('.list').hide();
}
function prepareTabTemoignageQuestion() {
    $('#avis-div').slideDown('slow');
}

function clearTabTemoignage(tab) {
    $('#tab'+ tab + ' .clearable').each(function() {
        var type = this.type;
        if(type == 'text' || type == 'textarea')
            this.value = '';
        if(type == 'checkbox') {
            this.checked = 0;
        }
        if(type == 'select-one')
            this.selectedIndex = 0; 
    });
}


function validateFormTemoignage_1() {
    var errors = false;
    
    if($('#question').val() == 0) {
        $('#questionError').show();
        errors = true;
    } else 
    { 
        $('#questionError').hide();
    }
    
    if($('#question').val() != 0 && $('#avis').val() == '') {
        $('#avisError').show();
        errors = true;
    } else 
    { 
        $('#avisError').hide(); 
    }
        
    
    if($("input[@name='checkbox']:checked").val() != 1) {
        $('#checkboxError').show();
        errors = true;
    } else {
        $('#checkboxError').hide();
    }
    
    if(!errors) {
      activeTabCount = 2;
      showTab(2);  
    }
}


function validateFormTemoignage_2() {
	var errors = false;
	
	if($('#lastName').val() == '') { 
	   $('#lastNameError').show(); errors = true; 
	   } else {
	   $('#lastNameError').hide(); 
	} 
	if($('#firstName').val() == '') { 
	   $('#firstNameError').show(); errors = true; 
	} else {
	   $('#firstNameError').hide();
	}
	if($('#companyName').val() == '') { 
	   $('#companyNameError').show(); errors = true; 
	} else {
	   $('#companyNameError').hide();
	}
	if($('#companyType').val() == 0) { 
	   $('#companyTypeError').show(); errors = true; 
	} else {
	   $('#companyTypeError').hide();
	}
    if($('#postCode').val() == '') { 
        $('#postCodeError').show(); errors = true; 
    } else {
        $('#postCodeError').hide();
    }
    if($('#city').val() == '') { 
        $('#cityError').show(); errors = true; 
    } else {
        $('#cityError').hide();
    }

	if(!errors) {
	   document.getElementById('main_form').submit();
	   return false;
    } else {
        return false;
    }
}

function clearFormPresseLocale() {
	$('#merchantId').val('');
	$('#companyName').val('');
	$('#contactName').val('');
	$('#phone').val('');
	$('#address').val('');
	$('#postCode').val('');
	$('#city').val('');
	$('#villePiliPili').val('');
	$('#publicationMois').val('');
}

function validateFormPresseLocale() {
	
	var errors = false;
	
	$(".tab-holder .errormsg").hide();
	
	merchantID  = new String();
	merchantID = $('#merchantId').val();
	
	if(($('#merchantId').val() == '') || (merchantID.length != 7)) { errors = true; $('#merchantIdError').show();}
	if($('#companyName').val() == '') { errors = true; $('#companyNameError').show();}
	if($('#contactName').val() == '') { errors = true; $('#contactNameError').show();}
	if($('#phone').val() == '') { errors = true; $('#phoneError').show();}
	if($('#address').val() == '') { errors = true; $('#addressError').show();}
	if($('#postCode').val() == '') { errors = true; $('#postCodeError').show();}
	if($('#city').val() == '') { errors = true; $('#cityError').show();}
	if($('#villePiliPili').val() == '') { errors = true; $('#villePiliPiliError').show();}
	if($('#publicationMois').val() == '') { errors = true; $('#publicationMoisError').show();}
	
	if(!errors) 
		document.getElementById('main_form').submit();
}

function showPresseLocale() {
	$('#header3').html("Confirmation");
	$('#confirmation-text').html("Merci, votre demande est bien prise en compte. Vous serez rappelé par l'équipe Pilipili sous 2 semaines maximum.");
}

function showConcoursConfirmation() {
	$('#header3').html("Validation de votre participation");
	$('#confirmation-text').html("Merci de votre participation. Elle a bien été prise en compte.<br /><br />Retrouvez la liste complète des gagnants sur resoclub.fr à compter du 2 mai 2009.<br /><br />Bonne chance !<br /><br /><a href='/home.html'>Accédez aux autres sections de resoclub.fr</a>");
	$('.hidden').hide();
}

function toggleLottaryForm()
{
	$('#step-1').hide();
	$('#step-2').show();
	return false;
	
}

function validateFormNewsletter()
{
	var error1 = false;
	var error2 = false;
	var error3 = false;
	var error4 = false;
	var errorMerchantLess = 'Attention, vous devez indiquer les 10 chiffres de votre numéro de commerçant American Express.';
	var errorMerchantWrong = 'Attention, votre N° de commerçant n\'est pas valide.';
	var errorCommon = 'Attention, vous devez compléter tous les champs du formulaire pour valider votre demande.';
    var errorEmail = 'Attention, il semble que vous ayez mal renseigné votre adresse email.';
    var merchantId = $('#merchantId').val();
    var companyName = $('#companyName').val();
    var emailAccount = $('#emailAccount').val();
    
	$('#commonError').html();
	
	merchantID = new String($('#merchantId').val());
	
	//check for empty merchant
	if(merchantID.length == 0) { 
		error1 = true; 
	}
	
	//check for long merchant
	if(merchantID.length < 10) { 
		error3 = true; 
	}
	
	//check if merchant starts with 949
	if( merchantID.substr(0, 3) != '949') { 
		error4 = true; 
	}
	
	//chgeck for company name
	if($('#companyName').val() == '') {
		error1 = true; 
	}
	
	//check for valid mail
	if(!validateEmail($('#emailAccount').val())) { 
		error1 = true; 
	}
	
	//cgeck for email confirmation
	if($('#emailAccountConfirm').val() == '') { 
		error1 = true; 
	}
	
	//check if mail are different
	if($('#emailAccount').val() != $('#emailAccountConfirm').val()) { 
		error2 = true; 
	}
	
	if(error1) { 
		$('#commonError').html(errorCommon); 
		$('#commonError').show();
		return false;
	}
	
	if(error3) { 
		$('#commonError').html(errorMerchantLess); 
		$('#commonError').show(); 
		return false;
	}
	
	if(error4) { 
		$('#commonError').html(errorMerchantWrong); 
		$('#commonError').show(); 
		return false;
	}
	
	if(error2) { 
		$('#commonError').html(errorEmail); 
		$('#commonError').show(); 
		return false;
	}
	
	if(!error1 && !error2 && !error3 && !error4)
	{
		$(".tab .errormsg").hide();
		
		$.ajax(
			{
				type: "POST",
				url: "/newsletter/send",
				data: "merchantId="+merchantId+"&companyName="+companyName+"&emailAccount="+emailAccount,
				success: function(html){
					$('#dialog').jqmShow();
					//return false;
			    }

			}
			);
		//$('#dialog').show(); 
		//return false;
		
	}
	
}

function clearFormNewsletter()
{
	$('.clearable').each(function() {
        this.value = '';
    });
}



//]]>
