﻿// JavaScript Document

var g_Email;
var g_Password;
//		if($('input[@name=sex_input]').get(1).checked==true)sex=1;


$(document).ready(function()
{
	
	$('#btn_Submit').click(function()
	{
		var Error = 0;
		g_Email = $("#tb_Email").val();
		g_Password = $("#tb_Password").val();
				
		if(g_Email.indexOf("@")<0)
		{
			$("#msg_Email").html("This E-mail address is invalid, have a check please");
			Error = 1;
		}

		if(g_Email=="")
		{
			$("#msg_Email").html("E-mail is required");
			Error = 1;
		}		

		if(g_Password=="")
		{
			$("#msg_Password").html("Password is required");
			Error = 1;
		}
		
		if(Error==1)return;

		var httpObj = getHttpObject();
		httpObj.onreadystatechange = function(){
			if(httpObj.readyState == 4){
				if(httpObj.status == 200){
					var conttext = httpObj.responseText;
					if(conttext.indexOf("FAILED")<0)
					{
						mySetCookie("LOGIN_USER_ID", conttext, 1);
						mySetCookie("LOGIN_USER_PASSWORD", g_Password, 1);
						location = "mypage.htm";
					}
					else
					{
						$("#msg_error").html("E-mail or Password is wrong, Please have check.");
					}
				}
			}
		}		
		
		httpObj.open("POST", domainname+"login.php", true);
		httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpObj.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
		httpObj.send("Email="+g_Email+"&Password="+g_Password);
		httpObj.send(null);

	});
	
	$('#btn_Reset').click(function()
	{
		$("#tb_Email").val("");
		$("#tb_Password").val("");
	});
	
	
});


