// Functions for the error / msg / debugmsg boxes
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// Function for displaying the image popup
var imageWindow;
function image_popup(url, width, height, title) {

	if (imageWindow && !imageWindow.closed) { 
		imageWindow.resizeTo(width, height);
		imageWindow.focus(); 
		imageWindow.document.clear();		
	} else { 
		imageWindow=window.open('','','width='+width+',height='+height+',resizable=0') 
	}
	imageWindow.document.writeln('<html>');
	imageWindow.document.writeln('  <head>');
	imageWindow.document.writeln('    <title>'+title+'<\/title>');
	imageWindow.document.writeln('  <\/head>');
	imageWindow.document.writeln('  <body style="margin: 0px;" onblur="self.close();">');
	imageWindow.document.writeln('    <img src="'+url+'" width="'+width+'" height="'+height+'" alt="'+title+'" />');
	imageWindow.document.writeln('  <\/body>');
	imageWindow.document.writeln('<\/html>');
	imageWindow.document.close();
	imageWindow.focus();
}

// Function for displaying the module help popup
var helpWindow;
var helpWindow_width 	= '450px';
var helpWindow_height 	= '550px';
function help_popup(moduleID, moduleInstanceID) {

	if (helpWindow && !helpWindow.closed) { 
		helpWindow.focus(); 
		helpWindow.close();
	}
	

	helpWindow=window.open('/admin/module_help/popup/'+moduleID+'/'+moduleInstanceID+'/','','width='+helpWindow_width+',height='+helpWindow_height+',scrollbars=yes,resizable=0') 
	helpWindow.focus();
}

var popupWindow;
function item_popup(url, popupWindow_width, popupWindow_height) {

	popupWindow_width 	= popupWindow_width  || '400px';
	popupWindow_height 	= popupWindow_height || '200px';
	
	if (popupWindow && !popupWindow.closed) { 
		popupWindow.focus(); 
		popupWindow.close();
	}

	popupWindow=window.open(url,'','width='+popupWindow_width+',height='+popupWindow_height+',scrollbars=yes,resizable=0') 
	popupWindow.focus();
}

// Function for inserting html from iframe
function insert_textarea_html(html) {
	
	edCanvas = parent.document.getElementById('text');
	edInsertContent(edCanvas, html);	
}

function insert_fck_html(html) {
	
	FCK = parent.window.FCKeditorAPI.GetInstance('text'); 
	FCK.InsertHtml(html);
}