

var L = 'length';

//	alias of document.createElment
function CE(x) { return document.createElement(x); }
//	alias of document.createTextNode 
function CTN(x) { return document.createTextNode(x); }
//	alias of document.getElementsByTagName 
function ETN(x) { return document.getElementsByTagName(x);}

function e() {
/*
	Document.write를 , 로 구분한다.
	param : arguments
*/
	var a = arguments;
	for (var i=0, r=[], c=a[L];i<c;i++)
		r.push(a[i]);
	document.write(r.join(' ')+'<br />');
}	// end of e


function eachfor(array, func) {
/*
	배열의 값을 함수로 실행시킨다.
	param1 : array
	param2 : function
*/
	for (var i=0,c=arguments[L];i<c;i++) 
		func(array[i]);
}	// end of eachfor

function infor(o) {
/*
	객체의 카와 값을 확인한다.
	param1 : object
*/
	for (var x in o) e(x, ' : ', o[x]);
}	// end of infor


function in_array(needle, haystack)
{
/*
	php에 in_array함수
*/
	var flag = false;
	for (var x in haystack) {
		if (haystack[x] == needle) {
			flag = true;
			break;
		}
	}
	return flag;                    
}

function print_page(id, total, page, limit)
{
	var el = $(id);

	var limit = limit||30;

	var lines = '';
	var total_page = Math.ceil(total/limit);
	var start = page - ((page-1) % limit);
//	var start = page - (page % limit) + 1;
	var end = start + limit - 1;

	if (end>=total_page) end = total_page;
	var p = page - 1;

	if (p){
		lines += '<a href="javascript:go_page(1)"><img src="/assets/images/bullet/icon_pre01.gif" align="absmiddle"  border="0"></a>';
		lines += '<a href="javascript:go_page('+p+')"><img src="/assets/images/bullet/icon_pre02.gif"  align="absmiddle"  border="0"></a>&nbsp;';
	} else {
		lines += '<img src="/assets/images/bullet/icon_pre01.gif" align="absmiddle">';
		lines += '<img src="/assets/images/bullet/icon_pre02.gif"  align="absmiddle">&nbsp;';
	}
//alert(page+' '+start+' '+end);
	for (var i=start;i<end+1;i++)
	{
		if (i==page) {
			lines += '<a href="javascript:;" class="paging">'+i+'</a>';
		} else {
			lines += '<a href="javascript:go_page('+i+')" class="paging1">'+i+'</a>';
		}
	}

	var n = parseInt(page)+1;

	if (n>total_page) n = total_page;

	if (page<total_page) {
		lines += '&nbsp;<a href="javascript:go_page('+n+')"><img src="/assets/images/bullet/icon_next02.gif" align="absmiddle" border="0"></a>';
		lines += '<a href="javascript:go_page('+total_page+')"><img src="/assets/images/bullet/icon_next01.gif"  align="absmiddle" border="0"></a>';
	} else {
		lines += '&nbsp;<img src="/assets/images/bullet/icon_next02.gif"  align="absmiddle">';
		lines += '<img src="/assets/images/bullet/icon_next01.gif"  align="absmiddle">';
	}

	el.innerHTML = lines;

}	// end of print_page


function all_check(it, name)
{
	var id = document.getElementsByName(name);
	var cnt = id.length;
	if (cnt==null||isNaN(cnt)) return;

	for(var i=0; i<cnt; i++){
//		alert(id[i].disabled);
		document.getElementsByName(name)[i].checked = (it.checked&&id[i].disabled==false) ? true : false; 
	}
}
function create_layer(src, width, height, alpha, e)
{

	if (document.getElementById('popup_layer') != null)	{
	    document.body.removeChild(document.body.lastChild);
	}

	var pixel = 5;
	var title_heigth = 12;
	width += pixel * 1;
	height += pixel * 2 + title_heigth;
	var BW = document.body.clientWidth;
	var BH = document.body.clientHeight;
//	var X = (BW - width) / 2;
//	var Y = (BH - height) / 2;

//alert(e.y);

	var add_height = 0;
	var st = document.body.scrollTop;

	if (st<300)	{
		add_height = st/2;
	} else if (st<400) {
		add_height = st/3;
	} else if (st<600) {
		add_height = st/2;
	} else {
		add_height = st/2;
	}

	var X = (BW - width) / 2;
	var Y = (BH - height) / 2 + (add_height);


/*
	var DIV = CE('DIV');
	DIV.id = 'back_layer';
	DIV.style.posotion = 'absolute';
//	DIV.style.border = ' 1px solid #D1D1D1';
//	DIV.setAttribute('style', 'border: 1px solid #D1D1D1');
	DIV.style.left = 0;
	DIV.style.top = 0;
	DIV.style.width = '100%';
	DIV.style.height = Y;//document.body.scrollHeight;
	DIV.style.backgroundColor = '#fff';
//	DIV.style.filter = 'Alpha(Opacity=100)';
//	DIV.style.opacity = 0.5;
	document.body.appendChild(DIV);
	allowtransparency='true'
*/

	var DIV1 = CE('DIV');
	DIV1.id = 'popup_layer';
	DIV1.style.position = 'absolute';
	DIV1.style.left = X; //+ document.body.scrollLeft;
	DIV1.style.top = Y; //+ document.body.scrollTop;
	DIV1.style.width = width-5;
	DIV1.style.height = height;
//	DIV1.style.backgroundColor = '#fff';
	DIV1.style.allowTransparency=true;
//	DIV1.style.filter = 'Alpha(Opacity=100)';

	document.body.appendChild(DIV1);

	var F = CE('IFRAME');
	F.id = 'F_detail';

	if (1)
	{

	}
	F.scroll = 'no';
	F.style.width = width-5;
//	F.style.height = height;
	F.style.position = 'absolute';
	F.style.left = X; //+ document.body.scrollLeft;
	F.style.top = Y; //+ document.body.scrollTop;
	F.style.height = Y;
		F.style.allowTransparency="true";
//	F.style.filter = 'Alpha(Opacity=10)';
	F.frameBorder = 0;
	F.src = src;
//	DIV1.appendChild(F);
	document.body.appendChild(F);

}




function parent_layer(src, width, height, alpha, e)
{
//    alert(src);
//    window.domain = 'hiworks.co.kr';

var DOC = window.parent.document; 
	if (parent.document.getElementById('popup_layer') != null)	{
	    DOC.body.removeChild(DOC.body.lastChild);
	}


	var pixel = 5;
	var title_heigth = 12;
	width += pixel * 1;
	height += pixel * 2;//+ title_heigth;
	var BW = DOC.body.clientWidth;
	var BH = DOC.body.clientHeight;

	var add_height = 0;
	var st = DOC.body.scrollTop;

//		add_height = st/2;

	var X = (BW - width) / 2;
	var Y = (BH - height) / 2 + (st);

	var DIV1 = parent.document.createElement('DIV');
	DIV1.id = 'popup_layer';
	DIV1.style.position = 'absolute';
	DIV1.style.left = X; //+ document.body.scrollLeft;
	DIV1.style.top = Y; //+ document.body.scrollTop;
	DIV1.style.width = width-5;
	DIV1.style.height = height;
//	DIV1.style.backgroundColor = '#fff';
	DIV1.style.allowTransparency=true;
//	DIV1.style.filter = 'Alpha(Opacity=100)';

//	parent.opener.id_tip.document.body.appendChild(DIV1);

    var t_id = parent.document.id_tip;
//    var t_id = parent.document.body;//FF
//        for(var x in t_id) {document.write(x+'<br>');    }

    DOC.body.appendChild(DIV1); 

	var F = parent.document.createElement('IFRAME');
	F.id = 'F_detail';

	F.scroll = 'no';
	F.style.width = width-5;
//	F.style.height = height;
	F.style.position = 'absolute';
	F.style.left = X; //+ document.body.scrollLeft;
	F.style.top = Y; //+ document.body.scrollTop;
	F.style.height = Y;
		F.style.allowTransparency="true";
//	F.style.filter = 'Alpha(Opacity=10)';
	F.frameBorder = 0;
	F.src = src;
//	DIV1.appendChild(F);

    DOC.body.appendChild(F); 
}


    function resizeToHeight(div, frame, h)
    {
        try  {
            var h = document.body.scrollHeight;
//			alert(h);
            if (div) parent.document.getElementById(div).style.height = h+'px';
            if (frame) parent.document.getElementById(frame).style.height = h+'px';
        } catch (e) {
        alert(e);
        }

    }   // end of resizeToAll

    function layer_init()
    {
        var id = document.getElementById('id_size');
        id.style.top = 0;
        id.style.left = 0;

        if (id.offsetHeight != 0) {
            var pheight = id.offsetHeight;
//			alert(pheight);
            var pwidth = id.offsetWidth;
            resizeToHeight('popup_layer', 'F_detail', pheight);
//            parent.frames['F_detail'].resizeTo(pwidth, pheight);
        }
    }

    function parent_close() 
    {
		if (parent.document.getElementById('popup_layer') != null)	{
			parent.document.body.removeChild(parent.document.getElementById('popup_layer'));
		}

        var id = parent.document.body.getElementsByTagName('DIV');
        parent.document.body.removeChild(parent.document.body.lastChild);
    }

        function chk_print(ordernum)
        {
            var f = document.frm_print;

            var url = '/myservice/popup_service_print/' + ordernum;
            var name = '_print';
            var opt = 'menubar=no,toolbar=no, scrollbars=yes,location=no,directories=no,resizable=no,status=no,width=805, height=740, left=300, top=50';

            var popup = window.open(url, name, opt);
            popup.focus();

            f.target = name;
            f.action = url;
            f.submit();
        }

// {{{ number_format
function number_format( number, decimals, dec_point, thousands_sep ) {
    // Format a number with grouped thousands
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/
    // +       version: 803.115
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://crestidg.com)
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57

    var i, j, kw, kd, km;

    // input sanitation & defaults
    if( isNaN(decimals = Math.abs(decimals)) ){
        decimals = 2;
    }

    if( dec_point == undefined ){
        dec_point = ".";
    }
    if( thousands_sep == undefined ){
        thousands_sep = ",";
    }

    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";

    if( (j = i.length) > 3 ){
        j = j % 3;
    } else{
        j = 0;
    }

    km = (j ? i.substr(0, j) + thousands_sep : "");
    kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
    //kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
    kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");


    return km + kw + kd;
}// }}}


function str_repeat ( input, multiplier ) {
    // Repeat a string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_str_repeat/
    // +       version: 801.3120
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: str_repeat('-=', 10);
    // *     returns 1: '-=-=-=-=-=-=-=-=-=-='

    var buf = '';

    for (i=0; i < multiplier; i++){
        buf += input;
    }

    return buf;
}// }}}


function isValidBizNum(strng, chkflag){
        re = /^[0-9]{3}-[0-9]{2}-[0-9]{5}$/;
        
	re2 = /^[0-9]{3}[0-9]{2}[0-9]{5}$/;

	if(chkflag){
		if (!re2.test(strng)) return false;
	}
	else
		if (!re.test(strng)) return false;

	strng = strng.replace(/-/g, '');

        var sum = 0;
        var getlist =new Array(10);
        var chkvalue =new Array("1","3","7","1","3","7","1","3","5");
        for(var i=0; i<10; i++) { getlist[i] = strng.substring(i, i+1); }
        for(var i=0; i<9; i++) { sum += getlist[i]*chkvalue[i]; }
        sum = sum + parseInt((getlist[8]*5)/10);
        sidliy = sum % 10;
        sidchk = 0;
        if(sidliy != 0) { sidchk = 10 - sidliy; }
        else { sidchk = 0; }
        if(sidchk != getlist[9]) { return false; }
        return true;

}

function checkJoomin(juno1, juno2) {
	// 주민등록번호 앞 부분에서 생년월일을 알아냄
	var year = juno1.substring(0,2)
	var month = juno1.substring(2,4)
	var day = juno1.substring(4,6)
	// 주민등록번호 뒷 부분에서 남녀 성별 정보 찾아냄
	var sex = juno2.substring(0,1)

	// 주민등록번호 앞 부분 체크하기

	if ((year <25 || month<1 || month>12 ||day<1) ) {
	  return false;
	}

	// 주빈등록번호 뒷 부분 체크하기

	if ( (sex != 1 && sex != 2 ) || (juno2.length != 7 ) ) {
	 return false;
	}

	var val = 0;
	for (var i = 0; i <=5 ; i++){ 
	  val = val + ((i%8+2) * parseInt(juno1.substring(i,i+1)))
	}

	for (var i = 6; i <=11 ; i++){ 
	   val = val + ((i%8+2) * parseInt(juno2.substring(i-6,i-5)))
	}

	val = 11 - (val %11)
	val = val % 10

	if (val != juno2.substring(6,7)) {
	   return false;
	}
	return true;
}

function zipcode()
{
	var url = '/join/zipcode';
	var name = '';
	if ('\v'=='v') {
	var opt = 'width=470, height=380,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	} else {
	var opt = 'width=480, height=380,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	}
	window.open(url, name, opt);
}

function select_address(zip1, zip2, addr)
{
	if(self.location.href == 'http://hiworks.incruit.com/join/zipcode'){
		document.domain = "incruit.com";
	}

	opener.document.getElementById('zip1').value = zip1;
	opener.document.getElementById('zip2').value = zip2;
	opener.document.getElementById('address1').value = addr;
	self.close();
}

function fix_size(x)
{
	var size = null;
	if (x>=1024) {
		size = number_format(x / 1024, 1);
		size = size + 'GB';
	} else {
		size = number_format(x, 1);
		size = size + 'MB';
	}
	return size;
}




// {{{ str_replace
function str_replace ( search, replace, subject ) {
    // Replace all occurrences of the search string with the replacement string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_str_replace/
    // +       version: 803.219
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'

    if(!(replace instanceof Array)){
        replace=new Array(replace);
        if(search instanceof Array){//If search    is an array and replace    is a string, then this replacement string is used for every value of search
            while(search.length>replace.length){
                replace[replace.length]=replace[0];
            }
        }
    }

    if(!(search instanceof Array))search=new Array(search);
    while(search.length>replace.length){//If replace    has fewer values than search , then an empty string is used for the rest of replacement values
        replace[replace.length]='';
    }

    if(subject instanceof Array){//If subject is an array, then the search and replace is performed with every entry of subject , and the return value is an array as well.
        for(k in subject){
            subject[k]=str_replace(search,replace,subject[k]);
        }
        return subject;
    }

    for(var k=0; k<search.length; k++){
        var i = subject.indexOf(search[k]);
        while(i>-1){
            subject = subject.replace(search[k], replace[k]);
            i = subject.indexOf(search[k],i);
        }
    }

    return subject;

}// }}}



function view_popup(viewID)
{
	$(viewID).show();

	//가운데 상하 스크롤 반영
	$(viewID).style.left = (document.body.clientWidth - $(viewID).clientWidth) /2;
	$(viewID).style.top = (document.body.clientHeight - $(viewID).clientHeight) /2 + document.body.scrollTop;
	$(viewID).style.filter = "alpha(opacity:100)";

}

String.prototype.URLEncode = function URLEncode( )
{
 var SAFECHARS = "0123456789" +     // Numeric
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
     "abcdefghijklmnopqrstuvwxyz" +
     "-_.!~*'()";     // RFC2396 Mark characters
 var HEX = "0123456789ABCDEF";
 var plaintext = this;
 var encoded = "";
 for (var i = 0; i < plaintext.length; i++ ) {
  var ch = plaintext.charAt(i);
     if (ch == " ") {
      encoded += "+";    // x-www-urlencoded, rather than %20
  } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
  } else {
      var charCode = ch.charCodeAt(0);
   if (charCode > 255) {
       alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
              "(URL encoding only supports 8-bit characters.)\n" +
        "A space (+) will be substituted." );
    encoded += "+";
   } else {
    encoded += "%";
    encoded += HEX.charAt((charCode >> 4) & 0xF);
    encoded += HEX.charAt(charCode & 0xF);
   }
  }
 } // for
 return encoded;
};




String.prototype.URLDecode = function URLDecode(  )
{
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var encoded = this;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
    if (ch == "+") {
        plaintext += " ";
     i++;
    } else if (ch == "%") {
   if (i < (encoded.length-2)
     && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
     && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
    plaintext += unescape( encoded.substr(i,3) );
    i += 3;
   } else {
    alert( 'Bad escape combination near ...' + encoded.substr(i) );
    plaintext += "%[ERROR]";
    i++;
   }
  } else {
     plaintext += ch;
     i++;
  }
 } // while
   return plaintext;
};

function rawurldecode( str ) {   
    // Decodes URL-encodes string     
    //    
    // version: 901.1411   
    // discuss at: http://phpjs.org/functions/rawurldecode   
    // +   original by: Brett Zamir   
    // *     example 1: rawurldecode('Kevin+van+Zonneveld%21');   
    // *     returns 1: 'Kevin+van+Zonneveld!'   
    // *     example 2: rawurldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');   
    // *     returns 2: 'http://kevin.vanzonneveld.net/'   
    // *     example 3: rawurldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');   
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'   
    var histogram = {};   
    var ret = str.toString();    
  
    var replacer = function(search, replace, str) {   
        var tmp_arr = [];   
        tmp_arr = str.split(search);   
        return tmp_arr.join(replace);   
    };   
  
    // The histogram is identical to the one in urlencode.   
    histogram["'"]   = '%27';   
    histogram['(']   = '%28';   
    histogram[')']   = '%29';   
    histogram['*']   = '%2A';   
    histogram['~']   = '%7E';   
    histogram['!']   = '%21';   
  
    for (replace in histogram) {   
        search = histogram[replace]; // Switch order when decoding   
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }   
  
    // End with decodeURIComponent, which most resembles PHP's encoding functions   
    ret = decodeURIComponent(ret);   
  
    return ret;   
}  

String.prototype.number_format=function()
{
	return this.replace(/(\d)(?=(?:\d{3})+(?!\d))/g,'$1,');
}

