// 文字コード: UTF-8
var bButtonDown = new Boolean(false);
var bInitAnchor = new Boolean(false);

window.document.onmouseup = function () {
	bButtonDown = false;
}

function SelectedValue(formId, element) {
	element = window.document.getElementById(formId).elements[element];
	element = element.options[element.selectedIndex].value; 

	return element;
}

function Focus(objectId) {
	var element = new Object();
	element = window.document.getElementById(objectId);
	element.focus();
	if (element.type == 'text') {
		element.select();
	}
}

function HistoryBack() {
	window.history.back();
}

function HistoryGo(n) {
	window.history.go(n);
}

function InitializeText() {
	var textBoxElements = new Object();
	var textAreaElements = new Object();
	textBoxElements = window.document.getElementsByTagName('input');
	textAreaElements = window.document.getElementsByTagName('textarea');
	for (i = 0; i < textBoxElements.length; i++) {
		switch(textBoxElements[i].type) {
			case 'text':
			case 'password':
				if (navigator.appName.indexOf('Netscape', 0) >= 0) {
					textBoxElements[i].setAttribute('class', 'text');
					textBoxElements[i].setAttribute('onfocus', 'javascript:TextOperations(this, \'focus\');');
					textBoxElements[i].setAttribute('onblur', 'javascript:TextOperations(this, \'blur\');');
				} else if (navigator.appName.indexOf('Microsoft', 0) >= 0) {
					textBoxElements[i].setAttribute('className', 'text');
					textBoxElements[i].setAttribute('onfocus', new Function('javascript:TextOperations(this, \'focus\');'));
					textBoxElements[i].setAttribute('onblur', new Function('javascript:TextOperations(this, \'blur\');'));
				}
				break;
		}
	}
	for (j = 0; j < textAreaElements.length; j++) {
		if (navigator.appName.indexOf('Netscape', 0) >= 0) {
			textAreaElements[j].setAttribute('class', 'text');
			textAreaElements[j].setAttribute('onfocus', 'javascript:TextOperations(this, \'focus\', \'記入してください。\');');
			textAreaElements[j].setAttribute('onblur', 'javascript:TextOperations(this, \'blur\', \'記入してください。\');');
		} else if (navigator.appName.indexOf('Microsoft', 0) >= 0) {
			textAreaElements[j].setAttribute('className', 'text');
			textAreaElements[j].setAttribute('onfocus', new Function('javascript:TextOperations(this, \'focus\', \'記入してください。\');'));
			textAreaElements[j].setAttribute('onblur', new Function('javascript:TextOperations(this, \'blur\', \'記入してください。\');'));
		}

	}
}

function TextOperations(element, sAction, sDefaultMessage) {
	switch (sAction.toLowerCase()) {
		case 'focus':
			if (navigator.appName.indexOf('Netscape', 0) >= 0) {
				element.setAttribute('class', 'text text-focus');
			} else if (navigator.appName.indexOf('Microsoft', 0) >= 0) {
				element.setAttribute('className', 'text text-focus');
			}
			if (sDefaultMessage != undefined) {
				if (element.value == sDefaultMessage) {
					element.value = '';
				}
			}
			break;
		case 'blur':
			if (navigator.appName.indexOf('Netscape', 0) >= 0) {
				element.setAttribute('class', 'text');
			} else if (navigator.appName.indexOf('Microsoft', 0) >= 0) {
				element.setAttribute('className', 'text');
			}
			if (sDefaultMessage != undefined) {
				if (element.value == '') {
					element.value = sDefaultMessage;
				}
			}
			break;
	}
}

function InitializeButton() {
	var buttonElements = new Object();

	bButtonDown = false;
	buttonElements = window.document.getElementsByTagName('input');
	for (i = 0; i < buttonElements.length; i++) {
		switch (buttonElements[i].type) {
			case 'button':
			case 'submit':
			case 'reset':
				if (navigator.appName.indexOf('Netscape', 0) >= 0) {
					buttonElements[i].setAttribute('class', 'button');
					buttonElements[i].setAttribute('onmousedown', 'javascript:ButtonOperations(this, \'mousedown\');');
					buttonElements[i].setAttribute('onmouseout', 'javascript:ButtonOperations(this, \'mouseout\');');
					buttonElements[i].setAttribute('onmouseover', 'javascript:ButtonOperations(this, \'mouseover\');');
					buttonElements[i].setAttribute('onmouseup', 'javascript:ButtonOperations(this, \'mouseup\');');
				} else if (navigator.appName.indexOf('Microsoft', 0) >= 0) {
					buttonElements[i].setAttribute('className', 'button');
				}
				break;
		}
	}
}

function ButtonOperations(element, sAction) {
	if (! (navigator.appName.indexOf('Netscape', 0) >= 0)) {
		return;
	}

	switch (sAction.toLowerCase()) {
		case 'mousedown':
			bButtonDown = true;
			element.setAttribute('class', 'button button-mousedown');
			break;
		case 'mouseout':
			element.setAttribute('class', 'button');
			break;
		case 'mouseover':
			if (bButtonDown) {
				element.setAttribute('class', 'button button-mousedown');
			}
			break;
		case 'mouseup':
			element.setAttribute('class', 'button');
			bButtonDown = false;
			break;
	}
}

function UpdatePart(url, divId, isMsieOnly) {
	var isMsie = new Boolean(false);
	var isFirefox = new Boolean(false);

	if (isMsieOnly == undefined) {
		isMsieOnly = false;
	}

	isMsie = window.navigator.appName.indexOf('Microsoft') >= 0 && window.navigator.userAgent.indexOf('MSIE') >= 0;
	isFirefox = window.navigator.appName.indexOf('Netscape') >= 0 && window.navigator.userAgent.indexOf('Firefox') >= 0;
	if (isMsie || (isFirefox && ! isMsieOnly)) {
		if (String(url) == undefined || String(url) == '') {
			$(String(divId)).innerHTML = '';
			return false;
		}

		new Ajax.Request(url, {
				method: 'get',
				asynchronous: true,
				onSuccess: function(httpObj) {
					var xmlDoc = new Object();
					var mainNode = new Object();

					xmlDoc = httpObj.responseXML;
					if (isMsie) {
						var xmlElem = new Object();

						xmlElem = xmlDoc.documentElement;

						mainNode = xmlElem.selectSingleNode("//div[@id='" + String(divId) + "']");
						$(String(divId)).outerHTML = mainNode.xml.stripScripts();
					} else if (isFirefox) {
						mainNode = xmlDoc.getElementById(String(divId));
						$(String(divId)).innerHTML = mainNode.innerHTML;
					}

					bInitAnchor = false;
					InitializeAnchorTag();
				}
			}
		);

		return false;
	}

	return true;
}

function InitializeAnchorTag() {
	var anchorElements = new Object();

	if (bInitAnchor == true) {
		return;
	}
	bInitAnchor = true;

	anchorElements = window.document.getElementsByTagName('a');
	for (i = 0; i < anchorElements.length; i++) {
		if (anchorElements[i].href.indexOf(window.location.hostname) < 0) {
			if (window.navigator.appName.indexOf('Netscape') >= 0) {
				anchorElements[i].setAttribute('onclick', 'javascript:window.open(\'' + anchorElements[i].href + '\'); return false;');
				anchorElements[i].setAttribute('onkeypress', 'javascript:void(0);');
			} else if (window.navigator.appName.indexOf('Microsoft') >= 0) {
				anchorElements[i].setAttribute('onclick', new Function('javascript:window.open(\'' + anchorElements[i].href + '\'); return false;'));
				anchorElements[i].setAttribute('onkeypress', new Function('javascript:void(0);'));
			}
		}
	}
}

function ErrorAlert(e) {
	if (navigator.appName.indexOf('Netscape', 0) >= 0) {
		alert('エラー内容 : \n' + e);
	} else if (navigator.appName.indexOf('Microsoft', 0) >= 0) {
		alert('エラー番号 : ' + String(e.number) + '\nエラー内容 : ' + e.description);
	}
}
