function getCID()
{
    var cid = $("input[name='cid[]']");
    var listcid=new Array();
    $(cid).each(function($key, $value){
        if ($(this).attr("checked") == true) 
            listcid.push(this);
    });
    return listcid;
}
function submitform($task, $option){
    if ($option == null) 
        $option = new Array();
    if ($option['refresh'] == null) 
        $option['refresh'] = true;
    switch ($task) {
        case "cancel":
        var parent = window.parent;
        if (parent != window) {
            return parent.hs.close();
        }
        break;
        case "remove":
        var cid = $("input[name='cid[]']");
        var count = 0;
        $(cid).each(function($key, $value){
            if ($(this).attr("checked") == true) 
                count = count + 1;
        });
        if (count == 0) {
            alert($lang["pleasechooserecord"]);
            return false;
        }
        if (confirm($lang["confirmdelete"]) == false) {
            return false;
        }
        break;
        case "clear":
        if (confirm($lang["confirmclear"]) == false) {
            return false;
        }
        break;
        case "published":
            published(1);
            break;
        case "unpublished":
            published(0);
            $task = "published";
            break;
    }
    if ($option['form'] != null) 
        form = getForm($option['form']);
    else 
        form = getForm();
    $submittwo = $(form).attr("submittwo");
    if ($submittwo == 1) 
        return;
    $(form).attr("submittwo", 1);
    var action = $(form).attr("action");
    var target = action;
    if ($task != null) {
        target = target + $task;
    }
    if ($option['highslide'] == true) {
        var checkbox = "";
        if (form["cid[]"] != null) {
            for (var i = 0; i < form["cid[]"].length; i++) {
                checkbox = form["cid[]"][i];
                if (checkbox.checked == 1) {
                    target = target + "/" + checkbox.value;
                    break;
                }
            }
            if (form["cid[]"].length == null) {
                checkbox = form["cid[]"];
                if (checkbox.checked == 1) {
                    target = target + "/" + checkbox.value;
                }
            }
        }
        else {
            return false;
        }
        var linkhighslide = $("<a  onclick='return ajaxHighslide(this)' href='" + target + "'   ></a>");
        $(linkhighslide).click();
        return false;
    }
    if ($option['link'] != null) 
        target = target + "/" + $option['link'];
    if ($option['superlink'] != null) 
        target = $option['superlink'];
    if ($option['ajax'] == "1") 
        target = target + "/ajax/1/";
    $(form).attr("action", target);
    if ($option['ajax'] == "1") {
        ajaxComponent(null, null, null, $option);
    }
    else {
        switch ($task) {
            case "builder":
            case "add":
            case "edit":
            case "ordering":
            case "remove":
            case "published":
            case "clear":
            case "store":
            case "apply":
            case "store2new":
                ajaxComponent(null, null, null, $option);
                break;
        }
    }
    if ($option['nosubmit'] == null) 
        $(form).submit();
    return false;
}

function addScript(jsname, func, doc, classscript){
    if (is_null(window.scripts) == true) {
        window.scripts = new Array();
    }
    if (doc == null) 
        doc = document;
    var th = doc.getElementsByTagName("head")[0];
    var scriptExist = false;
    $("script", th).each(function(){
        var $scripthd = $(this).attr("src");
        var exist = false;
        for (var i = 0; i < window.scripts.length; i++) {
            var $std = window.scripts[i];
            var $scripts = $std.scripts;
            var $status = $std.status;
            if ($scripthd == $scripts) {
                exist = true;
            }
        };
        if (exist == false) {
            var $std = new stdClass();
            $std.scripts = $scripthd;
            $std.status = 0;
            window.scripts.push($std);
        }
    });
    var funcEnable = function(pos){
        if (classscript == null) {
            window.scripts[pos].status == 1;
            func();
            return true;
        }
        var intval = setInterval(function(){
            if (is_null(eval(classscript)) == false) {
                clearInterval(intval);
                window.scripts[pos].status = 1;
                func();
            }
        }, 100);
    };
    var func_delay_loadscriptcontent = function(){
        for (var i = 0; i < window.scripts.length; i++) {
            $std = window.scripts[i];
            if ($std.scripts == jsname && $std.status == 1) {
                func();
                return true;
            }
            if ($std.scripts == jsname && $std.status == 0) {
                funcEnable(i);
                return true;
            }
        }
        return false;
    };
    if (func_delay_loadscriptcontent() == true) 
        return;
    if (doc == null) 
        doc = document;
    var th = doc.getElementsByTagName("head")[0];
    $std = new stdClass();
    $std.scripts = jsname;
    $std.status = 0;
    var pos = window.scripts.push($std);
    $.getScript(jsname, function(){
        if (func == null) 
            return;
        funcEnable(pos - 1);
    });
}

function attackSubmitLink(obj, $opt, func){
    if (is_null($opt)) 
        $opt = new Array();
    var href;
    if (is_string(obj) == true) 
        href = obj;
    else 
        href = $(obj).attr("href");
    var form = getForm('attackSubmitLink');
    if (form != null) 
        $(form).remove();
    form = $("<form name='attackSubmitLink' id='attackSubmitLink' method='post'><input type='hidden' name='ajax' value='1' /></form>")[0];
    form.action = href;
    $("body", document).append(form);
    $($opt).foreach(function(key, $value){
        setValueForm(key, $value, form);
    });
    if (is_null($opt['display']) == true) 
        $opt['display'] = "#component";
    ajaxComponent($opt['display'], "attackSubmitLink", document, $opt);
    if (func != null) {
        $opt['onBeforeSubmit'] = func;
    }
    $(form).submit();
    return false;
}

function ajaxComponent(selectortarget, formname, documents, $opt){
    if ($opt == null) 
        $opt = new Array();
    $opt["onBeforeDisplay"] = function(html){
        if (window.onBeforeDisplay != null) 
            onBeforeDisplay(html);
    };
    if (selectortarget == null) 
        selectortarget = "#component";
    if (formname == null) 
        formname = "adminlist";
    if (documents == null) 
        documents = document;
    var form = getForm(formname, documents);
    if (form == null) 
        return false;
    if (is_null($(form).attr('attack_ajaxcomponent')) == false) {
        return;
    }
    $(form).attr('attack_ajaxcomponent', 1);
    setValueForm("ajax", 1, form);
    if ($(form).attr("attacksubmit") == null) 
        $(form).attr("attacksubmit", true);
    else 
        return;
    var funcbind = function(){
        $(window.fck).each(function($key, $value){
            if (is_null(window.FCKeditorAPI) == false) {
                if (is_null(window.FCKeditorAPI.Instances[$value]) == false) 
                    FCKeditorAPI.Instances[$value].UpdateLinkedField();
            }
        });
        window.fck = null;
        var obj = this;
        $.jnet_ajax(function(){
            $(obj).ajaxSubmit({
                dataType: 'html',
                beforeSubmit: function(formData, jqForm, options){
                    showPleaseWait();
                    return true;
                },
                success: function($packet){
                    var packet = decodePacketAjax($packet);
                    if (is_null($opt['func']) == false) 
                        $opt['func'](packet);
                    closePleaseWait(packet);
                    var func = $(form).attr("onBeforeSubmit");
                    if (is_null(func) == true) 
                        func = $opt['onBeforeSubmit'];
                    if (is_null(func) == false) {
                        if (is_func(func) == true) 
                            func(form, packet);
                        else 
                            window[func](form, packet);
                    }
                    if (selectortarget != 'none') 
                        showResponeAjax(selectortarget, $packet, $opt);
                    return true;
                }
            });
        });
    };
    $bindform = array_key_get("bindform", $opt, 0);
    if ($bindform == 0) {
        $(form).bind('submit', function(){
            funcbind.apply(this);
            return false;
        });
    }
    else {
        funcbind.apply(form);
    }
}

function showPleaseWait(){
    var message = "<h1>" + $lang['confirmpleasewait'] + "</h1>";
    $.blockUI({
        message: message
    });
}

function closePleaseWait(packet){
    if (packet['message'] == "") {
        $.unblockUI();
    }
    else {
        $(".blockMsg").empty();
        $(".blockMsg").append(packet['message']);
        setTimeout($.unblockUI, 1000);
    }
}

function cancel(){
    history.back("-1");
}

function reset(){
    document.adminlist.reset();
}

function attackHistory(){
    $.history.init(function(link){
        if (is_null(window.myhistory) == true) 
            window.myhistory = new Array();
        if (link == "" || is_null(window.myhistory[link]) == true) {
            window.location.reload(false);
            return;
        }
        var $std = window.myhistory[link];
        var func = $std["func"];
        var params = $std["params"];
        var obj = $std["obj"];
        func.apply(obj, params);
    });
}

function ajaxPagenation(form){
    $(".pagenation  a").each(function(){
        var result = $(this).hasClass("attackedpagenation");
        if (result == true) 
            return true;
        $(this).addClass("attackedpagenation");
        $(this).click(function(event){
            $(this).jnet_addhistory(function(){
                $(this).attr("href", "#");
                var attpagenation = $(this).attr("pagenation");
                var arraypagenation = attpagenation.split(";");
                setValueForm("limit", arraypagenation[0]);
                setValueForm("limitstart", arraypagenation[1]);
                setValueForm("Itemid", arraypagenation[2]);
                if (is_object(form) == false) {
                    if (form == null) 
                        form = "adminlist";
                    form = $("form[name='" + form + "']")[0];
                }
                $(form).submit();
            });
            return false;
        })
    });
}

function submitLink(link){
    var form = getForm();
    $(form).attr("action", link);
    $(form).submit();
    return false;
}

function getForm($name, $document){
    if ($name == null) 
        $name = "adminlist";
    if ($document == null) 
        $document = document;
    form = null;
    var forms = $document.getElementsByTagName('form');
    for (var i = 0; i < forms.length; i++) {
        form_name = $(forms[i]).attr('name');
        if (form_name == $name) 
            form = forms[i];
    }
    return form;
}

function removeValueForm(name, form){
    if (form == null) 
        form = "adminlist";
    form = $("form[name='" + form + "']")[0];
    var tagName = $("input[name='" + name + "']")[0];
    $(tagName).remove();
}

function setValueForm(name, value, form){
    if (form == null) {
        form = getForm();
    }
    if (is_string(form) == true) {
        form = getForm(form);
    }
    if (value == null) 
        value = "";
    if (form[name] == null) {
        var input = document.createElement("input");
        input.name = name;
        input.value = value;
        input.id = name;
        input.type = "hidden";
        form.appendChild(input);
    }
    else 
        form[name].value = value;
}

function published(published, id){
    if (id != null) {
        var cid = $(" input[name='cid[]'] ").attr("checked", '');
        $(" input[name='cid[]'][value='" + id + "'] ").attr("checked", 'checked');
    }
    setValueForm("published", published);
    return false;
}

function checkall(obj){
    var cid = $(" input[name='cid[]'] ");
    if ($(obj).attr('checked') == 1) {
        cid.attr("checked", 'checked');
    }
    else 
        cid.attr("checked", '');
}

function pagenation(limit, limitstart){
    setValueForm("limit", limit);
    setValueForm("limitstart", limitstart);
    submitform();
}

function sort(ordering){
    var sorttadminlist = $(".adminlist").tableDnDSerialize();
    var serialStr = "";
    $(".listcategory ul li").each(function(i, elm){
        if ($(this).attr("value") != -1) 
            sorttadminlist += "&id=" + $(elm).attr("value");
    });
    if (ordering == null) 
        ordering = "ordering";
    setValueForm(ordering, sorttadminlist);
    submitform("ordering");
}

function attackSearch(selector){
    $(selector).each(function(){
        var obj = $(this);
        $(obj).attr("defaultvalue", $(obj).val());
        $(obj).blur(function(){
            var text = $(this).attr('value').replace(" ", "");
            if (text == "") {
                var value = $(this).attr('defaultvalue');
                $(this).val(value);
            }
        });
        $(obj).click(function(){
            if ($(this).val() == $(this).attr('defaultvalue')) {
                $(this).val("");
            }
        });
    })
}

function isIE(){
    var isIE = 0;
    if (navigator.appVersion.indexOf("MSIE") != -1) {
        isIE = 1;
    }
    return isIE;
}

function checkingIE(){
    return (navigator.appName == 'Microsoft Internet Explorer') ? parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]) : -1;
}

function orderby(name){
    setValueForm("orderby", name);
    submitform();
}

function addFocus(classname){
    var aclassname = classname.split(",");
    for (var i = 0; i < aclassname.length; i++) {
        classname = aclassname[i];
        $('.' + classname).focus(function(){
            $(this).addClass(classname + "_hover");
        });
        $('.' + classname).blur(function(){
            $(this).removeClass(classname + "_hover");
        });
    }
}

function addClassHover(classname){
    $('.' + classname).mouseover(function(){
        $(this).addClass(classname + "_hover");
    });
    $('.' + classname).mouseout(function(){
        $(this).removeClass(classname + "_hover");
    });
}

function autoHeight1(){
    var colleft = $("#colleft #colleft-padding").height();
    var colright = $("#colright #colright-padding").height();
    var maincontent = $("#maincontent #maincontent-padding").height();
    var max = colleft > colright ? colleft : colright;
    max = maincontent > max ? maincontent : max;
    $("#colleft #colleft-padding").height(max);
    $("#colright #colright-padding").height(max);
    var height = $("#maincontent #maincontent-padding").height();
    if (height == max) {
        $("#maincontent #maincontent-padding").height(max);
    }
    else 
        $("#maincontent #maincontent-padding").height(max - 40);
}

function autoHeight(selector){
    $(selector).css("height", "auto");
    var max = 0;
    var $max = 0;
    $(selector).each(function(){
        var height = $(this).height() + parseFloat($(this).css("margin-top")) + parseFloat($(this).css("margin-bottom"));
        if (height > max) {
            max = height;
            $max = this;
        }
    });
    $(selector).height(max);
    $(selector).resize(function(){
        autoHeight();
    });
}

function roundHeight(selector){
    var value = $(selector).height();
    var autoPadDiv = $(".autoPadDiv", selector)[0];
    var height = $(autoPadDiv).height();
    $("div:first", selector).height(height - value * 2);
    $(selector).height(height + value);
    var border = $(".border", $(autoPadDiv).parent())[0];
    $(border).height(height);
}

function preventDefault(e){
    if (!e) 
        event.returnValue = false;
    else 
        e.preventDefault();
    return false;
}

jQuery.fn.curvy = function(options){
    var settings = {
        tl: {
            radius: 10
        },
        tr: {
            radius: 10
        },
        bl: {
            radius: 10
        },
        br: {
            radius: 10
        },
        antiAlias: true,
        autoPad: true,
        validTags: ["div"]
    };
    if (options && typeof(options) != 'string') 
        jQuery.extend(settings, options);
    return this.each(function(){
        new curvyObject(settings, this).applyCorners();
    });
};
function showResponeAjax(selectortarget, html, $opt){
    if (array_key_exist("typedisplay", $opt) == false) 
        array_key_set($opt, "typedisplay", "append");
    var packet = decodePacketAjax(html);
    var content = packet['content'];
    var message = packet['message'];
    var heading = packet['heading'];
    if (heading != "") 
        $("span", ".heading").html(heading);
    if ($opt['typedisplay'] == "append") {
        $(selectortarget).empty();
        $(selectortarget).append(content);
    }
    if ($opt['typedisplay'] == "replace") {
        $(selectortarget).replaceWith(content);
    }
    $onBeforeDisplay = array_key_get("onBeforeDisplay", $opt);
    if (is_null($onBeforeDisplay) == false) {
        $onBeforeDisplay.apply(html);
    }
    if (window.autoWidth != null) 
        window.autoWidth();
    if (window.onBeforeResponeAjaxSite != null) {
        window.onBeforeResponeAjaxSite();
    }
}

function attackend(){
    $("ul").each(function(){
        $(this).find("li:last").addClass("end");
    });
}

function attackmenucenter(selector){
    $(selector).css("float", "left");
    $(selector).width($(selector).width());
    $(selector).css("float", "none");
    $(selector).css("margin-left", "auto");
    $(selector).css("margin-right", "auto");
}

function scrollWin(pos, time){
    if (time == false) {
        time = 1000;
    }
    if (window.scrolling == null) {
        window.scrolling = true;
        $('html,body').animate({
            scrollTop: pos
        }, time, "linear", function(){
            window.scrolling = null;
        });
    }
}

function gototop(){
    scrollWin(0);
}

function addAjaxHighslide(href){
    var pos = href.indexOf("/ajax/1/");
    if (pos == -1) {
        asplit = href.split("/");
        href = "";
        for (var i = 0; i < asplit.length; i++) {
            if (i == asplit.length - 1) {
                href = href + asplit[i];
            }
            else 
                href = href + asplit[i] + "/";
            if (i == asplit.length - 1) {
                href = href + "/ajax/1/template/highslide/";
            }
        }
    }
    return href;
}

function ajaxHighslide(obj, form, func){
    if (is_string(obj) == true) {
        var a = $("<a></a>");
        a.attr("href", obj);
        obj = a[0];
    }
    $(obj).jnet_highslide(function(){
        var href = obj;
        if (is_object(obj) == true) {
            var href = $(obj).attr("href");
        }
        href = addAjaxHighslide(href);
        $(obj).attr("href", href);
        hs.width = "840";
        hs.objectStyle = "overflow-x:hidden";
        var linkhighslide = $("<a  onclick=\" return hs.htmlExpand(this, { objectType: 'iframe' } )  \"  href='" + href + "' ></a>");
        $(linkhighslide).click();
        var form = getForm(form);
        var action = $(form).attr("action");
        hs.Expander.prototype.onAfterClose = function(sender){
            $(".highslide-controls").parent().remove();
            removeValueForm("template");
            $(form).attr("action", action);
            if (func == null) {
                $(form).submit();
            }
            else {
                (func)();
            }
        }
    });
    return false;
}

function ajaxlink(obj, silent, func){
    var href = obj;
    if (is_object(obj) == true) {
        href = $(obj).attr("href");
    }
    var pos = href.indexOf("/ajax/1/");
    if (pos == -1) {
        asplit = href.split("/");
        href = "";
        for (var i = 0; i < asplit.length; i++) {
            if (i == asplit.length - 1) {
                href = href + asplit[i];
            }
            else 
                href = href + asplit[i] + "/";
            if (i == asplit.length - 1) {
                if (silent == null) 
                    href = href + "/index/ajax/1/";
                else 
                    href = href + "/index/ajax/1/silent/1";
            }
        }
    }
    $.ajax({
        url: href,
        dataType: "html",
        success: function(html){
            var packet = decodePacketAjax(html);
            var content = packet['content'];
            var message = packet['message'];
            if (silent == null) {
                $("#component").empty();
                $("#component").html(content);
            }
            else {
                if (func != null) {
                    func(content, message);
                }
            }
        }
    });
    return false;
}

function addtocart(obj){
    var href = $(obj).attr("href");
    $.ajax({
        url: href,
        dataType: 'html',
        success: function(html){
            var result = $.evalJSON(html);
            if (parseInt(result.code) == 1) {
                var cartnumber = $("#cartnumber").html();
                cartnumber = parseInt(cartnumber) + 1;
                $("#cartnumber").html(cartnumber);
            }
            alert(result.message);
        }
    });
    return false;
}

function visuallightbox_png(){
    if ($("#outerImageContainer").html() != null) {
        $("#outerImageContainer .ml").pngFix();
        $("#outerImageContainer .tc").pngFix();
        $("#outerImageContainer .tl").pngFix();
        $("#outerImageContainer .mr").pngFix();
        $("#outerImageContainer .br").pngFix();
        $("#outerImageContainer .bc").pngFix();
        $("#outerImageContainer .bl").pngFix();
        $("#outerImageContainer .tr").pngFix();
        DD_belatedPNG.fix('#slideShowControl');
    }
}

function textAffect(selector, colors){
    var text = $(selector).html();
    var arrayColor = colors;
    var h1Anim = new HeaderFader(selector, arrayColor, function(){
        $(".heading .heading_span").textColor({
            'text': text,
            'colours': arrayColor
        });
    });
}

function is_type(obj, ext){
    var arraySplit = obj.split(".");
    if (arraySplit.length == 0) 
        return false;
    var myext = arraySplit[arraySplit.length - 1];
    if (is_string(ext) == true) {
        myext = myext.toLowerCase();
        if (myext == ext) 
            return true;
        if (ext == "image") {
            $option = new Array("jpg", "png", "jpeg", "gif", "bmp");
            for (var i = 0; i < $option.length; i++) {
                if (myext == $option[i]) 
                    return true;
            }
        }
    }
    return false;
}

function is_object(what){
    return (typeof what == 'object');
}

function is_func(what){
    return (typeof what == 'function');
}

function is_string(what){
    return (typeof what == 'string');
}

function is_array(what){
    return (typeof what == 'array');
}

function is_null(obj){
    if (obj == null) 
        return true;
    if (obj == undefined) 
        return true;
    return false;
}

function hidetr(name){
    var form = getForm();
    var object = form[name];
    $(object).parent().parent().hide();
}

function showtr(name){
    var form = getForm();
    var object = form[name];
    $(object).parent().parent().show();
}

function rounder(selector){
    if (checkingIE() != 6) 
        return false;
    setPosRounder(selector + " .rt", "l");
    setPosRounder(selector + " .lb", "t");
    setPosRounder(selector + " .rb", "l");
    setPosRounder(selector + " .rb", "t");
    $(selector).resize(function(){
        setPosRounder(selector + " .rt", "l");
        setPosRounder(selector + " .lb", "t");
        setPosRounder(selector + " .rb", "l");
        setPosRounder(selector + " .rb", "t");
    })
}

function setPosRounder(selector, type){
    $(selector).each(function(){
        var parent = $(this).parent();
        var padding_left = parseFloat(parent.css("padding-left"));
        var padding_right = parseFloat(parent.css("padding-right"));
        var padding_top = parseFloat(parent.css("padding-top"));
        var padding_bottom = parseFloat(parent.css("padding-bottom"));
        var width = parent.width() + padding_left + padding_right;
        var height = parent.height() + padding_top + padding_bottom;
        if (type == "l") {
            var width = width - 5;
            $(this).css("left", width);
            $(this).css("right", "auto");
        }
        if (type == "t") {
            var height = height - 5;
            $(this).css("top", height);
            $(this).css("bottom", "auto");
        }
    });
}

function uploadfile_delete(name, file, obj){
    var form = getForm();
    name = name + "_delete";
    if (form[name] != undefined) {
        file = $(form[name])[0].value + ";" + file;
    }
    setValueForm(name, file);
    $(obj).parent().remove();
}

Array.prototype.remove = function(from, to){
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
};
function showtooltip(selector){
    $(selector).jnet_bt(function(){
        $(selector).each(function(){
            $(this).bt({
                contentSelector: function(){
                    var title = $(this).html();
                    var decsription = $(this).attr("title");
                    var src = $(this).attr("src");
                    var div = $("<div class='tooltip'><a class='title'></a><div class='clear'></div><a class='img'><img src='' /></a><div class='description'></div></div>");
                    $(".title", div).html(title);
                    $(".title", div).attr("href", this.href);
                    if (src == null) {
                        $(".img", div).css("display", "none");
                    }
                    else {
                        if (is_type(src, "image") == true) {
                            $("img", div).attr("src", src);
                        }
                        else {
                            $(".img", div).css("display", "none");
                        }
                    }
                    $(".description", div).html(decsription);
                    return div[0];
                },
                width: 400,
                fill: '#fff',
                cornerRadius: 5,
                strokeWidth: 0,
                shadow: true,
                shadowOffsetX: 3,
                shadowOffsetY: 3,
                shadowBlur: 8,
                shadowColor: 'rgba(0,0,0,.9)',
                shadowOverlap: false,
                noShadowOpts: {
                    strokeStyle: '#999',
                    strokeWidth: 2
                },
                offsetParent: '#body'
            });
        });
    });
}

function showtooltipimg(selector, opts){
    var options = {
        trigger: 'hover',
        fill: '#000',
        cornerRadius: 10,
        strokeWidth: 0,
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: 'rgba(0,0,0,.9)',
        shadowOverlap: false,
        noShadowOpts: {
            strokeStyle: '#999',
            strokeWidth: 2
        },
        offsetParent: "#body"
    };
    options = array_copy(opts, options);
    function showtooltipimghover(){
        $(selector).jnet_bt(function(){
            $(selector).each(function(){
                $(this).hover(function(){
                    if (this.showtooltipimg == 1) 
                        return;
                    this.showtooltipimg = 1;
                    obja = this;
                    var rel = $(this).attr("rel");
                    getImages(rel, function(){
                        var divimg = $("<div style='position: absolute; left: -1000pc; top: -1000pc; z-index: -100;' ></div>");
                        var vcontentSelector = $("<img   src='" + rel + "'  />");
                        divimg.append(vcontentSelector);
                        $("body", document).append(divimg);
                        $(vcontentSelector).readybrowser(function(){
                            $width = $(vcontentSelector).width();
                            $height = $(vcontentSelector).height();
                            options['width'] = $width;
                            options['height'] = $height;
                            options['contentSelector'] = function(){
                                return vcontentSelector;
                            };
                            $(obja).bt(options);
                            $(obja).btOn();
                        });
                    });
                }, function(){
                    $(this).btOff();
                });
            });
        });
    }
    if (isIE() == true) {
        options["shadow"] = 0;
        addScriptGlobal("excanvas", function(){
            showtooltipimghover();
        }, null, "window.CanvasGradient_");
    }
    else 
        showtooltipimghover();
}

function ajaxmenu(selector){
    $(selector).click(function(){
        displayMenu(this);
        $(".lisuperactive", ".menutop").removeClass("lisuperactive");
        $("a", ".menutop").not(".submenuheader").removeClass("active");
        $("a#current", ".menutop").removeAttr("id");
        $("a.superactive", ".menutop").removeClass("superactive");
        $(this).addClass("active");
        window.onBeforeSubmit = function(){
            Cufon.replace(['.heading span', ".moduletablepage h3 span"], {
                hover: false,
                fontFamily: "UVN Bai Sau"
            });
        };
        attackSubmitLink(this);
        return false;
    })
}

function decodePacketAjax(packet){
    var result = new Array();
    var packet = json_decode(packet);
    result["content"] = base64_decode(packet['content']);
    result["message"] = base64_decode(packet['message']);
    if (result["message"] == "\"\"") 
        result["message"] = "";
    result["heading"] = base64_decode(packet['heading']);
    return result;
}

function bindubmitajax(form, func){
    $("[name='" + form + "']").bind('submit', function(){
        submitajax(form, func);
    });
}

function submitajax(form, func, task, display){
    setValueForm("ajax", 1, form);
    $form = getForm(form);
    $url = $form.action;
    if (task != null) 
        $url = $url + task;
    $("[name='" + form + "']").ajaxSubmit({
        dataType: 'html',
        url: $url,
        success: function(html){
            $packet = decodePacketAjax(html);
            if (is_func(func) == true) {
                func($packet);
            }
            else {
                if (display != null) {
                    content = $packet['content'];
                    $(display).html(content);
                }
            }
        }
    });
    return false;
}

function showgooglemap(selector, pos, title, description, zoom, maptype, showtip){
    var apos = pos.split(",");
    var myLatlng = new google.maps.LatLng(apos[0], apos[1]);
    var myOptions = {
        zoom: zoom,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId[maptype]
    };
    var map = new google.maps.Map($(selector)[0], myOptions);
    var contentString = $(description).html();
    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });
    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: title
    });
    google.maps.event.addListener(marker, 'click', function(){
        infowindow.open(map, marker);
    });
    if (showtip == 1) 
        infowindow.open(map, marker);
}

function initKeyboard(selecttor){
    var arrayid = new Array();
    $(selecttor).each(function(){
        if ($(this).attr("id") == "") {
            var id = null;
            for (var i = 1; i <= 100; i++) {
                id = "id" + i;
                if ($("#" + id).length != 0) 
                    continue;
                else 
                    break;
            }
            $(this).attr("id", id);
        }
        var id = $(this).attr("id");
        arrayid.push(id);
    });
}

function autoId(object){
    if ($(object).attr("id") != null) 
        return $(object).attr("id");
    i = 1;
    var id = null;
    while (true) {
        var id = "id" + i;
        if ($(object).attr("id") == null) {
            $(object).attr("id", id);
            break;
        }
        i++;
    }
    return id;
}

function AttackVideo(selector){
    if (selector == null) 
        selector = $(".video");
    var urlvideo = site_url + "templates/global/js/flowplayer/";
    var script_url = urlvideo + "flowplayer-3.2.2.min.js";
    var script_flash = urlvideo + "flowplayer-3.2.2.swf";
    addScript(script_url, function(){
        $(selector).each(function(){
            var height = $(this).height();
            $(this).height(height);
            $(this).html("");
            var video = this;
            var idvideo = autoId(video);
            flowplayer(idvideo, {
                src: script_flash,
                wmode: "transparent"
            }, {
                clip: {
                    autoPlay: true,
                    autoHide: true,
                    time: false
                }
            });
        });
    }, null, "window.flowplayer");
}

function addScriptGlobal(jsname, func, doc, classcript){
    var pathScript = template_global + "js/" + jsname + ".js";
    return addScript(pathScript, func, doc, classcript);
}

function getImages($src, $func){
    var img = $("<img src='" + $src + "' />");
    var divImages = $("<div style='position:absolute;left:-1000pc;top:-1000pc;z-index:-100'></div>");
    divImages.append(img);
    $("body", document).append(divImages);
    $(img).ready(function(){
        var $width = $(img).width();
        var $height = $(img).height();
        if ($width == 0 || $height == 0) {
            var intval = setInterval(function(){
                var $width = $(img).width();
                var $height = $(img).height();
                if ($width != 0 && $height != 0) {
                    clearInterval(intval);
                    if ($func != null) 
                        $func.apply(img);
                }
            }, 100)
        }
        else {
            if ($func != null) 
                $func.apply(img);
        }
    });
}

function checkbox(obj){
    var name = $(obj).attr("name");
    if ($(obj).attr('checked') == 1) {
        names = $("input[name='" + name + "']");
        names.each(function(){
            if (this != obj) 
                $(this).remove();
        });
        $(obj).val(1);
    }
    else {
        $(obj).val(0);
        var input = $("<input type='hidden' />");
        input.attr("name", name);
        input.val(0);
        $(obj).parent().append(input);
    }
}

function json_decode($str){
    return $.evalJSON($str);
}

function attackAVIM(doc){
    if (doc == null) 
        doc = document;
    setInterval(function(){
        var bodydoc = $("body", doc)[0];
        $("iframe", bodydoc).each(function(){
            if (this.attackiframe == true) 
                return;
            this.attackiframe = true;
            iFrameDocument = this.contentDocument;
            addScriptGlobal('avim/avim', null, iFrameDocument);
            addCss(site_url + '/global/js/avim/avim', null, iFrameDocument);
        });
    }, 1000);
}

function getNumberFromString(str){
    var astr = str.match(/[\d\.]+/g);
    var number = new String();
    for (var i = 0; i < astr.length; i++) {
        number = number + "" + astr[i];
    }
    return parseFloat(number)
}

function colorToHex(color){
    if (color.substr(0, 1) == '#') {
        if (color == "#000") 
            return "#000000";
        return color;
    }
    var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color);
    var red = parseInt(digits[2]);
    var green = parseInt(digits[3]);
    var blue = parseInt(digits[4]);
    var rgb = blue | (green << 8) | (red << 16);
    rgb = rgb.toString(16);
    if (red == 0) 
        rgb = "00" + rgb;
    if (red == 0 && green == 0 && blue == 0) 
        rgb = "000000";
    var result = digits[1] + '#' + rgb;
    return result;
}

function array_copy($from, $to){
    if ($from == null) 
        return $to;
    var $copy = $to;
    if (is_object($from) == true) {
        $($from).foreach(function(key, value){
            $copy[key] = value;
        });
    }
    if(is_array($from)==true)
        {
        $(from).each(function(index,value){
            $copy.push(value);
        })
    }
    return $copy;
}
(function($){
    var userAgent = navigator.userAgent.toLowerCase();
    $.browser = {
        version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1],
        safari: /webkit/.test(userAgent),
        opera: /opera/.test(userAgent),
        msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
        mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent),
        chrome: /chrome/.test(navigator.userAgent.toLowerCase())
    };
})(jQuery);
(function($){
    $.event.special.load = {
        setup: function(data, namespaces, hollaback){
            var retVal = false;
            if (this.tagName.toLowerCase() === 'img' && this.src !== "") {
                if (this.complete || this.readyState === 4) {
                    $(this).bind('load', data || {}, hollaback).trigger('load');
                    retVal = true;
                }
                else 
                    if (this.readyState === 'uninitialized' && this.src.indexOf('data:') >= 0) {
                    $(this).trigger('error');
                    retVal = true;
                }
            }
            return retVal;
        }
    }
}(jQuery));
function stdClass(){
    return new Array();
}

function addCss(link, func, doc){
    if (doc == null) 
        doc = document;
    pos = "head";
    var th = doc.getElementsByTagName(pos)[0];
    var s = doc.createElement('link');
    s.setAttribute('href', link + ".css");
    s.setAttribute("rel", "stylesheet");
    s.setAttribute("type", "text/css");
    th.appendChild(s);
    $(s).ready(function(){
        if (func != null) 
            func();
    });
}

function ajaxsimple($link, $func){
    $link = $link + "/ajax/1/template/ajaxsimple";
    $.ajax({
        url: $link,
        dataType: "html",
        success: function(html){
            $func(html);
        }
    });
}

$.fn.readybrowser = function(callback){
    return this.each(function(){
        var obj = this;
        if (obj.tagName == "IMG") {
            getImages(obj.src, function(){
                callback.apply(obj);
            });
        }
        else {
            $(this).ready(function(){
                callback.apply(obj);
            });
        }
    });
};
$.fn.jnet_cycle = function($opts){
    var selector = this;
    var $options = {
        fx: 'all',
        timeout: 8000
    };
    $options = array_copy($opts, $options);
    addScriptGlobal("jquery.cycle/jquery.cycle.all.min", function(){
        $(selector).cycle($options);
    }, null, "$.fn.cycle");
};
$.fn.jnet_validate = function($opts, func){
    var selector = this;
    var $options = {
        errorPlacement: function(error, element){
            var positions = $(element).attr("positions");
            var message = error.html();
            $(element).jnet_bt(function(){
                $(element).attr("attack_bt", 1);
                $(element).bt(message, {
                    trigger: ['focus', 'blur', 'type'],
                    positions: positions,
                    offsetParent: "#body",
                    fill: '#f2f2f2',
                    cornerRadius: 5,
                    strokeStyle: '#9d9b9b',
                    strokeWidth: 1,
                    shadow: false,
                    shadowOffsetX: 3,
                    shadowOffsetY: 3,
                    shadowBlur: 8,
                    shadowColor: '#969696',
                    shadowOverlap: false
                });
                $(element).btOn();
            });
        },
        success: function(label, element){
            if (is_null($.bt) == false) 
                $(element).btOff();
        },
        submitHandler: function(form){
            if (func != null) 
                func(form);
            else 
                form.submit();
        }
    };
    $options = array_copy($opts, $options);
    addScriptGlobal("jquery.validate", function(){
        addScriptGlobal("language_" + lang + "_validate", function(){
            var validate_messages = $lang['validate_messages'];
            $.validator.messages = array_copy(validate_messages, $.validator.messages);
            $(selector).validate($options);
        }, null, "$lang.validate_messages");
    }, null, "$.fn.validate");
};
$.fn.jnet_resize = function(func){
    var obj = this;
    addScriptGlobal("jquery.ba-resize", function(){
        $(obj).resize(func);
    }, null, "$.resize");
};
$.fn.jnet_reflex = function(opts){
    var $options = {
        transparency: 75,
        height: 25,
        boxmode: 1
    };
    $options = array_copy(opts, $options);
    var obj = this;
    addScriptGlobal("cvi/cvi_reflex_lib", function(){
        return obj.each(function(){
            $(this).readybrowser(function(){
                var border_width = parseInt($(this).css("border-left-width"));
                var color = $(this).css("border-left-color");
                var border_color = colorToHex(color);
                var img_width = $(this).css("width");
                var img_height = $(this).css("height");
                if (img_width == "auto") 
                    img_width = $(this).width();
                if (img_height == "auto") 
                    img_height = $(this).height();
                if (parseInt(border_width) > 0) {
                    if (isIE() == false) {
                        $(this).css("width", parseInt(img_width) + parseInt(border_width) * 2);
                        $(this).css("height", parseInt(img_height) + parseInt(border_width) * 2);
                    }
                    else {
                        $(this).css("width", parseInt(img_width) + parseInt(border_width));
                        $(this).css("height", parseInt(img_height) + parseInt(border_width));
                    }
                }
                $options["border"] = border_width;
                $options["color"] = border_color;
                cvi_reflex.add(this, $options);
            });
        });
    }, null, "window.cvi_reflex");
};
$.fn.jnet_bt = function(func){
    var obj = this;
    addScriptGlobal("jquery.hoverIntent.minified", function(){
        addScriptGlobal("bt/jquery.bt", function(){
            func.apply(obj);
        }, null, "$.fn.bt");
    }, null, "$.fn.hoverIntent");
};
$.jnet_ajax = function(func){
    addScriptGlobal("jquery.form", function(){
        addScriptGlobal("utf8_decode", function(){
            addScriptGlobal("base64_decode", function(){
                addScriptGlobal("jquery.json", function(){
                    addScriptGlobal("jquery.blockUI", function(){
                        if (func != null) 
                            func();
                    });
                });
            });
        });
    });
};
$.fn.jnet_font = function($fontName, $option, $colorHover, $optionHover){
    var obj = this;
    if ($option == null) 
        $option = new Array();
    if ($optionHover == null) 
        $optionHover = new Array();
    addScriptGlobal("cufon-yui", function(){
        addScriptGlobal("fonts/" + $fontName + ".font", function(){
            return obj.each(function(){
                $option = array_copy({
                    'fontFamily': $fontName
                }, $option);
                Cufon.replace(this, $option);
                if ($colorHover != null) {
                    $optionHover = array_copy({
                        'color': $colorHover
                    }, $optionHover);
                    Cufon(this, {
                        hover: $optionHover
                    });
                }
            });
        });
    }, null, "window.Cufon");
};
$.fn.jnet_fonthover = function($color, $option){
    var obj = this;
    if ($option == null) 
        $option = new Array();
    addScriptGlobal("cufon-yui", function(){
        return obj.each(function(){
            $option = array_copy({
                'color': $color
            }, $option);
            Cufon(this, {
                hover: $option
            });
        });
    });
};
$.fn.jnet_shadow = function(option){
    obj = this;
    addScriptGlobal("liquid-canvas/liquid-canvas", function(){
        addScriptGlobal("liquid-canvas/liquid-canvas-plugins", function(){
            if (option == null) 
                option = new Array();
            var count = $(obj).length;
            if (count == 0) 
                return false;
            return $(obj).each(function(){
                $(this).readybrowser(function(){
                    var border_width = getNumberFromString($(this).css("border-left-width"));
                    var border_color = $(this).css("border-left-color");
                    var border_color = colorToHex(border_color);
                    if ($(this).css("background-color") != "transparent") {
                        var bk_color = colorToHex($(this).css("background-color"));
                    }
                    var radius = array_key_get("radius", option, $(this).attr("radius"));
                    if (radius != null) 
                        radius = " roundedRect{radius:" + radius + "} ";
                    var shadow = array_key_get("shadow", option, $(this).attr("shadow"));
                    if (shadow != null) 
                        shadow = " shadow{width:" + shadow['width'] + "; color:" + shadow['color'] + "; shift:" + shadow['shift'] + "} ";
                    else 
                        shadow = "";
                    var gradient = array_key_get("gradient", option, $(this).attr("gradient"));
                    if (gradient != null) 
                        gradient = " gradient{from:" + gradient['from'] + "; to:" + gradient['to'] + "} ";
                    else 
                        gradient = "";
                    if (border_width > 0) {
                        $(this).css("border", "0px");
                        var border = " border{width:" + border_width + ";color:" + border_color + "} "
                    }
                    else 
                        var border = "";
                    if (is_null(bk_color) == false) 
                        bk_color = " fill{color:" + bk_color + "} ";
                    if (is_null(bk_color) == true) 
                        bk_color = "";
                    if (is_null(radius) == true) 
                        radius = "";
                    if (is_null(border) == true) 
                        border = "";
                    if (is_null(shadow) == true) 
                        shadow = "";
                    if (is_null(gradient) == true) 
                        gradient = "";
                    var config = "[" + gradient + shadow + border + bk_color + "]=>" + radius + " ";
                    $(this).liquidCanvas(config);
                });
            });
        }, null, "$.registerLiquidCanvasPlugin");
    }, null, "$.fn.liquidCanvas");
};
$.fn.jnet_fixpng = function(callback){
    var obj = this;
    if (checkingIE() != 6) 
        return;
    addScriptGlobal("iepngfix", function(){
        return obj.each(function(){
            DD_belatedPNG.fixPng(this);
        });
    }, null, "window.DD_belatedPNG");
};
$.fn.jnet_round = function(roundenumber, type){
    var obj = this;
    if (type == null) 
        type = "DD_roundies";
    switch (type) {
        case "curvycorners":
        addScriptGlobal("curvycorners", function(){
            roundenumbertl = roundenumbertr = roundenumberbl = roundenumberbr = roundenumber;
            if (isNaN(roundenumber) == true) {
                var asplit = roundenumber.split(";");
                roundenumbertl = asplit[0];
                roundenumbertr = asplit[1];
                roundenumberbl = asplit[2];
                roundenumberbr = asplit[3];
            };
            $(selector).curvy({
                tl: {
                    radius: roundenumbertl
                },
                tr: {
                    radius: roundenumbertr
                },
                bl: {
                    radius: roundenumberbl
                },
                br: {
                    radius: roundenumberbr
                },
                antiAlias: true,
                autoPad: false
            });
        });
        break;
        case "corner":
            $(selector).corner(roundenumber);
            break;
        case "DD_roundies":
        addScriptGlobal("DD_roundies", function(){
            return DD_roundies.addRule(obj.selector, roundenumber, true);
            var func = function(){
                DD_roundies.addRule(obj.selector, roundenumber, true);
            };
            var intval = setInterval(function(){
                if (is_null(window.DD_roundies) == false) {
                    clearInterval(intval);
                    func.apply();
                }
            }, 100);
        }, null, "window.DD_roundies");
        break;
    }
};
$.fn.jnet_tablesort = function(){
    var obj = this;
    if ($(this).html() == null) 
        return false;
    addScriptGlobal("jquery.tablednd_0_5", function(){
        return obj.each(function(){
            $(this).tableDnD();
            $("tbody tr", this).hover(function(){
                $(this.cells[0]).addClass('showDragHandle');
            }, function(){
                $(this.cells[0]).removeClass('showDragHandle');
            });
        });
    }, null, "$.fn.tableDnD");
    if ($(".listcategory ul", this).html() == null) {
        return false;
    }
    addScriptGlobal("jquery.dragsort-0.3.9", function(){
        return obj.each(function(){
            $(".listcategory ul", this).dragsort();
        });
    }, null, "$.fn.dragsort");
};
$.fn.jnet_menuleft = function(typeevent, opts){
    var $options = {
        timer: 100,
        click: false
    };
    $options = array_copy(opts, $options);
    if (typeevent == "hover") {
        $("li", this).hover(function(){
            var li = this;
            var ul = $("ul", li);
            if (ul.length == 0) 
                return;
            ul.show($options['hover']);
        }, function(){
            var li = this;
            var ul = $("ul");
            if (ul.length == 0) 
                return;
            ul.hide($options['hover']);
        });
    }
    if (typeevent == "click") {
        $("a", this).click(function(){
            var li = $(this).parent();
            var ul = $("ul", li);
            if (ul.length == 0) 
                return;
            $(li).not(this).siblings().each(function(){
                $("ul", this).slideUp();
            });
            ul.slideToggle();
            return false;
        });
    }
};
$.fn.jnet_ajaxmenuleft = function(opts){
    var $options = {
        ajaxhavechild: true
    };
    $options = array_copy(opts, $options);
    $("a", this).click(function(){
        var li = $(this).parent();
        var ul = $("ul", li);
        if (ul.html() != null && $options["ajaxhavechild"] == false) 
            return false;
        attackSubmitLink(this, {
            'ajax': 1
        });
        return false;
    })
};
$.fn.jnet_ajax_reload = function(func){
    var obj = this;
    var link = $(this).attr("href");
    attackSubmitLink(link, {
        'display': 'none'
    }, function(){
        if (func == null) 
            window.location.reload(true);
        else 
            func(obj);
    });
    return false;
};
$.jnet_ajax_reload_link = function(href, func){
    var a = $("<a></a>");
    $(a).attr("href", href);
    $(a).jnet_ajax_reload(func);
};
$.fn.jnet_attacksubmitlink = function(opts){
    return attackSubmitLink(this, opts);
};
$.fn.jnet_highslide = function(func, opts){
    var obj = this;
    addCss(template_global + "js/highslide/highslide/highslide", function(){
        addScriptGlobal("highslide/highslide/highslide-full", function(){
            var $options = {
                graphicsDir: site_url + 'templates/global/js/highslide/highslide/graphics/',
                align: 'center',
                transitions: ['expand', 'crossfade'],
                wrapperClassName: 'dark borderless floating-caption',
                outlineType: 'rounded-white',
                wrapperClassName: 'dark',
                fadeInOut: true,
                dimmingOpacity: 0.85
            };
            $options = array_copy(opts, $options);
            for ($key in $options) {
                hs[$key] = $options[$key];
            };
            obj.each(function(){
                if (func != null) 
                    func.apply(this);
            });
            return false;
        });
    });
    return false;
};
$.fn.jnet_highslide_expand = function(opts){
    $(this).jnet_highslide(function(){
        hs.expand(this);
    }, opts);
    return false;
};
$.fn.jnet_highslide_expandhtml = function(opts){
    $(this).jnet_highslide(function(){
        hs.htmlExpand(this, {
            objectType: 'iframe'
        });
    }, opts);
    return false;
};
$.fn.tablediv = function(opts){
    selector = this;
    $(selector).each(function(){
        var col = 0;
        var temp = 0;
        var max = 0;
        $(this).children().each(function(){
            temp = temp + 1;
            if (temp > col) 
                col = temp;
        });
        for (var i = 0; i < col; i++) {
            var max = 0;
            var td = ".td" + i;
            $(td, selector).each(function(){
                var width = $(this).width();
                if (width > max) 
                    max = width;
            });
            $(td, selector).width(max);
        }
        $(this).children().each(function(){
            var width = $(this).width();
            if (width > max) 
                max = width;
        });
        $(this).children().width(max);
    });
};
$.fn.jnet_addhistory = function(func, params){
    var obj = this;
    if (window.myhistory == null) 
        window.myhistory = new Array();
    $std = new stdClass();
    $std["func"] = func;
    $std["params"] = params;
    $std['obj'] = this;
    link = window.myhistory.length;
    window.myhistory[window.myhistory.length] = $std;
    var callback = function(){
        $.history.load(link, function(){
            func.apply(obj);
        });
    };
    if ($.history == null) {
        addScriptGlobal("jquery.history", function(){
            callback.apply();
        });
    }
    else 
        callback.apply();
};
$.jnet_geturlcontent = function($url, func, opts){
    var $options = {
        proxy: true
    };
    $options = array_copy(opts, $options);
    if ($options['proxy'] == true) {
        $url = site_url + "proxy.php?" + $url;
        $.ajax({
            url: $url,
            success: function(data){
                func(data);
            }
        });
    }
    else {
        request = new CrossXHR();
        request.onreadystatechange = function(request){
            if (request.readyState == 4 && request.status == 200) {
                func(request.responseText);
            }
        };
        request.open('GET', $url);
        request.send();
    }
};
$.fn.jnet_checkonline = function(){
    return $("img", this).each(function(){
        var obj = this;
        var nickname = $(this).attr("nickname");
        var online = $(this).attr("online");
        var offline = $(this).attr("offline");
        var type = $(this).attr("type");
        var func = function(status){
            if (status == 1) {
                $(obj).attr("src", site_url + "data/supportonline/offline/" + offline);
            }
            else {
                $(obj).attr("src", site_url + "data/supportonline/online/" + online);
                $(obj).parent().addClass("online");
                $(obj).jnet_fixpng();
            }
        };
        if (type == "@yahoo.com") {
            checkOnlineYahoo(nickname, func);
        }
        if (type == "@sky.com") {
            checkOnlineSkype(nickname, func);
        }
    });
};
$.fn.jnet_captcha_refresh = function(){
    var img = $("img", $(this).parent());
    var captcha_img = $(img).parent();
    var $opt = {
        'display': captcha_img
    };
    $(this).jnet_attacksubmitlink($opt);
    return false;
};
$.jnet_hotkey = function(key, func){
    addScriptGlobal("jquery.hotkeys", function(){
        $(document).bind('keydown', key, func);
    });
};
$.fn.jnet_smarttab = function($option){
    var obj = this;
    addScriptGlobal("jquery.smartTab", function(){
        $(obj).smartTab($option);
    }, null, "$.fn.smartTab");
};
$.fn.jnet_loadmodule = function(options){
    var id = $(this).attr("id");
    var len = new String("moduletable_").length;
    var key = id.substr(len);
    var href = site_url + "getajax/module/" + key;
    $(options).foreach(function(key, value){
        href = href + "/" + key + "/" + value;
    });
    $(this).attr("href", href);
    var $opt = {
        "display": this,
        'typedisplay': 'replace'
    };
    $(this).jnet_attacksubmitlink($opt);
    return false;
};
function loadModule(id, $method){
    $obj = id;
    if (is_string(id) == true) 
        $obj = "#" + id;
    if ($method != null) {
        var location = window.location.href;
        var lenstart = new String("moduletable_").length;
        var key = $($obj).attr("id").substr(lenstart);
        $option = {
            "display": $obj,
            'typedisplay': 'replace',
            'load_single_module': key
        };
        attackSubmitLink(location, $option);
        return false;
    }
    return $($obj).jnet_loadmodule($method);
}

function showvideo($id){
    href = addAjaxHighslide(site_url + "showvideo/show/");
    href = href + "id/" + $id;
    $(document).jnet_highslide(function(){
        hs.preserveContent = false;
        hs.objectStyle = "overflow:hidden";
        var linkhighslide = $("<a  onclick=\" return hs.htmlExpand(this, { objectType: 'iframe' } )  \"  href='" + href + "' ></a>");
        $(linkhighslide).click();
    });
    return false;
}

function checkOnlineYahoo($nickname, $func){
    var $url = "http://opi.yahoo.com/online?u=" + $nickname + "&m=t";
    $.jnet_geturlcontent($url, function($data){
        $status = 1;
        if ($data.lastIndexOf('NOT ONLINE') != -1) {
            $status = 1;
        }
        if ($data.lastIndexOf('is ONLINE') != -1) {
            $status = 2;
        }
        if ($func != null) 
            $func($status);
    });
}

function checkOnlineSkype($nickname, $func){
    var $url = "http://mystatus.skype.com/" + $nickname + ".num";
    $.jnet_geturlcontent($url, function($data){
        if ($data == 0 || $data == 1) 
            $data == 1;
        if ($func != null) 
            $func($data);
    });
}

function clearCache(){
    $.jnet_hotkey("Ctrl+c", function(){
        if ($.jnet_hotkey.clearCache == true) {
            return;
        }
        $.jnet_hotkey.clearCache = true;
        var link = site_url + "getajax/clearcache";
        $.jnet_ajax_reload_link(link, function(){
            $.jnet_hotkey.clearCache = false;
        });
    })
}

function configModule(){
    $.jnet_hotkey("Shift+f12+e", function(){
        if ($.jnet_hotkey.module_registeredit == true) {
            return;
        }
        $.jnet_hotkey.module_registeredit = true;
        var link = site_url + "getajax/module_registeredit/1";
        $.jnet_ajax_reload_link(link, function(){
            $.jnet_hotkey.module_registeredit = false;
        });
    });
    $.jnet_hotkey("Ctrl+Shift+d", function(){
        if ($.jnet_hotkey.module_unregisteredit == true) {
            return;
        }
        $.jnet_hotkey.module_unregisteredit = true;
        var link = site_url + "getajax/module_registeredit/0";
        $.jnet_ajax_reload_link(link, function(){
            $.jnet_hotkey.module_unregisteredit = false;
        });
    });
}

function attackModule(){
    configModule();
    clearCache();
}

function configModuleAttack(){
    addScriptGlobal("jquery.rightClick", function(){
        $(".moduletable_super").each(function(){
            var lenstart = new String("moduletable_").length;
            var key = $(this).attr("id").substr(lenstart);
            var moduletable = $("div", this)[0];
            $(moduletable).rightClick(function(){
                var href = site_url + "getajax/module_edit/" + key;
                var a = $("<a></a>")[0];
                a.href = href;
                ajaxHighslide(a);
            });
        });
    }, null, "$.fn.rightClick");
}

$.fn.foreach = function(func){
    var obj = this[0];
    if (is_array(obj) == true) {
        $(obj).each(function($key, $value){
            func.apply($key, $value);
        });
    }
    if (is_object(obj) == true) {
        for (var $key in obj) {
            func($key, obj[$key]);
        }
    }
};
function array_key_set(obj, $name, $value){
    obj[$name] = $value;
}

function array_key_get($keysearch, $array, $defaultvalue){
    $($array).foreach(function($key, $value){
        if ($key == $keysearch) 
            $defaultvalue = $value;
    });
    return $defaultvalue;
}

function array_key_exist($keysearch, $array){
    $($array).foreach(function($key, $value){
        if ($key == $keysearch) 
            return true;
    });
    return false;
}

function loadGoogleMap(){
    $(".googlemap").each(function(){
        if ($(this).attr('attackgooglemap') == 1) 
            return;
    })
}

function exec_module_reload($obj, $id, $method){
    $.jnet_ajax(function(){
        ajaxlink($obj, 1, function(){
            loadModule($id, $method);
        })
    });
    return false;
}

function pleaselogin(){
    var $please_login = $lang["pleaseplogin"];
    $result = confirm($please_login);
    if ($result == true) 
        window.location.href = site_url + "Dang-nhap.html";
    return false;
}

function module_pagenation_ajax(id, options){

    if(options==null)
        options=stdClass();
    $("#" + id + " .pagenation a").click(function(){

        var limitstart = $(this).attr("limitstart");
        var opts = {
            limitstart: limitstart
        };
        options = array_copy(opts, options);


        $("#" + id).jnet_loadmodule(options);
        return false;
    })
}
function clipboard(container,text,callback)
{
    addScriptGlobal("jquery.zclip", function()
    {
        ZeroClipboard.setMoviePath(site_url+"templates/global/js/ZeroClipboard.swf" );  
        clip = new ZeroClipboard.Client();  
        clip.setHandCursor( true ); 
        clip.setText(text);
        clip.glue($(container)[0],$("body")[0]);
        clip.addEventListener('complete', function (client, text) {
            if(callback!=null)
                callback.apply($(container),[clip]);
        });

        $("body").jnet_resize(function(){
            clip.reposition();   
            var offset=$(".clipboard").offset();
            $("#zclip-ZeroClipboardMovie_1").css("left",offset.left);

        });
        var offset=$(".clipboard").offset();
        $("#zclip-ZeroClipboardMovie_1").css("left",offset.left);

    },null,"$.fn.zclip");

}
