/***********************************************
	Usage:
	include('includeFileName');
***********************************************/

/* IncludeJsFiles */
function include(incFile) {
	var script = document.createElement('script');
	script.src = incFile;
	script.type = 'text/javascript';
	script.defer = true;
	document.getElementsByTagName('head').item(0).appendChild(script);
}

/* AutoExecution */
if(window.addEventListener) {
	window.addEventListener("load", commonFunc, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", commonFunc);
}
else {
	window.onload = commonFunc;
}

/* CommonFunction */
function commonFunc() {
	if (typeof anyFunction == "function") anyFunction();
	onClickCursorPointer();
}

/* HTMLescape */
function escapeHTML(str) {
	var replacement = function(word) {
		var characterReference = {'"':'&quot;', '&':'&amp;', '\'':'&#39;', '<':'&lt;', '>':'&gt;'};
		return characterReference[ word ];
	}
	if (str) {
		return str.replace( /"|&|'|<|>/g, replacement );
	} else {
		return '';
	}
}

/* RegExpescape */
function escapeReg(str) {
	var replacement = function(word) {
		var characterReference = {'\\':'\\\\', '|':'\\|', '(':'\(', ')':'\)', '[':'\[', ']':'\]', '-':'\-', '?':'\?'};
		return characterReference[ word ];
	}
	if (str) {
		return str.replace( /\\|\||\(|\)|\[|\]|\-|\?/g, replacement );
	} else {
		return '';
	}
}

/* ParentNode'sFormObject */
function thisForm(element) {
	var inpElem = document.createElement('input');
	element.parentNode.appendChild(inpElem);
	var objForm = inpElem.form;
	element.parentNode.removeChild(element.parentNode.lastChild);
	return objForm;
}

/* onClickImagesStyleSet */
function onClickCursorPointer() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("onclick")) {
				images[i].style.cursor = 'pointer';
			}
		}
	}
}

/* Checked Radio Buttons Value */
function getRadioValue(name) {
	var radio = document.getElementsByName(name);
	for(var i = 0 ; i < radio.length ; i++) {
		if (radio[i].checked && radio[i].type == "radio") {
			return radio[i].value;
		}
	}
}

/* Reset Radio Buttons Value */
function resetRadio(name) {
	var radio = document.getElementsByName(name);
	for(var i = 0 ; i < radio.length ; i++) {
		if (radio[i].checked && radio[i].type == "radio") {
			return radio[i].checked = false;
		}
	}
}

/* Open Subwindow */
function openWindow(url, width, height, windowName) {
	if (!windowName) windowName = '_blank';
	return window.open(url,windowName,'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height);
}

/* Get String Byte */
function getStringByte(str, limit) {
	var count = 0;
	var limitStr = '';
	for ( i = 0 ; i < str.length ; i++) {
		(str.charAt(i).match(/[ｱ-ﾝ]/) || escape(str.charAt(i)).length < 4) ? count++ : count += 2;
		count <= limit ? limitStr += str.charAt(i) : '';
	}
	if (limit) {
		return limitStr;
	} else {
		return count;
	}
}

/* Convert Multi to Single Byte */
function z2h(obj){
	if (obj.value) {
		var han= '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		var zen= '１２３４５６７８９０ａｂｃｄｅｆｇｈｉｊｋｌｍｎｏｐｑｒｓｔｕｖｗｘｙｚＡＢＣＤＥＦＧＨＩＪＫＬＭＮＯＰＱＲＳＴＵＶＷＸＹＺ';
		var word = obj.value;
		for(i=0;i<zen.length;i++){
			var regex = new RegExp(zen[i],"gm");
			word = word.replace(regex,han[i]);
		}
		obj.value = word;
	}
}

/***********************************************
	Usage: text入力ボックスの自動半角変換
	
	function anyFunction() {
		var target = new Array('age', 'height', 'bust', 'waist', 'hip');
		var obj = new Array;
		for (var i = 0 ; i < target.length ; i++) {
			obj[i] = document.getElementById(target[i]);
			if(obj[i].addEventListener) {
				obj[i].addEventListener("keyup", function (){z2h(this);}, false);
			}
			else if(obj[i].attachEvent) {
				obj[i].attachEvent("onkeyup", function (){z2h(this);});
			}
		}
	}
	
***********************************************/

/* 「この内容の説明」ポップアップ */
function note(html){
	var url = 'explanation/'+html;
	openWindow(url, 600, 3000, '説明');
}

/* アクセスログ */
function alog(b) {
	var d = new Date();
	$.get("/cgi-bin/common/alog.php", {t : d.getTime(),  bid : b});
}

/* 検索ボックス説明文 */
if(typeof jQuery != "undefined"){
	$(function(){
		var swapValues = [];
		$(".headSerchTxt").each(function(i){
			swapValues[i] = $(this).val();
			$(this).focus(function(){
				if ($(this).val() == swapValues[i]) {
					$(this).val("");
				}
			}).blur(function(){
				if ($.trim($(this).val()) == "") {
					$(this).val(swapValues[i]);
				}
			});
		});
	});
}

