
/////////////////////////////////////////////////////////////////////////
//////CONTROLE DES CHAMPS MARQUER COMME OBLIGATOIRE DANS LES MODALS//////
/////////////////////////////////////////////////////////////////////////

	function require(form){
		var pass=true;
		$(form).find('input,textarea,select').each(function(i,elm){
								//dans le cas d'un changement d'adresse le remplissage de certain champ est requis (title = requireNext) on v�rifie ces champs
			//REQUIRE EMAIL
			if($(elm).attr('title')=='requireVerifEmail'){
				if(!verifEmail($(elm).attr('value'))){
					pass=false;
					$(elm).addClass('editError');
					$(elm).prev('label').addClass('editError');
				}			
				if($.trim($(elm).attr('value'))==''){
					pass=false;
					$(elm).addClass('editError');
					$(elm).prev('label').addClass('editError');
				}
			}
			//REQUIRE VALUE
			if($(elm).attr('title')=='requireText'){
				if($.trim($(elm).attr('value'))==''){
					pass=false;
					$(elm).addClass('editError');
					$(elm).prev('label').addClass('editError');
				}
			}	
		});
		return pass;
	}

///////////////////////////////////////////////////////////
///////////////////INPUT TYPE radio//////////////////////
///////////////////////////////////////////////////////////
	function activeRadio(form){
		$(form).find('input[type="radio"]').each(function(){
			$(this).click(function(){
				$(form).parents('.activeRadio').find('input[type="radio"]').attr('checked',"");
				$(this).attr('checked',"checked");
			})
		})
	}


// => GRISE BACKGROUND OUVERTURE MODAL ACTIVE LAPPUI SUR ENTRER
	function backOpac(mode){
		if(mode==true){
			dialogOpen=true;
			$('.modalForm input').keydown(function(event){
				if (event.keyCode == '13') {
					$('.ui-button:last').click();
					return false;
				}	 
			});
			if($('.ui-widget-overlay').length>0){
				//montre le back gris
				$('.ui-widget-overlay').show();
				
				//redimmensionne le fond gris , si la taille du doc a changé			
				var h= $('body').height();
				if($('body').height()<$(document).height())h=$(document).height();
				$('.ui-widget-overlay').width(document.width);
				$('.ui-widget-overlay').height(h);
			}else{
				var h= $('body').height();
				if($('body').height()<$(document).height())h=$(document).height();
				$('.ui-dialog').before('<div class="ui-widget-overlay" style="width:'+document.width+'px; height:'+h+'px; z-index: 1000;"></div>');
			}	
		}else{
			dialogOpen=false;
			$('.ui-widget-overlay').hide();
		}
	}

// => LOADING
	function loading(){
		$('#loading').dialog({
			width: 50,
			height: 50,	
			resizable: false,
			draggable:false
		});		
	}
	
// => END LOADING
	function endLoading(nameClass){
		//TRADUCTION SAVE CANCEL
		$('.ui-button-text').each(function(){
			if($(this).html()=='save'){
				if(nameClass=="signalInfo editInfo"){
					$(this).html($('#modalSend').html());
				}else{
					$(this).html($('#modalSave').html());
				}
			}else if($('#modal'+ucfirst($(this).html())).length){
				$(this).html($('#modal'+ucfirst($(this).html())).html());
			}
		});
		
		//AJOUT DE LA TITLE BAR POUR LA SECONDE B>OITE DE DIALOGUE
		$(".ui-dialog-titlebar").css('display','block'); 
		
		//SIGNAL INFO SI LE CLIENT VEUT AJOUTER UNE INFO ON AUGMENTE LA TAILLE DE LA MODAL
		$('#addNewValueSignal').click(function(){
			$('#addNewValContenair').fadeIn(function(){
				//la taille du doc a pu augmenter donc on augmente la taille du fond gris
				backOpac(true);	
			});
			$('#modalForm').css('height', '100%');
			if ($('#gMapParams').length>0){
				initialize();
				$('#resetCoords').click(function(){
					$('#google_lat').val("");
					$('#google_long').val("");
					showAddress();
				});
			}

			
		});
		
		//SUPPRESSION DE LA BOX LOADING
		$('#loading').dialog('destroy');		
	}
	
// => CLOSE MODAL
	function closeModal(elm){
		$(elm).dialog("destroy");
		$(elm).remove();	
	}

// => SAVE EDIT AND ADD
	function saveInfo(elm){
		var info = $('#modalFormPost').serialize();
		$.ajax({
			type: "POST",
			url: domain+"/do/modal/edit/gdm_modal_save.php",
			data: info,
			success: function(newValue){
				var val = $.trim(newValue).split('SEP/');
				displayVal(val, elm)
			}
		});
	}
function verifEmail(email){
	var place = email.indexOf("@",1);
	var point = email.indexOf(".",place+1);
	
	if ((place > -1)&&(email.length >2)&&(point > 1)){
		return true;	
	}else{
		return(false);
	}
}


