txtSize = new Array();
iObjs = new Array('tbs', 'tbm', 'tbl', 'tbxl');
tObjs = new Array('tbts', 'tbtm', 'tbtl', 'tbtxl');
sObjs = new Array(10, 12, 14, 16);

var emailPage = '<form method=\'post\' action=\'index.php\'><input type=\'hidden\' name=\'emailPage\' /><table border=\'0\' cellpadding=\'3\' cellspacing=\'0\' style=\'background-color:#FFF; border:solid 1px #000;\'><tr><td><strong>To e-mail: </strong></td><td align=\'left\'><input type=\'text\' size=\'20\' name=\'em_to\' /></td></tr><tr><td><strong>Comment: </strong></td><td align=\'left\'><textarea style=\'width:200px; height:60px;\' name=\'em_com\'></textarea></td></tr><tr><td><strong>From e-mail: </strong></td><td align=\'left\'><input type=\'text\' size=\'20\' name=\'em_from\' /></td></tr><tr><td><strong>Name: </strong></td><td align=\'left\'><input type=\'text\' size=\'20\' name=\'em_name\' /></td></tr><tr><td colspan=\'2\'><input type=\'submit\' value=\'Send\' /></td></tr></div></form>';

function setTxtSize(size, tObj)
{
    var obj = document.getElementById('pageContent');

    if(obj != null) {
        obj.style.fontSize = size + 'px';

        for(var i = 0; i < tObjs.length; i++) {
            if(iObjs[i] == tObj.id) {
                switchTxtImage(tObjs[i], 0);
                txtSize[0] = tObjs[i];
                txtSize[1] = '/images/toolbar/txtSize' + i + '-1.gif';
            } else {
                switchTxtImage(tObjs[i], 1);
            }
        }

        createCookie('BUEITxtSize', size);
    }
}

function checkTxt()
{
    var size = readCookie('BUEITxtSize');

    if(size != null) {
        var id = null;

        for(var i = 0;i < iObjs.length;i++){
            if(sObjs[i] == size) {
                id = iObjs[i];
                txtSize[0] = tObjs[i];
                txtSize[1] = '/images/toolbar/txtSize' + i + '-1.gif';
            }
        }

        setTxtSize(size, document.getElementById(id));
    } else {
        txtSize[0] = 'tbtm';
        txtSize[1] = '/images/toolbar/txtSize1-1.gif';
    }
}

function newWindow(loc, w, h)
{
    window.open(loc, "bueiWindow", "status = 1, height = " + h + ", width = " + w + ", resizable = 1");
}

function switchTxtImage(name, bck)
{
    var img = null;

    if(document.getElementById) {
        i = resetTxtImgs(name, 1);

        if(bck == 0) {
            document.getElementById(name).src = '/images/toolbar/txtSize' + i + '-1.gif'
        }else if(bck == 1 && txtSize.length > 0) {
            document.getElementById(txtSize[0]).src = txtSize[1];
        }
    } else if(document.images) {
        i = resetTxtImgs(name, 0);

        if(bck == 0) {
            document.images[name].src = '/images/toolbar/txtSize' + i + '-1.gif'
        }else if(bck == 1 && txtSize.length > 0) {
            document.images[txtSize[0]].src = txtSize[1];
        }
    }
}

function resetTxtImgs(name, ids)
{
    var retrn = null;
    for(var i = 0; i < tObjs.length; i++) {
        if(ids == 1) {
            document.getElementById(tObjs[i]).src = '/images/toolbar/txtSize' + i + '.gif'
        } else {
            document.images[tObjs[i]].src = '/images/toolbar/txtSize' + i + '.gif'
        }

        if(tObjs[i] == name) {
                retrn = i;
            }
    }

    return retrn;
}

function createCookie(name,value,days)
{
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name)
{
    createCookie(name,"",-1);
}

function Toggle(txtAName, fckTxtAName, txtDivName, fckDivName)
{
	// Try to get the FCKeditor instance, if available.
	var oEditor ;
	if ( typeof( FCKeditorAPI ) != 'undefined' )
		oEditor = FCKeditorAPI.GetInstance( fckTxtAName ) ;

	// Get the _Textarea and _FCKeditor DIVs.
	var eTextareaDiv	= document.getElementById( txtDivName ) ;
	var eFCKeditorDiv	= document.getElementById( fckDivName ) ;

	// If the _Textarea DIV is visible, switch to FCKeditor.
	if ( eTextareaDiv.style.display != 'none' )
	{
		// If it is the first time, create the editor.
		if ( !oEditor )
		{
			CreateEditor(txtAName, fckTxtAName, txtDivName, fckDivName) ;
		}
		else
		{
			// Set the current text in the textarea to the editor.
			oEditor.SetData( document.getElementById(txtAName).value ) ;
		}

		// Switch the DIVs display.
		eTextareaDiv.style.display = 'none' ;
		eFCKeditorDiv.style.display = '' ;

		// This is a hack for Gecko 1.0.x ... it stops editing when the editor is hidden.
		if ( oEditor && !document.all )
		{
			if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
				oEditor.MakeEditable() ;
		}
	}
	else
	{
		// Set the textarea value to the editor value.
		document.getElementById(txtAName).value = oEditor.GetXHTML() ;

		// Switch the DIVs display.
		eTextareaDiv.style.display = '' ;
		eFCKeditorDiv.style.display = 'none' ;
	}
}

function CreateEditor(txtAName, fckTxtAName, txtDivName, fckDivName)
{
	// Copy the value of the current textarea, to the textarea that will be used by the editor.
	document.getElementById(fckTxtAName).value = document.getElementById(txtAName).value ;

	// Create an instance of FCKeditor (using the target textarea as the name).
	var oFCKeditor = new FCKeditor( fckTxtAName ) ;
	oFCKeditor.BasePath = '/fckeditor/';
	oFCKeditor.Width = '100%' ;
	oFCKeditor.Height = '800' ;
	oFCKeditor.ReplaceTextarea() ;
}

// The FCKeditor_OnComplete function is a special function called everytime an
// editor instance is completely loaded and available for API interactions.
function FCKeditor_OnComplete( editorInstance )
{
	// Enable the switch button. It is disabled at startup, waiting the editor to be loaded.
	document.getElementById('BtnSwitchTextarea').disabled = false ;
}

function PrepareSave(txtAName, fckTxtAName, txtDivName, fckDivName)
{
	// If the textarea isn't visible update the content from the editor.
	if ( document.getElementById( txtDivName ).style.display == 'none' )
	{
		var oEditor = FCKeditorAPI.GetInstance( fckTxtAName ) ;
		document.getElementById( txtAName ).value = oEditor.GetXHTML() ;
	}
}

function showCell(id)
{
    var obj = document.getElementById(id);

    obj.className = 'showCell';
}