Array.prototype.in_array = function(val){
	for(var i=0;i<this.length;i++){
		if(this[i] == val){
			return true;
		}
	}
	return false;
}


Array.prototype.unique = function(){
	var aa = {};
	for(var i=0; i<this["length"]; i++){
		if(typeof aa[this[i]] == "undefined") aa[this[i]] = 3;
	}
	this["length"] = 0;
	for(var i in aa) this[this["length"]] = i;

	return this;
}


Array.prototype.getIndex = function (val){
	for(var i=0;i<this.length;i++){
		if(this[i] == val){
			return i;
		}
	}
	return false;
}


function getParameterByName(name) {
	name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
	var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
		results = regex.exec(location.search);
	return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}


function validateEmail(email) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return re.test(email);
}



function number_format(num) {
	num = parseFloat(num);
	if(isNaN(num)) return '0';

	var decimals = 0;
	var dec_point = '.';
	var thousands_sep = ',';
	decimals = Math.pow(10, decimals);

	num = num * decimals;
	num = Math.round(num);
	num = num / decimals;

	num = String(num);
	var reg = /(^[+-]?\d+)(\d{3})/;
	var tmp = num.split('.');
	var n = tmp[0];
	var d = tmp[1] ? dec_point + tmp[1] : '';

	while(reg.test(n)) n = n.replace(reg, "$1"+thousands_sep+"$2");

	return n + d;
}


// 사업자번호 체크
function isBusinessSSN(num1,num2,num3) {
	var sCheck = "137137135";
	var temp = 0;
	var swap = "";
	var sBin = "";
	var swap1 = "";

	if(num1.length != 3)	return false;
	if(num2.length != 2)	return false;
	if(num3.length != 5)	return false;

	sBin = num1 + num2 + num3;
	for(var i=0; i < 8; i++) {
		temp = temp + parseFloat((sBin.charAt(i) * sCheck.charAt(i)) % 10);
	}
	swap = sBin.charAt(8)*sCheck.charAt(8);
	swap1 = ''+swap;

	if (swap1 != '0')	{
		if (swap1.length > 1){
			temp = temp + parseFloat(swap1.charAt(0))+parseFloat(swap1.charAt(1));
		}	else	{
			temp = temp + parseFloat(swap1.charAt(0));
		}
	}
	temp = temp + parseFloat(sBin.charAt(9));
	if ((parseFloat(temp)%10) == 0){
		return true;
	}else{
		return false;
	}
}

//###	Obj의 값이 ID로 적합(영문시작 영문+숫자)? ###//
function isOID(str,slen,elen) {
	if(str.length == 0)		return false;
	if (str.length < slen || str.length > elen) return false;

	for(var i=1; i < str.length; i++)
		if(!(('a' <= str.charAt(i) && str.charAt(i) <= 'z') || ('0' <= str.charAt(i) && str.charAt(i) <= '9') || (str.charAt(i) == '_')))
			return false;
	return true;
}


function setCookie( name, value, expiredays ){
	var endDate = new Date();
	endDate.setDate( endDate.getDate()+ expiredays );
	endDate.setHours(0);
	endDate.setMinutes(0);
	endDate.setSeconds(0);
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + endDate.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 "";
}

function jsFamilySiteGo(){
	if ($("#id_familySite").val() != ""){
		window.open($("#id_familySite").val(), "");
	}
}


// 한글 마지막 글자가 받침을 가지는지 여부 (받침이 있으면 true, 없으면 false)
function checkBatchimEnding(word) {
	if (typeof word !== 'string') return null;

	var lastLetter = word[word.length - 1];
	var uni = lastLetter.charCodeAt(0);

	if (uni < 44032 || uni > 55203) return null;

	return (uni - 44032) % 28 != 0;
}




function getRandomChar(nLength){
	var arr = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(",");
	var rndStr = '';

	for (var idx=0;idx<nLength ;idx++ ){
		rndStr+= arr[Math.floor(Math.random()*arr.length)];
	}

	return rndStr;
}



function Page_Navigator(list_cgi,aPN,articles_page,page,Total,pg_size){
	var articles_page	= parseInt(articles_page);
	var page			= parseInt(page);
	var Total			= parseInt(Total);
	var pg_size			= parseInt(pg_size);
	var pt_page = '';
	var now_page = 0;
	var end_rec = 0;
	var last_page = 0;
	var dis_page = 0;

	var arrPN = new Array();
	for(var idx=0;idx<aPN.length;idx++){
		arrPN.push("'" + aPN[idx] + "'");
	}

	strParm = arrPN.join(',');
	

	var total_page = parseInt((Total-1)/articles_page);

	if (page < 1){	now_page = 0;}
	else{			now_page = page;}

	var start_rec = now_page*articles_page;

	if ((start_rec+articles_page)>Total){	end_rec = Total;}
	else{									end_rec = start_rec+articles_page;}

	var first_page = parseInt(now_page/pg_size)*pg_size;

	if ((first_page+(pg_size-1)) > total_page){	last_page = total_page;}
	else{								last_page = first_page+(pg_size-1);}

	if (first_page == 0){
		pt_page += '';
	}else{
		var prev_page = first_page-1;
		pt_page += "<A href='javascript:;' onClick=\"javascript:"+list_cgi+"(" + strParm + ", '"+prev_page+"');return false;\"><div class='pg_def'>&lt;</div></A>";
	}

	for (idx=first_page;idx<=last_page ;idx++){
		dis_page = idx+1;
		if (idx==now_page){
			pt_page += "<div class='pg_def pg_on'>"+dis_page+"</div>";
		}else{
			pt_page += "<A href='javascript:;' onClick=\"javascript:"+list_cgi+"(" + strParm + ", '"+idx+"');return false;\"><div class='pg_def'>"+dis_page+"</div></A>";
		}
	}

	if (last_page != total_page){
		var next_page = first_page+pg_size;
		pt_page += "<A href='javascript:;' onClick=\"javascript:"+list_cgi+"(" + strParm + ",'"+next_page+"');return false;\"><div class='pg_def'>&gt;</div></A>";
	}else{
		pt_page += '';
	}

	return pt_page;
}


// Air
function viewAir(kind,enc){
	var winAir = window.open('/common/airChk.htm?sKind='+kind+'&sEnc='+enc,'winAir','width=680,height=800,scrollbars=yes');
	winAir.focus();
}




// NBP
function prtNBPResultContent(objData){
	try{
		if (objData.ads.length < 1) return;
	}catch(e){return;}

	var stmt = "<TABLE width='100%' border='0' cellpadding='0' cellspacing='0'>";
	stmt += "<TR><TD width='50%'><SPAN style='font-size:14px;font-weight:bold;color:#000'>파워링크 <IMG src='/images/search/ico_ad2.gif' border='0' align='absmiddle'></SPAN></TD>";
	stmt += "<TD width='50%' align='right'><A href='http://saedu.naver.com/adbiz/searchad/intro.nhn' target='_blank'><SPAN style='color:#777'><u>신청하기</u> > </SPAN></A></TD></TR>"
	stmt += "</TABLE>";

	stmt += "<DIV style='padding-left:10px;'>";
	$.each(objData["ads"],function (idx,aRow){
		//var sTitle = aRow["title"].replace(/<?=$_GET["sKeyword"]?>/gi,"<strong><?=$_GET['sKeyword']?></strong>");
		var sTitle = aRow["title"];
		var sDesc = aRow["desc"].replace(/<?=$_GET["sKeyword"]?>/gi,"<span style='font-weight:bold;'><?=$_GET['sKeyword']?></span>");
		stmt += "<DIV class='nbp_base'>";
		stmt += "<DIV class='nbp_item'>";
		stmt += "<SPAN class='nbp_title'><A href='"+aRow["cUrl"]+"' style='color:#00c;font-weight:bold;text-decoration:none;font-family:굴림,gulim' target='_blank' class='cExtList'>"+sTitle+"</A></SPAN>";
		stmt += "<SPAN class='nbp_url'><A href='"+aRow["cUrl"]+"' target='_blank' class='cExtList'>"+aRow["vUrl"]+"</A></SPAN>";
		stmt += "</DIV>";
		stmt += "<DIV class='nbp_desc'>"+sDesc+"</DIV>";
		stmt += "</DIV>";
	});
	stmt += "</DIV>";

	$("#DIV_NBP_AD").html(stmt);
	$("#DIV_NBP_AD").show();
}



// NBP
function prtNBPResultContentV2(objData){
	try{
		if (objData.ads.length < 1) return;
	}catch(e){return;}

	var bView = true;
	var sExp = new RegExp(/꼬망세/g);

	var stmt = "<TABLE width='100%' border='0' cellpadding='0' cellspacing='0'>";
	stmt += "<TR><TD width='50%'><SPAN style='font-size:14px;font-weight:bold;color:#000'>파워링크 <IMG src='/images/search/ico_ad2.gif' border='0' align='absmiddle'></SPAN></TD>";
	stmt += "<TD width='50%' align='right'><A href='http://saedu.naver.com/adbiz/searchad/intro.nhn' target='_blank'><SPAN style='color:#777'><u>신청하기</u> > </SPAN></A></TD></TR>"
	stmt += "</TABLE>";

	stmt += "<DIV style='padding-left:10px;'>";
	$.each(objData["ads"],function (idx,aRow){
		var sTitle = aRow["headline"];
		var sDesc = aRow["description"];

		var nExpCnt = sTitle.search(sExp);
		if (nExpCnt >= 0){
			bView = false;
		};

		stmt += "<DIV class='nbp_base'>";
		stmt += "<DIV class='nbp_item'>";
		stmt += "<SPAN class='nbp_title'><A href='"+aRow["clickUrl"]+"' style='color:#00c;text-decoration:none;font-family:굴림,gulim' target='_blank' class='cExtList'>"+sTitle+"</A></SPAN>";
		stmt += "<SPAN class='nbp_url'><A href='"+aRow["clickUrl"]+"' target='_blank' class='cExtList'>"+aRow["displayUrl"]+"</A></SPAN>";
		stmt += "</DIV>";
		stmt += "<A href='"+aRow["clickUrl"]+"' target='_blank'><DIV class='nbp_desc'>"+sDesc+"</DIV></A>";
		stmt += "</DIV>";
	});
	stmt += "</DIV>";

	if (bView){
		$("#DIV_NBP_AD").html(stmt);
		$("#DIV_NBP_AD").show();
	}

	
}

function popupOpen(name, url, width, height) {

	if (width === "") { width = 0; }
	if (height === "") { height = 0; }

	var resize_width = (screen.availWidth - width)/2;
	var resize_height = (screen.availHeight - height)/2 - 40;
	var popup_open = window.open(url,name,"top="+resize_height+",left="+resize_width+",width="+width+",height="+height+",toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0");
	if (popup_open) {
		popup_open.focus();
	}
}

function numberFormat(value) {

	return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

function viewPopResearch(nIdx){
	var winPoll = window.open("/common/popResearch.htm?nIdx="+nIdx,"winPoll","width=300,height=400");
	winPoll.focus();
}

function popMegaMD(){
	var winMegaMD = window.open('/popup/pop_megamd.htm','winMegaMD','width=500,height=600,scrollbars=no');
	winMegaMD.focus();
}



function rgb2hex(rgb){
	if (rgb.search("rgb") == -1) {
		return rgb;
	} else {
		rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/);
		function hex(x) {
			return ("0" + parseInt(x).toString(16)).slice(-2);
		}
		return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); 
	}
}


function fnPopup(name, url, width, height) {
	if (width === "") { width = 0; }
	if (height === "") { height = 0; }

	var resize_width = (screen.availWidth - width)/2;
	var resize_height = (screen.availHeight - height)/2 - 40;

	document.domain = "edupre.co.kr";
	var popup_open = window.open(url,name,"top="+resize_height+",left="+resize_width+",width="+width+",height="+height+",toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
	if (popup_open) {
		popup_open.focus();
	}
}

function l_click(f){
	$.ajax({ 'url' : '/_proc/procEtc.htm', 'data' : { commitType : 'l_click', f : f}, 'type' : 'post' });
}


