function download(id, offsetLeft, offsetTop) {

	$.ajax( {

		type : "GET",

		url : "./access.php?req=download",

		success : function(html) {

			if (html == "denied") {

				$("#content").fadeTo("slow", 0.5);
				
				$('#register').css('left', offsetLeft);
				$('#register').css('top', offsetTop-150);
				$('#register').animate( {

					height : 'show',

					opacity : 'show'

				}, 'slow'

				);

			} else {

				window.location = "downloadFile.php?id=" + id;

			}

		}

	});

}

function login(email) {

	$
			.ajax( {

				type : "GET",

				url : "access.php?req=login&email=" + email,

				success : function(html) {

					if (html == "denied") {

						alert("Please register first");

						$("#signup").click();

						$("#email").val(email);

					} else {

						// alert("answer of
						// reqreq=login&email"+email+":\n"+html);

				$("#content").fadeTo("slow", 1);
				$("#signUpForm").css("display", "none");
				$('#register').animate({
					height : 'hide',
					opacity : 'hide'
				}, 'fast');
				$(".footLine").html("Welcome "+ email+ " <br/><a href='javascript:logout();' class='logout'  ><img src='./images/cross.png' height='12' style='margin-right: 5px;'/>logout</a>");
				/*$("#searchBox").html("<form action='javascript:searchDownloads()'><input type='submit' value='search' style='float: right; font-weight: bold; color: #039; font-size: 12px; margin-right: 20px; background-color: lightgray'/><input style='float: left; margin-right: 10px;' type='text' id='searchWord'/></form><div class='nofloat'>&nbsp;</div>Search downloads.<br/>(Document Number, Download Name, ...)");*/			
			}

		}

			});

}

function logout() {

	$(".logout").unbind('click');
	$.ajax( {
		type : "GET",
		url : "access.php?req=logout",
		success : function(html) {
			alert("You are now loged out. Thank you for your visit.");
			$(".footLine").html("");
			//$("#searchBox").html("Please login to search for specific downloads.<br/><a style='display: inline; font-size: 12px;font-weight: bold' href='javascript:searchLogin();' ><img src='./images/arrow.png' style='margin-right: 5px;'/>Login</a>");
			//$("#searchResults").html("");
		}
	});
}

function register(title,

first,

last,

company,

department,

city,

state,

zip,

country,

email,

phone) {

	var args = "req=register&" +

	"title=" + title + "&" +

	"first=" + first + "&" +

	"last=" + last + "&" +

	"company=" + company + "&" +

	"department=" + department + "&" +

	"city=" + city + "&" +

	"state=" + state + "&" +

	"zip=" + zip + "&" +

	"country=" + country + "&" +

	"email=" + email + "&" +

	"phone=" + phone;

	$
			.ajax( {

				type : "post",

				url : "access.php?" + args,

				success : function(html) {

					if (html == "accepted") {

						$("#formContainerRegister")
								.animate(
										{

											height : 'hide',

											opacity : 'hide'

										},
										'slow',
										'linear',
										function() {// callback after animation
													// is done

											$("#formContainerSuccess").text("Thank you for your registration.");
											$("#formContainerSuccess").css(
													"display", "block");
											$("#registrationForm").css("display","none");

										}

								);

					} else {

						alert(html);

					}

				}

			});

}

