/**
 * @link http://www.web-solution-way.be/ 
 * @copyright clashdesign.be 2008 and web-solution-way.be
 * @author : Gérits Aurélien
 * @package : Price calculation
 * @version : 0.6 beta
 * @type : javascript
 * @library : jquery
 * @revision 02/10/2008
 * 
 */
jQuery(function(){
	/**
	 * Define var for IE6
	 */
	var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);
	var ie7 = (jQuery.browser.msie && jQuery.browser.version > 6);
	jQuery('input[type=radio]').check("off");
	/**
	 * Condition for msie with cascading style sheet for button
	 */
	if(ie6){
		jQuery('.globalForm fieldset div').css({'margin-top':'10px','margin-bottom':'10px'});
		jQuery('.globalForm input[type=button]#calc').css({backgroundColor: 'white',color: '#FFA500'});
	}
			/**
			 * Define class Hidden
			 */
			jQuery('.ChildQuest_1').hide();
			jQuery('.SecondChildQuest_1').hide();
			jQuery('.SecondChildQuest_2').hide();
			jQuery('.ChildQuest_3').hide();
			jQuery('.ChildQuest_4').hide();
			jQuery('.ChildQuest_5').hide();
			jQuery('.ChildQuest_51').hide();
			jQuery('.ChildQuest_52').hide();
			jQuery('.ChildQuest_53').hide();
			jQuery('.ChildQuest_6').hide();
			jQuery('.ChildQuest_6a').hide();
			jQuery('.ChildQuest_6b').hide();
			jQuery('.ChildQuest_61').hide();
			jQuery('.ParentsQuest_8').hide();
			jQuery('.ChildQuest_8').hide();
			jQuery('.ChildQuest_81').hide();
			jQuery('.ChildQuest_82').hide();
			jQuery('.ChildQuest_83').hide();
			jQuery('.ChildQuest_84').hide();
			jQuery('.ChildQuest_9').hide();
			/**
			* Define class Hidden for special span
			*/
			
			jQuery('div.ChildQuest_9 span[keyword]').hide();
			jQuery('div.ChildQuest_9 span[report]').hide();
			/**
			 * Define Style for ChildQuest and SecondChildQuest
			 */
			jQuery('[class^="ChildQuest"]').css({
				color: '#FFF',
				border:'1px dashed #A8CAE5',
				fontWeight: 600
			});//.prepend("a)");
			jQuery('[class^="SecondChildQuest"]').css({
				color: '#f0e68c',
				border:'1px dashed #A8CAE5',
				fontWeight: 600
			});//.prepend("b)");
			/** Define event click in ParentQuest:radio
			 * Show/Hide div 
			 * @visibility default #ChildQuest : hide
			 * @visibility default #ChildQuest : #SecondChildQuest
			 */ 
			jQuery('div.ParentsQuest_1 :radio.quantity').click(function(){
				
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					
					jQuery('.ChildQuest_1').show("slow");
					jQuery('.SpecialChildQuest_1').show("slow");
					
				}else{
					jQuery('.SecondChildQuest_1').hide("slow");
					jQuery('.ChildQuest_1').hide("slow");
					jQuery('.SpecialChildQuest_1').show("slow");		
					}
				
			})
			jQuery('div.ChildQuest_1 span[price] :radio.quantity').click(function(){
				
						if(jQuery(this).val() <=0){
							jQuery('.SecondChildQuest_1').show("slow");
						}else{
							jQuery('.SecondChildQuest_1').hide("slow");
						}
			});
			jQuery('div.ParentsQuest_3 :radio.quantity').click(function(){
			
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					
					jQuery('.ChildQuest_3').hide("slow");
					
				}else{
					
					jQuery('.ChildQuest_3').show("slow");
					
					if(ie6){
						
						if (jQuery('div.ChildQuest_3 input:checked').length == 0) {
							string = 'Veuillez cocher : ' + jQuery('div.ChildQuest_3 label span').text()  + "\n";
							alert(string);
							
						}
						
					}else{
						
						if (jQuery('div.ChildQuest_3 input:checked').length == 0) {
							string = '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">Veuillez cocher</strong>' + '<br />' + jQuery('div.ChildQuest_3 label span').text()  + "\n";
							jQuery.prompt(string);
							
						}
					}
				}
				
			});
			jQuery('div.ParentsQuest_4 :radio.quantity').click(function(){
				
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					
					jQuery('.ChildQuest_4').show("slow");
					
				}else{
					
					jQuery('.ChildQuest_4').hide("slow");
				}
				
			})
			jQuery('div.ParentsQuest_5 :radio.quantity').click(function(){
				
				if(jQuery(this).val() == 1){
				
					jQuery('.ChildQuest_5').show("slow");
					jQuery('.ChildQuest_51').hide("slow");
					jQuery('.ChildQuest_52').hide("slow");
					jQuery('.ChildQuest_53').hide("slow");
					
				}else if(jQuery(this).val() == 2){
					
					jQuery('.ChildQuest_5').show("slow");
					jQuery('.ChildQuest_51').show("slow");
					jQuery('.ChildQuest_52').hide("slow");
					jQuery('.ChildQuest_53').hide("slow");
					
				}else if(jQuery(this).val() == 3){
					
					jQuery('.ChildQuest_5').show("slow");
					jQuery('.ChildQuest_51').show("slow");
					jQuery('.ChildQuest_52').show("slow");
					jQuery('.ChildQuest_53').hide("slow");
					
				}else if(jQuery(this).val() == 4){
					
					jQuery('.ChildQuest_5').show("slow");
					jQuery('.ChildQuest_51').show("slow");
					jQuery('.ChildQuest_52').show("slow");
					jQuery('.ChildQuest_53').show("slow");
				}
				
				
			})
			jQuery('div.ParentsQuest_6 :radio.quantity').click(function(){
				
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					
					jQuery('.ChildQuest_6').show("slow");
					jQuery('.ChildQuest_61').show("slow");
					
				}else{
					
					jQuery('.ChildQuest_6').hide("slow");
					jQuery('.ChildQuest_61').hide("slow");
					jQuery('.ChildQuest_6a').hide("slow");
				}
				
			})
			jQuery('div.ChildQuest_6 :radio.quantity').click(function(){
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					jQuery('.ChildQuest_6a').hide("slow");
				}else{
					jQuery('.ChildQuest_6a').show("slow");
				}
			});
			jQuery('div.ChildQuest_61 :radio.quantity').click(function(){
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					jQuery('.ChildQuest_6b').hide("slow");
				}else{
					jQuery('.ChildQuest_6b').show("slow");
				}
			});
			jQuery('div.ParentsQuest_7 :radio.quantity').click(function(){
				
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					
					jQuery('.ParentsQuest_8').show("slow");
					
				}else{
					
					jQuery('.ParentsQuest_8').hide("slow");
				}
				
			})
			jQuery('div.ParentsQuest_8 :radio.quantity').click(function(){
				
				if(jQuery(this).val() <= 0 || jQuery(':radio.quantity').val() == null){
					
					jQuery('.ChildQuest_8').hide("slow");
					
				}else{
					
					jQuery('.ChildQuest_8').show("slow");
				}
				
			})
			jQuery('div.ChildQuest_8 :radio.campagn').click(function(){
				if (ie6) {
				
					if (jQuery('div.ChildQuest_81 input:checked').length == 0) {
						string = 'Veuillez choisir votre langue ! ' + "\n";
						alert(string);
						
					}
					
				}
				else {
				
					if (jQuery('div.ChildQuest_81 input:checked').length == 0) {
						string = '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">Veuillez choisir votre langue !</strong>' + "\n";
						jQuery.prompt(string);
						
					}
				}
				if(jQuery(this).val() == 1){
					
					jQuery('.ChildQuest_81').show("slow");
					jQuery('.ChildQuest_82').hide("slow");
					jQuery('.ChildQuest_83').hide("slow");
					jQuery('.ChildQuest_84').hide("slow");
					
				}else if(jQuery(this).val() == 2){
					
					jQuery('.ChildQuest_81').show("slow");
					jQuery('.ChildQuest_82').show("slow");
					jQuery('.ChildQuest_83').hide("slow");
					jQuery('.ChildQuest_84').hide("slow");
					
				}else if(jQuery(this).val() == 3){
					
					jQuery('.ChildQuest_81').show("slow");
					jQuery('.ChildQuest_82').show("slow");
					jQuery('.ChildQuest_83').show("slow");
					jQuery('.ChildQuest_84').hide("slow");
					
				}else if(jQuery(this).val() == 4){
					
					jQuery('.ChildQuest_81').show("slow");
					jQuery('.ChildQuest_82').show("slow");
					jQuery('.ChildQuest_83').show("slow");
					jQuery('.ChildQuest_84').show("slow");
				}
				
			})
			/**
			 * event CharCode in input:text NumberOptimisePage
			 * @param {CharCode} event
			 */
		jQuery("[@name=NumberOptimisePage]").keypress(function(event){
			if (event.charCode && (event.charCode < 48 || event.charCode > 57)) {
			
				event.preventDefault();
			}
		});
		/**
		 * Define function global change price in span with event click radio
		 * 
		 */
        jQuery('span[price] :radio.quantity').change(function(){
			
        jQuery('~ div:first :text',this).val(
		  
            jQuery(this).val() *  jQuery(this).parents("span[price]:first").attr('price')
			
          );
		  
        });
		/**
		 * Define function global change price in span with input:text
		 * 
		 */
		jQuery('span[price] :text.quantity').change(function(){
			
          jQuery('~ div:first :text',this).val(
		  
            jQuery(this).val() *  jQuery(this).parents("span[price]:first").attr('price')
			
          );
		  
        });
        /**
		 * Ini function change in span[price]
		 * 
		 */
        jQuery('span[price] :radio.quantity').change();
		jQuery('span[price] :text.quantity').change();
		/**
		 * Ini function change in span[report]
		 * 
		 */
		//jQuery('span[report] :text.bitrimestriel').change();
		/**
		 * function event click in button #calc
		 * - Execute global calculation
		 * - remove Attribute disabled in button sendForms
		 */
		jQuery('#calc').click(function(){
					// get the average of the elements
			if(jQuery('span[price] :text#NumberFirstLanguagePage').val() >= 16 && jQuery('span[price] :text#NumberFirstLanguagePage').val() < 24 ){
								
					var sum = jQuery(".total :text").sum() - 375;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}else if(jQuery('span[price] :text#NumberFirstLanguagePage').val() > 24 ){
								
					var sum = jQuery(".total :text").sum() - 750;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}else if(jQuery('span[price] :text#NumberSecondLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberSecondLanguagePage').val() < 24){
								
					var sum = jQuery(".total :text").sum() - 375;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}/*else if(jQuery('span[price] :text#NumberSecondLanguagePage').val() > 24){
								
					var sum = jQuery(".total :text").sum() - 750;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}*/else if(jQuery('span[price] :text#NumberFirstLanguagePage').val() > 24 || jQuery('span[price] :text#NumberSecondLanguagePage').val() > 24){
				
					var sum = jQuery(".total :text").sum() - 1500;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
				
			}else if(jQuery('span[price] :text#NumberThirdLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberThirdLanguagePage').val() < 24){
								
					var sum = jQuery(".total :text").sum() - 375;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}/*else if(jQuery('span[price] :text#NumberThirdLanguagePage').val() > 24){
								
					var sum = jQuery(".total :text").sum() - 750;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}*/else if(jQuery('span[price] :text#NumberFirstLanguagePage').val() > 24 && jQuery('span[price] :text#NumberSecondLanguagePage').val() > 24 && jQuery('span[price] :text#NumberThirdLanguagePage').val() >= 24){
				
					var sum = jQuery(".total :text").sum() - 1500;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
				
			}else if(jQuery('span[price] :text#NumberFourthLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberFourthLanguagePage').val() < 24){
								
					var sum = jQuery(".total :text").sum() - 375;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}else if(jQuery('span[price] :text#NumberFourthLanguagePage').val() > 24){
								
					var sum = jQuery(".total :text").sum() - 750;
					// update the total
					jQuery("#Alltotal").val(sum.toString());
								
			}else{
					var sum = jQuery(".total :text").sum();
					// update the total
					jQuery("#Alltotal").val(sum.toString());
					
			}
			var string = "";
			/*var i= 0;
			while(i <= 8){
				
				i++;
				if (jQuery('div.ParentsQuest_'+i+' input:checked').length == 0) {
					string = jQuery('div.ParentsQuest_'+i+' :radio.quantity').attr('name') + ": non coché" + "\n";
					alert(i+ ')' + ' ' + string);
				}else {
					var sendForms = jQuery('#process #sendForms');
						sendForms.removeAttr('disabled', 'disabled');
						sendForms.css({
							backgroundColor: 'white',
							color: 'orange',
							border: '1px solid grey'
						});
				}
				
			};*/
			if(ie6){
				
				if (jQuery('div.ParentsQuest_1 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_1 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else if(jQuery('div.ParentsQuest_2 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_2 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else if(jQuery('div.ParentsQuest_3 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_3 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else if(jQuery('div.ParentsQuest_4 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_4 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else if(jQuery('div.ParentsQuest_5 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_5 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else if(jQuery('div.ChildQuest_5 :text#NumberFirstLanguagePage').val()<= 4){
						string = ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						alert('Page a optimisé minimum 5' + string);
					return false;
				}else if(jQuery('div.ParentsQuest_6 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_6 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else if(jQuery('div.ParentsQuest_7 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_7 label span').text() + ': ' + 'non coché' + "\n";
						alert(string);
					return false;
				}else {
						if(jQuery('span[price] :text#NumberFirstLanguagePage').val() >= 16 && jQuery('span[price] :text#NumberFirstLanguagePage').val() < 24 ){
						
						alert('Vous avez choisi d\'optimiser un nombre de page compris entre 16 et 24, ce qui vous donne droit à une remise de 50 % sur la réflexion stratégique, à partir de la 25 ème page celle-ci est offerte');
						
					}else if(jQuery('span[price] :text#NumberFirstLanguagePage').val() > 24){
							
						alert('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}else if (jQuery('span[price] :text#NumberSecondLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberSecondLanguagePage').val() < 24 ) {
					
						alert('Le coût de la réflexion stratégique de la seconde langue est réduite de 50%.Si vous choisissez un nombre de page supérieur à 24, celle-ci vous est offerte.');
				
					}else if(jQuery('span[price] :text#NumberSecondLanguagePage').val() > 24){
							
						alert('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}else if(jQuery('span[price] :text#NumberThirdLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberThirdLanguagePage').val() < 24) {
					
						alert('Le coût de la réflexion stratégique de la seconde langue est réduite de 50%.Si vous choisissez un nombre de page supérieur à 24, celle-ci vous est offerte.');
				
					}else if(jQuery('span[price] :text#NumberThirdLanguagePage').val() > 24){
							
						alert('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}else if(jQuery('span[price] :text#NumberFourthLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberFourthLanguagePage').val() < 24) {
					
						alert('Le coût de la réflexion stratégique de la seconde langue est réduite de 50%.Si vous choisissez un nombre de page supérieur à 24, celle-ci vous est offerte.');
						
					}else if(jQuery('span[price] :text#NumberFourthLanguagePage').val() > 24){
							
						alert('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}
						var sendForms = jQuery('#process #sendForms');
							sendForms.show();
						return true;
				}
			}else{
				if (jQuery('div.ParentsQuest_1 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_1 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else if(jQuery('div.ParentsQuest_2 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_2 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else if(jQuery('div.ParentsQuest_3 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_3 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else if(jQuery('div.ParentsQuest_4 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_4 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else if(jQuery('div.ParentsQuest_5 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_5 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else if(jQuery('div.ChildQuest_5 :text#NumberFirstLanguagePage').val()<= 4){
						string = ': <br />' + '<img src="img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt('Page a optimisé minimum 5' + string);
					return false;
				}else if(jQuery('div.ParentsQuest_6 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_6 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else if(jQuery('div.ParentsQuest_7 input:checked').length == 0) {
						string = jQuery('div.ParentsQuest_7 label span').text() + ': <br />' + '<img src="/img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non coché</strong>' + "\n";
						jQuery.prompt(string);
					return false;
				}else {
					if(jQuery('span[price] :text#NumberFirstLanguagePage').val() >= 16 && jQuery('span[price] :text#NumberFirstLanguagePage').val() < 24 ){
						
						jQuery.prompt('Vous avez choisi d\'optimiser un nombre de page compris entre 16 et 24, ce qui vous donne droit à une remise de 50 % sur la réflexion stratégique, à partir de la 25 ème page celle-ci est offerte');
						
					}else if(jQuery('span[price] :text#NumberFirstLanguagePage').val() > 24){
							
						jQuery.prompt('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}else if (jQuery('span[price] :text#NumberSecondLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberSecondLanguagePage').val() < 24 ) {
					
						jQuery.prompt('Le coût de la réflexion stratégique de la seconde langue est réduite de 50%.Si vous choisissez un nombre de page supérieur à 24, celle-ci vous est offerte.');
				
					}else if(jQuery('span[price] :text#NumberSecondLanguagePage').val() > 24){
							
						jQuery.prompt('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}else if(jQuery('span[price] :text#NumberThirdLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberThirdLanguagePage').val() < 24) {
					
						jQuery.prompt('Le coût de la réflexion stratégique de la seconde langue est réduite de 50%.Si vous choisissez un nombre de page supérieur à 24, celle-ci vous est offerte.');
				
					}else if(jQuery('span[price] :text#NumberThirdLanguagePage').val() > 24){
							
						jQuery.prompt('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}else if(jQuery('span[price] :text#NumberFourthLanguagePage').val() >= 1 && jQuery('span[price] :text#NumberFourthLanguagePage').val() < 24) {
					
						jQuery.prompt('Le coût de la réflexion stratégique de la seconde langue est réduite de 50%.Si vous choisissez un nombre de page supérieur à 24, celle-ci vous est offerte.');
						
					}else if(jQuery('span[price] :text#NumberFourthLanguagePage').val() > 24){
							
						jQuery.prompt('Vous avez choisi d\'optimiser un nombre de pages supérieur à 24, la réflexion stratégique vous est offerte.');
							
					}
						var sendForms = jQuery('.globalForm div#process #sendForms');
						sendForms.show();
						return true;
				}
			}
			/*
			else if(jQuery('div.ChildQuest_5 select[name='FirstLanguage'] option:selected').value=='') {
					string = jQuery('div.ChildQuest_5 label span').text() + ': <br />' + '<img src="img/error.png" width="16px" height="16px" /> ' + '<strong style="color:red;">non selectionné</strong>' + "\n";
					jQuery.prompt(string);
					return false;
				}
			*/
		});
})