function affiliateUpdateBalance()
{
	$('#balance').hide();
	$('#balance').fadeIn('slow');
	$.ajax({
		type:		"GET",
		url:		"/manager/affiliate/ajax/ajax_balance.php?pending",
		success: 	function(data) {
			$('#balance_pending').html(data);		
		}
	});
	$.ajax({
		type:		"GET",
		url:		"/manager/affiliate/ajax/ajax_balance.php?approved",
		success: 	function(data) {
			$('#balance_approved').html('+ ' + data);	
		}
	});
	$.ajax({
		type:		"GET",
		url:		"/manager/affiliate/ajax/ajax_balance.php?available",
		success: 	function(data) {
			$('#balance_available').html('+ ' + data);	
		}
	});
	$.ajax({
		type:		"GET",
		url:		"/manager/affiliate/ajax/ajax_balance.php?total",
		success: 	function(data) {
			$('#balance_total').html('= ' + data);	
		}
	});
}
function affiliateSendMail()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/affiliate/ajax/ajax_sendmail.php', {
		merchant_id:	$('#merchant_id').val(),
		title:			$('#title').val(),
		message:		$('#message').val()
	},
	function (data) {
		$('#submit').html('<input type="submit" value="Skicka" />');
		if (data == 'true') {
			$('#error_message').hide();
			$('#ok_message').hide();
			$('#ok_message').fadeIn('slow');
		} else {
			$('#ok_message').hide();
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);			
		}
	});
}
function affiliateShowPrograms()
{
	$('#programs').show();
	$('#programs').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_programs.php', {
		category: 			$('#category').val(),
		partner:			$('#partner').val(),
		compensation:		$('#compensation').val()
	},
	function (data) {
		$('#programs').html(data);
	});
}
function affiliateShowPrograms2()
{
	$('#programs').show();
	$('#programs').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_programs.php', {
		category: 			0,
		partner:			0,
		compensation:		0
	},
	function (data) {
		$('#programs').html(data);
	});
}
function affiliateBannercode(banner_id)
{
	$('#banner_' + banner_id).toggle();
	$('#box_banner_' + banner_id).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_bannercode.php', {
		banner_id: banner_id
	},
	function (data) {
		$('#box_banner_' + banner_id).html(data);
	});
}
function affiliateShowBannerCode1(banner_id, link)
{
	link = link.replace('[PARAMETER]', '');
	link = link.replace('[SUBLINK]', '');
	link = link.replace('[TARGET]', '_blank');
	var bannercode = link;
	affiliateShowBannerCode2(banner_id, bannercode);
}
function affiliateShowBannerCode2(banner_id, bannercode)
{
	$('#bannercode_' + banner_id).val(bannercode);
}
function affiliateShowBanners()
{
	$('#banners').show();
	$('#banners').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_banners.php', {
		type:	$('#type').val(),
		format:	$('#format').val()
	},
	function (data) {
		$('#banners').html(data);
	});
}
function affiliateAddBannerRotation()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/affiliate/ajax/ajax_addbannerrotation.php', {
		title:		$('#title').val(),
		format:		$('#format').val()
	},
	function (data) {
		$('#submit').html('<input type="submit" value="Skapa" />');
		if (data == 'true') {
			alert('Annonsrotation skapad!');
			document.location = '/manager/affiliate/program-samarbeten/annonsrotation/';
		} else {
			$('#ok_message').hide();
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);			
		}			
	});
	
}
function affiliateRemoveBannerRotation(id)
{
	$('#br_' + id).fadeOut('slow');
	$.post('/manager/affiliate/ajax/ajax_removebannerrotation.php', {
		id: id
	});
}
function affiliateShowRotateBannerCode(id)
{
	$('#banner_' + id).toggle();
	$('#box_banner_' + id).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_rotatebannercode.php', {
		rotate_id: id
	},
	function (data) {
		$('#box_banner_' + id).html(data);
	});
}
function affiliateShowStatisticsOverview()
{
	$('#statistics').show("show");
	$('#statistics').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_statistics_overview.php', {
		period: $('#period').val()
	},
	function (data) {
		$('#statistics').html(data);
	});
}
function affiliateShowStatisticsDetailed()
{
	$('#statistics').show("show");
	$('#statistics').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_statistics_detailed.php', {
		period: $('#period').val()
	},
	function (data) {
		$('#statistics').html(data);
	});
}
function affiliateShowStatisticsDetailedProgram(id,start_date,end_date)
{
	$('#program_' + id).toggle();
	$('#box_program_' + id).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_statistics_detailed_program.php', {
		merchant_id: 	id,
		start_date:		start_date,
		end_date:		end_date
	},
	function (data) {
		$('#box_program_' + id).html(data);
	});
}
function affiliateShowStatisticsDetailedDate(id,date)
{
	$('#date_' + date).toggle();
	$('#box_date_' + date).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_statistics_detailed_date.php', {
		merchant_id: 	id,
		date:			date
	},
	function (data) {	
		$('#box_date_' + date).html(data);
	});
}
function affiliateShowStatisticsDetailedHour(id,date,hour)
{
	$('#hour_' + hour).toggle();
	$('#box_hour_' + hour).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/affiliate/ajax/ajax_statistics_detailed_hour.php', {
		merchant_id: 	id,
		date:			date,
		hour:			hour
	},
	function (data) {
		$('#box_hour_' + hour).html(data);
	});
}
function affiliateSettingsPerson()
{
	$('#account_type').val('person');
	$('#company').hide();
	$('#person').fadeIn('slow');
}
function affiliateSettingsCompany()
{
	$('#account_type').val('company');
	$('#person').hide();
	$('#company').fadeIn('slow');
}
function affiliateUpdateAccountSettings()
{
	$('#submit1').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/affiliate/ajax/ajax_settings_account.php', {
		account_type:		$('#account_type').val(),
		persnr:				$('#persnr').val(),
		company_name:		$('#company_name').val(),
		orgnr:				$('#orgnr').val(),
		firstname:			$('#firstname').val(),
		lastname:			$('#lastname').val(),
		address:			$('#address').val(),
		postnr:				$('#postnr').val(),
		city:				$('#city').val(),
		country:			$('#country').val(),
		telephone:			$('#telephone').val()
	},
	function (data) {
		$('#submit1').html('<input type="submit" value="Uppdatera" />');
		if (data == 'true') {
			$('#error_message').hide();
			$('#ok_message').hide();
			$('#ok_message').fadeIn('slow');
		} else {
			$('#ok_message').hide();
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);
		}		
	});
	
}
function affiliateUpdatePassword()
{
	$('#submit2').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/affiliate/ajax/ajax_update_password.php', {
		new_password:		$('#new_password').val(),
		new_password2:		$('#new_password2').val(),
		old_password:		$('#old_password').val()
	},
	function (data) {
		$('#submit2').html('<input type="submit" value="Uppdatera" />');
		if (data == 'true') {
			$('#error_message').hide();
			$('#ok_message').hide();
			$('#ok_message').fadeIn('slow');
		} else if (data == 'false') {
			document.location = "/logout.php";
		} else {
			$('#ok_message').hide();
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);
		}
	});
}
function affiliateUpdateBank()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/affiliate/ajax/ajax_settings_bank.php', {
		bank:			$('#bank').val(),
		clearingnr:		$('#clearingnr').val(),
		bank_account:	$('#bank_account').val(),
		info:			$('#info').val()
	},
	function (data) {
		$('#submit').html('<input type="submit" value="Uppdatera" />');
		if (data == 'true') {
			$('#error_message').hide();
			$('#ok_message').hide();
			$('#ok_message').fadeIn('slow');
		} else {
			$('#ok_message').hide();
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);
		}			
	});
}
function affiliateAddWebsite()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/affiliate/ajax/ajax_addwebsite.php', {
		category:		$('#category').val(),
		website_url:	$('#website_url').val(),
		description:	$('#description').val()
	},
	function (data) {
		if (data == 'true') {
			document.location = "/manager/affiliate/installningar/mina-webbplatser/";
		} else {
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);
			$('#submit').html('<input type="submit" value="Lägg till" />');
		}
	});
}
function affiliateDeleteWebsite(id)
{
	$.get('/manager/affiliate/ajax/ajax_deletewebsite.php', {
		website_id: id
	},
	function (data) {
		$('#website_' + id).fadeOut('slow');
	});
}
function affiliateProgramApply(id)
{
	$('#apply').hide();
	$('#loading').show();
	$.post('/manager/affiliate/ajax/ajax_program_apply.php', {
		merchant_id: id
	},
	function (data) {
		$('#loading').hide();
		if (data == 'a') {
			$('#ok_message').fadeIn('slow');
			$('#ok_message').html('Ansökningen godkändes direkt.');
		} else if (data == 'm') {
			$('#ok_message').fadeIn('slow');
			$('#ok_message').html('Ansökan har skickats till annonsören.');			
		} else {
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);
		}
	});
}