// JavaScript Document
function CheckFields(field) {

	

	var CpCitys = document.getElementById('ChoiceFrom').title.length;
	var City = document.getElementById('ChoiceFrom').value;
	var OldValue = document.getElementById('OldChoiceFrom').value;
	
	var CpCitys2 = document.getElementById('ChoiceTo').title.length;
	var City2 = document.getElementById('ChoiceTo').value;
	var OldValue2 = document.getElementById('OldChoiceTo').value;

	var DateStart = document.getElementById('DateStart').value;
	var OldDateStart = document.getElementById('OldDateStart').value;

	var TypeAdd = document.getElementById('TypeAdd').value;
	var OldTypeAdd = document.getElementById('OldTypeAdd').value;

	SendForm = false;
	
	// ON VERIFIE SI LE CODEPOSTAL A CHANGE
	if(field == "CpCity"){
		if(CpCitys  == 1 && City != ''){
				if( 		
				IsNotEmpty('form','CpCity','Code Postal','FR') && 
				OnlyNumber('form','CpCity','fr','Code Postal') &&
				MinChar('form','CpCity','4','fr','Code Postal')
				)
			{
				
				
				if(OldValue != document.getElementById('CpCity').value){
					
					SendForm = true;
					
				}
				
			}
		
		}
		else {
			if(OldValue != document.getElementById('CpCity').value){
				document.getElementById('CpCity').value = 0;
				SendForm = true;
			}
		}
			
	}
	
	
	if(field == "CpCity2"){
		if(CpCitys2  == 1 && City != ''){
				if( 		
				IsNotEmpty('form','CpCity2','Code Postal','FR') && 
				OnlyNumber('form','CpCity2','fr','Code Postal') &&
				MinChar('form','CpCity2','4','fr','Code Postal')
				)
			{
				
				
				if(OldValue2 != document.getElementById('CpCity2').value){
					
					SendForm = true;
					
				}
				
			}
		
		}
		else {
			if(OldValue2 != document.getElementById('CpCity2').value){
				document.getElementById('CpCity2').value = 0;
				SendForm = true;
			}
		}
			
	}


	if(field == "DateStart"){
		
		if(DateStart != OldDateStart){
			SendForm = true;
		}
		
	}

	// ON VERIFIE SI LE TYPE DE RECHERCHE A CHANGE
	if(field == "TypeAdd"){
		if(TypeAdd != OldTypeAdd){
			SendForm = true;
		}
		
	}

	if(SendForm == true) {
		
		if(document.getElementById('ChoiceFrom').value == 'Code postal'){	
			document.getElementById('ChoiceFrom').value = 0;	
		}
		if(document.getElementById('ChoiceTo').value == 'Code postal'){
			document.getElementById('ChoiceTo').value = 0;	
		}
			document.getElementById('sqlsearch').value = "yes";
			document.getElementById('forms').submit(); 

		
	}

}
