﻿var IE = 0,NN = 0,N6 = 0;
var waitOffLink = false;
if(document.all) {
	IE = true;
}
else if(document.layers) {
	NN = true;
}
else if(document.getElementById) {
	N6 = true;
}

//
// 日付
//	
function DateTime() {
	this.now = new Date();
	this.year = this.now.getYear();
	if (NN || N6) {
		this.year += 1900;
	}
	this.month = this.now.getMonth() + 1;
	this.day = this.now.getDate();
	this.hour = this.now.getHours();
	this.min = this.now.getMinutes();
	this.sec = this.now.getSeconds();
}

DateTime.prototype.toString = function(format) {
	if (format == null) {
		format = 'yyyy/MM/dd';
	}
	if (this.month < 10) {
		month = '0' + this.month;
	}
	else {
		month = this.month;
	}
	if (this.day < 10) {
		day = '0' + this.day;
	}
	else {
		day = this.day;
	}
	if (this.hour < 10) {
		hour = '0' + this.hour;
	}
	else {
		hour = this.hour;
	}
	if (this.min < 10) {
		min = '0' + this.min;
	}
	else {
		min = this.min;
	}
	if (this.sec < 10) {
		sec = '0' + this.sec;
	}
	else {
		sec = this.sec;
	}
	
	format = format.replace('yyyy', this.year);
	format = format.replace('MM', month);
	format = format.replace('dd', day);
	format = format.replace('hh', hour);
	format = format.replace('mm', min);
	format = format.replace('ss', sec);
	return format;
}

//
// Queue (FIFO)
//
function Queue() {
	this.__a = new Array();
}

Queue.prototype.enqueue = function(o) {
	this.__a.push(o);
}

Queue.prototype.dequeue = function() {
	if( this.__a.length > 0 ) {
		return this.__a.shift();
	}
	return null;
}

Queue.prototype.size = function() {
	return this.__a.length;
}

Queue.prototype.toString = function() {
	return '[' + this.__a.join(',') + ']';
}

Queue.prototype.last = function() {
	if( this.__a.length > 0 ) {
		o = this.__a.shift();
		this.enqueue(o);
		return o;
	}
	return null;
}

///
/// idから要素取得
///
function GetElement(Msg) {
	e = null;
	if(IE) {
		e = document.all(Msg);
	}
	if(NN) {
		e = document.layers[Msg];
	}
	if(N6) {
		e = document.getElementById(Msg);
	}
	return e;
}

///
/// idから要素を隠す
///
function ElementHiddenById(Msg) {
	var element = GetElement(Msg);
	
	if (element != null) {
		if(IE) {
				document.all(Msg).style.visibility = "hidden";
		}
		if(NN) {
				element.visibility = "hide";
		}
		if(N6) {
			element.visibility = "hide";
			element.style.visibility = "hidden";
		}
	}
}

function imagePopup(host, path, w, h)
{
	url = host + "/center/common/Popup.aspx?src=" + path;
	option = "menubar=no,toolbar=no,scrollbars=yes,width=" + (w + 26) + ",height=" + (h + 26) ;
	window.open(url, '__', option);
}

function getElement(anc, id)
{ 
	var element = document.getElementById(id);
	if (element == null) {
		return;
	}
	anc.text = document.getElementById(id).innerHTML;
}

function validateImpl(id)
{	
	if (id == null || id.length == 0)
	{
		return false;
	}
	var errormsg = "";
	
	$("#" + id).each(function(){
		$(".required").each(function(){
			if (this.value.length == 0) {
				errormsg += " ［" + this.title + "］は必須項目です。";
			}
		})
		
		$("input,textarea").each(function(){
			var o = jQuery(this);
			var max = o.attr("maxlength");
			if (max != null && max > 0 && o.attr("value").length > max) {
				errormsg += " ［" + this.title + "］は" + max + "文字までです。";
				return;
			}
			
			max = o.attr("maxlen");
			if (max != null && max > 0 && o.attr("value").length > max) {
				errormsg += " ［" + this.title + "］は" + max + "文字までです。";
				return;
			}
		})
	})
	
	$(".error").html(errormsg);
	
	if (errormsg.length > 0) {
		return false;
	}
	return true;
}

