var is2maximizeState = 0;
var is2WidTimer;
var is2Pas = 10;
var draggedElem;
var tooltipDiv = "is2_body:tooltip";
var scrollableDiv = "is2_body:windowContent:wrapped-main-window";
var releasebrowserIconView = "is2_body:windowContent:releasebrowser-icon-view";
var releasebrowserIconViewReleases = "is2_body:windowContent:releases-col";
var releasebrowserIconViewDates = "is2_body:windowContent:date-line";
var openPopups = {};

/** A post-it note height */
var _postitHeight = 118;

// Variable used to determine if the user's browser is IE
var _isIE_ = (navigator.appName == "Microsoft Internet Explorer") ? true:false;

/**
* Determine the current IE version the user is using.
* @return Integer Return -1 if not found, else return the current IE version
*/
function IEVersion() {
    // If we're not in IE, then it's all done
    if(!_isIE_) {
        return -1;
    } else {
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
            // Retrieve the "x.x" pattern from the userAgent
            var ieversion = new Number(RegExp.$1);
        }
        return ieversion;
    }
}

function initSameHeightColumns(){
    var maxHeight = $(scrollableDiv).parentNode.getHeight();
    var index;
    var item;
    for (index = 0, len = $(scrollableDiv).childElements().length; index < len; ++index) {
        item = $(scrollableDiv).childElements()[index];
        if(maxHeight < item.getHeight()) maxHeight = item.getHeight();
    }
    for (index = 0, len = $(scrollableDiv).childElements().length; index < len; ++index) {
        item = $(scrollableDiv).childElements()[index];
        item.style.height=maxHeight+'px';
    }
}

/**
 * Transparency effect on drag (only launched on left click).
 * The effect won't be applied if dragOpacity.DISABLED is TRUE.
 * @param event
 * @param source The element that caused the event
 */
dragOpacity.DISABLED = false;
function dragOpacity(event, source){
    if(!event) event = window.event;
    if (event.which) rightclick = (event.which == 3);
    else if (event.button) rightclick = (event.button == 2);

    if(!rightclick) {
        if(!dragOpacity.DISABLED){
            source.setOpacity(0.5);
            draggedElem = source;
            Event.observe('page','mouseup',endDragOpacity);
        }
    }
}

/**
 * End of the transparency effect
 */
function endDragOpacity(){
    Event.stopObserving('page','mouseup',endDragOpacity);
    draggedElem.setOpacity(1);
}

function launchDownload(){
    $('page').innerHTML += "<iframe id='dlframe' style='display:none;' src='./downloads/pdf/' />";
    setTimeout('$("dlframe").remove',5000);
}

function sendChatEnter(elem,event,target)
{
    if(sendEnter(elem,event,target)){
        this.value= '';
    }
}

function sendCellKey(elem,event)
{
    //call <ice:commandButton id="submit-cell" in mainTemplate.jspx
    if(!sendEnter(elem,event,'is2_body:submit-cell') && event.keyCode == 27){
        //call <ice:commandButton id="cancelCell" in mainTemplate.jspx
        $('is2_body:cancelCell').click();
    }
}

function sendEnter(elem,event,target)
{
    if (event.keyCode == 13)
    {
        if (! event.shiftKey && elem.value != "" )
        {
            var sub = $(target);
            sub.click();
        }
        return true;
    }
    return false;
}

function getDivByMousePosition(mouse,div){
    return $(div);
}

function callTooltip(idelem){
    $(tooltipDiv).style.left = ($(idelem).firstChild.firstChild.clientWidth+6+$(idelem).cumulativeOffset()[0])+'px';
    $(tooltipDiv).style.top = (-3+$(idelem).cumulativeOffset()[1])+'px';
}

function scrollViewer(sensH,sensV)
{
    var rbview=$(releasebrowserIconView).firstChild;
    var maxH = $(rbview).clientWidth+300;
    var	maxV = $(rbview).clientHeight+100;
    var scrollLeft = parseInt(rbview.style.left || 0) + is2Pas*sensH;
    var scrollTop = parseInt(rbview.style.top || 0) + is2Pas*sensV;
    var scroll=false;
    if(scrollLeft <= 0 && ((-scrollLeft+$(scrollableDiv).clientWidth)<=maxH ||(scrollLeft!=0 && sensH==1))){
        var rbline = $(releasebrowserIconViewDates).firstChild;
        clearTimeout(is2WidTimer);
        rbview.style.left = scrollLeft+'px';
        rbline.style.left = scrollLeft+'px';
        scroll=true;
    }
    if(scrollTop <= 0 && ((-scrollTop+$(scrollableDiv).clientHeight)<=maxV ||(scrollTop!=0 && sensV==1))){
        var rbrcol = $(releasebrowserIconViewReleases).firstChild;
        clearTimeout(is2WidTimer);
        rbview.style.top = scrollTop+'px';
        rbrcol.style.top = scrollTop+'px';
        scroll=true;
    }
    if(scroll)is2WidTimer = setTimeout("scrollViewer(" + sensH + "," + sensV + ");", 30);
}


function displayElement(element, value)
{
    $(element).style.display = value;
}

function setClass(element, value)
{
    element.className = value;
}

function moveOuttaRelativeBox(elem)
{
    var is2openMenuOldParent = elem.parentNode;
    if(openPopups[elem.id] && openPopups[elem.id] != elem)
    {
         $(openPopups[elem.id]).remove();
    	 openPopups[elem.id] = null;
    }
    is2openMenuOldParent.removeChild(elem);
    $('is2_body').appendChild(elem);
    openPopups[elem.id] = elem
}


function scrumOSwidgetWrapper(id,effect,action){
    if(effect){
        $('is2_widgets_'+id).blindUp({
            duration:0.3,
            afterFinish:function(){
                $('is2_widgets:toWinWrapperV').value=id;
                iceSubmit($('is2_widgets'),$('is2_widgets:toWinWrapper-'+action),null);
            }
        });
    }else{
        $('is2_widgets:toWinWrapperV').value=id;
        iceSubmit($('is2_widgets'),$('is2_widgets:toWinWrapper-'+action),null);
    }

}

function scrumOScallback(key){
    $('is2_header:serverSideCallBacksValue').value = key;
    iceSubmitPartial($('is2_callback'),$('is2_header:serverSideCallBacks'),null);
}

function switchMaximizeWindow(effect){
    if(is2maximizeState == 0){
        $('is2_body:main-window').style.zIndex = "180";
        if(effect)new Effect.MoveAndResizeTo('is2_body:main-window',2,2,{
            afterFinish: function(){
                setMaximize();
            }
        });
        else{
            $('is2_body:main-window').style.top = "2px";
            $('is2_body:main-window').style.left = "2px";
            setMaximize();
        }
    }else{
        if(effect)new Effect.MoveAndResizeTo('is2_body:main-window',82,304,{
            afterFinish: function(){
                resetMaximize();
            }
        });
        else{
            $('is2_body:main-window').style.top = "82px";
            $('is2_body:main-window').style.left = "304px";
            resetMaximize();
        }

    }
}

function coloredPulsate(id,color,aftercolor)
{
    $(id).style.backgroundColor=color;
    $(id).highlight({
        duration:1,
        startcolor:color,
        endcolor:aftercolor,
        restorecolor:aftercolor
    });
}

function scrollChat()
{
    var o = $("is2_body:windowContent:chat");
    if(o)
        o.scrollTop = o.scrollHeight;
    else if($("is2_widgets:chat"))
        $("is2_widgets:chat").scrollTop = $("is2_widgets:chat").scrollHeight;
    var i = 0;
    while(o = $('is2_popup:gdoc-container:'+i+':chat')){
        o.scrollTop = o.scrollHeight;
        i++;
    }


}

function setMaximize(){
    is2maximizeState = 1;
    var icon = $('main-window-maxicon').src;
    $('main-window-maxicon').src = icon.substring(0,icon.lastIndexOf("/"))+"/window.png";
}
function resetMaximize(){
    is2maximizeState = 0;
    if($('main-window-maxicon')){
        var icon = $('main-window-maxicon').src;
        $('main-window-maxicon').src = icon.substring(0,icon.lastIndexOf("/"))+"/expand.png";
        $('is2_body:main-window').style.zIndex = "169";
    }
}

function closeWin(elem,anim){
    elem.parentNode.lastChild.click();
}

function miseEnFormeChat (txtName, tag, enclose ) {
    if (document.getElementById(txtName).readOnly)
        return;
    var closeTag = ((enclose) ? "[/" + tag + "]" : "");
    var Tag = "[" + tag + "]"
    var txtObj = $(txtName);
    if (Prototype.Browser.IE)
    {
        var str = document.selection.createRange().text;
        txtObj.focus();
        var sel = document.selection.createRange();
        sel.text = Tag + str + closeTag;
        return;
    }
    else
    {
        // position du scroll
        oldPos = txtObj.scrollTop;
        oldHght = txtObj.scrollHeight;

        // position du curseur
        pos = txtObj.selectionEnd + Tag.length + closeTag.length;

        txtObj.value = txtObj.value.substr(0, txtObj.selectionStart) + Tag +
        txtObj.value.substr(txtObj.selectionStart,
            txtObj.selectionEnd-txtObj.selectionStart) +
        closeTag + txtObj.value.substr(txtObj.selectionEnd);

        // repositionnement cuseur apr�s la balise fermante
        // peut �tre grandemant am�lior� ;-)
        txtObj.selectionStart = pos;
        txtObj.selectionEnd = pos;

        // calcul et application de la nouvelle bonne postion du scroll
        newHght = txtObj.scrollHeight - oldHght;
        txtObj.scrollTop = oldPos + newHght;
    }
    txtObj.focus();
}

function selectPrivateChat(){
    var maxZ = 0;
    var index;
    for (index = 0, len = $('is2_popup:gdoc-container').childElements().length; index < len; ++index) {
        var item = $('is2_popup:gdoc-container').childElements()[index];
        if(maxZ < parseInt(item.style.zIndex || 0)) maxZ = parseInt(item.style.zIndex || 0);
    }
    $(this.id).style.zIndex = maxZ+1;
}

function scrollPrivates(){
    var maxZ = 0;
    var index;
    for (index = 0, len = $('is2_popup:gdoc-container').childElements().length; index < len; ++index) {
        var item = $('is2_popup:gdoc-container').childElements()[index];
        if(maxZ < parseInt(item.style.zIndex || 0)) maxZ = parseInt(item.style.zIndex || 0);
    }
    $(this.id).style.zIndex = maxZ+1;
}

function restartChange(){
    if(confirm('The current application settings will be overwritten and the server will restart. Continue ?')){
        setTimeout('window.location.reload(true)',15000);
        return true;
    }
    return false;
}

function confirmChange(bundle){
    if(!bundle) bundle = "Are you sure ?";
    if(confirm(bundle)){
        return true;
    }
    return false;
}

function updateColor(color){
    $('is2_body:windowContent:dummytext').parentNode.parentNode.style.backgroundColor = color;
    $('is2_body:windowContent:dummytext').parentNode.parentNode.parentNode.parentNode.lastChild.firstChild.style.backgroundColor = color;
}

function updateTextColor(color){
    $('is2_body:windowContent:dummytext').style.color = color;
}

var currentRelease = 0;
function moveToRelease(direction){
	if(!$('is2_body:windowContent:releases:'+(currentRelease+direction)+':releaseDetails')){
		currentRelease = 0;
	}
	if((currentRelease+direction)<0)
		currentRelease = 1;
	$('is2_body:windowContent:releases:'+(currentRelease+direction)+':releaseDetailsC').scrollIntoView();
	currentRelease+=direction;
}

/**
 * In the roadmap, set the window viewport on the current active sprint
 */
function focusOnActiveSprint() {
    $('is2_body:windowContent:wrapped-main-window').scrollLeft = $('currentSprintPosition').offsetLeft - getElementWidth($('is2_body:windowContent:wrapped-main-window'))/2;
}

/**
 * Cross-browser function allowing to retrieve the target from an Event.
 */
function getSrcFromEvent(event){
    var targ = false;
    if(event == undefined || event == null) {
        return false;
    }

    // IE
    if (event.srcElement){
        targ = event.srcElement;
    // W3C Compliant browsers
    } else if (event.target != null && event.target != undefined){
        targ = event.target;
    }
    // defeat Safari bug
    if (targ.nodeType == 3)
	targ = targ.parentNode;

    return targ;
}
/**
 * Cross-browser function allowing to retrieve the mouse X position from a MouseEvent
 */
function getMousePosX(event) {
    var posx = 0;
    if (!event)  {
        var e = window.event;
        event = e;
    }
    // Mozilla & W3C
    if (event.pageX) {
        posx = event.pageX;
    // IE
    } else if (event.clientX) 	{
        posx = event.clientX + document.body.scrollLeft
                + document.documentElement.scrollLeft;
    }
    return posx;
}
/**
 * Cross-browser function allowing to retrieve the mouse Y position from a MouseEvent
 */
function getMousePosY(event) {
    var posy = 0;
    if (!event)  {
        var e = window.event;
        event = e;
    }
    // Mozilla & W3C
    if (event.pageY) 	{
        posy = event.pageY;
    // IE
    } else if (event.clientY) 	{
        posy = event.clientY + document.body.scrollTop
                + document.documentElement.scrollTop;
    }
    return posy;
}
/**
* Retrieve the real X pos of the element passed in argument (css "left" attribute)
* @param Elem
* @return Integer
*/
function getElementLeft(Elem) {
	var elem = Elem;
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

/**
* Retrieve the real Y pos of the element passed in argument (css "top" attribute)
* @param Elem
* @return Integer
*/
function getElementTop(Elem) {
	var elem = Elem;
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

/**
* Retrieve the real height value of the element passed in argument
* @param Elem
* @return Integer
*/
function getElementHeight(Elem) {
	var elem = Elem;
	xPos = elem.offsetHeight;
	return xPos;
}

/**
* Retrieve the real width value of the element passed in argument
* @param Elem
* @return Integer
*/
function getElementWidth(Elem) {
		var elem = Elem;
		xPos = elem.offsetWidth;
		return xPos;
}

/**
* Retrieve the cumulative scrollTop value applicated on an element
* @param Elem
* @return Integer
*/
function getElementScrollTop(Elem) {
	var elem = Elem;
	scrollTop = 0;
	tempEl = elem.parentNode;

	while (tempEl != null) {
		if(tempEl.scrollTop) {
			scrollTop += tempEl.scrollTop;
		}
		tempEl = tempEl.parentNode;
	}

	return scrollTop;
}

/**
* Retrieve the cumulative scrollLeft value applicated on an element
* @param Elem
* @return Integer
*/
function getElementScrollLeft(Elem) {
	var elem = Elem;
	scrollLeft = 0;
	tempEl = elem.parentNode;

	while (tempEl != null) {
		if(tempEl.scrollLeft) {
			scrollLeft += tempEl.scrollLeft;
		}
		tempEl = tempEl.parentNode;
	}

	return scrollLeft;
}

/**
 * Display the embedded menu in the postit note.
 * @param element The id of the element to display
 * @param value The value to insert in the style.display properties
 * @param forceUp Force the position where the menu is shown, the value for this
 * can be displayFloatMenu.UP ou displayFloatMenu.BOTTOM.
 */
displayFloatMenu.UP = 1;
displayFloatMenu.BOTTOM = 2;
displayFloatMenu.BLOCKED = false ;
displayFloatMenu.requestQueue = new Array();
function displayFloatMenu(element, value, forceOrientation)
{
    // If the BLOCKED bool is false, nothing is done
    if(displayFloatMenu.BLOCKED) {
        return;
    }
    // If the menu is not already in the specified "value"
    if($(element).style.display != value) {
        $(element).style.display = value;

        var menu = $(element).firstChild.nextSibling;
        var icon = $(element).firstChild;
        // The TOP position of the bottom of the menu layer
        var bottomPos = getElementTop($(element)) + getElementHeight(icon) + getElementHeight(menu) - getElementScrollTop($(element));
        // The TOP position of the bottom of the wrapped-main-window body (or main-window if the later does not exist)
        var bodyPos;

        if($('is2_body:windowContent:wrapped-main-window') != null) {
            bodyPos = getElementTop($('is2_body:windowContent:wrapped-main-window')) + getElementHeight($('is2_body:windowContent:wrapped-main-window'));
        } else {
            bodyPos = getElementTop($('is2_body:main-window')) + getElementHeight($('is2_body:main-window'));
        }

        // IE fix for the flickering issue
        swapOnMouseOnIE($(element).parentNode.id);

        if(value !='none') {
            // Get the post-it id
            var temp = $(element).parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;

            // If the mouse come over the menu, the current menu is deleted from
            // the clearMenu and the postitOnBottom requests lists so it won't disapear.
            // The dragOpacity effect and the drag&drop are also temporarly disabled
            // until the user leave the post-it note
            menu.onmouseover = function() {
                if($(temp).onmousemove != null) {
                    displayFloatMenu.requestQueue[temp] = $(temp).onmousemove;
                    $(temp).onmousemove = null;
                }

                if(clearMenu.requestQueue[element] != undefined && clearMenu.requestQueue[element]!=null){
                    clearMenu.requestQueue[element] = null;
                }
                if(postitOnBottom.requestQueue[element.replace("_menuFloatPanel","")] != undefined && postitOnBottom.requestQueue[element.replace("_menuFloatPanel","")]!=null){
                    postitOnBottom.requestQueue[element.replace("_menuFloatPanel","")] = null;
                }
                dragOpacity.DISABLED = true;
            }

            // When the mouse leave the menu, the dragOpacity effect and the drag&drop are restored
            menu.onmouseout = function() {
                if(displayFloatMenu.requestQueue[temp] != undefined &&
                    displayFloatMenu.requestQueue[temp] != null
                  ) {
                    $(temp).onmousemove = displayFloatMenu.requestQueue[temp];
                    displayFloatMenu.requestQueue[temp] = null;
                }
                dragOpacity.DISABLED = false;
            }

            // IE fix for the flickering issue (again)
            swapOnMouseOnIE(menu.id);

            // If the post-it note is too close to the bottom border, the menu will not
            // be entirely displayed, in this case, the menu is shown at the top of the menu icon
            // instead of the bottom
            if(((forceOrientation != undefined && forceOrientation == displayFloatMenu.UP) || forceOrientation == undefined) &&
                    (bottomPos > bodyPos && (menu.isUp == undefined || !menu.isUp))) {
                icon.className="floatMenuIcon_hover floatMenuIconBUp";
                menu.oldTop = menu.style.top;
                menu.style.top = -(getElementHeight(menu) - (_postitHeight-1) + getElementHeight(icon)) + "px";
                menu.isUp = true;
            } else if ( ((forceOrientation!=undefined && forceOrientation == displayFloatMenu.BOTTOM) || forceOrientation == undefined ||
                (forceOrientation == displayFloatMenu.UP && (bottomPos <= bodyPos)))
                && (bottomPos <= bodyPos)) {
                menu.style.top = (_postitHeight-2) + "px";
                icon.className="floatMenuIcon_hover floatMenuIconBDown";
                if(menu.isUp != undefined && menu.isUp) {
                    menu.isUp = undefined;
                }
                if(menu.oldTop != undefined && menu.oldTop != null) {
                    menu.style.top = menu.oldTop;
                    menu.oldTop = null;
                }
            }
        }
    }
}

/**
 * Open the embedded menu on the right click event
 * @param event
 * @param baseElement
 * @param source
 */
function forcePostitMenu(event, baseElement, source) {
    if(!event) event = window.event;
    if (event.which) rightclick = (event.which == 3);
    else if (event.button) rightclick = (event.button == 2);
    // Put the post-it on the front
    postitOnTop(source);
    var element = baseElement+'_menuFloatPanel';
    if(rightclick) {
        // Stop event propagation to its ancestors
        event.cancelBubble = true;  //IE
        if (event.stopPropagation) event.stopPropagation(); // W3C

        // Bypass the browser context menu
        source.oncontextmenu = function() {return false;};
        $(element).isShown = true;

        // Hide the tooltip
        displayElement(idGoUp(source.id)+':description', 'none');

        // Display the menu
        displayFloatMenu(baseElement+'_menuFloatPanel', 'block', displayFloatMenu.UP);

        // The displayFloatMenu action is temporarly disabled so it will remain displayed
        // enough time so the user can move its mouse over the menu
        displayFloatMenu.BLOCKED = true;

        // The menu is shown for at least 800 ms, then the displayFloatMenu is unblocked
        // and the requests lists of clearMenu and postitOnBottom are executed
        setTimeout(cleanReq, 800);
    }
    return false;
}

/**
 * Unblock displayFloatMenu function and execute the pending requests on
 * clearMenu and postitOnBottom functions. When finished, clear the requests lists.
 */
function cleanReq(){
    displayFloatMenu.BLOCKED = false;

    for (obj in clearMenu.requestQueue) {
        if(clearMenu.requestQueue.hasOwnProperty(obj)) {
            if(clearMenu.requestQueue[obj] != null){
                clearMenu(clearMenu.requestQueue[obj], obj.replace("_menuFloatPanel",""));
            }
        }
    }
    clearMenu.requestQueue = new Array();
    for (obj in postitOnBottom.requestQueue) {
        if(postitOnBottom.requestQueue.hasOwnProperty(obj)) {
            if(postitOnBottom.requestQueue[obj] != null) {
                postitOnBottom($(postitOnBottom.requestQueue[obj]), obj);
            }
        }
    }
    postitOnBottom.requestQueue = new Array();
}

/** Clear menu pending requests */
clearMenu.requestQueue = new Array();
/**
 * Hide the embedded menu if displayFloatMenu is not blocked.
 * If displayFloatMenu.BLOCKED is TRUE, add a pending request in clearMenu.requestQueue.
 */
function clearMenu(source, baseElement) {
    if(baseElement == null) return;
    if(displayFloatMenu.BLOCKED) {
        clearMenu.requestQueue[baseElement+"_menuFloatPanel"] = source;
        return;
    }
    if(baseElement != null) {
        var element = baseElement+"_menuFloatPanel";
       if($(element) != null && $(element).isShown) {
           displayFloatMenu(element, 'none');
           $(element).isShown = undefined;
       }
    }
}

/**
 * Give a z-index of 1000 to the post-it note in argument.
 * @param element The element id
 */
function postitOnTop(element) {
    swapOnMouseOnIE(element);
    _postitHeight = getElementHeight($(element));
    $(element).style.zIndex = 1000;
}

/** postitOnBottom pending requests */
postitOnBottom.requestQueue = new Array();
/**
 * Restore the z-index of the post-it note in argument to 999 if displayFloatMenu is not blocked.
 * If displayFloatMenu.BLOCKED is TRUE, then add a pending request in postitOnBottom.requestQueue.
 * @param element The element id
 * @param baseId
 */
function postitOnBottom(element, baseId) {
    if(element == null) return;
    if(displayFloatMenu.BLOCKED ||
        ($(baseId+"_menuFloatPanel").isShown != undefined && !$(baseId+"_menuFloatPanel").isShown)
      ){
        postitOnBottom.requestQueue[baseId] = element.id;
        return;
    }
    element.style.zIndex = 999;
}

/**
 * On Internet Explorer, replace the onemouseover and onmouseout event listeners
 * by the onmouseenter and onmouseleave event listeners respectively.
 * The old onmouseover and onmouseout listener are dropped.
 * @param element The element id which need to swap its listeners.
 */
function swapOnMouseOnIE(element){
    if(_isIE_) {
        if(!$(element).onmouseleave) {
            $(element).onmouseleave = $(element).onmouseout;
            $(element).onmouseout = null;
        }
        if(!$(element).onmouseenter){
            $(element).onmouseenter = $(element).onmouseover;
            $(element).onmouseover = null;
        }
    }
}

/**
 * Remove the last part of an Icefaces/JSF generated id.
 * @example
 * idGoUp('is2_body:window-content:main-window') will return "is2_body:window-content".
 */
function idGoUp(generatedId){
    var lastId = generatedId.lastIndexOf(':');
    return generatedId.substr(0, lastId);
}

tinyMCE.init({
    theme : "advanced",
    mode : "none",
    plugins : "fullscreen",
    theme_advanced_buttons1 : "undo,redo,bold,italic,underline,numlist,bullist,link,unlink,blockquote,cleanup,fullscreen",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    submit_patch : false,
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
	theme_advanced_buttons3_add : "",
	fullscreen_new_window : false,
	fullscreen_settings : {
        theme_advanced_buttons1 : "fullscreen,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help,code,forecolor,backcolor",
        theme_advanced_buttons3 : "hr,removeformat,|,sub,sup,|,charmap",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom"
	}
});

function tinySave(id){
    id = "is2_body:windowContent:"+id;
    var  editor = tinyMCE.get(id);
    if (editor.isDirty()){
        tinyMCE.triggerSave();
    }
}

function tinyUpdateContent(id){
    id = "is2_body:windowContent:"+id;
    if(tinyMCE.getInstanceById(id)){
        try {
            var  editor = tinyMCE.get(id);
            editor.setContent(document.getElementById(id).value);
        } catch(err) {
            tinyMCE.editors = new Array();
            tinyMCE.execCommand('mceAddControl', false, id);
            var  editor = tinyMCE.get(id);
            editor.setContent(document.getElementById(id).value);   
        }
    }
}

function tinyForceUpdateContent(id){
    id = "is2_body:windowContent:"+id;
    if(tinyMCE.getInstanceById(id)){
        try {
            tinyMCE.editors = new Array();
            var oldEditor = document.getElementById(id+"_parent");
            var parent = oldEditor.parentNode;
            parent.removeChild(oldEditor);
            tinyMCE.execCommand('mceAddControl', false, id);
            var  editor = tinyMCE.get(id);
            var newEditor = document.getElementById(id+"_parent");
            newEditor.style.display='block';
            editor.setContent(document.getElementById(id).value);    
        } catch(err) {
             
        }
    }
}

function tinyClearContent(id){
    id = "is2_body:windowContent:"+id;
    if(tinyMCE.getInstanceById(id)){
        try {
            var  editor = tinyMCE.get(id);
            editor.setContent('');
            } catch(err) {

        }
    }
}

function tinyShow(id){
    id = "is2_body:windowContent:"+id;
    if(tinyMCE.getInstanceById(id)){
        try {
            tinyMCE.execCommand('mceRemoveControl', false, id);
        } catch(err) {
            tinyMCE.editors = new Array();
        }
    }
    tinyMCE.execCommand('mceAddControl', false, id);
}