// 한글 체크
function isKorean(str)
{
	var retValue = true;

	if (str == null ) 	return false;
	else {
		for( var i = 0; i < str.length; i++ ) {
			var chr = escape(str.charAt(i));					//입력된 값의 하나하나를 아스키(ASCII) 값으로 변환시킨 후...

			if ( chr.length == 1 ) return false;					//영문의 경우 아스키값이 1자리니까...
			else if ( chr.indexOf("%u")	 != -1 )  continue;
			else if ( chr.indexOf("%") != -1 ) return false;		//"~"와 같은 특수문자의 경우 아스키값이 3자리니까...
		}
	}
	return true;
}

//숫자영문체크
function isNumberAlphabet(str)
{
	var temp1;
	len1 = str.length;
	for(l=0;l<len1;l++){
	     temp1 = str.charAt(l);
	     if (escape(temp1).length >= 4) return false;
             if ( (temp1<'a' || temp1 > 'z') && (temp1 <'A' || temp1 >'Z') && (temp1 <'0' || temp1 >'9') && (temp1 != '_') && (temp1 != '&')) return false;
       }
     return true;
}


//영문체크
function isAlphabet(str)
{
	var temp1;
	len1 = str.length;
	for(l=0;l<len1;l++){
	     temp1 = str.charAt(l);
	     if (escape(temp1).length >= 4) return false;
             if ( (temp1<'a' || temp1 > 'z') && (temp1 <'A' || temp1 >'Z') ) return false;
       }
     return true;
}

//숫자체크
function isNumber(str)
{
	var temp1;
	len1 = str.length;
	for(l=0;l<len1;l++){
	     temp1 = str.charAt(l);
	     if (escape(temp1).length >= 4) return false;
             if (temp1 <'0' || temp1 >'9') return false;

    }
    //if(len1==0) return false;
    return true;
}

//특문체크

function containsChars(str) {
	chars = "!,*&^%$#@~;"
  for (var i = 0; i < str.length; i++) {
     if (chars.indexOf(str.charAt(i)) != -1)
         return true;
  }
  return false;
}


// ####################################################################
//	작업시작일 : 2006년 10월 17일
//	소스설명   : 값입력여부 체크
//	작 성 자   : 임승택
// ####################################################################
function isEmpty(value)
{
	if(value==null || value =="" || chkNull(value)) return true;
	return false;
}

function chkNull(str) { 
    str = str.replace(/\s/g, ''); 
    return (str.length==0); 
} 

/**************************************************************************
* Function Name : checknumber()
'* Description :  숫자여부 체크
'* Parameters :	input box의 개체 (this)
**************************************************************************/
function checknumber(obj){
	var keynum = event.keyCode;
	if(event.shiftKey) return false;
	if((keynum<58 && keynum>47) || (keynum<106 && keynum>95)){
		return true;
	}
	else if(keynum==46 || keynum==8){
		return true;
	}
	else if((keynum<41 && keynum>34) || keynum==9){
		return true;
	}
	else{
		event.returnValue = false;
		return false;
	}
}

// 적합한 메일주소 여부 체크
/*----------------------------------------------------------------------------*/

function EmailCheck(String)
{
   var checkflag = true;
   var retvalue;

   if (window.RegExp) {
      var tempstring = "a";
      var exam = new RegExp(tempstring);
      if (tempstring.match(exam)) {
         var ret1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
         var ret2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
         retvalue = (!ret1.test(String) && ret2.test(String));
      } else {
         checkflag = false;
      }
   } else {
      checkflag = false;
   }

   if (!checkflag) {
      retvalue = ( (String != "") && (String.indexOf("@")) > 0 && (String.index.Of(".") > 0) ); 
   }

   return retvalue;
}

/************************************************************************
/************************************************************************
* Function Name : ResNo_Check
'* Description :   입력한 주민등록번호가 올바른지 검사.
'* Parameters :	ResNo 입력된 주민등록번호
'*************************************************************************/
function ResNo_Check(ResNo){

	var str_serial1=ResNo.substring(0,6)
	var str_serial2=ResNo.substring(6,13)

	if (str_serial1.length != 6){
		//alert("올바른 주민등록번호를 입력해주세요.");
		return false;
	}else if (str_serial2.length != 7){
		//alert("올바른 주민등록번호를 입력해주세요.");
		return false;
	}else if(isNaN(str_serial1) || isNaN(str_serial2)){
		//alert("올바른 주민등록번호를 입력해주세요.");
		return false;
	}else{
		var a1=str_serial1.substring(0,1)
		var a2=str_serial1.substring(1,2)
		var a3=str_serial1.substring(2,3)
		var a4=str_serial1.substring(3,4)
		var a5=str_serial1.substring(4,5)
		var a6=str_serial1.substring(5,6)

		var check_digit=a1*2+a2*3+a3*4+a4*5+a5*6+a6*7

		var b1=str_serial2.substring(0,1)
		var b2=str_serial2.substring(1,2)
		var b3=str_serial2.substring(2,3)
		var b4=str_serial2.substring(3,4)
		var b5=str_serial2.substring(4,5)
		var b6=str_serial2.substring(5,6)
		var b7=str_serial2.substring(6,7)

		var check_digit=check_digit+b1*8+b2*9+b3*2+b4*3+b5*4+b6*5

		check_digit = check_digit%11
		check_digit = 11 - check_digit
		check_digit = check_digit%10

		if (str_serial1.substring(2,3) > 1){
			//alert('잘못된 주민등록번호입니다.\n\n다시 확인하시고 입력해 주세요.');
			return false;
		}else	if (str_serial1.substring(4,5) > 3){
			//alert('잘못된 주민등록번호입니다.\n\n다시 확인하시고 입력해 주세요.');
			return false;
		}else	if (str_serial2.substring(0,1) > 4 || str_serial2.substring(0,1) == 0){
			//alert('잘못된 주민등록번호입니다.\n\n다시 확인하시고 입력해 주세요.');
			return false;
		}else	if (check_digit != b7){
			//alert('잘못된 주민등록번호입니다.\n\n다시 확인하시고 입력해 주세요.');
			return false;
		}else{
			return true;
		}
	}
}

/**************************************************************************
* Function Name : makeCookie()
'* Description :  쿠키생성
'* Parameters :	쿠키명, 생성값
**************************************************************************/
function makeCookie(name, value) {
	document.cookie = name+"="+value+"; path=/;domain=cob.yonsei.ac.kr;"
}

/**************************************************************************
* Function Name : clearCookie()
'* Description :  쿠키삭제
'* Parameters :	쿠키명
**************************************************************************/
function clearCookie(name) {
	document.cookie= name+"=; path=/;domain=cob.yonsei.ac.kr;"
}

/**************************************************************************
* Function Name : getCookie()
'* Description :  쿠키호출
'* Parameters :	쿠키명
**************************************************************************/
function getCookie(name) {
		var Found = false												
		var start, end
		var i = 0
		while(i <= document.cookie.length) {
				 start = i
				 end = start + name.length
				 if(document.cookie.substring(start, end) == name) {
						 Found = true
						 break
				 }
				 i++
		}
		if(Found == true) {
				start = end + 1
				end = document.cookie.indexOf(";", start)
				if(end < start)
						end = document.cookie.length
				return document.cookie.substring(start, end)
		}
		return ""
	}

/**************************************************************************
* Function Name : fontPlus()
'* Description :  폰트 사이트 확대
'* Parameters :	
**************************************************************************/
function fontPlus() {
	var targetObj = document.getElementById("content");
	if(targetObj == null) targetObj = document.getElementById("container-search");
	var nowFontSize = targetObj.style.fontSize;
	var fontSize = getCookie("fontSize");
	
	if ( nowFontSize == 0 || nowFontSize == "") {
		if(fontSize == ""){
		    targetObj.style.fontSize = "10pt";
		}
		else{
			count = fontSize.substring(0,fontSize.lastIndexOf("p"));
			count = parseInt(count);
			count++;
			fontSize = count+"pt";
			targetObj.style.fontSize = fontSize;
		}
	} 
	else {
		var tmpSize = nowFontSize.substring(0, nowFontSize.indexOf("p"));

		if ( parseInt(tmpSize) < 13 ) {
			targetObj.style.fontSize = "" + (parseInt(tmpSize) +1) + "pt";
	
			//쿠키 설정
			clearCookie("fontSize");
			makeCookie("fontSize", ""+(parseInt(tmpSize) +1) + "pt");
		} 
		else {
			alert("더이상 글자크기를 늘일 수 없습니다.");
		}
	}
}

/**************************************************************************
* Function Name : fontMinus()
'* Description :  폰트 사이트 축소
'* Parameters :	
**************************************************************************/
function fontMinus() {
	var targetObj = document.getElementById("content");
	if(targetObj == null) targetObj = document.getElementById("container-search");
	var nowFontSize = targetObj.style.fontSize;
	var fontSize=getCookie("fontSize");
	var count = 0;
	
	if ( nowFontSize == 0 || nowFontSize == "") {
		if(fontSize == ""){
		    targetObj.style.fontSize = "8pt";
		}
		else{
			count = fontSize.substring(0,fontSize.lastIndexOf("p"));
			count = parseInt(count);
			count--;
			fontSize = count+"pt";
			targetObj.style.fontSize = fontSize;
		}
	} 
	else {
		var tmpSize = nowFontSize.substring(0, nowFontSize.indexOf("p"));
	
		if ( parseInt(tmpSize) > 5 ) {
			targetObj.style.fontSize = "" + (parseInt(tmpSize) -1) + "pt";
			clearCookie("fontSize");
			makeCookie("fontSize", ""+(parseInt(tmpSize) -1) + "pt");
		} 
		else {
			alert("더이상 글자크기를 줄일 수 없습니다.");
		}
	}
}

/**************************************************************************
* Function Name : loadAfterFunction()
'* Description :  쿠키에 저장되어 있는 폰트설정값 호출하여 초기값으로 생성
'* Parameters :	
**************************************************************************/
function loadAfterFunction() {
	var nowFongSize = getCookie("fontSize");
	var targetObj = document.getElementById("content");
	
	if(nowFongSize != 0 && nowFongSize != ""){
		targetObj.style.fontSize = nowFongSize;
	}
}

/** 
* string String::cut(int len)
* 글자를 앞에서부터 원하는 바이트만큼 잘라 리턴합니다.
* 한글의 경우 2바이트로 계산하며, 글자 중간에서 잘리지 않습니다.
*/
String.prototype.cut = function(len) {
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++) {
        l += (str.charCodeAt(i) > 128) ? 2 : 1;
        if (l > len) return str.substring(0,i) + "...";
    }
    return str;
}

/**
* bool String::bytes(void)
* 해당스트링의 바이트단위 길이를 리턴합니다. (기존의 length 속성은 2바이트 문자를 한글자로 간주합니다)
*/
String.prototype.bytes = function() {
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
    return l;
}

/**************************************************************************
* Function Name : 
'* Description : best 글 롤링관련 function
'* Parameters :	
**************************************************************************/
var Toggle =1;
function MStop() { Toggle =0; NewsMarQuee.stop(); }
function MStart() { Toggle =1; NewsMarQuee.start(); }
function movr(src,clrOver){ if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver;}}
function mout(src,clrIn) { if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn; }}


/**************************************************************************
* Function Name : recom_prev_model()
'* Description :  이전 정보 갖고오기
'* Parameters :	
**************************************************************************/
function recom_prev_model() {
	var f = document.recomModelForm;
	var recom_prev_count = parseInt(f.recom_prev_count.value);
	var recom_next_count = parseInt(f.recom_next_count.value);

	if (recom_prev_count == 0){
		alert("처음 서적입니다.");
		return;
	} else {
		start = recom_prev_count - 1;
		for(i=0,j=start;i<4;i++,j++) {
			recom_model = document.getElementById('recom_model_'+i);
			recom_model.innerHTML = recom_model_html[j];
		}
		f.recom_prev_count.value = recom_prev_count - 1;
		f.recom_next_count.value = recom_next_count + 1;
	}
	return;
}

/**************************************************************************
* Function Name : recom_next_model()
'* Description :  다음정보 갖고오기
'* Parameters :	
**************************************************************************/
function recom_next_model() {
	var f = document.recomModelForm;
	var recom_prev_count = parseInt(f.recom_prev_count.value);
	var recom_next_count = parseInt(f.recom_next_count.value);

	if (recom_next_count <= 0 ) {
		alert("마지막 서적입니다.");
		return;
	} else {
		start = recom_prev_count + 1;
		for(i=0,j=start;i<4;i++,j++) {
			recom_model = document.getElementById('recom_model_'+i);
			recom_model.innerHTML = recom_model_html[j];
		}
		f.recom_prev_count.value = recom_prev_count + 1;
		f.recom_next_count.value = recom_next_count - 1;
	}
	return;
}

/**************************************************************************
* Function Name : OpenWin()
'* Description :  윈도우 오픈창
'* Parameters :	retValue
**************************************************************************/
function OpenWin(URL,WinName,x,y,Menu,cSize,scroll) {

	var features;

	var nTop = (screen.height - y) / 2 - 30;
	var nLeft = (screen.width - x) / 2;

	if (Menu == 0 )
		features = "toolbar=no,width=" + x + ",height=" + y + ",top=" + nTop + ",left=" + nLeft + ",status=no,menubar=no";
	else
		features = "toolbar=no,width=" + (x + 18) + ",height=" + y + ",top=" + nTop + ",left=" + nLeft + ",status=no,menubar=yes";

	if (cSize == 0)
		features = features + ",resizable=no";
	else
		features = features + ",resizable=yes";

	if (scroll == 0 )
		features = features + ",scrollbars=no";
	else if(scroll == 2)
		features = features + ",scrollbars=yes";
	else
		features = features + ",scrollbars=no";

	//alert(features);

	var TheWindow = window.open(URL, WinName, features);
	if(TheWindow){
		TheWindow.focus();
	}
}

 // 주소복사창
 function copyURL(articleId){ 
  if(copyclipboard(articleId)) {   
    alert('클립보드에 주소가 복사되었습니다.');
  }  
 } 

 function copyclipboard(intext) {
  if (window.clipboardData) {
   window.clipboardData.setData("Text", intext);
    return true;     
  }
  else if (window.netscape) {
   try {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');    
    var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
    if (!clip) return;   
    var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);    
    if (!trans) return;   
    trans.addDataFlavor('text/unicode');
   
    var str = new Object();
    var len = new Object();
   
    var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
   
    var copytext=intext;
   
    str.data=copytext;
   
    trans.setTransferData("text/unicode",str,copytext.length*2);
   
    var clipid=Components.interfaces.nsIClipboard;
   
    if (!clip) return false;
   
    clip.setData(trans,null,clipid.kGlobalClipboard);
    return true;
   } catch(e) {
   }  
  }
  return false;
 }
