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

// 플래시 스크립트
function flashTrace(url,id,w,h,bg,vars,win){
	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='FlashVars' value='"+vars+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";
	document.write(flashStr);
}

//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 + "()"); }
	}
}

//----- 이미지가 load 된 후에 이미지 resize s. -----//
function ImgResize(ImgName, width, height) {
	var True_width = ImgName.width;
	var True_height = ImgName.height;
	
	try
	{
		//가로가 '0'일 경우 세로 기준으로 이미지 resize
		if(width == 0 && height != 0) {
			//원본 세로가 선언된 세로보다 클경우 선언된 세로로 resize.
			if(True_height > height) {
				var Fixed_height = height;
			}
		} else if(width != 0 && height == 0) {
			//세로가 '0'일 경우 가로 기준으로 이미지 resize
			//원본 가로가 선언된 가로보다 클경우 선언된 가로로 resize.
			if(True_width > width) {
				var Fixed_width = width;
			}
		} else {
			//가로, 세로 둘다 '0'이 아닐 경우
			//이미지의 가로 사이즈와 세로 사이즈중 큰값 확인.
			//가로가 세로보다 클경우.
			//가로를 기준으로 이미지 resize.
			if(True_width * height > True_height * width) {
				if(True_width > width) {
					var Fixed_width = width;
				}
			} else {
				//세로가 가로보다 클경우.
				//세로를 기준으로 이미지 resize.
				if(True_height > height) {
					var Fixed_height = height;
				}
			}
		}
		
		//가로, 세로 중 하나의 사이즈라도 '0'일 경우.(이미지 사이즈를 재대로 가져오지 못했을 경우.)
		if(True_width == 0 || True_height == 0) {
			if(width != 0) {
				ImgName.width = width;
			}
			if(height != 0) {
				ImgName.height = height;
			}
		} else {
			//이미지 사이즈를 제대로 가져왔을 경우.
			if(Fixed_width) { 
				ImgName.width = Fixed_width;
			} else if(Fixed_height) {
				ImgName.height = Fixed_height;
			}
		}
	}
	catch(e)
	{
	}
}
//----- 이미지가 load 된 후에 이미지 resize e. -----//

//----- 이미지 높이에 맞춰서 div 높이 맞춰주기 s. -----//
function ImgDivheight(DivName, ImgName, height, pad) {
	if(parseInt(ImgName.height) > height) {
		DivName.style.height = height + pad;
	}
}
//----- 이미지 높이에 맞춰서 div 높이 맞춰주기 e. -----//


// keyCode 가 13 일 경우 tab.
function EnterTab(FocusName) {
  if (window.event.keyCode == 13) {    
	eval("document.all." + FocusName + ".focus()");
  }
}

// keyCode 가 13 일 경우만 submit
function EnterSubmit(SubmitName) {
	if(window.event.keyCode == 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;

	if( $F(fieldID).length<6 || !re.test($F(fieldID)) ) {
			alert("이메일형식이 바르지 않습니다.");
			$(fieldID).value="";
			$(fieldID).focus();
			return false;
	}
	else { return true; }
}
