// JavaScript Document

function moveEditor(x,y,divId){
				
				var obj = document.getElementById(divId);
				obj.style.left = x + leftOffset + "px";
				obj.style.top = y + topOffset + "px";
				
				
			}

			function moveEditorAbs(x,y,divId){

				var obj = document.getElementById(divId);
				obj.style.left = x +"px";
				obj.style.top = y + "px";
				
				
			}
    
    		function sizeEditor(w,h,divId){
				/*var obj = document.getElementById(divId);
				obj.style.width = w + "px";
				obj.style.height = h + "px";
				*/
				resizeEditors(w,h);
			}
			
			function setContent(value){

				editor.setData(value);
			}
			
			function getContent(){
				return editor.getData();
			}
				
			function createEditor(width,height,left,top,divId){
								
				removeEditor();
				leftOffset = left;
				topOffset = top;
				var obj = document.getElementById(divId);
				obj.style.width = width;
				obj.style.height = height;
				obj.style.display = "block";
				/*obj.style.borderStyle="solid";
				obj.style.borderWidth="10px";
				obj.style.borderColor="#0000CC";*/
				editor = CKEDITOR.appendTo(divId,{
										    height: height + "px",
										    width: width + "px",
										    resize_enabled: false,
											toolbar: 	[
															['Cut','Copy', 'Paste', 'PasteText','RemoveFormat','-', 'Undo','Redo'],
															['Bold', 'Italic',,'Underline', '-', 'NumberedList', 'BulletedList', '-'],
															['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
															['Indent','Outdent','-','Link','Unlink','Anchor','-','Image', 'Table','HorizontalRule','SpecialChar'],
															['Format','FontSize','TextColor']
														],
										     
										   filebrowserBrowseUrl: '/ckfinder/ckfinder.html',
										   filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html?type=Images',
										   filebrowserImageUploadUrl: '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images&currentFoldder=/uploads/images/',
										   format_tags: 'h1;h2;h3;h4;div',
										   scayt_autoStartup: true
										   }
										   );
				
			}
			
			function removeEditor(){
				if(editor){
					editor.destroy(); 
					editor = null;
					
					
				}
			}
			
			function hideEditor(divId)
			{				
				//document.getElementById("editor").style.display="none";
				//document.getElementById("editor").visibility="hidden";
				document.getElementById(divId).style.display="none";
				document.getElementById(divId).visibility="hidden";
			}
			
			function showEditor(divId)
			{
				//document.getElementById("editor").style.display="block";
				//document.getElementById("editor").visibility="visible";
				document.getElementById(divId).style.display="block";
				document.getElementById(divId).visibility="visible";
			}
			
			function cleanUp(){
				removeEditor();
				document.getElementById("editor").innerHTML="";
				document.getElementById("editor").style.display="none";
			}
							
			function cleanUpAndReload(){
				removeEditor();
				document.getElementById("editor").innerHTML="";
				document.getElementById("editor").style.display="none";
				location.reload();
			}
							
			function resizeEditors(width, height)
			{	

				/*if(editor){
					alert("moo!");
				}*/
				for ( var i in CKEDITOR.instances ){
						
						CKEDITOR.instances[i].resize(width,height);            
						
					}
		
			}

			function getDimensions(x,y,w,h){
				alert("X: " + x + ", Y: " + y + ", W: " + w + ", H:" + h);
			}
			
			function viewSource(){
				
				for(var i in CKEDITOR.instances){
					name = CKEDITOR.instances[i].execCommand('source');
					
				}
				
			}
			CKEDITOR.on( 'dialogDefinition', function( ev )
			{
				// Take the dialog name and its definition from the event data.
				var dialogName = ev.data.name;
				var dialogDefinition = ev.data.definition;
		 
				// Check if the definition is from the dialog we're
				// interested on (the Link dialog).
				/*if ( dialogName == 'link' )
				{
					// FCKConfig.LinkDlgHideAdvanced = true
					dialogDefinition.removeContents( 'advanced' );
		 
					// FCKConfig.LinkDlgHideTarget = true
					//dialogDefinition.removeContents( 'target' );*/
				/*
				Enable this part only if you don't remove the 'target' tab in the previous block.
				 
							// FCKConfig.DefaultLinkTarget = '_blank'
							// Get a reference to the "Target" tab.
							var targetTab = dialogDefinition.getContents( 'target' );
							// Set the default value for the URL field.
							var targetField = targetTab.get( 'linkTargetType' );
							targetField[ 'default' ] = '_blank';
				*/
				//}
		 
				if ( dialogName == 'image' )
				{
					
					/*
						Hack to enable focus on the Upload tab
					*/
					dialogDefinition.removeContents( 'advanced' );
					var uploadTab = dialogDefinition.getContents( 'Upload' );
					
					// Add a text field to the "upload" tab.
					uploadTab.add( {
							type : 'text',
							hidden : true,
							label : 'focusEnabler',
							id : 'txtAid',
							'default' : 'moo'
						});

					
					
					
					
					//dialogDefinition.removeContents( 'Link' );
					dialogDefinition.onFocus = function()
					{
						var fileField = this.getContentElement( 'Upload', 'txtAid' );
						fileField.select();

					};
					
					dialogDefinition.onError = function(){
						var fileField = this.getContentElement( 'Upload', 'txtAid' );
						fileField.select();
					};
				}
		 
				if ( dialogName == 'flash' )
				{
					
					dialogDefinition.removeContents( 'advanced' );
				}
				
				if ( dialogName == 'table' )
				{
					
					dialogDefinition.removeContents( 'advanced' );
				}
				
				if ( dialogName == 'link' )
				{
					
					dialogDefinition.removeContents( 'advanced' );
				}

				
			});

			var editor;
			var leftOffset = 0;
			var topOffset = 0;
	function refreshDiv(textFromFlex,regionClientId) {
    
		document.getElementById(regionClientId).innerHTML = textFromFlex;
		/*var url = location.href;

		setInterval(function() {
		$("#content").load(location.href+" #content>*","");
		}, 100);*/

}

function openWindow() {
    window.location = '../';
}
