﻿
/*
---------------------------------------------------------------------------------------------------
When an FCKeditor is placed in a FormView that is nested in an AJAX UpdatePanel, the FCKeditor
will display, and its contents will be properly filled in from the database. However, if a
change is made to the FCKeditor contents and the Update button clicked, the change won't "stick."

This problem is caused by a missing call of the function FCK.UpdateLinkedField(). By submitting 
the editor's surrounding form with an ajax function the values of all form elements are collected 
in a javascript object (some kind of an array). At this time the value of the hidden field that 
usually contains the editor's html output is empty, because the editor's surrounding form wasn't 
submitted for real, you can call it a simulated submit. The workaround is to call the 
FCK.UpdateLinkedField() function before submitting the form. Either you call it directly before 
the ajax collect function or in the onClick attribute of the submit button or in the OnClientClick
attribute of an asp:Button. 

For general use, use the following hack to solve the problem in all FCKeditors. The function
FCKeditorUpdatePanelFixClass is used here as a class - a variable of the function type is created.

In an aspx file that uses and FCKeditor within an UpdatePanel, add the OnClientClick attribute to 
the Update button:

<asp:Button ID="ButtonAboutUsItemEditUpdate" CommandName="Update" Text="Update" runat="server"
   CssClass="ButtonStandard" OnClientClick="FCKeditorUpdatePanelFixObject.UpdateEditorFormValue();" />

This is called before the form's onSubmit event, so the FCKeditor will be "fixed" before the
editor's data is submitted for updating the database.
*/

function FCKeditorUpdatePanelFixClass()
{
    this.UpdateEditorFormValue = function()
    {
        for ( i = 0; i < parent.frames.length; ++i )
            if ( parent.frames[i].FCK )
            parent.frames[i].FCK.UpdateLinkedField();
    }
}

// instantiate the class
var FCKeditorUpdatePanelFixObject = new FCKeditorUpdatePanelFixClass();


/*
---------------------------------------------------------------------------------------------------
Following code displays an image offset from the current mouse position.
Used to display a large version of a thumbnail when the user moves the cursor over the thumbnail.

To use, add onmouseover and onmouseout attributes to an Image.
For onmouseover, pass big() the full pathname to the image to display, along with the width at
which the image should be displayed.

   photoImage.Attributes.Add("onmouseover", "big('" + rolloverImagePath + "', " + scaledWidth + ");");
   photoImage.Attributes.Add("onmouseout", "big_hide();");
*/

ns4=(navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? 1 : 0;
ie4=(document.all && !document.getElementById)? 1 : 0;
ie5=(document.getElementById && document.all)? 1 : 0;
ns6=(document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? 1: 0;
w3c=(document.getElementById)? 1 : 0;

wid=(ie4||ie5)?window.document.body.clientWidth-20:window.innerWidth-36

if(ns4)
{
    document.write ('<layer name="di1"></layer>')
}
else
{
    document.write ('<div id="di1" style="position:absolute;z-index:100"></div>')
}

outd=""

if(w3c)
    div1=document.getElementById('di1')
if(ie4)
    div1=document.all['di1']
if(ns4)
    div1=document.layers['di1']

function move_div(x,y)
{
	if (isNaN(x+y))
	    return
	if(ns4)
	{
	    div1.moveTo(x,y)
	}
	else
	{
	    div1.style.left=x+'px';
	    div1.style.top=y+'px';
	}
}

function write_div(text)
{
	if(ns4)
	{
		div1.document.open();
		div1.document.write(text);
		div1.document.close();
	}
	else 
	{
	    div1.innerHTML=text;
	}
}
 
function big(n,scaledWidth)
{
    ondiv=n
    write_div("<a href=javascript:void(0) onmouseout='big_hide()' onmouseover='ondiv=1'><img name=ib src="+n+" width="+scaledWidth+" style='border: solid 1px #000000;'></a>");
 
    if(ie4||ie5)
    {
        x = x - 15;
        y = y - 155;
    }
    else 
    {
        x = x - 130;
        y = y - 155;
    }
    
    // If the rollover image goes too far to the right, move it to the right.
    // The app is targeting screen width of approx 1000 pixels, and is displaying
    // pictures in a table of width approx. 900 pixels.
    maxRightSideDisplayOfRollover = 900;
    minLeftSideDisplayOfRollover = 20;
    
    widthScreenOverflow = (x + scaledWidth) - maxRightSideDisplayOfRollover;
    
    if (widthScreenOverflow > 0)
    {
        x = x - widthScreenOverflow;
    }
    
    if (x < minLeftSideDisplayOfRollover)
    {
        x = minLeftSideDisplayOfRollover;
    }
    
    move_div(x,y);
}

function big_hide()
{
	ondiv=0;
	t3=window.setTimeout('big_hide2()',100)
}

function big_hide2()
{
    if (ondiv==0)
    {
	    write_div("");
	    move_div(-1000,-1000)
	}
}

y=x=0

function dragIt(evt)
{
    if (!evt) 
        var evt = window.event;
    
    if(ie4||ie5)
    {
        x = window.event.clientX + document.body.scrollLeft; 
        y = window.event.clientY + document.body.scrollTop
    }
    else 
    {
        x = evt.pageX; 
        y = evt.pageY 
    }
}

document.onmousemove = dragIt

if(ns4)
{
    document.captureEvents( Event.MOUSEMOVE )
}


/*
---------------------------------------------------------------------------------------------------
*/
