function SessionLogin()
{

	var self = this;
	this.sessionButton = document.getElementById("session");
	this.fullscreen = document.getElementById("fullscreen");
	this.div = document.getElementById("login");
	this.inner = this.div.getElementsByTagName("div")[0];
	this.ul = this.div.getElementsByTagName("ul")[0];
	this.loading = this.div.getElementsByTagName("img")[0];
	this.form = document.getElementById("login");
	this.close = this.div.getElementsByTagName("a")[0];
	this.loginResult = this.div.getElementsByTagName("p")[0];
	
	this.form = document.forms["login"];
	this.button = document.forms["login"].elements["button"];
	
	this.sessionButton.onmouseover = function()
	{
		this.style.cursor = "pointer";
	}
	
	this.close.onclick = function()
	{
		self.hidden();
	}
	
	this.sessionButton.onclick = function()
	{
		self.display();
	}

	this.button.onclick = function()
	{
		self.login();
		
	}
	
}

SessionLogin.prototype.display = function()
{
	this.fullscreen.style.display = "block";
	this.div.style.display = "block";
	this.ul.style.display = "block";
}

SessionLogin.prototype.hidden = function()
{
	this.fullscreen.style.display = "none";
	this.div.style.display = "none";
	this.loginResult.style.display = "none";
}

SessionLogin.prototype.login = function()
{
	var self = this;

	
	var uid = document.forms["login"].elements["uid"].value.replace(/[^A-Za-z0-9]*/,"");
	var trip = document.forms["login"].elements["trip"].value.replace(/[^A-Za-z0-9]*/,"");
	
	
	if(uid.length > 0)
	{
		this.inner.style.display = "none";
		this.loading.style.display = "block";
		
		var url = "./tripmake.php?uid=" + uid;
		if(trip) url += "&trip=" + trip;
		
		new Ajax.Request(url, {method: 'get',onComplete: function(httpObj)
			{
				var myId = httpObj.responseText;
				var now = new Date();
				now.setTime(now.getTime() + 1000*60*60*24*7);
				document.cookie = "name=" + myId + ";expires=" + now.toGMTString();

				self.loginResult.style.display = "block";
				self.loginResult.innerHTML = myId+ "でログインしました";
				self.ul.style.display = "none";
				self.loading.style.display = "none";
				self.inner.style.display = "block";
			}
		}
		);
		
		
	}else
	{
		document.forms["login"].elements["uid"].style.background="#FFFFCC";
	}
}