/**************************************************
			°ø¿ë ½ºÅ©¸³Æ® ÆÄÀÏ
			ÀÛ¼ºÀÚ : ¾È¼±±Õ
			ÃÖÃÊÀÛ¼ºÀÏ : 2009.11.13
**************************************************/

/* °ø¹éÁ¦°Å */
function trim(str){
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); 
}

/* ±âº»°ªÁ¦°Å */
function FocusInputTxt(obj){
	if(obj.getAttribute("isDefault") == "true"){
		setNodeAttribute(obj, '#666666', '', 'false');
	}
}

/* ±âº»°ª º¹¿ø */
function BlurInputTxt(obj){
	if(obj[getValueKey(obj)] == ''){
		setNodeAttribute(obj, '#666666', 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");
}

/* ¼ýÀÚ Ã¼Å©( ¸Þ¼¼Áö )
	»ç¿ë : 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 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("ÀÌ¸ÞÀÏÀÇ Ã¹ ±ÛÀÚ´Â ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù.");
			frm_service_2.email1.value="";
			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, brd_old_id){
	win = window.open('../src/board/ImgView.php?brd_code='+brd_code+'&brd_id='+brd_id+'&brd_old_id='+brd_old_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 ImgView_infor_2(brd_id, num){
	win = window.open('../src/board/ImgView.php?id='+brd_id+'&file_num='+num+'&mode=infor_2', '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 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)


/*******************************************
		ÆäÀÌÁö ÀÌµ¿(ÀÎµ¦½º)
*******************************************/
///////// bo -> brd_con_code
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");
	}
}

/* ¼ýÀÚ Ã¼Å©( ¸Þ¼¼Áö )
	»ç¿ë : onKeyUp="number_check(this);" */
function number_checked(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;
}
/**********************************************************/

//-->

//·Î±×ÀÎ ±âº» °ª Á¦°Å
function clearTxt(obj){
	if(obj.name=="in_id"){
		if(obj.defaultValue == obj.value){
			obj.value = "";
		}else if(!trim(obj.value)){
			obj.value = obj.defaultValue;
		}
	}else if(obj.name=="in_pwd"){
		if(obj.className == "form_pw_nofocus"){
			obj.className = "form_pw_focus";
		}else{
			if(!trim(obj.value)){
				obj.className = "form_pw_nofocus";
			}
		}

	}
}
