
function submitForm(formID) {
	$("#"+formID).submit();
}
function submitFormOnce(formID, buttonID) {
	submitForm = disableSubmit;
    switch (arguments.length) {
        case 1: buttonID = 'submit_once';
    } 
	$("#"+buttonID).removeAttr("href");
	$("#"+buttonID).attr("disabled", "disabled");
	$("#"+formID).submit();
}
function confirmClear() {
	return confirm("編集内容をクリアします。\nよろしいですか？");
}

function disableSubmit() {

}

function checkStrLength(str, minSize, maxSize) {
	return (str.length >= minSize && str.length <= maxSize);
}

function checkRadioValue(obj) {
	if(obj.length) {
		var i;
		for(i = 0;i < obj.length;i++){
			if (obj[i].checked) return obj[i].value;
		}
		return false;
	}else{
		return obj.checked ? obj.value : false;
	}
}

function checkCheckboxGroupValue(fName, preStr, count) {
	var i;
	var obj;
	var checkCount;
	checkCount = 0;
	for (i = 1;i <= count;i++) {
		if (obj = document.forms[fName].elements[preStr + i]) {
			if (obj.checked) checkCount++;
		}
	}
	return checkCount;
}

function checkMailAddress(str) {
	return str.match(/[\w\.\-]+\@[\w\.\-]+\.[a-zA-Z]{2,5}$/);
}
function formatNumber(str) {
	var num = new String(str).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}

function cleanNumber(str) {
	return new String(str).replace(/,/g, "");
}

Array.prototype.shuffle = function () {
    for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
    return this;
}
function getRandomStr (len, charSet) {
	if (!charSet) charSet = ["2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","k","m","n","p","q","r","s","t","u","v","w","x","y","z","2","3","4","5","6","7","8","9"];
	return charSet.shuffle().join("").slice(0, len || 10);
}

//URL Encode (UTF-8)
function encodeURL(str) {
	var character = '';
	var unicode   = '';
	var string    = '';
	var i         = 0;
	
	if (!str) return '';
	for (i = 0; i < str.length; i++) {
		character = str.charAt(i);
		unicode   = str.charCodeAt(i);
	
		if (character == ' ') {
			string += '+';
		} else {
			if (unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a))) {
				string = string + character;
			} else {
				if ((unicode >= 0x0) && (unicode <= 0x7f)) {
					character   = '0' + unicode.toString(16);
					string += '%' + character.substr(character.length - 2);
				} else if (unicode > 0x1fffff) {
					string += '%' + (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
					string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else if (unicode > 0x7ff) {
					string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else {
					string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				}
			}
		}
	}
	
	return string;
}