var __debug__           = false;

function MxGetObjectById( objectId ){
MxDebugAlert("MxGetObjectById");
	var isInternetExplorer	= navigator.appName.indexOf("Microsoft") != -1;
	var mxObj				= isInternetExplorer ? eval( "document.all." + objectId ) : eval( "document." + objectId );
	
	return mxObj;
}


// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --]

function MxResizeWidth( newWidth, objectId ){
MxDebugAlert("MxResizeWidth");
	var resizeObj	= MxGetObjectById( objectId );	
	resizeObj.width = newWidth;
}

function MxResizeHeight( newHeight, objectId ){
MxDebugAlert("MxResizeHeight");
	var resizeObj	= MxGetObjectById( objectId );	
	resizeObj.height = newHeight;
}

function MxConfirm( message ){
MxDebugAlert("MxConfirm");
	return confirm( message );
}

function MxAlert( message ){
MxDebugAlert("MxAlert");
	alert( message );
}

function MxDebugAlert( message ){
	if(__debug__)alert( message );
}

function MxCloseDialog(){	
MxDebugAlert("MxCloseDialog");				
	window.returnValue	= new Object();
	window.close();
	return false;
}

function MxCloseWindow(){	
MxDebugAlert("MxCloseWindow");
	window.close();
}

function MxPopUp( webUri, windowName, width, height, resizeble, scrollable ){	
MxDebugAlert("MxPopUp");
    if( scrollable==null ) scrollable = 1;
    
	var xloc=(window.screen.availWidth-width)/2; 
	var yloc=(window.screen.availHeight-height)/2; 
	
	window.open( webUri , windowName, "height="+height+", width="+width+", top="+yloc+", left="+xloc+", scrollbars=" + ( scrollable ? 1 : 0 ) + ", menubar=0, location=0, resizable=" + (resizeble ? 1 : 0 ) + ", status=0");

}

function MxDoScroll( delta ){
MxDebugAlert("MxDoScroll");	
	//window.status	= "Delta: " + delta;		 
	window.scrollBy( 0, delta<0 ? 50 : -50 );
}

function MxResetPageScroll(  ){	
MxDebugAlert("MxResetPageScroll");
	window.scroll( 0, 0 );
}


function MxStatus( message ){
MxDebugAlert("MxStatus");
	window.status	= message;
}

function MxSetBGColor( color, objectId ){
MxDebugAlert("MxSetBGColor");
    var mxObj	= MxGetObjectById( objectId );	    
	document.body.style.backgroundColor = color;
	mxObj.style.backgroundColor = document.body.style.backgroundColor;
	mxObj.bgColor               = mxObj.style.backgroundColor;	
}



function MxReload( ){
MxDebugAlert("MxReload");
	document.location.reload(true);
}

function MxDownload( downloadArgs ){
MxDebugAlert("MxDownload");
	document.all["ifr_download"].src = "Download.aspx" + downloadArgs;
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --]


function MxEditor( currentHtml, maxLength, editorUrl, width, height )
{	
    if( currentHtml==null ) currentHtml = "";
    
    if( width==null || width<=800) width = 800;
    if( height==null || height<=600) height = 600;
    
    
	var windowLoc	= editorUrl + "?width=" + width + "&height=" + height + "&maxLength=" + maxLength + "&content=" + currentHtml;
	
	var returnVar	= showModalDialog( windowLoc, this,'dialogWidth:' + width + 'px; dialogHeight:' + (height+250/*/extra height for emoticons*/) + 'px; help:0; status:0; center:1; resizable=0; scroll=0; unadorned=1' );

	if (returnVar != null) 
	{	   
		if( returnVar.Valid ) return returnVar.returnValue;
	}
	
	return currentHtml;	//return given value
}

function MxEditorAccept( ftb_editorId ){ //return dialog result    
    var result			= new Object;
    result.Valid		= true;						
    result.returnValue	= FTB_API[ftb_editorId].GetHtml();
    window.returnValue  = result;
    
    window.close();
    return false;            
}

function MxEditorAddImg( ftb_editorId, imgUri ){ 
    FTB_API[ftb_editorId].InsertHtml( "<img src=\"" + imgUri + "\" />" );
    return false;            
}

function MxEditorAddHtml( ftb_editorId, htmlPart ){ 
    FTB_API[ftb_editorId].InsertHtml( htmlPart );
    return false;            
}