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

function trim(str){ 
	return this.replace(/(^\s*)|(\s*$)/gi, ""); 
}//

function bookmarksite(title,url) {
	if (window.sidebar) // firefox
			window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
	}
	else if(document.all) // ie
			window.external.AddFavorite(url, title);
}//

function captcha_refresh(refresh_url) {
    $.ajax({
        type: 'POST',
        url: refresh_url,
        success: function(data, status, xhr){
            if(data)
                $('#captcha_span').html(data);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log(jqXHR.responseText);
            console.log(textStatus+'=>'+errorThrown);
        }
    });//ajax
}//

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;
}