/*********************************************/
/*  ÆäÀÌÁö ¼³¸í : ÀÚ¹Ù½ºÅ©¸³Æ® ÇÔ¼ö ¸ðÀ½     */
/*  ÀÛ¼ºÀÚ		: js_lib.js                  */
/*  ÀÛ¼ºÀÏ		: 06.03.06				     */
/*********************************************/

//*------------------ ÀÚµ¿ Æ÷Ä¿½º ÀÌµ¿ ----------------------*
function focusChange(current, next, maxSize)
{
	if(current.value.length > parseInt(maxSize)) {
		next.focus()
	}
}

//*------------------ »õÃ¢ (½ºÅ©·Ñ ¾øÀ½) ----------------------*
function wOpen(URL,wName,wWidth,wHeight) {
	var x 
	var y
	var wFeatures
	x = (screen.width - wWidth) / 2 
	y = (screen.height - wHeight) / 2
	
	wFeatures = 'width='+wWidth+',height='+wHeight+',top='+y+',left='+x+'scrollbar=1,resizeable=no,status=no'
	window.open(URL,wName,wFeatures)
}

//*------------------ ÁÖ¼Ò  ----------------------*
function ZipCode() {
	var x 
	var y
	var wFeatures
	x = (screen.width - wWidth) / 2 
	y = (screen.height - wHeight) / 2
	URL = "../ZipCode_Finder.asp?gubun=member";
	wFeatures = 'width=436,height=354,top='+y+',left='+x+'scrollbar=1,resizeable=no,status=no'
	window.open(URL,"ZipCodeFinder",wFeatures);
}


//*------------------ »õÃ¢ (½ºÅ©·Ñ ÀÖÀ½) ----------------------*
function wOpen_scroll(URL, wName, wWidth, wHeight) {
	var x 
	var y
	var wFeatures
	x = (screen.width - wWidth) / 2 
	y = (screen.height - wHeight) / 2
	
	wFeatures = 'width='+wWidth+',height='+wHeight+',top='+y+',left='+x+',scrollbars=yes,resizeable=yes,status=no'
	window.open(URL,wName,wFeatures)
}

//*----------------- ¹®ÀÚ ±æÀÌ ------------------*
function checkLen(str) {
	var totalLen, cnt, sUserid, arrUserid, lenOfUserid, lenOfChar;

	sUserid = str;
	arrUserid = sUserid.split("")
	totalLen = sUserid.length
	lenOfUserid = 0
	for(cnt=0;cnt<totalLen;cnt++) {
		lenOfChar = escape(arrUserid[cnt])
		if (lenOfChar.length==6) {
			lenOfUserid = lenOfUserid + 2
		} else {
			lenOfUserid = lenOfUserid + 1
		}
	}
	return lenOfUserid
}


//*------------- ÇÑ±ÛÀÌ µé¾î°£ ¹®ÀÚ¿­ ±æÀÌ --------------*
function getLenByte(str)
{
  return(str.length+(escape(str)+"%u").match(/%u/g).length-1);
}

//*------------------ Blank Ã¼Å© ----------------*
function checkBlank(str) {
	for (var n=0; n < str.length; n++)  {
		var thisChar = str.substring(n, n+1);
		if(thisChar == " ") {
			return true;
		}
	}
	return false;	
}

//*----------------	¼ýÀÚ Ã¼Å© --------------------*
function isNum(num_Val) {
	var numStr="0123456789";
	var thisChar;
	var counter = 0;
	for (var n=0; n < num_Val.length; n++)  {
       	thisChar = num_Val.substring(n, n+1);
    	if (numStr.indexOf(thisChar) != -1)
       		counter ++;
    }
    if(counter == num_Val.length) return true;
        else return false;
}

//*-------------- ¼ýÀÚ Ã¼Å©2 --------------------*
//	¼ýÀÚ Ã¼Å©2
function isNum2(num) {
	var num_Val = num.value;
	var numStr="0123456789";
	var thisChar;
	var counter = 0;
	for (var n=0; n < num_Val.length; n++)  {
       thisChar = num_Val.substring(n, n+1);
       if (numStr.indexOf(thisChar) != -1)
                        counter ++;
    }
    if(counter != num_Val.length) {
		alert("¼ýÀÚ¸¦ ÀÔ·ÂÇÏ¼¼¿ä.")
		num.value = ""
	}	
}

//*------ ¼ýÀÚÀÎÁö °Ë»çÇÏ°í ¼ýÀÚ °¹¼ö ¸®ÅÏ(ÁÖ¹Î¹øÈ£Ã¼Å©»ç¿ë) ----------*
function numeric_check(m_num) {
	count = 0;
	for( i = 0 ; i < m_num.length ; i++) {
		buf = m_num.charAt(i);
		if(buf > "9" || buf < "0") return -1;
		else count = count + 1;
	}
	return count;
}

//*--- °ø¹éÀ» Á¦¿ÜÇÑ ¹®ÀÚ¼ö ±¸ÇÏ±â(strFind:Ã£´Â ¹®ÀÚ,strChange:¹Ù²Ü¹®ÀÚ, ¸®ÅÏ°ª ¹®ÀÚ¼ö) ----*
function CheckStr(strOriginal, strFind, strChange){
    var position, strOri_Length;
    position = strOriginal.indexOf(strFind);  
    
    while (position != -1){
      strOriginal = strOriginal.replace(strFind, strChange);
      position    = strOriginal.indexOf(strFind);
    }
  
    strOri_Length = strOriginal.length;
    return strOri_Length;
}

//*------------------ select¹Ú½º option Ãß°¡  ----------------------*
function add_select(obj, add_value, add_text, pos)
{
	var opt = new Option(add_value, add_text);
	obj.options[pos] = opt;
	return ;
}

//*------------------ ums ±ÛÀÚ¼ö Á¦ÇÑ  ----------------------*
function chk_byte(frm, maxByte) {
	
	var aquery = frm.value;
	var tmpStr;
	var temp=0;
	var onechar;
	var tcount = 0;

	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for (k=0;k<temp;k++)
		{
		onechar = tmpStr.charAt(k);
		if (escape(onechar) =='%0D') 
		{ } 
		else if (escape(onechar).length > 4) 
		{ tcount += 2; } 
		else 
		{ tcount++; }
	}
	
	document.form.cbyte.value = tcount;

	if(tcount > maxByte)
	{
		reserve = tcount - maxByte;
		alert(maxByte + "¹ÙÀÌÆ® ÀÌ»ó ÀÔ·ÂÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
		cutText(frm, aquery, maxByte);
		return;
	}

}

//*------------------ ums ±æÀÌ ÀÚ¸£±â ----------------------*
function cutText(frm, aquery, iLength)
{

	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;
	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for(k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);

		if(escape(onechar).length > 4) {
			tcount += 2;
			} 
			else {
			if(escape(onechar)=='%0A') {
			} else {
			tcount++;
			}
		}

		if(tcount>eval(iLength)) {
			tmpStr = tmpStr.substring(0,k);
			break;
		}

	}

	frm.value = tmpStr;

}

//*------------------ ÁÂÃø °ø¹é Á¦°Å ÇÔ¼ö ----------------------*
function Ltrim(strValue){
    while (strValue.length>0){
       if(strValue.charAt(0)==' '){
           strValue=strValue.substring(1,strValue.length);              
	   }
       else
          return strValue;	    
    }
	return strValue;
}


//*------------------ ¿ìÃø °ø¹é Á¦°Å ÇÔ¼ö ----------------------*
function Rtrim(strValue){
    while (strValue.length>0){
       if(strValue.charAt(strValue.length-1)==' '){
           strValue=strValue.substring(0,strValue.length-1);              
	   }
       else
           return strValue;	    
   }
   return strValue;
}


//*------------------ ¾çÂÊ °ø¹é Á¦°Å ÇÔ¼ö ----------------------*
function Trim(strValue){
   strValue = Ltrim(strValue);
   strValue = Rtrim(strValue);
   return strValue;
}

//*------------- text¿¡ °ª ÀÔ·Â ÈÄ ºñ È°¼ºÈ­  ------------------*
function fillTextValue(current, strValue) {
	current.value = strValue;
	current.disabled = true;
}

//*------------- ³¯Â¥ À¯È¿¼º Ã¼Å©  ------------------*
function checkdate(v_year,v_month,v_day ){

	var err=0
	if ( v_year.length != 4) err=1
	if ( v_month.length != 1 &&  v_month.length !=  2 ) err=1
	if ( v_day.length != 1  &&  v_day.length !=  2) err=1


	r_year = eval(v_year) ; 
	r_month = eval(v_month); 
	r_day = eval(v_day)  ; 

	if (r_month<1 || r_month>12) err = 1
	if (r_day<1 || r_day>31) err = 1
	if (r_year<0 ) err = 1


	if (r_month==4 || r_month==6 || r_month==9 || r_month==11){
		if (r_day==31) err=1
	}

	// 2,À±³âÃ¼Å©
	if (r_month==2){
		var g=parseInt(r_year/4)

		if (isNaN(g)) {
			err=1
		}
		if (r_day>29) err=1
		if (r_day==29 && ((r_year/4)!=parseInt(r_year/4))) err=1
	}

	if (err==1){
		return false
	}else{
	    return true;

	}
}

function checkDateValid(tDate) {

	tmpYear = tDate.substring(0,4);
	tmpMonth = tDate.substring(4,6);
	tmpDay = tDate.substring(6,8);

	if (!checkdate(tmpYear,tmpMonth,tmpDay))
	{
		return false;
	}

	return true;

}

function addZero(n) {
	return n.length == 1 ? "0"+n : n ;
}
	


function openCal(obj) {
	x = (screen.width - 200) / 2 
	y = (screen.height - 200) / 2
	
	wFeatures = 'width='+'200'+',height='+'230'+',top='+y+',left='+x+'scrollbar=1,resizeable=no,status=no'
	window.open("/calendar/pop_calendar.asp?obj="+obj,"pop_calendar",wFeatures)
}

function openCalDiv(obj) {
	x = (screen.width - 200) / 2 
	y = (screen.height - 200) / 2
	
	wFeatures = 'width='+'200'+',height='+'230'+',top='+y+',left='+x+'scrollbar=1,resizeable=no,status=no'
	window.open("/calendar/pop_calendar.asp?obj="+obj+"&div=1","pop_calendar",wFeatures)
}


function makeChkStr(obj,cnt) {
	var str="";
	for (i = 0 ; i < cnt ; i++) {
		str += ( document.form.elements[obj][i].checked == true ) ? "1" : "0" ;
	}
	return str;
}

function ChkNull(str,msg){
	if (str.value.split(' ').join('')==""){ 
		alert( msg +" ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		try {str.focus();} catch(e){}
		return 0; 
	}
	return 1;
}


function ChkNull_N(str,msg){
	if (str.value ==""){ 
		alert( msg +" ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		try {str.focus();} catch(e){}
		return 0; 
	}
	return 1;
}
		
function ChkNullRadio(str,msg){
	for ( i = 0 ; i < str.length ;i++ ) {
		if (str[i].checked == true)	return true;
	}
	alert( msg +" ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
	try {str[0].focus();} catch(e){}
	return 0; 
}

function ChkNullCheck(str,msg){
	for ( i = 0 ; i < document.form.elements[str].length ;i++ ) {
		obj = document.form.elements[str][i];
		if (obj.checked == true)	return true;
	}
	alert( msg +" ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
	try {document.form.elements[str][0].focus();} catch(e){}
	return 0; 
}

function onlyNumber() {
	if	(  ((event.keyCode >= 48) && (event.keyCode <= 57)) || ((event.keyCode >= 96) && (event.keyCode <= 105)) || ((event.keyCode >= 37) && (event.keyCode <= 40)) || event.keyCode==8 || event.keyCode==46 || event.keyCode==9 ) {}
	else event.returnValue = false;
}

function goZipcode(zip,addr) {
	wOpen_scroll('/member/zipcode.asp?Zip='+zip+"&Addr="+addr, 'zipSearch', '440', '322');
}

function goZipcodeForm(zip,addr,frm) {
	wOpen_scroll('/member/zipcode.asp?Zip='+zip+"&Addr="+addr+"&frm="+frm, 'zipSearch', '440', '322');
}

function goLabSearch(wcode) {
	wOpen_scroll('/gieop/popup_lab_search.asp?wcode='+wcode, 'popup_lab_search', '440', '322');
}


function goTDSearch(wcode) {
	wOpen_scroll('/gieop/popup_td_search.asp?wcode='+wcode, 'TDSearch', '440', '322');
}


function goTDSearch2(wcode, code, comp_repeat) {
	wOpen_scroll('/gieop/popup_td_search.asp?wcode='+wcode+'&code='+code+'&comp_repeat='+comp_repeat, 'TDSearch', '440', '322');
}


function NumberCheck() { 
    if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false; 
} 



function addComma(obj) { 
    var strValue = "" + obj.value.replace(/,/gi,''); // ÄÞ¸¶ Á¦°Å 
    var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
    while(objRegExp.test(strValue)) { 
        strValue = strValue.replace(objRegExp, '$1,$2'); 
    } 
    obj.value = strValue; 
} 

function jsTrim(str) { 
    return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 

function trimCommaObj(objectname) { 
    var TextBox = document.getElementById(objectname); 
    var num = TextBox.value.replace(/,/gi,''); // ÄÞ¸¶Á¦°Å 
} 

function trimComma(t) { 
    return t.replace(/,/gi,''); // ÄÞ¸¶Á¦°Å 
} 


function openReport(winName,ReportName,ReportParam) {

	var ReportURL = "http://59.18.91.23:9999/REQUBE/bin/RQISAPI.dll?View?doc=TechDoctor/" + ReportName + 
					"&id=techdoctor&pw=techdoctor&runvar="+ReportParam;

	wOpen_scroll(ReportURL,winName,815,830) ;
}

function ViewGieop(Sno) {
    window.open("gieop_view.asp?Sno="+Sno ,"MEMINFO","width=630,state=no,scrollbars=yes");
}

function ViewGaein(Sno) {
    window.open("gaein_view.asp?Sno="+Sno,"MEMINFO","width=630,stat=no,scrollbars=no");
}


function ViewGaeinJiweon(Sno) {
    window.open("/gieop/gieop_jiweonseo.asp?adMode=true&Sno="+Sno,"MEMINFO","width=730,stat=no,scrollbars=yes");
}


function winOpen(loc_url, pop_name, n_top, n_left, n_width, n_height, re_scrollbar, re_size) { 
			
	settings='width=' + n_width + ',height=' + n_height + ',top=' + n_top + ',left=' + n_left + ',scrollbars=' + re_scrollbar + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=' + re_size;

	loc_url = loc_url

	position_win = window.open(loc_url, pop_name, settings);

	if(position_win.focus)	position_win.focus();

}
