function changeCarriers(selcountry){
	clearCarrierAndDevice();			
	var country_id = selcountry.options[selcountry.selectedIndex].value;
	var carrierRequest = new Request({
		method: 'get',
		url: 'eaRequests.php',
		onSuccess: function(txt){
			document.getElementById('carrier').innerHTML = txt;
		}
	});
	carrierRequest.send('country_id='+country_id);
}

function changeDevices(selcountry, selcarrier){
	clearDevices();
	var country_id = selcountry.options[selcountry.selectedIndex].value;
	var carrier_id = selcarrier.options[selcarrier.selectedIndex].value;
	var deviceRequest = new Request({
		method: 'get',
		url: 'eaRequests.php',
		onSuccess: function(txt){
			document.getElementById('device').innerHTML = txt;
		}
	});
	deviceRequest.send('carrier_id='+carrier_id);
}

function changeImage(url) {
	var obj = document.getElementById('deviceImage');
	obj.innerHTML = '';
	obj.style.background = "url(\'" + url + "\') no-repeat center center";
}

function changeSelectedImage(selobj) {
	var url = selobj.options[selobj.selectedIndex].getAttribute('image');
	var obj = document.getElementById('deviceImage');
	obj.innerHTML = '';
	obj.style.background = "url(\'" + url + "\') no-repeat center center";
}

function clearCarrierAndDevice(){
	var carrier = document.getElementById('carrier_select');
	carrier.length = 0;
	clearDevices();
}

function clearDevices(){
	var device = document.getElementById('device_select');
	device.length = 0;
}

function submitEAInfo(){
	var country_id = document.getElementById('country_select').options[document.getElementById('country_select').selectedIndex].value;
	var carrier_id = document.getElementById('carrier_select').options[document.getElementById('carrier_select').selectedIndex].value;
	var device_id = document.getElementById('device_select').options[document.getElementById('device_select').selectedIndex].value;
	
	var gameRequest = new Request.HTML({
		url: 'gamegrid.php?javascript=on',
		encoding: 'iso-8859-1',
		onSuccess: function(tree, elmt, txt, js){
			document.getElementById('step2').innerHTML = txt;
		}
	});
	gameRequest.post($('ea_info'));
	// if this works, return false to stop the normal form submit process
	return false;
}

function getGameInfo(product_id){
	var gameInfoRequest = new Request.HTML({
		url: 'gameinfo.php',
		encoding: 'iso-8859-1',
		onSuccess: function(tree, elmt, txt, js){
			var popup = document.getElementById('popup');
			popup.innerHTML = txt;
			document.getElementById('country_select').style.visibility = 'hidden';
			document.getElementById('carrier_select').style.visibility = 'hidden';
			document.getElementById('device_select').style.visibility = 'hidden';
			window.scrollTo(0,0);
			
			var popupFx = new Fx.Morph('popup').set({
				'display': 'block'
			});
		}
	});
	gameInfoRequest.get({'product_id': product_id, 'javascript': 'on'});
	return false;
}

function closePopup(){
	document.getElementById('country_select').style.visibility = 'visible';
	document.getElementById('carrier_select').style.visibility = 'visible';
	document.getElementById('device_select').style.visibility = 'visible';
	document.getElementById('popup').style.display = 'none';
}