/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
	
    var forum_reply_win;
	Ext.ux.TinyMCE.initTinyMCE();
	
    function popup_reply(quote){
    	if(fake_user){
    		open_login_popup();
    		return;
    	}
    	if(lock){
	   		Ext.MessageBox.show({
				title:'Locked Thread',
				msg: 'This thread has been closed by the site admins.',
				buttons: Ext.MessageBox.OK,
				width: 364,
				icon: Ext.MessageBox.WARNING,
				cls:'feedbackm'
			});
			return;
    	}
        // create the window on the first click and reuse on subsequent clicks
        if (quote) {
        	var quote_text = document.getElementById("quote_"+quote).innerHTML;
        }
        else {
        	var quote_text = '';
        }
        if (forum_reply_win)
        	forum_reply_win.destroy();
        forum_reply_win = new Ext.Window({
			title: 'Reply to this Thread',
			cls: 'reply-win',
			id: '',
			border: false,
			bodyBorder: false,
			bodyStyle: 'padding-left: 13px; padding-right:13px;',
			shadow: false,
			resizable: false,
            width       : 567,
			autoHeight      : true,
            closeAction :'hide',
			layout: 'fit',
			items: [{
				xtype: 'form',
				id: 'form_sys_id',
				cls: 'reply-win-form',
				title: "You're replying to the '"+thread_title+"' thread",
		        fileUpload: true,
				url: location.href,
				border: false,
				bodyBorder: false,
				autoHeight      : true,
				defaults: {hideMode: 'display'},
				items: [{
					html: quote_text,
					id: 'reply_with_quote',
					border: false
				},{
					/*html: '<span style="font-weight:bold;">Shift-Enter:</span> skip 1 line, <span style="font-weight:bold;">Enter:</span> skip 2 lines<br /><br />',
					border: false
				},{*/
					xtype: "tinymce",
					id: "tinymce_window",
					hideLabel: true,
					name: "form[cf_text]",
					width: 523,
					height: 208,
					tinymceSettings: {
						theme : "advanced",
						plugins: "safari,style,emotions,visualchars,paste",
						//plugins: "safari,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
						//theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
						//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
						//theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|",
						//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
						theme_advanced_buttons1 : "bold,italic,underline,|,forecolor,backcolor,|,emotions,|,link,unlink",
						theme_advanced_buttons2 : "",//"pastetext,pasteword,selectall",
						theme_advanced_buttons3 : "",
						theme_advanced_buttons4 : "",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						//theme_advanced_statusbar_location : "bottom",
						theme_advanced_resizing : false,
						extended_valid_elements : "a[name|href|target=_new|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
						template_external_list_url : "example_template_list.js",
						paste_auto_cleanup_on_paste : true,
			            paste_remove_spans: true,
			            paste_remove_styles: true,
			            paste_remove_styles_if_webkit: true,
			            paste_strip_class_attributes: true/*,
					    setup: function(ed) {
					        // Force Paste-as-Plain-Text
					        ed.onPaste.add( function(ed, e, o) {
					            ed.execCommand('mcePasteText', true);
					            return tinymce.dom.Event.cancel(e);
					        });
					    }*/
					},
					value: ""
				},{
					xtype: 'toolbar',
					cls: 'reply-win-tb',
					items: [{
						text: 'Add Photos',
						cls:'x-btn-text-icon',
						iconCls: 'add-photos',
						handler: function(){
							var cmp = Ext.getCmp('reply-photos');
							cmp.isVisible() ? cmp.hide() : cmp.show();
						}
					}, {
						text: 'Add YouTube Video',
						iconCls: 'add-youtube',
						handler: function(){
							var cmp = Ext.getCmp('reply-youtube');
							cmp.isVisible() ? cmp.hide() : cmp.show();
						}
					}]
				}, {
					id: 'reply-photos',
					cls: 'add_title_extjs',
					title: 'Add Photos:',
					hidden: true,
					layout: 'column',
					border: false,
					defaults: {border: false, bodyBorder: false},
					items: [{
							columnWidth:.4,
							defaults: {
								xtype: 'fileuploadfield', 
								buttonOnly: true, 
								style: 'margin-bottom: 10px',
								width: (browser_type=="IE7" ? 261 : 250)
								},
							items: [{name: 'form[cf_photo1]'}, {name: 'form[cf_photo2]'}]
						},{
							columnWidth:.2,
							html:'&nbsp;'
						},{
							columnWidth:.4,
							defaults: {
								xtype: 'fileuploadfield', 
								buttonOnly: true, 
								width: (browser_type=="IE7" ? 261 : 250)
								},
							items: [{name: 'form[cf_photo3]'}, {name: 'form[cf_photo4]'}]
					}]
				}, {
					id: 'reply-youtube',
					cls: 'add_title_extjs',
					layout: 'form',
					title: 'Add YouTube videos:',
					hidden: true,
					border: false,
					defaults: {
						xtype: 'textfield',
						emptyText: 'Paste YouTube link here',
						width: 520,
						hideLabel: true
					},
					items: [{
						id: 'cf_file1'
					}, {
						id: 'cf_file2'
					}]
				},{
					id: 'cf_mail',
					xtype: 'checkbox',
					hideLabel: true,
					checked:true,
					boxLabel: 'Notify me when someone replies to my thread'
				}],
				buttonAlign: 'left',
				buttons: [{
					minWidth: 36,
					icon: g_params["static_media_domain"]+'/public/global/post-btn.jpg',
					cls: "post-btn x-btn-text-icon",
					handler: function(){
						if (Ext.getCmp("cf_mail").getValue())
							Ext.getCmp("cf_mail").setValue(1);
						if (Ext.getCmp("cf_file1").getValue()=="Paste YouTube Link Here")
							Ext.getCmp("cf_file1").setValue("");
						if (Ext.getCmp("cf_file2").getValue()=="Paste YouTube Link Here")
							Ext.getCmp("cf_file2").setValue("");
						Ext.getCmp("tinymce_window").syncValue();
				        if (this.ownerCt.getForm().isValid()) {
				        	$('.x-panel-btns').html('<div class="loading-indicator">Posting...</div>');
						    this.ownerCt.getForm().submit({
					            params:{
					            	'form_sys':'',
					            	'form[cf_id]':'',
					            	'form[cf_fol_id]':fol_id,
					            	'form[cf_mem_id]':mem_id,
					            	'form[cf_master]':master_id,
					            	'form[cf_pre_master]':master_id,
					            	'form[cf_title]':'Re: '+thread_title,
					            	'form[cf_date]':timestamp,
					            	'form[cf_replies]':0,
					            	'form[cf_views]':0,
					            	'form[cf_quote]': quote,
					            	'form[cf_file1]': Ext.getCmp("cf_file1").getValue(),
					            	'form[cf_file2]': Ext.getCmp("cf_file2").getValue(),
					            	'form[cf_mail]': Ext.getCmp("cf_mail").getValue(),
					            	'form_sys_was_submit':1,
					            	'form_sys_field_list':'cf_id cf_fol_id cf_mem_id cf_master cf_pre_master cf_title cf_date cf_text cf_stuck cf_inner_mail cf_mail cf_photo1 cf_photo2 cf_photo3 cf_photo4 cf_link1 cf_link_name1 cf_link2 cf_link_name2 cf_link3 cf_link_name3 cf_link4 cf_link_name4 cf_file1 cf_file2 cf_replies cf_views cf_quote cf_thanks',
					            	'mod':'forums',
					            	'act':'display_forum',
					            	'langId':1,
					            	'sub':'add',
					            	'pagesCount':'',
					            	'page_num':''
					            },
								failure: function(form, action) {
									alert(action.clientCode);
								}
					        });
						}
					}
                },{
					minWidth: 50,
                    icon: g_params["static_media_domain"]+'/public/global/popup/btn-cancel.jpg',
					cls: "cancel-btn x-btn-text-icon",
                    handler  : function(){
                        forum_reply_win.hide();
                    }
                }]
			}]
        });
    	forum_reply_win.show();
    }

Ext.onReady(function(){
//	Ext.SSL_SECURE_URL = 'javascript:false;';
   	if(lock){
   		document.getElementById("thread_reply_box_middle_inner").innerHTML = "<span style=\"font-size:18px;color:#DA4B07;\">This thread has been closed by the site admins.</span>";
   	}
   	else if (!fake_user) {
		new Ext.FormPanel({
			title: '',
			cls: 'reply-win-form',
			id: 'form_sys_id1',
			border: false,
			bodyBorder: false,
			//bodyStyle: 'padding-left: 13px; padding-right:13px;',
			shadow: false,
			resizable: false,
		    width: 527,
			autoHeight: true,
		    //closeAction :'hide',
			layout: 'fit',
			fileUpload: true,
			url: location.href,
			defaults: {hideMode: 'display'},
			items: [/*{
				name: 'form[cf_text]',
				xtype: 'htmleditor',
				hideLabel: true,
				enableFont: false,
				enableFontSize: false,
				enableLists: false,
				enableSourceEdit: false,
				enableAlignments: false,
				height: 100,
		        width:523,
		        listeners: {
		        	activate: function(e) {
		        		e.execCmd('delete');
		        	}
		        }
			},*/{
				xtype: "tinymce",
				id: "tinymce_panel",
				hideLabel: true,
				name: "form[cf_text]",
				width: 523,
				height: 208,
				tinymceSettings: {
					theme : "advanced",
					plugins: "safari,style,emotions,visualchars,paste",
					//plugins: "safari,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
					//theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
					//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
					//theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|",
					//theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
					theme_advanced_buttons1 : "bold,italic,underline,|,forecolor,backcolor,|,emotions,|,link,unlink",
					theme_advanced_buttons2 : "",//"pastetext,pasteword,selectall",
					theme_advanced_buttons3 : "",
					theme_advanced_buttons4 : "",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					//theme_advanced_statusbar_location : "bottom",
					theme_advanced_resizing : false,
					extended_valid_elements : "a[name|href|target=_new|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
					template_external_list_url : "example_template_list.js",
					paste_auto_cleanup_on_paste : true,
		            paste_remove_spans: true,
		            paste_remove_styles: true,
		            paste_remove_styles_if_webkit: true,
		            paste_strip_class_attributes: true/*,
				    setup: function(ed) {
				        // Force Paste-as-Plain-Text
				        ed.onPaste.add( function(ed, e, o) {
				            ed.execCommand('mcePasteText', true);
				            return tinymce.dom.Event.cancel(e);
				        });
				    }*/
				},
				value: ""
			},{
				xtype: 'toolbar',
				cls: 'reply-win-tb',
				items: [{
					text: 'Add Photos',
					cls:'x-btn-text-icon',
					iconCls: 'add-photos',
					handler: function(){
						var cmp = Ext.getCmp('reply-photos1');
						cmp.isVisible() ? cmp.hide() : cmp.show();
					}
				}, {
					text: 'Add YouTube Video',
					iconCls: 'add-youtube',
					handler: function(){
						var cmp = Ext.getCmp('reply-youtube1');
						cmp.isVisible() ? cmp.hide() : cmp.show();
					}
				}]
			},{
				id: 'reply-photos1',
				cls: 'add_title_extjs',
				title: 'Add Photos:',
				hidden: true,
				layout: 'column',
				border: false,
				defaults: {border: false, bodyBorder: false},
				items: [{
						columnWidth:.4,
						defaults: {
							xtype: 'fileuploadfield', 
							buttonOnly: true, 
							style: 'margin-bottom: 10px',
							width: (browser_type=="IE7" ? 261 : 250)
							},
						items: [{name: 'form[cf_photo1]'}, {name: 'form[cf_photo2]'}]
					},{
						columnWidth:.2,
						html:'&nbsp;'
					},{
						columnWidth:.4,
						defaults: {
							xtype: 'fileuploadfield', 
							buttonOnly: true, 
							width: (browser_type=="IE7" ? 261 : 250)
							},
						items: [{name: 'form[cf_photo3]'}, {name: 'form[cf_photo4]'}]
				}]
			},{
				id: 'reply-youtube1',
				cls: 'add_title_extjs',
				layout: 'form',
				title: 'Add YouTube videos:',
				hidden: true,
				border: false,
				defaults: {
					xtype: 'textfield',
					emptyText: 'Paste YouTube link here',
					width: 520,
					hideLabel: true
				},
				items: [{
					id: 'cf_file11'
				}, {
					id: 'cf_file21'
				}]
			},{
				id: 'cf_mail1',
				xtype: 'checkbox',
				hideLabel: true,
				checked:true,
				boxLabel: 'Notify me when someone replies to my thread'
			}],
			buttonAlign: 'left',
			buttons: [{
				minWidth: 36,
				icon: g_params["static_media_domain"]+'/public/global/post-btn.jpg',
				cls: "post-btn x-btn-text-icon",
				handler: function(){
					if (Ext.getCmp("cf_mail1").getValue())
						Ext.getCmp("cf_mail1").setValue(1);
					if (Ext.getCmp("cf_file11").getValue()=="Paste YouTube Link Here")
						Ext.getCmp("cf_file11").setValue("");
					if (Ext.getCmp("cf_file21").getValue()=="Paste YouTube Link Here")
						Ext.getCmp("cf_file21").setValue("");
					Ext.getCmp("tinymce_panel").syncValue();
			        if (this.ownerCt.getForm().isValid()) {
			        	$('.x-panel-btns').html('<div class="loading-indicator">Posting...</div>');
					    this.ownerCt.getForm().submit({
				            params:{
				            	'form_sys':'',
				            	'form[cf_id]':'',
				            	'form[cf_fol_id]':fol_id,
				            	'form[cf_mem_id]':mem_id,
				            	'form[cf_master]':master_id,
				            	'form[cf_pre_master]':master_id,
				            	'form[cf_title]':'Re: '+thread_title,
				            	'form[cf_date]':timestamp,
				            	'form[cf_replies]':0,
				            	'form[cf_views]':0,
				            	'form[cf_quote]': '',
				            	'form[cf_file1]': Ext.getCmp("cf_file11").getValue(),
				            	'form[cf_file2]': Ext.getCmp("cf_file21").getValue(),
				            	'form[cf_mail]': Ext.getCmp("cf_mail1").getValue(),
				            	'form_sys_was_submit':1,
				            	'form_sys_field_list':'cf_id cf_fol_id cf_mem_id cf_master cf_pre_master cf_title cf_date cf_text cf_stuck cf_inner_mail cf_mail cf_photo1 cf_photo2 cf_photo3 cf_photo4 cf_link1 cf_link_name1 cf_link2 cf_link_name2 cf_link3 cf_link_name3 cf_link4 cf_link_name4 cf_file1 cf_file2 cf_replies cf_views cf_quote cf_thanks',
				            	'mod':'forums',
				            	'act':'display_forum',
				            	'langId':1,
				            	'sub':'add',
				            	'pagesCount':'',
				            	'page_num':''
				            },
							failure: function(form, action) {
								alert(action.clientCode);
							}
				        });
					}
				}
		    }],
		    renderTo:'thread_reply_box_middle_inner'
		});
   	}
});