function merchantShowStatisticsAffiliate(id)
{
	$('#statistics').show("show");
	$('#statistics').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/merchant/ajax/ajax_statistics_affiliate.php', {
		affiliate_id:	id,
		period: 		$('#period').val()
	},
	function (data) {
		$('#statistics').html(data);
	});	
}
function merchantAddBannerType()
{
	var type = $('#banner_type').val();
	
	if (type == 'img' || type == 'swf') {
		$('#format').show();
		$('#file').show();
		$('#txt').hide();
		$('#flash_banner').hide();
		if (type == 'swf') {
			$('#flash_banner').show();
		} else {
			$('#extra_tab').show();
		}
	}
	if (type == 'txt') {
		$('#format').hide();
		$('#file').hide();
		$('#txt').show();
		$('#flash_banner').hide();
	}
}
function merchantAddBanner()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/merchant/ajax/ajax_add_banner.php', {
		campaign:			$('#campaign').val(),
		banner_type:		$('#banner_type').val(),
		format:				$('#banner_format').val(),
		data:				$('#banner_data').val(),
		data2:				$('#banner_data2').val(),
		extra:				$('#extra').val(),
		destination_url:	$('#destination_url').val(),
		ownref:				$('#ownref').val()
	},
	function (data) {
		$('#submit').html('<input type="submit" value="Lägg till" />');
		if (data == 'true') {
			$('#error_message').hide();
			$('#ok_message').hide();
			$('#ok_message').fadeIn('slow');
		} else {
			$('#error_message').hide();
			$('#error_message').fadeIn('slow');
			$('#error_message').html(data);
		}
	});
}
function merchantEditBanner()
{
	$('#edit_banner #submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/merchant/ajax/ajax_edit_banner.php', {
		banner_id:			$('#banner_id').val(),
		campaign:			$('#campaign').val(),
		data:				$('#data').val(),
		ownref:				$('#ownref').val(),
		destination_url:	$('#destination_url').val()
	},
	function (data) {
		if (data == 'true') {
			alert('Annonsen uppdaterades!');
			document.location = '/manager/merchant/annonser-kampanjer/alla-annonser/';
		} else {
			$('#edit_banner #error_message').hide();
			$('#edit_banner #error_message').fadeIn('slow');
			$('#edit_banner #error_message').html(data);
			$('#edit_banner #submit').html('<input type="submit" value="Ändra" />');
		}
	});	
}
function merchantAddCampaign(a)
{
	if (a == true) {
		$('#add_campaign #submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	} else {
		$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	}
	$.post('/manager/merchant/ajax/ajax_add_campaign.php', {
		title:			$('#title').val(),
		description:	$('#description').val()
	},
	function (data) {
		if (data == 'true') {
			if (a == 'true') {
				alert('Kampanjen ' + $('#title').val() + ' lades till!');
				document.location = '/manager/merchant/annonser-kampanjer/lagg-till-annons/';
			} else {
				document.location = '/manager/merchant/annonser-kampanjer/kampanjer/';	
			}
		} else {
			if (a == true) {
				$('#add_campaign #error_message').hide();
				$('#add_campaign #error_message').fadeIn('slow');
				$('#add_campaign #error_message').html(data);
				$('#add_campaign #submit').html('<input type="submit" value="Lägg till" />');
			} else {
				$('#error_message').hide();
				$('#error_message').fadeIn('slow');
				$('#error_message').html(data);
				$('#submit').html('<input type="submit" value="Lägg till" />');				
			}
		}
	});
}
function merchantShowStatisticsOverview()
{
	$('#statistics').show("show");
	$('#statistics').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/merchant/ajax/ajax_statistics_overview.php', {
		period: $('#period').val()
	},
	function (data) {
		$('#statistics').html(data);
	});
}
function merchantShowStatisticsDetailed()
{
	$('#statistics').show("show");
	$('#statistics').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/merchant/ajax/ajax_statistics_detailed.php', {
		period: $('#period').val()
	},
	function (data) {
		$('#statistics').html(data);
	});
}
function merchantShowStatisticsDetailedAffiliate(id,start_date,end_date)
{
	$('#affiliate_' + id).toggle();
	$('#box_affiliate_' + id).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/merchant/ajax/ajax_statistics_detailed_affiliate.php', {
		affiliate_id: 	id,
		start_date:		start_date,
		end_date:		end_date
	},
	function (data) {
		$('#box_affiliate_' + id).html(data);
	});
}
function merchantShowStatisticsDetailedDate(id,date)
{
	$('#date_' + date).toggle();
	$('#box_date_' + date).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/merchant/ajax/ajax_statistics_detailed_date.php', {
		affiliate_id: 	id,
		date:			date
	},
	function (data) {	
		$('#box_date_' + date).html(data);
	});
}
function merchantShowStatisticsDetailedHour(id,date,hour)
{
	$('#hour_' + hour).toggle();
	$('#box_hour_' + hour).html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.get('/manager/merchant/ajax/ajax_statistics_detailed_hour.php', {
		affiliate_id: 	id,
		date:			date,
		hour:			hour
	},
	function (data) {
		$('#box_hour_' + hour).html(data);
	});
}
function merchantUpdateAccountSettings()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/merchant/ajax/ajax_update_account_settings.php', {
		firstname:		$('#firstname').val(),
		lastname:		$('#lastname').val(),
		telephone:		$('#telephone').val(),
		fax:			$('#fax').val(),
		company_name:	$('#company_name').val(),
		orgnr:			$('#orgnr').val(),
		address:		$('#address').val(),
		postnr:			$('#postnr').val(),
		city:			$('#city').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 merchantUpdateProgramSettingsApproveEmail()
{
	if ($("#approve_email").val() == "no") {
		$("#approve_email").val("yes");
	} else {
		$("#approve_email").val("no");
	}
}
function merchantUpdateProgramSettingsApproveType()
{
	if ($("#approve_type").val() == "no") {
		$("#approve_type").val("yes");
	} else {
		$("#approve_type").val("no");
	}
}
function merchantUpdateProgramSettingsSendAffiliateEmail()
{
	if ($("#send_affiliate_email").val() == "no") {
		$("#send_affiliate_email").val("yes");
	} else {
		$("#send_affiliate_email").val("no");
	}
}
function merchantUpdateProgramSettings()
{
	var country_sweden 	= 0;
	var country_norway 	= 0;
	var country_denmark = 0;
	var country_finland = 0;
	
	if ($('#country_sweden').attr('checked') == true) {
		var country_sweden = 1; 
	}
	if ($('#country_norway').attr('checked') == true) {
		var country_norway = 1; 
	}
	if ($('#country_denmark').attr('checked') == true) {
		var country_denmark = 1; 
	}
	if ($('#country_finland').attr('checked') == true) {
		var country_finland = 1; 
	}
	
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/merchant/ajax/ajax_update_program_settings.php', {
		country_sweden:			country_sweden,
		country_norway:			country_norway,
		country_denmark:		country_denmark,
		country_finland:		country_finland,
		category:				$('#category').val(),
		program_name:			$('#program_name').val(),
		description:			$('#description').val(),
		destination_url:		$('#destination_url').val(),
		keyword_policy:			$('#keyword_policy').val(),
		incentive_policy:		$('#incentive_policy').val(),
		sublink_policy:			$('#sublink_policy').val(),
		approve_email:			$('#approve_email').val(),
		approve_type:			$('#approve_type').val(),
		send_affiliate_email:	$('#send_affiliate_email').val(),
		affiliate_email:		$('#affiliate_email').val(),
		email_invoice:			$('#email_invoice').val(),
		paper_invoice:			$('#paper_invoice').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 merchantUpdatePassword()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/merchant/ajax/ajax_update_password.php', {
		new_password:		$('#new_password').val(),
		new_password2:		$('#new_password2').val(),
		old_password:		$('#old_password').val()
	},
	function (data) {
		$('#submit').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 merchantSendMail()
{
	$('#submit').html('<img src="/images/loading.gif" alt="" /> Laddar...');
	$.post('/manager/merchant/ajax/ajax_sendmail.php', {
		affiliate_id:	$('#affiliate_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 merchantApproveTransaction(frossle_id,transaction_type,transaction_id)
{
	$.post('/manager/merchant/ajax/ajax_transaction_approve.php', {
		frossle_id:			frossle_id,
		transaction_type: 	transaction_type,
		transaction_id: 	transaction_id
	});
	$('#transaction_' + transaction_id).fadeOut('slow');
}
function merchantDenyTransaction()
{
	$.post('/manager/merchant/ajax/ajax_transaction_deny.php', {
		frossle_id:			$('#frossle_id').val(),
		transaction_type: 	$('#transaction_type').val(),
		transaction_id: 	$('#transaction_id').val(),
		comment:			$('#comment').val()
	});
	$.facebox.close();
	window.location.reload();
}
function merchantUpdateAffiliateCompensation()
{
	$.post('/manager/merchant/ajax/ajax_update_affiliate_compensation.php', {
		affiliate_id:		$('#affiliate_id').val(),
		imp:				$('#imp').val(),
		click:				$('#click').val(),
		lead:				$('#lead').val(),
		sale_flat:			$('#sale_flat').val(),
		sale_procent:		$('#sale_procent').val()
	}, function (data) {
		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 merchantAddSem()
{
	$.post('/manager/merchant/ajax/ajax_add_sem.php', {
		click:		$('#click').val(),
		budget:		$('#budget').val(),
		keywords:	$('#keywords').val()
	}, function (data) {
		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);
		}
	});
}
