/*!	$Id: popup-insert-uncompressed.js 989 2008-06-25 19:02:32Z Fritz Elfert $ */
function AvReloadedInsert() {

	this.init = function(tags,ltags,w,h,havepv) {
		o = this._getUriObject(window.self.location.href);
		q = $H(this._getQueryObject(o.query));
		this.editor = decodeURIComponent(q.get('e_name'));
        pl = q.get('playlist');
		this.playlist = pl ? decodeURIComponent(pl) : 0;
        this.form = $("adminForm");

		// Setup fields object
		this.fields = new Object();
		this.fields.url       = $("url");
		this.fields.mloc      = $("mloc");
		this.fields.provider  = $("provider");
		this.fields.lprovider = $("lprovider");
		this.fields.tagid     = $("tagid");
		this.fields.ltagid    = $("ltagid");
		this.fields.width     = $("width");
		this.fields.lwidth    = $("lwidth");
		this.fields.height    = $("height");
		this.fields.lheight   = $("lheight");
		this.fields.mtag      = $("mtag");
		this.fields.lmtag     = $("lmtag");
		this.fields.local     = $("local");

        this.buttons = [ $('pv'), $('ins') ];
        this.lbuttons = [ $('lpv'), $('lins') ];

        // Setup media tags
        this.tags = tags;
        this.ltags = ltags;

        // Setup default dimensions
		this.dim = new Object();
        this.dim.w = w;
        this.dim.h = h;

        if (!havepv) {
            $("preview").style['height'] = h+'px';
        }
        this.checkTag(0);
        this.checkTag(1);
	};

    this.buildTag = function(local, t) {
        if (local) {
            var w = this.fields.lwidth.getValue();
            var h = this.fields.lheight.getValue();
            var t = this.fields.ltagid.getValue();
            var p = this.fields.lprovider.getValue();

            for (var i = 0; i < this.ltags.length; i++) {
                if (this.ltags[i].val == p) {
                    var tagval = this.ltags[i].tag;
                    var v = '{'+tagval;
                    if ((w != '') && (w != this.dim.w)) {
                        v += ' width="'+w+'"';
                    }
                    if ((h != '') && (h != this.dim.h)) {
                        v += ' height="'+h+'"';
                    }
                    v += '}'+t+'{/'+tagval+'}';
                    this.fields.lmtag.value = v;
                    this.checkTag(local);
                    break;
                }
            }
        } else {
            var w = this.fields.width.getValue();
            var h = this.fields.height.getValue();
            var t = this.fields.tagid.getValue();
            var p = this.fields.provider.getValue();

            for (var i = 0; i < this.tags.length; i++) {
                if (this.tags[i].val == p) {
                    var tagval = this.tags[i].tag;
                    var v = '{'+tagval;
                    if ((w != '') && (w != this.dim.w)) {
                        v += ' width="'+w+'"';
                    }
                    if ((h != '') && (h != this.dim.h)) {
                        v += ' height="'+h+'"';
                    }
                    v += '}'+t+'{/'+tagval+'}';
                    this.fields.mtag.value = v;
                    this.checkTag(local);
                    break;
                }
            }
        }
        return false;
    };

    this.matchLOC = function(loc) {
        for (var i = 0; i < this.ltags.length; i++) {
            if (this.ltags[i].rx != null) {
                var result;
                if (result = this.ltags[i].rx.exec(loc)) {
                    this.fields.lprovider.value = this.ltags[i].val;
                    this.fields.ltagid.value = result[1];
                    this.buildTag(true);
                    break;
                }
            }
        }
        return false;
    };

    this.matchURL = function(url) {
        for (var i = 0; i < this.tags.length; i++) {
            if (this.tags[i].rx != null) {
                var result;
                if (result = this.tags[i].rx.exec(url)) {
                    this.fields.provider.value = this.tags[i].val;
                    this.fields.tagid.value = result[1];
                    thi