google.load("jquery", "1.4");
google.setOnLoadCallback(function() {
	update();
});
function update(){
	var url = "http://www.babe-kiss.com/forum/lifem/ajax.php?type=json&action=checklogin&callback=?";
	$("#ajaxloading").show();
	$("#content").hide();
	$.getJSON(url, function(json){
		if(json.logined=='0'){
			$("#msgrecv").html('Guest');
			$("#menu").html(' | <a href="login.html">按此登入</a> | <a href="reg.html">登記會員</a> |');
		}else if(json.logined=='1'){
			$("#msgrecv").html(json.username+' 現有積分 : '+json.point+' 分');
			$("#menu").html(' | <a href="profile.html">會員資料</a> | <a href="#" onclick="loginout()">退出系統</a> |');
		}
		$("#ajaxloading").hide();
		$("#content").show();
	});
}
function submit(){
	var url = "http://www.babe-kiss.com/forum/lifem/ajax.php?type=json&action=submit&callback=?";
	var data = {username:$("#username").val(),password:$("#password").val(), email:$("#email").val()};
	$.getJSON(url,data, function(json){
		if(json.status=='0'){
			alert('已完成登記 正在返回首頁')
			window.location="index.html";
		}else if(json.status=='1'){
			$("#msg").html("申請失敗<br><br />Email 格式錯誤 請重新輸入");
		}else if(json.status=='2'){
			$("#msg").html("申請失敗<br><br />會員名稱 格式錯誤 請重新輸入");
		}else if(json.status=='3'){
			$("#msg").html("申請失敗<br><br />會員密碼 格式錯誤 請重新輸入");
		}else if(json.status=='4'){
			$("#msg").html("申請失敗<br><br />會員名稱已被使用 請輸入新的會員名稱");
		}else if(json.status=='5'){
			$("#msg").html("申請失敗<br><br />電子郵件地址已被使用 請輸入新的電子郵件地址");
		}
	});
}
function loginin(){
	var url = "http://www.babe-kiss.com/forum/lifem/ajax.php?type=json&action=loginin&callback=?";
	var data = {username:$("#username").val(),password:$("#password").val()};
	$.getJSON(url,data, function(json){
		if(json.status=='0'){
			alert('登入成功 正在返回首頁')
			window.location="index.html";
		}else if(json.status=='1'){
			$("#msg").html("登入失敗<br><br />會員名稱 格式錯誤 請重新輸入");
		}else if(json.status=='2'){
			$("#msg").html("登入失敗<br><br />會員密碼 格式錯誤 請重新輸入");
		}else if(json.status=='3'){
			$("#msg").html("登入失敗<br><br />會員名稱 或 密碼錯誤");
		}else if(json.status=='4'){
			$("#msg").html("登入失敗<br><br />此會員名稱不存在");
		}
	});
}
function loginout(){
	var url = "http://www.babe-kiss.com/forum/lifem/ajax.php?type=json&action=loginout&callback=?";
	$.getJSON(url, function(){
		update()
	});
}
function submitprofile(){
	var url = "http://www.babe-kiss.com/forum/lifem/ajax.php?type=json&action=submitprofile&callback=?";
	var data = {id:$("#uid").val(),tel:$("#telphone").val(),mobile:$("#mobile").val(),password:$("#password").val(), email:$("#email").val()};
	$.getJSON(url,data, function(json){
		if(json.status=='0'){
			alert('修改完成 正在返回首頁')
			window.location="index.html";
		}else if(json.status=='1'){
			$("#msg").html("修改失敗<br><br />Email 格式錯誤 請重新輸入");
		}else if(json.status=='2'){
			$("#msg").html("修改失敗<br><br />會員密碼 格式錯誤 請重新輸入");
		}else if(json.status=='3'){
			$("#msg").html("修改失敗<br><br />電子郵件地址已被使用 請輸入新的電子郵件地址");
		}else if(json.status=='4'){
			$("#msg").html("修改失敗<br><br />家用電話 格式錯誤 請重新輸入");
		}else if(json.status=='5'){
			$("#msg").html("修改失敗<br><br />手提電話 格式錯誤 請重新輸入");
		}
	});
}
function getprofile(){
	var url = "http://www.babe-kiss.com/forum/lifem/ajax.php?type=json&action=getprofile&callback=?";
	$.getJSON(url, function(json){
		$("#uid").val(json.id);
		$("#username").val(json.username);
		$("#email").val(json.email);
		$("#telphone").val(json.tel);
		$("#mobile").val(json.mobile);
	});
}