function boardSel(tab,obj)
{
	location.href="board.php?table="+tab+"&sca="+obj;
}

function searchForm(id)
{
     var f=document.sch;
     if (f.txtWord.value=="") {
        alert("검색하실 검색어를 입력하십시오.");
        f.txtWord.focus();
        return;
     }
     
     f.method="post";
     f.action="board.php?table="+id;
     f.submit();
}

function regOK() {
	var f=document.regform;

	if (f.hMail.value=="")
	{
		alert("이메일 아이디를 입력하여 주시기 바랍니다.");
		f.hMail.focus();
		return false;
	}

	if (f.isSelect.options[f.isSelect.selectedIndex].value=="")
	{
		alert("이메일 주소(URL)을 선택하여 주시기 바랍니다.");
		f.isSelect.focus();
		return false;

	}

	if (f.passwd.value=="")
	{
		alert("비밀번호를 입력하여 주시기 바랍니다.");
		f.passwd.focus();
		return false;
	}

	if (f.repasswd.value=="")
	{
		alert("비밀번호를 입력하여 주시기 바랍니다.");
		f.repasswd.focus();
		return false;
	}

	if (f.passwd.value != f.repasswd.value) {
        alert("입력하신 비밀번호가 일치하지 않습니다.\n다시 확인하시고 입력하여 주십시오.");
        f.repasswd.focus();
        return false;
	}

	if (f.username.value=="")
	{
       alert("본명을 입력해 주세요");
	   f.username.focus();
	   return false;
	}

    if (!f.birthY.options[f.birthY.selectedIndex].value)
    {
		alert("년도를 선택하여 주세요.");
		f.birthY.focus();
		return false;
    }

    if (!f.birthM.options[f.birthM.selectedIndex].value)
    {
		alert("월을 선택하여 주세요.");
		f.birthM.focus();
		return false;
    }

	if (!f.birthD.options[f.birthD.selectedIndex].value)
    {
		alert("일을 선택하여 주세요.");
		f.birthD.focus();
		return false;
    }

	if(f.mailYN.checked==true) {
		f.mailYN.value="Y";
	}

	if(f.fbYN.checked==true) {
		f.fbYN.value="Y";
	}

    f.action="act.php?mode=dSave";
	f.method="post";
}


function regEdit() {
	var f=document.regform;

	if (f.passwd.value != f.repasswd.value) {
        alert("입력하신 비밀번호가 일치하지 않습니다.\n다시 확인하시고 입력하여 주십시오.");
        f.repasswd.focus();
        return false;
	}

	if (f.username.value=="")
	{
       alert("본명을 입력해 주세요");
	   f.username.focus();
	   return false;
	}

    if (!f.birthY.options[f.birthY.selectedIndex].value)
    {
		alert("년도를 선택하여 주세요.");
		f.birthY.focus();
		return false;
    }

    if (!f.birthM.options[f.birthM.selectedIndex].value)
    {
		alert("월을 선택하여 주세요.");
		f.birthM.focus();
		return false;
    }

	if (!f.birthD.options[f.birthD.selectedIndex].value)
    {
		alert("일을 선택하여 주세요.");
		f.birthD.focus();
		return false;
    }

	if(f.mailYN.checked==true) {
		f.mailYN.value="Y";
	}

	if(f.fbYN.checked==true) {
		f.fbYN.value="Y";
	}

    f.action="act.php?mode=eSave";
	f.method="post";
}

function openNick() {
	    var winWidth = 300;
        var winHeight = 300;
        var winPosLeft = (screen.width - winWidth) / 2;
        var winPosTop = (screen.height - winHeight) / 2;
        var winOpt = "width="+winWidth+",height="+winHeight+",top="+winPosTop+",left="+winPosLeft;
        window.open("nickname_search.html", "_new", winOpt + "");
}

function idFind() {
		var f=document.yform;

		if (f.UserName.value=="")
		{
			alert("회원 이름을 입력하여 주세요.");
			f.UserName.focus();
			return;
		}

		 if (f.uGender.value=="")
		{
			alert("성별을 체크하여 주시기 바랍니다.");
			f.uGender[0].focus();
			return;
		}

	    var winWidth = 300;
        var winHeight = 300;
        var winPosLeft = (screen.width - winWidth) / 2;
        var winPosTop = (screen.height - winHeight) / 2;

		if(f.uGender[0].checked==true) {
		   f.uGender.value="1";
	    } else {
		   f.uGender.value="2";
		}
        var winOpt = "width="+winWidth+",height="+winHeight+",top="+winPosTop+",left="+winPosLeft;
        window.open("id_find.html?uname="+f.UserName.value+"&birthY="+f.birthY.options[f.birthY.selectedIndex].value+"&birthM="+f.birthM.options[f.birthM.selectedIndex].value+"&birthD="+f.birthD.options[f.birthD.selectedIndex].value+"&gender="+f.uGender.value, "_new", winOpt + "");
}


function pwFind() {
		var f=document.yform;

		if (f.UserMail.value=="")
		{
			alert("이메일 주소를 입력하여 주세요.");
			f.UserMail.focus();
			return;
		}

		if (f.iUserName.value=="")
		{
			alert("회원 이름을 입력하여 주세요.");
			f.iUserName.focus();
			return;
		}

		if (f.gender.value=="")
		{
			alert("성별을 체크하여 주시기 바랍니다.");
			f.gender[0].focus();
			return;
		}

	    var winWidth = 300;
        var winHeight = 300;
        var winPosLeft = (screen.width - winWidth) / 2;
        var winPosTop = (screen.height - winHeight) / 2;

		if(f.gender[0].checked==true) {
		   f.gender.value="1";
	    } else {
		   f.gender.value="2";
		}

        var winOpt = "width="+winWidth+",height="+winHeight+",top="+winPosTop+",left="+winPosLeft;
        window.open("pw_find.html?usermail="+f.UserMail.value+"&uname="+f.iUserName.value+"&birthY="+f.ibirthY.options[f.ibirthY.selectedIndex].value+"&birthM="+f.ibirthM.options[f.ibirthM.selectedIndex].value+"&birthD="+f.ibirthD.options[f.ibirthD.selectedIndex].value+"&gender="+f.gender.value, "_new", winOpt + "");
}

function rAgree()
{
	var f=document.yform;
	if (f.yakok1.checked==false)
	{
		alert("이용약관에 동의하셔야 회원에 가입할 수 있습니다.");
		f.yakok1.focus();
		f.yakok1.checked=true;
		return;

	}

	if (f.yakok2.checked==false)
	{
		alert("개인 정보수집 및 이용목적에 동의하셔야 회원에 가입할 수 있습니다.");
		f.yakok2.focus();
		f.yakok2.checked=true;
		return;
	}
	f.yakok1.value="Y";
    f.yakok2.value="Y";
	f.action="register_step1.html";
	f.method="post";
	f.submit();
}


var c=false;
                // 포커스가 인풋 박스안에 있을때 배경이미지 지우기
function ch (valueid) {
         if(valueid == 'id')  document.login_form.UserID.style.backgroundImage="";
         else document.login_form.PassWd.style.backgroundImage="";
         c=true;
}

                // 포커스가 인풋 박스를 벗어났을때 배경이미지 살리기 (입력값이 있으면 살리지 않기)
function chout (valueid) {
         if(valueid == 'id') {
            if(!document.login_form.UserID.value) document.login_form.UserID.style.backgroundImage="url(/images/log_id.gif)"; // 아이디에 쓰일 이미지경로
         }else {
            if(!document.login_form.PassWd.value) document.login_form.PassWd.style.backgroundImage="url(/images/log_pw.gif)"; //패스워드 쓰일 이미지경로
         }
         c=true;
}

function clearField(field) {
    if (field.value == field.defaultValue) {
        field.value = "";
    }
}

function checkField(field) {
    if (!field.value) {
        field.value = field.defaultValue;
    }
}

function emailServ(f) {
  var email_url=f.isSelect.options[f.isSelect.selectedIndex].text;

  if (email_url == "직접입력")  {
     f.isUrl.readOnly = false;
     f.isUrl.value="";
     f.hMail.focus();
  } else {
     f.isUrl.readOnly = true;
     f.isUrl.value=email_url;
     f.hMail.focus();
   }
  return;
}

function go_twiter(){
	urls = "http://twitter.com/home?status="+encodeURIComponent("'긴급후송' 신영록, 호흡 되찾았지만 여전히 의식불명상태") + "+http://www.sportalkorea.com/news/view.php?gisa_uniq=2011050816360427";
	window.open(urls,"tw","");
}
function go_meeto(){
	urls = "http://me2day.net/posts/new?new_post[body]=\""+encodeURIComponent("'긴급후송' 신영록, 호흡 되찾았지만 여전히 의식불명상태") + "\":"+ escape("http://www.sportalkorea.com/news/view.php?gisa_uniq=2011050816360427") +"&new_post[tags]=" + encodeURIComponent("스포탈코리아 뉴스 스크랩");
	window.open(urls,"mee","");
}
function go_naver(){
	urls = "http://bookmark.naver.com/post?ns=1&title="+encodeURIComponent("'긴급후송' 신영록, 호흡 되찾았지만 여전히 의식불명상태") + "&url="+ escape("http://www.sportalkorea.com/news/view.php?gisa_uniq=2011050816360427");
	window.open(urls,"na","");
}
function go_google(){
	urls = "http://www.google.com/bookmarks/mark?op=add&title=\""+encodeURIComponent("'긴급후송' 신영록, 호흡 되찾았지만 여전히 의식불명상태") + "\"&bkmk="+ escape("http://www.sportalkorea.com/news/view.php?gisa_uniq=2011050816360427");
	window.open(urls,"goo","");
}
 
function go_facebook(){
	urls = "http://www.facebook.com/sharer.php?u=http://www.sportalkorea.com/news/view.php?gisa_uniq=2011050816360427&t=" + encodeURIComponent("'긴급후송' 신영록, 호흡 되찾았지만 여전히 의식불명상태"); 
	window.open(urls,"fc","");
}

function go_cyworld(){
	urls = "http://csp.cyworld.com/bi/bi_recommend_pop_euc.php?url=http%3A%2F%2Fwww.sportalkorea.com%2Fnews%2Fview.php%3Fgisa_uniq%3D2011050816360427&title=J7Hksd7IxLzbJyC9xb%2B1t88sIMijyO0gtcfDo77Swfa4uCC%2FqcD8yPcgwMe9xLrSuO2788XC&thumbnail=http://img.sportalkorea.com/service_img/2011/SK004_20110508_270201.jpg&summary=W726xvfFu8TauK6%2Bxj3BpsHWXSDAzLDmx%2BUgseLA2j0gsOax4iC1tcHfIL6yt6%2FBriC6tL%2F4wLi3ziCx5LHeIMjEvNu1yCC9xb%2B1t88oMjQsIMGmwdYpwMwgwMe9xMC7ILXHw6PB9iC4%2BMfPsO0gwNa02S4NCg0KvcW%2FtbfPwLogOMDPIL%2FAyMQgM73DIMGmwdbBvsfVsOax4sDlv6G8rSC%2FrS4uLg%3D%3D&writer=sportalkorea";
	window.open(urls,"fc","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no");
}

function borderIt(which,color) {
         if (document.all || document.getElementById) {
            which.style.borderColor=color
         }

}

function logOut()
{
   if(confirm("로그아웃 하시겠습니까?")) {
      location.replace("logout.php");
  } else return;
}

function imgFile() {
	 var src = $("input[name=files]").val();    
     if (!src.match(/\.(gif|jpg|png)$/i)) { alert("이미지 파일이 아닙니다.\n지원하는 파일은 GIF/JPG/PNG파일입니다."); return false; }
}

function openWin(){
  window.open("danga.html","null","scrollbars=yes,toolbar=no,status=no,width=1000,height=705")
}


function qsearch() {
    var f=document.sform;
    if (f.KeyWord.value.replace(/ /g, "")=="") {
       alert("검색하고자하는 검새어를 입력해주세요!");
       f.KeyWord.focus();
       return false;
    }

    f.method="get";
    f.action="search_result.html";
}

function imgPOP(table,id,img,w,h) {
        var winWidth = w;
        var winHeight = h+30;
        var winPosLeft = (screen.width - winWidth) / 2;
        var winPosTop = (screen.height - winHeight) / 2;
        var winOpt = "width="+winWidth+",height="+winHeight+",top=0,left="+winPosLeft;
        window.open("imgPOP.php?table="+table+"&id="+id+"&img="+img, "_blank", winOpt + "");
}

function loGIN() {
     var f=document.login_form;
     if (f.UserID.value.replace(/ /g, "")=="") {
        alert('아이디를 입력하여 주십시오');
        f.UserID.focus();
        return false;
     }

     if (f.PassWd.value.replace(/ /g, "")=="") {
        alert('비밀번호를 입력하여 주십시오.');
        f.PassWd.focus();
        return false;
     }
     f.action="loginfrm.php";
     f.method="post";
}


function pwdGIN() {
     var f=document.login_form;
     if (f.UserID.value.replace(/ /g, "")=="") {
        alert('아이디를 입력하여 주십시오.');
        f.UserID.focus();
        return false;
     }
     
     if (f.UserMail.value.replace(/ /g, "")=="") {
        alert('등록한 이메일 주소를 입력하여 주십시오.');
        f.UserMail.focus();
        return false;
     }
         
     f.target="_parent";
     f.action="act.php?mode=pwdFind";
     f.method="post";
}

function talGIN() {
     var f=document.login_form;
     var check;
     if (f.UserID.value.replace(/ /g, "")=="") {
        alert('아이디를 입력하여 주십시오.');
        f.UserID.focus();
        return false;
     }

     if (f.UserMail.value.replace(/ /g, "")=="") {
        alert('등록한 이메일 주소를 입력하여 주십시오.');
        f.UserMail.focus();
        return false;
     }

   check = confirm("탈퇴를 진행 하시겠습니까?");
   if(check==true) { 
     f.target="_parent";
     f.action="act.php?mode=tal";
     f.method="post";
   }
}

function FlashBody(Ftrans,wid,hei) {
        mainbody = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='"+ wid +"' height='"+ hei +"'>";
        mainbody += "<param name='movie' value='"+ Ftrans +"'>";
        mainbody += "<param name='quality' value='high'>";
        mainbody += "<param name='menu' value='false'>";
        mainbody += "<param name='scale' value='noscale'>";
        mainbody += "<param name='wmode' value='transparent'>";
        mainbody += "<param name='salign' value='lt' />";
        mainbody += "<embed src='"+ Ftrans +"' quality='high' scale='noscale' salign='lt' align='top' wmode='Transparent' align='middle' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ wid +"' height='"+ hei +"'></embed>"
        mainbody += "</object>";

        //document.body.innerHTML = mainbody;
        document.write(mainbody);
        return;
} 

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 nameOfCookie = name + "=";
  var x = 0;

  while ( x <= document.cookie.length ){
   var y = (x+nameOfCookie.length);
   if ( document.cookie.substring( x, y ) == nameOfCookie ) {
    if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ){
     endOfCookie = document.cookie.length;}
   return unescape( document.cookie.substring( y, endOfCookie ) );
   }
   x = document.cookie.indexOf( " ", x ) + 1;
   if ( x == 0 ){break;}
  }
  return "";
 }


 /************** Board 관련 함수 ***/
function boardform(obj) {
   var f=document.boardw;
   //var content=ed.getHtml().replace(/&lt;br&gt;|\s/g,"");
   var content=ed.getHtml();
   var x=document.getElementsByName("sca");

   if (obj !==110628) {
      if (f.secYN.checked==true) {
         f.secYN.value="1";
      } else {
         f.secYN.value="0";
      }

     if (f.username.value=="") {
        alert("글쓴이를 입력하여 주십시오.");
        f.username.focus();
        return false;
     }

     if (x.length > 0 && f.sca.options[f.sca.selectedIndex].value=="") {
        alert("분류를 선택하여 주십시오.");
        f.sca.focus();
        return false;
     }
   }//끝

   if (f.subject.value=="") {
      alert("제목을 입력하여 주십시오.");
      f.subject.focus();
      return false;
   }

   if (content=="" || content=="<P>&nbsp;</P>") {
      alert('내용을 입력하여 주시기 바랍니다.');
      ed.focus(); 
      return false;
   }
   
   f.method="post";
   f.action="boardwrite_result.php";
}

function boardModify(obj) {
   var f=document.boardm;
   var x=document.getElementsByName("sca");
   var content=ed.getHtml();
   if (obj !==110628) {
   if (f.secYN.checked==true) {
       f.secYN.value="1";
   } else {
       f.secYN.value="0";
   }

   if (f.username.value=="") {
      alert("글쓴이를 입력하여 주십시오.");
      f.username.focus();
      return;
   }

   if (x.length > 0 && f.sca.options[f.sca.selectedIndex].value=="") {
      alert("분류를 선택하여 주십시오.");
      f.sca.focus();
      return;
   }
   }//끝

   if (f.subject.value=="") {
      alert("제목을 입력하여 주십시오.");
      f.subject.focus();
      return;
   }

   if (content=="" || content=="<P>&nbsp;</P>") {
      alert('내용을 입력하여 주시기 바랍니다.');
      ed.focus(); 
      return;
   }

   f.method="post";
   f.action="boardmodify_result.php?table="+idx+"&num="+ndx;
   f.submit();
}

function boardReply() {
   var f=document.boardre;
   var x=document.getElementsByName("sca");
   var content=ed.getHtml();
   if (obj !==110628) {
   if (f.secYN.checked==true) {
       f.secYN.value="1";
   } else {
       f.secYN.value="0";
   }



   if (f.username.value=="") {
      alert("글쓴이를 입력하여 주십시오.");
      f.username.focus();
      return;
   }
  
   if (x.length > 0 && f.sca.options[f.sca.selectedIndex].value=="") {
      alert("분류를 선택하여 주십시오.");
      f.sca.focus();
      return;
   }
   }//끝


   if (f.subject.value=="") {
      alert("제목을 입력하여 주십시오.");
      f.subject.focus();
      return;
   }

   if (content=="" || content=="<P>&nbsp;</P>") {
      alert('내용을 입력하여 주시기 바랍니다.');
      ed.focus(); 
      return;
   }

   f.action="boardreply_result.php?table="+idx+"&num="+ndx;
   f.method="post";
   f.submit();
}

function myConfirm(t,id) {
   var check;
   var f=document.boardview;
   check = confirm("삭제를 하시겠습니까?");
   if(check==true) {
     f.method="post";
     f.action="boarddelete_result.php?table="+t+"&num="+id;
     f.submit();
    }
}

function memowriteform() {
     var f=document.memoform;

     if (f.memo.value=="") {
        alert("댓글 내용을 입력하십시오.");
        f.memo.focus();
        return;
     }

     f.method="post";
     f.action="memo_writeok.php";
     f.submit();
}

function etctxt_count(filed, max_count) {
    var str;
    var str_count = 0;
    var cut_count = 0;
    var max_length = max_count;
    var str_length = filed.value.length;

    for (k=0;k<str_length;k++) {
        str = filed.value.charAt(k);
        if (escape(str).length > 4) {
            str_count += 2;
            max_length -= 2;
        } else {
            // (\r\n은 1byte 처리)
            if (escape(str) == '%0A') {
            } else {
                str_count++;
                max_length--;
            }
        }

        if (max_count < str_count) {
            alert("글자수가 "+ (max_count/2) +"자 이상은 사용불가능합니다");
            if (escape(str).length > 4) {
                str_count -= 2;
                max_length += 2;
            } else {
                str_count--;
                max_length++;
            }
            filed.value = filed.value.substring(0,k);
            break;
        }
    }
    document.getElementById('etc_length').innerHTML = "<b><font color=red>"+(max_length/2)+"</b></font>";
}
