//<![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 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;
}

/* ¿µ¹® ÀÔ·Â È®ÀÎ(¿µ¹®¸¸ ÀÔ·Â°¡´É) */
function CheckEnglish(Obj){
	var valid = "abcdefghijklmnopqrstuvwxyz0123456789_-"; 
	var startChar = "abcdefghijklmnopqrstuvwxyz0123456789";
	var temp, rtn_value = 1;
	value = Obj.value.toLowerCase();
	temp = value.substring(0,1);
	if(startChar.indexOf(temp) == "-1"){ alert("Ã¹±ÛÀÚ´Â ¿µ¹®ÀÌ³ª ¼ýÀÚÀÌ¿©¾ß ÇÕ´Ï´Ù."); Obj.value = ""; Obj.focus(); return false; }
	for(var i=0; i<value.length; i++){
		temp = "" + value.substring(i, i + 1);
		if(valid.indexOf(temp) == "-1"){ alert("¿µ¹®ÀÌ³ª ¼ýÀÚ _, - ¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù."); Obj.focus(); return false; }
	}
}

/* ÁöÁ¤µÈ ±æÀÌ ÀÌÈÄ Æ÷Ä¿½º ÀÌµ¿ */
function M_NxtField(flag,len,nextfield_id){ 
	if (flag.value.length==len) {
		document.getElementById(nextfield_id).focus();
		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(NumberTxt){
	var num_len, tmp_price;
	var tmp = "";
	var pos = 3;

	tmp_price = NumberTxt;

	if(trim(tmp_price)){
		tmp_price = tmp_price.replace(/,/g, "");
		if(!CheckNumber(tmp_price)){ return; }
		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(); }
}

/**************************************************/

//¾ÆÀÌµð À¯È¿¹®ÀÚ Ã¼Å©
function ValidID(value){
	var valid = "abcdefghijklmnopqrstuvwxyz0123456789_"; 
	var startChar = "abcdefghijklmnopqrstuvwxyz";
	var temp, rtn_value = 1;

	value = value.toLowerCase();
	temp = value.substring(0,1);

	if(startChar.indexOf(temp) == "-1"){
		rtn_value = 0;
	}

	for(var i=0; i<value.length; i++){
		temp = "" + value.substring(i, i + 1);
		if(valid.indexOf(temp) == "-1"){
			rtn_value = 9;
		}
	}

	if(value.length < 5){
		rtn_value = 8;
	}

	return rtn_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 chech_web_url(txt){
	var str = "";
	var reg = new RegExp("^http://", "i");
	reg.test(txt) ? str = "y" : str = "n";
	return str;
}

/**********************************************************/

//ºñ¹Ð¹øÈ£ ¾ÆÀÌµð Áßº¹ È®ÀÎ
function MyPassCheck2ID(p_id, p_pass){
	var cnt=0,cnt2=1,cnt3=1;
	var temp="";

	for(i=0;i < p_id.length;i++){
		temp_id =p_id.charAt(i);

		for(j=0;j < p_pass.length;j++){
			if (cnt >0)
				j=tmp_pass_no+1;

			if (temp == "r"){
				j=0;
				temp="";
			}

			temp_pass = p_pass.charAt(j);

			if (temp_id == temp_pass){
				cnt = cnt + 1;
				tmp_pass_no = j;
				break;
			}else if(cnt > 0 && j > 0){
				temp="r";
				cnt = 0;
			}else
				cnt = 0;
		}
		if (cnt > 3) break;
	}
	if(cnt > 3) return false;
	else return true;
}

//ºñ¹Ð¹øÈ£ Áßº¹¹®ÀÚ È®ÀÎ(4~12ÀÚ »çÀÌ, ¿µ¹® ¼ýÀÚ È¥¿ëÀÔ·Â)
function MyPassCheck(p){
	chk1 = /^[a-z\d]{4,12}$/i;
	chk2 = /[a-z]/i;
	chk3 = /\d/;

	return chk1.test(p) && chk2.test(p) && chk3.test(p);
}

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 CheckJumin(str){
	//re = /^[0-9]{6}-[0-9]{7}$/;
	//if(!re.test(str)) return false;
	newStr = str.replace("-","");
	key="234567892345";
	sum=0;
	for (i=0;i<key.length ;i++ ){
		sum+=parseInt(newStr.charAt(i))*parseInt(key.charAt(i))
	}
	na=(11-(sum%11))%10;
	if (newStr.charAt(12)!=na){
		return false;
	}
}

//»ç¾÷ÀÚÃ¼Å©
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 = 600; // °¡·Î»çÀÌÁî ( ´Ù¸¥°ªÀ¸·Î ÁöÁ¤ÇÏ¸éµÊ) 
	var content = document.getElementById("brd_contents");

	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;

/*******************************************
		ÆäÀÌÁö ÀÌµ¿(ÀÎµ¦½º)
*******************************************/
function goPage(bo, id, mod){
	var url, params;

	url = "/src/inc/rsp_link_path.php";
	params = "bo=" + bo + "&id=" + id + "&mod=" + mod;

	new Ajax.Request(
		url,
		{
			method:"get",
			parameters:params,
			onComplete:MovePage
		}
	);
}

function MovePage(result){
	var rsp_txt;
	if(result.responseText != ""){
		rsp_txt = result.responseText;

		if(rsp_txt == "error"){
			alert("ERROR");
		}else{
			location.href = "/" + rsp_txt;
		}
	}else{
		alert("ERROR");
	}
}

/**********************************************************/

//]]>
