function check_login_name(obj)
{
	var obj1 = document.getElementById("err_email");
	if(obj.value == "")
	{
		obj1.innerHTML = _ERR_MAIL_FORMAT;
		return true;
	}
	if(!StringChecker(obj.value, "trim=all,strlvl=7,length=100,empty=no,return=boolen", obj))
	{
		obj1.innerHTML = _ERR_MAIL_FORMAT;
		obj.select();
		obj.focus();
		return false;
	}
	xml_file = "?act=check_login_name&email=" + obj.value;
	makeRequest2(ajax_check_login_name);
}
function ajax_check_login_name()
{
	var HtmlCode="", str, xmldoc, root_node;
	var NodeID, SortID, ParentID, NodeName;
  if (http_request2.readyState == 4)
	{
    if (http_request2.status == 200)
		{
			xmldoc = http_request2.responseXML;
			root_node = xmldoc.getElementsByTagName('count').item(0);
			var n = parseInt(root_node.firstChild.data, 10);
			var obj1 = document.getElementById("err_email");
			if(n > 0)
			{
				obj1.innerHTML = _ERR_MAIL_EXISTED;
				PasswordIsUsed = true;
			}
			else
			{
				obj1.innerHTML = _ERR_MAIL_OK;
				EmailIsUsed = false;
			}
 	  }
		else
		{
      //alert("There was a problem with the request.");
    }
 	}
}
function check_pet_name(obj)
{
	var obj1 = document.getElementById("err_petname");
	if(obj.value == "")
	{
		obj1.innerHTML = _ERR_PETNAME_FORMAT;
		return true;
	}
	if(!StringChecker(obj.value, "trim=all,strlvl=8,length=100,empty=no,return=boolen", obj))
	{
		obj1.innerHTML = _ERR_PETNAME_FORMAT;
		obj.select();
		obj.focus();
		return false;
	}
	s = word_encode(obj.value);
	xml_file = "?act=check_pet_name&petname=" + s;
	makeRequest2(ajax_check_pet_name);
}
function ajax_check_pet_name()
{
	var HtmlCode="", str, xmldoc, root_node;
	var NodeID, SortID, ParentID, NodeName;
  if (http_request2.readyState == 4)
	{
    if (http_request2.status == 200)
		{
			xmldoc = http_request2.responseXML;
			root_node = xmldoc.getElementsByTagName('count').item(0);
			var n = parseInt(root_node.firstChild.data, 10);
			var obj1 = document.getElementById("err_petname");
			if(n > 0)
			{
				obj1.innerHTML = _ERR_PETNAME_EXISTED;
				PetNameIsUsed = true;
			}
			else
			{
				obj1.innerHTML = _ERR_PETNAME_OK;
				PetNameIsUsed = false;
			}
 	  }
		else
		{
      //alert("There was a problem with the request.");
    }
 	}
}
function ajax_set_mydata()
{
	var HtmlCode="", str, xmldoc, root_node, FieldName;
  if (http_request.readyState == 4)
	{
    if (http_request.status == 200)
		{
			xmldoc = http_request.responseXML;
			root_node = xmldoc.getElementsByTagName('count').item(0);
			var n = parseInt(root_node.firstChild.data, 10);
			root_node = xmldoc.getElementsByTagName('FieldName').item(0);
			FieldName = root_node.firstChild.data;
			if(FieldName == "PetName")
			{
				if(n == 0)
				{
					var obj = document.dataFrm.PetName;
					alert(_MSG_PETNAME_IS_EXISTED);
					nowPetName = oldPetName;
					obj.value = oldPetName;
					obj.focus();
				}
				else
				{
					oldPetName = nowPetName;
				}
			}
 	  }
		else
		{
      //alert("There was a problem with the request.");
    }
 	}
}
function set_offline()
{
	xml_file = "?act=set_offline";
	makeRequest2(ajax_set_offline);
}
function set_online()
{
	windowWidth =(document.all)?document.body.offsetWidth-21:innerWidth;
	windowHeight =(document.all)?document.body.offsetHeight-4:innerHeight;
	_page_deamon1();
	_page_deamon2();
	check_message_online();
	xml_file = "?act=set_online";
	makeRequest2(ajax_set_offline);
}
function ajax_set_offline()
{
	var HtmlCode="", str, xmldoc, root_node;
	try
	{
		if (http_request2.readyState == 4)
		{
			if (http_request2.status == 200)
			{
				xmldoc = http_request2.responseXML;
				root_node = xmldoc.getElementsByTagName('count').item(0);
				var n = parseInt(root_node.firstChild.data, 10);
				//OK
			}
			else
			{
				//alert("There was a problem with the request.");
			}
		}
	}
	catch (e){
		//OK
	}
}
function check_message_online()
{
	var obj = document.getElementById("MessageDiv");
	if(obj)
	{
		if(msg_count > 0)
		{
				var x = document.msgFrm;
				msg_count --;
				document.getElementById("msgIP").innerHTML = msg_list[msg_count].IPAddr;
				document.getElementById("msgPetName").innerHTML = msg_list[msg_count].PetName;
				x.DataID.value = msg_list[msg_count].DataID;
				x.UID.value = msg_list[msg_count].UID;
				x.IPAddr.value = msg_list[msg_count].IPAddr;
				x.receiveMsg.value = msg_list[msg_count].MsgString;
				x.replyMsg.value = "";
				var str = msg_list[msg_count].PetName;
				if(msg_list[msg_count].IPAddr == "")
				{
					document.getElementById("msgSender").innerHTML = str;
					x.Close_Message.disabled = true;
					x.IP_Deny.disabled = true;
					document.getElementById("msgFromStr").innerHTML = _MSG_TO_STRING;
				}
				else
				{
					document.getElementById("msgSender").innerHTML = str + " (" + msg_list[msg_count].IPAddr + ")";
					document.getElementById("msgFromStr").innerHTML = _MSG_FROM_STRING;
					x.Close_Message.disabled = false;
					x.IP_Deny.disabled = false;
				}
				sw_message = true;
				display_message_board();
		}
		else if(!sw_message)
		{
			xml_file1 = "?act=check_message_online";
			makeRequest1(ajax_check_message_online);
		}
	}
}

function ajax_check_message_online()
{
	var HtmlCode="", str, xmldoc, root_node, n, i;
	var DataID, FID, PetName, IPAddr, MsgString;
  if (http_request1.readyState == 4)
	{
    if (http_request1.status == 200)
		{
			xmldoc = http_request1.responseXML;
			root_node = xmldoc.getElementsByTagName('count').item(0);
			n = parseInt(root_node.firstChild.data, 10);
			if(n > 0)
			{
				root_node = xmldoc.getElementsByTagName('DataID').item(0);
				DataID = root_node.firstChild.data;
				root_node = xmldoc.getElementsByTagName('FID').item(0);
				FID = root_node.firstChild.data;
				root_node = xmldoc.getElementsByTagName('PetName').item(0);
				PetName = root_node.firstChild.data;
				root_node = xmldoc.getElementsByTagName('IPAddr').item(0);
				IPAddr = root_node.firstChild.data;
				root_node = xmldoc.getElementsByTagName('MsgString').item(0);
				MsgString = root_node.firstChild.data;
				msg_list[msg_count] = new Elucard_Message(DataID, FID, PetName, IPAddr, MsgString);
				msg_count ++;
				check_message_online();
			}
			else
			{
				window.setTimeout("check_message_online();", 5000);
			}
 	  }
		else
		{
      //alert("There was a problem with the request.");
    }
 	}
}

function get_card_name_by_id()
{
	var HtmlCode="", str, xmldoc, root_node, CardName, CardMemo;
  if (http_request2.readyState == 4)
	{
    if (http_request2.status == 200)
		{
			xmldoc = http_request2.responseXML;
			root_node = xmldoc.getElementsByTagName('count').item(0);
			var n = parseInt(root_node.firstChild.data, 10);
			if(n > 0)
			{
				root_node = xmldoc.getElementsByTagName('CardName').item(0);
				if(root_node.firstChild)
				{
					CardName = root_node.firstChild.data;
					document.cardClipFrm.iCardName.value = CardName;
				}
				else
					document.cardClipFrm.iCardName.value = "";
				
				root_node = xmldoc.getElementsByTagName('CardMemo').item(0);
				if(root_node.firstChild)
				{
					CardMemo = root_node.firstChild.data;
					document.cardClipFrm.iCardMemo.value = CardMemo;
				}
				else
					document.cardClipFrm.iCardMemo.value = "";
			}
 	  }
		else
		{
      //alert("There was a problem with the request.");
    }
 	}
}

function CheckNewSharedCallback() {
	var result;
  if (http_request3.readyState == 4)
	{
    if (http_request3.status == 200)
		{
			var result = eval( "(" + http_request3.responseText + ")" );

			if(result.CardID != 'null' && result.CardID != OldSharedCardID) {				
				OldSharedCardID = result.CardID;
				NewSharedCard(result);
			}
 	  }
		else
		{
      //alert("There was a problem with the request.");
    }
 	}	
}
