$(document).ajaxError(function(a, b, c, d) {
    alert(c.url + " returned error:\n" + d)
    });
$.createElement = function(a) {
    return jQuery(document.createElement(a))
    };
function nl2br(a) {
    return a.replace(/(\\r)?\\n/g, "<br />")
    }
function is_empty(a) {
    for (i in a)
        return false;
    return true
}
function nohtml(a) {
    a = a.replace(/"/g, "&quot;");
    a = a.replace(/</g, "&lt;");
    return a = a.replace(/>/g, "&gt;")
    }
function my_url(a) {
    return a = a.replace(/\|/g, "&")
    }
function field_number(a) {
    return parseInt(a.replace(/[^0-9]/g, ""))
    }
function field_number2(a) {
    return a.replace(/[^0-9\.]/g, "")
    }
function field_text(a) {
    return a.replace(/[0-9]/g, "")
    }
function check_all(a) {
    a = $(a);
    var b = $(a).is(":checked");
    a.closest("form").find("input[type='checkbox']").each(function() {
        $(this).attr("checked", b)
        })
    }
function confirm_delete() {
    return confirm(lang.sure_delete) ? true: false
}
   var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

   function encode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;

         if (isNaN(chr2)) {
            enc3 = enc4 = 64;
         } else if (isNaN(chr3)) {
            enc4 = 64;
         }

         output = output +
            keyStr.charAt(enc1) +
            keyStr.charAt(enc2) +
            keyStr.charAt(enc3) +
            keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
   }

   function decode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
      if (base64test.exec(input)) {
         alert("There were invalid base64 characters in the input text.");
      }
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
   }
var loader = {
    url: siteurl + "images/load.gif",
    replace: function(a) {
        if (typeof a == "string")
            a = $("#" + a);
        else
            a.jQuery || (a = $(a));
        var b = (a.height() - 16) / 2;
        if (b < 0)
            b = 0;
        a.html('<div class="center"><img src="' + loader.url + '" style="width: 16px; height:16px; margin: ' + b + 'px 0px;" /></div>')
        },
    insert: function(a) {
        if (typeof a == "string")
            a = $("#" + a);
        var b = a.next();
        b.size() > 0 && b.hasClass("loader") ? b.show() : $.createElement("img").attr("src", loader.url).addClass("loader").insertAfter(a);
        a.get(0).nodeName.toLowerCase() == "input" && a.attr("disabled", true)
        },
    remove: function(a) {
        if (typeof a == "string")
            a = $("#" + a);
        var b = a.next();
        b.size() > 0 && b.hasClass("loader") && b.hide();
        a.get(0).nodeName.toLowerCase() == "input" && a.attr("disabled", false)
        }
},
error = {
    insert: function(a, b, c) {
        if (typeof b == "string")
            b = $("#" + b);
        if (c == undefined)
            c = [];
        if (c.after) {
            if (b.next().size() > 0 && (b.next().hasClass("error") || b.next().hasClass("error_green")))
                var d = b.next()
            } else if (b.prev().size() > 0 && (b.prev().hasClass("error") || b.prev().hasClass("error_green")))
            d = b.prev();
        if (d == undefined) {
            d = $.createElement("div");
            c.after ? d.insertAfter(b) : d.insertBefore(b)
            }
        d.attr("class", c.error == false ? "error_green": "error");
        d.text(a);
        d.hide();
        d.slideDown(250);
        c.error == false && c.hide && d.delay(1E3 * c.hide).slideUp(250)
        }
},
url_hash = {
    set_hash: function(a, b) {
        var c = "" + location.hash;
        if (c.length == 0 || c == "#")
            location.hash = a + "/" + b;
        else {
            var d = c.match(RegExp("(#|^|/)" + a + "/[0-9]+"));
            if (d != null)
                location.hash = c.replace("" + d[0], "" + d[1] + a + "/" + b);
            else
                location.hash += "/" + a + "/" + b
        }
    },
    get_hash: function(a) {
        a = ("" + location.hash).match(RegExp("(#|^|/)" + a + "/([0-9]+)"));
        return a == null ? null: parseInt(a[2])
        }
},
image_verification = {
    image_url: siteurl + "includes/verification_image.php",
    refresh_image: siteurl + "images/reload.png",
    refresh: function() {
        $(this).prev().attr("src", image_verification.image_url + "?" + Math.random())
        },
    attach: function(a) {
        a = $("#" + a);
        if (a.size() != 0)
            if (a.children("div.image_verification").size() > 0)
            a.find("img.refresh_image").click();
        else {
            var b = $.createElement("div").addClass("image_verification");
            $.createElement("img").attr("src", image_verification.image_url).addClass("code_image").appendTo(b);
            $.createElement("img").attr("src", image_verification.refresh_image).addClass("refresh_image").appendTo(b).click(image_verification.refresh);
            $.createElement("input").attr({
                type: "text",
                maxlength: 4,
                name: "image_verification",
                id: "image_verification_id"
            }).addClass("small").appendTo(b);
            a.append(b)
            }
    }
},
favourites_menu = {
    link: null,
    menu: null,
    content: null,
    loaded: false,
    create: function() {
        favourites_menu.menu = $.createElement("div").addClass("bubble").width("150px").attr("id", "favourites_menu");
        favourites_menu.content = $.createElement("div").appendTo(favourites_menu.menu);
        $.createElement("div").addClass("bubble_up").appendTo(favourites_menu.menu);
        $(document.body).append(favourites_menu.menu)
        },
    load: function() {
        $.getJSON(siteurl + "usercp.php?a=get_favourites&ajax=1", function(a) {
            favourites_menu.content.empty();
            var b;
            for (i in a) {
                b = $.createElement("p");
                b.html("<a href=\""+ a[i].url +"\">"+ a[i].title +"</a>");
                b.appendTo(favourites_menu.content)
                }
            favourites_menu.loaded = true
        })
        },
    open: function() {
        favourites_menu.menu == null && favourites_menu.create();
        favourites_menu.menu.show();
        var a = favourites_menu.link.offset();
        favourites_menu.menu.css({
            left: a.left + "px",
            top: a.top + 24 + "px"
        });
        $(document).bind("click", favourites_menu.close);
        favourites_menu.menu.click(function(b) {
            b.stopPropagation()
            });
        if (favourites_menu.loaded == false) {
            loader.replace(favourites_menu.content);
            favourites_menu.load()
            }
    },
    close: function() {
        $("#favourites_menu").hide();
        $(document).unbind("click", favourites_menu.close)
        },
    init: function() {
        favourites_menu.link = $("#favourites_link");
        favourites_menu.link.click(function(a) {
            favourites_menu.open();
            a.stopPropagation();
            return false
        })
        }
};
$(document).ready(favourites_menu.init);
$(document).ready(function()
{
	var ajax_url = window.location.href;
	var c_url = ajax_url.split("#");
	if(c_url[1] && c_url[1].indexOf("_tabs") == -1){
		c_url[1] = decode64(c_url[1]);
		var c_url = c_url[1].split("___");
		var url_load_ajax = c_url[0];
		var id_load_ajax = c_url[1];
		if(url_load_ajax && id_load_ajax){
			if(url_load_ajax.indexOf(siteurl) != -1 && $("#" + id_load_ajax)){
				load_ajax(id_load_ajax, encode64(url_load_ajax));
				if(url_load_ajax.indexOf("file.php?a=comments") != -1){
					setTimeout("comments.attach()", 1000);
				}
				if(url_load_ajax.indexOf("profile.php?a=comments") != -1){
			        setTimeout('$("#comments .click").click(function() {fast_edit.change($(this), "text", "tab=profile_comments&id_field=comment_id&cos=comment&nohtml=1&id", "tab=profile_comments&id_field=comment_id&cos=comment&id", 170, 100, null);})', 1000);
			    }

			}
		}
	}
    $("#cal_rate").submit(function() {
        cal_rate($(this));
        return false
    });
});
function tab_menu(a, b) {
    this.tabs_id = a;
    this.contents_id = b;
    this.tab = [];
    this.content = [];
    this.tab_functions = [];
    this.initiating = false;
    this.get_content = function(c) {
        return this.content.eq(c)
        };
    this.get_tab = function(c) {
        return this.tab.eq(c)
        };
    this.click_tab = function(c) {
        var d = parseInt(c.data("id"));
        this.tab.removeClass("selected");
        c.addClass("selected");
        this.content.hide();
        this.content.eq(d).show();
        this.content.eq(d).children(".error,.error_green").hide();
        if (url_hash.get_hash(this.tabs_id) != null || d > 0)
            url_hash.set_hash(this.tabs_id, d + 1);
        if (this.tab_functions[d] != undefined)
            for (i in this.tab_functions[d])
            this.tab_functions[d][i]()
        };
    this.add_action = function(c, d) {
        if (this.tab_functions[c] != undefined)
            this.tab_functions[c].push(d);
        else
            this.tab_functions[c] = [d]
        };
    this.init = function() {
        var c = this;
        this.ul = $("#" + this.tabs_id);
        this.div = this.contents_id == undefined ? this.ul.nextAll("div:first") : $("#" + this.contents_id);
        this.tab = this.ul.find("li>a");
        this.content = this.div.children("div").hide();
        if (this.tab.size() != this.content.size())
            window.alert("ERROR! Tabs and contents not equal.");
        else {
            this.tab.each(function(g) {
                $(this).data("id", g).click(function(j, f) {
                    c.initiation = f != undefined && f == true;
                    c.initiating = f != undefined && f == true;
                    c.click_tab($(this));
                    return false
                })
                });
            var d = 0,
            e = url_hash.get_hash(this.tabs_id);
            if (e != null) {
                e--;
                if (e < this.tab.size())
                    d = e
            }
            this.tab.eq(d).trigger("click", [true])
            }
    }
}
var scroller = {
    files: [],
    width: 70,
    height: 59,
    size: 0,
    moving: false,
    scroller: null,
    scroller_width: 0,
    ul: null,
    ul_width: 0,
    title: null,
    active: null,
    interval: null,
    current_offset: 0,
    goal_offset: 0,
    show_title: function(a) {
        if (scroller.title == null)
            scroller.title = $.createElement("div").addClass("title").click(function() {
            scroller.active.click()
            }).appendTo(scroller.scroller);
        scroller.title.show();
        scroller.active = $(this);
        scroller.title.text(scroller.active.attr("alt"));
        a = a.pageX - scroller.scroller.offset().left - scroller.title.width() / 2;
        if (a < 0)
            a = 0;
        scroller.title.css("left", a + "px")
        },
    hide_title: function() {
        scroller.title.hide()
        },
    mouse_move: function(a) {
        a = a.pageX - scroller.scroller.offset().left;
        scroller.goal_offset = a * ((scroller.ul_width - scroller.scroller_width) / scroller.scroller_width);
        scroller.moving || scroller.start_move()
        },
    go_to: function(a) {
        window.location = a.data
    },
    build_list: function() {
        scroller.ul = $.createElement("ul");
        var a;
        for (i in scroller.files) {
            a = $.createElement("li");
            $.createElement("img").attr("src", scroller.files[i][2]).width(scroller.width).height(scroller.height).attr("alt", scroller.files[i][0]).mouseenter(scroller.show_title).bind("click", scroller.files[i][1], scroller.go_to).appendTo(a);
            a.appendTo(scroller.ul)
            }
        scroller.ul.appendTo(scroller.scroller);
        scroller.scroller_width = scroller.scroller.width();
        scroller.ul_width = a.outerWidth() * scroller.size;
        scroller.ul.width(scroller.ul_width);
        scroller.scroller.mouseleave(scroller.hide_title).mousemove(scroller.mouse_move)
        },
    start_move: function() {
        scroller.interval = setInterval(scroller.move, 10);
        scroller.moving = true
    },
    stop_move: function() {
        clearInterval(scroller.interval);
        scroller.moving = false
    },
    move: function() {
        if (scroller.current_offset != scroller.goal_offset) {
            var a = scroller.goal_offset - scroller.current_offset,
            b = a / 25;
            if (a > 0) {
                if (b < 1)
                    b = 1;
                scroller.current_offset += b;
                if (scroller.current_offset > scroller.goal_offset) {
                    scroller.current_offset = scroller.goal_offset;
                    scroller.stop_move()
                    }
            } else {
                if (b > -1)
                    b = -1;
                scroller.current_offset += b;
                if (scroller.current_offset < scroller.goal_offset) {
                    scroller.current_offset = scroller.goal_offset;
                    scroller.stop_move()
                    }
            }
            scroller.ul.css("left", "-" + scroller.current_offset + "px")
            }
    },
    init: function(a, b) {
        if (scroller.files.length != 0) {
            scroller.scroller = $("#scroller");
            scroller.width = a;
            scroller.height = b;
            scroller.size = this.files.length;
            scroller.build_list()
            }
    }
};
function link_out(a) {
    window.open(siteurl + "/links.php?a=out&id=" + a);
    return false
}
var rate_file = {
    rating: 0,
    active: 0,
    file_id: 0,
    element: null,
    star: [],
    images: [],
    hover: function() {
        var a = $(this).data("star");
        for (i = 1; i <= a; i++)
            rate_file.star[i].attr("src", siteurl + "images/star_hover.png")
        },
    clear: function() {
        for (i = 1; i <= 5; i++)
            rate_file.star[i].attr("src", rate_file.images[i])
        },
    submit: function() {
        loader.insert(rate_file.star[5]);
        $.post(siteurl + "/file.php?f=" + rate_file.file_id + "&a=rate&ajax=1", {
            rating: $(this).data("star")
            }, function(a) {
            rate_file.rating = a.rating;
            rate_file.active = 0;
            rate_file.draw();
            rate_file.element.append("<span>" + a.message + "</span>")
            }, "json")
        },
    draw: function() {
        this.element.empty();
        var a;
        for (i = 1; i <= 5; i++) {
            this.star[i] = $.createElement("img").attr("title", this.rating + " / 5").data("star", i);
            if (i <= this.rating)
                this.star[i].attr("src", siteurl + "images/star.png");
            else {
                a = i - this.rating;
                a < 0.75 ? this.star[i].attr("src", siteurl + "images/star" + (a < 0.25 ? "": "_half") + ".png") : this.star[i].attr("src", siteurl + "images/star_empty.png")
                }
            if (this.active == 1) {
                this.images[i] = this.star[i].attr("src");
                this.star[i].css("cursor", "pointer").click(rate_file.submit).mouseover(rate_file.hover).mouseout(rate_file.clear)
                }
            this.star[i].appendTo(this.element)
            }
    },
    init: function(a) {
        this.element = $("#file_rating");
        this.file_id = a;
        this.draw(); (new Image).src = siteurl + "images/star_hover.png"
    }
};
var fast_rate = {
    rating: [],
    active: [],
    file_id: [],
    field_id: [],
    element: [],
    star: [],
    images: [],
    stars_count: [],
    submit_url: [],
    hover: function(select_rate, field_id) {
        var a = select_rate;
        for (i = 1; i <= a; i++)
            fast_rate.star[field_id][i].attr("src", siteurl + "images/star_hover.png")
        },
    clear: function(field_id) {
        for (i = 1; i <= fast_rate.stars_count[field_id]; i++)
            fast_rate.star[field_id][i].attr("src", fast_rate.images[field_id][i])
        },
    submit: function(select_rate, field_id) {
        loader.insert(fast_rate.star[field_id][fast_rate.stars_count[field_id]]);
        $.post(siteurl + fast_rate.submit_url[field_id] +"=" + fast_rate.file_id[field_id] + "&ajax=1", {
            rating: select_rate
            }, function(a) {
            fast_rate.rating[field_id] = a.rating;
            fast_rate.active[field_id] = 0;
            fast_rate.draw(fast_rate.file_id[field_id], fast_rate.field_id[field_id], fast_rate.stars_count[field_id], fast_rate.submit_url[field_id], fast_rate.active[field_id], fast_rate.rating[field_id]);
            fast_rate.element[field_id].append("<span>" + a.message + "</span>")
            }, "json")
        },
    draw: function(a, field_id, stars_count, submit_url, active, rating) {
        fast_rate.field_id[field_id] = [];
        fast_rate.field_id[field_id] = field_id;
        fast_rate.element[field_id] = [];
        fast_rate.element[field_id] = $("#"+ field_id);
        fast_rate.file_id[field_id] = [];
        fast_rate.file_id[field_id] = a;
        fast_rate.stars_count[field_id] = [];
        fast_rate.stars_count[field_id] = stars_count;
        fast_rate.submit_url[field_id] = [];
        fast_rate.submit_url[field_id] = my_url(submit_url);
        fast_rate.active[field_id] = [];
        fast_rate.active[field_id] = active;
        fast_rate.rating[field_id] = [];
        fast_rate.rating[field_id] = rating;
        fast_rate.element[field_id].empty();
        fast_rate.star[field_id] = [];
        fast_rate.images[field_id] = [];
        var a;
        for (i = 1; i <= fast_rate.stars_count[field_id]; i++) {
            fast_rate.star[field_id][i] = $.createElement("img").attr("title", fast_rate.rating[field_id] + " / "+ fast_rate.stars_count[field_id]).data("star", i);
            if (i <= fast_rate.rating[field_id])
                fast_rate.star[field_id][i].attr("src", siteurl + "images/star.png");
            else {
                a = i - fast_rate.rating[field_id];
                a < 0.75 ? fast_rate.star[field_id][i].attr("src", siteurl + "images/star" + (a < 0.25 ? "": "_half") + ".png") : fast_rate.star[field_id][i].attr("src", siteurl + "images/star_empty.png")
                }
            if (fast_rate.active[field_id] == 1) {
                fast_rate.images[field_id][i] = fast_rate.star[field_id][i].attr("src");
                fast_rate.star[field_id][i].css("cursor", "pointer").click(function(){fast_rate.submit($(this).data("star"), field_id)}).mouseover(function(){fast_rate.hover($(this).data("star"),field_id)}).mouseout(function(){fast_rate.clear(field_id)})
                }
            fast_rate.star[field_id][i].appendTo(fast_rate.element[field_id])
            }
    }
};
function make_favorite(a) {
    $.getJSON(siteurl + "file.php?a=make_favorite&f=" + a + "&ajax=1", function(b) {
        b.error || $("#make_favorite").attr("src", siteurl + "images/" + b.image + ".png")
        })
    }
function make_thank(a, parent, id) {
	var query;
	if(parent == "file" || parent == "file_hot" || parent == "file_unhot")
		query = "f";
	else
		query = "c";
    $.getJSON(siteurl + "file.php?a=make_thank&parent=" + parent + "&" + query + "=" + a + "&ajax=1", function(b) {
        if (b.error)
            alert(b.message);
        else {
        	$("#" + id).attr("src", siteurl + "images/" + b.image);
        	if(parent == "file") {
        		if(b.image == "remove_thank.gif")
	       			document.getElementById("count_thank_" + a).innerHTML++;
	       		else
	       			document.getElementById("count_thank_" + a).innerHTML--;
	       		$("#thankers_box").show();
	        	$("#content_thanker_box").html(b.content);
	        } else if(parent == "file_hot" || parent == "cm_like") {
        		if(b.image == "remove_like.jpg")
	       			document.getElementById((parent == "file_hot" ? "count_hot_" : "count_like_") + a).innerHTML++;
	       		else
	       			document.getElementById((parent == "file_hot" ? "count_hot_" : "count_like_") + a).innerHTML--;
	        } else if(parent == "file_unhot" || parent == "cm_dislike") {
        		if(b.image == "remove_dislike.png")
	       			document.getElementById((parent == "file_unhot" ? "count_unhot_" : "count_dislike_") + a).innerHTML++;
	       		else
	       			document.getElementById((parent == "file_unhot" ? "count_unhot_" : "count_dislike_") + a).innerHTML--;
	        }
        }
        })
    }
function add_subscribe(parent, id, id_field) {
    $.getJSON(siteurl + "file.php?a=make_subscribe&parent=" + parent + "&id=" + id + "&ajax=1", function(b) {
        if (b.error)
            alert(b.message);
        else {
        	$("#"+id_field).attr("src", siteurl + "images/" + b.image);
        }
        })
    }
function add_promote(parent, id, id_field) {
    $.getJSON(siteurl + "file.php?a=make_promote&parent=" + parent + "&id=" + id + "&ajax=1", function(b) {
        if (b.error)
            alert(b.message);
        else {
        	$("#"+id_field).attr("src", siteurl + "images/" + b.image);
        	if(b.image == 'unpromote.gif'){
				var c = $.createElement("div").attr("class", "ad_box promote_id").html(lang.link_promote +": <input type=\"text\" value=\""+ b.link +"\" onfocus=\"this.select();\" />");
				c.insertBefore($("#file_tabs"));
        	}else
        		$(".promote_id").slideUp();
        }
        })
    }
var full_screen = {
    real_width: 0,
    real_height: 0,
    file: null,
    overlay: null,
    button: null,
    iframes: null,
    open: function() {
        full_screen.file.parent().css("height", full_screen.file.parent().height() + "px");
        full_screen.iframes = $("iframe:visible").hide();
        var a = full_screen.file.position();
        full_screen.file.css({
            position: "absolute",
            top: a.top + "px",
            left: a.left + "px"
        });
        var b = $(window).scrollTop(),
        c = full_screen.file.offset(),
        d = $(window).width(),
        e = $(window).height(),
        g = d - 30,
        j = g / full_screen.real_width,
        f = full_screen.real_height * j;
        if (f > e) {
            f = e - 30;
            j = f / full_screen.real_height;
            g = full_screen.real_width * j
        }
        full_screen.file.animate({
            top: a.top - c.top + (e - f) / 2 + b,
            left: a.left - c.left + (d - g) / 2,
            width: g,
            height: f
        }, 1E3);
        $(document).click(full_screen.close);
        full_screen.file.click(function(h) {
            h.stopPropagation()
            });
        if (full_screen.overlay == null) {
            a = $(document).height();
            full_screen.overlay = $.createElement("div").attr("id", "resize_overlay").width(d).height(a > e ? a: e).insertBefore(document.body.firstChild)
            } else
            full_screen.overlay.show()
        },
    close: function() {
        full_screen.file.stop();
        full_screen.overlay.hide();
        full_screen.file.css("position", "static").width(full_screen.real_width).height(full_screen.real_height);
        $(document).unbind("click", full_screen.close);
        full_screen.iframes.show()
        },
    init: function() {
        full_screen.file = $("#resize_file");
        if (full_screen.file.size() != 0) {
            full_screen.real_width = this.file.width();
            full_screen.real_height = this.file.height();
            full_screen.button = $("#full_screen").show().click(function() {
                full_screen.open();
                return false
            })
            }
    }
};
function submit_tell_friend(a, b) {
    var c = a.find("input:submit");
    loader.insert(c);
    $.post(siteurl + "file.php?a=tell_friend&f=" + b + "&ajax=1", a.serializeArray(), function(d) {
        loader.remove(c);
        error.insert(d.message, a, {
            hide: 3,
            error: d.error
        });
        if (!d.error) {
            a.find("input:text").val("");
            image_verification.attach("tell_image_verification")
            }
    }, "json")
    }
function submit_report_broken(a, b) {
    var c = a.find("input:submit");
    loader.insert(c);
    $.post(siteurl + "file.php?a=report_broken&f=" + b + "&ajax=1", a.serializeArray(), function(d) {
        loader.remove(c);
        error.insert(d.message, a, {
            error: d.error
        });
        d.error || a.delay(250).slideUp()
        }, "json")
    }
function cal_rate(a) {
    var c = a.find("input:submit");
    $("#result_cal").load(siteurl + "index.php?a=cal_rate&ajax=1", a.serializeArray())
    }
var preloader = {
    time: 10,
    ad: null,
    file: null,
    loader: null,
    hide: function(a) {
        a == true && preloader.loader.children("div").stop();
        preloader.ad.slideUp();
        preloader.file.slideDown();
        full_screen.button != null && full_screen.button.show()
        },
    init: function() {
        this.ad = $("#file_ad_box");
        if (this.ad.size() != 0) {
            this.loader = $("#ad_loader");
            this.file = $("#file_box").hide();
            full_screen.button != null && full_screen.button.hide();
            $("#no_wait").children("a").click(function() {
                preloader.hide(true);
                return false
            });
            this.loader.children("div").animate({
                width: "100%"
            }, this.time * 1E3, "linear", preloader.hide)
            }
    }
};
function init_file_info(a) {
    $(".content_file .click").click(function() {
        fast_edit.change($(this), "content_file", "tab=customcodes&id_field=fileid&cos=customcode&id", "tab=customcodes&id_field=fileid&cos=customcode&id", 550, 500, "rte");
        });
    $(".title_file .click").click(function() {
        fast_edit.change($(this), "title_file", "tab=files&id_field=fileid&cos=title&id", "tab=files&id_field=fileid&cos=title&nohtml=1&id", 500, 30, "text");
        });
    $(".description_file .click").click(function() {
        fast_edit.change($(this), "description_file", "tab=files&id_field=fileid&cos=description&id", "tab=files&id_field=fileid&cos=description&nohtml=1&id", 500, 30, null);
        });
    $(".keyword_file .click").click(function() {
        fast_edit.change($(this), "keyword_file", "tab=files&id_field=fileid&cos=keywords&id", "tab=files&id_field=fileid&cos=keywords&nohtml=1&id", 500, 30, "text");
        });
    $(".submit_comment .click_reply").click(function() {
        fast_edit.change($(this), "submit_comment", "tab=submit_comment&id", "tab=submit_comment&id", 550, 500, "rte");
       	$("#submit_comment_form").show();
        image_verification.attach("comment_verification_field");
        });
    $("#make_favorite").click(function() {
        make_favorite(a);
        return false
    });
    $("#make_thank").click(function() {
        make_thank(a, "file", "make_thank");
        return false
    });
    $("#make_hot").click(function() {
        make_thank(a, "file_hot", "make_hot");
        return false
    });
    $("#make_unhot").click(function() {
        make_thank(a, "file_unhot", "make_unhot");
        return false
    });
    fast_load_bubble.init("users_make_hot", "users_make_hot_id", "index.php?a=json_data_cached_2&content=dXNlci1fXy11c2VyLV9fLXVzZXJpZC1fXy0wLV9fLTEtX18tcHJvZmlsZXVybC1fX19fLTAtX19fXy0tX19fXy0wLV9fX18tPHNwYW4gY2xhc3M9InRodW1ibmFpbCI%2BPGEgaHJlZj0iLV9fX18tIj4tX19fXy0wLV9fXy1hdmF0YXJfdXJsLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy08aW1nIHNyYz0iLV9fX18tIiB3aWR0aD0iMzAiIGhlaWdodD0iMzAiLV9fX18tMS1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gYWx0PSItX19fXy0iLV9fX18tMi1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gdGl0bGU9Ii1fX19fLSIgLz48L2E%2BPC9zcGFuPi1fX19fLTMtX19fLXByb2ZpbGV1cmwtX19fXy0wLV9fX18tLV9fX18tMC1fX19fLTxhIGhyZWY9Ii1fX19fLSI%2BLV9fX18tNC1fX18tZnVsbF9uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0tX19fXy08L2E%2BLV9fX18tNS1fLXRoYW5rLV9fLXRoYW5rLV9fLWlkLV9fLTAtX18tMS1fXy10aGFua2VkX29uLV9fX18tMC1fX19fLWZvcm1hdF9kYXRlLV9fX18tNC1fX19fLTxiciAvPi1fX19fLTxkaXYgY2xhc3M9InNlcGFyYXRvciI%2BPC9kaXY%2BLV9fX18tNg%3D%3D&query=dXMudXNlcmlkLCB0aC5pZCBGUk9NIG9uX3RoYW5rcyBBUyB0aCBMRUZUIEpPSU4gb25fdXNlcnMgQVMgdXMgT04odXMudXNlcmlkID0gdGgudXNlcmlkKSBXSEVSRSB0aC5wYXJlbnRfaWQgPSAnZmlsZV9ob3RfcmVwbGFjZV9tZV8wXycgT1JERVIgQlkgdGgudGhhbmtlZF9vbiBERVND&load_ajax=1&id=users_make_hot_id&other=_"+ a +"&b=5&show_nav=1", null, 300, null, null, null);
	fast_load_bubble.init("users_make_unhot", "users_make_unhot_id", "index.php?a=json_data_cached_2&content=dXNlci1fXy11c2VyLV9fLXVzZXJpZC1fXy0wLV9fLTEtX18tcHJvZmlsZXVybC1fX19fLTAtX19fXy0tX19fXy0wLV9fX18tPHNwYW4gY2xhc3M9InRodW1ibmFpbCI%2BPGEgaHJlZj0iLV9fX18tIj4tX19fXy0wLV9fXy1hdmF0YXJfdXJsLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy08aW1nIHNyYz0iLV9fX18tIiB3aWR0aD0iMzAiIGhlaWdodD0iMzAiLV9fX18tMS1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gYWx0PSItX19fXy0iLV9fX18tMi1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gdGl0bGU9Ii1fX19fLSIgLz48L2E%2BPC9zcGFuPi1fX19fLTMtX19fLXByb2ZpbGV1cmwtX19fXy0wLV9fX18tLV9fX18tMC1fX19fLTxhIGhyZWY9Ii1fX19fLSI%2BLV9fX18tNC1fX18tZnVsbF9uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0tX19fXy08L2E%2BLV9fX18tNS1fLXRoYW5rLV9fLXRoYW5rLV9fLWlkLV9fLTAtX18tMS1fXy10aGFua2VkX29uLV9fX18tMC1fX19fLWZvcm1hdF9kYXRlLV9fX18tNC1fX19fLTxiciAvPi1fX19fLTxkaXYgY2xhc3M9InNlcGFyYXRvciI%2BPC9kaXY%2BLV9fX18tNg%3D%3D&query=dXMudXNlcmlkLCB0aC5pZCBGUk9NIG9uX3RoYW5rcyBBUyB0aCBMRUZUIEpPSU4gb25fdXNlcnMgQVMgdXMgT04odXMudXNlcmlkID0gdGgudXNlcmlkKSBXSEVSRSB0aC5wYXJlbnRfaWQgPSAnZmlsZV91bmhvdF9yZXBsYWNlX21lXzBfJyBPUkRFUiBCWSB0aC50aGFua2VkX29uIERFU0M%3D&load_ajax=1&id=users_make_unhot_id&other=_"+ a +"&b=5&show_nav=1", null, 300, null, null, null);
    rate_file.init(a);
    //fast_rate.draw(a, "file_rating", 10, "file.php?a=rate&f", 1, 5);
    //fast_rate.draw(a, "file_rating_2", 10, "file.php?a=rate&f", 1, 4);
    //fast_rate.draw(a, "file_rating_3", 10, "file.php?a=rate&f", 1, 1);
    //(new Image).src = siteurl + "images/star_hover.png";
    full_screen.init();
    $("#tell_friend_form").submit(function() {
        submit_tell_friend($(this), a);
        return false
    });
    $("#report_broken_form").submit(function() {
        submit_report_broken($(this), a);
        return false
    });
    var b = new tab_menu("file_tabs");
    b.add_action(1, function() {
        image_verification.attach("tell_image_verification")
        });
    b.init();
    preloader.init()
    }
function init_frame() {
    $("#file_frame").height($(window).height() - $("#file_frame_info").height())
    }
var comments = {
    file_id: 0,
    file_more_id: 0,
    page: 1,
    comments: null,
    form: null,
    button: null,
    spam_actions: function(a) {
        var b = a.find(".text:first");
        b.hide();
        a.find(".report:first").hide();
        a.mouseenter(function() {
            b.is(":hidden") && b.slideDown()
            });
        a.mouseleave(function() {
            b.is(":visible") && b.slideUp()
            })
        },
    load: function(a) {
        loader.replace(this.comments);
        this.comments.load(siteurl + "file.php?a=comments&ajax=1&f=" + this.file_id + "&fm=" + this.file_more_id + "&p=" + a, null, function() {
            comments.attach()
            })
        },
    submit: function() {
        loader.insert(this.button);
        $.post(siteurl + "file.php?a=submit_comment&ajax=1&f=" + this.file_id + "&fm=" + this.file_more_id, {text : RTE.getContent(), name_guest : $("#name_guest").val(), email_guest : $("#email_guest").val(), image_verification : $("#image_verification_id").val(), private : ($('#private').attr('checked')==true?"on":"off")}, function(a) {
            error.insert(a.message, comments.form, {
                error: a.error
            });
            if (a.error)
                loader.remove(comments.button);
            else {
                comments.form.slideUp();
                loader.remove(comments.button);
                a = $.createElement("div").addClass("comment").html(a.avatar + '<p><span class="user">' + a.user + '</span> <span class="date">(' + a.date + ')</span></p><p class="text">' + a.comment + '</p><div class="clear"></div>');
                var b = comments.comments.children("div:first-child");
                b.size() > 0 ? b.before(a) : comments.comments.append(a);
                fast_edit.edit_content.remove();
                fast_edit.text.append(fast_edit.button);
	            if($("#submit_comment_form"))
					$("#submit_comment_form").slideUp();
                }
        }, "json")
        },
    delete_comment: function(a) {
        if (confirm_delete()) {
            var b = a.closest(".comment");
            loader.insert(a);
            $.getJSON(siteurl + "file.php?a=delete_comment&c=" + field_number(b.attr("id")) + "&ajax=1", function(c) {
                c.error ? alert(c.message) : b.slideUp()
                })
            }
        },
    delete_all_comment: function(a) {
        if (confirm_delete()) {
            loader.insert(a);
            $.getJSON(siteurl + "file.php?a=delete_all_comment&f=" + this.file_id + "&fm=" + this.file_more_id + "&ajax=1", function(c) {
                c.error ? alert(c.message) : $("#comments").slideUp()
                });
            loader.remove(a);
            }
        },
    report: function(a) {
        a = a.closest(".comment");
        a.addClass("spam");
        comments.spam_actions(a);
        $.getJSON(siteurl + "file.php?a=report_comment&ajax=1&id=" + field_number(a.attr("id")))
        },
    make_like: function(a) {
        a = a.closest(".comment");
        a = field_number(a.attr("id"));
	    fast_load_bubble.init("users_like_"+ a, "users_like_"+ a +"_id", "index.php?a=json_data_cached_2&content=dXNlci1fXy11c2VyLV9fLXVzZXJpZC1fXy0wLV9fLTEtX18tcHJvZmlsZXVybC1fX19fLTAtX19fXy0tX19fXy0wLV9fX18tPHNwYW4gY2xhc3M9InRodW1ibmFpbCI%2BPGEgaHJlZj0iLV9fX18tIj4tX19fXy0wLV9fXy1hdmF0YXJfdXJsLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy08aW1nIHNyYz0iLV9fX18tIiB3aWR0aD0iMzAiIGhlaWdodD0iMzAiLV9fX18tMS1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gYWx0PSItX19fXy0iLV9fX18tMi1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gdGl0bGU9Ii1fX19fLSIgLz48L2E%2BPC9zcGFuPi1fX19fLTMtX19fLXByb2ZpbGV1cmwtX19fXy0wLV9fX18tLV9fX18tMC1fX19fLTxhIGhyZWY9Ii1fX19fLSI%2BLV9fX18tNC1fX18tZnVsbF9uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0tX19fXy08L2E%2BLV9fX18tNS1fLXRoYW5rLV9fLXRoYW5rLV9fLWlkLV9fLTAtX18tMS1fXy10aGFua2VkX29uLV9fX18tMC1fX19fLWZvcm1hdF9kYXRlLV9fX18tNC1fX19fLTxiciAvPi1fX19fLTxkaXYgY2xhc3M9InNlcGFyYXRvciI%2BPC9kaXY%2BLV9fX18tNg%3D%3D&query=dXMudXNlcmlkLCB0aC5pZCBGUk9NIG9uX3RoYW5rcyBBUyB0aCBMRUZUIEpPSU4gb25fdXNlcnMgQVMgdXMgT04odXMudXNlcmlkID0gdGgudXNlcmlkKSBXSEVSRSB0aC5wYXJlbnRfaWQgPSAnY21fbGlrZV9yZXBsYWNlX21lXzBfJyBPUkRFUiBCWSB0aC50aGFua2VkX29uIERFU0M%3D&load_ajax=1&id=users_like_"+ a +"_id&other=_"+ a +"&b=5&show_nav=1", null, 200, null, null, null);
        },
    make_dislike: function(a) {
        a = a.closest(".comment");
        a = field_number(a.attr("id"));
	    fast_load_bubble.init("users_dislike_"+ a, "users_dislike_"+ a +"_id", "index.php?a=json_data_cached_2&content=dXNlci1fXy11c2VyLV9fLXVzZXJpZC1fXy0wLV9fLTEtX18tcHJvZmlsZXVybC1fX19fLTAtX19fXy0tX19fXy0wLV9fX18tPHNwYW4gY2xhc3M9InRodW1ibmFpbCI%2BPGEgaHJlZj0iLV9fX18tIj4tX19fXy0wLV9fXy1hdmF0YXJfdXJsLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy08aW1nIHNyYz0iLV9fX18tIiB3aWR0aD0iMzAiIGhlaWdodD0iMzAiLV9fX18tMS1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gYWx0PSItX19fXy0iLV9fX18tMi1fX18tZnVsbF9hbGlhc19uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0gdGl0bGU9Ii1fX19fLSIgLz48L2E%2BPC9zcGFuPi1fX19fLTMtX19fLXByb2ZpbGV1cmwtX19fXy0wLV9fX18tLV9fX18tMC1fX19fLTxhIGhyZWY9Ii1fX19fLSI%2BLV9fX18tNC1fX18tZnVsbF9uYW1lLV9fX18tMC1fX19fLS1fX19fLTAtX19fXy0tX19fXy08L2E%2BLV9fX18tNS1fLXRoYW5rLV9fLXRoYW5rLV9fLWlkLV9fLTAtX18tMS1fXy10aGFua2VkX29uLV9fX18tMC1fX19fLWZvcm1hdF9kYXRlLV9fX18tNC1fX19fLTxiciAvPi1fX19fLTxkaXYgY2xhc3M9InNlcGFyYXRvciI%2BPC9kaXY%2BLV9fX18tNg%3D%3D&query=dXMudXNlcmlkLCB0aC5pZCBGUk9NIG9uX3RoYW5rcyBBUyB0aCBMRUZUIEpPSU4gb25fdXNlcnMgQVMgdXMgT04odXMudXNlcmlkID0gdGgudXNlcmlkKSBXSEVSRSB0aC5wYXJlbnRfaWQgPSAnY21fZGlzbGlrZV9yZXBsYWNlX21lXzBfJyBPUkRFUiBCWSB0aC50aGFua2VkX29uIERFU0M%3D&load_ajax=1&id=users_dislike_"+ a +"_id&other=_"+ a +"&b=5&show_nav=1", null, 200, null, null, null);
        },
    report: function(a) {
        a = a.closest(".comment");
        a.addClass("spam");
        comments.spam_actions(a);
        $.getJSON(siteurl + "file.php?a=report_comment&ajax=1&id=" + field_number(a.attr("id")))
        },
    /*page_click: function() {
        comments.page += $(this).hasClass("next") ? 1: -1;
        comments.load(comments.page);
        return false
    },*/
    attach: function() {
        this.comments.children("div.arrow_nav").find(".next, .previous").click(this.page_click);
        this.comments.find(".report").click(function() {
            comments.report($(this))
            });
        this.comments.find(".spam").each(function() {
            comments.spam_actions($(this))
            })
        this.comments.find(".click").click(function() {
            fast_edit.change($(this), "text", "tab=comments&id_field=commentid&cos=comment&id", "tab=comments&id_field=commentid&cos=comment&id", 550, 500, "rte");
            });
	    this.comments.find(".click_quote").click(function() {
	        fast_edit.change($(this), "quote_comment", "tab=quote_comment&id", "tab=quote_comment&id", 550, 500, "rte");
	       	$("#submit_comment_form").show();
	        image_verification.attach("comment_verification_field");
	        });
        this.comments.find(".make_like").each(function() {
        	comments.make_like($(this));
        	});
        this.comments.find(".make_dislike").each(function() {
        	comments.make_dislike($(this));
        	});
        },
    init: function(a, file_more_id, page) {
        this.file_id = a;
        this.file_more_id = file_more_id;
        this.page = page;
        this.comments = $("#comments");
        this.attach();
        this.form = $("#comment_form");
        if (this.form.size() > 0) {
            this.button = this.form.find("input:submit");
            this.form.submit(function() {
                comments.submit();
                return false
            });
            var b = $("#comment_verification_field");
            b.size() > 0 && $("#comment").focusin(function() {
                if (b.is(":hidden")) {
                    b.show();
                    image_verification.attach("comment_verification_field")
                    }
            })
            }
        $("#comments .delete a").live("click", function(b) {
            b.preventDefault();
            comments.delete_comment($(this))
            });
        $("#to_comments .delete_all a").live("click", function(b) {
            b.preventDefault();
            comments.delete_all_comment($(this))
            });
	    $("#comments .make_like").live("click", function() {
		    text = $(this).closest(".comment");
		    id = field_number(text.attr("id"));
	        make_thank(id, "cm_like", "make_like_" + id);
	    	});
	    $("#comments .make_dislike").live("click", function() {
		    text = $(this).closest(".comment");
		    id = field_number(text.attr("id"));
	        make_thank(id, "cm_dislike", "make_dislike_" + id);
	    	});
    }
},
score_comment = {
    score_id: 0,
    comment: null,
    button: null,
    change: function(a) {
        this.comment = a.closest("p");
        this.score_id = field_number(this.comment.attr("id"));
        this.button = a.detach();
        this.comment.empty();
        a = $.createElement("form");
        var b = $.createElement("input").attr("type", "text").width("100%").css("margin", 0).appendTo(a);
        $.createElement("input").attr("type", "submit").val(lang.submit).appendTo(a);
        a.submit(function() {
            score_comment.submit(b.val());
            return false
        }).appendTo(this.comment);
        b.focus()
        },
    submit: function(a) {
        loader.replace(this.comment);
        $.post(siteurl + "scores.php?a=edit_comment&id=" + score_comment.score_id, {
            comment: a
        }, function(b) {
            if (b.error)
                alert(b.message);
            else {
                score_comment.comment.html(b.comment + " ");
                score_comment.comment.append(score_comment.button)
                }
        }, "json")
        }
};
function init_scores(a) {
    rate_file.init(a);
    $(".change_comment").click(function() {
        score_comment.change($(this));
        return false
    })
    }
fast_edit = {
    id: 0,
    text: null,
    button: null,
    edit_content: null,
    old_content: null,
    loading: null,
    id_field: null,
    change: function(a, id_field, get_url, post_url, width, height, type) {
    	fast_edit.id_field = id_field;
    	if(fast_edit.loading == true)
    		fast_edit.close();
    	width = (width==null?500:width);
    	height = (height==null?200:height);
    	type = (type==null?"textarea":type);
        get_url = my_url(get_url);
        post_url = my_url(post_url);
        fast_edit.text = a.closest("."+fast_edit.id_field);
        fast_edit.id = field_number(fast_edit.text.attr("id"));
        fast_edit.button = a.detach();
        fast_edit.old_content = fast_edit.text.html();
        fast_edit.text.empty();
        fast_edit.edit_content = $.createElement("form");
        if(type == "rte")
        	var b = $.createElement("span").attr("id", "rte1").appendTo(fast_edit.edit_content);
        else if(type == "textarea")
        	var b = $.createElement("textarea").css({margin: 0,width: width + "px",height: height + "px"}).appendTo(fast_edit.edit_content);
        else if(type == "text")
        	var b = $.createElement("input").attr("type", "text").width(width + "px").css("margin", 0).appendTo(fast_edit.edit_content);
        $.getJSON(siteurl + "index.php?a=json_data&"+ get_url +"="+ fast_edit.id +"&ajax=1", function(c) {
            if (c.error)
                alert(c.message);
            else {
		        if(type == "rte"){
		        	RTE=new Editor("RTE","rte1",c.text,width, height);
		            RTE.backgroundImage.url = "";
		            setTimeout("RTE.display()", 0);
		        }else if(type == "textarea")
	            	b.html(c.text)
	            else if(type == "text")
	            	b.val(c.text)
	    	}
            });
        $.createElement("div").addClass("clear").appendTo(fast_edit.edit_content);
        if(type == "rte"){
        	$.createElement("input").attr("type", "button").attr("id", "preview_ajax").val(lang.preview).css({background: "#000",color: "#fff"}).appendTo(fast_edit.edit_content);
        	setTimeout('fast_load_bubble.init("preview_ajax", "hehe", "index.php?a=preview_ajax", "json", 550, null, null, "fast_edit")', 0);
        }
        if(fast_edit.id_field != "submit_comment" && fast_edit.id_field != "quote_comment")
        	$.createElement("input").attr("type", "submit").val(lang.submit).appendTo(fast_edit.edit_content);
        else{
        	if($("#image_verification_id"))
        		$("#image_verification_id").val("");
        	comments.form.show();
        }
        fast_edit.edit_content.submit(function() {
            fast_edit.submit(b.val(), post_url, type);
            return false
        }).appendTo(fast_edit.text);
        b.focus();
        setTimeout('$(document).bind("click", fast_edit.close)', 0);
        fast_edit.edit_content.click(function(b) {
            b.stopPropagation()
            });
        if(fast_edit.id_field == "submit_comment" || fast_edit.id_field == "quote_comment"){
	        $("#submit_comment_form").click(function(b) {
	            b.stopPropagation()
	            });
			var position = b.position();
	       	$("#submit_comment_form").css({position: "absolute", background: "#004040", width: "550px", color: "#fff", padding: "10px", left: position.left+60 +"px", top: position.top+530 +"px"});
	    }
        fast_edit.loading = true;
        },
    close: function() {
        fast_edit.edit_content.hide();
        fast_edit.edit_content.remove();
        fast_edit.text.append(fast_edit.old_content);
        fast_edit.text.append(fast_edit.button);
        fast_edit.old_content = '';
        if($("#submit_comment_form") || fast_edit.id_field == "submit_comment" || fast_edit.id_field == "quote_comment"){
            if($(".error"))
            	$(".error").hide();
            if($(".error_green"))
            	$(".error_green").hide();
        	$("#submit_comment_form").hide();
        }
        $(document).unbind("click", fast_edit.close);
        },
    submit: function(a, post_url, type) {
        loader.replace(fast_edit.text);
        $.post(siteurl + "index.php?a=update_ajax&"+ post_url +"=" + fast_edit.id +"&ajax=1", {
            text: (type != "rte" ? a : RTE.getContent())
        }, function(b) {
            if (b.error)
                alert(b.message);
            else {
                fast_edit.text.html(b.text + " ");
                fast_edit.text.append(fast_edit.button)
                }
        }, "json");
        $(document).unbind("click", fast_edit.close);
        }
};
var fast_load = {
    file_id: 0,
    field_id: null,
    page: 1,
    comments: null,
    form: null,
    button: null,
    cm_class: null,
    load_url: null,
    submit_url: null,
    delete_url: null,
    delete_all_url: null,
    report_url: null,
    content_temp: null,
    spam_actions: function(a) {
        var b = a.find(".text:first");
        b.hide();
        a.find(".report:first").hide();
        a.mouseenter(function() {
            b.is(":hidden") && b.slideDown()
            });
        a.mouseleave(function() {
            b.is(":visible") && b.slideUp()
            })
        },
    load: function(a) {
        loader.replace(fast_load.comments);
        if(fast_load.content_temp != null){
            fast_load.comments.html(fast_load.content_temp);
        }else{
            fast_load.comments.load(siteurl + fast_load.load_url +"=" + fast_load.file_id + "&p=" + a +"&ajax=1", null, function() {
                fast_load.attach()
                })
            }
        },
    submit: function() {
        loader.insert(fast_load.button);
        $.post(siteurl + fast_load.submit_url +"=" + fast_load.file_id + "&ajax=1", fast_load.form.serializeArray(), function(a) {
            error.insert(a.message, fast_load.form, {
                error: a.error
            });
            if (a.error)
                loader.remove(fast_load.button);
            else {
                fast_load.form.slideUp();
                a = $.createElement("div").addClass("comment").html('<p><span class="user">' + a.user + '</span> <span class="date">(' + a.date + ')</span></p><p class="text">' + a.comment + "</p>");
                var b = fast_load.comments.children("div:first-child");
                b.size() > 0 ? b.before(a) : fast_load.comments.append(a)
                }
        }, "json")
        },
    delete_comment: function(a) {
        if (confirm_delete()) {
            var b = a.closest("."+ fast_load.cm_class);
            loader.insert(a);
            $.getJSON(siteurl + fast_load.delete_url +"=" + field_number(b.attr("id")) + "&ajax=1", function(c) {
                c.error ? alert(c.message) : b.slideUp()
                })
            }
        },
    delete_all_comment: function(a) {
        if (confirm_delete()) {
            loader.insert(a);
            $.getJSON(siteurl + fast_load.delete_all_url +"=" + fast_load.file_id + "&ajax=1", function(c) {
                c.error ? alert(c.message) : $("#"+ fast_load.field_id).slideUp()
                });
            loader.remove(a);
            }
        },
    report: function(a) {
        a = a.closest("."+ fast_load.cm_class);
        a.addClass("spam");
        fast_load.spam_actions(a);
        $.getJSON(siteurl + fast_load.report_url +"=" + field_number(a.attr("id")) + "&ajax=1")
        },
    page_click: function() {
        fast_load.page += $(this).hasClass("next") ? 1: -1;
        fast_load.load(fast_load.page);
        return false
    },
    attach: function() {
        fast_load.comments.children("div.arrow_nav").find(".next, .previous").click(fast_load.page_click);
        fast_load.comments.find(".report").click(function() {
            fast_load.report($(this))
            });
        fast_load.comments.find(".spam").each(function() {
            fast_load.spam_actions($(this))
            })
        },
    init: function(a, page, field_father, field_id, form_id, ver_id, text_id, cm_class, load_url, submit_url, edit_url, submit_edit_url, delete_url, delete_all_url, report_url, content_temp) {
        this.file_id = a;
        this.page = page;
        this.field_id = field_id;
        this.comments = $("#"+ field_id);
        this.attach();
        this.form = $("#"+ form_id);
        this.cm_class = cm_class;
        this.load_url = my_url(load_url);
        this.submit_url = my_url(submit_url);
        this.edit_url = my_url(edit_url);
        this.submit_edit_url = my_url(submit_edit_url);
        this.delete_url = my_url(delete_url);
        this.delete_all_url = my_url(delete_all_url);
        this.report_url = my_url(report_url);
        this.content_temp = content_temp;
        if (this.form.size() > 0) {
            this.button = this.form.find("input:submit");
            this.form.submit(function() {
                fast_load.submit();
                return false
            });
            var b = $("#"+ ver_id);
            b.size() > 0 && $("#"+ text_id).focusin(function() {
                if (b.is(":hidden")) {
                    b.show();
                    image_verification.attach(ver_id)
                    }
            })
            }
        $("#"+ field_id +" .delete a").live("click", function(b) {
            b.preventDefault();
            fast_load.delete_comment($(this))
            });
        $("#"+ field_father +" .delete_all a").live("click", function(b) {
            b.preventDefault();
            fast_load.delete_all_comment($(this))
            });
        $("#"+ field_id +" .click").live("click", function() {
            fast_edit.change($(this), "text", edit_url, submit_edit_url, null, null);
            })
    }
}
fast_load_bubble = {
    link: [],
    menu: [],
    content: [],
    loaded: [],
    field_id: [],
    menu_id: [],
    load_url: [],
    json: [],
    width: [],
    content_temp: [],
    mouse_type: [],
    fast_edit: [],
    create: function(field_id) {
        fast_load_bubble.menu[field_id] = $.createElement("div").addClass("bubble").width(fast_load_bubble.width[field_id] +"px").attr("id", fast_load_bubble.menu_id[field_id]);
        fast_load_bubble.content[field_id] = $.createElement("div").appendTo(fast_load_bubble.menu[field_id]);
        $.createElement("div").addClass("bubble_up").appendTo(fast_load_bubble.menu[field_id]);
        $(document.body).append(fast_load_bubble.menu[field_id])
        },
    load: function(field_id) {
        if(fast_load_bubble.content_temp[field_id] != null){
            fast_load_bubble.content[field_id].empty();
            var b;
            b = $.createElement("p");
            b.html(fast_load_bubble.content_temp[field_id]);
            b.appendTo(fast_load_bubble.content[field_id])
            fast_load_bubble.loaded[field_id] = true
        }else{
            fast_load_bubble.content[field_id].empty();
	        if(fast_load_bubble.json[field_id] == "json")
		        $.post(siteurl + fast_load_bubble.load_url[field_id] +"&ajax=1", {
		            content: RTE.getContent()
		        }, function(b) {
		            if (b.error)
		                alert(b.message);
		            else
		        		fast_load_bubble.content[field_id].html(b.text);
		        }, "json")
	        else
	        	fast_load_bubble.content[field_id].load(siteurl + fast_load_bubble.load_url[field_id] +"&ajax=1")
            if(fast_load_bubble.json[field_id] != null)
	            fast_load_bubble.loaded[field_id] = false;
            else
            	fast_load_bubble.loaded[field_id] = true;
        }
        },
    open: function(field_id) {
        fast_load_bubble.menu[field_id] == null && fast_load_bubble.create(field_id);
        fast_load_bubble.menu[field_id].show();
        var a = fast_load_bubble.link[field_id].offset();
        fast_load_bubble.menu[field_id].css({
            left: a.left + "px",
            top: a.top + 0 + "px"
        });
       	if(fast_load_bubble.fast_edit[field_id] != null)
	        $(document).unbind("click", fast_edit.close);
        if(fast_load_bubble.mouse_type[field_id] == null){
            $(document).bind("click", function(){fast_load_bubble.close(field_id)});
        	if(fast_load_bubble.fast_edit[field_id] != null){
        		fast_edit.edit_content.bind("click", function(){fast_load_bubble.close(field_id)});
		        if(fast_edit.id_field == "submit_comment" || fast_edit.id_field == "quote_comment")
			        $("#submit_comment_form").bind("click", function(){fast_load_bubble.close(field_id)});
        	}
            fast_load_bubble.menu[field_id].click(function(b) {
                b.stopPropagation()
                });
        }else{
            $(document).bind("mouseover", function(){fast_load_bubble.close(field_id)});
            fast_load_bubble.menu[field_id].mouseover(function(b) {
                b.stopPropagation()
                });
        }
        if (fast_load_bubble.loaded[field_id] == false) {
            loader.replace(fast_load_bubble.content[field_id]);
            fast_load_bubble.load(field_id)
            }
    },
    close: function(field_id) {
        fast_load_bubble.menu[field_id].hide();
        if(fast_load_bubble.mouse_type[field_id] == null){
           	$(document).unbind("click", function(){fast_load_bubble.close(field_id)})
        	if(fast_load_bubble.fast_edit[field_id] != null)
        		fast_edit.edit_content.unbind("click", function(){fast_load_bubble.close(field_id)})
        }
        else
            $(document).unbind("mouseover", function(){fast_load_bubble.close(field_id)})
       	if(fast_load_bubble.fast_edit[field_id] != null)
	        setTimeout('$(document).bind("click", fast_edit.close)', 0);
        },
    init: function(field_id, menu_id, load_url, json, width, content_temp, mouse_type, fast_edit) {
        this.loaded[field_id] = false;
        this.field_id[field_id] = field_id;
        this.menu_id[field_id] = menu_id;
        this.load_url[field_id] = my_url(load_url);
        this.content_temp[field_id] = content_temp;
        this.mouse_type[field_id] = mouse_type;
        this.width[field_id] = (width==null?500:width);
        this.json[field_id] = json;
        this.fast_edit[field_id] = fast_edit;
        fast_load_bubble.link[field_id] = $("#"+ field_id);
        if(mouse_type == null){
            fast_load_bubble.link[field_id].click(function(a) {
                fast_load_bubble.open(field_id);
                a.stopPropagation();
                return false
            })
        }else{
            fast_load_bubble.link[field_id].mouseover(function(a) {
                fast_load_bubble.open(field_id);
                a.stopPropagation();
                return false
            })
        }
        }
};
function load_ajax(id_display, url){
	url = decode64(url);
	url = my_url(url);
	loader.replace($("#"+ id_display));
	$("#"+ id_display).load(url +"&ajax=1")
}
var id_add_file = null;
function add_file(id){
	id = (id_add_file > id ? id_add_file : id);
    var b = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html("<font color=\"#FF0000\">"+ lang.file_more +" "+ id +"</font>").appendTo(b);
    $.createElement("p").attr("id", "select_upload_file_direct_"+ id).html("<input name=\"upload_c_file[]\" type=\"file\" /> "+ lang.max_size_kb).hide().appendTo(b);
    $.createElement("p").attr("id", "select_upload_file_link_"+ id).html("<input type=\"text\" name=\"upload_c_file_link[]\" maxlength=\"255\" />").appendTo(b);
    $.createElement("p").attr("id", "select_upload_file_code_"+ id).html("<textarea name=\"upload_c_file_customcode[]\"></textarea>").hide().appendTo(b);
    $.createElement("p").html("<select name=\"select_upload_c_file[]\" onchange=\"if(this.value=='link'){document.getElementById('select_upload_file_direct_"+ id +"').style.display='none';document.getElementById('select_upload_file_code_"+ id +"').style.display='none';document.getElementById('select_upload_file_link_"+ id +"').style.display='block';}else if(this.value=='upload'){document.getElementById('select_upload_file_link_"+ id +"').style.display='none';document.getElementById('select_upload_file_code_"+ id +"').style.display='none';document.getElementById('select_upload_file_direct_"+ id +"').style.display='block';}else{document.getElementById('select_upload_file_direct_"+ id +"').style.display='none';document.getElementById('select_upload_file_link_"+ id +"').style.display='none';document.getElementById('select_upload_file_code_"+ id +"').style.display='block';}\"><option value=\"upload\">"+ lang.upload +"</option><option value=\"link\" selected=\"selected\">"+ lang.link +"</option><option value=\"code\">"+ lang.code +"</option></select><a href=\"\" onclick=\"add_file("+ (id+1) +");return false;\">"+ lang.add_file +"</a>").appendTo(b);
    $.createElement("br").appendTo(b);$.createElement("br").appendTo(b);$.createElement("br").appendTo(b);$.createElement("br").appendTo(b);$.createElement("br").appendTo(b);
    $.createElement("p").addClass("left").html(lang.description +" "+ id).appendTo(b);
    $.createElement("p").html("<input type=\"text\" name=\"des_c_file[]\" maxlength=\"255\" /><input type=\"hidden\" name=\"c_file_id[]\" />").appendTo(b);
    b.appendTo($("#new_file"));
    id_add_file = id + 1;
    return false;
}
var id_add_ques = null;
function add_poll(id){
	id = (id_add_ques > id ? id_add_ques : id);
    var b = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html(lang.qtitle +" "+ id).appendTo(b);
    $.createElement("p").html("<textarea name=\"qtitle[]\" style=\"background:#524A52;color:#fff\"></textarea><input type=\"hidden\" name=\"qid[]\" /><a href=\"\" onclick=\"add_poll("+ (id+1) +");return false;\">"+ lang.add_qtitle +"</a>").appendTo(b);
    b.appendTo($("#new_poll"));
    var d = $.createElement("div").addClass("add_more_poll").html($(".add_more_poll").html());
    d.appendTo($("#new_poll"));
    $(".datepicker").dynDateTime();
    var c = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html(lang.atitle).appendTo(c);
    $.createElement("p").html("<input type=\"text\" name=\"atitle_"+ id +"[]\" /><input type=\"hidden\" name=\"aid_"+ id +"[]\" /><a href=\"\" onclick=\"add_opt("+ id +");return false;\">"+ lang.add_atitle +"</a>").appendTo(c);
    c.appendTo($("#new_poll"));
    $.createElement("div").attr("id", "new_opt_"+ id).appendTo($("#new_poll"));
    id_add_ques = id + 1;
    return false;
}
function add_opt(id){
    var b = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html(lang.atitle).appendTo(b);
    $.createElement("p").html("<input type=\"text\" name=\"atitle_"+ id +"[]\" /><input type=\"hidden\" name=\"aid_"+ id +"[]\" />").appendTo(b);
    b.appendTo($("#new_opt_"+ id));
    return false;
}
var id_add_mv = null;
function add_mv(id){
	id = (id_add_mv > id ? id_add_mv : id);
    var b = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html(lang.mv +" "+ id).appendTo(b);
    $.createElement("p").html("<textarea name=\"mv[]\" style=\"background:#F67616;color:#fff\"></textarea><input type=\"hidden\" name=\"mvid[]\" /><a href=\"\" onclick=\"add_mv("+ (id+1) +");return false;\">"+ lang.add_mv +"</a>").appendTo(b);
    b.appendTo($("#new_mv"));
    var d = $.createElement("div").addClass("add_more_mv").html($(".add_more_mv").html());
    d.appendTo($("#new_mv"));
    $(".datepicker").dynDateTime();
    id_add_mv = id + 1;
    return false;
}
var id_price_range = null;
function add_price_range(id){
	id = (id_price_range > id ? id_price_range : id);
    var b = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html(lang.price_range +" "+ id).appendTo(b);
    $.createElement("p").html("<input type=\"text\" name=\"price_range[]\" style=\"width:80px\" maxlength=\"15\" /><input type=\"text\" name=\"price_change[]\" maxlength=\"15\" /><a href=\"\" onclick=\"add_price_range("+ (id+1) +");return false;\">"+ lang.add_price_range +"</a>").appendTo(b);
    b.appendTo($("#new_price_range"));
    id_price_range = id + 1;
    return false;
}
var id_other_more = null;
function add_other_more(id){
	id = (id_other_more > id ? id_other_more : id);
    var b = $.createElement("div").addClass("line");
    $.createElement("p").addClass("left").html(lang.other_more +" "+ id).appendTo(b);
    $.createElement("p").html("<input type=\"text\" name=\"other_more[]\" style=\"width:80px\" maxlength=\"50\" /><input type=\"text\" name=\"other_more_value[]\" maxlength=\"255\" /><a href=\"\" onclick=\"add_other_more("+ (id+1) +");return false;\">"+ lang.add_other_more +"</a>").appendTo(b);
    b.appendTo($("#new_other_more"));
    id_other_more = id + 1;
    return false;
}
var bb_code = {
    codes: [["text_bold.png", "b"], ["text_italic.png", "i"], ["text_underline.png", "u"], ["text_strikethrough.png", "s"], ["text_center.png", "center"], ["text_right.png", "right"], ["text_quote.png", "quote"], ["text_url.png", "url"], ["text_image.png", "img"]],
    emoticons: [["1.gif", ":)"], ["2.gif", ":("], ["3.gif", ";)"], ["13.gif", ":-O"], ["16.gif", "B-)"], ["41.gif", "=D>"], ["39.gif", ":-?"], ["8.gif", ":X"]],
    open: {},
    insert_emoticon: function(a, b) {
        a = " " + a + " ";
        b.focus();
        if (document.selection)
            document.selection.createRange().text = a;
        else if (b.selectionStart || b.selectionStart == 0) {
            var c = b.selectionStart,
            d = b.selectionEnd,
            e = b.scrollTop;
            b.value = b.value.substring(0, c) + a + b.value.substring(d, b.value.length);
            b.selectionStart = c + a.length;
            b.selectionEnd = c + a.length;
            b.scrollTop = e
        } else
            b.value += a
    },
    get_tag: function(a) {
        if (bb_code.open[a] == undefined || bb_code.open[a] == false) {
            bb_code.open[a] = true;
            return "[" + a + "]"
        } else {
            bb_code.open[a] = false;
            return "[/" + a + "]"
        }
    },
    insert_code: function(a, b) {
        b.focus();
        if (document.selection)
            var c = document.selection.createRange().text,
        d = "ie";
        else if (b.selectionStart || b.selectionStart == 0) {
            var e = b.selectionStart,
            g = b.selectionEnd,
            j = b.scrollTop,
            f = b.value.substring(0, e),
            h = b.value.substring(g, b.value.length);
            c = b.value.substring(e, g);
            d = "other"
        }
        if (a == "url")
            if (d == "ie")
            if (c.length > 0)
            if (c.match(/^https?:\/\//i))
            document.selection.createRange().text = "[url=" + c + "]" + c + "[/url]";
        else
            document.selection.createRange().text = "[url=http://]" + c + "[/url]";
        else
            document.selection.createRange().text = "[url=http://]text[/url]";
        else if (d == "other")
            if (c.length > 0)
            if (c.match(/^https?:\/\//i)) {
            b.value = f + "[url=" + c + "]" + c + "[/url]" + h;
            e += 6 + c.length;
            g = e + c.length
        } else {
            b.value = f + "[url=http://]" + c + "[/url]" + h;
            e += 5;
            g = e + 7
        } else {
            b.value = f + "[url=http://]text[/url]" + h;
            e += 5;
            g = e + 7
        } else
            b.value += "[url=http://]text[/url]";
        else if (a == "img")
            if (d == "ie")
            document.selection.createRange().text = c.length > 0 ? "[img]" + c + "[/img]": "[img]http://[/img]";
        else if (d == "other")
            if (c.length > 0) {
            b.value = f + "[img]" + c + "[/img]" + h;
            e += 5;
            g = e + c.length
        } else {
            b.value = f + "[img]http://[/img]" + h;
            e += 5;
            g += 12
        } else
            b.value += "[img]http://[/img]";
        else if (d == "ie") {
            if (c.length > 0)
                document.selection.createRange().text = "[" + a + "]" + c + "[/" + a + "]";
            else
                document.selection.createRange().text = bb_code.get_tag(a);
            b.focus()
            } else if (d == "other")
            if (c.length > 0) {
            b.value = f + "[" + a + "]" + c + "[/" + a + "]" + h;
            e += a.length + 2;
            g += a.length + 2
        } else {
            a = bb_code.get_tag(a);
            b.value = f + a + h;
            e += a.length;
            g = e
        } else
            b.value += bb_code.get_tag(a);
        if (d == "other") {
            b.selectionStart = e;
            b.selectionEnd = g;
            b.scrollTop = j
        }
    },
    attach_emoticons: function(a, b) {
        a = $("#" + a);
        b = $("#" + b).get(0);
        var c = $.createElement("p");
        for (i in bb_code.emoticons)
            $.createElement("img").attr("src", "http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/" + bb_code.emoticons[i][0]).attr("alt", bb_code.emoticons[i][1]).attr("title", bb_code.emoticons[i][1]).click(function() {
            bb_code.insert_emoticon($(this).attr("alt"), b)
            }).addClass("bb_emoticon").appendTo(c);
        c.appendTo(a)
        },
    attach_codes: function(a, b) {
        a = $("#" + a);
        b = $("#" + b).get(0);
        var c = $.createElement("p");
        for (i in bb_code.codes)
            $.createElement("img").attr("src", siteurl + "images/" + bb_code.codes[i][0]).attr("alt", bb_code.codes[i][1]).attr("title", bb_code.codes[i][1]).click(function() {
            bb_code.insert_code($(this).attr("alt"), b)
            }).addClass("bb_code").appendTo(c);
        c.appendTo(a)
        },
    attach: function(a, b) {
        bb_code.attach_emoticons(a, b);
        bb_code.attach_codes(a, b)
        }
};
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ' ' + '$2');
	}
	return x1 + x2;
}
function change_currency(amount, currency, to_currency, id){
	if(currency == "VND")
		amount = amount * VND_rate;
	else if(currency == "USD")
		amount = amount * USD_rate;
	else if(currency == "CAD")
		amount = amount * CAD_rate;
	if(to_currency == "VND")
		currency_rate = VND_rate;
	else if(to_currency == "USD")
		currency_rate = USD_rate;
	else if(to_currency == "CAD")
		currency_rate = CAD_rate;
	$("#"+ id).find("em").html(addCommas(amount / currency_rate) +" "+ to_currency);
}
$(".change_currency").live("mouseover", function() {
    text = $(this).closest(".currency");
    id = text.attr("id");
    decode_id = $(this).attr("id");
	fast_load_bubble.init($(this).attr("id"), "change_currency_"+ $(this).attr("id") +"_id" , "", null, 100, "<a href=\"\" onclick=\"change_currency("+ field_number2(decode_id.replace(/[0-9]{1,}_/g, "")) +", '"+ field_text(decode_id.replace(/[0-9]{1,}_/g, "").replace(/\./g, "")) +"', 'VND', '"+ id +"');return false\">to VND</a><br /><a href=\"\" onclick=\"change_currency("+ field_number2(decode_id.replace(/[0-9]{1,}_/g, "")) +", '"+ field_text(decode_id.replace(/[0-9]{1,}_/g, "")) +"', 'USD', '"+ id +"');return false\">to USD</a><br /><a href=\"\" onclick=\"change_currency("+ field_number2(decode_id.replace(/[0-9]{1,}_/g, "")) +", '"+ field_text(decode_id.replace(/[0-9]{1,}_/g, "")) +"', 'CAD', '"+ id +"');return false\">to CAD</a>", "mouseover", null);
	fast_load_bubble.open($(this).attr("id"));
	});
