$(document).ready(function() {


	getList();
	showEmailList();
	showDefaultDays();
	
	$("#logout").click( function() {
	
		data = "a=4";
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				window.location.href="index.asp";
			}	
		});
	
	});
	
	$("#showPass").toggle(function() {
		$("#userpass").attr("type","text");
}, function() {
	$("#userpass").attr("type","password");
});

$("#addGratis").click(function() {
		data = "a=17&v1=" + $("#gratisFirstName").val() + ":" + $("#gratisLastName").val() + ":" + $("#gratisEmail").val();
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				getList();
			}	
		});


});







	$("#submitSubject").click( function() {
	data = "a=13&v1=" + $("#emailSubject").val();
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				alert("Welcome email subject successfully updated");
			},	
			error: function() {
				alert("An error occured, please try again");
			}			
		});
	
	});

	$("#submitBody").click( function() {
		//verify that [item] and [link] exist in the text, otherwise return an error
		if ($("#emailBody").val().indexOf('[item]') >= 0 &&  $("#emailBody").val().indexOf('[link]') >= 0)
		{
				data = "a=14&v1=" + escape($("#emailBody").val());
				alert(data);
				   $.ajax({
						type: "GET",
						url: "actions.asp",
						data : data,
						dataType: "html",
						processData : true,
						success: function(data) {
							alert("Welcome email text successfully updated");
						},	
						error: function() {
							alert("An error occured, please try again");
						}			
					});
		} else {
			alert("You must include both the [item] and [link] tags in order to update the email body");
		}	


	});

	$("#submitEmail").click( function() {
	data = "a=8&v1=" + escape($("#emailList").val());
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				showEmailList();
			}	
		});
	
	});
	
	
	$("#submitDays").click( function() {
		data = "a=10&v1=" + $("#defaultDays").val();
		   $.ajax({
				type: "GET",
				url: "actions.asp",
				data : data,
				dataType: "html",
				processData : true,
				success: function(data) {
					showDefaultDays();
				}	
			});
		
	
	});
	
	$("#submitUserName").click( function() {
		data = "a=11&v1=" + $("#username").val();
		   $.ajax({
				type: "GET",
				url: "actions.asp",
				data : data,
				dataType: "html",
				processData : true,
				success: function(data) {
					alert("Username successfully updated");
				},	
			error: function() {
				alert("An error occured, please try again");
			}	
			});
		
	
	});
	
		$("#submitUserPass").click( function() {
		data = "a=12&v1=" + $("#userpass").val();
		   $.ajax({
				type: "GET",
				url: "actions.asp",
				data : data,
				dataType: "html",
				processData : true,
				success: function(data) {
					alert("Password successfully updated");
				},	
			error: function() {
				alert("An error occured, please try again");
			}		
			});
		
	
	});
	
		$("#submitIP").click( function() {
		data = "a=16&v1=" + $("#IPfraud").val();
		   $.ajax({
				type: "GET",
				url: "actions.asp",
				data : data,
				dataType: "html",
				processData : true,
				success: function(data) {
				alert("success");
				}	
			});
		
	
	});





});


function killThis(target)
{
	data = "a=2&v1=" + target;
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
			}	
		});
		getList();

}

function deleteThis(target)
{
	data = "a=15&v1=" + target;
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
			}	
		});
		getList();

}

function extendThis(target)
{


	data = "a=5&v1=" + target;
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
			}	
		});
		getList();

}
	
	
function getList() {

	data = '';
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : "a=1",
			dataType: "html",
			processData : true,
			success: function(data) {
				$('#aData').html(data);
			}	
		});
}	

function viewLogins(target) {


	data = "a=3&v1=" + target;
	respTarget = "#logins" + target;
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				alert(data);
			},	
			error: function() {
				alert("No logins have been recorded for this account");
			}
		});
}	

function showInfo(target)
{
	data = "a=6&v1=" + target;
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				alert(data);
			},	
			error: function() {
				alert("No other information is available for this account");
			}
		});
}

function showEmailList()
{
	data = "a=7"
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				$('#emailList').val(data)
			},	
			error: function() {
				$('#emailList').val("ERR");
			}
		});
}

function showDefaultDays()
{
	data = "a=9"
	   $.ajax({
			type: "GET",
			url: "actions.asp",
			data : data,
			dataType: "html",
			processData : true,
			success: function(data) {
				$('#defaultDays').val(data)
			},	
			error: function() {
				$('#defaultDays').val("ERR");
			}
		});
}

