﻿var is_ing = false;

function getImgUrl()
{
    var url = "http://image.suddenattack.gamehi.com";
    return url;
}

function getFileUrl()
{
    var url = "http://file.gamehi.com";
    return url;
}

function check_ing()
{
	if(is_ing)
	{
		alert("처리 중 입니다.\n잠시만 기다려 주세요.");
		return false;
	}
	else
	{
		is_ing = true;
		return true;
	}
}

function resize()
{
    var p_height, p_width;
    p_width = document.getElementById("img_Preview").width;
    p_height = document.getElementById("img_Preview").height;
    //if (p_width > 1024) p_width = 1024;
    //if (p_height > 768) p_height = 768;
    
   
    fnResizePopup(p_width, p_height);

}
function fnResizePopup(nWidth, nHeight)
{
    var strAgent = navigator.userAgent.toLowerCase();
    var bIE = (strAgent.indexOf("msie") != -1);
    var bXP = (strAgent.indexOf("nt 5.1") != -1);
    var bIE7 = (strAgent.indexOf("msie 7.0") != -1);
    var bSafari = (strAgent.indexOf("konqueror") != -1 || strAgent.indexOf("safari") != -1);
    var bFirefox = (strAgent.indexOf("firefox")!= -1);
    window.resizeTo(nWidth, nHeight + (bXP ? (bIE7 ? 40: 20) : 0));
}

// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}

// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}

// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}

// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}

String.prototype.cut = function(len,lstr)
{
	var str = this;
	if(typeof(lstr)=='undefined')
	{
		lstr = "";
	}
	var c = 0;
	for(var i=0; i<str.length; i++)
	{
		c += (str.charCodeAt(i) > 128) ? 2 : 1;
		if(c > len) return str.substring(0,i) + lstr;
	}
}


String.prototype.bytes = function()
{
	var str = this;
	var c = 0;
	for (var i=0; i<str.length; i++)
	{
		c += (str.charCodeAt(i) > 128) ? 2 : 1;
	}
	return c;
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

function getObject(elementId) { 
    if (document.getElementById) 
        { return document.getElementById(elementId);}
    else if (document.all) { 
        return document.all[elementId];}
    else if (document.layers) {
        return document.layers[elementId];}
}

function getSWF(movieName)
{
	if(navigator.appName.indexOf("Microsoft") != -1)
	{
		return document.getElementById(movieName);
	}
	else
	{
		if(document[movieName].length != undefined)
		{
			return document[movieName][1];
		}
		return document[movieName];
	}
}

function _top(tt)
{
	if(document.body.scrollTop > tt)
	{
		document.body.scrollTop = tt;
	}
	if(document.documentElement.scrollTop > tt)
	{
		document.documentElement.scrollTop = tt;
	}
}

var StickerAnimation = function(){};
StickerAnimation.prototype = {
		duration : null
	,	obj : null
	,	from : null
	,	to: null
	,	timer : 0
	,	step : 0
	,	start : function(obj,from,to, duration){
		var self = this;
		this.obj = obj;
		this.from = from;
		this.to = to;
		this.now = new Date;
		this.duration = duration || 1000;
		this._delta = this['_deltaExpo'];
		if(this.timer)
		{
			this.stop();
		}
		
		this.timer = setInterval(function(){self.run();}, 10);
	}
	,run : function()
	{
		var time = ((new Date) - this.now) / this.duration;
		var delta = this._delta(time);
		
		var step = Math.pow(2, this.step);
		var dep_y = (this.to.y - this.from.y) * delta;
		if(time > 1)
		{
			this.stop();
			this.end();
		}
		else
		{
			this.obj.style.top = (this.from.y + dep_y) + "px";
		}
	}
	,end: function()
	{
		this.obj.style.top = (this.to.y) + "px";
	}
	,stop : function()
	{
		clearInterval(this.timer);
		this.timer = 0;
	}
	,_deltaExpo: function(pos)
	{
		var p = 1 - pos;
		return 1 - Math.pow(2, 8 * (p - 1));
	}
}


var _quick_menu = {
		init : false
	,	sticker : null
	,	opts : []
	,	start : function(id, duration)
	{
		if(!this.init)
		{
			var self = this;
			var init_event = function(){self.oninit();};
			var scroll_event = function(){self.onscroll();};
			if(window.attachEvent)
			{
				window.attachEvent('onload', init_event);
				window.attachEvent('onscroll', scroll_event);
			}
			else
			{
				window.addEventListener('load', init_event, false);
				document.addEventListener('scroll', scroll_event, false);
			}
			this.init = true;
		}
		this.sticker = document.getElementById(id);
		this.opts.push({duration:duration});
	}
	,oninit : function()
	{
		this.sticker.style.top = "0px";
	}
	,onscroll : function()
	{
		var top = 0;
		var form;
		var to;
		var ttt = 350 + 0;
		if(typeof(window.pageYOffset) == 'number')
		{
			top = window.pageYOffset;
		}
		else if(document.body && document.body.scrollTop)
		{
			top = document.body.scrollTop;
		}
		else if(document.documentElement && document.documentElement.scrollTop)
		{
			top = document.documentElement.scrollTop;
		}
		
		from = parseInt(this.sticker.style.top);
		if(top > ttt)
		{
			to = top - ttt;
		}
		else
		{
			to = 0;
		}
		
		if(!this.sticker.animation)
		{
			this.sticker.animation = new StickerAnimation();
		}
		else
		{
			this.sticker.animation.stop();
		}
		
		this.sticker.animation.start(
			this.sticker, 
			{y:from},
			{y:to},
			this.opts.duration
		);
	}
}

function _forum(idx)
{
	if(idx==0)
	{
		window.open("http://www.playforum.net/metalrage");
	}
	else if(idx==1)
	{
		window.open("http://mr.inven.co.kr");
	}
	else if(idx==2)
	{
		window.open("http://metalrage.mud4u.com");
	}
}

function getCookie(name)
{
	var flag = document.cookie.indexOf(name+'=');
	if(flag!=-1)
	{
		flag += name.length + 1;
		end = document.cookie.indexOf(';',flag);
	    if(end==-1) end = document.cookie.length;
		return document.cookie.substring(flag,end);
	}
	else
	{
		return "";
	}
}

function setCookie(name,value) {
	var MinMilli = 1000 * 60;
	var HrMilli = MinMilli * 60;
	var DyMilli = HrMilli * 24;

	var todayDate = new Date();
	todayDate.setTime(Math.round(todayDate.getTime()/DyMilli + 1) * DyMilli);// 1day
	document.cookie = name + "=" + escape( value ) + "; expires=" + todayDate.toGMTString() + ";"
}

function openPopup(name,url,width,height)
{
	var winpos = "left=" + ((window.screen.width-width)/2) + ",top=" + ((window.screen.height-height)/2 - 60);
	var _popup = window.open(url,name,"width="+width+",height="+height+","+winpos);
	
	if(typeof(_popup)!='undefined')
	{
		_popup.focus();
	}
}

function openUserInfo(userno,publisher_id,type)
{
    if(typeof(type) == 'undefined')
    {
        type='user';
    }
	openPopup('_userinfo','/popup/userinfo.aspx?userno=' + userno + '&publisher_id=' + publisher_id + '&type=' + type,570,730);
}

function openClanInfo(userno,clanno,publisher_id,type)
{
	openPopup('_claninfo','/popup/claninfo.aspx?userno=' + userno +'&clanno=' + clanno + '&publisher_id=' + publisher_id + '&type=' + type,570,730);
}


function setPng24(obj)
{
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src = IMG_URL + '/_common/blank.gif'; 
	return '';
}

function getGameLevelImg(level, color_sort, size)
{
	level = level == 0 ? 1 : level;
	var img = "";
	if(color_sort != "" && level > 0)
	{
		var sb = new StringBuilder();
		sb.append("gl_");
		if(color_sort=="2") sb.append("2");
		else sb.append("1");
		sb.append("_");
		sb.append(level);
		sb.append("_");
		sb.append(size);
		sb.append(".png");
		img = "<img align='absmiddle' src='" + IMG_URL + "/_common/class/" + sb.toString() + "' class='png24' style='vertical-align:middle' />";
	}
	return img;
}

function create_div(target_id){
    if(getObject(target_id) == null){
        var NewDiv = document.createElement("Div");
        NewDiv.id = target_id;
        NewDiv.width = NewDiv.height = 0;
        NewDiv.style.display = 'none';
        document.body.appendChild(NewDiv);
    }
}

function create_iframe(target_id){
    if(getObject(target_id) == null){
        var NewFrame = document.createElement("iframe");
        NewFrame.id = target_id;
        NewFrame.width = NewFrame.height = NewFrame.frameborder =0;
        document.body.appendChild(NewFrame);
    }
}

function click_gamestart()
{
	if($.browser.msie)
	{
		create_iframe("Act_frame");
		getObject("Act_frame").src = "/etc/gamestart.aspx";
	}
	else
	{
		if(confirm("게임실행은 Internet Explorer 환경에서만 가능합니다.\n다운로드 하시겠습니까?"))
		{
			window.open("http://www.microsoft.com/korea/windows/downloads/ie/getitnow.mspx");
		}
	}
}

function _enable_write(_async)
{
	return true;
}

function number_format(str)
{
	str += "";
	var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
	while(objRegExp.test(str))
	{
		str = str.replace(objRegExp, '$1,$2');
	} 
	return str;
}

function _open_coupon()
{
	if(is_login)
	{
		openPopup('coupon', 'https://secure.gamehi.co.kr/App/pop/pop_coupon/main.aspx?gamesite=MR', 450, 460);
	}
	else
	{
		__login();
	}
}

//login
function 
    clrImg(obj){
        obj.style.backgroundImage="";obj.onkeydown=obj.onmousedown=null;
    }