//<![CDATA[
/*----------------------------------------------------------------------------
 *  ÆÄÀÏ¸í : common.js
 *  ¼³¸í : °ø¿ë ½ºÅ©¸³Æ® ÆÄÀÏ
 *  ÀÛ¼ºÀÚ : ¾È¼±±Õ
 *  ÃÖÃÊÀÛ¼ºÀÏ : 2009-11-13
 *--------------------------------------------------------------------------*/
//select ÅÂ±× ¸ðµç option »èÁ¦ÇÏ±â
function removeAllOption(obj){ if($(obj).options.length>0){ for (var i = $(obj).options.length-1; i>=0; i--) { $(obj).remove(i); } } }
//Ã¼Å©¹Ú½º ÀüÃ¼ Ã¼Å©
function CheckBoxAllChecked(Oid){
	var Obj = document.getElementById(Oid).getElementsByTagName("input");
	for(var i=0; i<Obj.length; i++){ if(Obj[i].type == "checkbox"){ if(Obj[i].checked == true){ Obj[i].checked = false; }else{ Obj[i].checked = true; } } }
}
/* °ø¹éÁ¦°Å */
function trim(str){ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }
/* ±âº»°ªÁ¦°Å */
function FocusInputTxt(obj){ if(obj.getAttribute("isDefault") == "true"){ setNodeAttribute(obj, '#000000', '', 'false'); } }
/* ±âº»°ª º¹¿ø */
function BlurInputTxt(obj){ if(obj[getValueKey(obj)] == ''){ setNodeAttribute(obj, '#000000', obj.defaultValue, 'true'); } }
/* ½ÇÁ¦ ÇÁ·Î¼¼½º°¡ ÁøÇàµÇ´Â ÇÔ¼ö */
function setNodeAttribute(obj, oColor, oValue, isDefault){ obj.style.color = oColor; obj[getValueKey(obj)] = oValue; obj.setAttribute("isDefault", isDefault); }
/* ¿ÀºêÁ§Æ®ÀÇ tag type Ã¼Å© */
function getValueKey(obj){ return isTextArea(obj) ? 'innerHTML' : 'value'; }
function isTextArea(obj){ return (obj.tagName == "textarea"); }
/* ÇÑ±Û ÀÔ·ÂÈ®ÀÎ(ÇÑ±Û¸¸ ÀÔ·Â °¡´É) */
function CheckHangul(Obj){ var Str = Obj.value; if(Str == null){ return; } for(var i=0; i<Str.length; i++){ var c = Str.charCodeAt(i); if(!((0xAC00 <= c && c <= 0xD7A3) || (0x3131 <= c && c <= 0x318E))){ alert("ÇÑ±Û¸¸ ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); Obj.value = ""; return; } } return; }

/* ¼ýÀÚ Ã¼Å©( ¸Þ¼¼Áö )
	»ç¿ë : onKeyUp="number_check(this);" */
function number_check(obj){
	var num_vaild = "0123456789"; var Object = obj.value; var tmp = "";
	for(var i=0; i<Object.length; i++){ tmp = "" + Object.substring(i, i+1); if(num_vaild.indexOf(tmp) == "-1"){ alert("¼ýÀÚ¸¸ ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); obj.value = ""; obj.focus(); return false; } }
	return true;
}
/* ¼ýÀÚ Ã¼Å© (return type : bool) */
function CheckNumber(num){ var vaild = "0123456789"; var ReturnValue = true; var tmp = ""; for(var i=0; i<num.length; i++){ tmp = "" + num.substring(i, i+1); if(vaild.indexOf(tmp) == "-1"){ ReturnValue = false; } } return ReturnValue; }
/* ÀÚµ¿À¸·Î ÄÞ¸¶Ä¡±â
	»ç¿ë : onKeyUp="auto_comma(this);" */
function auto_comma(Obj){ var num_len, tmp_price; var tmp = ""; var pos = 3; tmp_price = Obj.value; if(trim(tmp_price)){ tmp_price = tmp_price.replace(/,/g, ""); if(!CheckNumber(tmp_price)){ alert("¼ýÀÚ¸¸ ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); Obj.value = ""; return false; } tmp_price = new String(tmp_price); num_len = tmp_price.length; while(num_len > 0){ num_len = num_len - pos; if(num_len < 0){ pos = num_len + pos; num_len = 0; } tmp = "," + tmp_price.substr(num_len, pos) + tmp; } tmp_price = tmp.substr(1); }else{ tmp_price = 0; } Obj.value = tmp_price; return; }
function auto_comma2(value){
	var num_len, tmp_price;
	var tmp = "";
	var pos = 3;
	tmp_price = value;
	if(trim(tmp_price)){
		tmp_price = tmp_price.replace(/,/g, "");
		if(!CheckNumber(tmp_price)){ alert("¼ýÀÚ¸¸ ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); Obj.value = ""; return false; }
		tmp_price = new String(tmp_price);
		num_len = tmp_price.length;
		while(num_len > 0){
			num_len = num_len - pos;
			if(num_len < 0){
				pos = num_len + pos;
				num_len = 0;
			}
			tmp = "," + tmp_price.substr(num_len, pos) + tmp;
		}
		tmp_price = tmp.substr(1);
	}else{
		tmp_price = 0;
	}
	return tmp_price;
}

//ÀÌ¸ÞÀÏ Ã¼Å©
function check_email(email1, email2){ var valid = "abcdefghijklmnopqrstuvwxyz0123456789_."; var startChar = "abcdefghijklmnopqrstuvwxyz"; var temp; if(email1){ obj = email1.toLowerCase(); temp = email1.substring(0,1); if (startChar.indexOf(temp) == "-1"){ alert("ÀÌ¸ÞÀÏÀÇ Ã¹ ±ÛÀÚ´Â ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù."); return false; }else{ for (var i=0; i<email1.length; i++) { temp_1 = "" + email1.substring(i, i+1); if (valid.indexOf(temp) == "-1") { alert("ÀÌ¸ÞÀÏÀº ¿µ¹®°ú ¼ýÀÚ, _ ·Î¸¸ ÀÌ·ç¾îÁú¼ö ÀÖ½À´Ï´Ù."); return false; } } } }else{ alert("ÀÌ¸ÞÀÏÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); return false; } if(email2){ obj = email2.toLowerCase(); temp = email2.substring(0,1); if (startChar.indexOf(temp) == "-1"){ alert("ÀÌ¸ÞÀÏÀº ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù."); return false; } }else{ alert("ÀÌ¸ÞÀÏÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä."); return false; } var email = email1 + '@' + email2; if(email.length <= 6 || email.indexOf ('@', 0) == -1 || email.indexOf ('.', 0) == -1){ alert("'' " + email + " ''Àº(´Â) ¿Ã¹Ù¸¥ ÀÌ¸ÞÀÏÁÖ¼Ò°¡ ¾Æ´Õ´Ï´Ù"); return false; } return true; }
//ÀÌ¹ÌÁö º¸±â
function PopImage(imgsrc){
	var img = new Image();
	img.src = imgsrc;
	var winl = (screen.width - img.width) / 2;
	var wint = (screen.height - img.height) / 2 - 40;
	if(img.width > 0){
		var popwin = window.open('', 'popimg', 'width='+img.width+',height='+img.height+',top='+wint+',left='+winl+',toolbar=no,scrollbars=no,resizable=no');
		var str = '<title>Image Window</title>'
		str += '<body topmargin=0 leftmargin=0>'
		str += '<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"><tr>'
		str += '<td align=center><img style="cursor:pointer;" onclick="self.close()" src="'+imgsrc+'" alt="´Ý±â" galleryimg="no"></td>'
		str += '</tr></table>'
		str += '</body>'
		popwin.document.open();
		popwin.document.write(str);
		popwin.document.close();
	}
}

//µå·¡±× °¡´ÉÇÑ Ã¢ ¶ç¿ì±â(ÀÌ¹ÌÁö)
function ImgView(brd_code, brd_id, file_id){
	win = window.open('../src/board/ImgView.php?brd_code='+brd_code+'&brd_id='+brd_id+'&file_id='+file_id, 'imgView', 'width=100, height=100, scrollbars=no, toolbar=no, status=no, resizable=no');
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/*************************************************
#   Ã·ºÎÀÌ¹ÌÁö ¹Ì¸®º¸ÀÌ±â(IE, FF Áö¿ø)
#   »ç¿ë : fileUploadPreview(ÆÄÀÏ ¾÷·Îµå ¿ÀºêÁ§Æ® ¾ÆÀÌµð, ¹Ì¸®º¸±â ¿ÀºêÁ§Æ® ¾ÆÀÌµð);
*************************************************/
function fileUploadPreview(thisObj, preViewer) {
	if(!/(\.gif|\.jpg|\.jpeg|\.png)$/i.test(thisObj.value)) {
		alert("ÀÌ¹ÌÁö Çü½ÄÀÇ ÆÄÀÏÀ» ¼±ÅÃÇÏ½Ê½Ã¿À");
		return;
	}

	preViewer = (typeof(preViewer) == "object") ? preViewer : document.getElementById(preViewer);
	var ua = window.navigator.userAgent;

	if (ua.indexOf("MSIE") > -1) {
		preViewer.innerHTML = "";
		var img_path = "";
		if (thisObj.value.indexOf("\\fakepath\\") < 0) {
			img_path = thisObj.value;
		} else {
			thisObj.select();
			var selectionRange = document.selection.createRange();
			img_path = selectionRange.text.toString();
			thisObj.blur();
		}
		preViewer.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='fi" + "le://" + img_path + "', sizingMethod='scale')";
	} else {
		preViewer.innerHTML = "";
		var W = preViewer.offsetWidth;
		var H = preViewer.offsetHeight;
		var tmpImage = document.createElement("img");
		preViewer.appendChild(tmpImage);

		tmpImage.onerror = function () {
			return preViewer.innerHTML = "";
		}

		tmpImage.onload = function () {
			if (this.width > W) {
				this.height = this.height / (this.width / W);
				this.width = W;
			}
			if (this.height > H) {
				this.width = this.width / (this.height / H);
				this.height = H;
			}
		}
		if (ua.indexOf("Firefox/3") > -1) {
			var picData = thisObj.files.item(0).getAsDataURL();
			tmpImage.src = picData;
		} else {
			tmpImage.src = "file://" + thisObj.value;
		}
	}
}

/**************************************************/

//ÆÄÀÏ È®ÀåÀÚ Ã¼Å©
function check_file_type(fileValue){
	var spl, pos, sp, po, ext, resultValue = "";
	var imgExtn = new Array("gif", "jpg", "jpeg");
	var NoAttachExtn = new Array("html", "htm", "php", "inc", "cgi", "exe", "com", "bat", "pif", "txt");

	spl = fileValue.split("/");
	pos = spl.length-1;
	sp = spl[pos].split(".");
	po = sp.length-1;

	if(po == 0){
		resultValue = "no_extn";
	}

	if(!trim(resultValue)){
		ext = sp[po].toLowerCase();
		for(var i=0; i<imgExtn.length; i++){
			if(imgExtn[i] == ext){
				resultValue = "image";
			}
		}
	}

	if(!trim(resultValue)){
		ext = sp[po].toLowerCase();
		for(var i=0; i<NoAttachExtn.length; i++){
			if(NoAttachExtn[i] == ext){
				resultValue = "no_attach_file";
			}
		}
	}

	if(!trim(resultValue)) resultValue = "other_file";

	return resultValue;
}

//WEB ÁÖ¼Ò Ã¼Å©
function CheckWebURL(txt){
	var str = "";
	var reg = new RegExp("^http://", "i");
	reg.test(txt) ? str = "y" : str = "n";
	return str;
}

/**********************************************************/

function Jumin_chk(it) {
	IDtot = 0;
	IDAdd = "234567892345";
	for(i=0; i<12; i++) IDtot = IDtot + parseInt(it.substring(i,i+1)) * parseInt(IDAdd.substring(i,i+1));
	IDtot = 11 - (IDtot%11);
	if (IDtot == 10) IDtot = 0;
	else if (IDtot == 11) IDtot = 1;
	if(parseInt(it.substring(12,13)) != IDtot) return true;
}

function is_leap_year(year) {
	if(year%4==0) {
		if(year%100==0) {
			if(year%400) return true;
			else return false;
		}else return true;
	}else return false;
} // function is_leap_year(year)

//ÁÖ¹Î¹øÈ£ Ã¼Å©
function checking_SSN_Kr(str) {
	re = /^[0-9]{6}-[0-9]{7}$/;
	if (!re.test(str)) return false;
	newStr = str.replace("-","");
	var tmp    = 0;
	var year   = parseInt(newStr.substr(0,2));
	var month  = parseInt(newStr.substr(2,2));
	var day    = parseInt(newStr.substr(4,2));
	var gender = parseInt(newStr.charAt(6));
	if ( month < 1 || month > 12 || day < 1 || gender < 1 || gender > 4 ) return false;
	if(month==2) {
		year += gender<3 ? 1900 : 2000;
		if(is_leap_year(year)) {
			if(day > 29) return false;
		} else {
			if(day > 28) return false;
		} // if(is_leap_year(year))
	} else {
		var arrayOfLasts = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
		if(day > arrayOfLasts[month-1]) return false;
	} // if(month==2)
	for(var n=0; n<12; n++) {
		tmp += (n%8+2) * parseInt(newStr.charAt(n));
	}
	tmp = (11-(tmp%11))%10;
	if (tmp != newStr.charAt(12)) return false;
	return true;
} // function checking_SSN_Kr(str)

//»ç¾÷ÀÚÃ¼Å©
function checking_RN_Kr(str) {
	re = /^[0-9]{3}-[0-9]{2}-[0-9]{5}$/;
	if (!re.test(str)) return false;
	var tmp = 0;
	newStr = str.replace(/^([0-9]{3})-([0-9]{2})-([0-9]{5})$/,"$1$2$3");
	strAdd = "137137135";
	for(n=0; n<9; n++) tmp += newStr.charAt(n)*strAdd.charAt(n);
	tmp += newStr.charAt(8)*5/10;
	tmp = (10 - (tmp % 10))%10;
	if (tmp!=newStr.charAt(9)) return false;
	return true;
} // function checking_RN_Kr(year)

//ÄÁÅÙÃ÷ ÀÌ¹ÌÁö Å©±â Á¦¾î
function ContentsImageResize(){
	// DivContents ¿µ¿ª¿¡¼­ ÀÌ¹ÌÁö°¡ maxsize º¸´Ù Å©¸é ÀÚµ¿ ¸®»çÀÌÁî ½ÃÄÑÁÜ 
	maxsize = 620; // °¡·Î»çÀÌÁî ( ´Ù¸¥°ªÀ¸·Î ÁöÁ¤ÇÏ¸éµÊ) 
	var content = document.getElementById("print_contents_layer");

	if(content != null){
		var img = content.getElementsByTagName("img"); 

		for(i=0; i<img.length; i++){
			if(eval('img[' + i + '].width > maxsize')){
				var heightSize = ( eval('img[' + i + '].height')*maxsize )/eval('img[' + i + '].width');
				eval('img[' + i + '].width = maxsize');
				eval('img[' + i + '].height = heightSize');
			}
		}
	}
}
window.onload=ContentsImageResize;

//]]>
