function ResellersNear(_alpha2, _iso1,_email, _info,_internet, _chooseOptionText,_infoLink){
	var regionsArr = new Array("DE", "NL", "BE", "FR", "AT", "ES", "IT", "US", "GB", "CH");
	var alpha2 = _alpha2;
	var iso1=_iso1;
	var xmlRegions;
	var xmlCountries;
	var xmlStores;
	var iso2;
	var zipCode;
	var email=_email;
	var info=_info;
	var internet=_internet;		
	var chooseOptionText = _chooseOptionText;
	var infoLink = _infoLink;
	this.onEnterSearch = onEnterSearch;
	this.search = search;
	this.multipleSearch=multipleSearch;
	this.back = back;
	this.startS1=startS1;
	this.buildLists = buildLists;
	this.buildCountriesSelect = buildCountriesSelect;
	this.buildS1CountriesSelect=buildS1CountriesSelect;
	this.changeAlpha2Event = changeAlpha2Event;
	this.changeS1Alpha2Event = changeS1Alpha2Event;	
	this.changeIso2Event = changeIso2Event;
	this.changeZipCodeEvent = changeZipCodeEvent;
	
	// call the reset
	back();
	
	function showError(){
		setDisplayBlockOrNoneById('element_city_zip_error', true);
	}
	function hideError(){
		setDisplayBlockOrNoneById('element_city_zip_error', false);
	}
	
	function showNoResult(){
		setDisplayBlockOrNoneById('element_city_zip_no_location', true);
	}
	
	function hideNoResult(){
		setDisplayBlockOrNoneById('element_city_zip_no_location', false);
	}
	function showMultipleMessage(){
		setDisplayBlockOrNoneById('element_city_zip_multiple_location', true);
	}
	function hideMultipleMessage(){
		setDisplayBlockOrNoneById('element_city_zip_multiple_location', false);
	}
	function search() {
		var 
			cityOrZip=getValueById('city_zip');
		var
			alpha2=getValueById('alpha2');
			
		if (!checkElementByLength('city_zip', 2) || alpha2 == null || alpha2==''){
			showError();
			return;
		}else
			hideError();
			
		debug('alpha2: '+alpha2+' city or zip:'+cityOrZip);
		
		var
			xmlHttp = getXMLHttpRequest();
				
	    xmlHttp.open('GET', '/flash_pos_search.xml?alpha2='+alpha2+'&city_or_zipcode='+cityOrZip, true);
	    xmlHttp.onreadystatechange = function () {
	        if (xmlHttp.readyState == 4) {
	        	var
	        		options = xmlHttp.responseXML.getElementsByTagName('zc')
	        	
	        	if (options == null){
	        		showNoResult();
	        		return;	        	
	        	}
	        	if(options.length>1){
	        		hideNoResult();
	        		showMultipleMessage();
					setDisplayBlockOrNoneById('city_zip_list', true);
					setDisplayBlockOrNoneById('city_zip', false);
						var select = document.getElementById('city_zip_list');
						for (var i = 0; i < options.length; i++) {
							var
								opt=new Option(options[i].getAttribute("zc_groupcolumn")+" "+options[i].getAttribute("zc_searchname"), options[i].getAttribute("zc_lat")+";"+options[i].getAttribute("zc_lon"), false, true);
							select.options[i]=opt;
						}
						showElementById('link_reset');
						hideElementById('link_search');
						select.options[0].selected=true;
						multipleSearch(alpha2, select.options[0].value);
							
	        	} else if (options.length==1){
	        		hideNoResult();
	        		hideMultipleMessage();
					setDisplayBlockOrNoneById('city_zip_list', false);
					setDisplayBlockOrNoneById('city_zip', true);

					buildStoresResult(alpha2, options[0].getAttribute("zc_lat"), options[0].getAttribute("zc_lon"));
				}else
			   		showNoResult();
			
	        }
	    };
	    xmlHttp.send(null);
	}

	function multipleSearch(_alpha2, _latlon) {
		var latLon = _latlon.split(";");
		buildStoresResult(_alpha2, latLon[0], latLon[1]);
	}
	
	function buildStoresResult(_alpha2, _lat, _lon) {
		var
			xmlHttp = getXMLHttpRequest();
			if(_alpha2=="US")
				xmlHttp.open('GET', '/flash_stores_search.xml?alpha2='+_alpha2+'&limit=2&distance=160&lat='+_lat+'&lon='+_lon, true);
			else
	    	xmlHttp.open('GET', '/flash_stores_search.xml?alpha2='+_alpha2+'&lat='+_lat+'&lon='+_lon, true);
	    xmlHttp.onreadystatechange = function () {
	        if (xmlHttp.readyState == 4) {
				showSearchResult(xmlHttp.responseXML.getElementsByTagName('st'), null, null);
	        }
	    };
	    xmlHttp.send(null);
	}
	
	function buildCountriesSelectOptions(_select){
		var 
			selectedIndex=-1;
		var
			alphaLower = alpha2.toLowerCase();
	  	var
	  		len = xmlCountries.length;
	
		for (var i = 0; i < len; i++) {
			var
				znAlpha2 = xmlCountries[i].getAttribute('zn_alpha2');
			var
				znName = xmlCountries[i].getAttribute('zna_name');
	      	
	      if(znAlpha2.toLowerCase() == alphaLower){
	      	selectedIndex = i;
	      }
	      	
	      _select.options[i]=new Option(znName, znAlpha2);
	  	}
	  	
	  	if (selectedIndex != -1)
	  		_select.selectedIndex = selectedIndex;
	}

	function loadCountries(_callback){
		if (xmlCountries == null){
			debug('start loading countries in iso:'+_iso1);
			var
				xmlHttp = getXMLHttpRequest();
			
			xmlHttp.open('GET', '/flash_countries_with_stores_'+_iso1+'.xml', true);
			xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4) {
					// set the countries
					xmlCountries=xmlHttp.responseXML.getElementsByTagName('country');
					debug(xmlCountries.length+" countries loaded");
					
					if (_callback != null)
						_callback();
				}
			};
			
			xmlHttp.send(null);
		}else		
			if (_callback != null)
				_callback();
	}
	function startS1(){
  		var select1 = document.getElementById('alpha2');
  		select1.disabled=true;
		var
			callback = function(){
				// build the select boxes
		  		if (select1!=null){
					buildCountriesSelectOptions(select1);
					select1.disabled = false;
					if(select1.selectedIndex>-1){
						changeS1Alpha2Event(xmlCountries[select1.selectedIndex].getAttribute('zn_alpha2').toLowerCase());
					} else {
						changeS1Alpha2Event("de");
					}					
				}
			};
		loadS1Countries(callback);
	}
	
	function loadS1Countries(_callback){
		if (xmlCountries == null){
			debug('start loading countries in iso:'+_iso1);
			var
				xmlHttp = getXMLHttpRequest();
			
			xmlHttp.open('GET', '/flash_countries_with_s1_stores_'+_iso1+'.xml', true);
			xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4) {
					// set the countries
					xmlCountries=xmlHttp.responseXML.getElementsByTagName('country');
					debug(xmlCountries.length+" countries loaded");
					
					if (_callback != null)
						_callback();
				}
			};
			
			xmlHttp.send(null);
		}else		
			if (_callback != null)
				_callback();
	}

	function loadRegions(_alpha2, _callback){
		debug('start loading regions alpha2:'+_alpha2);
		var
			xmlHttp = getXMLHttpRequest();
		xmlHttp.open('GET', '/flash_regions_per_country_'+(_alpha2.toLowerCase())+'.xml', true);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				// set the regions
		 		xmlRegions=xmlHttp.responseXML.getElementsByTagName('region');
		 		
		 		if (_callback != null)
		 			_callback();
			 }
		};
	  xmlHttp.send(null);
	}

	function loadStores(_alpha2, _callback){
		debug('start loading stores alpha2:'+_alpha2);
		var
			xmlHttp = getXMLHttpRequest();
		xmlHttp.open('GET', '/flash_stores_per_country_'+(_alpha2.toLowerCase())+'.xml', true);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				debug('stores loaded');
				xmlStores=xmlHttp.responseXML.getElementsByTagName('store');				
				
				if (_callback != null)
					_callback();									        
		    }
		};
		xmlHttp.send(null);
	}
	
	function loadS1Stores(_alpha2, _callback){
		debug('start loading stores alpha2:'+_alpha2);
		var
			xmlHttp = getXMLHttpRequest();
		xmlHttp.open('GET', '/flash_s1_stores_per_country_'+(_alpha2.toLowerCase())+'.xml', true);
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				debug('stores loaded');
				xmlStores=xmlHttp.responseXML.getElementsByTagName('store');				
				
				if (_callback != null)
					_callback();									        
		    }
		};
		xmlHttp.send(null);
	}	

	function buildCountriesSelect() {
	  	var select1 = document.getElementById('alpha2');
	  	select1.disabled=true;
		var select2 = document.getElementById('alpha2a');
		if (select2 != null)
			select2.disabled=true;
		var
			callback = function(){
				// build the select boxes
			  	if (select1!=null){
					buildCountriesSelectOptions(select1);
					select1.disabled = false;
				}

		  		if (select2!=null){
					buildCountriesSelectOptions(select2);
					select2.disabled = false;
				}
			};
		loadCountries(callback);
	}
	
	function buildS1CountriesSelect() {
  	var select1 = document.getElementById('alpha2');
  	select1.disabled=true;
		var
			callback = function(){
				// build the select boxes
		  	if (select1!=null){
					buildCountriesSelectOptions(select1);
					select1.disabled = false;
				}
			};
		loadS1Countries(callback);
	}	

	function hasRegion(_alpha2){
		var regionflag=false;
		for (var i=0;i<regionsArr.length;i++){
			if (regionsArr[i]==_alpha2.toUpperCase()){
				regionflag=true;
			}
		}
		return regionflag;
	}

	function buildRegionsSelect(_alpha2, _callback) {
		var
			select = document.getElementById('iso2');
			
		select.disabled = true;
		
		var 
			callback = function(){
			debug('build regions select length:'+xmlRegions.length);

			select.disabled = false;
			select.options.length=0;
			
			select.options[0]=new Option(chooseOptionText, "");
			select.options[0].disabled=true;
			select.selectedIndex = 0;
		  		
		  	var
		  		startIndex = select.options.length;
		  		
		 	for (var i = 0; i < xmlRegions.length; i++) {
		 		var
		 			item = xmlRegions[i];
		     	select.options[i+startIndex]=new Option(item.getAttribute('zn_searchname'), item.getAttribute('zn_iso3166_2'));
		  	}
		  	
		  	if (_callback != null)
		  		_callback();
		};
		
		loadRegions(_alpha2, callback);
	}

	function showHDS2(){
		debug('has region: '+alpha2);
		hideElementById('hds1');
	  	var select1 = document.getElementById('alpha2');
	  	select1.disabled = true;
		var select2 = document.getElementById('alpha2b');
		select2.disabled = true;
		var
			callback = function(){
	
				// build the select boxes
			  	if (select1 != null){
					buildCountriesSelectOptions(select1);
					select1.disabled = false;
				}

		  		if (select2 != null){
					buildCountriesSelectOptions(select2);
					select2.disabled = false;
				}
				var
					cb = function(){
						if (alpha2 != null)
							loadStores(alpha2, null);
					};
				buildRegionsSelect(alpha2, cb);
				
		};
		loadCountries(callback);

		showElementById('hds2');
	}

	function showHDS1(){
		hideElementById('hds2');
		hideZipCodes();
		debug('has no regions: '+alpha2);
		buildCountriesSelect();
		showElementById('hds1');
		if (alpha2 != null){
			var
				callback = function(){
					showSearchResult(xmlStores, null, null);
				};
			loadStores(alpha2, callback);
		}
	}
	function showS1HDS(){
		hideElementById('hds2');
		buildS1CountriesSelect();
		showElementById('hds1');
		if (alpha2 != null){
			var
				callback = function(){
					showS1SearchResult(xmlStores);
				};
			loadS1Stores(alpha2, callback);
		}
	}	

	function buildLists() {
		hideResellers();
		if (hasRegion(alpha2)){
			showHDS2();
		} else {
			showHDS1();
		}
	}
	function showS1SearchResult(_items) {
		hideElementById('content_unten_text');
	    var detailsHtml="";
	    var
	    	subBoxOpen=false;
	    var
	    	pos = 0;
	    for (var i = 0; i < _items.length; i++) {
	    	var
	    		item = _items[i];
	    		
			if (true){
				if (subBoxOpen){
					// close it
					detailsHtml+= "</div>";
					subBoxOpen = false;
				}
				// open it
				detailsHtml+= "<div class=\"s1subbox\">";	
	      subBoxOpen = true;
				detailsHtml+="<div class=\"adressbox\">";
	    }	else {
	       		detailsHtml+="<div class=\"adressbox2\">";
	    }
	    
	    detailsHtml+="<b>"+(item.getAttribute('st_name'))+"</b>";
	    if (item.getAttribute('distance') != null)
	    	detailsHtml+=" ["+(item.getAttribute('distance'))+"&nbsp;km]";
			
			detailsHtml+="<br />";
	    detailsHtml+=(item.getAttribute('st_street'))+"<br />";
	    detailsHtml+="<b>"+(item.getAttribute('st_zipcode'))+" "+(item.getAttribute('st_city'))+"</b><br />";
			
			if (item.getAttribute('st_phone')!=null)
				detailsHtml+="Tel "+(item.getAttribute('st_phone'))+"<br />";
			
			if (item.getAttribute('st_fax')!=null && item.getAttribute('st_fax').length>1)
				detailsHtml+="Fax "+(item.getAttribute('st_fax'))+"<br />";
			
			detailsHtml+="<br />"
			
			if (item.getAttribute('st_email')!=null && item.getAttribute('st_email').length>1)
				detailsHtml+="<a class=\"email\" href=\"mailto:"+(item.getAttribute('st_email'))+"\">"+email+"</a><br />";
			if (item.getAttribute('st_ext_url')!=null && item.getAttribute('st_ext_url').length>1)
				detailsHtml+="<a class=\"link\" target=\"_blank\" href=\""+(item.getAttribute('st_ext_url'))+"\">"+internet+"</a><br />";
			if (item.getAttribute('st_sv_url')!=null && item.getAttribute('st_sv_url').length>1)
				detailsHtml+="<a class=\"link\" target=\"_blank\" href=\""+(item.getAttribute('st_sv_url'))+"\">Street view</a><br />";				
			if (item.getAttribute('sti_id')!=null)
				detailsHtml+="<a class=\"link\" href=\""+infoLink+"?sti_id="+(item.getAttribute('sti_id'))+"\">"+info+"</a><br /><br />";
		  detailsHtml+="<br /></div>";
		  pos++;
	 }
	 if (subBoxOpen){
			// close it
			detailsHtml+= "</div>";
		}
		setContent('hds_s1_result', detailsHtml);
		showElementById('near_s1_retailers');
	}
	function showSearchResult(_items, _iso2, _zipCode) {
		hideElementById('content_unten');
	    var detailsHtml="";
	    
	    var
	    	subBoxOpen=false;
	    
	    var
	    	pos = 0;
	    
	    for (var i = 0; i < _items.length; i++) {
	    	var
	    		item = _items[i];
	    		
	    	if (_iso2 != null && item.getAttribute('st_iso3166_2') != _iso2 || _zipCode != null && item.getAttribute('st_zipcode').indexOf(_zipCode)==-1)
	    		continue;
	    		
			if (pos%2==0){
				if (subBoxOpen){
					// close it
					detailsHtml+= "</div>";
					subBoxOpen = false;
				}
				// open it
				detailsHtml+= "<div class=\"subbox\">";	
	       		subBoxOpen = true;
			
	       		detailsHtml+="<div class=\"adressbox\">";
	       	}
	       	else
	       		detailsHtml+="<div class=\"adressbox2\">";

	        detailsHtml+="<b>"+(item.getAttribute('st_name'))+"</b>";
	        if (item.getAttribute('distance') != null)
	        	detailsHtml+=" ["+(item.getAttribute('distance'))+"&nbsp;km]";
	        detailsHtml+="<br />";
	        detailsHtml+=(item.getAttribute('st_street'))+"<br />";
	        detailsHtml+="<b>"+(item.getAttribute('st_zipcode'))+" "+(item.getAttribute('st_city'))+"</b><br />";
			if (item.getAttribute('st_phone')!=null)
				detailsHtml+="Tel "+(item.getAttribute('st_phone'))+"<br />";
			if (item.getAttribute('st_fax')!=null && item.getAttribute('st_fax').length>1)
				detailsHtml+="Fax "+(item.getAttribute('st_fax'))+"<br />";
			detailsHtml+="<br />"
			if (item.getAttribute('st_email')!=null && item.getAttribute('st_email').length>1)
				detailsHtml+="<a class=\"email\" href=\"mailto:"+(item.getAttribute('st_email'))+"\">"+email+"</a><br />";
			if (item.getAttribute('st_ext_url')!=null && item.getAttribute('st_ext_url').length>1)
				detailsHtml+="<a class=\"link\" target=\"_blank\" href=\""+(item.getAttribute('st_ext_url'))+"\">"+internet+"</a><br />";
			if (item.getAttribute('st_sv_url')!=null && item.getAttribute('st_sv_url').length>1)
				detailsHtml+="<a class=\"link\" target=\"_blank\" href=\""+(item.getAttribute('st_sv_url'))+"\">Street view</a><br />";				
			if (item.getAttribute('sti_id')!=null)
				detailsHtml+="<a class=\"link\" href=\""+infoLink+"?sti_id="+(item.getAttribute('sti_id'))+"\">"+info+"</a><br /><br />";
		    detailsHtml+="<br /></div>"
		    /*if (pos%2==0)
		    	detailsHtml+="";
		    else
		    	detailsHtml+="</div><div class=\"subbox\">";*/
		    pos++;
		   	if(_iso2!=null && _iso2.indexOf("US-")==0 && pos>1) {
	    		break;
	    	}		    
	    }
	    if (subBoxOpen){
			// close it
			detailsHtml+= "</div>";
		}
		setContent('hds_result', detailsHtml);
		showElementById('near_retailers');
		showElementById('rn_back');
	}

	function changeAlpha2Event(_alpha2){
		alpha2 = _alpha2;
		iso2 = null;
		zipCode = null;
		debug('change alpha2: '+_alpha2);
		buildLists();
	} 
	
	function changeS1Alpha2Event(_alpha2){
		alpha2 = _alpha2;
		iso2 = null;
		zipCode = null;
		debug('change alpha2: '+_alpha2);
		showS1HDS();
	} 
		
	function changeIso2Event(_iso2){
		iso2 = _iso2;
		zipCode = null;
		debug('change iso2: '+iso2);
		
		if (alpha2 != 'DE')
			showSearchResult(xmlStores, iso2, null);
		else
			showZipCodes(iso2, null);
		
	} 
	function changeZipCodeEvent(_zipCode){
		zipCode = _zipCode;
		debug('change zipcode: '+zipCode);
		showZipCodes(iso2, zipCode);
		
		if (alpha2 == 'DE')
			showSearchResult(xmlStores, iso2, zipCode);
	} 

	function showZipCodes(_iso2, _zipcode){
		 	var zipcodesHtml="";
		 	if (xmlRegions!=null){
		 		var items = xmlRegions;
		 		for (var i = 0; i < items.length; i++) {
		 			if (items[i].getAttribute('zn_iso3166_2')==_iso2){
		 				var zipcodes=items[i].firstChild.childNodes;
		 				for (var j=0;j<zipcodes.length;j++){
		 					var zip=zipcodes[j].attributes[0].nodeValue;
		 					zipcodesHtml+="<a "+((zip==_zipcode)?"class=\"activezip\"":"")+" href=\"javascript:rn.changeZipCodeEvent('"+zip+"');\">"+zip+"</a>";
		 				}
		 			}
		 		}
		 	}
		setContent('zipcodelist', zipcodesHtml);
	    showElementById('zipcodes');
	}			
	function hideZipCodes(){
		hideElementById('zipcodes');
	}

	
	function hideResellers(){
		hideElementById('near_retailers');
		hideElementById('rn_back');
		showElementById('content_unten');
		hideElementById('link_reset');
		showElementById('link_search');
	}
	function back(){
		hideResellers();
		setDisplayBlockOrNoneById('city_zip_list', false);
		setDisplayBlockOrNoneById('city_zip', true);
		hideMultipleMessage();
		hideNoResult();
		hideError();
	}

	function onEnterSearch(_form, _event){
		var charCode = getKeyCode(_event);
		if(charCode == 13){ 
			_form.submit();
			return true;
		}
		return false;
	}
}