if($j.cookie('Homepage'))
		document.location = $j.cookie('Homepage');

$j(document).ready(function(){
		
	$j('#Language').change( SelectLanguage );
	
	$j('#Region').change(function(){
		Launch(document.getElementById('LaunchForm'));	
	});
	
	$j('#LaunchForm').submit(function(event){
			event.preventDefault();
			Launch(this);
		});
	
//	flashvars = {};
//	params = {};
//	attributes = {};
	
//	swfobject.embedSWF('/shared/flash/global-entry.swf', 'GlobalFlash', '1000', '500', '9.0.0', null, flashvars, params, attributes);
	
});

//======================================================================================================================

function SelectLanguage(){
	
	$j('#Region').css('display','block');
	
	$j.post('/shared/cs/global_entry_xhr.aspx',
		{cmd: 'GetRegionsByLanguage', Language: this.value},
		function(Data, Code) {
			$j('#Region option[value]').remove();
			$j(Data.Regions).each(function(){
				$j('#Region').append('<option value="' + this + '">' + this + '</option>');
			});
			
		},
		'json'
	);
}

//======================================================================================================================

function Launch(Form){

	$j.post(
		'/shared/cs/global_entry_xhr.aspx', 
		{ cmd: 'ChooseRegion', Region: Form.Region.value, Language: Form.Language.value },
		function(Data) {
			//SubGear.Cookie.set('Region',Data.Region);
			//SubGear.Cookie.set('Language', Data.Language);
			//SubGear.Cookie.set('ProductSelections', Data.ProductSelections);
			document.location = '/' + Data.Culture + '/' + Data.CountryCode + '/home.aspx';
		},
		'json'
	);
}
