function CharLength(str) {
	var tmpStr;
	var temp = 0;
	var onechar;
	var tcount = 0;

	tmpStr = new String(str);
	temp = tmpStr.length;
	for (var k=0;k<temp;k++) {
		onechar = tmpStr.charAt(k);
		if (escape(onechar).length > 4) {
			tcount += 2;
		}
		else if (onechar!='\r') {
			tcount++;
		}
	}

	return tcount;
}

function trim(value) {  
	return value.replace(/^\s+|\s+$/g,"");  
}

function ZipCode() {
	open("/common/include/pop_search_post.asp", "zipcode", "toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no, width=400, height=350");
}
/*
function OnlyNumber(){
	if(((event.keyCode<48)||(57<event.keyCode))&&(45!=event.keyCode)) event.returnValue=false;}
*/
function Validchar(g,str){
	for( var i=0 ; i < g.length; i++ ){
		if( str.indexOf(g.charAt(i)) == -1 ) return g.charAt(i);
	}
	return true;
}

function ChkPhoneLen (ss,len) {
	var val = Object.length;
	alert(ss);

}

function ChkInput(Object,Name) {
	if (typeof(Object)!="undefined") {
		if(Object.value=="") {
			alert(Name);
			eval(Object.focus());
			return false;
		}
	}
}

function ChkSelect(Object,Name) {
	if(!Object.options[Object.selectedIndex].value) {
		alert(Name);
		eval(Object.focus());
		return false;
	}
}

function ChkArray(Object,Name) {
	var Key=0;

	if (Object!=null && isNaN(Object.length)) {
		if (!Object.checked) {
			alert(Name);
			return false;
		}
	} else {

        if(Object!=null) {
    		for(i=0;i<Object.length;i++) if(!Object[i].checked) Key++;
    		if(Key==Object.length){
    			alert(Name);
    			return false;
    		}
    	} else {
    	    alert("자료가 없습니다.");
    	    return false;   
    	}
	}
}

function ChkNumeric(Object,Name) {
	if (typeof(Object)!="undefined") {
		if(isNaN(Object.value) == true) {
			alert(Name);
			eval(Object.focus());
			return false;
		}
	}
}


/* 미디어 공통 사용 */
function MediaObject(URL, Name, width, height) {
	document.write('<object ID="'+Name+'" name="'+Name+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"  standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" align="middle" width="'+width+'" height="'+height+'">');
	document.write('  <param name="CurrentPosition" value="1">');
	document.write('  <param name="SetCurrentEntry" value="1">');
	document.write('  <param name="ClickToPlay" value="1">');
	document.write('  <param name="AutoSize" value="0">');
	document.write('  <param name="AutoStart" value="1">');
	document.write('  <param name="ShowControls" value="1">');
	document.write('  <param name="ShowAudioControls" value="1">');
	document.write('  <param name="ShowDisplay" value="0">');
	document.write('  <param name="ShowStatusBar" value="1">');
	document.write('  <param name="EnableContextMenu" value="0">');
	document.write('  <param name="ShowPositionControls" value="0">');
	document.write('  <param name="DisplayBackColor" value="0">');
	document.write('  <param name="ShowTracker" value="1">');
	document.write('  <param name="ShowCaptioning" value="0">');
	document.write('  <param name="AutoRewind" value="0">');
	document.write('  <param name="EnableTracker" value="1">');
	document.write('  <param name="Volume" value="-1">');
	document.write('  <param name="Filename" value="'+URL+'">');
	document.write('</object>');
}

function ShowProgressNew(ProgID) { 
	strAppVersion = navigator.appVersion;
	if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4) {
		winstyle = "dialogWidth=385px; dialogHeight:160px; center:yes";
		window.showModelessDialog("/common/inc/progress.asp?Progressid="+ProgID,null,winstyle); 
	}
	else {
		winpos = "left=" + ((window.screen.width-380)/2) + ",top=" + ((window.screen.height-110)/2);
		winstyle="width=380,height=110,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
		window.open("/common/inc/progress.asp?Progressid="+ProgID,null,winstyle); 
	}
}

function openPopupWin(url, name, width, height) {
	window.open (url, name, 'scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, width=' + width + ', height=' + height) ;
}

function getValueById(objId) {
	var resultVal = "";
	var resultObj = document.getElementById(objId);

	if(resultObj!=null)
		resultVal = resultObj.value;

	return resultVal;
}

function ChkLen(obj, len) {
	if(obj.value.length > len) {
		alert(len+"자 제한이 되어 있습니다");
		//obj.value = obj.value.substring(0,len);
		return false;
	}
}


//============================================
//이메일 체크
//============================================
function email_CHK(emailad) 
{ 
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/; 
	var check=/@[\w\-]+\./; 
	var checkend=/\.[a-zA-Z]{2,3}$/; 

   if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
   { 
	   return false; 
   }else 
   { 
  		return true;
   } 
} 

//============================================
//스페이스 체크 함수
//============================================
function CheckSpaces(strValue) 
{
	var flag=true;

	if (strValue!="") 
	{
		for (var i=0; i < strValue.length; i++) 
		{
			if (strValue.charAt(i) != " ") 
			{
				flag=false;
				break;
			}
		}
	}
	return flag;
}



//============================================
// 필수입력 체크 및 길이 체크 함수 
//		CheckSpaces();
//		성공:true 실패: alert() 띄우고 return false
//============================================
function chk_len(theitem, maxlength, strTitle)
{
	var tmpStr;;
	tmpStr = theitem.value;
	
	if (CheckSpaces(tmpStr))
	{{
		alert(strTitle + '을(를) 입력하세요.');
		theitem.value = '';
		theitem.focus();
		return false;
	}}
	
	return cal_len(theitem, tmpStr, maxlength, strTitle);
	
}

//============================================
// 미필수입력 길이 체크 함수
//============================================
function unfinChk_len(theitem, maxlength, strTitle)
{
	var tmpStr;;
	tmpStr = theitem.value;
	
	return cal_len(theitem, tmpStr, maxlength, strTitle);
}


//============================================
// 길이 체크 함수 
//============================================
function cal_len(theform,str,maxlength, strTitle) 
{
	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;
	 
	tmpStr = new String(str);
	temp = tmpStr.length;

	for (k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);

		if (escape(onechar).length > 4) {
			tcount += 2;
			max_char=maxlength/2; 
		}
		else if (onechar!='\r') {
			tcount++;
			max_char=maxlength; 			
		}
	}

	if(tcount>maxlength) {
		reserve = tcount-maxlength;
		alert(strTitle + "은(는) " + max_char+"자 이상 입력하실 수 없습니다.\n한글은 2자로 계산됩니다."); 
		
		theform.select();
		theform.focus();
		return false;
	}
	return true;
}

//이미지 미리 보기
function ImagePreView(what) { 
	var imgwin = window.open("","WIN","scrollbars=yes,status=no,toolbar=no,resizable=1,location=no,menu=no,width=10,height=10,top=0,left=0"); 
	imgwin.focus(); 
	imgwin.document.open(); 
	imgwin.document.write("<html>\n"); 
	imgwin.document.write("<head>\n"); 
	imgwin.document.write("<title>Image</title>\n"); 
	imgwin.document.write("<sc"+"ript>\n"); 
	imgwin.document.write("function resize() {\n"); 
	imgwin.document.write("pic = document.il;\n"); 
	imgwin.document.write("if (eval(pic).height) { var name = navigator.appName\n"); 
	imgwin.document.write("  if (name == 'Microsoft Internet Explorer') { myHeight = eval(pic).height + 80; myWidth = eval(pic).width + 30;\n"); 
	imgwin.document.write("  } else { myHeight = eval(pic).height + 9; myWidth = eval(pic).width; }\n"); 
	imgwin.document.write("  clearTimeout();\n"); 
	imgwin.document.write("  var height = screen.height;\n"); 
	imgwin.document.write("  var width = screen.width;\n"); 
	imgwin.document.write("  var leftpos = width / 2 - myWidth / 2;\n"); 
	imgwin.document.write("  var toppos = height / 2 - myHeight / 2; \n"); 
	imgwin.document.write("  self.resizeTo(myWidth, myHeight);\n"); 
	imgwin.document.write("}else setTimeOut(resize(), 100);}\n"); 
	imgwin.document.write("</sc"+"ript>\n"); 
	imgwin.document.write("</head>\n"); 
	imgwin.document.write('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#FFFFFF">\n'); 
	imgwin.document.write("<center><a href='javascript:window.close()'><img border=0 src='"+what+"' xwidth=100 xheight=9 name=il onload='resize();'></a>\n");
	imgwin.document.write("</center>");
	imgwin.document.write("</body>\n"); 
	imgwin.document.close(); 
}


var fnm, fp1, fp2, fa1, fa2;
function popSearchPost(form, po1, po2, ad1, ad2) {
	fnm = form;
	fp1 = po1;
	fp2 = po2;
	fa1 = ad1;
	fa2 = ad2;

	var url = "/common/inc/pop_search_post.asp?popName=searchPost";
	CreateFrame("searchPost", url, "400", "400");
}

function ImgResize(obj, w, h) {
	var iw = obj.width;
	var ih = obj.height;

	if (w != 0 || h != 0) {
		if (w == 0) {
			if(obj.height > h) obj.height = h;
		} else if (h == 0) {
			if(obj.width > w) obj.width = w;
		} else {
			if (iw/w > ih/h) {
				if(obj.width > w) obj.width = w;
			} else {
				if(obj.height > h) obj.height = h;
			}
		}
	}
}
function ImgResize2(size, div_name) {
	// DivContents 영역에서 이미지가 maxsize 보다 크면 자동 리사이즈 시켜줌
	var maxsize = size; // 가로사이즈 ( 다른값으로 지정하면됨)
	var content = document.getElementById(div_name);
	var img = content.getElementsByTagName("img");
	for(i=0; i<img.length; i++) {
//		alert( eval('img[' + i + '].width'));
		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') ;
		}
	}
}
//업로드 파일명 체크
function FileCheck(file,imgchk){

	//파일명만 추출하자..
	var str = file.value;
	var pos = str.lastIndexOf("\\");
	var ln = str.lastIndexOf(".");
	var filename = str.substring(pos + 1, ln);
	var extname = str.substring(ln + 1);
	extname = extname.toLowerCase();
	
	/*
	var regexp = /^[a-zA-Z0-9_]*$/i;

	if(!regexp.test(filename)) {    
		alert("파일명은 영문과 숫자만 사용하실 수 있습니다.");
		return 0;
	}
	*/
	
	if (imgchk == "Y") {
		if (extname != "jpg" && extname != "jpeg" && extname != "png" && extname != "gif" && extname != "bmp") {    
			alert("이미지파일만 업로드 가능합니다.");
			return 0;
		}
	}

	return 1;
}

//인풋박스에 번호만 넣는 함수
function OnlyNumber( Ev ){ 

    var evCode = ( window.netscape ) ? Ev.which : event.keyCode ; 
	
    /* FF일 경우 Ev.which 값을, 
        IE을 경우 event.keyCode 값을 evCode에 대입 */ 
    if ( ! ( evCode == 0 || evCode == 8 || ( evCode > 47 && evCode < 58 ) ) ) { 
    /* 눌러진 키 코드가 숫자가 아닌 경우 
        ( '0'은 FF에서 Tab 키, 
          '8'은 FF에서 BackSpace가 먹히지 않아 삽입)    */ 
        if ( window.netscape ) {        // FF일 경우 
            Ev.preventDefault() ;        // 이벤트 무효화 
        } else {                                // IE일 경우 
            event.returnValue=false;    // 이벤트 무효화 
        } 
    } 
}


function Login() {
	var obj = document.frmLogin;

	if (ChkInput(obj.id, "아이디를 입력하세요.") == false) return;
	if (CharLength(obj.id.value) < 4) {
		alert("아이디는 4자 이상 입력하세요.");
		obj.id.focus();
		return;
	}
	if (ChkInput(obj.pass, "패스워드를 입력하세요.") == false) return;
	if (CharLength(obj.pass.value) < 4) {
		alert("패스워드는 4자 이상 입력하세요.");
		obj.pass.focus();
		return;
	}

	obj.submit();
}

function pstTwitter(msg,url) {
	var href = "http://twitter.com/home?status=" + encodeURIComponent(msg) + " " + encodeURIComponent(url);
	var a = window.open(href, 'twitter', '');
	return;
}
function pstMe2Day(msg,url,tag) {
	var href = "http://me2day.net/posts/new?new_post[body]=" + encodeURIComponent(msg) + " " + encodeURIComponent(url) + "&new_post[tags]=" + encodeURIComponent(tag);
	var a = window.open(href, 'me2Day', '');
	return;
}
function pstFaceBook(msg,url) {
	var href = "http://www.facebook.com/sharer.php?u=" + url + "&t=" + encodeURIComponent(msg);
	var a = window.open(href, 'facebook', '');
	return;
}

function pstYozmDaum(link,prefix,parameter) {
	var href = "http://yozm.daum.net/api/popup/prePost?sourceid=54&link=" + encodeURIComponent(link) + "&prefix=" + encodeURIComponent(prefix) + "&parameter=" + encodeURIComponent(parameter);
	var a = window.open(href, 'yozm', 'width=466, height=356');
	
	return;
}
