function changeCity(obj) {
	var alt = document.getElementById('city_alternative');
	if (obj.name == 'city_id') {
		alt.style.display = (obj.value == 0) ? 'block' : 'none';
	}
}


function window_opener_s(w,h,page,pagename){
	if (typeof(pagename) == 'undefined')
	 pagename='openedpage';
	//ah = available screen height, aw = available screen width
	var ah = screen.availHeight
	var aw = screen.availWidth
	//ph - where the window horizontal top will be positioned to
	//pw - where the window left edge will be positioned to
	var ph = ah/2-(h/2)
	var pw = aw/2-(w/2)
	
	return window.open(page,pagename,'width='+w+',height='+h+',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,left='+pw+',top='+ph);
}


function getDispalyStyle(){
    myUserAgent = navigator.userAgent.toLowerCase();
    
	if(myUserAgent.indexOf("msie") > 0){
		return "block";
	}else{
		return "table-row";
	}
}


function addOnContryChange(){	
	var country_id = document.forms.user_form['country_id'];	
	var city_id = document.forms.user_form['city_id'];	
	var city    = document.forms.user_form['city'];	
	var cityText = document.getElementById("city_text");
	var citySelect = document.getElementById('city_select');	
	var remove_old_town = false;
	
    country_id.onchange = function(){
    	if (countries[this.value] != null){			    		
    		citySelect.style.display = 'block';           
	    	cityText.style.display = 'none';      
//    		city.value = '';
    
			cities =  countries[this.value];
			//remove old sities
			options_to_remove = Array();
			for(i = 0; i < city_id.options.length; i++){											
				options_to_remove[i] = city_id.options[i];
			}
			for(i = 0; i < options_to_remove.length; i++){							
				city_id.remove(options_to_remove[i]);
			}
			//adding new cities
			option = new Option();
			option.value = "-2";
			option.text  = "Select";
			try {
				city_id.add (option,null); // standards compliant; doesn't work in IE
			} catch(ex) {
				city_id.add (option, city_id.options.length); // IE only
			}			
//			city_id.add (option, city_id.options.length);

			for(i = 0; i < cities.length-1; i++){
				option = new Option();
				option.value = cities[i+1][0];
				option.text  = cities[i+1][1];
				try {
					city_id.add (option,null); // standards compliant; doesn't work in IE
				} catch(ex) {
					city_id.add (option, city_id.options.length); // IE only
				}			
//				city_id.add (option, city_id.options.length);

				if (default_city_id == option.value){
					option.selected = true;
				}
			}
    	}else{
    		citySelect.style.display = 'none';           
	    	cityText.style.display = 'block';        
	    	if (remove_old_town){
//	    		city.value = '';
	    		remove_old_town = false;
	    	}
    	}
    }

	var customCity = city.value;
	var flag = false;
	city_id.onchange = function(){

		if (countries[country_id.value]){
			isOtherTown = false;
   			for(i = 0; i < cities.length-1; i++){
				if((this.value == cities[i+1][0]) && cities[i+1][2]){
					isOtherTown = true; // если выбрано "Другие города"
				}
			}
			if (isOtherTown) // если выбрано "Другие города"
			{
			   	cityText.style.display = 'block';  
				city.value = customCity;
				flag = true;
			} else {
		    	cityText.style.display = 'none';  
				if (flag)
				{
					flag = false;
					customCity = city.value;
				}
		    	city.value = this.options[this.selectedIndex].text;   
		    	if (this.value == -2) city.value = "";
			}
		}

/*		if (countries[country_id.value]){
    		cities =  countries[country_id.value];
			falge = false;
    		for(i = 0; i < cities.length-1; i++){
				if((this.value == cities[i+1][0]) && cities[i+1][2]){
					falge = true;
				}
			}

	    	if (falge){			    		
		    	cityText.style.display = 'block';  
		    	city.value = "";    
	    	}else{
		    	cityText.style.display = 'none';        
		    	if (this.value == -2){
			    	city.value = "";
			    }else{
			    	city.value = this.options[this.selectedIndex].text;   
			    	remove_old_town = true;			    
			   	}
	    	}
    	}*/
    }
}