		(function($){			
			
			
			$('option').focus(function(){
				
				$(this).attr({'style':'border:2px solid #73A6FF;'});
				
			});
			
			function focusThis(obj){ // *********************************************************************************	
					if ( $(obj).attr('type') != 'select-one' ){	
						$(obj).removeClass("idleField").removeClass("activite").removeClass("poste")
						.addClass("focusField");
					}
					
					$(obj).parents('div.questionRFQ').children('p.identite').css({'font-weight':'bold'});
					$('#div_cli_civilite').children('p.identite').attr({'style':''});
					
					if ( $('input[type = radio]', '#div_cli_civilite').is(':checked') == true
								&& $('#div_cli_civilite').children('div.ok').length == 0 
							 ){
							 		$('#div_cli_civilite').children('div.warn').hide();
									$('#div_cli_civilite').append('<div class=\'ok\'>OK</div>');
								}						
				}				
				
				
				 // *********************************************************************************
			
			function checkThis(obj){ // *********************************************************************************
				
				var thisParent = $(obj).parents('div.questionRFQ');
				var thisParentID = thisParent.attr('id');
				var thisParentLib = thisParent.children('p.identite').text();
				
				$('div.ok',$(obj).parents('div.questionRFQ')).remove();
				
				if ( thisParent.children('p').children('span').hasClass('required') ){
				
						switch($(obj).attr('type')){ 
							
							case 'radio':
								
								if( $('input[type = radio]', '#div_cli_civilite').is(':checked') == true  ){
																
								$('label', '#div_cli_civilite').attr({'style':''});
									
								}
								
								
							break;
								
							case 'text':
								$(obj).removeClass("focusField").addClass("idleField");
								$('div.ok',thisParent).remove();
								if( thisParentID == 'div_company_name' ){ // Si CAS PARTICULIER
									if( $(obj).val() == '' && $('select','#div_segment').val() != '' ){
										$('div.warn', thisParent).hide();
										$('#notice_cn_' +$('select','#div_segment').val(), '#div_company_name').show();
									
									}else if( $(obj).val() == '' && $('select','#div_segment').val() == '' ){
										$('div.warn', thisParent).hide();
										$('#notice_cn_1', '#div_company_name').show();
									}else{
										$('div.warn', thisParent).hide();
										thisParent.append('<div class=\'ok\'>OK</div>');	
									}
									
								}
								else if(thisParentID == 'cli_mail'){ 
									checkEmail(obj); 
								}
								else{
									if( $(obj).val() == '' ){ // Si le champ est vide
										if( $('div.warn:visible', thisParent).length == 0 ){ // erreur non affiché donc afficher
											$('div.ok',thisParent).remove();
											$('div.warn', thisParent).show();
										}						
									}else{ // Si le champ est remplis 
										if( $('div.warn:visible', thisParent).length == 1 ){ // Si message d'erreur
											$('div.warn', thisParent).hide();
											$(obj).attr({'style':''});					
										}
										
										
										if( thisParentID == 'div_cli_prenom' && $('input[type = radio]', '#div_cli_civilite').is(':checked') != true ){
											$('div.ok',thisParent).remove();
											thisParent.append('<div class=\'ok\'>OK</div>');
											$('div.warn', '#div_cli_civilite').show(); 
										}
										
										if($('div.ok',thisParent).length == 0){
											thisParent.append('<div class=\'ok\'>OK</div>');
										}
									}
								
								}
							break;	
						
							case 'textarea':
							
								$(obj).removeClass("focusField").addClass("idleField");
								
								if( $(obj).val() == '' && $('div.warn:visible', thisParent).length == 0 ){
									
									$('div.ok',thisParent).remove();
									$('div.warn', thisParent).show();
								
								}else if( $(obj).val() != '' && $('div.warn:visible', thisParent).length == 1 ){
									
									$('div.warn', thisParent).hide();
									$(obj).attr({'style':''});
									thisParent.append('<div class=\'ok\'>OK</div>');
								
								}else if( $(obj).val() != '' && $('div.warn:visible', thisParent).length == 0 && thisParent.children('div.ok').length == 0 ){
									
									thisParent.append('<div class=\'ok\'>OK</div>');								
								
								}
								
								
							break;	
							case 'select-one':
							case 'select-multiple':
							case 'select':
								
								$(obj).removeClass("focusField").addClass("idleField");
								$(obj).attr({'style':''});
								$('div.ok',thisParent).remove();
								
								if( $(obj).val() == '' && $('div.warn:visible', thisParent).length == 0 ){
									$('div.ok',thisParent).remove();
									$('div.warn', thisParent).show();							
								}else if( $(obj).val() != '' && $('div.warn:visible', thisParent).length == 1 ){
									$('div.warn', thisParent).hide();
									$(obj).attr({'style':''});
									thisParent.append('<div class=\'ok\'>OK</div>');
								}else if( $(obj).val() != '' && $('div.warn:visible', thisParent).length == 0 && thisParent.children('div.ok').length == 0 ){	
									thisParent.append('<div class=\'ok\'>OK</div>');
								}
							break;	
						}
				}

				$(obj).parents('div.questionRFQ').children('p.identite').attr('style','');
				
			}
			// ******************************  E MAIL *******************************************
			function checkEmail(obj){ 
			
	
				
				var email_regexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-\.])+\.)+([a-zA-Z0-9]{2,4})+$/;
	 			var is_valid = $('#cli_mail').val().toLowerCase().match(email_regexp);
						
				if(!is_valid ){
					$('div.ok',$(obj).parents('div.questionRFQ')).remove();
					$('div.warn', $(obj).parents('div.questionRFQ') ).show();
				}
				else if(is_valid && $(obj).parents('div.questionRFQ').children('div.ok').length == 0 ){
					$('div.warn', $(obj).parents('div.questionRFQ') ).hide();
					$(obj).parents('div.questionRFQ').append('<div class=\'ok\'>OK</div>');
					
				}else{
					
					$('div.warn', thisParent).show();
				
				
				}
			}
			
			function warn_company_name (index) {
					if(index != undefined && $('#company_name').val() == ''){
						$('div.ok', '#div_company_name').remove();
						$('.warn', '#div_company_name').hide();
						$('#notice_cn_'+index, '#div_company_name' ).show();
					}
					
				
				}			
			// ******************************  E MAIL *******************************************
			
			// **********************************************************************************
			// Public methods Public methods Public methods Public methods Public methods 
			// **********************************************************************************
					

			
			$.fn.coupon_helper = function() {
				$('p.quiVous').attr('class','identite');
				
					$('#list_segment').bind('change', function(){
						warn_company_name($(this).val());
						});
				
					$('input, select,textarea','.questionRFQ').each(function(){
					
						$(this).bind('focus', function(){focusThis(this);})
							    .bind('blur', function(){checkThis(this);});

							
						thisParent = $(this).parents('div.questionRFQ');
						thisParentID = $(this).parents('div.questionRFQ').attr('id');
						thisID = $(this).attr('id');							    
					
						if( $(this).hasClass('error') ){
							
							$('div.ok',thisParent).remove();							
							
							if( thisParentID == 'div_company_name' ){
								if( $('select','#div_segment').val() != '' ){
									$('select','#div_segment').trigger('change');
									$('div.warn', thisParent).hide();
									$('div.warn', thisParent).filter('#notice_cn_' + $('select','#div_segment').val()).show();
								}
							
							}else if(thisParentID != 'div_cli_civilite'  ) {
								$('div.warn', thisParent).show();
							}
							
							
							if ( $('input[type = radio]', '#div_cli_civilite').is(':checked') != true){
										$('div.warn', '#div_cli_civilite').show(); 
							}
						
						}else if ( thisParentID == 'div_cli_civilite' && $('input[type = radio]', '#div_cli_civilite').is(':checked') == true
									&&	$('div.ok',thisParent).length == 0 ){
							$('#div_cli_civilite').append('<div class=\'ok\'>OK</div>');  
						}else if(thisID == 'cli_mail'){	
								checkEmail(this);
						}else if($(this).val() != '' && $(this).attr('type') != 'radio'	&& thisID != 'cli_news_partner' && $(this).attr('type')!='checkbox' && $(this).attr('type')!='hidden'  ){	
								thisParent.append('<div class=\'ok\'>OK</div>');
						}
					});		
					
					$('select','#div_segment').trigger('change');
										

			}

		})(jQuery);

