﻿
//==============BEGIN COMMON Functions-=====================
$(document).ready(function () {
	$.post("/LoginBox", {}, function (data) {
		//alert(data);
		$("#loginBox1").html(data);
	});

});



function top() {
	document.documentElement.scrollTop = top;
}

function getCookie(c_name) {

	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1
			c_end = document.cookie.indexOf(";", c_start)
			if (c_end == -1) c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end))
		}
	}
	return ""
}

function setCookie(c_name, value, expiredays) {
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
}



//=================END COMMOM Function===================


//================BEGIN  Login======================



function changelmage() {
	document.getElementById("imgRandom").src = document.getElementById("imgRandom").src + '?';
}

function submits() {
	if (event.keyCode == 13) {
		$("#submitlogin").click();
	}
}

function submit_onclick() {
	$("#spanMsg").hide();

	var txt_username = $.trim($("#txt_username").val());
	var txt_password = $.trim($("#txt_password").val());

	if (txt_username.length == 0) {
		$("#spanUsername").show();
		$("#txt_username").focus();
		return false;
	}

	if (txt_password.length == 0) {
		$("#spanPassword").show();
		$("#txt_password").focus();
		return false;
	}



	$("#submitlogin").hide();
	$("#progressBar").show();

	$.post("/UserLogin", { txt_username: txt_username, txt_password: txt_password }, function (data) {
		if (data == "ok") {
			window.location.reload();
		}
		else {
	
			$("#spanMsg").show();
			$("#spanMsg").html(data);
			$("#spanMsg").css("background-color", "#ff0000");
			$("#spanMsg").animate({ backgroundColor: "#ffffff" }, 500);


			var marginLeft = 1 * $("#TB_window").css("margin-left").replace("px", "");
			thickBoxShakeStepTimeHandle = setInterval("thickBoxShakeStep(" + marginLeft + ");", 20);


		}

		$("#submitlogin").show();
		$("#progressBar").hide();
	});
}


function logout() {
	$.post("/logout", {}, function (data) {
		if (data == "ok") {
			window.location.reload();
		}
		else { }
	});
		
}

//End  Login======================

//=========================BEGIN Register=====================


function initRegister() {
	//注册事件
	$("#btn_register").click(function () {


		var txt_userName = $.trim($("#txt_userName").val());
		var txt_Pass = $.trim($("#txt_Pass").val());
		var txt_Pass2 = $.trim($("#txt_Pass2").val());
		var txt_Code = $.trim($("#txt_Code").val());
		var txt_Name = $.trim($("#txt_Name").val());
		var txt_email = $.trim($("#txt_email").val());

		$("#btn_register").hide();
		$("#progressBar").show();


		$.post("/UserRegists", { txt_Name: txt_Name, txt_userName: txt_userName, txt_email: txt_email, txt_Pass: txt_Pass, txt_Pass2: txt_Pass2, txt_Code: txt_Code }, function (data) {
			if (data.substring(0, 2) == "ok") {
				var userID = data.substring(3);
				alert("注册成功！");
				window.location.reload();
			}
			else {
				$("#spanMsg").show();
				$("#spanMsg").html(data);
				$("#spanMsg").css("background-color", "#ff0000");
				$("#spanMsg").animate({ backgroundColor: "#ffffff" }, 500);

				changelmage();
			}

			$("#btn_register").show();
			$("#progressBar").hide();
		});
	});
}

//



function submit() {
	if (event.keyCode == 13) {
		$("#btn_register").click();
	}
}





//=================END register==================



