//ũ Ŀ ش
function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring;



//ѿ ̹
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/*
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}*/

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}






//â 
var win = null;
function NewWin(url,winname,w,h,scroll){
winToTop = (screen.height) ? (screen.height-h)/2 : 0;
winToLeft = (screen.width) ? (screen.width-w)/2 : 0;

making =
'height='+h+',width='+w+',top='+winToTop+',left='+winToLeft+',scrollbars='+scroll+',toolbar=no,resizable=no'
win = window.open(url,winname,making)
}

/***********************************************************************************************************************************/

// ̹ ѿ 
function img_rollover(size, idNum, id, imgSrc)
{
	for(i = 1; i <= size; i++)
	{
		if(i == idNum && document.getElementById(id + i) != undefined)
		{
			document.getElementById(id + i).src = "../image/" + imgSrc + i + "r.gif";
		}
		else
		{
			if(document.getElementById(id + i) != undefined)
			{
				document.getElementById(id + i).src = "../image/" + imgSrc + i + ".gif";				
			}			
		}
	}
}

function magazineDiv2(size, idNum) 
{
	for (i = 1; i < size; i++) 
	{
		if(document.getElementById("magazineDiv2_" + i ) != undefined)
		{
			var xx = 'document.getElementById("magazineDiv2_' + i + '").style.display = "none"';
			eval(xx);
		}		
	}
	if(document.getElementById("magazineDiv2_" + idNum ) != undefined)
	{
		xx = 'document.getElementById("magazineDiv2_' + idNum + '").style.display = "block"';	
		eval(xx);
	}	
}

/** 
* 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;
}


String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function isHangul(value)
{     
    var pattern = new RegExp('[^-R]', 'i'); 
    if(pattern.exec(value) != null) 
	{       
        return false; 
    }
	else 
	{ 
        return true; 
    } 
}

String.prototype.replaceAll = replaceAll;
function replaceAll(str1, str2)
{
	var strTemp = this;	
	while(1)
	{
		if(strTemp.indexOf(str1) != -1)
		{
			strTemp = strTemp.replace(str1, str2);
		}
		else
		{
			break;
		}
	}
	return strTemp;
}

function getFileIcon(file)
{
	var file;	
	var ext = file.substr(file.lastIndexOf(".") + 1);	
	var icon = "";
	var icon_dis = "";
	switch(ext.toLowerCase())
	{
		case "gif" :
			icon = "gif.gif"; icon_dis = "GIF ̹"; break;
		case "zip" :
		case "rar" :
		case "arj" :
			icon = "zip.gif"; icon_dis = ""; break;
		case "xls" :
			icon = "xls.gif"; icon_dis = ""; break;
		case "jpg" :
		case "jpeg" :
			icon = "jpg.gif"; icon_dis = "JPG ̹"; break;
		case "hwp" :
			icon = "hwp.gif"; icon_dis = "ѱ۹"; break;
		case "bmp" :
			icon = "bmp.gif"; icon_dis = "BMP ̹"; break;
		case "ppt" :
			icon = "ppt.gif"; icon_dis = "ĿƮ"; break;
		case "pdf" :
			icon = "pdf.gif"; icon_dis = "ũιPDF"; break;
		case "css" :
			icon = "css.gif"; icon_dis = "CSS "; break;
		case "doc" :
			icon = "doc.gif"; icon_dis = "幮"; break;
		case "exe" :
			icon = "exe.gif"; icon_dis = ""; break;
		case "htm" :
		case "html" :
			icon = "htm.gif"; icon_dis = "HTML"; break;
		case "js" :
			icon = "js.gif"; icon_dis = "JS "; break;
		case "dll" :
			icon = "dll.gif"; icon_dis = "DLL "; break;
		case "ini" :
			icon = "ini.gif"; icon_dis = "ȯ漳 "; break;
		case "asf" :
		case "wma" :
		case "wmv" :
			icon = "asf.gif"; icon_dis = "̵"; break;
		case "wav" :
			icon = "wav.gif"; icon_dis = "̺"; break;
		case "mp3" :
			icon = "mp3.gif"; icon_dis = "MP3"; break;
		case "avi" : 
			icon = "avi.gif"; icon_dis = "AVI"; break;
		case "mpg" : 
		case "mpeg" : 
			icon = "mpg.gif"; icon_dis = "MPEG"; break;
		case "ra" :
		case "ram" :
			icon = "ra.gif"; icon_dis = ""; break;
		case "txt" :
			icon = "txt.gif"; icon_dis = "ؽƮ"; break;
		case "" :
			icon = "blank.gif"; icon_dis = "Ͼ"; break;
		default :
			icon = "unknown.gif"; icon_dis = "";
	}
	arr_info = new Array();
	arr_info[0] = "/module/webhard/img/icon_type/" + icon;	
	arr_info[1] = icon_dis;
	
	return arr_info;
}


function getFormatFileSize(size)
{
	var size;
	var size_string = "";

	if(size > 512)
	{
		if(size/1024 > 512)
		{
			size_string = getFloatNumber((size / 1024) / 1024) + " MB";
		}
		else
		{
			size_string = getFloatNumber(size / 1024) + " kB";			
		}
	}
	else
	{
		size_string = size + " B";
	}

	return size_string;
}

function getFloatNumber(num)
{
	var str_num = num + "";
	if(str_num.indexOf(".") > 0)
	{
		return str_num.substr(0, str_num.indexOf(".") + 3);
	}
	else
	{
		return str_num;
	}
}

function isHangul(value)
{     
    var pattern = new RegExp('[^-R]', 'i'); 
    if(pattern.exec(value) != null) 
	{       
        return false; 
    }
	else 
	{ 
        return true; 
    } 
}

function __make_object__(obj_id)
{
	document.write(obj_id.text);
	obj_id.id = '';
}

/* 
* ȭ  ó (-00,000,000.00000) (, Ҽ) 
*/ 
function number_format(numstr, ret) 
{ 
	if(event.keyCode == 9 || event.keyCode == 13)
	{

	}
	else
	{
		ret.value = SetComma(DelComma(numstr));
	}
}

// ڿ ޸ ´. 
function SetComma(numstr) 
{ 
    numstr = String(numstr); 
    var re0 = /^(-?\d+)(\d{3})($|\..*$)/; 
    if (re0.test(numstr)) 
        return numstr.replace(re0, 
            function(str,p1,p2,p3) { 
                return SetComma(p1) + ',' + p2 + p3; 
            } 
        ); 
    else 
        return numstr; 
}

String.prototype.SetComma = function () 
{ 
    return SetComma(this); 
} 

// ڸ ڷ Ѵ. 
function DelComma(numstr) 
{ 
    numstr = String(numstr); 
    if (numstr == '') return '0'; 
    else if (numstr == '-') return '0'; 
    else if (numstr == '0-') return '-0'; 
    numstr = numstr.replace(/[^\d\.-]/g,''); 
    numstr = String(numstr.match(/^-?\d*\.?\d*/)); 
    numstr = numstr.replace(/^(-?)(\d*)(.*)/, 
        function(str,p1,p2,p3) { 
            p2 = (p2>0) ? String(p2.match(/[1-9]\d*$/)) : '0'; 
        //    p2 = (p2>0) ? String(parseInt(p2,10)) : '0'; 
            return p1 + p2 + p3; 
        } 
    ); 
    return numstr; 
} 
String.prototype.DelComma = function () 
{ 
    return DelComma(this); 
} 

// Ҽ ڸ Ѵ.() 
function cutFloat(numstr, length) 
{ 
    numstr = String(numstr); 
    eval('var re0 = /.*\\.\\d{'+ length +'}/;'); 
    if (re0.test(numstr)) 
        numstr = String(numstr.match(re0)); 
    return numstr; 
} 
String.prototype.cutFloat = function (length) 
{ 
    return cutFloat(this,length); 
} 

function addDate(i)
{
	 var currentDate; 
	currentDate = this.getDate() + (i*1);
	this.setDate(currentDate);
} 

function addMonth(i)
{
	var currentDate;
	currentDate = this.getMonth() + (i*1);
	this.setMonth(currentDate);
}
Date.prototype.addDate = addDate; // Date ü ޼ 
Date.prototype.addMonth = addMonth;

function stripFormMoneyComma(form)
{
	var form;
	var length = form.elements.length;
	for(i=0; i<length; i++)
	{		
		if(form.elements[i].className == "number_format")
		{
			form.elements[i].value = form.elements[i].value.DelComma();
		}
	}
}

function checkFormDate(obj)
{
	var obj;
	obj.value = obj.value.trim();
	var v = obj.value;
	if(v != "")
	{
		var delim = "-";
		if(v.indexOf(".") >= 0)
		{
			delim = ".";
		}
		else if(v.indexOf("-") >= 0)
		{
			delim = "-";
		}
		else if(v.indexOf("/") >= 0)
		{
			delim = "/";
		}
		else
		{

			if(isNaN(v) || v.length > 8)
			{
				
				obj.value = "";				
			}
			else
			{
				if(v.length <= 2)
				{
					var d = new Date();
					var year = d.getYear();
					var month = d.getMonth() + 1 + "";
					if(month.length == 1)
					{
						month = "0" + month;
					}
					var day = v;
					if(day.length == 1)
					{
						day = "0" + day;
					}

					obj.value = year + "-" + month + "-" + day;

				}
				else if(v.length == 4)
				{
					var d = new Date();
					var year = d.getYear();
					var month = v.substring(0, 2);
					var day = v.substring(2);

					obj.value = year + "-" + month + "-" + day;
				}
				else if(v.length == 8)
				{
					var year = v.substring(0, 4);
					var month = v.substring(4, 6);
					var day = v.substring(6);

					obj.value = year + "-" + month + "-" + day;
				}
				else
				{
					obj.value = "";
				}				
			}

			return;
		}

		var arr_v = v.split(delim);
		var arr_v_len = arr_v.length;
		if(arr_v_len == 2)
		{
			arr_v[0] = arr_v[0].trim();
			arr_v[1] = arr_v[1].trim();
			var d = new Date();
			var year = d.getYear();
			if(arr_v[0].length == 0 || arr_v[0].length > 2 || arr_v[1] == 0 || arr_v[1].length > 2 || isNaN(arr_v[0]) || isNaN(arr_v[1]))
			{
				obj.value = "";
			}
			else
			{				
				var month = arr_v[0];
				var day = arr_v[1];				

				if(month.length == 1)
				{
					month = "0" + month;
				}

				if(day.length == 1)
				{
					day = "0" + day;
				}
				
				obj.value = year + "-" + month + "-" + day;
			}

		}
		else if(arr_v_len == 3)
		{
			arr_v[0] = arr_v[0].trim();
			arr_v[1] = arr_v[1].trim();
			arr_v[2] = arr_v[2].trim();
			if(arr_v[0].length == 0 || arr_v[0].length > 4 || arr_v[1] == 0 || arr_v[1].length > 2 || arr_v[2] == 0 || arr_v[2].length > 2 || isNaN(arr_v[0]) || isNaN(arr_v[1]) || isNaN(arr_v[2]))
			{
				obj.value = "";
			}
			else
			{
				var year = arr_v[0];
				var month = arr_v[1];
				var day = arr_v[2];
				if(year.length == 1)
				{
					year = "200" + year;
				}
				else if(year.length == 2)
				{
					year = "20" + year;
				}
				else if(year.length == 3)
				{
					year = "2" + year;
				}

				if(month.length == 1)
				{
					month = "0" + month;
				}

				if(day.length == 1)
				{
					day = "0" + day;
				}

				obj.value = year + "-" + month + "-" + day;
			}
		}
		else
		{
			obj.value = "";
		}

	}
}

function getKorReCode(evn)
{ 
    var evn=String.fromCharCode(evn).toUpperCase().charCodeAt(0);
	var re = /[-]/;
    switch(evn)
	{ 
        case 82:re=/[-]/;break; // 
        case 83:re=/[-]/;break; // 
        case 69:re=/[-]/;break; // 
        case 70:re=/[-]/;break; // 
        case 65:re=/[-J]/;break; // 
        case 81:re=/[-]/;break; // 
        case 84:re=/[-]/;break; // 
        case 68:re=/[-]/;break; // 
        case 87:re=/[-]/;break; // 
        case 67:re=/[-]/;break; // 
        case 90:re=/[ī-i]/;break; // 
        case 88:re=/[Ÿ-M]/;break; // 
        case 86:re=/[-]/;break; // 
        case 71:re=/[-R]/;break; // 
    } 
    return re; 
} 

function selectOptionText(obj, evn)
{ 
    var tmpdata=new Array(); 
    var cnt=-1; 
    var cnt2=-1; 

    for(i=0;i<=obj.length-1;i++){ 
        if(getKorReCode(evn).test(obj.options[i].text.substr(0,1))) {cnt++;tmpdata[cnt]=i;} 
    } 
    for(i=0;i<=tmpdata.length-1;i++){ 
        if(obj.selectedIndex==tmpdata[i]){cnt2=i} 
    } 
    tmpdata.length-1<=cnt2 ? cnt2=0:cnt2++; 
    obj.selectedIndex=    tmpdata[cnt2]; 
} 

function checkDigit(text) {
	var numPattern = /([^0-9])/;
	numPattern = text.match(numPattern);
	if (numPattern != null) {
		return false;
	}
	return true;
}


function openEBook(docu, kd, board_gubun, point, id)
{	
	//board_gubun : 1 - ִ  Ȱ, 2 -  Ǵ , 3 - ˰ ִ..., 4 -  
	if(id == '')
	{
		alert("α ̿밡 մϴ.");
		if(confirm("α  ̵Ͻðڽϱ?"))
		{
			location.href="/member/login.jsp";
			return ;
		}		
	}
	else if(board_gubun == 1 && point <= 2 && id != '')
	{
		alert("Ű մϴ.");
		return ;
	}
	else if(board_gubun != 1 && point <= 1 && id != '')
	{
		alert("Ű մϴ.");
		return ;
	}
	else if(screen.width < 800)
	{
		alert("The screen resolution should be over 800*600");
		return ;
	}
	else
	{
		if(kd == "fixed"){ x = 1024; y = 768; wname = "fixed_ecatalog"; }
		else if(screen.width > 1600 || screen.height > 1200){ x = 1600; y = 1200; wname = "ecatalog"; }
		else{ x = screen.width; y = screen.height; wname = "ecatalog"; }

		x = x - 10;
		y = y - 58;

		property = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no,copyhistory=no,";
		//property += "width=" + x + ",height=" + y + ",left=" + 0 + ",top=" + 0;
		property += "width=" + screen.availwidth + ",height=" + screen.availHeight + ",left=" + 0 + ",top=" + 0;

		//ecawin = window.open(docu, wname, property);

		ecawin = window.open('/recipe/openEBook_cookie_process.jsp?docu=' + docu+ '&kd=' + kd + '&board_gubun=' + board_gubun + '&point=' + point + '&id=' + id + '', wname, property);
	}
}

function openEBook2(docu, kd)
{	
	//board_gubun : 1 - ִ  Ȱ, 2 -  Ǵ , 3 - ˰ ִ..., 4 -  
	if(board_gubun == 1 && point <= 2)
	{
		alert("Ű մϴ.");
		return;
	}
	if(board_gubun != 1 && point <= 1)
	{
		alert("Ű մϴ.");
		return;
	}
	if(screen.width < 800)
	{
		alert("The screen resolution should be over 800*600");
		return;
	}

	if(kd == "fixed"){ x = 1024; y = 768; wname = "fixed_ecatalog"; }
	else if(screen.width > 1600 || screen.height > 1200){ x = 1600; y = 1200; wname = "ecatalog"; }
	else{ x = screen.width; y = screen.height; wname = "ecatalog"; }

	x = x - 10;
	y = y - 58;

	property = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,copyhistory=no,";
	property += "width=" + x + ",height=" + y + ",left=" + 0 + ",top=" + 0;

	ecawin = window.open(docu, wname, property);

	//ecawin = window.open('/recipe/openEBook_cookie_process.jsp?docu=' + docu+ '&kd=' + kd + '&board_gubun=' + board_gubun + '&point=' + point + '', wname, property);
}





/* ÷ ˾ ҽ */


function popupWindow(url, w, h) {
  var posX = (screen.width - w) / 2;
  var posY = (screen.height - h) / 2;
  var option = ",resizable=no,scrollbars=yes,status=no";
  window.open(url, "new_win","width="+w+",height="+h+",left="+posX +",top="+posY+option);
}









//============================================================================ 
// ̹ ڵ  
//============================================================================ 
//
//image_auto_resize_inarea(document.getElementById('div_area'),100,'',true); 
//document.getElementById('div_area') ȿ  img ڵ  մϴ. 
function image_auto_resize(this_s,width,height)
{ 
	var ta_image = new Image(); 
	ta_image.src = this_s.src; 
	if(!width)
	{
		this_s.removeAttribute('width'); 
		this_s.style.width='auto';
	} 
	else if(width < ta_image.width)
	{ 
		this_s.width = width; 
	}
	else
	{ 
		this_s.width = ta_image.width; 
	} 
	if(!height)
	{
		this_s.removeAttribute('height'); 
		this_s.style.height='auto';
	} 
	else if(height < ta_image.height)
	{ 
		this_s.height = height; 
	}
	else
	{ 
		this_s.height = ta_image.height; 
	} 
} 

function image_auto_resize_inarea(this_s,width,height,view)
{ 	
	//this_s  ̹ ڵ  ȴ. 
	//alert(this_s.childNodes.length); 
	if(!view)
	{
		view=true;
	} 
	if(!this_s)
	{
		return;
	} 
	if(this_s.nodeType!=1)
	{
		return;
	} 
	for(var i=0,m=this_s.childNodes.length;i<m;i++)
	{ 
		var ta = this_s.childNodes[i]; 

		if(ta.nodeName=='IMG')
		{ 
			//ta.style.border='1px solid #333333';  
			image_auto_resize(ta,width,height); 

			if(view)
			{ 
				if(!ta.title)
				{
					ta.title=ta.src;
				} 
				if(!ta.onclick)
				{ 
					ta.style.cursor='pointer'; 
					ta.onclick=function(){js_image_view(this,1);} 
				} 
				if(!ta.onload)
				{
					ta.onload=function()
					{
						image_auto_resize(this,width,height);
					} 
				}				
				if(!ta.onmouseover) 
				{
					ta.onmouseover=function()
					{
						image_auto_resize(this,width,height);
					}
				}					 
			} 
		} 
		if(ta.childNodes.length>0)
		{ 
			image_auto_resize_inarea(ta,width,height); 
		} 
	} 
	return; 
}

function js_image_view(obj, num)
{
	return false;
}
function addCaption (oImgElem) 
{
	return false;
}