$(document).ready(function () {
	// set change handler for city, and do an initial check
	$('#city').change( function(){ checkCreateCity(); } );
	checkCreateCity();

	$("#uri_alias").keyup(function(key_event) {updateURIAlias(key_event.target);});
    $("#uri_alias").change(function(key_event) {updateURIAlias(key_event.target);});

    $('#change_country').hide();
    $('#country').change(function() { changeCountry(); } );

	$('.more_link').click( function(){ return storePopup( this.href ); } );
});

function changeCountry()
{
    submit_button('change_country');
}

function checkCreateCity()
{
	if( $('#city').val() == 0 )
		$('#row_city_new').show();
	else
	{
		$('#row_city_new').hide();
		$('#city_new').val( '' );
	}
}

function storePopup( url ){
	popupWindow = window.open( url, 'popup', 'height=300,width=500' );
	if( window.focus )
		popupWindow.focus();
	return false;
}

function updateURIAlias(element)
{
	$('#url_alias').html(element.value);
}

