var editors = new Array();
var config = new Array();
			 

function InitInternalEditor(lang,width,height)
{
	config[lang] = 
			{
		    height: '400px',
		    width: '600px',
		    animate: true,
		    dompath: true,
		    focusAtStart: true,
		    handleSubmit :true,
		    collapse: true,
			titlebar: 'Text Editing Tools', 
			draggable: false 
		};

	editors[lang] = new  YAHOO.widget.Editor('editor_'+lang,config[lang]);
	editors[lang].render(); 




	editors[lang].on
	('toolbarLoaded', function() 
		    { 
		
		    var UploadConfig = {
		            type: 'push',
		            label: 'Upload Image',
		            value: 'upload'
		    }
		    
		     editors[lang].toolbar.addButtonToGroup(UploadConfig, 'insertitem');
		
		     editors[lang].toolbar.on('uploadClick', function(ev) 
				{
				   OpenSendWindow();
					
			    },  editors[lang], true);
			}
	);


}



  	YAHOO.namespace("news");
		
		  
	function initNewsWindow()
	{
	
			var handleSubmit = function() { 
			//	document.getElementById("cart").style.display = 'none';
				
				this.submit(); 
			}; 
			var handleCancel = function() { 
				//document.getElementById("cart").style.display = 'none';
				this.cancel(); 
			}; 
			
			var handleUpload = function(o) {
				insertImageInText(o.responseText);
			};
			var handleSuccess = function(o) {
				alert('s')
			};
			var handleFailure = function(o) {
				alert('f')
			};

			
			
			YAHOO.news.panel = new YAHOO.widget.Dialog("uploadForm",  
						{ 
							width : "300px",
							postmethod : "async",
							fixedcenter : true, 
							visible : false,  
							constraintoviewport : true, 
							draggable:true, 
				            modal:true,
				            visible:false,
							buttons : [ 
										{ text:"Send", handler:handleSubmit, isDefault:true }, 
										{ text:"Cancel", handler:handleCancel } ] 
						} ); 
			YAHOO.news.panel.render(document.body);
	
			YAHOO.news.panel.callback = { success: handleSuccess,
						     	  failure: handleFailure,
								  upload: handleUpload };
								  

	}
	
		
	function OpenSendWindow()
	{
		 YAHOO.news.panel.show();
	}


	function insertImageInText(image)
	{
	  for (i in editors)
	  { 
	
	 //  	editors[i].execCommand('inserthtml', image ); 
	  	editors[i].execCommand('inserthtml', '<img src="' + image + '" border="0">'); 
	  }
	}

 	YAHOO.util.Event.addListener(window, "load", initNewsWindow);