/* ------------------------------------------------------------
 * Name	: admin.js
 * Desc	: Admin Javascrip
 * Created	: 2016/9/11 Tri-aBility by Junheum,Choi
 * Updated	:
 ------------------------------------------------------------ */

function is_NumericKey(evt,obj){
	var charCode = (evt.which) ? evt.which : event.keyCode;
	switch(charCode){
		case 48://0
		case 49://1
		case 50://2
		case 51://3
		case 52://4
		case 53://5
		case 54://6
		case 55://7
		case 56://8
		case 57://9
		case 96://KeyPad:0
		case 97://KeyPad:1
		case 98://KeyPad:2
		case 99://KeyPad:3
		case 100://KeyPad:4
		case 101://KeyPad:5
		case 102://KeyPad:6
		case 103://KeyPad:7
		case 104://KeyPad:8
		case 105://KeyPad:9
			break;
		default:
			alert('숫자만 가능합니다['+charCode+']');
			obj.value = obj.value.substring(0,obj.value.length-1);
			break;
	}
}
function is_NumericType(data){
	if(!data.match(/^[0-9]+$/)){
		throw (new Error('숫자가 아닌값['+data+']이 있습니다'));
	}
	return true;
}//
function change_CurrencyFormat(obj,currencies){
	//var currencies = document.getElementsByClassName("currency");
	var total_currency = 0;
	for(i=0; i<currencies.length; i+2){
		try {
			is_NumericType(currencies[i].value)//값이 숫자형식인지 판단
		} catch(err) {
			alert(err.message);
			currencies[i].focus();
			return false;
		}
		total_currency += parseInt(currencies[i].value);
		currencies[i].parentElement.innerHTML=currencies[i].value.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+'원';
	}
	obj.parentElement.innerHTML=total_currency.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")+'원'
	return true;
}

//해당하는 클래스의 내용을 메모리에 Copy
async function getElementsByClassNameCopyToClipboard(class_name)
{
	var x = document.getElementsByClassName(class_name);
	var textToCopy = '';
	for (var i = 0; i < x.length; i++) {
		textToCopy += x[i].textContent+'\n';
	}
	await navigator.clipboard.writeText(textToCopy)
			.then(() => { alert("복사가 완료되었습니다."); })
			.catch(err => { console.log('복사가 오류', err); })
}

//해당 URL의 페이지를 접속해서 targ의 위치에 표시한다.
function loadContentForm(url,target) {
    fetch(url)
        .then(response => response.text())
        .then(data => {target.innerHTML = data})
        .catch(error => console.error('Error loading form:', error));
}