var aaa="sss";

var closeCurrent = function(){
	Windows.closeAllModalWindows();
};

var getCurrent = function(){
	return Windows.getFocusedWindow();
}
var leftCursor = function(){
 if($('cursor')){
   $('cursor').style.left = (ScreenManager.getRelativeLeft(-260))+"px";		
 }
 if(self.mainWindow){
   self.mainWindow.setLocation(114,ScreenManager.getRelativeLeft(-222));		
 }
};
var afterLoad = function(evt){
	if(evt.id!="mainWindow_content")return;
	var height = getActualHeight(evt.contentWindow.document);
	var now = $('mainWindow_content').getHeight();
	if(height>now){
		new Fx.Style('mainWindow_content', 'height',{duration:50,transition: Fx.Transitions.linear})._start($('mainWindow_content').getHeight(),height);
		new Fx.Style('tanzakuContainer', 'height',{duration:50,transition: Fx.Transitions.linear})._start($('tanzakuContainer').getHeight(),height-120);		
	} else {
		new Fx.Style('tanzakuContainer', 'height',{duration:50,transition: Fx.Transitions.linear})._start($('tanzakuContainer').getHeight(),height-120);
	}
}
var getActualHeight = function(root){
	if (root.all) return Math.max(root.documentElement.offsetHeight, root.documentElement.scrollHeight);
	if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)){
		return root.body.scrollHeight;
	}
	return root.documentElement.scrollHeight;
}
Event.observe(window,'resize',leftCursor,false);
var windowCnt = 0;
var GB_base = function(classname,title,url,height,width,onClose){
	if(!onClose)onClose = Prototype.emptyFunction;
	var win =  new Window("window"+(windowCnt++),{className: classname, title: title, url:url,width:width, height:height,resizable:false,draggable:false,showEffect:Element.show,hideEffect:Element.hide,minimizable:false,maximizable:false,closable:true,onClose:onClose,destroyOnClose:true});
	win.showCenter(true);
};
var GB_show = function(title,url,height,width,onClose){
	GB_base("lifelog",title,url,height,width,onClose);
};
var GB_showSolid = function(title,url,height,width,onClose){
	GB_base("lifelogbx",title,url,height,width,onClose);
};
var GB_showTransparent = function(title,url,height,width,onClose){
	GB_base("lifelogtp",title,url,height,width,onClose);
};

function showLogin(){
	GB_show("ログイン","/logs/showLogin.php",180,350);
}
var GB_ROOT_DIR = "/media/js/greybox/";
var Validator = Object.extend(Class.create(),{
	checkBlank : function(element){
		var value = element.value;
		if(element.type=='select-one'){
			return element.selectedIndex >0;
		}
		if(value && value != "") return true;
		else return false;
	},
	checkDate : function(form,label,year,month,date){
		var seed = [year,month,date].map(function(elem){
			return form[elem].value;
		});
		var parsedate = new Date(seed.join("/"));
		if(seed[0] != parsedate.getFullYear()
			|| seed[1] != (parsedate.getMonth()+1)
			|| seed[2] != parsedate.getDate()){
			throw label + "の入力が不正です。"
		}
	},
	prototype : {
		initialize : function(elementNames){
			this.elementNames = $H(elementNames);
		},
		checkBlanks : function(form,elementNames){
			var validator = this;
			if(!elementNames) elementNames = this.elementNames.keys();
			//var set = {};
			elementNames.each(function(elementName){
				//new Logger().alert(elementName,form[elementName]);
				validator._check(form[elementName],Validator.checkBlank,"が未入力です");
			});
		},
		checkEqual : function(_element,compare){
			var checker = function(element){
				var value = element.value;
				if(value == compare) return true;
				else return false;
			};
			this._check(_element,checker,"が一致しません");
		},
		_check : function(element,checker,errMsg){
			if(element){
				if(element.length){
					var elementName;
					element = $A(element).find(function(elem){
						elementName = elem.name;
						return elem.checked;
					});
					if(!element) element = {name:elementName,value : null};
				}
				if(!checker(element)) throw this.elementNames[element.name] + errMsg;
			}
		}
	}
});
var Header = {
	register : {
		validator : new Validator({
			last_name : "名前(姓)",
			first_name : "名前(名)",
			handle : "ニックネーム",
			sex : "性別",
			birth_y : "誕生日(年)",
			birth_m : "誕生日(月)",
			birth_d : "誕生日(日)",
			mail_address : "メールアドレス",
			password : "パスワード"
		}),
		submit : function(form){
			try{
				Header.register.validator.checkBlanks(form);
				Header.register.validator.checkEqual(form.password,$('pass_confirm').value);
				if(form.mail_address && $('mail_confirm')){
					Header.register.validator.checkEqual(form.mail_address,$('mail_confirm').value);
				}
				Validator.checkDate(form,"誕生日","birth_y","birth_m","birth_d");
				form.submit();
				/*alert(Form.serialize(form));
				new Ajax.Updater($('toolbar_main'),form.action,{
					method : "post",
					parameters : Form.serialize(form),
					evalScripts: true
				});*/
			}catch(e){
				alert(e);
			}
		}
	}
};
var ScreenManager = {
	getRelativeLeft:function(offset){
		var windowScroll = WindowUtilities.getWindowScroll();
	    var pageSize = WindowUtilities.getPageSize();
	    left = (pageSize.windowWidth>890?pageSize.windowWidth:890)/2 + windowScroll.left + offset;
		if(document.all)left+=6;
		return left;
	}
};
var LifelogWindow = {
	defs : {className: "lifelog", title: "", url:"/",width:300, height:200,resizable:true,draggable:false,showEffect:Element.show,hideEffect:Element.hide,minimizable:false,maximizable:false,closable:false},
	newWindow : function(id,options){
		return new Window(id,Object.extend(LifelogWindow.defs,options));
	},
	newDialog : function(id,options){
		return Dialog.alert('this is a message',{windowParameters:options})
	}
};
var Timeline = {
	moveTo : function(dest,id){
		if(!dest)return;
		//$A($$('.entry_pub','.entry_pri')).each(function(elem){new Effect.Puff(elem)});
				new Ajax.Updater('tanzakuContainer','/logs/timeline.php?id='+id+'&date='+dest,{asynchronous:false,evalScripts:true});
	}
};