$(document).ready(function(){	
	$("#userlogin").submit(function () {			
		$("#Homeprocess").css("display","block");
		$(".HomeLoginButton").css("display","none");
		$(this).delay(500,function(){
			userName = $("#Name").val();
			passWord = $("#Password").val();
			if((userName == "User ID") || (userName == "")) {
				$("#HomeError").css("height","18px");
				$("#HomeError").html("Invalid login, please try again.");
				$("#Homeprocess").css("display","none");
				$(".HomeLoginButton").css("display","block");
			} else if((passWord == "Password") || (passWord == "")) {
				$("#HomeError").css("height","18px");
				$("#HomeError").html("Invalid login, please try again.");
				$("#Homeprocess").css("display","none");
				$(".HomeLoginButton").css("display","block");
			} else {						
				$.ajax({
					method: "get",
					url: homelink+"/otto/loginCheck.php",
					data: ({Name : $("#Name").val(), Password: $("#Password").val()}),
					success:function(html){	
					//alert(html);
							switch (html) {							
							case "admin":
								window.location = homelink+"/otto/Admin/";
								break;
							case "home":
								window.location = homelink+"/otto/home.php?page=admin";
								break;
							case "error1":
								window.location = homelink+"/otto/home.php?page=admin";
								break;
							case "error2":
								$("#HomeError").css("height","18px");
								$("#HomeError").html("Invalid login, please try again.");
								$("#Homeprocess").css("display","none");
								$(".HomeLoginButton").css("display","block");
								break;						
						}
					}	   
				});	
			}			
						   
		});
		return false;	
	});		
	$("#loginSubmit").click(function () {			
		$("#Homeprocess").css("display","block");
		$(".HomeLoginButton").css("display","none");
		$(this).delay(500,function(){
			userName = $("#Name").val();
			passWord = $("#Password").val();
			if((userName == "User ID") || (userName == "")) {
				$("#HomeError").css("height","18px");
				$("#HomeError").html("Invalid login, please try again.");
				$("#Homeprocess").css("display","none");
				$(".HomeLoginButton").css("display","block");
			} else if((passWord == "Password") || (passWord == "")) {
				$("#HomeError").css("height","18px");
				$("#HomeError").html("Invalid login, please try again.");
				$("#Homeprocess").css("display","none");
				$(".HomeLoginButton").css("display","block");
			} else {
				$.ajax({
					method: "get",
					url: homelink+"/otto/loginCheck.php",
					data: ({Name : $("#Name").val(), Password: $("#Password").val()}),
					success:function(html){	
					//alert(html);
						switch (html) {
							case "admin":
								window.location = homelink+"/otto/Admin/";
								break;
							case "home":
								window.location = homelink+"/otto/home.php?page=admin";
								break;
							case "error1":
								window.location = homelink+"/otto/home.php?page=admin";
									break;
							case "error2":
								$("#HomeError").css("height","18px");
								$("#HomeError").html("Invalid login, please try again.");
								$("#Homeprocess").css("display","none");
								$(".HomeLoginButton").css("display","block");
								break;						
						}
					}	   
				});	
			}			
		});
	});
});

function clearn_input() {
	var nameInput = document.getElementById("Name");
	if(nameInput.value == "User ID") {
		nameInput.value = "";
	}
}
function clearn_input_PW() {
	var PWInput = document.getElementById("Password");
	if(PWInput.value == "Password") {
		PWInput.value = "";
	}
}

function password_clear() {	
	//document.loginCheckForm.password.type="password";
	//document.loginCheckForm.password.value="";		
	var input = document.getElementById("Password");
	var input_show = document.getElementById("passwordshow");
	input_show.style.display = "none";
	input.style.display = "";
	input.focus();
}

function showPop() {
	testpopup3.showPopup('anchor3');
	return false;	
}

function formSubmit() {
	document.userlogin.submit();
}