
tinyMCE_GZ.init({
    plugins : 'none',
    themes : 'advanced',
    languages : 'en',
    disk_cache : true,
    debug : false
});


function toggleEditor(id, ship) {
    var inst = tinyMCE.getInstanceById(id);

    if (inst == null)
    {
        $(id).setHTML(editinfo);
        tinyMCE.execCommand('mceAddControl', false, id);
    }
    else
    {
        if(! submit_changes(ship)) return;
        inst.setHTML('');
        tinyMCE.execCommand('mceRemoveControl', false, id);
    }
}


function submit_changes(ship)
{
    var inst = tinyMCE.getInstanceById("content");

    if ($('emailname').getValue() == "")
    {
        $('emailname').setStyle('background-color', '#FFD700');
        return false;
    }

    apos=$('email').getValue().indexOf("@");
    dotpos=$('email').getValue().lastIndexOf(".");


    if ($('email').getValue() == "" || apos<1 || dotpos-apos<2)
    {
        $('email').setStyle('background-color', '#FFD700');
        return false;
    }

    hideDiv('editbox'); 
    showDiv('edit'); 
    hideDiv('submit');

    var myXHR = new XHR ({
		          method:'post',
                          onSuccess: 
                              function(text) { 
                                    $('supply').setHTML(text); 
                              }     
                         });

    myXHR.send('email_edit.php',"name="+$('emailname').getValue()+"&email="+$('email').getValue()+"&ship="+ship+"&content="+inst.getHTML().replace(/&/g , '$')+"");

    $('emailname').setStyle('background-color', '#131313');
    $('email').setStyle('background-color', '#131313');

    return true;
}
