// +--------------------------------------------------------+
// | Copyright (c) 2008                                     |
// +--------------------------------------------------------+
// | Author : Noh Seong-Woo <nhosw at i-swear.com>          |
// +--------------------------------------------------------+


var _d=document;
var _index = "";
/* 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+":: net4ts.com ::\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) }
}

function win_open(url, w_name, param) {
	return window.open(url, w_name, param);
}
function base64_encode (data) {
    // Encodes string using MIME base64 algorithm  
    // 
    // version: 1102.614
    // discuss at: http://phpjs.org/functions/base64_encode
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Bayron Guevara
    // +   improved by: Thunder.m
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // *     example 1: base64_encode('Kevin van Zonneveld');
    // *     returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['atob'] == 'function') {
    //    return atob(data);
    //}
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        enc = "",
        tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data = this.utf8_encode(data + '');
 
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1 << 16 | o2 << 8 | o3;
 
        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;
        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
 
    enc = tmp_arr.join('');
 
    switch (data.length % 3) {
    case 1:
        enc = enc.slice(0, -2) + '==';
        break;
    case 2:
        enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}

function utf8_encode (argString) {
    // Encodes an ISO-8859-1 string to UTF-8  
    // 
    // version: 1102.614
    // discuss at: http://phpjs.org/functions/utf8_encode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
    var utftext = "",
        start, end, stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.slice(start, end);
            }
            utftext += enc;
            start = end = n + 1;
        }
    }
 
    if (end > start) {
        utftext += string.slice(start, stringl);
    }
 
    return utftext;
}


//_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;
};


function trim(str) {
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

String.prototype.trim = function() {
    return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
