function OpenComponentTypeAndDesignDefsWindow( PageTypeId , PanelId )
{
	window.showModalDialog('LMSiteMng/LMCompDesignDefsDialog.aspx?PageTypeId='+ PageTypeId +'&PanelId='+ PanelId +'&CommandAction=1', self , 'dialogHeight:600px; dialogWidth:400px; dialogLeft:200px; status:no; scroll:no');
	/*window.open('LMCompDesignDefsDialog.aspx?PageTypeId='+ PageTypeId +'&PanelId='+ PanelId +'&CommandAction=1');*/
}

function OpenComponentContentDefsWindow( ComponentId, ComponentTypeId, ActualPageId, FieldToUpdate )
{
	/*window.showModalDialog('LMCompContentDefsDialog.aspx?ActualPageId='+ ActualPageId +'&PageTypeId='+ PageTypeId +'&PanelId='+ PanelId +'&CommandAction=1', self , 'dialogHeight:600px; dialogWidth:500px; dialogLeft:200px; status:no; scroll:no');*/
	
	if(ComponentTypeId == 12/*List*/)
	{
		window.showModalDialog('LMSiteMng/LMListDefsDialog.aspx?ComponentId='+ ComponentId +'&ComponentTypeId='+ ComponentTypeId +'&CommandAction=1&ActualPageId='+ActualPageId, self , 'dialogHeight:450px; dialogWidth:400px; dialogLeft:200px; status:no; scroll:no');
		/*window.open('LMListDefsDialog.aspx?ComponentId='+ ComponentId +'&ComponentTypeId='+ ComponentTypeId +'&CommandAction=1&ActualPageId='+ActualPageId);*/
	}
	else if(ComponentTypeId == 20)
	{
		window.open('LMSiteMng/LMCompContentDefsDialog.aspx?ComponentId='+ ComponentId +'&ComponentTypeId='+ ComponentTypeId + '&FieldToUpdate='+ FieldToUpdate +'&CommandAction=1',null,"height=550,width=600,status=no,toolbar=no,menubar=no,location=no");
	}
	else
	{
	
	newDlg = window.showModalDialog('LMSiteMng/LMListDefsManagementDialog.aspx?ComponentId='+ ComponentId +'&ActualPageId='+ ActualPageId +'&CommandAction=1',window,"dialogHeight:400px; dialogLeft:200px; status:no; scroll:no");
	if(newDlg == 1) document.location = document.location;
	
		/*component type, not page type like in list ,anagement*/
	/*	var newDlg = window.showModalDialog('LMSiteMng/LMListDefsManagementDialog.aspx?ComponentId='+ ComponentId +'&CommandAction=1&ActualPageId='+ActualPageId, window , 'dialogHeight:450px; dialogLeft:200px; status:no; scroll:no'");
		if(newDlg == 1) document.location = document.location;*/
	}
		
	
}

function OpenComponentsContentUpdate( ComponentId , ActualPageId )
{
		/*Update - CommandAction = 1*/
			/*Add new - CommandAction = 2*/
			/*Delete - CommandAction = 3*/
	window.showModalDialog('LMSiteMng/LMListDefsManagementDialog.aspx?ComponentId="+ ComponentId +"&CommandAction=1&ActualPageId="+ActualPageId+"', window , 'dialogHeight:400px; dialogLeft:200px; status:no; scroll:no');
}
				

/*Editor functions*/
function ChangeImages(ImageObg, SrcName)
{
	ImageObg.src = SrcName
}
 
function GetColorFromUser(oldcolor)
{
	var posX    = event.screenX;
	var posY    = event.screenY + 20;
	var screenW = screen.width;                                 // screen size
	var screenH = screen.height - 20;                           // take taskbar into account
	if (posX + 232 > screenW) { posX = posX - 232 - 40; }       // if mouse too far right
	if (posY + 164 > screenH) { posY = posY - 164 - 80; }       // if mouse too far down
	var wPosition   = 'dialogLeft:' +posX+ '; dialogTop:' +posY;
	var newcolor = showModalDialog('LMEditorColorPicker.html', oldcolor, 'dialogWidth:238px; dialogHeight: 187px; '
	+ 'resizable: no; help: no; status: no; scroll: no; '+ wPosition);
			return newcolor;
}

function EditorSetText(EditorID, EditorText)
{
	EditorID.document.body.innerHTML = EditorText;
}

function ExecuteCommand(EditorID, Sender, CommandStr)
{
	switch(CommandStr)
	{
		case 'Save':
			var str = EditorID.document.body.innerHTML;
			var re;                    

			re = /\n/g;             
			str = str.replace(re, ""); 
			   
			re = /\\n/g;             
			str = str.replace(re, "");  
			  
			re = /\r/g;             
			str = str.replace(re, "");  
			  
			re = /\\r/g;             
			str = str.replace(re, ""); 
			
			re = /\"/g;             
			str = str.replace(re, ""); 
			
			re = /"/g;             
			str = str.replace(re, ""); 
			
			re = /\'/g;             
			str = str.replace(re, ""); 
			
			re = /'/g;             
			str = str.replace(re, ""); 
			
			re = /<BR>/g;             
			str = str.replace(re, "</BR>"); 
			/*re = /<BR>/g;             
			str = str.replace(re, "<BR></BR>"); 
			
			re = /<BR><\/BR><BR><\/BR>/g;             
			str = str.replace(re, "<BR></BR>"); */
			
			re = /&nbsp;/g;    
			str = str.replace(re, " ");  
			
			/*alert(str);*/
			
			Sender.value = encodeURIComponent(str);
			
			document.Form1.submit();
						
			break;
			
		case 'Link' :
			EditorID.focus ();
			alert("Link");
			EditorID.document.execCommand ('createlink', true, null);
			EditorID.focus ();
			break;	
				
		case 'OrderList':
			EditorID.focus ();
			EditorID.document.execCommand ('insertorderedlist', false, null);
			EditorID.focus ();
			break;
			
		case 'UnOrderList':
			EditorID.focus ();
			EditorID.document.execCommand ('insertunorderedlist', false, null);
			EditorID.focus ();
			break;
			
		case 'AlignLeft':
			EditorID.focus ();
			EditorID.document.execCommand ('justifyleft', false, null);
			EditorID.focus ();
			break;
		
		case 'AlignCenter':
			EditorID.focus ();
			EditorID.document.execCommand ('justifycenter', false, null);
			EditorID.focus ();
			break;
			
		case 'AlignRight':
			EditorID.focus ();
			EditorID.document.execCommand ('justifyright', false, null);
			EditorID.focus ();
			break;
			
		case 'ChangeFont' :
			EditorID.focus ();
			EditorID.document.execCommand ('fontname', false, Sender.options[Sender.selectedIndex].value);
			EditorID.focus ();
			break;
			
		case 'ChangeFontSize' :
			EditorID.focus ();
			EditorID.document.execCommand ('fontsize', false, Sender.options[Sender.selectedIndex].value);
			EditorID.focus ();
			break;
			
		case 'Bold':
			EditorID.focus ();
			EditorID.document.execCommand ('bold', false, null);
			EditorID.focus ();
			break;
			
		case 'Italic':
			EditorID.focus ();
			EditorID.document.execCommand ('italic', false, null);
			EditorID.focus ();
			break;
			
		case 'Underline':
			EditorID.focus ();
			EditorID.document.execCommand ('underline', false, null);
			EditorID.focus ();
			break;
			
		case 'Striket':
			EditorID.focus ();
			EditorID.document.execCommand ('strikethrough', false, null);
			EditorID.focus ();
			break;
			
		case 'FontColor':
		
			var oldcolor = EditorID.document.queryCommandValue('forecolor');    		
						
			EditorID.focus ();
			EditorID.document.execCommand ('forecolor', true, GetColorFromUser(oldcolor));
			EditorID.focus ();
	
		break;
		
		case 'AlignJustify' :
			EditorID.focus ();
			EditorID.document.execCommand ('justifyfull', false, null);
			EditorID.focus ();
			break;	
		
		case 'InsertImage':
			EditorID.focus ();
			var UploadWin = window.showModalDialog('LMUploadFiles.aspx', self , 'dialogHeight:200px; dialogWidth:300px; dialogLeft:200px; status:no; scroll:no');
			
			if(UploadWin)
			{
				EditorID.document.execCommand ('insertimage', false, UploadWin);
			}
			
			/*window.open('LMUploadFiles.aspx');*/
				
			EditorID.focus ();
			
			break;
			
		case 'InsertLink':
			EditorID.focus ();
			var InsertLinkWin = window.showModalDialog('LMInsertLink.aspx', self , 'dialogHeight:280px; dialogWidth:280px; dialogLeft:200px; status:no; scroll:no');
			
			var sel=EditorID.document.selection.createRange();
			sel.pasteHTML(InsertLinkWin);
			sel.select();
				
			EditorID.focus ();
			
			break;
	}
}
