//숫자 판별 IE only
function onlyNum(el,event){
	if(window.event) var e = window.event.keyCode;
	else var e = event.code;

	if(!el.maxlen || parseInt(el.maxlen) > el.value.length){
		if (e >=48 && e<=57) return;
		if (e>=96 && e<=105) return;
		if (e>=37 && e<=40) return;
	}
	if (e==8 || e==9 || e==13 || e==46) return;
	if(window.event) window.event.returnValue = false;
	else event.stop();
}

/* 전체 선택(체크박스) - 객체 전달방식 */
function allSelect(sel){
	for (z=0;z<sel.options.length;z++){
		sel.options[z].selected = true;
	}
	return;
}

/* 전체 선택(체크박스) - 폼과 이름 전달 */
function allSelect2(frm,name){
	for(i=0;i<frm.length;i++){
		if(frm[i].name == name) frm[i].checked = true;
	}
}

/* 마지막 전달 객체(el)의 선택 여부에 따라 대상폼의 대상 항목을 선택 또는 선택 해제 처리 */
function selectControl(frm,name,el){	
	if(el.checked) chk = true;
	else chk = false	
	for(i=0;i<frm.length;i++){
		if(frm[i].name == name) frm[i].checked = chk;
	}
}

function unAllSel(frm,allname,el){
	if(!el.checked && frm[allname]){
		frm[allname].checked = false;
	}
}

function checkCount(frm,name){
	var chkcnt = 0;
	for(i=0;i<frm.length;i++){
		if(frm[i].type == "checkbox" || frm[i].type == "radio"){
			if(frm[i].name == name && frm[i].checked == true){
				chkcnt++;
			}
		}
	}
	return chkcnt;
}

//플래시파일 출력용
function swf(swf,w,h,bg){
	var tit='';
	document.write('<object id="" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'" align="middle" title="'+tit+'">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+swf+'" />');
	document.write('<param name="quality" value="high" />');
	if(bg == ''){
		document.write('<param name="wmode" value="transparent" />');
		document.write('<embed name="" src="'+swf+'" quality="high" wmode="transparent" width="'+w+'" height="'+h+'"  align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />');
	}else{
		document.write('<param name="bgcolor" value="'+bg+'" />');
		document.write('<embed name="" src="'+swf+'" quality="high" bgcolor="'+bg+'" width="'+w+'" height="'+h+'"  align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" />');
	}
	document.write('</object>');
}


function _falseAlert(msg){
	alert(msg);
	return false;
}

function getRadioVal(el){	
	if(el.length < 1) return '';
	for(i=0;i<el.length;i++){
		if(el[i].checked == true) return el[i].value;
	}
}

// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
function sprintf()
{
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
				   if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
				   if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
				   if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
				   if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
				   if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}
