/*
	공통으로 사용하는 script 를 저장하는 파일 입니다.
	Auth : 엄익민 (NEXTBIZ)
*/
// import : prototype
document.write('<script type="text/javascript" src="../lib/prototype.js"><\/script>');

//iframe auto resize
function iframe_autoresize(arg) {
    arg.height = eval(arg.name+".document.body.scrollHeight");
}

// PNG IE6 에서 구현하기
function setPng24(obj) { 
	obj.width=obj.height=1; 
	obj.className=obj.className.replace(/\bpng24\b/i,''); 
	obj.style.filter = 
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
	obj.src='';  
	return ''; 
} 

// 글자수 제한.
function in_ti(word, length) {
	if(word.length > length) { word = word.substring(0, length) + ".."; }	
	document.write(word);
}

// launchCenter(url, name, width, height, att)
function launchCenter(url, name, width, height, att) 
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str += "," + att
  }
  return window.open(url, name, str);
}

// keyCode 가 13 일 경우 tab.
function enterTab(e, FocusName) {
  var focusname_obj = document.getElementsByName(FocusName);
  var ev = (window.event) ? window.event.keyCode : e.keyCode;

  if (ev == 13) { eval(focusname_obj[0].focus()); }
}

// keyCode 가 13 일 경우만 submit
function enterSubmit(e, SubmitName) {
	var ev = (window.event) ? window.event.keyCode : e.keyCode;

    if (ev == 13) {
		if(SubmitName != "") { eval(SubmitName + "()"); }
	}
}

// 준비중
function ready() {
	window.alert("해당메뉴는 서비스 준비중입니다.");
}

// add event listener (cf. onload)
function addLoadEvent(func)
{
	var oldonload = window.onload;
	window.onload = (typeof window.onload != 'function') ? func : function() {
		if (oldonload) { oldonload(); }
		func();
	}
}

// 특정 문자만 입력받기 (나머지 글자 무시)
function chkInputVal(targetEl, mode)
{ 
	tmpVal = targetEl.value.toString(); 
	regexp = ''; 
	repexp = ''; 
	switch(mode) {
		case 'small':regexp = /[^a-z]/g;break;
		case 'smallnum':regexp = /[^a-z0-9]/g;break;
		case 'smallnumunder':regexp = /[^a-z0-9_]/g;break;
		case 'big':regexp = /[^A-Z]/g;break;
		case 'all':regexp = /[^a-z]/i;break;
		default :regexp = /[^a-z]/i;break;
	}
	tmpVal = tmpVal.replace(regexp, repexp);
	
	// chk : returnVal
	var returnVal = "";
	if ( targetEl.value.toString() == tmpVal ) {
		returnVal = "true";
	}
	else { returnVal = "false"; }

	targetEl.value = tmpVal;	
	return returnVal;
}

// mailto : 단순메일링크 생성
function mailTo(mailAdd)
{
	if ( confirm(mailAdd+" 로 이메일을 발송하시겠습니까?") ) {
		window.location.href = "mailto:"+mailAdd;
	}
}

// 이미지 미리보기 (이미지만 보임)
function imgPreWin(picName, windowName, windowWidth, windowHeight)
{
	var winHandle = window.open("", "_blank","left=0, top=0,toolbar=no,scrollbars=no,resizable=no,width=" + windowWidth + ",height=" + windowHeight);
	if (winHandle != null)
	{
		var htmlString = "<html><head><title>"+windowName+"</title></head>"
			+ "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
			+ "<a href=javascript:window.close()><img src='" + picName + "' border='0' alt='창 닫기'></a>"
			+ "</body></html>";
		winHandle.document.open();
		winHandle.document.write(htmlString);
		winHandle.document.close();
	}
	if(winHandle != null) winHandle.focus();
}

//Email 형식 check
function emailChk(fieldID)
{
	re=/^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$/i;
	return ( $F(fieldID).length<6 || !re.test($F(fieldID)) ) ? false : true;
}

/* 간단한 img resize */
function resizeImg(imgEl, imgX, imgY) {
	if ( $(imgEl) && (!isNaN(imgX) && !isNaN(imgY)) ) {
		var imgXbo = false;

		if (imgEl.width > imgX) {
			if (imgX > 0) {
				imgEl.width = imgX;
				imgXbo = true;
			}
		}
		if (imgEl.height > imgY) {
			if (imgY > 0) {
				if (imgXbo == true) imgEl.width = imgEl.width/(imgEl.height/imgY);
				imgEl.height = imgY;
			}
		}
	}
}


/* 우편번호찾기 */
function new_zipcode(formName, i_zipcode, i_add) {
	window.open("../inc/zipcode.php?form="+formName+"&i_zipcode="+i_zipcode+"&i_add="+i_add, "_blank", "width=492,height=300,top=100,left=100,scrollbars=yes");
}


/* Email 형식 check (old) */
function Email_chk(Form_Name, Field_Name) {
	var t = eval("document." + Form_Name + "." + Field_Name + ".value");
	var ValidFlag = false;
	var atCount = 0;
	var SpecialFlag;
	var atLoop;
	var atChr;
	var BadFlag;
	var tAry1;
	var UserName;
	var DomainName;
	
	if(t.length > 0 && t.indexOf("@") > 0 && t.indexOf(".") > 0) {
		atCount = 0;
		SpecialFlag = false;
		
		for(atLoop=1; atLoop<=t.length; atLoop++) {
			atChr = t.substring(atLoop, atLoop+1);
			
			if(atChr == "@") atCount = atCount + 1;
			if((atChr >= 32) && (atChr <= 44)) SpecialFlag = true;
			if((atChr == 47) || (atChr == 96) || (atChr >= 123)) SpecialFlag = true;
			if((atChr >= 58) && (atChr <= 63)) SpecialFlag = true;
			if((atChr >= 91) && (atChr <= 94)) SpecialFlag = true;
		}
		
		if((atCount == 1) && (SpecialFlag == false)) {
			BadFlag = false;
			tAry1 = t.split("@");
			UserName = tAry1[0];
			DomainName = tAry1[1];
			
			if((UserName.length <= 0) || (DomainName.length <= 0 )) BadFlag = true;
			if(DomainName.substring(1, 2 ) == ".") BadFlag = true;
			if(DomainName.substring(DomainName.length-1, DomainName.length) == ".") BadFlag = true;
			
			ValidFlag = true;
		}
	}
	
	if(BadFlag == true) ValidFlag = false;
	
	return ValidFlag;
}
