$j = jQuery.noConflict();


function enableButtonHover(){
    $j(document).ready(function(){
        $j(".CtrlButton").mouseover(function(){        
            $j(this).addClass("CtrlButtonHover");
        }).mouseout(function(){
            $j(this).removeClass("CtrlButtonHover");
        });
    });
}

function initMCE(area){
    
    /*tinyMCE_GZ.init({
	    plugins : 'bbcode',
	    themes : 'advanced',
	    languages : 'de',
	    disk_cache : true,
	    debug : false
    });*/

    tinyMCE.init({
        language : "de",
        mode : area?"exact":"none",
        elements : area?area:null,
        theme : "advanced",
        plugins : "bbcode",
	    theme_advanced_buttons1 : "bold,italic,underline,bullist,|,link,unlink,image,|,forecolor,fontsizeselect,formatselect,|,undo,redo,removeformat,cleanup,code",
	    theme_advanced_buttons2 : "",
	    theme_advanced_buttons3 : "",	    
	    theme_advanced_toolbar_location : "top",
	    theme_advanced_toolbar_align : "left",
	    //theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",
	    theme_advanced_styles : "Infobox links 200px=leftBox;Infobox rechts 200px=rightBox;",
	    content_css : "/css/bbcode.css?t="+ new Date().getTime(),
	    entity_encoding : "raw",
	    add_unload_trigger : false,
	    remove_linebreaks : false
    });
}


function setWysiwygCookie(value){
    var a = new Date();
    a = new Date(a.getTime() +1000*60*60*24*10);
    document.cookie = ".USE_WYSIWYG="+value+";path=/;expires="+a.toGMTString()+";"; 
}

function enableMCE(id, stateFieldID){
    debugger;
    var elm = document.getElementById(id);        
    tinyMCE.execCommand('mceAddControl', false, id);
    var state = document.getElementById(stateFieldID);
    state.value = "True";
    setWysiwygCookie("True");
}

function disableMCE(id, stateFieldID){
    debugger;
    var elm = document.getElementById(id);        
    tinyMCE.execCommand('mceRemoveControl', false, id);
    var state = document.getElementById(stateFieldID);
    state.value = "False";
    setWysiwygCookie("False");
}

function toggleEditor(id, stateFieldID) {
	var elm = document.getElementById(id);        
	if (tinyMCE.getInstanceById(id) == null){
		enableMCE(id, stateFieldID);
	} else {
		disableMCE(id, stateFieldID);
	}
}


function openWindow(url){
    window.open(url, "Vollbild", "width=840,height=630,toolbar=no,menubar=no");
    return false;
}

    
function invokeGetTicket(addr, successFunction){
    $j.ajax({
       type: "GET",
       url: addr,
       dataType: "text",
       success: successFunction
     });
}

function putTicket(addr, ctrl) {
    invokeGetTicket(addr, function(msg) { 
                                document.getElementById(ctrl).value = msg;
                            }
                   );
}