
cont_mgr = Class.create();  

cont_mgr.prototype=                
{
    initialize: function()
    {
    }
};

cont_mgr.obtain = function(key, editable, widget)
{
    var cont_inst = eval("new cont_"+key+"(editable, widget);");
    cont_mgr.list.push(cont_inst);
    return(cont_inst);
};

cont_mgr.list = Array();

function cont_getHtml(file, cb, index, extra_args)
{
    var args= Array('file='+file,"action=send", "page_id="+page_id, "widget_num="+index);
    if (extra_args != null)
    {
        for(var i =0; i<extra_args.length; i++)
        {
            args.push(extra_args[i]);
        }
    }
    var sajax = new SimpleAjax("get_html_"+index, "/ajax/get_html.php", cb);
    sajax.sendPost(args);
}

var cm_base_url="/ajax/cm_update.php?site_id="+site_id+"&page_id="+page_id;

var cm_updater_index = 0;
function cont_cmUpdate(args, cb)
{
    var sajax = new SimpleAjax("data__updater", cm_base_url, cb);
    sajax.sendPost(args);
}

function insert_html_response(el, response)
{
    var scripts = response.getElementsByTagName("script");
    var script_strs = new Array();
    if(scripts.length > 0)
    {
        for(var i = 0; i < scripts.length; i++)
        {
            var script = scripts[i];
            script_strs[script_strs.length] = RicoUtil.getContentAsString(script);
//            response.removeChild(script);
        }
    }
    var text = RicoUtil.getContentAsString(response);
    el.innerHTML = text;
    //now run the scripts
    for(var i = 0; i < script_strs.length; i++)
    {
        try
        {
            if (script_strs[i].length > 0)
            {
                if (window.execScript) 
                {
                    window.execScript(script_strs[i]); // IE global scope eval
                }
                else
                {
                    window.eval(script_strs[i]);
                }
            }
        }
        catch(err)
        {
            alert("eval script error:\nLine number: "+err.lineNumber+"\nMessage: "+err.message+"\n"+ script_strs[i]);
        }
    
    }
}
var cont_class = Class.create();
cont_class.prototype=

{
    initialize: function(editable, widget)
    {
        this.editable = editable;
        this.widget = widget;
        this.ext_args = null;
    },
    display: function(save)
    {
        var div= this.display_div = document.createElement("DIV");
        div.id=this.widget.key+"_"+this.widget.widget_number;
        div.style.position="relative";
        div.style.top="0px";
        div.style.left="0px";
        div.style.height="100%";
        div.style.width="100%";
	//Setting font-size to 0 fixes the difference between FF and IE in the initial space, but causes other problems.
	//Try setting the margin-top to 0 of all interior paragraphs.
        //div.style.fontSize="0";
        this.widget.div.appendChild(div);
        this.save_after_display = save;
        
        if(!this.ext_args)this.ext_args=new Array(); //pixelchutes
        this.ext_args.push('db_id='+this.widget.db_id); //pixelchutes
        
        cont_getHtml("/content/code/code_"+this.widget.key+".inc", this.disp_cb.bind(this), this.widget.widget_number, this.ext_args);
    },

    layer_info: function()
    {
        var layerInfo = "cont_mgr ";
        if (this.display_div != null)
            layerInfo += "display_div: "+this.display_div.style.zIndex;
        if (this.edit_div != null)
        {
            layerInfo += "edit_div: "+this.edit_div.style.zIndex;
        }
        if (this.bg_div != null)
        {
            layerInfo += "bg_div: "+this.bg_div.style.zIndex;
        }
        if (this.close_div != null)
        {
            layerInfo += "close_div: "+this.close_div.style.zIndex;
        }
        return(layerInfo+"<br/><br/>");
    },
   
    disp_cb: function(response)
    {
        insert_html_response(this.display_div, response);
        this.update_display();
        if (this.save_after_display)
        {
            this.save_after_display=false;
            this.widget.save();
        }
    },
    
    reset_display: function()
    {
    },
    
    update_display: function()
    {
    },
    
    edit: function()
    {
    },
    
    save: function()
    {
        var args = Array();
        for (var key in this.data)
        {
            if (typeof(this.data[key]) != 'function')
            {
		//We were having problems when someone saved a build-your-own widget with plus signs (+) in it (e.g. in Javascript code)
		//These + were being interpreted as spaces because the code was being passed as a URI component
		//As a result, we're now encoding the value before saving it.
		//Should we do this for every value?  The build-your-own-widget is the only one we've really seen problems with...
		var data_value = this.data[key];
		if (key == "code")
			data_value = encodeURIComponent(this.data[key]);

                args.push("data_"+key+"="+data_value);
                //args.push("data_"+key+"="+this.data[key]);
            }
        }
        args.push("updater_prefix=data_");
        if (this.widget.db_id == -1)
        {
            args.push("action=add");
        }
        else
        {
            args.push("action=update");
            args.push("content_id="+this.widget.db_id);
        }
        args.push("container="+this.widget.get_cont_number());
        args.push("list_order="+this.widget.get_list_order());
        args.push("posx="+this.widget.getx());
        args.push("posy="+this.widget.gety());
        args.push("posz="+this.widget.getz());
        args.push("width="+this.widget.width);
        args.push("height="+this.widget.height);
        args.push("index=1");
        args.push("content_1_title=none");
        args.push("content_type_id="+this.widget.get_content_type_id());
        if (this.widget.get_content_type_id()==7)
        {
            args.push("global_site=1");
            args.push("site_data_type=featured");
        }
        cont_cmUpdate(args, this.save_cb.bind(this));
        return(true);
    },
    save_position: function()
    {
        var args = Array();
		args.push("updater_prefix=data_");
        args.push("action=update_position");
        args.push("content_id="+this.widget.db_id);
        args.push("container="+this.widget.get_cont_number());
        args.push("list_order="+this.widget.get_list_order());
        args.push("posx="+this.widget.getx());
        args.push("posy="+this.widget.gety());
        args.push("posz="+this.widget.getz());
        args.push("width="+this.widget.total_width());
        args.push("height="+this.widget.total_height());
        args.push("index=1");
        cont_cmUpdate(args, this.save_cb.bind(this));

	if (typeof this.resize_cb == 'function')
		this.resize_cb();
    },
    
    save_border: function()
    {
        var args = Array();
        args.push("action=update_border");
		args.push("updater_prefix=data_");
        args.push("content_id="+this.widget.db_id);
        args.push("border_id="+this.widget.border.id);
        args.push("border_color="+this.widget.border.color);
        args.push("border_background="+this.widget.border.backgroundColor);
        cont_cmUpdate(args, this.save_cb.bind(this));
    },

    finish_save: function(response)
    {
        var update = response.getElementsByTagName('update');
        var db_id = update[0].getAttribute('content_id');
        if (db_id != null)
            this.widget.db_id = db_id;
        if (this.save_border_after_save)
        {
            this.save_border();
            this.save_border_after_save = false;
        }
        this.widget.save_cb(response);
    },
    
    save_cb: function(response)
    {
        this.finish_save(response);
        this.widget.cancel();
        this.update_display();
    },
    
    del: function()
    {
        var args = Array();
        args.push("action=remove");
		args.push("updater_prefix=data_");
        args.push("content_id="+this.widget.db_id);
        args.push("index=1");
        cont_cmUpdate(args, this.del_cb.bind(this));
    },
    
    del_cb: function(response)
    {
    
    },
    cancel: function()
    {
    },
    
    load_form : function (width, height, form_file, close_func)
    {
	//Horizontally center the popup on the screen
	form_left = Math.floor(1020/2-width/2);

	//Put the popup at the same height as the widget
	//top = 20; //WARNING: apparently "top" is an object...not sure where from.  Regardless, causes an error if you use.
	form_top = 20;
	if (this.widget && !isNaN(this.widget.gety()))
		form_top = this.widget.gety();

	//Form border/close button
        var div= this.bg_div = document.createElement("DIV");
        this.edit_id = "form_"+this.widget.widget_number;
        div.style.width= width+"px";
        div.style.height= height+"px";
        div.style.position="absolute";
        div.style.top=form_top;
	div.style.left=form_left;
        div.style.background="url(/shared/images/border.php?w="+width+"&h="+height+"&b=41&f=1&img=/shared/images/cal_bdr.png)";
        div.style.zIndex = "2000000";
        div.className = "png";
        $('wrapper').appendChild(div);

	//Contents of form
        div= this.edit_div = document.createElement("DIV");
        div.style.width= width+"px";
        div.style.height= height+"px";
        div.style.position="absolute";
        div.style.top=form_top;
        div.style.left=form_left;
        div.style.zIndex = "2000001";
        $('wrapper').appendChild(div);
        
	//Div over close button
        div=this.close_div = document.createElement("DIV");
        div.style.width = "40px";
        div.style.height="40px";
        div.style.position="absolute";
        div.style.top=form_top;
        div.style.left=form_left;
        div.style.cursor="pointer";
        div.onclick=close_func;
        div.style.zIndex = "2000002";
        $('wrapper').appendChild(div);

//        $('gray_page').style.visibility='visible';

        cont_getHtml("/content/form/"+form_file,  this.edit_cb.bind(this), this.widget.widget_number, new Array('id='+this.widget.db_id)); //pixelchutes
        return;
    },
    
    clear_form: function()
    {
//        $('gray_page').style.visibility='hidden';
        $('wrapper').removeChild(this.edit_div);
        $('wrapper').removeChild(this.bg_div);
        $('wrapper').removeChild(this.close_div);
    }
};



/* text widgets */

var cont_text1 = Class.create();
Object.extend(cont_text1.prototype, cont_class.prototype);

cont_text1.prototype.display = function()
{
    var wid_num = this.widget.get_widget_num();
    var data = this.widget.get_data();
    var t= this.table = document.createElement("TABLE");
    t.width = "100%";
    t.cellSpacing = "8px";
    t.cellPadding = "0";
    t.id="container_"+wid_num;
    var tb = document.createElement("TBODY");
    tb.id = "content_table"+wid_num;
    t.appendChild(tb);
    tr = document.createElement("TR");
    tb.appendChild(tr);
    var td = document.createElement("TD");
    td.className="page_header";
    tr.appendChild(td);
    var span = document.createElement("SPAN");
    span.id="content_"+wid_num+"_title";
    span.className = "cltblue";
    if (data['title'] != null)
    {
        this.title = document.createTextNode(data['title']);
        span.appendChild(this.title);
    }
    td.appendChild(span);
    this.title_span = span;
    tr = document.createElement("TR");
    tb.appendChild(tr);
    td=document.createElement("TD");
    td.className = "cdgrey page_text";
    tr.appendChild(td);
    span = document.createElement("SPAN");
    span.id="content_"+wid_num+"_body";
    if (data['body'] != null)
    {
        span.innerHTML = data['body'];
    }
    td.appendChild(span);
    this.body_span = span;
    this.widget.get_div().appendChild(t);
    if (this.editable)
    {
        this.editor= new InlineEditor(t, "content_"+wid_num+"_", cm_base_url+"&index="+wid_num);
        this.textarea = document.createElement("textarea");
        this.textarea.className = "form_input";
        this.textarea.cols = "30";
        this.textarea.rows = "5";
        this.editor.setInput("content_"+wid_num+"_body", this.textarea);
        
    }
};

cont_text1.prototype.edit = function()
{
/*    if (this.widget.border_div != null)
    {
        this.widget.border_div.style.display='none';
    }
*/
    this.save_pad_top = this.widget.div.style.paddingTop;
    this.widget.div.style.paddingTop = "10px";
    this.widget.div.style.zIndex = this.widget.layer +100000;
    this.widget.edit_buttons.style.zIndex = this.widget.layer+100000+54000;
    this.textarea.cols = Math.round(((this.widget.width-35) / 7));
    this.textarea.rows = Math.round(((this.widget.height - 85 )/ 16));
    this.editor.edit();
};

cont_text1.prototype.save = function()

{
    var db_id = this.widget.get_db_id();
    if (db_id == -1)
    {
        var action = "add";
    }
    else
    {
        action = "update";
    }
    var args = Array("container="+this.widget.get_cont_number(), "list_order="+this.widget.get_list_order(), "action="+action, "content_id="+db_id, "content_type_id="+this.widget.get_content_type_id());
    args.push("posx="+this.widget.getx());
    args.push("posy="+this.widget.gety());
    args.push("posz="+this.widget.getz());
    args.push("width="+this.widget.width);
    args.push("height="+this.widget.height);
    this.editor.save(this.save_cb.bind(this), args);

    this.widget.div.style.paddingTop = this.save_pad_top;
    return(true);
};
 
cont_text1.prototype.save_cb = function(response, update)
{
    this.widget.cancel();
    this.finish_save(response);
};

cont_text1.prototype.del = function()
{
    this.editor.save(this.widget.del_cb, new Array("action=remove", "content_id="+this.widget.get_db_id()));
};

cont_text1.prototype.cancel= function()
{
/*    if (this.widget.border_div != null)
    {
        this.widget.border_div.style.display='block';
    }
*/
    this.widget.div.style.paddingTop = this.save_pad_top;
    this.widget.div.style.zIndex = this.widget.layer;
    this.widget.edit_buttons.style.zIndex = this.widget.layer+54000;
    this.editor.cancel();
};

var cont_text2 = Class.create();
Object.extend(cont_text2.prototype, cont_class.prototype);

cont_text2.prototype.initialize = function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = null;
    this.edit_config = tiny_full_config;
};

cont_text2.prototype.update_display = function()
{
    this.display_div.style.height="";
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.text_div = this.display_div.getElementsByTagName('DIV')[0];
        this.text_div.id = 'text2_text_'+this.widget.widget_number;
    }
    else
    {
        this.text_div = $('text2_text_'+this.widget.widget_number);
    }
        
//bch36: apparently FF and IE handing the margins of <p> differently.  Set to something constant.
    this.text_div.innerHTML = "<style>p {margin-top: 0px;}</style>";
    this.text_div.innerHTML += this.data['text'];
};

cont_text2.prototype.imageSelected= function(parms)
{
	image_loading.win.document.getElementById('src').value = parms[0];
};

cont_text2.prototype.edit = function()
{
	//bch36: need to add callback for selecting from image library
    curImgSelFunc = this.imageSelected.bind(this);

    var h = this.widget.height;
    var w = this.widget.width < 520 ? 520 : this.widget.width;
    if (this.ed == null)
    {
        var id = this.id = 'text2_area_'+this.widget.widget_number;
        var editor_div = this.edit_div = document.createElement("DIV");
        editor_div.style.position="absolute";
        editor_div.style.top=this.widget.get_div().style.top;//0;//this.widget.rel_x-125;
        editor_div.style.left="50%";
        editor_div.style.marginLeft=-340;
        editor_div.id = "my_editor";
        editor_div.name = "my_editor";
        editor_div.style.zIndex = "900000";
        var text2= this.text_area = document.createElement("TEXTAREA");
        text2.id = id;
        text2.name= id;
        text2.cols = "50";
        text2.rows = "14";
        text2.className = this.edit_class;
        text2.value = this.data['text'];
        text2.style.zIndex = "900001";
        editor_div.appendChild(text2);
        $('wrapper').appendChild(editor_div);
        myCallback = this.post_render_cb.bind(this);
        this.tiny = tinyMCE.init(this.edit_config);
        this.ed = tinyMCE.getInstanceById(id);

        if (this.ed == null)
            tinyMCE.execCommand('mceAddControl', false, id);
    }
    else
    {
        this.edit_div.style.display="block";
        this.ed.show();
        this.ed.load();
    }

    return(true);
};

cont_text2.prototype.post_render_cb = function(ed, cb)
{
    this.ed = tinyMCE.getInstanceById(this.id);
    this.ed.my_class = this;
};

var myCallback;

cont_text2.prototype.saveit = function()
{
    this.text_div.innerHTML = this.data['text'] = this.ed.save();
    this.widget.save();
    this.ed.hide();
    this.edit_div.style.display="none";
};
cont_text2.prototype.cancelit = function()
{
//    this.text_area.innerHTML = this.text_div.value;
    this.ed.load();
    this.ed.hide();
    this.edit_div.style.display="none";
    this.widget.cancel();
};

var cont_text4 = Class.create();
Object.extend(cont_text4.prototype, cont_class.prototype);

cont_text4.prototype.initialize = function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = null;
    this.edit_config = tiny_full_config;
};

cont_text4.prototype.update_display = function()
{
    this.display_div.style.height="";
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.text_div = this.display_div.getElementsByTagName('DIV')[0];
        this.text_div.id = 'text4_text_'+this.widget.widget_number;
    }
    else
    {
        this.text_div = $('text4_text_'+this.widget.widget_number);
    }
        
//bch36: apparently FF and IE handing the margins of <p> differently.  Set to something constant.
    this.text_div.innerHTML = "<style>p {margin-top: 0px;}</style>";
    this.text_div.innerHTML += this.data['text'];
};

cont_text4.prototype.imageSelected= function(parms)
{
	image_loading.win.document.getElementById('src').value = parms[0];
};

cont_text4.prototype.edit = function()
{
	//bch36: need to add callback for selecting from image library
    curImgSelFunc = this.imageSelected.bind(this);

    var h = this.widget.height;
    var w = this.widget.width < 520 ? 520 : this.widget.width;
    if (this.ed == null)
    {
        var id = this.id = 'text4_area_'+this.widget.widget_number;
        var editor_div = this.edit_div = document.createElement("DIV");
        editor_div.style.position="absolute";
        editor_div.style.top=this.widget.get_div().style.top;//0;//this.widget.rel_x-125;
        editor_div.style.left="50%";
        editor_div.style.marginLeft=-340;
        editor_div.id = "my_editor";
        editor_div.name = "my_editor";
        editor_div.style.zIndex = "900000";
        var text4= this.text_area = document.createElement("TEXTAREA");
        text4.id = id;
        text4.name= id;
        text4.cols = "50";
        text4.rows = "14";
        text4.className = this.edit_class;
        text4.value = this.data['text'];
        text4.style.zIndex = "900001";
        editor_div.appendChild(text4);
        $('wrapper').appendChild(editor_div);
        myCallback = this.post_render_cb.bind(this);
        this.tiny = tinyMCE.init(this.edit_config);
        this.ed = tinyMCE.getInstanceById(id);

        if (this.ed == null)
            tinyMCE.execCommand('mceAddControl', false, id);
    }
    else
    {
        this.edit_div.style.display="block";
        this.ed.show();
        this.ed.load();
    }

    return(true);
};

cont_text4.prototype.post_render_cb = function(ed, cb)
{
    this.ed = tinyMCE.getInstanceById(this.id);
    this.ed.my_class = this;
};

var myCallback;

cont_text4.prototype.saveit = function()
{
    this.text_div.innerHTML = this.data['text'] = this.ed.save();
    this.widget.save();
    this.ed.hide();
    this.edit_div.style.display="none";
};
cont_text4.prototype.cancelit = function()
{
//    this.text_area.innerHTML = this.text_div.value;
    this.ed.load();
    this.ed.hide();
    this.edit_div.style.display="none";
    this.widget.cancel();
};
// Bio widget
var cont_bio1 = Class.create();
Object.extend(cont_bio1.prototype, cont_class.prototype);

cont_bio1.prototype.initialize = function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = null;
    this.edit_config = tiny_full_config;
};

cont_bio1.prototype.update_display = function()
{
    this.display_div.style.height="";
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.text_div = this.display_div.getElementsByTagName('DIV')[0];
        this.text_div.id = 'bio1_text_'+this.widget.widget_number;
    }
    else
    {
        this.text_div = $('bio1_text_'+this.widget.widget_number);
    }
        
	/* bch36: removed this so it would work properly
    if (this.data['text'])
    	this.text_div.innerHTML = this.data['text'];
	*/
};

cont_bio1.prototype.edit = function()
{
//bch36: This was confusing people. Only allow them to edit their bio one place.
alert("Edit your bio under Account Information in the administration section of your website.");
return false; //bch36: no editing of bio here?
    var h = this.widget.height;
    var w = this.widget.width < 520 ? 520 : this.widget.width;
    if (this.ed == null)
    {
        var id = this.id = 'bio1_area_'+this.widget.widget_number;
        var editor_div = this.edit_div = document.createElement("DIV");
        editor_div.style.position="absolute";
        editor_div.style.top=0;
        editor_div.style.left=0;
        editor_div.id = "my_editor";
        editor_div.name = "my_editor";
        editor_div.style.zIndex = "900000";
        var bio1= this.text_area = document.createElement("TEXTAREA");
        bio1.id = id;
        bio1.name= id;
        bio1.cols = "50";
        bio1.rows = "14";
        bio1.className = this.edit_class;
        bio1.value = this.data['text'];
        bio1.style.zIndex = "900001";
        editor_div.appendChild(bio1);
        $('wrapper').appendChild(editor_div);
        myCallback = this.post_render_cb.bind(this);
        this.tiny = tinyMCE.init(this.edit_config);
        this.ed = tinyMCE.getInstanceById(id);
        if (this.ed == null)
            tinyMCE.execCommand('mceAddControl', false, id);
    }
    else
    {
        this.edit_div.style.display="block";
        this.ed.show();
        this.ed.load();
    }

    return(true);
};

cont_bio1.prototype.post_render_cb = function(ed, cb)
{
    this.ed = tinyMCE.getInstanceById(this.id);
    this.ed.my_class = this;
};


cont_bio1.prototype.saveit = function()
{
    this.text_div.innerHTML = this.data['text'] = this.ed.save();
    this.widget.save();
    this.ed.hide();
    this.edit_div.style.display="none";
};
cont_bio1.prototype.cancelit = function()
{
//    this.text_area.innerHTML = this.text_div.value;
    this.ed.load();
    this.ed.hide();
    this.edit_div.style.display="none";
    this.widget.cancel();
};
// Bio widget #2
var cont_bio2 = Class.create();
Object.extend(cont_bio2.prototype, cont_class.prototype);

cont_bio2.prototype.initialize = function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = null;
    this.edit_config = tiny_full_config;
};

cont_bio2.prototype.update_display = function()
{
    this.display_div.style.height="";
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.text_div = this.display_div.getElementsByTagName('DIV')[0];
        this.text_div.id = 'bio2_text_'+this.widget.widget_number;
    }
    else
    {
        this.text_div = $('bio2_text_'+this.widget.widget_number);
    }
        
    
    this.text_div.innerHTML = this.data['text'];
};
cont_bio2.prototype.edit = function()
{
    var h = this.widget.height;
    var w = this.widget.width < 520 ? 520 : this.widget.width;
    if (this.ed == null)
    {
        var id = this.id = 'bio2_area_'+this.widget.widget_number;
        var editor_div = this.edit_div = document.createElement("DIV");
        editor_div.style.position="absolute";
        editor_div.style.top=0;
        editor_div.style.left=0;
        editor_div.id = "my_editor";
        editor_div.name = "my_editor";
        editor_div.style.zIndex = "900000";
        var bio2= this.text_area = document.createElement("TEXTAREA");
        bio2.id = id;
        bio2.name= id;
        bio2.cols = "50";
        bio2.rows = "14";
        bio2.className = this.edit_class;
        bio2.value = this.data['text'];
        bio2.style.zIndex = "900001";
        editor_div.appendChild(bio2);
        $('wrapper').appendChild(editor_div);
        myCallback = this.post_render_cb.bind(this);
        this.tiny = tinyMCE.init(this.edit_config);
        this.ed = tinyMCE.getInstanceById(id);
        if (this.ed == null)
            tinyMCE.execCommand('mceAddControl', false, id);
    }
    else
    {
        this.edit_div.style.display="block";
        this.ed.show();
        this.ed.load();
    }

    return(true);
};

cont_bio2.prototype.post_render_cb = function(ed, cb)
{
    this.ed = tinyMCE.getInstanceById(this.id);
    this.ed.my_class = this;
};

cont_bio2.prototype.saveit = function()
{
    this.text_div.innerHTML = this.data['text'] = this.ed.save();
    this.widget.save();
    this.ed.hide();
    this.edit_div.style.display="none";
};
cont_bio2.prototype.cancelit = function()
{
//    this.text_area.innerHTML = this.text_div.value;
    this.ed.load();
    this.ed.hide();
    this.edit_div.style.display="none";
    this.widget.cancel();
};

//   img1 widget
var curImgSelFunc;               
function imageSelected(control, src)
{
	var parms = Array(control, src);
    curImgSelFunc(parms);
};

var updateTextBg;
var updateTextColor;

//A couple more for the color choosers on the featprop3 widget:
var updateBackgroundColor;
var updateBorderColor;
var data_backgroundColor = "737373";
var data_borderColor = "FFFFFF";

//A couple more for the color choosers on the recent posts widget
var updateTitleColor;
var updateLinkColor;
var data_titleColor;
var data_linkColor;

//Another one for the market snapshot widget
var updateText2Color;
var data_text2Color;
var updateText3Color;
var data_text3Color;

var data_textColor = "ffffff";
var data_textBg = "000000";
var cont_img1 = Class.create()
Object.extend(cont_img1.prototype, cont_class.prototype);
cont_img1.prototype.initialize= function(editable, widget)
{
    this.editable = editable;
    this.widget=widget;
    this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
};
cont_img1.prototype.display= function(save)
{
    this.data = this.widget.get_data();
    var wid_num = this.widget.get_widget_num();
    this.preview(this.widget.get_div(), this.widget.get_data(), this.widget.width, this.widget.height, wid_num);
    if (save)
        this.save();
};
    
cont_img1.prototype.preview= function(par_div, data, width, height, wid_num)
{
    if (data == null)
    {
        data = this.def();
    }
    if (data['remove_bar'] == 'true' || data['remove_bar'] == true)
    {
        this.bar_height = 0;
    }
    else
    {
        this.bar_height = 30;
    }
    if (data['href'] == null)
    {
        data['href'] = '#';
    }
    var t = document.createElement("TABLE");
//    t.width = width;
//    t.height = height;
    t.cellSpacing = "0";
    t.cellPadding = "0";
    t.id="container_"+wid_num;
    var tb = document.createElement("TBODY");
    tb.id = "content_table"+wid_num;
    t.appendChild(tb);
    var tr = document.createElement("TR");
    tb.appendChild(tr);
    var td = document.createElement("TD");
    tr.appendChild(td);
    var a = td; // in case of no link, skip adding it
    if (data['href'] != '' && data['href'] != '#')
    {
        a = document.createElement("A");
        a.href = data['href'];
        a.id = "img1_anchor_"+wid_num;
        td.appendChild(a);
    }
    var img = this.img = document.createElement("IMG");
    img.border="0";
    img.id="img1_"+wid_num;
    img.src = data['src'];
    if (data['use_image_size'] != 'true')
    {
        img.width=width;
        img.height = height-this.bar_height;
    }
    img.className = 'png';
    a.appendChild(img);
    tr = document.createElement("TR");
    tb.appendChild(tr);
    td = document.createElement("TD");
    td.valign="middle";
    td.height="30";
    td.align="center";
    if (data['href'] != null)
        td.onclick="goToPage('"+data['href']+"');";
    td.style.cursor="pointer";
    td.style.className="cwhite borange";
    td.style.color = data['color'];
    td.style.backgroundColor = data['backgroundColor'];
    td.id="img1_text_"+wid_num;
    if (data['remove_bar'] == 'true' || data['remove_bar'] == true)
    {
        this.bar_height = 0;
        td.style.display='none';
    }
    tr.appendChild(td);
    var div=document.createElement("DIV");
    div.id="desc_"+wid_num;
    if (data['font_size'] != null && (data['font_size'].length > 0))
        div.style.fontSize = data['font_size']+"px";
    div.style.fontFamily= data['font'];
    div.style.paddingLeft="10px";
    div.style.paddingRight="10px";
    if (data['desc'] != null)
        div.appendChild(document.createTextNode(data['desc']));
    td.appendChild(div);
    par_div.appendChild(t);
};

cont_img1.prototype.reset_display = function()
{
    if (this.data['remove_bar'] && this.data['remove_bar'] != 'false')
        this.bar_height = 0;
    else
        this.bar_height = $('img1_text_'+this.widget.get_widget_num()).offsetHeight;
    if (this.data['use_image_size'] != 'true')
    {
        this.img.width = this.widget.width;
    //    this.img.height= this.widget.height;
        this.img.height = this.widget.height-this.bar_height;
    }
    else
    {
//	if (ie6)
//        {
//            this.img.width= this.img.naturalWidth;
//            this.img.height= this.img.naturalHeight;
//        }
//        else
//        {
            this.img.removeAttribute("width");
            this.img.removeAttribute("height");
//        }
    }
};
    
cont_img1.prototype.update_display= function()
{
    var wid_num = this.widget.get_widget_num();
    if (this.data['href'] != null)
    {
	if ($('img1_anchor_'+wid_num))
		$('img1_anchor_'+wid_num).href = this.data['href'];
	if ($('img1_text'+wid_num))
		$('img1_text_'+wid_num).onclick="goToPage('"+this.data['href']+"');";
    }
    if (this.data['src'] != null)
        $('img1_'+wid_num).src = this.data['src'];
    if (this.data['color'] != null)
        $('img1_text_'+wid_num).style.color=this.data['color'];
    if (this.data['backgroundColor'] != null)
        $('img1_text_'+wid_num).style.backgroundColor=this.data['backgroundColor'];
    if (this.data['font_size'] != null)
        $('img1_text_'+wid_num).style.fontSize=this.data['font_size']+"px";
    if (this.data['font'] != null)
        $('img1_text_'+wid_num).style.fontFamily=this.data['font'];
    if (this.data['desc'] != null)
        $('img1_text_'+wid_num).innerHTML=this.data['desc'];
    if (this.data['remove_bar'] == 'true' ||  this.data['remove_bar'] == true)
    {
        $('img1_text_'+wid_num).style.display='none';
    }
    else
    {
        $('img1_text_'+wid_num).style.display='';
    }
    this.reset_display();
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
};

cont_img1.prototype.def= function()
{
    var data = Array();
    data['href'] = "/";
    data['src'] = "/shared/images/nophoto.gif";
    data['desc1'] = "Description";
    data['desc2'] = "Goes Here";
    data['bg_class'] = "borange";
    return(data);
};

cont_img1.prototype.edit= function()
{
    this.load_form(650, 500, 'frm_img1.inc', this.save.bind(this));
};
    
cont_img1.prototype.updateText= function()
{   
    $('data_desc').innerHTML = this.data['desc']= $('data_text').value;
    
};
    
cont_img1.prototype.updateFont= function ()
{
    $('data_desc').style.fontFamily= this.data['font'] =  $('data_font').options[$('data_font').selectedIndex].value;
};
    
cont_img1.prototype.updateFontSize= function ()
{
    $('data_desc').style.fontSize= this.data['font_size'] =  $('data_font_size').options[$('data_font_size').selectedIndex].value;
};
    
cont_img1.prototype.updateTextColor= function (color)
{
    data_textColor = color;
    $('data_desc').style.color = "#"+color;
    this.data['color'] = color;
};
    
cont_img1.prototype.updateTextBg= function (color)
{
    data_textBg = color;
    $('data_desc').style.backgroundColor =  $('color_sample').style.backgroundColor = "#"+color;
    this.data['backgroundColor'] = color;
};
    
cont_img1.prototype.updateImage= function ()
{
    var imageWindow = window.open('/site/image_manage.php?site_id='+site_id+'&control=find_img&dir=small', 'images', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=1280,height=800');
};
    
cont_img1.prototype.imageSelected= function(parms)
{
    $('data_img1').src = this.data['src'] =  parms[0];
};

cont_img1.prototype.updateLink = function()
{
    this.data['href'] = $('data_url_link').value;
};

cont_img1.prototype.updateLocLink = function()
{
    this.data['href'] = $('data_url_link').value = $('data_local_link').options[$('data_local_link').selectedIndex].value;
};

cont_img1.prototype.updateRemoveBar = function()
{
    var remove = $('data_remove_bar').checked;
    if (remove)
    {
        this.data['remove_bar'] = 'true';
        $('data_desc').style.display='none';
    }
    else
    {
        this.data['remove_bar'] = 'false';
        $('data_desc').style.display='';
    }
};

cont_img1.prototype.imageSizeWidget = function()
{
    this.data['use_image_size'] = 'false';
    $('data_img1').width=this.widget.width;
    $('data_img1').height=this.widget.height- this.bar_height;
};

cont_img1.prototype.imageSizePhoto = function()
{
    this.data['use_image_size'] = 'true';
    var img = $('data_img1');
    var checkImg = new Image();
    checkImg.src= this.data['src'];
    img.width= checkImg.width;
    img.height= checkImg.height;
};

cont_img1.prototype.scaleAndCrop = function()
{
    $('scale_crop_div').style.display="";
    CropImage.init(this.data['src'], $('scale_crop_div'), this.widget.width, this.widget.height, this.scaleCropCB.bind(this));
}

cont_img1.prototype.scaleCropCB = function(new_url, update)
{
    $('scale_crop_div').style.display="none";
    if (update)
    {
        $('data_img1').src = this.data['src'] =  new_url;
    }
}


cont_img1.prototype.edit_cb= function(response)
{
    var data = this.data;
    insert_html_response(this.edit_div, response);
    $('color_pick_wrap').appendChild($('plugin'));
    // setup updates
    $('data_text').onkeyup= this.updateText.bind(this);
    $('select_img_btn').onclick= this.updateImage.bind(this);
    $('image_size_widget').onclick= this.imageSizeWidget.bind(this);
    $('image_size_photo').onclick= this.imageSizePhoto.bind(this);
    $('scale_crop').onclick= this.scaleAndCrop.bind(this);
    $('data_font').onchange= this.updateFont.bind(this);
    $('data_font_size').onchange= this.updateFontSize.bind(this);
    $('data_save').onclick= this.save.bind(this);
    $('data_cancel').onclick= this.widget.cancel.bind(this.widget);
    $('data_url_link').onchange= this.updateLink.bind(this);
    $('data_local_link').onchange= this.updateLocLink.bind(this);
    $('data_remove_bar').onclick= this.updateRemoveBar.bind(this);
    updateTextBg = this.updateTextBg.bind(this);
    updateTextColor = this.updateTextColor.bind(this);
    curImgSelFunc = this.imageSelected.bind(this);
    
    $('data_img1').src = this.data['src'];
    $('data_desc').innerHTML = this.data['desc'];
    $('data_text').value = this.data['desc'];
    $('data_desc').style.fontFamily = this.data['font'];
    if (this.data['font_size'] != null)
        $('data_desc').style.fontSize = this.data['font_size'];
    if (this.data['color'])
        $('data_desc').style.color = data_textColor = this.data['color'];
    if (this.data['backgroundColor'] != null)
        $('data_desc').style.backgroundColor = $('color_sample').style.backgroundColor = data_textBg = this.data['backgroundColor'];
    if (this.data['href'] != null)
        $('data_url_link').value = this.data['href'];
    if (this.data['remove_bar'] == 'true' || data['remove_bar'] == true)
    {
        $('data_remove_bar').checked = true;
    }
    if (this.data['use_image_size'] != 'true')
    {
        $('data_img1').width=this.widget.width;
        $('data_img1').height=this.widget.height- this.bar_height;
    }
    this.updateRemoveBar();
}

cont_img1.prototype.cancel= function()
{
    $('plugin').style.display='none';
    $('wrapper').appendChild($('plugin'));
    this.clear_form();
}

cont_img1.prototype.get_aspect_ratio = function(width, height, max_width, max_height)
{
	width_ratio = 1;
	height_ratio = 1;

	if (width > max_width)
		width_ratio = max_width/width;
	if (height > max_height)
		height_ratio = max_height/height;

	min_ratio = min(width_ratio, height_ratio);

	return new Array(width * min_ratio, height * min_ratio);
}
   
var cont_img4 = Class.create()
Object.extend(cont_img4.prototype, cont_class.prototype);
cont_img4.prototype.initialize= function(editable, widget)
{
    this.editable = editable;
    this.widget=widget;
    this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}
cont_img4.prototype.display= function(save)
{
    this.data = this.widget.get_data();
    var wid_num = this.widget.get_widget_num();
    this.preview(this.widget.get_div(), this.widget.get_data(), this.widget.width, this.widget.height, wid_num);
    if (save)
        this.save();
}
    
cont_img4.prototype.preview= function(par_div, data, width, height, wid_num)
{
    if (data == null)
    {
        data = this.def();
    }
    if (data['remove_bar'] == 'true')
    {
        this.bar_width = 0;
    }
    else
    {
        this.bar_width = Math.round(width/3);
    }
    var t = document.createElement("TABLE");
/*    t.width = width; */
/*    t.height = height; */
    t.cellSpacing = "0";
    t.cellPadding = "0";
    t.id="container_"+wid_num;
    var tb = document.createElement("TBODY");
    tb.id = "content_table"+wid_num;
    t.appendChild(tb);
    var tr = document.createElement("TR");
    tb.appendChild(tr);
    var td = document.createElement("TD");
    tr.appendChild(td);
    var a = document.createElement("A");
    a.href = data['href'];
    a.id = "img4_anchor_"+wid_num;
    td.appendChild(a);
    var img = this.img = document.createElement("IMG");
    img.border="0";
    img.id="img4_"+wid_num;
    img.src = data['src'];
    img.width=width-this.bar_width;
    img.height = height;
    a.appendChild(img);
//    tr = document.createElement("TR");
//    tb.appendChild(tr);
    this.bar = td = document.createElement("TD");
    td.valign="middle";
    if (this.bar_width == 0)
        td.width=1; // IE won't tak 0 as a width.
    else
        td.width = this.bar_width;
    td.align="center";
    if (data['href'] != null)
        td.onclick="goToPage('"+data['href']+"');";
    td.style.cursor="pointer";
    td.className="cwhite borange";
    td.style.color = data['color'];
    td.style.backgroundColor = data['backgroundColor'];
    td.id="img4_text_"+wid_num;
    if (data['remove_bar'] == 'true')
    {
        td.style.display='none';
    }
    tr.appendChild(td);
    var div=document.createElement("DIV");
    div.id="desc_"+wid_num;
    if (data['font_size'] != null)
        div.style.fontSize = data['font_size']+"px";
    div.style.fontFamily= data['font'];
    div.style.paddingLeft="10px";
    div.style.paddingRight="10px";
    if (data['desc'] != null)
        div.appendChild(document.createTextNode(data['desc']));
    td.appendChild(div);
    par_div.appendChild(t);
}

cont_img4.prototype.reset_display = function()
{
    this.img.height = this.widget.height;
//    this.img.height= this.widget.height;
    if ((this.data['remove_bar'] != null) && (this.data['remove_bar']== true || this.data['remove_bar'] == 'true'))
        this.bar_width = 0;
    else
        this.bar_width = Math.round(this.widget.width /3);
    this.img.width = this.widget.width -this.bar_width;
    this.bar.width = this.bar_width == 0 ? 1 : this.bar_width;
}
    
cont_img4.prototype.update_display= function()
{
    var wid_num = this.widget.get_widget_num();
    if (this.data['href'] != null)
    {
        $('img4_anchor_'+wid_num).href = this.data['href'];
        $('img4_text_'+wid_num).onclick="goToPage('"+this.data['href']+"');";
    }
    if (this.data['src'] != null)
        $('img4_'+wid_num).src = this.data['src'];
    if (this.data['color'] != null)
        $('img4_text_'+wid_num).style.color=this.data['color'];
    if (this.data['backgroundColor'] != null)
        $('img4_text_'+wid_num).style.backgroundColor=this.data['backgroundColor'];
    if (this.data['font_size'] != null)
        $('img4_text_'+wid_num).style.fontSize=this.data['font_size']+"px";
    if (this.data['font'] != null)
        $('img4_text_'+wid_num).style.fontFamily=this.data['font'];
    if (this.data['desc'] != null)
        $('img4_text_'+wid_num).innerHTML=this.data['desc'];
    if (this.data['remove_bar'] == 'true' ||  this.data['remove_bar'] == true)
    {
        $('img4_text_'+wid_num).style.display='none';
    }
    else
    {
        $('img4_text_'+wid_num).style.display='';
    }
    this.reset_display();
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}

cont_img4.prototype.def= function()
{
    var data = Array();
    data['href'] = "/";
    data['src'] = "/shared/images/nophoto.gif";
    data['desc1'] = "Description";
    data['desc2'] = "Goes Here";
    data['bg_class'] = "borange";
    return(data);
}

cont_img4.prototype.edit= function()
{
    this.load_form(660, 535, 'frm_img4.inc', this.save.bind(this));
}
    
cont_img4.prototype.updateText= function()
{   
    $('data_desc').innerHTML = this.data['desc']= $('data_text').value;
    
}
    
cont_img4.prototype.updateFont= function ()
{
    $('data_desc').style.fontFamily= this.data['font'] =  $('data_font').options[$('data_font').selectedIndex].value;
}
    
cont_img4.prototype.updateFontSize= function ()
{
    $('data_desc').style.fontSize= this.data['font_size'] =  $('data_font_size').options[$('data_font_size').selectedIndex].value;
}
    
cont_img4.prototype.updateTextColor= function (color)
{
    data_textColor = color;
    $('data_desc').style.color = "#"+color;
    this.data['color'] = color;
}
    
cont_img4.prototype.updateTextBg= function (color)
{
    data_textBg = color;
    $('data_desc').style.backgroundColor =  $('color_sample').style.backgroundColor = "#"+color;
    this.data['backgroundColor'] = color;
}
    
cont_img4.prototype.updateImage= function ()
{
    var imageWindow = window.open('/site/image_manage.php?site_id='+site_id+'&control=find_img&dir=large', 'images', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=1280,height=800');
}
    
cont_img4.prototype.imageSelected= function(parms)
{
    $('data_img4').src = this.data['src'] =  parms[0];
}

cont_img4.prototype.updateLink = function()
{
    this.data['href'] = $('data_url_link').value;
}

cont_img4.prototype.updateLocLink = function()
{
    this.data['href'] = $('data_url_link').value = $('data_local_link').options[$('data_local_link').selectedIndex].value;
}

cont_img4.prototype.updateRemoveBar = function()
{
    var remove = $('data_remove_bar').checked;
    if (remove)
    {
        this.data['remove_bar'] = 'true';
        $('data_desc').style.display='none';
    }
    else
    {
        this.data['remove_bar'] = 'false';
        $('data_desc').style.display='';
    }
}
cont_img4.prototype.edit_cb= function(response)
{
    var data = this.data;
    insert_html_response(this.edit_div, response);
    $('color_pick_wrap').appendChild($('plugin'));
    // setup updates
    $('data_text').onkeyup= this.updateText.bind(this);
    $('select_img_btn').onclick= this.updateImage.bind(this);
    $('data_font').onchange= this.updateFont.bind(this);
    $('data_font_size').onchange= this.updateFontSize.bind(this);
    $('data_save').onclick= this.save.bind(this);
    $('data_cancel').onclick= this.widget.cancel.bind(this.widget);
    $('data_url_link').onchange= this.updateLink.bind(this);
    $('data_local_link').onchange= this.updateLocLink.bind(this);
    $('data_remove_bar').onclick= this.updateRemoveBar.bind(this);
    updateTextBg = this.updateTextBg.bind(this);
    updateTextColor = this.updateTextColor.bind(this);
    curImgSelFunc = this.imageSelected.bind(this);
    
    $('data_img4').src = this.data['src'];
    $('data_desc').innerHTML = this.data['desc'];
    $('data_text').value = this.data['desc'];
    $('data_desc').style.fontFamily = this.data['font'];
    if (this.data['font_size'] != null)
        $('data_desc').style.fontSize = this.data['font_size'];
    if (this.data['color'])
        $('data_desc').style.color = data_textColor = this.data['color'];
    if (this.data['backgroundColor'] != null)
        $('data_desc').style.backgroundColor = $('color_sample').style.backgroundColor = data_textBg = this.data['backgroundColor'];
    if (this.data['href'] != null)
        $('data_url_link').value = this.data['href'];
    if (this.data['remove_bar'] == 'true')
    {
        $('data_remove_bar').checked = true;
    }
    this.updateRemoveBar();
}

cont_img4.prototype.cancel= function()
{
    $('plugin').style.display='none';
    $('wrapper').appendChild($('plugin'));
    this.clear_form();
}
   
var cont_text3 = Class.create();
Object.extend(cont_text3.prototype,cont_class.prototype);
cont_text3.prototype.update_display = function()
{
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        var bg_el = this.widget.div.getElementsByTagName('TABLE')[0];
        bg_el.id = 'text3_bg_'+this.widget.widget_number;
        var text_el = this.widget.div.getElementsByTagName('SPAN')[0];
        text_el.id = 'text3_text_'+this.widget.widget_number;
    }
    else
    {
        bg_el= $('text3_bg_'+this.widget.widget_number);
        text_el = $('text3_text_'+this.widget.widget_number);
    }
        
    
    bg_el.style.backgroundColor = this.data['backgroundColor'];
    text_el.style.color = this.data['color'];
    text_el.style.fontFamily = this.data['font'];
    text_el.style.fontSize = this.data['fontSize'];
    text_el.innerHTML = this.data['text'];
}

cont_text3.prototype.edit = function()
{
    this.load_form(600, 375, 'frm_text3.inc', this.save.bind(this));
}
cont_text3.prototype.updateText= function()
{   
    $('form_text').innerHTML = this.data['text']= $('data_text').value;
}
    
cont_text3.prototype.updateFont= function ()
{
    $('form_text').style.fontFamily= this.data['font'] =  $('data_font').options[$('data_font').selectedIndex].value;
}
    
cont_text3.prototype.updateFontSize= function ()
{
    $('form_text').style.fontSize= this.data['fontSize'] =  $('data_font_size').options[$('data_font_size').selectedIndex].value;
}
    
cont_text3.prototype.updateTextColor= function (color)
{
    data_textColor = color;
    $('form_text').style.color = "#"+color;
    this.data['color'] = color;
}
    
cont_text3.prototype.updateTextBg= function (color)
{
    data_textBg = color;
    $('form_text').style.backgroundColor =  $('color_sample').style.backgroundColor = "#"+color;
    this.data['backgroundColor'] = color;
}
cont_text3.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    $('color_pick_wrap').appendChild($('plugin'));
    
    // setup updates
    $('data_text').onkeyup= this.updateText.bind(this);
    $('data_font').onchange= this.updateFont.bind(this);
    $('data_font_size').onchange= this.updateFontSize.bind(this);
    $('data_save').onclick= this.save.bind(this);
    $('data_cancel').onclick= this.widget.cancel.bind(this.widget);
    updateTextBg = this.updateTextBg.bind(this);
    updateTextColor = this.updateTextColor.bind(this);
    
    $('form_text').innerHTML = this.data['text'];
    $('data_text').value = this.data['text'];
    $('form_text').style.fontFamily = this.data['font'];
    $('form_text').style.fontSize = this.data['fontSize'];
    $('form_text').style.color = data_textColor = this.data['color'];
    $('form_bg').style.backgroundColor = $('color_sample').style.backgroundColor = data_textBg = this.data['backgroundColor'];
}
/*cont_text3.prototype.save_cb= function(response)
{
    var update = response.getElementsByTagName('update');
    
    this.widget.db_id = update[0].getAttribute('content_id');
    this.update_display();
    this.widget.cancel();
}
*/
cont_text3.prototype.cancel= function()
{
    $('plugin').style.display='none';
    $('wrapper').appendChild($('plugin'));
    this.clear_form();
}


// this function will replace cdgrey, corange and cltblue text colors with a configured text color. Assign it to the content class' update_display method.

function changeTextClass()
{
    if (this.widget.data['text_class'] != null)
    {
        var newClass = this.widget.data['text_class'];
        var els = $(this.widget.div).select(".cdgrey");
        els.each(function(el)
        {
            el.removeClassName("cdgrey");
            el.addClassName(newClass);
        });
        els = this.widget.div.select(".corange");
        els.each(function(el)
        {
            el.removeClassName("corange");
            el.addClassName(newClass);
        });
        els = this.widget.div.select(".cltblue");
        els.each(function(el)
        {
            el.removeClassName("cltblue");
            el.addClassName(newClass);
        });
    }
}

var cont_search1 = Class.create();
Object.extend(cont_search1.prototype,cont_class.prototype);

var cont_search2 = Class.create();
Object.extend(cont_search2.prototype,cont_class.prototype);
cont_search2.prototype.update_display = changeTextClass;

var cont_search3 = Class.create();
Object.extend(cont_search3.prototype,cont_class.prototype);

var cont_search4 = Class.create();
Object.extend(cont_search4.prototype,cont_class.prototype);

var cont_search_pruflorida2 = Class.create();
Object.extend(cont_search_pruflorida2.prototype,cont_class.prototype);

var cont_search_bell = Class.create();
Object.extend(cont_search_bell.prototype,cont_class.prototype);
cont_search_bell.prototype.update_display = changeTextClass;

var cont_search_knoxville = Class.create();
Object.extend(cont_search_knoxville.prototype,cont_class.prototype);
cont_search_knoxville.prototype.update_display = changeTextClass;

var cont_search_knoxville_2 = Class.create();
Object.extend(cont_search_knoxville_2.prototype,cont_class.prototype);
cont_search_knoxville_2.prototype.update_display = changeTextClass;

var cont_search_pureutah = Class.create();
Object.extend(cont_search_pureutah.prototype,cont_class.prototype);
cont_search_pureutah.prototype.update_display = changeTextClass;

var cont_search_prucolorado = Class.create();
Object.extend(cont_search_prucolorado.prototype,cont_class.prototype);
cont_search_prucolorado.prototype.update_display = changeTextClass;

var cont_search_prusantafe = Class.create();
Object.extend(cont_search_prusantafe.prototype,cont_class.prototype);
cont_search_prusantafe.prototype.update_display = changeTextClass;

var cont_search_pruarizona = Class.create();
Object.extend(cont_search_pruarizona.prototype,cont_class.prototype);
cont_search_pruarizona.prototype.update_display = changeTextClass;

var cont_search_ramb1 = Class.create();
Object.extend(cont_search_ramb1.prototype,cont_class.prototype);
cont_search_ramb1.prototype.update_display = changeTextClass;

var cont_search_registermarketing = Class.create();
Object.extend(cont_search_registermarketing.prototype,cont_class.prototype);
cont_search_registermarketing.prototype.update_display = changeTextClass;

var cont_search_empty = Class.create();
Object.extend(cont_search_empty.prototype,cont_class.prototype);
cont_search_empty.prototype.update_display = changeTextClass;

var cont_search_pruholmes = Class.create();
Object.extend(cont_search_pruholmes.prototype,cont_class.prototype);
cont_search_pruholmes.prototype.update_display = changeTextClass;

var cont_search_pruholmes_broker = Class.create();
Object.extend(cont_search_pruholmes_broker.prototype,cont_class.prototype);
cont_search_pruholmes_broker.prototype.update_display = changeTextClass;

var cont_search_prutexas_small = Class.create();
Object.extend(cont_search_prutexas_small.prototype,cont_class.prototype);
cont_search_prutexas_small.prototype.update_display = changeTextClass;

var cont_search_prutexas = Class.create();
Object.extend(cont_search_prutexas.prototype,cont_class.prototype);
cont_search_prutexas.prototype.update_display = changeTextClass;

var cont_search_pruflorida = Class.create();
Object.extend(cont_search_pruflorida.prototype,cont_class.prototype);
cont_search_pruflorida.prototype.update_display = changeTextClass;

//bch36: added for the Generic Search widget
var cont_search_generic = Class.create();
Object.extend(cont_search_generic.prototype,cont_class.prototype);

cont_search_generic.prototype.def= function()
{
	var data = Array();

	data['background_color'] = "ffffff";
	data['use_background_color'] = "N";

	data['location_text'] = "";
	data['text_color'] = "535353";
	data['property_text_color'] = "535353";

	data['header_text_size'] = 30;
	data['text_size'] = 12;
	data['hint_text_size'] = 11;

	return(data);
}

cont_search_generic.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(300, 550, 'frm_search_generic.inc', this.save.bind(this));
}

cont_search_generic.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);
	$('color_pick_wrap').appendChild($('plugin'));

	// set up updates
	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	updateBackgroundColor = this.updateColor.bind(this, "background_color", data_backgroundColor);
	updateTextColor = this.updateColor.bind(this, "text_color", data_textColor);
	updateText2Color = this.updateColor.bind(this, "property_text_color", data_text2Color);

	$('location_text').onkeyup = this.updateText.bind(this, "location_text");

	$('header_text_size').onkeyup = this.updateText.bind(this, "header_text_size");
	$('text_size').onkeyup = this.updateText.bind(this, "text_size");
	$('hint_text_size').onkeyup = this.updateText.bind(this, "hint_text_size");

	$('use_background_color').onclick = this.updateCheckbox.bind(this, "use_background_color"); 

	if (this.data['use_background_color'] && this.data['use_background_color'] == "Y")
		$('use_background_color').checked = true;

	if (this.data['location_text'])
		$('location_text').value = this.data['location_text'];

	if (this.data['background_color'])
		data_backgroundColor = this.data['background_color'];
	if (this.data['text_color'])
		data_textColor = this.data['text_color'];
	if (this.data['property_text_color'])
		data_text2Color = this.data['property_text_color'];

	if (this.data['header_text_size'])
		$('header_text_size').value = this.data['header_text_size'];
	if (this.data['text_size'])
		$('text_size').value = this.data['text_size'];
	if (this.data['hint_text_size'])
		$('hint_text_size').value = this.data['hint_text_size'];
}

cont_search_generic.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget=widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_search_generic.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['background_color'] == undefined || this.data['background_color'] == "")
			this.data = this.def();
	}

	//Get the two div sections: image and content, as well as the destination div
	var main_div = this.widget.div.getElementsByTagName("DIV")[1];
	var main_table = this.widget.div.getElementsByTagName("TABLE")[0];
	var location_span = this.widget.div.getElementsByTagName("SPAN")[1];
	var property_span = this.widget.div.getElementsByTagName("SPAN")[0];
	var header_div = main_div.getElementsByTagName("DIV")[2];

	//Set the text color
	main_div.style.color = this.data['text_color'];
	main_table.style.color = this.data['text_color'];
	property_span.style.color = this.data['property_text_color'];

	//Set the text sizes
	header_div.style.fontSize = this.data['header_text_size'];
	main_div.style.fontSize = this.data['text_size'];
	main_table.style.fontSize = this.data['hint_text_size'];

	//Set the location text
	if (this.data['location_text'])
		location_span.innerHTML = " in " + this.data['location_text'];

	//Set the background color
	if (this.data['use_background_color'] == "Y")
	{
		main_div.style.backgroundColor = "#"+this.data['background_color'];
		//main_table.style.backgroundColor = "#"+this.data['background_color'];
	}
	else
	{
		main_div.style.backgroundColor = "transparent";
	}
}

cont_search_generic.prototype.resize_cb= function()
{
	this.update_display();
}

cont_search_generic.prototype.updateColor= function (field, variable, color)
{
	variable = color;
	this.data[field] = color;
}

cont_search_generic.prototype.updateText= function(field)
{   
	this.data[field] = $(field).value;
}

cont_search_generic.prototype.updateCheckbox= function(field)
{   
    this.data[field] = $(field).checked ? "Y" : "N";
}

cont_search_generic.prototype.cancel= function()
{
	$('plugin').style.display='none';
	$('wrapper').appendChild($('plugin'));
	this.clear_form();
}

var cont_search_part_address = Class.create();
Object.extend(cont_search_part_address.prototype,cont_class.prototype);

var cont_developments_slc = Class.create();
Object.extend(cont_developments_slc.prototype,cont_class.prototype);

var cont_calc1 = Class.create();
Object.extend(cont_calc1.prototype,cont_class.prototype);

var cont_calc2 = Class.create();
Object.extend(cont_calc2.prototype,cont_class.prototype);

var cont_calc3 = Class.create();
Object.extend(cont_calc3.prototype,cont_class.prototype);

var cont_help_form = Class.create();
Object.extend(cont_help_form.prototype,cont_class.prototype);

var cont_sellhome_form = Class.create();
Object.extend(cont_sellhome_form.prototype,cont_class.prototype);

var cont_relocate_form = Class.create();
Object.extend(cont_relocate_form.prototype,cont_class.prototype);

var cont_extended_contact_form = Class.create();
Object.extend(cont_extended_contact_form.prototype,cont_class.prototype);

var cont_findhome_form = Class.create();
Object.extend(cont_findhome_form.prototype,cont_class.prototype);

var cont_contact1 = Class.create();
Object.extend(cont_contact1.prototype,cont_class.prototype);

var cont_contact2 = Class.create();
Object.extend(cont_contact2.prototype,cont_class.prototype);

var cont_contact3 = Class.create();
Object.extend(cont_contact3.prototype,cont_class.prototype);

var cont_contact4 = Class.create();
Object.extend(cont_contact4.prototype,cont_class.prototype);

var cont_contact5 = Class.create();
Object.extend(cont_contact5.prototype,cont_class.prototype);

var cont_contact6 = Class.create();
Object.extend(cont_contact6.prototype,cont_class.prototype);

var cont_contact7 = Class.create();
Object.extend(cont_contact7.prototype,cont_class.prototype);

var cont_cellphone1 = Class.create();
Object.extend(cont_cellphone1.prototype,cont_class.prototype);

var cont_testimonials = Class.create();
Object.extend(cont_testimonials.prototype, cont_class.prototype);

var cont_secure_login = Class.create();
Object.extend(cont_secure_login.prototype,cont_class.prototype);

var cont_find_agent_form = Class.create();
Object.extend(cont_find_agent_form.prototype,cont_class.prototype);

var cont_modal_dialog = Class.create();
Object.extend(cont_modal_dialog.prototype,cont_class.prototype);

//bch36: added for the "link to mobile site" widget (mobile_link)
var cont_mobile_link = Class.create();
Object.extend(cont_mobile_link.prototype,cont_class.prototype);

cont_mobile_link.prototype.def= function()
{
	var data = Array();
	data['color'] = "FFFFFF";
	data['backgroundColor'] = "FF0000";

	return(data);
}

cont_mobile_link.prototype.edit= function()
{
	this.load_form(250, 140, 'frm_mobile_link.inc', this.save.bind(this));
}

cont_mobile_link.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);
	$('color_pick_wrap').appendChild($('plugin'));

	// setup updates
	//$('data_text').onkeyup= this.updateText.bind(this);
	//$('select_img_btn').onclick= this.updateImage.bind(this);
	//$('data_font').onchange= this.updateFont.bind(this);
	//$('data_font_size').onchange= this.updateFontSize.bind(this);
	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);
	//$('data_url_link').onchange= this.updateLink.bind(this);
	//$('data_local_link').onchange= this.updateLocLink.bind(this);
	//$('data_remove_bar').onclick= this.updateRemoveBar.bind(this);
	updateTextBg = this.updateTextBg.bind(this);
	updateTextColor = this.updateTextColor.bind(this);
	//curImgSelFunc = this.imageSelected.bind(this);

	//$('data_img4').src = this.data['src'];
	//$('data_desc').innerHTML = this.data['desc'];
	//$('data_text').value = this.data['desc'];
	//$('data_desc').style.fontFamily = this.data['font'];
	//if (this.data['font_size'] != null)
	//$('data_desc').style.fontSize = this.data['font_size'];

	if (this.data['color'])
		$('mobile_link_preview_element').style.color = data_textColor = this.data['color'];
	if (this.data['backgroundColor'] != null)
		$('mobile_link_preview_element').style.backgroundColor = data_textBg = this.data['backgroundColor'];

	//if (this.data['href'] != null)
	//$('data_url_link').value = this.data['href'];
	//if (this.data['remove_bar'] == 'true' || this.data['remove_bar'] == true)
	//{
	//$('data_remove_bar').checked = true;
	//}
	//this.updateRemoveBar();
}

cont_mobile_link.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget=widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

/*
cont_mobile_link.prototype.display= function(save)
{
	this.data = this.widget.get_data();
	var wid_num = this.widget.get_widget_num();
	this.preview(this.widget.get_div(), this.widget.get_data(), this.widget.width, this.widget.height, wid_num);

	if (save)
		this.save();
}

cont_mobile_link.prototype.preview= function(par_div, data, width, height, wid_num)
{
}
*/

cont_mobile_link.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['backgroundColor'] == undefined)
			this.data = this.def();

		var mobile_link_background = this.widget.div.getElementsByTagName("DIV")[1];
		mobile_link_background.id = "mobile_link_background_"+this.widget.widget_number;

		var mobile_link_table_top = this.widget.div.getElementsByTagName("TABLE")[0];
		mobile_link_table_top.id = "mobile_link_table_top_"+this.widget.widget_number;

		var mobile_link_table_bottom = this.widget.div.getElementsByTagName("TABLE")[1];
		mobile_link_table_bottom.id = "mobile_link_table_bottom_"+this.widget.widget_number;

		var mobile_link_href = this.widget.div.getElementsByTagName("A")[0];
		mobile_link_href.id = "mobile_link_href_"+this.widget.widget_number;
	}
	else
	{
		mobile_link_background = $('mobile_link_background_'+this.widget.widget_number);
		mobile_link_table_top = $('mobile_link_table_top_'+this.widget.widget_number);
		mobile_link_table_bottom = $('mobile_link_table_bottom_'+this.widget.widget_number);
		mobile_link_href = $('mobile_link_href_'+this.widget.widget_number);
	}

	mobile_link_background.style.backgroundColor = this.data['backgroundColor'];
	mobile_link_table_top.style.color = this.data['color'];
	mobile_link_table_bottom.style.color = this.data['color'];
	mobile_link_href.style.color = this.data['color'];
}

cont_mobile_link.prototype.updateTextColor= function (color)
{
	data_textColor = color;
	$('mobile_link_preview_element').style.color = "#"+color;
	this.data['color'] = color;
}

cont_mobile_link.prototype.updateTextBg= function (color)
{
	data_textBg = color;
	$('mobile_link_preview_element').style.backgroundColor = "#"+color;
	this.data['backgroundColor'] = color;
}

cont_mobile_link.prototype.cancel= function()
{
	$('plugin').style.display='none';
	$('wrapper').appendChild($('plugin'));
	this.clear_form();
}

//bch36: added for the Market Snapshot widget
var cont_market_snapshot = Class.create();
Object.extend(cont_market_snapshot.prototype,cont_class.prototype);

cont_market_snapshot.prototype.def= function()
{
	var data = Array();

	data['image'] = 1;

	data['background_color'] = "ffffff";
	data['use_background_color'] = "N";

	data['border_color'] = "737373";
	data['use_border_color'] = "Y";

	data['input_field_color'] = "535353";

	data['header_text'] = "FIND OUT WHAT'S GOING ON IN YOUR AREA";
	data['header_color'] = "535353";

	data['message_text'] = "Sign up for a FREE monthly market report";
	data['message_color'] = "737373";

	data['input_field_font_size'] = 12;
	data['header_font_size'] = 12;
	data['message_font_size'] = 12;

	return(data);
}

cont_market_snapshot.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(600, 550, 'frm_market_snapshot.inc', this.save.bind(this));
}

cont_market_snapshot.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);
	$('color_pick_wrap').appendChild($('plugin'));

	$('market_snapshot_image1').onclick= this.updateImage.bind(this, 1);
	$('market_snapshot_image2').onclick= this.updateImage.bind(this, 2);
	$('market_snapshot_image3').onclick= this.updateImage.bind(this, 3);

	// set up updates
	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	updateBackgroundColor = this.updateColor.bind(this, "background_color", data_backgroundColor);
	updateBorderColor = this.updateColor.bind(this, "border_color", data_borderColor);
	updateTextColor = this.updateColor.bind(this, "header_color", data_textColor);
	updateText2Color = this.updateColor.bind(this, "message_color", data_text2Color);
	updateText3Color = this.updateColor.bind(this, "input_field_color", data_text3Color);

	$('header_text').onkeyup = this.updateText.bind(this, "header_text");
	$('message_text').onkeyup = this.updateText.bind(this, "message_text");

	$('input_field_font_size').onkeyup = this.updateText.bind(this, "input_field_font_size");
	$('header_font_size').onkeyup = this.updateText.bind(this, "header_font_size");
	$('message_font_size').onkeyup = this.updateText.bind(this, "message_font_size");

	$('use_background_color').onclick = this.updateCheckbox.bind(this, "use_background_color"); 
	$('use_border_color').onclick = this.updateCheckbox.bind(this, "use_border_color"); 

	if (this.data['image'])
		$('market_snapshot_image'+this.data['image']).firstChild.style.border = "thin solid red";
	else
		$('market_snapshot_image1').firstChild.style.border = "thin solid red";

	if (this.data['use_background_color'] && this.data['use_background_color'] == "Y")
		$('use_background_color').checked = true;
	if (this.data['use_border_color'] && this.data['use_border_color'] == "Y")
		$('use_border_color').checked = true;

	if (this.data['header_text'])
		$('header_text').value = this.data['header_text'];
	if (this.data['message_text'])
		$('message_text').value = this.data['message_text'];

	if (this.data['background_color'])
		data_backgroundColor = this.data['background_color'];
	if (this.data['border_color'])
		data_borderColor = this.data['border_color'];
	if (this.data['header_color'])
		data_textColor = this.data['header_color'];
	if (this.data['message_color'])
		data_text2Color = this.data['message_color'];
	if (this.data['input_field_color'])
		data_text2Color = this.data['input_field_color'];

	if (this.data['input_field_font_size'])
		$('input_field_font_size').value = this.data['input_field_font_size'];
	if (this.data['header_font_size'])
		$('header_font_size').value = this.data['header_font_size'];
	if (this.data['message_font_size'])
		$('message_font_size').value = this.data['message_font_size'];
}

cont_market_snapshot.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget=widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_market_snapshot.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['background_color'] == undefined || this.data['background_color'] == "")
			this.data = this.def();
	}

	//Decide whether we're going for a vertical or horizontal look
	orientation = "horizontal";
	if (this.widget.height > this.widget.width) //vertical
		orientation = "vertical";

	//Get the two div sections: image and content, as well as the destination div
	dest_div = this.widget.div.getElementsByTagName("DIV")[1];
	image_div = this.widget.div.getElementsByTagName("DIV")[2];
	content_div = this.widget.div.getElementsByTagName("DIV")[3];

	dest_div.innerHTML = "";

	//Set the header and message text color
	header_div = content_div.getElementsByTagName("DIV")[0];
	header_div.style.color = this.data['header_color'];
	header_div.style.fontSize = this.data['header_font_size'] ? this.data['header_font_size'] : 12;
	header_div.innerHTML = this.data['header_text'];

	content_div.style.color = this.data['message_color'];
	message_div = content_div.getElementsByTagName("DIV")[1];
	message_div.style.color = this.data['message_color'];
	message_div.style.fontSize = this.data['message_font_size'] ? this.data['message_font_size'] : 12;
	message_div.innerHTML = this.data['message_text'];

	input_fields_div = content_div.getElementsByTagName("DIV")[2];
	input_fields_div.style.color = this.data['input_field_color'];
	input_fields_div.style.fontSize = this.data['input_field_font_size'] ? this.data['input_field_font_size'] : 12;

	//Get the image element
	image = image_div.getElementsByTagName("IMG")[0];
	image.src = "/shared/images/market_snapshot/report_image_"+(isNaN(this.data['image']) ? 1 : this.data['image'])+(orientation == "horizontal" ? "_sm" : "")+".png";

	//Build the correct table structure
	table = document.createElement("TABLE");
	table.style.width = "100%";
	table.cellPadding = "0";
	table.cellSpacing = "0";

	if (this.data['use_border_color'] == "Y")
		table.style.border = "thin solid #"+this.data['border_color'];

	if (this.data['use_background_color'] == "Y")
		table.style.backgroundColor = "#"+this.data['background_color'];

	var tbody = document.createElement("TBODY");
	table.appendChild(tbody);

	if (orientation == "vertical")
	{
		tr = document.createElement("TR");
		tbody.appendChild(tr);

		image.style.width = this.widget.width; //"100%" doesn't work because in IE, the image will go full-size
		image.style.height = "";

		if (this.data['use_border_color'] == "Y")
			image.style.borderBottom = "thin solid #"+this.data['border_color'];

		td = document.createElement("TD");
		td.appendChild(image_div);
		tr.appendChild(td);

		tr = document.createElement("TR");
		tbody.appendChild(tr);

		td = document.createElement("TD");
		td.appendChild(content_div);
		tr.appendChild(td);
	}
	else //horizontal
	{
		tr = document.createElement("TR");
		tbody.appendChild(tr);

		image.style.width = "";
		image.style.height = this.widget.height; //"100%"

		if (this.data['use_border_color'] == "Y")
			image.style.borderRight = "thin solid #"+this.data['border_color'];

		td = document.createElement("TD");
		td.appendChild(image_div);
		tr.appendChild(td);

		td = document.createElement("TD");
		td.appendChild(content_div);
		tr.appendChild(td);
	}

	dest_div.appendChild(table);
}

cont_market_snapshot.prototype.resize_cb= function()
{
	this.update_display();
}

cont_market_snapshot.prototype.updateImage= function (image)
{
	//Unset borders on all the images
	for (i=1; i <= 3; i++)
		$('market_snapshot_image'+i).firstChild.style.border = "";

	//Set the border on the selected image
	$('market_snapshot_image'+image).firstChild.style.border = "thin solid red";

	this.data['image'] = image;
}

cont_market_snapshot.prototype.updateColor= function (field, variable, color)
{
	variable = color;
	this.data[field] = color;
}

cont_market_snapshot.prototype.updateText= function(field)
{   
	this.data[field] = $(field).value;
}

cont_market_snapshot.prototype.updateCheckbox= function(field)
{   
    this.data[field] = $(field).checked ? "Y" : "N";
}

cont_market_snapshot.prototype.cancel= function()
{
	$('plugin').style.display='none';
	$('wrapper').appendChild($('plugin'));
	this.clear_form();
}

//bch36: added for the CoolIris widget
var cont_cooliris = Class.create();
Object.extend(cont_cooliris.prototype,cont_class.prototype);

cont_cooliris.prototype.def= function()
{
	var data = Array();

	data['style'] = 4;
	data['number_of_rows'] = 3;

	data['background_color'] = "";
	data['use_background_color'] = "N";

	data['use_agent_id'] = "N";
	data['agent_id'] = "";

	data['use_office_id'] = "N";
	data['office_id'] = "";

	data['open_houses'] = "N";

	data['mls_nums'] = "";

	data['city'] = "";
	data['min_price'] = "";
	data['max_price'] = "";
	data['min_sq_feet'] = "";
	data['min_lot_size'] = "";
	data['min_garages'] = "";
	data['min_bedrooms'] = "";
	data['min_bathrooms'] = "";
	data['table_prefix'] = "";
	data['property_type'] = "";
	data['new_listings'] = "";

	return(data);
}

cont_cooliris.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(600, 550, 'frm_cooliris.inc', this.save.bind(this));
}

cont_cooliris.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);
	$('color_pick_wrap').appendChild($('plugin'));

	$('cooliris_style1').onclick= this.updateStyle.bind(this, 1);
	$('cooliris_style2').onclick= this.updateStyle.bind(this, 2);
	$('cooliris_style3').onclick= this.updateStyle.bind(this, 3);
	$('cooliris_style4').onclick= this.updateStyle.bind(this, 4);

	// set up updates
	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	updateBackgroundColor = this.updateBackgroundColor.bind(this);

	$('agent_id').onkeyup = this.updateText.bind(this, "agent_id");
	$('office_id').onkeyup = this.updateText.bind(this, "office_id");
	$('mls_nums').onkeyup = this.updateText.bind(this, "mls_nums");
	$('number_of_rows').onkeyup = this.updateText.bind(this, "number_of_rows");

	//Ran into problems where other things on the page had an ID of city
	var city = null;
	var search_form = $('search_form');
	var inputs = search_form.getElementsByTagName('input');
	for (var i in inputs)
		if (inputs[i].id == "city")
		{
			city = inputs[i];
			break;
		}

	city.onkeyup = this.updateText.bind(this, "city");
	$('city_suggestion').onclick = this.updateText.bind(this, "city");
	$('min_price').onkeyup = this.updateText.bind(this, "min_price");
	$('max_price').onkeyup = this.updateText.bind(this, "max_price");

	$('use_agent_id').onclick = this.updateCheckbox.bind(this, "use_agent_id"); 
	$('use_office_id').onclick = this.updateCheckbox.bind(this, "use_office_id"); 
	$('open_houses').onclick = this.updateCheckbox.bind(this, "open_houses"); 
	$('new_listings').onclick = this.updateCheckbox.bind(this, "new_listings"); 

	$('use_background_color').onclick = this.updateCheckbox.bind(this, "use_background_color"); 

	$('min_sq_feet').onchange = this.updateText.bind(this, "min_sq_feet"); 
	$('min_lot_size').onchange = this.updateText.bind(this, "min_lot_size"); 
	$('min_garages').onchange = this.updateText.bind(this, "min_garages"); 
	$('min_bedrooms').onchange = this.updateText.bind(this, "min_bedrooms"); 
	$('min_bathrooms').onchange = this.updateText.bind(this, "min_bathrooms"); 

	all_table_prefixes = $('all_table_prefixes').value.split(",");
	for (var i=0; i < all_table_prefixes.length; i++)
	{
		if ($('table_prefix_'+all_table_prefixes[i]))
			$('table_prefix_'+all_table_prefixes[i]).onclick = this.updateText.bind(this, "table_prefix_"+all_table_prefixes[i]); 

		if ($('property_type_'+all_table_prefixes[i]))
			$('property_type_'+all_table_prefixes[i]).onchange = this.updateText.bind(this, "property_type_"+all_table_prefixes[i]);
	}

	if (this.data['style'])
	{
		$('cooliris_style'+this.data['style']).style.border = "thin solid red";
	}

	if (this.data['use_agent_id'] && this.data['use_agent_id'] == "Y")
		$('use_agent_id').checked = true;
	if (this.data['use_office_id'] && this.data['use_office_id'] == "Y")
		$('use_office_id').checked = true;

	if (this.data['agent_id'])
		$('agent_id').value = this.data['agent_id'];
	if (this.data['office_id'])
		$('office_id').value = this.data['office_id'];

	if (this.data['mls_nums'])
		$('mls_nums').value = this.data['mls_nums'];
	if (this.data['number_of_rows'])
		$('number_of_rows').value = this.data['number_of_rows'];

	//if (this.data['background_color'])
	//	$('cooliris_preview_background_color').style.backgroundColor = data_backgroundColor = this.data['background_color'];
	if (this.data['use_background_color'] == "Y")
		$('use_background_color').checked = true;

	if (this.data['open_houses'] && this.data['open_houses'] == "Y")
		$('open_houses').checked = true;

	if (this.data['city'])
		city.value = this.data['city'];
	if (this.data['min_price'])
		$('min_price').value = this.data['min_price'];
	if (this.data['max_price'])
		$('max_price').value = this.data['max_price'];

	if (this.data['min_sq_feet'])
	{
		for (i=0; i < $('min_sq_feet').options.length; i++)
			if ($('min_sq_feet').options[i].value == this.data['min_sq_feet'])
				$('min_sq_feet').options[i].selected = true;
	}

	if (this.data['min_lot_size'])
	{
		for (i=0; i < $('min_lot_size').options.length; i++)
			if ($('min_lot_size').options[i].value == this.data['min_lot_size'])
				$('min_lot_size').options[i].selected = true;
	}

	if (this.data['min_garages'])
	{
		for (i=0; i < $('min_garages').options.length; i++)
			if ($('min_garages').options[i].value == this.data['min_garages'])
				$('min_garages').options[i].selected = true;
	}

	if (this.data['min_bedrooms'])
	{
		for (i=0; i < $('min_bedrooms').options.length; i++)
			if ($('min_bedrooms').options[i].value == this.data['min_bedrooms'])
				$('min_bedrooms').options[i].selected = true;
	}

	if (this.data['min_bathrooms'])
	{
		for (i=0; i < $('min_bathrooms').options.length; i++)
			if ($('min_bathrooms').options[i].value == this.data['min_bathrooms'])
				$('min_bathrooms').options[i].selected = true;
	}

	if (this.data['table_prefix'] != undefined)
	{
		for (var i in all_table_prefixes)
		{
			if ($('table_prefix_'+all_table_prefixes[i]) && $('table_prefix_'+all_table_prefixes[i]).value == this.data['table_prefix'])
			{
				$('table_prefix_'+all_table_prefixes[i]).checked = true;
				$('list_class_'+all_table_prefixes[i]).style.display = "block";
			}
			else if ($('table_prefix_'+all_table_prefixes[i]))
				$('list_class_'+all_table_prefixes[i]).style.display = "none";

			for (j=0; $('property_type_'+all_table_prefixes[i]) && j < $('property_type_'+all_table_prefixes[i]).options.length; j++)
				if ($('property_type_'+all_table_prefixes[i]).options[j].value == this.data['property_type'])
					$('property_type_'+all_table_prefixes[i]).options[j].selected = true;
		}
	}
		
	//If there's no table prefix set, then show at least the first set of property types
	if (this.data['table_prefix'] == undefined || this.data['table_prefix'] == "")
		$('list_class_'+all_table_prefixes[0]).style.display = "block";


	if (this.data['new_listings'] && this.data['new_listings'] == "Y")
		$('new_listings').checked = true;
}

cont_cooliris.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget=widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_cooliris.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['use_agent_id'] == undefined)
			this.data = this.def();

		if (isNaN(this.data['number_of_rows']))
			this.data['number_of_rows'] = 3;
	}

	//Get the element to create the player in
	span = this.widget.div.getElementsByTagName("SPAN")[0];

	//Figure out what style they want
	style = "black";
	if (this.data['style'] == 1)
		style = "white";
	else if (this.data['style'] == 2)
		style = "light";
	else if (this.data['style'] == 3)
		style = "dark";
	else if (this.data['style'] == 4)
		style = "black";

	//Create the flashvars 
	flashvar = "feed="+encodeURIComponent("http://"+window.location.hostname+"/site/media_rss.xml"
		+ "?agent_id="+this.data['agent_id']
		+ "&use_agent_id="+this.data['use_agent_id']
		+ "&office_id="+this.data['office_id']
		+ "&use_office_id="+this.data['use_office_id']
		+ "&mls_nums="+this.data['mls_nums']
		+ "&city="+this.data['city']
		+ "&min_price="+this.data['min_price']
		+ "&max_price="+this.data['max_price']
		+ "&min_sq_feet="+this.data['min_sq_feet']
		+ "&min_lot_size="+this.data['min_lot_size']
		+ "&min_garages="+this.data['min_garages']
		+ "&min_bedrooms="+this.data['min_bedrooms']
		+ "&min_bathrooms="+this.data['min_bathrooms']
		+ "&table_prefix="+this.data['table_prefix']
		+ "&property_type="+this.data['property_type']
		+ "&new_listings="+this.data['new_listings']
		+ "&open_houses="+this.data['open_houses'])
		+ "&numRows="+this.data['number_of_rows']
		+ "&style="+style
		+ "&showChrome=false"
		+ (this.data['use_background_color'] == "Y" ? "&backgroundColor=#"+this.data['background_color']  : "")
	;

	//Create the player
	player = '';
	player += '<object id="o"';
	player += '        classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
	player += '        width="'+this.widget.width+'"';
	player += '        height="'+this.widget.height+'">';

	player += '        <param name="movie" value="http://apps.cooliris.com/embed/cooliris.swf" />';
	player += '        <param name="allowFullScreen" value="true" />';
	player += '        <param name="allowScriptAccess" value="always" />';
	player += '        <param name="flashvars" value="'+flashvar+'" />'
	player += '        <param name="wmode" value="transparent" />';

	player += '        <embed type="application/x-shockwave-flash"';
	player += '                src="http://apps.cooliris.com/embed/cooliris.swf"';
	player += '                flashvars="'+flashvar+'"';
	player += '                width="'+this.widget.width+'"';
	player += '                height="'+this.widget.height+'"';
	player += '                allowFullScreen="true"';
	player += '                wmode="transparent"';
	player += '                allowScriptAccess="always">';
	player += '        </embed>';
	player += '</object>';

	//Put the player in the span
	span.innerHTML = player;
}

cont_cooliris.prototype.resize_cb= function()
{
	this.update_display();
}

cont_cooliris.prototype.updateStyle= function (style)
{
	//Unset borders on all the styles
	for (i=1; i <= 4; i++)
		$('cooliris_style'+i).style.border = "";

	//Set the border on the selected style
	$('cooliris_style'+style).style.border = "thin solid red";

	this.data['style'] = style;
}

cont_cooliris.prototype.updateBackgroundColor= function (color)
{
	data_backgroundColor = color;
	//$('cooliris_preview').style.backgroundColor = "#"+color;
	this.data['background_color'] = color;
}

cont_cooliris.prototype.updateText= function(field)
{   
	if (field.substr(0, 13) == "table_prefix_")
	{
		this.data['table_prefix'] = $(field).value;

		change_property_types($(field).value);

		all_table_prefixes = $('all_table_prefixes').value.split(",");
		for (var i in all_table_prefixes)
		{
			for (j=0; $('property_type_'+all_table_prefixes[i]) && j < $('property_type_'+all_table_prefixes[i]).options.length; j++)
				$('property_type_'+all_table_prefixes[i]).options[j].selected = false;
		}
		this.data['property_type'] = "";
	}
	else if (field.substr(0, 14) == "property_type_")
		this.data['property_type'] = $(field).value;
	else if (field == "number_of_rows")
	{
		value = 3;
		if (!isNaN($(field).value))
		{
			value = parseInt($(field).value);
			if ($(field).value < 1)
				value = 1;
			else if ($(field).value > 7)
				value  = 7;
		}

		this.data[field] = value;
	}
	else if (field == "city")
	{
		auto_complete_city();

		//Ran into problems where other things on the page had an ID of city
		var city = null;
		var search_form = $('search_form');
		var inputs = search_form.getElementsByTagName('input');
		for (var i in inputs)
			if (inputs[i].id == "city")
			{
				city = inputs[i];
				break;
			}

		this.data[field] = city.value;
	}
	else
	{
		this.data[field] = $(field).value;
	}
}

cont_cooliris.prototype.updateCheckbox= function(field)
{   
	if (field == "use_background_color")
		alert("If the new background doesn't appear after saving this form, you may need to clear your browser's cache and refresh the page.");

	this.data[field] = $(field).checked ? "Y" : "N";
}

cont_cooliris.prototype.cancel= function()
{
	$('plugin').style.display='none';
	$('wrapper').appendChild($('plugin'));
	this.clear_form();
}

//bch36: added for Register Marketing's builder profile widget
/* */
var cont_builder_profile = Class.create();
Object.extend(cont_builder_profile.prototype,cont_class.prototype);

cont_builder_profile.prototype.def= function()
{
	var data = Array();

	data['builder_name'] = "";

	return(data);
}

cont_builder_profile.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(350, 100, 'frm_builder_profile.inc', this.save.bind(this));
}

cont_builder_profile.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);

	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	$('builder_name').onkeyup = this.update_builder_name.bind(this);

	if (this.data['builder_name'])
		$('builder_name').value = this.data['builder_name'];
}

cont_builder_profile.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget = widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_builder_profile.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['builder_name'] == undefined)
			this.data = this.def();
	}

	this.widget.div.getElementsByTagName("iframe")[0].src = "http://registermarketing.blueroof360.com/builder_profile.php?builder="+this.data['builder_name'];
}

cont_builder_profile.prototype.resize_cb= function()
{
	this.update_display();
}

cont_builder_profile.prototype.update_builder_name= function(field)
{   
	this.data['builder_name'] = $('builder_name').value;
}

cont_builder_profile.prototype.cancel= function()
{
	$('plugin').style.display='none';
	$('wrapper').appendChild($('plugin'));
	this.clear_form();
}
/* */

//bch36: added for the new featured property widget
var cont_featprop3 = Class.create();
Object.extend(cont_featprop3.prototype,cont_class.prototype);

cont_featprop3.prototype.def= function()
{
	var data = Array();

	data['style'] = 1;

	data['text_color'] = "FFFFFF";
	data['background_color'] = "737373";
	data['border_color'] = "FFFFFF";

	data['use_agent_id'] = "N";
	data['agent_id'] = "";

	data['use_office_id'] = "N";
	data['office_id'] = "";

	data['no_background_color'] = "N";
	data['open_houses'] = "N";

	data['mls_nums'] = "";
	data['number_of_listings'] = 3;

	data['city'] = "";
	data['min_price'] = "";
	data['max_price'] = "";
	data['min_sq_feet'] = "";
	data['min_lot_size'] = "";
	data['min_garages'] = "";
	data['min_bedrooms'] = "";
	data['min_bathrooms'] = "";
	data['table_prefix'] = "";
	data['property_type'] = "";
	data['new_listings'] = "";

	return(data);
}

cont_featprop3.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(600, 700, 'frm_featprop3.inc', this.save.bind(this));
}

cont_featprop3.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);
	$('color_pick_wrap').appendChild($('plugin'));

	// set up updates
	$('featprop3_style1').onclick= this.updateStyle.bind(this, 1);
	$('featprop3_style2').onclick= this.updateStyle.bind(this, 2);
	$('featprop3_style3').onclick= this.updateStyle.bind(this, 3);

	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	updateTextColor = this.updateTextColor.bind(this);
	updateBackgroundColor = this.updateBackgroundColor.bind(this);
	updateBorderColor = this.updateBorderColor.bind(this);

	$('agent_id').onkeyup = this.updateText.bind(this, "agent_id");
	$('office_id').onkeyup = this.updateText.bind(this, "office_id");
	$('mls_nums').onkeyup = this.updateText.bind(this, "mls_nums");
	$('number_of_listings').onkeyup = this.updateText.bind(this, "number_of_listings");

	$('city').onkeyup = this.updateText.bind(this, "city");
	$('city_suggestion').onclick = this.updateText.bind(this, "city");
	$('min_price').onkeyup = this.updateText.bind(this, "min_price");
	$('max_price').onkeyup = this.updateText.bind(this, "max_price");

	$('use_agent_id').onclick = this.updateCheckbox.bind(this, "use_agent_id"); 
	$('use_office_id').onclick = this.updateCheckbox.bind(this, "use_office_id"); 
	$('no_background_color').onclick = this.updateCheckbox.bind(this, "no_background_color"); 
	$('open_houses').onclick = this.updateCheckbox.bind(this, "open_houses"); 
	$('new_listings').onclick = this.updateCheckbox.bind(this, "new_listings"); 

	$('min_sq_feet').onchange = this.updateText.bind(this, "min_sq_feet"); 
	$('min_lot_size').onchange = this.updateText.bind(this, "min_lot_size"); 
	$('min_garages').onchange = this.updateText.bind(this, "min_garages"); 
	$('min_bedrooms').onchange = this.updateText.bind(this, "min_bedrooms"); 
	$('min_bathrooms').onchange = this.updateText.bind(this, "min_bathrooms"); 

	all_table_prefixes = $('all_table_prefixes').value.split(",");
	for (var i=0; i < all_table_prefixes.length; i++)
	{
		if ($('table_prefix_'+all_table_prefixes[i]))
			$('table_prefix_'+all_table_prefixes[i]).onclick = this.updateText.bind(this, "table_prefix_"+all_table_prefixes[i]); 

		if ($('property_type_'+all_table_prefixes[i]))
			$('property_type_'+all_table_prefixes[i]).onchange = this.updateText.bind(this, "property_type_"+all_table_prefixes[i]);
	}

	if (this.data['style'])
		$('featprop3_style'+this.data['style']).style.border = "thin solid red";

	if (this.data['use_agent_id'] && this.data['use_agent_id'] == "Y")
		$('use_agent_id').checked = true;
	if (this.data['use_office_id'] && this.data['use_office_id'] == "Y")
		$('use_office_id').checked = true;

	if (this.data['agent_id'])
		$('agent_id').value = this.data['agent_id'];
	if (this.data['office_id'])
		$('office_id').value = this.data['office_id'];

	if (this.data['mls_nums'])
		$('mls_nums').value = this.data['mls_nums'];

	if (this.data['number_of_listings'])
		$('number_of_listings').value = this.data['number_of_listings'];

	if (this.data['text_color'])
		$('featprop3_preview_text').style.color = data_textColor = this.data['text_color'];
	if (this.data['background_color'])
		$('featprop3_preview').style.backgroundColor = data_backgroundColor = this.data['background_color'];
	if (this.data['border_color'])
		$('featprop3_preview_image').style.borderColor = data_borderColor = this.data['border_color'];

	if (this.data['no_background_color'] && this.data['no_background_color'] == "Y")
		$('no_background_color').checked = true;

	if (this.data['open_houses'] && this.data['open_houses'] == "Y")
		$('open_houses').checked = true;

	if (this.data['city'])
		$('city').value = this.data['city'];
	if (this.data['min_price'])
		$('min_price').value = this.data['min_price'];
	if (this.data['max_price'])
		$('max_price').value = this.data['max_price'];

	if (this.data['min_sq_feet'])
	{
		for (i=0; i < $('min_sq_feet').options.length; i++)
			if ($('min_sq_feet').options[i].value == this.data['min_sq_feet'])
				$('min_sq_feet').options[i].selected = true;
	}

	if (this.data['min_lot_size'])
	{
		for (i=0; i < $('min_lot_size').options.length; i++)
			if ($('min_lot_size').options[i].value == this.data['min_lot_size'])
				$('min_lot_size').options[i].selected = true;
	}

	if (this.data['min_garages'])
	{
		for (i=0; i < $('min_garages').options.length; i++)
			if ($('min_garages').options[i].value == this.data['min_garages'])
				$('min_garages').options[i].selected = true;
	}

	if (this.data['min_bedrooms'])
	{
		for (i=0; i < $('min_bedrooms').options.length; i++)
			if ($('min_bedrooms').options[i].value == this.data['min_bedrooms'])
				$('min_bedrooms').options[i].selected = true;
	}

	if (this.data['min_bathrooms'])
	{
		for (i=0; i < $('min_bathrooms').options.length; i++)
			if ($('min_bathrooms').options[i].value == this.data['min_bathrooms'])
				$('min_bathrooms').options[i].selected = true;
	}

	if (this.data['table_prefix'] == undefined)
		this.data['table_prefix'] = all_table_prefixes[0];

	if (this.data['table_prefix'] != undefined)
	{
		for (var i in all_table_prefixes)
		{
			if ($('table_prefix_'+all_table_prefixes[i]) && $('table_prefix_'+all_table_prefixes[i]).value == this.data['table_prefix'])
			{
				$('table_prefix_'+all_table_prefixes[i]).checked = true;
				$('list_class_'+all_table_prefixes[i]).style.display = "block";
			}
			else if ($('table_prefix_'+all_table_prefixes[i]))
				$('list_class_'+all_table_prefixes[i]).style.display = "none";

			for (j=0; $('property_type_'+all_table_prefixes[i]) && j < $('property_type_'+all_table_prefixes[i]).options.length; j++)
				if ($('property_type_'+all_table_prefixes[i]).options[j].value == this.data['property_type'])
					$('property_type_'+all_table_prefixes[i]).options[j].selected = true;
		}
	}
		
	//If there's no table prefix set, then show at least the first set of property types
	if (this.data['table_prefix'] == undefined || this.data['table_prefix'] == "")
		$('list_class_'+all_table_prefixes[0]).style.display = "block";


	if (this.data['new_listings'] && this.data['new_listings'] == "Y")
		$('new_listings').checked = true;
}

cont_featprop3.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget=widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_featprop3.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['style'] == undefined)
			this.data = this.def();

		if (isNaN(this.data['number_of_listings']))
			this.data['number_of_listings'] = 3;

		this.updater = new featprop3_updater(this.widget.get_widget_num(), this.data);
	}

	//Clear old data first
	for (i=0; i < 3; i++)
	{
		//Get the data div and empty it
		featprop3_data = this.widget.div.getElementsByTagName("SPAN")[i];
		featprop3_data.innerHTML = "<img src='/shared/images/loading.gif' />";

		table = this.widget.div.getElementsByTagName("TABLE")[i];
		table.style.display = "none";
	}
	
	// make sure the updater knows the size of the widget
	this.updater.reset_widget_dimensions(this.widget.width, this.widget.height);

	//Needed to change background color and color
	var featprop3_table = this.widget.div.getElementsByTagName("TABLE")[(this.data['style']-1)];

	//On style 2, the left/right images are the last two.
	//On style 1 and 3, they're the first and last

	var images = featprop3_table.getElementsByTagName("IMG");

	var featprop3_left_arrow_image = images[this.data['style'] != 2 ? 0 : images.length-2]; 
	featprop3_left_arrow_image.src = "/shared/images/colorize.php?c="+this.data['text_color']+"&img=/shared/images/featprop3_"+(this.data['style'] != 3 ? "left" : "up")+"_arrow.png";

	var featprop3_right_arrow_image = images[images.length-1];
	featprop3_right_arrow_image.src = "/shared/images/colorize.php?c="+this.data['text_color']+"&img=/shared/images/featprop3_"+(this.data['style'] != 3 ? "right" : "down")+"_arrow.png";

	if (this.data['no_background_color'] == "Y")
		featprop3_table.style.backgroundColor = "";
	else
		featprop3_table.style.backgroundColor = this.data['background_color'];

	featprop3_table.style.color = this.data['text_color'];

	featprop3_table.style.display = "block";

	this.updater.get_listings(0, this.data['number_of_listings'], this.widget.get_widget_num());
}

cont_featprop3.prototype.resize_cb= function()
{
	this.update_display();
}

cont_featprop3.prototype.updateStyle= function (style)
{
	//Unset borders on all the styles
	for (i=1; i <= 3; i++)
		$('featprop3_style'+i).style.border = "";

	//Set the border on the selected style
	$('featprop3_style'+style).style.border = "thin solid red";

	this.data['style'] = style;
}

cont_featprop3.prototype.updateTextColor= function (color)
{
	data_textColor = color;
	$('featprop3_preview_text').style.color = "#"+color;
	this.data['text_color'] = color;
}

cont_featprop3.prototype.updateBackgroundColor= function (color)
{
	data_backgroundColor = color;
	$('featprop3_preview').style.backgroundColor = "#"+color;
	this.data['background_color'] = color;
}

cont_featprop3.prototype.updateBorderColor= function (color)
{
	data_borderColor = color;
	$('featprop3_preview_image').style.borderColor = "#"+color;
	this.data['border_color'] = color;
}

cont_featprop3.prototype.updateText= function(field)
{   
	if (field.substr(0, 13) == "table_prefix_")
	{
		this.data['table_prefix'] = $(field).value;

		change_property_types($(field).value);

		all_table_prefixes = $('all_table_prefixes').value.split(",");
		for (var i in all_table_prefixes)
		{
			for (j=0; $('property_type_'+all_table_prefixes[i]) && j < $('property_type_'+all_table_prefixes[i]).options.length; j++)
				$('property_type_'+all_table_prefixes[i]).options[j].selected = false;
		}
		this.data['property_type'] = "";
	}
	else if (field.substr(0, 14) == "property_type_")
		this.data['property_type'] = $(field).value;
	else
	{
		if (field == "city")
			auto_complete_city();

		this.data[field] = $(field).value;
	}
}

cont_featprop3.prototype.updateCheckbox= function(field)
{   
    this.data[field] = $(field).checked ? "Y" : "N";
}

cont_featprop3.prototype.cancel= function()
{
	$('plugin').style.display='none';
	$('wrapper').appendChild($('plugin'));
	this.clear_form();
}

//bch36: the top blog posts widget
var cont_blog_top_posts = Class.create();
Object.extend(cont_blog_top_posts.prototype,cont_class.prototype);

//bch36: the blog comments widget
var cont_blog_recent_comments = Class.create();
Object.extend(cont_blog_recent_comments.prototype,cont_class.prototype);

//bch36: the blog blogroll widget
var cont_blog_blogroll = Class.create();
Object.extend(cont_blog_blogroll.prototype,cont_class.prototype);

cont_blog_blogroll.prototype.def= function()
{
	var data = Array();

	//data['number_to_show'] = 6;

	return data;
}

cont_blog_blogroll.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(400, 300, 'frm_blog_blogroll.inc', this.save.bind(this));
}

cont_blog_blogroll.prototype.edit_cb= function(response)
{
	//var data = this.data;

	insert_html_response(this.edit_div, response);

	// set up updates
	//$('number_to_show').onkeyup= this.updateKeyUpField.bind(this, "number_to_show");

	//$('data_save').onclick= this.save.bind(this);
	$('data_done').onclick= this.widget.cancel.bind(this.widget);
	$('data_add').onclick= this.addBlog.bind(this);

	/*
	if (this.data['number_to_show'])
		$('number_to_show').value = this.data['number_to_show'];
	else
		$('number_to_show').value = 6;
	*/

	blogroll = new SimpleAjax("get_blogroll", "/ajax/blog_blogroll.php", this.blogroll_callback.bind(this));
	blogroll.sendPost(new Array("action=get_blogroll"
		, "site_page_content_id="+this.widget.db_id
	));
}

cont_blog_blogroll.prototype.blogroll_callback = function(response)
{
        var status = response.getAttribute("status");
        var action = response.getAttribute("action");
        var link_color = response.getAttribute("link_color");
        var title = response.getAttribute("title");
        var link = response.getAttribute("link");
        var blogroll_id = response.getAttribute("blogroll_id");

        if (status == "error")
        {
		alert(response.firstChild.nodeValue);
        }
        else 
        {
		var blogroll = util_json(response.firstChild.nodeValue);

		if ($('form_blogroll_list'))
		{
			//If a new blog was added, add it to the list, otherwise, set the list
			if (action == "add_blogroll")
			{
				$('form_blogroll_list').innerHTML = this.get_link(id, title, link, link_color) + $('form_blogroll_list').innerHTML;
			}
			else if (action == "delete_blogroll")
			{
				$('link_'+blogroll_id).style.display = "none";
			}
			else
			{
				for (i = 0; i < blogroll.length; i++)
				{
					$('form_blogroll_list').appendChild(this.get_edit_link(blogroll[i]['id'], blogroll[i]['title'], blogroll[i]['link'], link_color));
				}
			}
		}

		//Add all the blogs to the widget
		blogrolls = this.widget.div.getElementsByTagName("div")[2];
                blogrolls.innerHTML = "";
		for (i = 0; i < blogroll.length; i++)
		{
			blogrolls.appendChild(this.get_link(blogroll[i]['title'], blogroll[i]['link'], link_color));
		}
	}
}

cont_blog_blogroll.prototype.delete_link= function(id)
{
	blogroll = new SimpleAjax("get_blogroll", "/ajax/blog_blogroll.php", this.blogroll_callback.bind(this));
	blogroll.sendPost(new Array("action=delete_blogroll"
		, "site_page_content_id="+this.widget.db_id
		, "blogroll_id="+id
	));
}

cont_blog_blogroll.prototype.get_link= function(title, link, link_color)
{
	div = document.createElement("div");

	a = document.createElement("a");
	a.href = link;
	a.className = "cltblue";
	a.style.fontWeight = "bold";
	a.style.textDecoration = "none";
	if (link_color != "")
		a.style.color = "#"+link_color;
	a.innerHTML = title;

	div.appendChild(a);

	return div;
}

cont_blog_blogroll.prototype.get_edit_link= function(id, title, link, link_color)
{
	div = document.createElement("div");
	div.id = "link_"+id;
	div.style.borderBottom = "thin dotted black";
	div.style.fontWeight = "bold";
	div.style.margin = "5px";

	left_div = document.createElement("div");
	left_div.style.cssFloat = "left";
	left_div.style.styleFloat = "left";

	a = document.createElement("a");
	a.href = link;
	a.className = "cltblue";
	if (link_color != "")
		a.style.color = "#"+link_color;
	a.innerHTML = title;

	left_div.appendChild(a);

	right_div = document.createElement("div");
	right_div.style.cssFloat = "right";
	right_div.style.styleFloat = "right";
	right_div.style.cursor = "pointer";
	right_div.value = id;
	right_div.onclick = this.delete_link.bind(this, id);
	right_div.innerHTML = "<img src='/shared/images/delete.png' border='0' />";

	final_div = document.createElement("div");
	final_div.style.clear = "both";

	div.appendChild(left_div);
	div.appendChild(right_div);
	div.appendChild(final_div);

	return div;
}

cont_blog_blogroll.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget = widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_blog_blogroll.prototype.update_display = function()
{
/*
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['number_to_show'] == undefined)
			this.data = this.def();
	}
*/

	//Modify the display based on the preferences
	//eval("update_display('"+this.data['number_to_show']+"', '"+this.data['show_all']+"', '"+this.data['show_only_used']+"')");

	blogroll = new SimpleAjax("get_blogroll", "/ajax/blog_blogroll.php", this.blogroll_callback.bind(this));
	blogroll.sendPost(new Array("action=get_blogroll"
		, "site_page_content_id="+this.widget.db_id
	));
}

cont_blog_blogroll.prototype.resize_cb= function()
{
	this.update_display();
}

cont_blog_blogroll.prototype.addBlog= function ()
{
	blogroll = new SimpleAjax("get_blogroll", "/ajax/blog_blogroll.php", this.blogroll_callback.bind(this));
	blogroll.sendPost(new Array("action=add_blogroll"
		, "site_page_content_id="+this.widget.db_id
		, "title="+$('blogroll_title').value
		, "link="+$('blogroll_link').value
	));

	$('blogroll_title').value = "";
	$('blogroll_link').value = "http://";
}

cont_blog_blogroll.prototype.updateKeyUpField= function (field_name)
{
        this.data[field_name] = $(field_name).value;
}

cont_blog_blogroll.prototype.cancel= function()
{
	this.clear_form();
}



//bch36: the blog search widget
var cont_blog_search = Class.create();
Object.extend(cont_blog_search.prototype,cont_class.prototype);

//bch36: the blog archive widget
var cont_blog_archive = Class.create();
Object.extend(cont_blog_archive.prototype,cont_class.prototype);

//bch36: the registration form widget
var cont_registration = Class.create();
Object.extend(cont_registration.prototype,cont_class.prototype);

//bch36: the php file widget
var cont_php_file = Class.create();
Object.extend(cont_php_file.prototype,cont_class.prototype);

var cont_loginform = Class.create();
Object.extend(cont_loginform.prototype, cont_class.prototype);

var cont_loginforminline = Class.create();
Object.extend(cont_loginforminline.prototype, cont_class.prototype);

var cont_citylistings = Class.create();
Object.extend(cont_citylistings.prototype,cont_class.prototype);


cont_citylistings.prototype.edit = function()
{
	this.load_form(250, 150, 'frm_citylistings.inc', this.save.bind(this));
}

cont_citylistings.prototype.updateKeyUpField= function (field_name)
{
	var ctrl = 'data_' + field_name;
        this.data[field_name] = $(ctrl).value;
}

cont_citylistings.prototype.edit_cb= function(response)
{
	var data = this.data = this.widget.get_data();
	insert_html_response(this.edit_div, response);

	if(data.count) {
		$('data_count').value = data.count;
	}

	if(data.title) {
		$('data_title').value = data.title;
	}

	if(data.threshold) {
		$('data_threshold').value = data.threshold;
	}

	$('data_title').onkeyup = this.updateKeyUpField.bind(this, "title");
	$('data_count').onkeyup = this.updateKeyUpField.bind(this, "count");
	$('data_threshold').onkeyup = this.updateKeyUpField.bind(this, "threshold");
	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

}

cont_citylistings.prototype.cancel = function()
{
	this.clear_form();
}

cont_php_file.prototype.def= function()
{
	var data = Array();

	data['filename'] = '';

	return data;
}

cont_php_file.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(250, 150, 'frm_php_file.inc', this.save.bind(this));
}

cont_php_file.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);

	// set up updates
	$('filename').onkeyup= this.updateKeyUpField.bind(this, "filename");

	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	if (this.data['filename'])
		$('filename').value = this.data['filename'];
}

cont_php_file.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget = widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_php_file.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['filename'] == undefined)
			this.data = this.def();
	}

	//Get the php file contents and display them
	content = new SimpleAjax("get_php_file", "/ajax/php_file.php", this.php_file_callback.bind(this));
	content.sendPost(new Array("action=get_php_file"
		, "filename="+this.data['filename']
		, "widget_num="+this.widget.get_widget_num()
	));
}

cont_php_file.prototype.php_file_callback = function(response)
{
        var status = response.getAttribute("status");
        var widget_num = response.getAttribute("widget_num");

        if (status == "error")
        {
		alert(response.firstChild.nodeValue);
        }
        else 
        {
		var content = response.firstChild.nodeValue;
		content_div = cont_mgr.list[widget_num].widget.div.getElementsByTagName("div")[1];
		content_div.innerHTML = content;
	}
}

cont_php_file.prototype.resize_cb= function()
{
	this.update_display();
}

cont_php_file.prototype.updateKeyUpField= function (field_name)
{
        this.data[field_name] = $(field_name).value;
}

cont_php_file.prototype.cancel= function()
{
	this.clear_form();
}

//bch36: the blog recent posts widget
var cont_blog_recent_posts = Class.create();
Object.extend(cont_blog_recent_posts.prototype,cont_class.prototype);

cont_blog_recent_posts.prototype.def= function()
{
	var data = Array();

	data['blog_id'] = 0;
	data['rss_feed'] = '';

	data['number_to_show'] = 5;
	data['show_all'] = 'N';

	data['widget_title'] = '';
	data['use_feed_title'] = 'Y';

	data['title_color'] = "";
	data['link_color'] = "";
	data['text_color'] = "";

	return data;
}

cont_blog_recent_posts.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(400, 430, 'frm_blog_recent_posts.inc', this.save.bind(this));
}

cont_blog_recent_posts.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);

	if ($('plugin') != null) //For some reason the plugin was becoming null, so I added this check as a stopgap fix
		$('color_pick_wrap').appendChild($('plugin'));

	// set up updates
	$('blog_id').onchange= this.updateChangeField.bind(this, "blog_id");
	$('rss_feed').onkeyup= this.updateKeyUpField.bind(this, "rss_feed");

	$('number_to_show').onkeyup= this.updateKeyUpField.bind(this, "number_to_show");
	$('widget_title').onkeyup= this.updateKeyUpField.bind(this, "widget_title");

	$('show_all').onclick= this.updateClickField.bind(this, "show_all");
	$('use_feed_title').onclick= this.updateClickField.bind(this, "use_feed_title");

	updateTitleColor = this.updateTitleColor.bind(this);
	updateLinkColor = this.updateLinkColor.bind(this);
	updateTextColor = this.updateTextColor.bind(this);

	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	if (this.data['blog_id'] && $('blog_id'))
	{
		for (i = 0; i < $('blog_id').options.length; i++)
			if ($('blog_id').options[i].value == this.data['blog_id'])
				$('blog_id').options[i].selected = true;
	}

	if (this.data['rss_feed'])
		$('rss_feed').value = this.data['rss_feed'];

	if (this.data['number_to_show'])
		$('number_to_show').value = this.data['number_to_show'];
	else
		$('number_to_show').value = 5;

	if (this.data['widget_title'] && this.data['widget_title'] != "")
		$('widget_title').value = this.data['widget_title'];

	if (this.data['show_all'] && this.data['show_all'] == "Y")
		$('show_all').checked = true;

	if (this.data['use_feed_title'] && this.data['use_feed_title'] == "Y")
		$('use_feed_title').checked = true;

	if (this.data['title_color'])
		$('recent_posts_test_title').style.color = data_titleColor = this.data['title_color'];
	if (this.data['link_color'])
		$('recent_posts_test_link').style.color = data_linkColor = this.data['link_color'];
	if (this.data['text_color'])
		$('recent_posts_test_text').style.color = data_textColor = this.data['text_color'];
}

cont_blog_recent_posts.prototype.updateTitleColor= function (color)
{
	data_titleColor = color;
	$('recent_posts_test_title').style.color = "#"+color;
	this.data['title_color'] = color;
}

cont_blog_recent_posts.prototype.updateLinkColor= function (color)
{
	data_linkColor = color;
	$('recent_posts_test_link').style.color = "#"+color;
	this.data['link_color'] = color;
}

cont_blog_recent_posts.prototype.updateTextColor= function (color)
{
	data_textColor = color;
	$('recent_posts_test_text').style.color = "#"+color;
	this.data['text_color'] = color;
}

cont_blog_recent_posts.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget = widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_blog_recent_posts.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['number_to_show'] == undefined)
			this.data = this.def();
		this.updater = new blog_recent_posts_updater(this.widget.get_widget_num(), this.data);
	}

	this.updater.get_recent_posts();
}

cont_blog_recent_posts.prototype.recent_posts_callback = function(response)
{
        var status = response.getAttribute("status");
        var widget_num = response.getAttribute("widget_num");

        if (status == "error")
        {
		alert(response.firstChild.nodeValue);
        }
        else 
        {
		var title = response.getAttribute("title");

		title_div = cont_mgr.list[widget_num].widget.div.getElementsByTagName("div")[1];
		if (cont_mgr.list[widget_num].data['use_feed_title'] == "Y" && title != "")
			title_div.innerHTML = title;
		else if (cont_mgr.list[widget_num].data['widget_title'] != "")
			title_div.innerHTML = cont_mgr.list[widget_num].data['widget_title'];

		if (cont_mgr.list[widget_num].data['title_color'] != "" && cont_mgr.list[widget_num].data['title_color'] != undefined)
			title_div.style.color = "#"+cont_mgr.list[widget_num].data['title_color'];

		var content = response.firstChild.nodeValue;

		content_div = cont_mgr.list[widget_num].widget.div.getElementsByTagName("div")[2];
		content_div.innerHTML = content;
	}
}

cont_blog_recent_posts.prototype.resize_cb= function()
{
	this.update_display();
}

cont_blog_recent_posts.prototype.updateChangeField= function (field_name)
{
        this.data[field_name] = $(field_name).value;
}

cont_blog_recent_posts.prototype.updateKeyUpField= function (field_name)
{
        this.data[field_name] = $(field_name).value;
}

cont_blog_recent_posts.prototype.updateClickField= function (field_name)
{
        this.data[field_name] = $(field_name).checked ? "Y" : "N";
}

cont_blog_recent_posts.prototype.cancel= function()
{
	this.clear_form();
}


//bch36: the blog categories widget
var cont_blog_categories = Class.create();
Object.extend(cont_blog_categories.prototype,cont_class.prototype);

cont_blog_categories.prototype.def= function()
{
	var data = Array();

	data['number_to_show'] = 6;
	data['show_all'] = 'N';
	data['show_only_used'] = 'N';

	return data;
}

cont_blog_categories.prototype.edit= function()
{
	//These are the total dimensions of the entire popup
	this.load_form(300, 200, 'frm_blog_categories.inc', this.save.bind(this));
}

cont_blog_categories.prototype.edit_cb= function(response)
{
	var data = this.data;

	insert_html_response(this.edit_div, response);

	// set up updates
	$('number_to_show').onkeyup= this.updateKeyUpField.bind(this, "number_to_show");
	$('show_all').onclick= this.updateClickField.bind(this, "show_all");
	$('show_only_used').onclick= this.updateClickField.bind(this, "show_only_used");

	$('data_save').onclick= this.save.bind(this);
	$('data_cancel').onclick= this.widget.cancel.bind(this.widget);

	if (this.data['number_to_show'])
		$('number_to_show').value = this.data['number_to_show'];
	else
		$('number_to_show').value = 6;

	if (this.data['show_all'] && this.data['show_all'] == "Y")
		$('show_all').checked = true;

	if (!this.data['show_only_used'] || (this.data['show_only_used'] && this.data['show_only_used'] == "Y"))
		$('show_only_used').checked = true;
}

cont_blog_categories.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget = widget;
	this.widget.min_height -= this.widget.border.top+this.widget.border.bottom;
}

cont_blog_categories.prototype.update_display = function()
{
	if (this.data == null)
	{
		this.data = this.widget.get_data();
		if (this.data['number_to_show'] == undefined)
			this.data = this.def();
	}

	//Modify the display based on the preferences
	eval("update_display('"+this.data['number_to_show']+"', '"+this.data['show_all']+"', '"+this.data['show_only_used']+"')");
}

cont_blog_categories.prototype.resize_cb= function()
{
	this.update_display();
}

cont_blog_categories.prototype.updateKeyUpField= function (field_name)
{
        this.data[field_name] = $(field_name).value;
}

cont_blog_categories.prototype.updateClickField= function (field_name)
{
        this.data[field_name] = $(field_name).checked ? "Y" : "N";
}

cont_blog_categories.prototype.cancel= function()
{
	this.clear_form();
}



//bch36: the blog search widget
var cont_blog_search = Class.create();
Object.extend(cont_blog_search.prototype,cont_class.prototype);

//bch36: the blog archive widget
var cont_blog_archive = Class.create();
Object.extend(cont_blog_archive.prototype,cont_class.prototype);

//bch36: the blog calendar widget
var cont_blog_calendar = Class.create();
Object.extend(cont_blog_calendar.prototype,cont_class.prototype);

//bch36: added for the main blog content
var cont_blog_content = Class.create();
Object.extend(cont_blog_content.prototype,cont_class.prototype);

cont_blog_content.prototype.initialize= function(editable, widget)
{
	this.editable = editable;
	this.widget = widget;

        listings = new SimpleAjax("create_blog", "/ajax/blog_create.php", this.blog_content_callback.bind(this));
        listings.sendPost(new Array("action=create_blog"
                , "page_id="+page_id
        ));
}

cont_blog_content.prototype.blog_content_callback = function(response)
{

}

cont_blog_content.prototype.edit = function()
{
	window.open("/site/blog.php?page_id="+page_id, "BlogEditor", "");
	this.widget.cancel();
}

//bch36: added for the second featured property widget (featprop2)
var cont_featprop2 = Class.create();
Object.extend(cont_featprop2.prototype,cont_class.prototype);
cont_featprop2.prototype.edit = function()
{
    alert("This widget will only show listings with your Agent ID.  To set your Agent ID, choose the \"Account Information\" menu option from the administration area, then choose \"Personal Information\", then click \"edit\".");
    this.widget.cancel();
}


var cont_podcast1 = Class.create();
Object.extend(cont_podcast1.prototype,cont_class.prototype);

cont_podcast1.disp_cb = function(response)
{
    insert_html_response(this.display_div, response);
    this.update_display();
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}
cont_podcast1.prototype.edit = function()
{
    this.load_form(310, 270, 'frm_simple_widget.inc',this.my_save.bind(this));
}
cont_podcast1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    this.code_text = $('widget1_text');
    if (this.code_text != null && this.data != null)
        this.code_text.innerHTML = this.data['code'];
    $('widget1_save_btn').onclick = this.my_save.bind(this);
    this.close_div.onclick = this.my_save.bind(this);
    $('widget1_cancel_btn').onclick = this.my_cancel.bind(this);
    $('widget1_instruct').innerHTML = "Enter the URL of the RSS for your Podcast. If you need help creating a podcast, try a service such as <a class='unlink admin_link_color' target='_blank' href='http://www.podomatic.com'>podomatic.com</a>";
}

cont_podcast1.prototype.update_display = function()
{
    if (this.data == null)
    {
        this.data= this.widget.get_data();
    }
    var link = this.display_div.getElementsByTagName("A")[0];
    var script = this.display_div.getElementsByTagName("SCRIPT")[0];
    var iframe = this.display_div.getElementsByTagName("IFRAME")[0];
    
    if (this.data['code'] == null) this.data['code'] = "";
    if (link != null)
    {
        link.src = "http://grazr.com/read?view=o&amp;file="+this.data['code'];
    }
    if (script != null)
    {
        script.src = "http://grazr.com/gzloader.js?view=o&amp;file="+this.data['code'];
    }
    if (iframe != null)
    {
        iframe.src = "http://grazr.com/gzpanel.html?view=o&file="+this.data['code'];
    }
}


cont_podcast1.prototype.my_save = function()
{
     this.data['code'] = this.code_text.value;
     this.update_display();
     this.widget.save();
     this.clear_form();
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}

cont_podcast1.prototype.my_cancel = function()
{
    this.clear_form();
    this.widget.cancel();
}

var cont_chat1 = Class.create();
Object.extend(cont_chat1.prototype,cont_class.prototype);

cont_chat1.disp_cb = function(response)
{
    insert_html_response(this.display_div, response);
    this.update_display();
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}
cont_chat1.prototype.edit = function()
{
    this.load_form(370, 300, 'frm_simple_widget.inc',this.my_save.bind(this));
}
cont_chat1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    this.code_text = $('widget1_text');
    if (this.code_text != null && this.data != null)
        this.code_text.innerHTML = this.data['code'];
    $('widget1_save_btn').onclick = this.my_save.bind(this);
    this.close_div.onclick = this.my_save.bind(this);
    $('widget1_cancel_btn').onclick = this.my_cancel.bind(this);
    $('widget1_instruct').innerHTML = "This chat widget uses plugoo to provide instant messaging to many existing IM services. Go to <a class='unlink admin_link_color' target='_blank' href='http://www.plugoo.com'>www.plugoo.com</a> and sign up. Ater you sign up, paste or type your plugoo code in the box below. It is a 15 character value that you will find in the URL field on your plugoo account under \"my widgets\".";
}

cont_chat1.prototype.reset_display = function()
{
    this.widget.div.removeChild(this.display_div);
    var iframe = this.display_div.getElementsByTagName("IFRAME")[0]; 
    var object = this.display_div.getElementsByTagName("OBJECT")[0];
    var param = this.display_div.getElementsByTagName("PARAM")[0];
    
    if (iframe != null)
    {
        iframe.width = this.widget.width;
        iframe.height = this.widget.height;
    }
    if (object != null)
    {
        object.width = this.widget.width;
        object.height = this.widget.height;
    }
    this.widget.div.appendChild(this.display_div);
}

cont_chat1.prototype.update_display = function()
{
    if (this.data == null)
    {
        this.data= this.widget.get_data();
    }
    var object = this.display_div.getElementsByTagName("OBJECT")[0];
    var param = this.display_div.getElementsByTagName("PARAM")[0];
    var iframe = this.display_div.getElementsByTagName("IFRAME")[0]; 
    
    if (this.data['code'] == null) this.data['code'] = "";
    if (iframe != null)
    {
        var src = iframe.src;
        iframe.src = src.replace(/V015DM7M1AZV291/g, this.data['code']);
        iframe.width = this.widget.width;
        iframe.height = this.widget.height;
    }
    if (object != null)
    {
        object.data = "http://www.plugoo.com/plug.swf?go="+this.data['code'];
        object.width = this.widget.width;
        object.height = this.widget.height;
    }
    
    if (param != null)
    {
        param.value = "http://www.plugoo.com/plug.swf?go="+this.data['code'];
    }
//    this.widget.div.removeChild(this.display_div); 
//    this.widget.div.appendChild(this.display_div);
}


cont_chat1.prototype.my_save = function()
{
     this.data['code'] = this.code_text.value;
     this.update_display();
     this.widget.save();
     this.clear_form();
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}

cont_chat1.prototype.my_cancel = function()
{
    this.clear_form();
    this.widget.cancel();
}

var add_lth = null;

var homeSelected = null;
var remove_featured = null;
var add_featured_prop = null;

var cont_featprop1 = Class.create();
Object.extend(cont_featprop1.prototype,cont_class.prototype);
cont_featprop1.prototype.initialize = function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = Array("width="+widget.cont.width);
    if (editable)
    {
        this.ext_args.push("edit_mode=true");
        homeSelected = this.home_selected.bind(this);
        remove_featured = this.remove_featured.bind(this);
        add_featured_prop = this.add_prop.bind(this);
    }

    this.data = widget.get_data();
}

var lookupWindow = null;
cont_featprop1.prototype.edit = function()
{
    
    this.widget.div.style.zIndex = 53500;
}

cont_featprop1.prototype.add_prop = function()
{
    lookupWindow = window.open(layout_path+"/home_lookup.php", '', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=500,height=600');
    if(lookupWindow != null)
    {
        lookupWindow.focus();
        this.widget.div.style.zIndex = 53500;
    }
}

cont_featprop1.prototype.save_cb =  function(response)
{
    this.finish_save(response);
    this.update_display();
}

cont_featprop1.prototype.home_selected = function(lth)
{
    if (this.data['lth'] == null)
    {
        this.data['lth'] = "";
    }
    if (this.data['lth'].length > 0)
    {
        this.data['lth'] += ',';
    }
    this.data['lth'] += lth;
    this.save();
    this.widget.div.removeChild(this.display_div);
    this.display(false);
//    lookupWindow.close();
}

cont_featprop1.prototype.remove_featured = function(lth)
{
    var feat_array = this.data['lth'].split(',');
    for (var i=0; i< feat_array.length; i++)
    {
        if (feat_array[i] == lth)
        {
            feat_array.splice(i,1);
        }
    }
    
    this.data['lth'] = feat_array.join(',');
    this.save();
    this.widget.div.removeChild(this.display_div);
    this.display(false);
//    lookupWindow.close();
}

cont_featprop1.prototype.update_display = function()
{
    this.reset_display();    
}

cont_featprop1.prototype.reset_display = function()
{
    var el = this.display_div.getElementsByTagName('DIV')[0];
    if (el != null)
    {
        el.style.height= this.widget.height;
        el.style.width = this.widget.width-1;
    }

}
cont_featprop1.prototype.cancel= function()
{
    this.widget.div.style.zIndex = this.widget.layer;
    this.widget.edit_buttons.style.zIndex = this.widget.layer+54000;
}

var sold_add_lth = null;

var sold_homeSelected = null;
var sold_remove = null;
var sold_add_prop = null;

var cont_soldprop1 = Class.create();
Object.extend(cont_soldprop1.prototype,cont_class.prototype);
cont_soldprop1.prototype.initialize = function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = Array("width="+widget.cont.width);
    if (editable)
    {
        this.ext_args.push("edit_mode=true");
        sold_homeSelected = this.home_selected.bind(this);
        sold_remove = this.remove_sold.bind(this);
        sold_add_prop = this.add_prop.bind(this);
    }

    this.data = widget.get_data();
}

cont_soldprop1.prototype.edit = function()
{
    
    this.widget.div.style.zIndex = 53500;
}

cont_soldprop1.prototype.add_prop = function()
{
    lookupWindow = window.open(layout_path+"/home_lookup.php", '', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=500,height=600');
    if(lookupWindow != null)
    {
        lookupWindow.focus();
        this.widget.div.style.zIndex = 53500;
    }
}

cont_soldprop1.prototype.save_cb =  function(response)
{
    this.finish_save(response);
    this.update_display();
}

cont_soldprop1.prototype.home_selected = function(lth)
{
    if (this.data['lth'] == null)
    {
        this.data['lth'] = "";
    }
    if (this.data['lth'].length > 0)
    {
        this.data['lth'] += ',';
    }
    this.data['lth'] += lth;
    this.save();
    this.widget.div.removeChild(this.display_div);
    this.display(false);
//    lookupWindow.close();
}

cont_soldprop1.prototype.remove_sold = function(lth)
{
    var feat_array = this.data['lth'].split(',');
    for (var i=0; i< feat_array.length; i++)
    {
        if (feat_array[i] == lth)
        {
            feat_array.splice(i,1);
        }
    }
    
    this.data['lth'] = feat_array.join(',');
    this.save();
    this.widget.div.removeChild(this.display_div);
    this.display(false);
//    lookupWindow.close();
}

cont_soldprop1.prototype.update_display = function()
{
    this.reset_display();    
}

cont_soldprop1.prototype.reset_display = function()
{
    var el = this.display_div.getElementsByTagName('DIV')[0];
    if (el != null)
    {
        el.style.height= this.widget.height;
        el.style.width = this.widget.width-1;
    }

}
cont_soldprop1.prototype.cancel= function()
{
    this.widget.div.style.zIndex = this.widget.layer;
    this.widget.edit_buttons.style.zIndex = this.widget.layer+54000;
}


var cont_img2 = Class.create();
Object.extend(cont_img2.prototype,cont_class.prototype);

var cont_img3 = Class.create();
Object.extend(cont_img3.prototype,cont_class.prototype);
cont_img3.prototype.update_display = function()
{
     this.data = this.widget.get_data();
     $('data_img3').width = this.widget.width;
     $('data_img3').height = this.widget.height;
     $('data_img3').src = this.data['src'];
     $('data_img3').id = this.id = 'data_img3'+this.widget.get_widget_id();
}
cont_img3.prototype.reset_display = function()
{
    if ($(this.id) != null)
    {
        $(this.id).width = this.widget.width;
        $(this.id).height = this.widget.height;
    }
}
cont_img3.prototype.edit = function()
{
    curImgSelFunc = this.imageSelected.bind(this);
    var imageWindow = window.open('/site/image_manage.php?site_id='+site_id+'&control=find_img&dir=large', 'images', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=1280,height=800');
}
cont_img3.prototype.imageSelected = function(parms)
{
    $('data_img3'+this.widget.get_widget_id()).src = this.data['src'] =  parms[0];
}

var cont_secnav1 = Class.create();
Object.extend(cont_secnav1.prototype,cont_class.prototype);

cont_secnav1.prototype.initialize= function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = Array("page_id="+page_id);
}

var cont_secnav2 = Class.create();
Object.extend(cont_secnav2.prototype,cont_class.prototype);

cont_secnav2.prototype.initialize= function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = Array("page_id="+page_id);
}

var cont_website_message = Class.create();
Object.extend(cont_website_message.prototype,cont_class.prototype);

cont_website_message.prototype.initialize= function(editable, widget)
{
    this.editable = editable;
    this.widget = widget;
    this.ext_args = Array("page_id="+page_id);
}

var cont_space1 = Class.create();
Object.extend(cont_space1.prototype,cont_class.prototype);

var cont_video1 = Class.create();
Object.extend(cont_video1.prototype,cont_class.prototype);
cont_video1.prototype.edit = function()
{
    this.load_form(310, 270, 'frm_simple_widget.inc',this.my_save.bind(this));
}
cont_video1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    this.code_text = $('widget1_text');
    if (this.code_text != null && this.data != null)
        this.code_text.innerHTML = this.data['code'];
    $('widget1_text').style.height = '35px';
    $('widget1_save_btn').onclick = this.my_save.bind(this);
    $('widget1_cancel_btn').onclick = this.my_cancel.bind(this);
    $('widget1_instruct').innerHTML = "Enter the YouTube video code here. You can paste embed text, URL, or video code from YouTube. After saving, you may need to refresh your browser to see your video.";
}

cont_video1.prototype.update_display = function()
{
    if (this.data == null)
    {
        this.data= this.widget.get_data();
    }
    if (this.data['code'] == null) this.data['code'] = "";
    if (this.data['code'].length > 15)
        this.data['code'] = 'nosuch_code';
    this.display_div.innerHTML = '<div><object id="u2be_obj" width="'+
                this.widget.width+
                '" height="'+
                this.widget.height+
                '"><param name="movie" value="http://www.youtube.com/v/"'+
                this.data['code']+
                '"/><param name="wmode" value="transparent"/><embed id="u2be_embed" src="http://www.youtube.com/v/'+
                this.data['code']+
                '" type="application/x-shockwave-flash" wmode="transparent" width="'+
                this.widget.width+
                '" height="'+
                this.widget.height+
                '" allowscriptaccess="always" ></embed></object></div>';

    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}


cont_video1.prototype.my_save = function()
{
     if (this.code_text.value.length > 18)
     {
          var exp = /(\/v\/|\?v\=)([\-a-zA-Z0-9_\&]{1,})(\=|$|\&)/i; 
          
          var newval = this.code_text.value.match(exp);
          if (newval != null)
          {
              this.code_text.value = newval[2];
          }
          else 
          {
              this.code_text.value = 'nosuch_code';
          }
     }
     this.data['code'] = this.code_text.value;
     this.update_display();
     this.widget.save();
     this.clear_form();
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}

cont_video1.prototype.my_cancel = function()
{
    this.clear_form();
    this.widget.cancel();
}

cont_video1.prototype.reset_display = function()
{
    var obj = this.display_div.getElementsByTagName("OBJECT")[0];
    var embed = this.display_div.getElementsByTagName("EMBED")[0];
    if (obj != null)
    {
        obj.width = this.widget.width;
        obj.height = this.widget.height;
    }
    if (embed != null)
    {
        embed.width = this.widget.width;
        embed.height = this.widget.height;
    }
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}


var cont_quotes1 = Class.create();
Object.extend(cont_quotes1.prototype,cont_class.prototype);


var updateOvlColor;
var updateOvlBg;
var transparentOvl;
var chooseOvl;
var data_ovlColor = "FFFFFF";
var data_ovlBg = "d0d0d0";

var cont_ovl1 = Class.create();
Object.extend(cont_ovl1.prototype,cont_class.prototype);

cont_ovl1.prototype.update_display = function()
{
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.bg_div = this.display_div.getElementsByTagName('DIV')[0];
        this.ovl_div = this.bg_div.getElementsByTagName('DIV')[0];
        this.ovl_div.id = 'ovl1_'+this.widget.widget_number;
    }
    
    if (this.data['background'] == null || this.data['transparent'] == 'y')
        this.bg_div.style.backgroundColor = null;
    else
        this.bg_div.style.backgroundColor = "#"+this.data['background'];
    this.ovl_div.style.background = "url(/shared/images/colorize.php?&c="+this.data['color']+"&img=/shared/images/overlays/"+this.data['image']+") no-repeat bottom center";
//    this.display_div.style.position="absolute";
//    this.display_div.style.top=this.widget.cont_el.my_class.height - this.widget.height;
}
    

cont_ovl1.prototype.edit = function()
{             
    this.load_form(690, 300, 'frm_ovl.inc', this.save.bind(this));
        
};

cont_ovl1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    $('color_pick_wrap').appendChild($('plugin'));
        
    updateOvlBg = this.updateOvlBg.bind(this);
    updateOvlColor = this.updateOvlColor.bind(this);
    transparentOvl = this.transparentOvl.bind(this);
    $('ovl_cancel').onclick= this.widget.cancel.bind(this.widget);

    chooseOvl = this.chooseOvl.bind(this);
    cancelOvl = this.cancel.bind(this);
    $('ovl_transparent').checked = this.data['transparent'] == 'y';
    this.updateOvlColor(this.data['color']);
    this.updateOvlBg(this.data['background']);
//    this.updateOvlImg(this.data['image']);
};
cont_ovl1.prototype.updateOvlBg= function (color)
{
    data_ovlBg = color;
    if (this.data['transparent'] == 'y')
    {
        $('ovl_samples').style.backgroundColor = "#e0e0e0";
        $('ovl_bg_sample').style.background = "url(/shared/images/redslash.gif)";
    }
    else
    {
        $('ovl_bg_sample').style.background = "";
        $('ovl_samples').style.backgroundColor = $('ovl_bg_sample').style.backgroundColor = "#"+color;
    }
    this.data['background'] = color;
};

cont_ovl1.prototype.transparentOvl= function(checked)
{
    if (checked)
    {
        this.data['transparent'] = 'y';
    }
    else
    {
        this.data['transparent'] = 'n';
    }
    this.updateOvlBg(this.data['background']);
};


cont_ovl1.prototype.updateOvlColor = function(color)
{
    for (var i=0; i<cont_ovl1.list.length; i++)
    {
        if (cont_ovl1.list[i].color != "")
        {
            $("ovl_"+i).style.background = "url(/shared/images/colorize.php?&c="+color+"&img=/shared/images/overlays/"+cont_ovl1.list[i]+") no-repeat bottom";
        }
    }
    data_ovlColor = color;
    $('ovl_color_sample').style.backgroundColor = "#"+color;
    this.data['color'] = color;
};

cont_ovl1.prototype.chooseOvl = function(index)
{
    if (index == null)
        index = 0;
    if (index != -1)
        this.data['image'] = cont_ovl1.list[index];
    this.data['color'] = data_ovlColor;
    this.data['background'] = data_ovlBg;
    this.update_display(this.data);
    this.widget.save();
};
cont_ovl1.prototype.cancel = function()
{
    $('plugin').style.display='none';
    $('wrapper').appendChild($('plugin'));
    this.clear_form();
};

var cont_ovl2 = Class.create();
Object.extend(cont_ovl2.prototype,cont_ovl1.prototype);

cont_ovl2.prototype.update_display = function()
{
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.bg_div = this.display_div.getElementsByTagName('DIV')[0];
        this.ovl_div = this.bg_div.getElementsByTagName('IMG')[0];
        this.ovl_div.id = 'ovl2_'+this.widget.widget_number;
    }
    
    if (this.data['background'] == null || this.data['transparent'] == 'y')
        this.bg_div.style.backgroundColor = null;
    else
        this.bg_div.style.backgroundColor = "#"+this.data['background'];
    this.ovl_div.src = "/shared/images/colorize.php?c="+this.data['color']+"&img=/shared/images/overlays2/"+this.data['image'];
    this.ovl_div.width = this.widget.width;
    this.ovl_div.height = this.widget.height;
    this.ovl_div.className = "png";
//    this.display_div.style.position="absolute";
//    this.display_div.style.top=this.widget.cont_el.my_class.height - this.widget.height;
}
cont_ovl2.prototype.edit = function()
{             
    this.load_form(690, 300, 'frm_ovl2.inc', this.save.bind(this));
        
};

cont_ovl2.prototype.updateOvlColor = function(color)
{
    for (var i=0; i<cont_ovl2.list.length; i++)
    {
        if (cont_ovl2.list[i].color != "")
        {
            $("ovl_"+i).style.background = "url(/shared/images/colorize.php?&c="+color+"&img=/shared/images/overlays2/"+cont_ovl2.list[i]+") no-repeat bottom";
        }
    }
    data_ovlColor = color;
    $('ovl_color_sample').style.backgroundColor = "#"+color;
    this.data['color'] = color;
};

cont_ovl2.prototype.chooseOvl = function(index)
{
    if (index == null)
        index = 0;
    if (index != -1)
        this.data['image'] = cont_ovl2.list[index];
    this.data['color'] = data_ovlColor;
    this.data['background'] = data_ovlBg;
    this.update_display(this.data);
    this.widget.save();
};
/*var cont_ovl2 = Class.create();
Object.extend(cont_ovl2.prototype, cont_ovl1.prototype);
cont_ovl1.prototype.update_display = function()
{
    if (this.data == null)
    {
        var data = this.data= this.widget.get_data();
        this.bg_div = this.display_div.getElementsByTagName('DIV')[0];
        this.ovl_img = this.bg_div.getElementsByTagName('IMG')[0];
        this.ovl_img.id = 'ovl2_'+this.widget.widget_number;
    }
    
    if (this.data['background'] == null || this.data['transparent'] == 'y')
        this.bg_div.style.backgroundColor = null;
    else
        this.bg_div.style.backgroundColor = "#"+this.data['background'];
    this.ovl_img.src = "/shared/images/colorize.php?&c="+this.data['color']+"&img=/shared/images/overlays/"+this.data['image'];
}

*/

var cont_widget1 = Class.create();
Object.extend(cont_widget1.prototype,cont_text2.prototype);
cont_widget1.disp_cb = function(response)
{
    insert_html_response(this.display_div, response);
    this.update_display();
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}
cont_widget1.prototype.edit = function()
{
    this.load_form(510, 470, 'frm_simple_widget.inc',this.my_save.bind(this));
}
cont_widget1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    this.code_text = $('widget1_text');
    if (this.code_text != null && this.data != null)
        this.code_text.value = this.data['code'];
    $('widget1_save_btn').onclick = this.my_save.bind(this);
    $('widget1_cancel_btn').onclick = this.my_cancel.bind(this);
    $('widget1_instruct').innerHTML = "Enter widget code here";
}


cont_widget1.prototype.update_display = function()
{
    if (this.data == null)
    {
        this.data= this.widget.get_data();
    }
    var iframe = this.display_div.getElementsByTagName("iframe")[0];
    
    if (this.data['code'] == null) this.data['code'] = "";
    if (iframe != null)
    {
        iframe.contentWindow.location.replace("/ajax/preview.php?id="+this.widget.db_id);
        //iframe.contentWindow.location.href = "/ajax/preview.php?id="+this.widget.db_id;
        //iframe.contentWindow.location.href = "/ajax/preview.php?code="+encodeURIComponent(this.data['code']);
    }
}
cont_widget1.prototype.reset_display = function()
{
    this.update_display();
}

cont_widget1.prototype.reset_display = function()
{
    this.update_display();
}


cont_widget1.prototype.my_save = function()
{
     this.data['code'] = this.code_text.value;
     this.update_display();
     this.widget.save();
     this.clear_form();
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}

cont_widget1.prototype.my_cancel = function()
{
    this.clear_form();
    this.widget.cancel();
}

var cont_rss1 = Class.create();
Object.extend(cont_rss1.prototype,cont_text2.prototype);
cont_rss1.disp_cb = function(response)
{
    insert_html_response(this.display_div, response);
    this.update_display();
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}
cont_rss1.prototype.edit = function()
{
    this.load_form(310, 270, 'frm_simple_widget.inc',this.my_save.bind(this));
}
cont_rss1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    this.code_text = $('widget1_text');
    if (this.code_text != null && this.data != null)
        this.code_text.innerHTML = this.data['code'];
    $('widget1_save_btn').onclick = this.my_save.bind(this);
    $('widget1_cancel_btn').onclick = this.my_cancel.bind(this);
    $('widget1_instruct').innerHTML = "Enter your RSS feed URL here";
}

cont_rss1.prototype.update_display = function()
{
    if (this.data == null)
    {
        this.data= this.widget.get_data();
    }
    var script = this.display_div.getElementsByTagName("script")[0];
    
    if (this.data['code'] == null) this.data['code'] = "";
    if (script != null)
    {
        script.src = "/marquee_feed.php?src="+escape(this.data['code'])+"&amp;chan=y&amp;date=y&amp;html=a";
    }
}


cont_rss1.prototype.my_save = function()
{
     this.data['code'] = this.code_text.value;
     this.update_display();
     this.widget.save();
     this.clear_form();
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}

cont_rss1.prototype.my_cancel = function()
{
    this.clear_form();
    this.widget.cancel();
}


var cont_links1 = Class.create();
Object.extend(cont_links1.prototype,cont_class.prototype);

var cont_weather1 = Class.create();
Object.extend(cont_weather1.prototype,cont_class.prototype);

cont_weather1.prototype.edit = function()
{
    this.load_form(310, 270, 'frm_simple_widget.inc',this.my_save.bind(this));
}
cont_weather1.prototype.edit_cb= function(response)
{
    insert_html_response(this.edit_div, response);
    this.code_text = $('widget1_text');
    if (this.code_text != null && this.data != null)
        this.code_text.innerHTML = this.data['code'];
    $('widget1_save_btn').onclick = this.my_save.bind(this);
    $('widget1_cancel_btn').onclick = this.my_cancel.bind(this);
    $('widget1_instruct').innerHTML = "Enter the local zipcode for weather information.";
}

cont_weather1.prototype.update_display = function()
{
    if (this.data == null)
    {
        this.data= this.widget.get_data();
    }
    var iframe = this.display_div.getElementsByTagName("IFRAME")[0];
    if (this.data['code'] == null) this.data['code'] = "";
    if (iframe != null)
    {
        var src = '<div id="wx_module_4720"><a href="http://www.weather.com/weather/local/'+this.data['code']+'">Local Weather Forcast ('+this.data['code']+')</a></div><scr'+'ipt src="http://wow.weather.com/weather/wow/module/'+this.data['code']+'?config=SZ=300x250*WX=FHW*LNK=SSNL*UNT=F*BGI=sun*MAP=null|null*DN=blueroof360.com*TIER=0*PID=1058481579*MD5=387b724f338bcc7a3d81e2367ebb0af0&proto=http&target=wx_module_4720"></scr'+'ipt>';
        iframe.src = "/ajax/preview.php?code="+escape(src);
    }
    if (this.save_after_display)
    {
        this.save_after_display=false;
        this.widget.save();
    }
}

cont_weather1.prototype.my_save = function()
{
     this.data['code'] = this.code_text.value;
     this.update_display();
     this.widget.save();
     this.clear_form();
     this.widget.div.removeChild(this.display_div); 
     this.widget.div.appendChild(this.display_div);
}

cont_weather1.prototype.my_cancel = function()
{
    this.clear_form();
    this.widget.cancel();
}


                            
var cont_cal1 = Class.create();
Object.extend(cont_cal1.prototype,cont_class.prototype);

var cont_searchpan1 = Class.create();
Object.extend(cont_searchpan1.prototype,cont_class.prototype);


//********* Flash Button Widget - Begin *********//
        var flashbtnx;
        var flashbtny;
        var cont_flashbutton1 = Class.create();
        Object.extend(cont_flashbutton1.prototype,cont_class.prototype);

        cont_flashbutton1.prototype.initialize = function(editable, widget){
            
            this.editable = editable;
            this.widget = widget;
            this.ext_args = null;
            
            if( editable){
                this.ext_args=new Array();
                this.ext_args.push('edit_mode=true')
            }
        }

        cont_flashbutton1.prototype.custom_save = function()
        {                
            if($('plugin')){
                $('plugin').style.display='none';
                $('wrapper').appendChild($('plugin'));
                
            }
            
            this.widget.save();
            this.clear_form();

            this.widget.div.removeChild(this.display_div); 
            this.widget.div.appendChild(this.display_div);

            this.widget.edit();

        }

        cont_flashbutton1.prototype.save_cb= function(response)
        {    
            this.finish_save(response);
            
            //alert('Saved!');
            
            //this.widget.cancel();
            //this.update_display();
        }

        cont_flashbutton1.prototype.save = function()
        {
            var args = Array("container="+this.widget.get_cont_number(), "list_order="+this.widget.get_list_order(), "content_type_id="+this.widget.get_content_type_id());

            for (var key in this.data)
            {
                if (typeof(this.data[key]) != 'function')
                {
                    args.push("data_"+key+"="+this.data[key]);
                }
            }
            args.push("updater_prefix=data_");

            if (this.widget.db_id == -1)
            {
                args.push("action=add");
            }
            else
            {
                args.push("action=update");
                args.push("content_id="+this.widget.db_id);
            }

            args.push("posx="+this.widget.getx());
            args.push("posy="+this.widget.gety());
            args.push("posz="+this.widget.getz());
            args.push("width="+this.widget.width);
            args.push("height="+this.widget.height);
                
            cont_cmUpdate(args, this.save_cb.bind(this));
            return(true);
            
        }
            
        cont_flashbutton1.prototype.reset_display = function()
        {
            //alert('reset display');
            if(this.edit_div){
                
                this.edit_div.style.top = this.widget.gety();
                this.edit_div.style.left = this.widget.getx();
            }
			var flash_btn = $('flash_button_swf_'+this.widget.widget_number);
			if (flash_btn != null)
			{
				flash_btn.width = this.widget.width;
				flash_btn.height = this.widget.height;
			}
        }    

        cont_flashbutton1.prototype.update_display = function()
        {
            this.widget.edit_buttons.style.marginTop='-20px';
            
            //$('flash_button').style.display='none';
            
            if (this.data == null)
            {
                this.data = this.widget.get_data();
                
                // Init
                if( $('flash_button_swf_-1') ) {
                    setTimeout(function(){ this.edit() }.bind(this), 1000 ); // 250
                }
            }
			this.reset_display();
//			$('flash_button_swf_'+this.widget.widget_number).width = this.widget.width;
//			$('flash_button_swf_'+this.widget.widget_number).height = this.widget.height;
        }    

        cont_flashbutton1.prototype.edit = function()
        {
            if(!$('flash_button_console')){

                this.load_form(0, 0, 'frm_flash_button.inc',this.custom_save.bind(this));

                this.edit_div.style.top = flashbtny = this.widget.gety();
                this.edit_div.style.left = flashbtnx = this.widget.getx();
                flashbtny += this.widget.height;
                flashbtnx -= this.widget.width;
                
                // Remove init instance
                if($('flash_button_swf_'+this.widget.widget_number)){
                    //$('flash_button_swf_'+this.widget.widget_number).parentNode.innerHTML = '';
                    $('flash_button_swf_'+this.widget.widget_number).style.display='none';
                    if($('flash_button_swf_-1')){
                        //alert('going');
                        $('flash_button_swf_-1').style.display='none';
                    }
                }
                
               
            }else this.cancel();                        
        }

        cont_flashbutton1.prototype.form_cancel = function()
        {
            this.widget.cancel();            
        }
        
        cont_flashbutton1.prototype.cancel= function()
        {

            if($('flash_button_swf_'+this.widget.widget_number) || $('flash_button_swf_-1') ){

                  // Add Enumerable to childNodes
                  // Loop through this.edit_div to find current OBJECT node to append into display_div
                  var children = $A(this.edit_div.childNodes);
                  children.each(function(child) {
                    if(child.id == 'flash_button_console'){
                        var grandchildren = $A(child.childNodes);
                        grandchildren.each(function(gchild) {
                            if(typeof gchild.className != 'undefined' && gchild.className.indexOf('text_body') > -1 ){
                            var greatgrandchildren = $A(gchild.childNodes);
                            greatgrandchildren.each(function(ggchild) {
                                if(ggchild.id == 'flash_button'){
                                    
                                    //alert('found!!');
                                    this.display_div.innerHTML='';
                                    this.display_div.appendChild( ggchild );
                                    $('flash_button_swf').id='flash_button_swf_'+this.widget.widget_number;
                                    
                                }      
                            }.bind(this));
                            }      
                        }.bind(this));                        
                    }
                  }.bind(this));

            }            
        
            if($('plugin')){
                $('plugin').style.display='none';
                $('wrapper').appendChild($('plugin'));
            }
                        
            this.clear_form();
        }

        cont_flashbutton1.prototype.clear_form = function()
        {
            if(this.edit_div)
            {
                $('wrapper').removeChild(this.bg_div);
                $('wrapper').removeChild(this.edit_div);
                $('wrapper').removeChild(this.close_div);

                this.edit_div = null;                
            }
        }
                
        cont_flashbutton1.prototype.edit_cb= function(response)
        {   
            insert_html_response(this.edit_div, response);

            
            $('color_pick_wrap').appendChild($('plugin'));

            // Reset color picker positioning                    
//            if($('plugin')){
//                $('plugin').style.top = parseInt( this.widget.height ) + 20 + 'px';
//                $('plugin').style.left = 0;
//            }
            
            // Event Handling
            $('flashbutton1_save_btn').onmouseover = this.updateTitles.bind(this);
            $('flashbutton1_save_btn').onclick = this.custom_save.bind(this);
            $('flashbutton1_cancel_btn').onclick = this.form_cancel.bind(this);
            $('data_url_link').onchange = $('data_url_link').onblur = this.updateLink.bind(this);
            $('data_local_link').onchange = $('data_local_link').onblur = this.updateLocLink.bind(this);
            $('data_href_target').onchange = $('data_href_target').onblur = this.updateHrefTarget.bind(this);
            $('flash_button_title1').onchange = $('flash_button_title1').onblur = this.updateTitle1.bind(this);
            $('flash_button_title2').onchange = $('flash_button_title2').onblur = this.updateTitle2.bind(this);
            $('flash_button_title3').onchange = $('flash_button_title3').onblur = this.updateTitle3.bind(this);
            $('flash_button_font_size').onchange = $('flash_button_font_size').onblur = this.updateFontSize.bind(this);
            $('flash_button_changeCase').onchange = $('flash_button_changeCase').onblur = this.updateCase.bind(this);
            $('flash_button_transparent_bg').onchange = $('flash_button_transparent_bg').onblur = this.updateTransparent.bind(this);
            $('flash_button_use_overlay').onchange = $('flash_button_use_overlay').onblur = this.updateOverlay.bind(this);
            $('flash_button_overlay_alpha').onchange = $('flash_button_overlay_alpha').onblur = this.updateOverlayAlpha.bind(this);
            $('flash_button_radius').onchange = $('flash_button_radius').onblur = this.updateRadius.bind(this);
            $('flash_button_font_face').onchange = $('flash_button_font_face').onblur = this.updateFontFace.bind(this);
            
            
            
            $('flash_button_event_appear').onchange = $('flash_button_event_appear').onblur = this.updateEventAppear.bind(this);
            $('flash_button_event_roll_over').onchange = $('flash_button_event_roll_over').onblur = this.updateEventRollOver.bind(this);
            $('flash_button_event_roll_out').onchange = $('flash_button_event_roll_out').onblur = this.updateEventRollOut.bind(this);
            $('flash_button_event_press').onchange = $('flash_button_event_press').onblur = this.updateEventPress.bind(this);
            $('flash_button_event_release').onchange = $('flash_button_event_release').onblur = this.updateEventRelease.bind(this);
            
            updateFontColor = this.updateFontColor.bind(this);
            updateStartColor = this.updateStartColor.bind(this);
            updateEndColor = this.updateEndColor.bind(this);
            updateBgColor = this.updateBgColor.bind(this);
            updateBorderColor = this.updateBorderColor.bind(this);            
            updateOverlayColor = this.updateOverlayColor.bind(this);

            // Re-populate
            if ( this.data['href'] != null){
                $('data_url_link').value = this.data['href'];
                $('data_local_link').value = this.data['href'];
            }
            if ( this.data['data_href_target'] != null){ $('data_href_target').value = this.data['data_href_target']; }
            if ( this.data['btnTitle1'] != null){ $('flash_button_title1').value = this.data['btnTitle1']; }
            if ( this.data['btnTitle2'] != null){ $('flash_button_title2').value = this.data['btnTitle2']; }
            if ( this.data['btnTitle3'] != null){ $('flash_button_title3').value = this.data['btnTitle3']; }
            if ( this.data['font_size'] != null){ $('flash_button_font_size').value = this.data['font_size']; }
            if ( this.data['changeCase'] != null){ $('flash_button_changeCase').value = this.data['changeCase']; }
            if ( this.data['bg_transparent'] != null){ $('flash_button_transparent_bg').value = this.data['bg_transparent']; }
            if ( this.data['use_overlay'] != null){ $('flash_button_use_overlay').value = this.data['use_overlay']; }
            if ( this.data['overlay_alpha'] != null){ $('flash_button_overlay_alpha').value = this.data['overlay_alpha']; }
            if ( this.data['radius'] != null){ $('flash_button_radius').value = this.data['radius']; }
            if ( this.data['font_face'] != null){ $('flash_button_font_face').value = this.data['font_face']; }
            
            if( this.data['event_appear'] != null ){ $('flash_button_event_appear').value = this.data['event_appear']; }
            if( this.data['event_roll_over'] != null ){ $('flash_button_event_roll_over').value = this.data['event_roll_over']; }
            if( this.data['event_roll_out'] != null ){ $('flash_button_event_roll_out').value = this.data['event_roll_out']; }
            if( this.data['event_press'] != null ){ $('flash_button_event_press').value = this.data['event_press']; }
            if( this.data['event_release'] != null ){ $('flash_button_event_release').value = this.data['event_release']; }

            // Colors
            this.updateFontColor( this.data['font_color'] );
            this.updateStartColor( this.data['start_color'] );
            this.updateEndColor( this.data['end_color'] );
            this.updateBgColor( this.data['bg_color'] );
            this.updateBorderColor( this.data['border_color'] );            
            this.updateOverlayColor( this.data['overlay_color'] );
                                   
        }

        // Data Updates
        cont_flashbutton1.prototype.updateFontSize = function(){ this.data['font_size'] = $('flash_button_font_size').value; }
        cont_flashbutton1.prototype.updateTitles = function(){         
            $('flash_button_title1').value = $('flash_button_title1').value.replace( new RegExp("&","gi"), 'and');
            $('flash_button_title2').value = $('flash_button_title2').value.replace( new RegExp("&","gi"), 'and');
            $('flash_button_title3').value = $('flash_button_title3').value.replace( new RegExp("&","gi"), 'and');
            
            this.data['btnTitle'] = $('flash_button_title1').value+( ( $('flash_button_title2').value.length > 0 ) ? '%250D'+$('flash_button_title2').value : '' )+( ( $('flash_button_title3').value.length > 0 ) ? '%250D'+$('flash_button_title3').value : '' );
        }
        cont_flashbutton1.prototype.updateTitle1 = function(){ $('flash_button_title1').value = $('flash_button_title1').value.replace( new RegExp("&","gi"), 'and'); this.data['btnTitle1'] = $('flash_button_title1').value; }
        cont_flashbutton1.prototype.updateTitle2 = function(){ $('flash_button_title2').value = $('flash_button_title2').value.replace( new RegExp("&","gi"), 'and'); this.data['btnTitle2'] = $('flash_button_title2').value; }
        cont_flashbutton1.prototype.updateTitle3 = function(){ $('flash_button_title3').value = $('flash_button_title3').value.replace( new RegExp("&","gi"), 'and'); this.data['btnTitle3'] = $('flash_button_title3').value; }
        cont_flashbutton1.prototype.updateLink = function(){ this.data['href'] = $('data_url_link').value; }
        cont_flashbutton1.prototype.updateHrefTarget = function(){ this.data['data_href_target'] = $('data_href_target').value; }        
        cont_flashbutton1.prototype.updateCase = function(){ this.data['changeCase'] = $('flash_button_changeCase').value; }        
        cont_flashbutton1.prototype.updateLocLink = function(){ this.data['href'] = $('data_url_link').value = $('data_local_link').options[$('data_local_link').selectedIndex].value; }
        cont_flashbutton1.prototype.updateFontColor = function(color){ this.data['font_color'] = update_font_color = $('flash_button_font_color').value = $('flash_button_font_color_sample').style.backgroundColor = color; }
        cont_flashbutton1.prototype.updateStartColor = function(color){ this.data['start_color'] = update_start_color = $('flash_button_start_color').value = $('flash_button_start_color_sample').style.backgroundColor = color; }
        cont_flashbutton1.prototype.updateEndColor = function(color){ this.data['end_color'] = update_end_color = $('flash_button_end_color').value = $('flash_button_end_color_sample').style.backgroundColor = color; }
        cont_flashbutton1.prototype.updateBgColor = function(color){ this.data['bg_color'] = update_bg_color = $('flash_button_bg_color').value = $('flash_button_bg_color_sample').style.backgroundColor = color; }
        cont_flashbutton1.prototype.updateBorderColor = function(color){ this.data['border_color'] = update_border_color = $('flash_button_border_color').value = $('flash_button_border_color_sample').style.backgroundColor = color; }
        cont_flashbutton1.prototype.updateTransparent = function( trans ){ this.data['bg_transparent'] = $('flash_button_transparent_bg').value; }
        cont_flashbutton1.prototype.updateOverlay = function( arg ){ this.data['use_overlay'] = $('flash_button_use_overlay').value; }
        cont_flashbutton1.prototype.updateOverlayColor = function(color){ this.data['overlay_color'] = update_overlay_color = $('flash_button_overlay_color').value = $('flash_button_overlay_color_sample').style.backgroundColor = color; }
        cont_flashbutton1.prototype.updateOverlayAlpha = function(){ this.data['overlay_alpha'] = $('flash_button_overlay_alpha').value; }
        cont_flashbutton1.prototype.updateRadius = function(){ this.data['radius'] = $('flash_button_radius').value; }
        cont_flashbutton1.prototype.updateFontFace = function(){ this.data['font_face'] = $('flash_button_font_face').value; }
        
        cont_flashbutton1.prototype.updateEventAppear = function(){ this.data['event_appear'] = $('flash_button_event_appear').value; }
        cont_flashbutton1.prototype.updateEventRollOver = function(){ this.data['event_roll_over'] = $('flash_button_event_roll_over').value; }
        cont_flashbutton1.prototype.updateEventRollOut = function(){ this.data['event_roll_out'] = $('flash_button_event_roll_out').value; }
        cont_flashbutton1.prototype.updateEventPress = function(){ this.data['event_press'] = $('flash_button_event_press').value; }
        cont_flashbutton1.prototype.updateEventRelease = function(){ this.data['event_release'] = $('flash_button_event_release').value; }
     
//********* Flash Button Widget - End *********//





var updateBorderColor;
var updateBorderBg;
var chooseBorder;
var cancelBorder;
var data_borderColor = "808080";
var data_borderBg = "FFFFFF";
var form_class = Class.create();
form_class.prototype=
{
    updateBorderBg: function (color)
    {
        data_borderBg = color;
        $('border_samples').style.backgroundColor = "#"+color;
        this.data['border_bg'] = color;
    },
    
    updateBorderColor: function(color)
    {
        for (var i=0; i<form_class.list.length; i++)
        {
            if (form_class.list[i].color != "")
            {
                $("border_"+i).style.background = "url(/shared/images/border.php?w=200&h=200&b="+form_class.list[i].corner+"&c="+color+"&img=/shared/images/"+form_class.list[i].img+")";
            }
        }
        data_borderColor = color;
        $('border_color_sample').style.backgroundColor = "#"+color;
        this.data['border_color'] = color;
    },
    
    initialize: function(width, height, code_file, callback)
    {
        this.callback = callback;
        var div= this.bg_div = document.createElement("DIV");
        this.id = form_class.next_id++;
        div.id="pop_form_"+this.id;
        div.style.width= width+"px";
        div.style.height= height+"px";
        div.style.position="absolute";
        div.style.top="20";
        div.style.left="130";
        div.style.background="url(/shared/images/border.php?w="+width+"&h="+height+"&b=41&f=1&img=/shared/images/cal_bdr.png)";
        div.style.zIndex = "2000000";
        div.className = "png";
        $('wrapper').appendChild(div);
        var div= this.edit_div = document.createElement("DIV");
        div.style.width= width+"px";
        div.style.height= height+"px";
        div.style.position="absolute";
        div.style.top="20";
        div.style.left="130";
        div.style.zIndex = "2000001";
        $('wrapper').appendChild(div);
        div=this.close_div = document.createElement("DIV");
        div.style.width = "40px";
        div.style.height="40px";
        div.style.position="absolute";
        div.style.top="20";
        div.style.left="130";
        div.style.cursor="pointer";
        div.onclick=this.close.bind(this);
        div.style.zIndex = "2000002";
        $('wrapper').appendChild(div);

        cont_getHtml("/content/form/"+code_file, this.disp_cb.bind(this), 1000);
        this.data = Array();
    },
    
    disp_cb: function(response)
    {
        insert_html_response(this.edit_div, response);
        $('color_pick_wrap').appendChild($('plugin'));
        
        updateBorderBg = this.updateBorderBg.bind(this);
        updateBorderColor = this.updateBorderColor.bind(this);
        chooseBorder = this.chooseBorder.bind(this);
        cancelBorder = this.cancel.bind(this);
        this.updateBorderColor(data_borderColor);
        this.updateBorderBg(data_borderBg);
    },
    
    close: function()
    {
        var bdr = new border(0,0,0,0,0,null,0, data_borderColor, data_borderBg);
        this.callback(bdr);
        this.cancel();
    },
    
    chooseBorder: function(index)
    {
        if (index == null)
            index = 0;
        if (index == -1)
        {
            this.callback(null);
        }
        else
        {
            var bdr = form_class.list[index];
            bdr.color = data_borderColor;
            bdr.backgroundColor = data_borderBg;
            this.callback(bdr);
        }
        this.cancel();
    },
    
    cancel: function()
    {
        $('plugin').style.display='none';
        $('wrapper').appendChild($('plugin'));
        $('wrapper').removeChild(this.bg_div);
        $('wrapper').removeChild(this.edit_div); 
        $('wrapper').removeChild(this.close_div); 
    }
}


form_class.next_id = 0;

var cm_n = navigator.userAgent.toLowerCase();
var cm_ie = !!(cm_n.indexOf("msie") >= 0 && document.all);
var cm_ie6 = !!(cm_ie && cm_n.indexOf("msie 6") >=0);

