function common_swf(objhtml) {
    document.write(objhtml);
}

function common_open_url(url_str , param) {
  if ( window.open(url_str,'',param) == false ) {
    alert('XP ÆË¾÷ Â÷´Ü ±â´ÉÀ» ²ô¼¼¿ä.');
  }
}

function OhMyGod() {
  common_open_url("https://web.humoruniv.com/prog/ohmygod/ohmygod.html", "fullscreen=yes,scrollbars=no");
} 

function basename(path) {
   return path.split('/').reverse()[0];
}

// Æ¯¼ö¹®ÀÚ Ã¼Å©
function spc_check(str){
	var spc = /[~!@#$%^&*()_+|<>?:{}=\;\,\.\[\]\`\-\\\/]/g
	if(spc.test(str)){
		return true;
	}
	return false;
}

function trim(str){
	return $.trim(str);
}
function strpos(str, find){
	var n = str.indexOf(find);
	if(n == -1){
		return false;
	}else{
		return true;
	}
}
function str_replace(find, replace, str){
	var str = str.replaceAll(find, replace)
	return str;
}

function bin2hex(s){
    var v,i, f = 0, a = [];
    s += '';
    f = s.length;

    for (i = 0; i<f; i++) {
        a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
    }

    return a.join('');
}
function common_real_len(s){
	if(s != undefined && s != "") {
		for(b=i=0;c=s.charCodeAt(i++);b+=c>>11?3:c>>7?2:1);
		return b;
	} else {
		return 0;
	}
}



function clip_copy(str){
	var text_area = document.createElement("textarea");
	text_area.value = str;
	document.body.appendChild(text_area);

	text_area.select();
	document.execCommand("Copy");
	text_area.remove();

	window.alert("Å¬¸³º¸µå¿¡ º¹»çµÇ¾ú½À´Ï´Ù.\n" + str);
}


function getBrowser(){ 
	var agent = navigator.userAgent; 
	var result = "unknown"; 
	if (agent == null) { } 
	else if (agent.indexOf("MSIE 6.0") > -1) { result = "ie6"; return result;} 
	else if (agent.indexOf("MSIE 7.0") > -1) { result = "ie7"; return result;} 
	else if (agent.indexOf("MSIE 8.0") > -1) { result = "ie8"; return result;} 
	else if (agent.indexOf("MSIE 9.0") > -1) { result = "ie9"; return result;} 
	else if (agent.indexOf("MSIE 10.0") > -1) { result = "ie10"; return result;} 
	else if (agent.indexOf("Firefox") > -1) { result = "firefox"; return result;}
	else if (agent.indexOf("Opera") > -1) { result = "opera"; return result;} 
	else if (agent.indexOf("Android") > -1) { result = "android"; return result;} 
	else if (agent.indexOf("iPhone") > -1) { result = "iphone"; return result;} 
	else if (agent.indexOf("iPad") > -1) { result = "ipad"; return result;} 
	else if (agent.indexOf("Chrome") > -1) { result = "chrome"; return result;} 
	else if (agent.indexOf("Safari") > -1) { result = "safari"; return result;} 
	return result; 
}  

function is_hu_app(){ 
	var agent = navigator.userAgent; 
	if (agent.indexOf("hu_app_version") > -1) {
		return 1;
	} 
	return 0;
}  


function WhatMyPass() {
	var pw_url = 'https://web.humoruniv.com/user/idpw/idpw_qus.html';
	window.open(pw_url,'ºñ¹Ð¹øÈ£Ã£±â','scrollbars=no,toolbar=no,directories=no,status=no,width=380,height=330,resizable=no,menubar=no,top=10,left=340');
}

function common_real_len(Source)
{
  len = Source.length;

  for (i = 0; i < Source.length; i++)
    if (Source.charCodeAt(i) > 127)
      len++;

  return len;
}


function OnOff_Layers() {
var e = document.getElementById("login_view");
 
 if (e.style.visibility == 'visible') {
  e.style.visibility = 'hidden';
  e.style.display = 'none';
 } else {
  e.style.visibility = 'visible';
  e.style.display = 'block';
 }
}

function OnOff_Layers_bak() {
  if (document.all.login_view.style.visibility == 'hidden') {
	document.all.login_view.style.visibility = 'visible';
  } else {
	document.all.login_view.style.visibility = 'hidden';
  }
}

function OnImageResizing(img) {
  if(img.width > 600) {
    img.width = 600;
  }
}

function profile_popup(id) {
		//window.alert(id);
        //var url = "http://msg.humoruniv.com/profile/profile.html?user_address=" + id;
        //var url = "http://mini.humoruniv.com/index.html?nick=" + id;
        ///aaa = window.open(url,'','left margin=0 top margin=0 width=903,height=662');
        //aaa = window.open(url,'','left margin=0 top margin=0 width=880,height=600');

        //if (aaa == false) alert('XP ÆË¾÷Â÷´ÜÀ» ²¨ÁÖ¼Å¾ß ÇÕ´Ï´Ù.');
}

function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function common_isnumber(str) {
	var numstr = "0123456789";
	var i = 0; 
	
	for (i = 0; i < str.length; i++ ) {
	  if (numstr.indexOf(str.charAt(i)) == -1) return false;
	}
	
	return true;
}

function total_graph_bak( nWidth, nHeight, nData ){
  document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ");
  document.write("codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0' ");
  document.write("width='" + nWidth + "' height='" + nHeight + "'>");
  document.write("<param name='movie' value='/images/engine/pollgraph.swf'>");
  document.write("<param name='quality' value='high'>");
  //document.write("<param name='flashVars' value='Indata=10,100;20,200;30,300;40,400;50,700;60,300;70,900&Userdata=300&'>");
  document.write("<param name='flashVars' value='" + nData + "'>");
  document.write("</object>");
}


function total_graph(f_name,f_value,f_width,f_height,f_align,f_param){
 document.write('<object id="'+f_name+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+f_width+'" height="'+f_height+'">') ;
 document.write('<param name="movie" value="'+f_value+'.swf?'+f_param+'" />') ;
 document.write('<param name="quality" value="high" />') ;
 document.write('<param name="menu" value="false" />') ;
 document.write('<param name="wmode" value="transparent" />') ;
 document.write('<param name="allowScriptAccess" value="always" />');
 document.write('<param name="showLiveConnect" " value="true" />' );
 document.write('<param name="allowFullScreen" value="true" />') ;
 document.write('<PARAM NAME=scale VALUE=noscale> ');
 document.write('<PARAM NAME="SAlign" VALUE="'+f_align+'">') ;
 document.write('<param name="FlashVars" value="'+f_param+'">');
 document.write('<embed src="'+f_value+'.swf?'+f_param+'" quality="high" name="'+f_name+'" SAlign="'+f_align+'" scale=noscale width="'+f_width+'" height="'+f_height+'" allowScriptAccess="always"  allowFullScreen="true" showLiveConnect="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />') ;
 document.write('</object>') ; 
}


  function JSOnInitScript(object) {
    if ( hu_getCookie("hu_on_bar") == "set" ) {
	// setted
    } else {
        hu_setCookie("hu_on_bar", "set", 30);
    }

    if ( hu_getCookie("hu_on_init") == "inited" ) {
        // toolvar check already.
    } else {
        // toolvar
        hu_setCookie("hu_on_init", "inited", 30);
    }
  }

  function hu_on_adrun() {
    if ( hu_getCookie("hu_on_init") == "inited" ) {
        // not view...
    } else {
        hu_on_var.style.display = 'block';
    }
  }

  /**
   * ÄíÅ°°ª ÃßÃâ
   * @param cookieName ÄíÅ°¸í
   */
  function hu_getCookie( cookieName ) {

    var search = cookieName + "=";
    var cookie = document.cookie;

    // ÇöÀç ÄíÅ°°¡ Á¸ÀçÇÒ °æ¿ì
    if( cookie.length > 0 ) {
      // ÇØ´ç ÄíÅ°¸íÀÌ Á¸ÀçÇÏ´ÂÁö °Ë»öÇÑ ÈÄ Á¸ÀçÇÏ¸é À§Ä¡¸¦ ¸®ÅÏ.
      startIndex = cookie.indexOf( cookieName );

      // ¸¸¾à Á¸ÀçÇÑ´Ù¸é
      if( startIndex != -1 ) {
        // °ªÀ» ¾ò¾î³»±â À§ÇØ ½ÃÀÛ ÀÎµ¦½º Á¶Àý
        startIndex += cookieName.length;

        // °ªÀ» ¾ò¾î³»±â À§ÇØ Á¾·á ÀÎµ¦½º ÃßÃâ
        endIndex = cookie.indexOf( ";", startIndex );

        // ¸¸¾à Á¾·á ÀÎµ¦½º¸¦ ¸øÃ£°Ô µÇ¸é ÄíÅ° ÀüÃ¼±æÀÌ·Î ¼³Á¤
        if( endIndex == -1) endIndex = cookie.length;

        // ÄíÅ°°ªÀ» ÃßÃâÇÏ¿© ¸®ÅÏ
        return unescape( cookie.substring( startIndex + 1, endIndex ) );
      } 
    }

    return false;
  }
 
 
  /**
   * ÄíÅ° ¼³Á¤
   * @param cookieName ÄíÅ°¸í
   * @param cookieValue ÄíÅ°°ª
   * @param expireDay ÄíÅ° À¯È¿³¯Â¥
   */
  function hu_setCookie( cookieName, cookieValue, expireDate ) {
    var today = new Date();
    today.setDate( today.getDate() + parseInt( expireDate ) );
    document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + today.toGMTString() + ";";
    //document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; ";
  }
  function hu_setDomainCookie( cookieName, cookieValue, expireDate ) {
    var today = new Date();
    today.setDate( today.getDate() + parseInt( expireDate ) );
    document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + today.toGMTString() + "domain=.humoruniv.com" + ";";
    //document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; ";
  }

  function hu_setCookieSec( cookieName, cookieValue, expireSec ) {
	var now = new Date();
	var time = now.getTime();
	time += expireSec * 1000;
	now.setTime(time);
	
    document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + now.toGMTString() + ";";
  }

  function hu_setCookie2( cookieName, cookieValue ) {
    var today = new Date();
    document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; ";
  }

  function hu_getschkey( cookie_name ){ 
	/*
	var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
	if ( results )    return ( unescape ( results[2] ) );  
	else return null;
	*/

	return hu_getCookie( cookie_name );
  }

  function huon_close() {
	document.getElementById('hu_on_var').style.display = 'none';

	if ( hu_getCookie("hu_on_init") == "inited" ) {
		// pass
	} else {
		document.cookie = "hu_on_init=" + escape( "inited" ) + "; path=/; ";
	}
  }

  function huon_move(nick) {
	if ( hu_getCookie("hu_on_init") == "inited" ) {
		profile_popup(nick);
	} else {
		top.location.href = 'https://web.humoruniv.com/hu_on/index.html?nick=' + nick;
	}
  }

  function hu_sckput() {
	var rndnum = Math.floor(Math.random() * 10); // 0 ~ 9 int
	if ( hu_getschkey("sck" + rndnum) == false ) {
		document.getElementById('search_text').value = '';
	} else {
		document.getElementById('search_text').value = hu_getschkey("sck" + rndnum);
	}
  }

	// banner open
	function exp_banner_open(mode) {
	//	exp_banner_inner(mode);	
		if (document.getElementById(mode).style.display == 'none') {
			document.getElementById(mode).style.display = 'block';
        	}
	}

	// banner close
	function exp_banner_close(mode) {
		if (top.document.getElementById(mode).style.display == 'block') {
			top.document.getElementById(mode).style.display = 'none';
        	}
	}

	function exp_banner_inner(mode){
	alert(mode);
		switch(mode){
			case "b_wide_exp" :
				inner_str = '';  //adÁ¦°Å
				break;
			case "b_branding_exp" :
				inner_str = ''; //adÁ¦°Å
				break;
			case "b_drag_exp" :
				inner_str = ''; //adÁ¦°Å
				break;
		}
		
	alert(inner_str);
		document.getElementById(mode).innerHTML = inner_str;

		document.getElementById(mode).style.display = 'block';
	}

function getLocationHref(){ return document.location.href;} 

var memo_win;
var memo_pop_left = 30;
var memo_pop_top = 5;

function memo_popup(you_hex){

	var regType1 = /^[A-Za-z0-9+]*$/;
	if (!regType1.test(you_hex)) {  // hex test 
		return;
	}
	if(document.domain == "m.humoruniv.com" || document.domain == "vaultm.humoruniv.com"){
		var url = "/memo/memo.html?you_hex=" + you_hex;
		memo_win = window.open(url, "w_" + you_hex,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=520,height=720,resizable=yes,left=0,top=0");
	}else{
		var url = "https://web.humoruniv.com/memo/memo.html?you_hex=" + you_hex;
		if(memo_pop_left < 100){
			memo_pop_left += 10;
			memo_pop_top += 10;
		}
		//memo_win = window.open(url, "w_" + you_hex,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=520,height=720,resizable=yes,left=" + memo_pop_left + ",top=" + memo_pop_top);
		memo_win = window.open(url, "w_" + you_hex,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=520,height=720,resizable=yes");

		//memo_win.focus(); // - omit auto focus at 2012.08.16 
	}
}

var chat_win;
function chat_popup(ch, chat_key){
	var url = "/chat/chat.html?ch="+ ch +"&chat_key=" + chat_key;
	chat_win = window.open(url, "c_" + ch,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=900,height=720,resizable=yes");
}

var pong_win;
function pong_popup(nick_hex){
	var url = "//avatar-file.humoruniv.com/pong/pong_hex.php?nick_hex=" + nick_hex;
	pong_win = window.open(url, "p_" + nick_hex,"scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,status=no,width=330,height=160,resizable=yes");
}


function banner_swf(w,h,u) {
 var flash_tag = "";
 flash_tag = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
 flash_tag +='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ';
 flash_tag +='WIDTH="'+w+'" HEIGHT="'+h+'" >';
 flash_tag +='<param name="movie" value="'+u+'">';
 flash_tag +='<param name="quality" value="high">';
 flash_tag +='<param name="allowScriptAccess" value="never">';
 flash_tag +='<param name="autostart" value="false">';
 flash_tag +='<param name="invokeURLs" value="false">';
 flash_tag +='<param name="allowNetworking" value="internal">';
 flash_tag +='<param name="enableHtmlAccess" value="false">';
 flash_tag +='<param name="AllowHtmlPopupwindow" value="false">';
 flash_tag +='<param name="wmode" value="opaque">';
 flash_tag +='<embed allowScriptAccess="never" autostart="false" invokeURLs="false" allowNetworking="internal" wmode="opaque" enableHtmlAccess="false" AllowHtmlPopupwindow="false"  src="'+u+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" WIDTH="'+w+'" HEIGHT="'+h+'"></embed></object>'
 document.write(flash_tag);
}
function strpos(str, find){
	var n = str.indexOf(find);
	if(n == -1){
		return false;
	}else{
		return true;
	}
}

function ua_check(){
	var ua = navigator.userAgent; 

	if(ua.indexOf("IEMobile") > -1){
		return "iemobile";
	}
	if(ua.indexOf("Windows Phone") > -1){
		return "iemobile";
	}
	if(ua.indexOf("Android") > -1){		
		return "android";
	}
	if(ua.indexOf("iPhone") > -1){		
		return "iphone";
	}
	if(ua.indexOf("iPad") > -1){		
		return "ipad";
	}
	if(ua.indexOf("MSIE") > -1){		
		return "ie";
	}
	if(ua.indexOf("Chrome") > -1){		
		return "chrome";
	}
	if(ua.indexOf("Safari") > -1){		
		return "safari";
	}
	if(ua.indexOf("Firefox") > -1){		
		return "firefox";
	}
	if(ua.indexOf("Windows") > -1 && ua.indexOf("rv:1") > -1 && ua.indexOf("Trident") > -1){
		return "ie";
	}
	return "";
}

function set_charset(){
	var br = ua_check();
	if(br == "ie"){
		document.charset='korean';
	}
	if(br == "firefox"){
		document.charset = 'x-windows-949';
	}
}

function get_timestamp(){
	if (!Date.now) {
	    Date.now = function() { return new Date().getTime(); }
	}
	var timestamp = Math.floor(Date.now() / 1000);
	return timestamp;
}

function set_last_content(code, number, uptime){
	var c_str = code + "|" + number + "|" + uptime;
	hu_setCookie("last_content_cook", c_str, 30);
}

function getCaret(el) { 
  if (el.selectionStart) { 
    return el.selectionStart; 
  } else if (document.selection) { 
    el.focus(); 

    var r = document.selection.createRange(); 
    if (r == null) { 
      return 0; 
    } 

    var re = el.createTextRange(), 
        rc = re.duplicate(); 
    re.moveToBookmark(r.getBookmark()); 
    rc.setEndPoint('EndToStart', re); 

    return rc.text.length; 
  }  
  return 0; 
}

var cr_content_pos;
function cr_file_popup(cr_idx){
	var url = "/cr/cr_file_popup.html?cr_idx="+ cr_idx;
	cr_file_win = window.open(url, "c_file_" + cr_idx,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=880,height=710,resizable=yes");
}
function cr_file_popup_content(cr_idx){
	cr_content_pos = getCaret(document.getElementById('content'));
	cr_file_popup(cr_idx);
}
function cr_profile_popup(cr_idx){
	var url = "/cr/cr_profile_popup.html?cr_idx="+ cr_idx;
	cr_profile_win = window.open(url, "c_profile_" + cr_idx,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=880,height=710,resizable=yes");
}
function cr_payment_popup(cr_idx, number){
	var url = "/cr/cr_payment_popup.html?cr_idx="+ cr_idx + "&number=" + number;
	cr_profile_win = window.open(url, "c_profile_" + cr_idx,"scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,status=no,width=640,height=480,resizable=yes");
}
function hu_log(val1, val2, val3, val4, val5, val6){
	if(getBrowser() != "chrome" && getBrowser() != "android" && getBrowser() != "iphone" && getBrowser() != "ipad"){
		return;
	}
	if(val6){
		console.log(val1, val2, val3, val4, val5, val6);
	}else if(val5){
		console.log(val1, val2, val3, val4, val5);
	}else if(val4){
		console.log(val1, val2, val3, val4);
	}else if(val3){
		console.log(val1, val2, val3);
	}else if(val2){
		console.log(val1, val2);
	}else{
		console.log(val1);
	}
}

function check_img(upload){
	if(upload){
		upload = upload.slice(upload.lastIndexOf(".") + 1).toLowerCase();
		if(upload != "jpeg" && upload != "webp" && upload != "jpg" && upload != "png" &&  upload != "gif"){
			return false;
		}
		return true;
	}
	return false;
}


function btn_blur_blue(obj){
	$(obj).css('filter', 'opacity(50%)');
	setTimeout(function() {
		$(obj).css('filter', 'opacity(100%)');
	}, 100)
}

function go_to(enc, obj){
	if(!enc){
		return;
	}
	btn_blur_blue(obj);

	url = "boardexp/go_to.html?enc="+enc;

	var obj = document.getElementById("body");
	var anchor = document.createElement("a");

	anchor.setAttribute("href", url);
	anchor.setAttribute('target', '_blank');
	anchor.style.display = "none";
	obj.appendChild(anchor);
	anchor.click();
}

function gogogo(enc, obj){
	go_to(enc, obj);
}

function go_to_top(enc, obj){
	if(!enc){
		return;
	}
	btn_blur_blue(obj);

	url = "boardexp/go_to.html?enc="+enc;

	var obj = document.getElementById("body");
	var anchor = document.createElement("a");

	anchor.setAttribute("href", url);
	anchor.setAttribute('target', '_top');
	anchor.style.display = "none";
	obj.appendChild(anchor);
	anchor.click();
}


function run(obj_id){
	var param_guess = 2;
    var params = jQuery("#ch2_form").serialize();
	if(!params){
		var param_guess = 4;
		params = jQuery("#ch4_form").serialize();
	}
	
    jQuery.ajax({
        url: 'boardexp/goods.html',
        type: 'GET',
        data:params,
        contentType: 'application/x-www-form-urlencoded; charset=EUC-KR', 
        dataType: 'html',
		error: function(xhr, status, error) {
	        if (xhr.responseText == ""){
				$("#"+obj_id).hide();
				$(".five").hide();
				document.cookie = "post_cook=ok; path=/; domain=humoruniv.com; ";
		        run2();
			}
	    },
        success: function (data) {
            if (data){
				//data = atob(data);
				data = data.replace(/__blank__/gi, "");
				data = data.replace(/__dot__/gi, ".");
				data = data.replace(/__start__/gi, "<");
				data = data.replace(/__end__/gi, ">");
				data = data.replace(/__nbsp__/gi, " ");
				data = data.replace(/__mark__/gi, ".");
				data = data.replace(/__class__/gi, "class");

				$( "#"+obj_id).html( data );
				$( "#"+obj_id).addClass('bt1');
				
				setTimeout(function() {
					var height = $( "#"+obj_id).css("height").replace("px", "");
					if(typeof height != "string" || height == 0 || (height && 1 <= height && height <= 20) ){
						$("#"+obj_id).hide();
						$(".five").show();
						$(".five").css('min-height','101px');
						if(param_guess == 2){
							$(".five").css('min-height','141px');
						}
						$(".five").html( data );
						setTimeout(function() {
							var height = $( "#"+obj_id).css("height").replace("px", "");
							if(typeof height != "string" || height == 0 || (height && 1 <= height && height <= 20) ){
								$("#"+obj_id).hide();
								$(".five").hide();
								document.cookie = "post_cook=ok; path=/; domain=humoruniv.com; ";
								run2();
							}
						}, 10);

					}else{
						$(".five").hide();
					}
				}, 20);
            }
        }
    });
}
