function sendSubscribeEmail()
{
	$('send_subscribe_email_button').set('disabled', true);
	
	var data = 'email='+encodeURIComponent($('subscribe_email').value);

	var req = new Request.JSON({
		method: 'post',
		url: PF_ROOT_URL+'/thankyou/ajaxsendsubscribeemail',
		data: data,
		onSuccess: function(response) {
			if (response) {
				if (response.result == 'error') {
					showNotification('error', response.msg);
				} else if (response.result == 'success'){
					window.location=response.redirect;
				}
				
				$('send_subscribe_email_button').set('disabled', false);
			}
		}						
	}).send();
}

function postIt()
{
	$('post_it_button').set('disabled', true);
	
	var data;
	if (GET['mloc']) {
		data = 'country='+encodeURIComponent($('manual_country').value);
		data += '&region='+encodeURIComponent($('manual_region').value);
		data += '&city='+encodeURIComponent($('manual_city').value);
	} else {
		data = 'country='+encodeURIComponent($('auto_country').value);
		data += '&region='+encodeURIComponent($('auto_region').value);
		data += '&city='+encodeURIComponent($('auto_city').value);
	}
	
	data += '&price='+encodeURIComponent($('price').value);
	data += '&amount='+encodeURIComponent($('amount').value);
	data += '&quality='+encodeURIComponent($('quality').value);
	data += '&recaptcha_response_field='+encodeURIComponent($('recaptcha_response_field').value);
	data += '&recaptcha_challenge_field='+encodeURIComponent($('recaptcha_challenge_field').value);
	
	var req = new Request.JSON({
		method: 'post',
		url: PF_ROOT_URL+'/index/ajaxpostit',
		data: data,
		onSuccess: function(response) {
			if (response) {
				if (response.result == 'error') {
					showNotification('error', response.msg);
					Recaptcha.reload();
				} else if (response.result == 'success'){
					window.location=response.redirect;
				}
				
				$('post_it_button').set('disabled', false);
			}
		}						
	}).send();
}

function updateManualRegions(country)
{
	$('manual_region').set('disabled', true);
	$('manual_city').set('disabled', true);

	var data = 'country='+encodeURIComponent($('manual_country').value);

	var req = new Request.JSON({
		method: 'post',
		url: PF_ROOT_URL+'/index/ajaxgetregionsbycountry',
		data: data,
		onSuccess: function(response) {
			if (response) {
				if (response.result == 'error') {
					showNotification('error', response.msg);
				} else if (response.result == 'success'){
					$('manual_region').empty();
					$('manual_city').empty();
					
					var html = '<option value="">Select Region</option>';
					for(var i=0; i<response.regions.length; i++) {
						html += '<option value="'+response.regions[i]['name']+'">'+response.regions[i]['name']+'</option>';
					}
					
					$('manual_region').innerHTML = html;
					$('manual_city').innerHTML = '<option value="">Select City</option>';
				}
			}
			$('manual_region').set('disabled', false);
			$('manual_city').set('disabled', false);
		}						
	}).send();
}

function updateManualCities(country, region)
{
	$('manual_city').set('disabled', true);
	
	var data = 'country='+encodeURIComponent($('manual_country').value);
	data += '&region='+encodeURIComponent($('manual_region').value);

	var req = new Request.JSON({
		method: 'post',
		url: PF_ROOT_URL+'/index/ajaxgetcitiesbyregion',
		data: data,
		onSuccess: function(response) {
			if (response) {
				if (response.result == 'error') {
					showNotification('error', response.msg);
				} else if (response.result == 'success'){
					$('manual_city').empty();
					
					var html = '<option value="">Select City</option>';
					for(var i=0; i<response.cities.length; i++) {
						html += '<option value="'+response.cities[i]['name']+'">'+response.cities[i]['name']+'</option>';
					}
					
					$('manual_city').innerHTML = html;
				}
			}
			$('manual_city').set('disabled', false);
		}						
	}).send();
}
