// +--------------------------------------------------------+
// | Copyright (c) 2008                                     |
// +--------------------------------------------------------+
// | Author : Noh Seong-Woo <nhosw at i-swear.com>          |
// +--------------------------------------------------------+
/*@cc_on _d=document; eval('var document=_d;')@*/

var _d=document;
var _index = "/index.php";
/* browser detect */
try {
var aq={ua:navigator.userAgent.toLowerCase()};
aq.browser = {_isStrict:document.compatMode=="CSS1Compat",_isOpera:aq.ua.indexOf("opera")>-1,_isSafari:(/webkit|khtml/).test(aq.ua),_isIE:!this._isOpera&&aq.ua.indexOf("msie")>-1,_isIE7:!this._isOpera&&aq.ua.indexOf("msie7")>-1,_isGecko:!this._isSafari&&aq.ua.indexOf("gecko")>-1,_isBorderBox:this._isIE&&!this._isStrict,_isWindows:(aq.ua.indexOf("windows")!=-1||aq.ua.indexOf("win32")!=-1),_isMac:(aq.ua.indexOf("macintosh")!=-1||aq.ua.indexOf("macosx")!=-1),
_isLinux:(aq.ua.indexOf("linux")!=-1),_isSecure:window.location.href.toLowerCase().indexOf("https")===0};
}catch(e){ alert(e); };
/* dom */
var dy_loaded = [];
function dynamic_src(get_src) {
	try {
		var cnt = dy_loaded.length;
		var bln = false;
		for (var i=0;i<cnt; i++) { if (dy_loaded[i] == get_src) { bln = true; break; }; }	
		if (bln == false) {
			var script = document.createElement('SCRIPT');
			script.type = 'text/javascript';
			script.src = get_src + '?' + new Date().getTime();
			script.charset = 'UTF-8';
			document.getElementsByTagName('HEAD')[0].appendChild(script);
			dy_loaded[dy_loaded.length] = get_src;
		}
	} catch (e) { alert(e); }
}
function crEl(tag) {var t=document.createElement(tag); try { return t; } finally { t=null;}};
function getTag(el, tag, g_type) { var res = el.getElementsByTagName(tag); if (g_type == undefined && res) return res[0]; else if (g_type != undefined && res) return res; else return null; };
function getValue(el) { if (!el) { return null; } else { if (el.firstChild) return el.firstChild.nodeValue; else return null; }; };
function eventSrc(e) {return (aq.browser._isIE)?e.srcElement:e.target}
/* cookie */
function setCookie(name,value,expire,path) {
	path = (!path)?"/":path;
	var todaydate = new Date();
	var unixtime = todaydate.getTime();
	if (value==null) {
		expire = 0;
	}
	if (expire != null) {
	var extime = unixtime+(expire*1000);
	todaydate.setTime(extime);
	expiretime = " expires=" + todaydate.toUTCString() +";";
	}else{
	expiretime = "";
	}
	document.cookie = name + "=" + escape(value) + "; path="+path+";"+expiretime;
}
function getCookie(s){
    var tmp=document.cookie.split(';');
    for (var i=0; i<tmp.length;i++){
        var c_name = tmp[i].split('=');
        if (c_name[0]==s) return c_name[1];
    }
    return false;
} 
/* short tag */
var _N = 'none';var _B = 'block';var _A = 'absolute';var _UD = 'undefined';

/* util layer */
function getBounds(tag) // getBounds is create by SHJ . PHPSCHOOL
{ 
    var ret = new Object(); 
    if(tag.getBoundingClientRect) { 
        var rect = tag.getBoundingClientRect(); 
        ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
        ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop); 
        ret.width = rect.right - rect.left; 
        ret.height = rect.bottom - rect.top; 
    } else { 
        var box = document.getBoxObjectFor(tag); 
        ret.left = box.x; 
        ret.top = box.y; 
        ret.width = box.width; 
        ret.height = box.height; 
    } 
    return ret; 
};
function byteConvert(size) {
	try {
	if (size == 0) return "0B";
	var s = ['B', 'Kb', 'MB', 'GB', 'TB', 'PB'];
	var e = Math.floor(Math.log(size)/Math.log(1024));
	var tmp = size/Math.pow(1024,Math.floor(e));
	tmp = tmp+'';
	return tmp.substring(0,tmp.indexOf('.')+3) + s[e];
	} catch (e) { alert(e) }
}
function msgbox(msg) { 
	msg = msg.replace(/<br>|<br \/>/gi, "\n"); 
	var tmp = msg.split("\n"), len = 0;
	for (var i=0,cnt=tmp.length; i<cnt; i++) {
		if (len < tmp[i].bytes()) len = tmp[i].bytes();
	}
	len = len / 2 - 9;
	var tmp2 = "";
	for(var i=0;i<len;i++) tmp2 += " ";
	window.alert(tmp2+":: xmiz.net ::\n\n"+msg); 
	tmp = null; len = null; tmp2 = null; msg = null;
}
//function dmsgbox(msg) { msgbox(msg); }
var contentCheck = "/index.php/board/contentCheck";
var TmpUpload = "/index.php/upload/tmpupload";
function dummy() { return (new Date()).getTime(); }
/* ajax upload */
var uploadI = 0;  
var uploadStatus = []; // Assoc array uniqid=>boolean, true -> still uploading, false -> done
function pollTimer(uniqId) {
	return false;
	if (!uploadStatus[uniqId]) return;  
	$.get('upload_stat.php', {id: uniqId}, function(data, textStatus) {  
		if (!uploadStatus[uniqId]) return;  
  
		if (data && data['bytes_total'] && parseInt(data['bytes_total'])) {  
			var percentage = Math.floor(100 * parseInt(data['bytes_uploaded']) / parseInt(data['bytes_total']));  
			updateProgress(uniqId, percentage, false);  
		}  
		setTimeout("pollTimer('" + uniqId + "')", 200);  
	}, 'json')
}
try {
    document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

function chk_check(form, el) {
	try {
	if (typeof form == "string") form = document.forms[form];
	if (form.elements[el] == undefined) return "";
	if (form.elements[el].length == undefined) {
		if (form.elements[el].checked) return "0";
		else return null;
	}
	else {
		var tmp = null;
		for (var i=0,cnt=form.elements[el].length; i<cnt; i++) {
			if (form.elements[el][i].checked) {
				if (tmp == null) tmp = i;
				else tmp += ","+i;
			}
		}
		return tmp;
	}
	} catch (e) { alert(e) }
}


_d.oncontextmenu = ecancel;
// _d.onselectstart = ecancel;

function ecancel(e) {
	if (!e) var e = window.event;

	return false;
}
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;
};