// This makes the edit form AJAX
IYAClass.implement({

	// **************************************************************************
	// Geo select does the AJAX country counties and states select for forms
	// **************************************************************************
	GeoSelectImplement : function(objCountries, strFormNameCounty1, strFormNameCounty2, idCountyInput, FunctionRun, Function2Run, firstCountyOption) {
			
		objCountries.addEvent('change', function() {
	
			var objCountyInput;
			var objCountyInputHolder;
		
			objCountyInput = $(idCountyInput);
			objCountyInputHolder = objCountyInput.parentNode;
			objCountyInputHolder.setStyle('display', 'block');
			objCountyInput.fade(0.5);
			
			if(objCountries.value=='0') {
			
				objCountyInputHolder.setStyle('display', 'none');
			
			} else {
			
				new Request({
					url: '/ajax/geo',
					method: 'post',
					onComplete: function(response, responseXML){
						
						if (response!='') {
							
							var xmlCountyStates = responseXML.getElementsByTagName('countystate');
							var CountyStateName = responseXML.getElementsByTagName("countystates")[0].getAttribute("countystate");
							
							HTML = '<select class="select" name="'+strFormNameCounty1+'" id="'+idCountyInput+'" class="InputSelect">';
							
							if(firstCountyOption!=null) { HTML = HTML + '<option value="0">'+firstCountyOption+' '+CountyStateName+'</option>'; }
							
							for(var i=0; i<xmlCountyStates.length; i++) {
								HTML = HTML + '<option value="'+xmlCountyStates[i].getAttribute("id")+'">'+xmlCountyStates[i].firstChild.nodeValue+'</option>';
							}
							
							HTML = HTML + '</select>';
							objCountyInputHolder.innerHTML = HTML;
			
						} else {
							
							if (objCountyInput.type == 'text') {
								objCountyInput.value='';
								$(idCountyInput).fade(1);
							} else {
								objCountyInputHolder.innerHTML='';
								objCountyInputHolder.innerHTML = '<input type="text" class="text" value="" name="'+strFormNameCounty2+'" id="'+idCountyInput+'" />';
							}
						
						}
						
						if(FunctionRun) {
							Function2Run();					
						}
						
					}.bind(this)
				}).send('GEOCOUNTRY_ID='+objCountries.value); 
				
			}
		
		});
	
	}
	
});
