//확인창 스크립트 - 특정 문구를 사용할 경우에는 msg 에 값 입력, '삭제하시겠습니까?' 기본값

function ConfirmMsg(msg){
	if(msg) var chk = confirm(msg);
	else var chk = confirm("처리하시겠습니까?");

	if(chk) return true;
	else return false;
}

//이메일 함수 변경 추가 - FormBoxClass 의 email 셋팅과 연동
function domainChange(obj){
	var input = jQuery("#emal_domain");
	var email_domain = obj.value;
	
	if(!email_domain) {
		input.val('');
		input.attr("readonly","");
	}
	else {
		input.val(email_domain);
		input.attr("readonly","readonly");
	}
}

//이미지 사이즈가 클 경우 처리
function ImgResize(obj, width){
	if(!obj) var obj = ".board_viewDetail";
	if(!width) var width = 600;

	jQuery(obj + " img").each(
		function(i){
			if(this.width == 0) this.width = jQuery(this).parent().width();
			if(this.width > width){
				this.width = width;
			}
			
			//이미지 정보 불러오기
			var img = jQuery(this).attr("src");

			//링크생성
			var link = jQuery("<a></a>");

			//링크에 이미지 추가 및 facebox 셋팅
			link.attr({"href":img,"rel":"facebox"});
			jQuery(this).wrap(link);
			
			this.style.border = "1px solid #999";
		}
	);
}

//자바스크립트 trim
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/gi, "");
}

//입력폼 필수처리
function disableForm(form, obj){
	var arr = form.split(',');
	var cnt = arr.length;
	
	if(!document.getElementById(arr[0]).disabled) {
		for(i=0;i<cnt;i++){
			document.getElementById(arr[i].trim()).disabled = true;
		}
		jQuery(obj).find('span').html('사용함');
	}
	else {
		for(i=0;i<cnt;i++){
			document.getElementById(arr[i].trim()).disabled = false;
		}
		jQuery(obj).find('span').html('사용안함');
	}
}



//새창 뛰우기 
function openwin(code,linkurl,width,height,scroll)
{		

	/*** 팝업 창 화면 중앙에 오픈시키기**/
	
	if ( getCookie(code) != "done" )	{
	    var str;
	    
	    str = "height=" + height + ",innerHeight=" + height;
	    str += ",width=" + width + ",innerWidth=" + width;
	    if(scroll==1) str += ",scrollbars=yes";
	
	    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;

	    }
		//팝업이 없을시 아래 2줄 앞부분을 "//"으로 가려줌
	    noticeWindow = window.open(linkurl, code , str);
	    //noticeWindow.opener = self;
	    noticeWindow.focus();
	}
}

//쿠키
function setCookie( name, value, expiredays ) { 
 var todayDate = new Date(); 
 todayDate.setDate( todayDate.getDate() + expiredays ); 
 document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
} 

function getCookie(name) 
{ 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; while(i< clen) 
	{ 
		var j = i + alen; 
		if(document.cookie.substring(i,j)==arg)
			{ 
			var end = document.cookie.indexOf(";",j); 
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(j,end)); 
			} 
		i=document.cookie.indexOf(" ",i)+1; 
		if (i==0) break; 
	} 
	return null; 
}

//팝업창 관련
function close_layer(id,to_close){
	document.getElementById(id).style.display = 'none';
	//쿠키굽기
	if(to_close=="Y"){
		setCookie(id, 'done' , 1); 
	}
}

//클립보드 복사하기
function clipboard(str){
	if(window.clipboardData){
		window.clipboardData.setData("Text",str);
		alert('클립보드에 복사되었습니다. Ctrl + v 로 붙여넣기 하세요.');
	}else{
		alert("해당 브라우져에서는 복사하기 기능이 작동하지 않습니다.\n\nflash 로 처리하기 귀찮...-ε -;");
	}
}

//facebox forminit

function formInit(obj){
	site.showBG();

	var dialog = obj
	
	var width = dialog.width();
	var height = dialog.height();

	var top = jQuery("body").height()/2 - height / 2;
	var left = jQuery("body").width()/2 - width / 2;

	jQuery("body").scrollTop(0);

	dialog.css({"position":"absolute","top":top,"left":left,"z-index":"99"});

	dialog.fadeIn();

	dialog.find(".close a").click(function(){
		jQuery(this).parent().parent().fadeOut();
		site.hideBG();
	});

	return dialog;
}

// flash(파일경로, 가로, 세로, 아이디, 배경색, 변수윈도우모드(transparent, opaque), 보안사항(sameDomain, always))
function flash(url,w,h,id,win){
	
	if(!win) win ="transparent";

	// 플래시 정의
	var flashStr=
		"<object type='application/x-shockwave-flash' id='"+id+"' title='"+id+"' data='"+url+"' width='"+w+"' height='"+h+"'>"+
		"<param name='movie' value='"+url+"' />"+
		"<param name='wmode' value='"+win+"' />"+
		"</object>";

 // 플래시 출력
 document.write(flashStr);
}
