/**
 * Validation trigger for all tinyMCEs
 * 
 * @param editor_id die unique id des tinymce
 * @param css_error css-string für border
 * @param css_ok    css-string für border
 * 
 * @author AJS
 */
function trigger_tiny_mce_validation(editor_id, css_error, css_ok){
    tinyMCE.triggerSave();
    if($("#" + editor_id).valid() == 0){
        if(css_error == undefined){
            css_error = '1px dashed #FF0000';
        }
        jQuery('#'+editor_id +'_tbl.mceLayout').css('border',css_error);
    }else{
        if(css_ok == undefined){
            css_ok = '1px solid #BABB3B';
        }
        jQuery('#'+editor_id +'_tbl.mceLayout').css('border', css_ok);
    }
}


/**
 * checks number character from text_area with id=id and writes information or warning text in chek_number_character_+id
 *
 * @param string id from textarea
 * @param int max_count
 * @author Nugo
 */
function update_chek_number_character_status(id, max_count, warning)
{
    //check if elements exists
    if (jQuery('#'+id).length &&  jQuery('#chek_number_character_'+id).length)
    {
        if (jQuery('#'+id).val().length > max_count)
        {
            jQuery('#chek_number_character_'+id).html("<span style='color:red'>Die maximale Anzahl der Zeichen wurde überschritten!</span>");
            jQuery('#chek_number_character_'+id).addClass('error');

            if (warning)
            {
                jQuery('#'+id).addClass('error');
                jQuery('#chek_number_character_'+id).addClass('error');
            }
        }
        else
        {
            var numChar = max_count- jQuery('#'+id).val().length;
            jQuery('#chek_number_character_'+id).text("Noch "+numChar+ " Zeichen.");
            jQuery('#chek_number_character_'+id).removeClass('error');

            if (warning && jQuery('#'+id).val().length > 0)
            {
                jQuery('#'+id).removeClass('error');
                jQuery('#chek_number_character_'+id).removeClass('error');
            }
        }

        if (warning && jQuery('#'+id).length)
        {
            if(jQuery('#'+id).val().length == 0) jQuery('#'+id).addClass('error');
        }
    }
}

/**
 * @abstract checks number character from text_area with id=id and writes information or warning text in chek_number_character_+id
 * @param string id from textarea
 * @param int max_count
 * @author Nugo
 */
function set_class_by_id(id, max_count)
{
    if (jQuery('#'+id).val().length == 0 ||
        jQuery('#'+id).val().length > max_count)
    {
        jQuery('#'+id).addClass('error');
    }
    else
    {
        jQuery('#'+id).removeClass('error');
    }
}

/**
 * @abstract For to reset inputs of type 'file'.
 * @param string id of html area to be resetted
 * @author <maak.fischer@semigator.de>
 */
function reset_html(id)
{
    jQuery('#'+id).html(jQuery('#'+id).html());
}



/**
 * @abstract Memorize seminars
 * @param base_url - needed, since we cannot use php here!
 * @param id_products - the id of the seminar to be memorized
 * @author <maak.fischer@semigator.de>
 */
function seminar_merken(base_url, id_products)
{
    jQuery.post(base_url + 'merkliste/notice_seminar/' + id_products);
    jQuery("#MemorizeLink").hide();
    jQuery("#MemerizedText").fadeIn("slow");
    jQuery("#MemorizeLink_" + id_products).hide();
    jQuery("#MemerizedText_" + id_products).fadeIn("slow");
    jQuery("#Merkliste").fadeIn("slow");
}



/**
 * @abstract Memorize resources (seminars, trainers)
 * @param id - the id of the resource to be memorized
 * @param type - resource type
 * @author Nugo
 */
function merken(id, type)
{
    var target_url;
    target_url = "http://"+ window.location.hostname + '/merkliste/notice/' + type+'/'+id;
    jQuery.post(target_url);
    if(jQuery('#MemorizeLink_'+id).length > 0)
    {
        jQuery("#MemorizeLink_" + id).hide();
    }

    if(jQuery('#MemerizedText_'+id).length > 0)
    {
        jQuery("#MemerizedText_" + id).fadeIn("slow");
    }
    jQuery("#Merkliste").fadeIn("slow");
}



/**
 * Nachbildung der PHP-Funktion für Javascript
 * @param string term
 * @return string
 */

function sgtr_speaking_url_part(term)
{
    if (typeof(term) == 'undefined') return("");

    term = term.replace(/ /g,"-");
	term = term.replace(/__/g,'-');
    // term = term.replace(/ä/g,'ae');
    // term = term.replace(/ö/g,'oe');
    // term = term.replace(/ü/g,'ue');
    // term = term.replace(/ß/g,'ss');
    // term = term.replace(/Ä/g,'Ae');
    // term = term.replace(/Ö/g,'Oe');
    // term = term.replace(/Ü/g,'Ue');
    term = term.replace(/!/g,'');
    term = term.replace(/\?/g,'');
	term = term.replace(/ć/g,'c');
    term = term.replace(/é/g,'e');
    term = term.replace(/è/g,'e');
    term = term.replace(/ê/g,'e');
    term = term.replace(/\(/g,'');
    term = term.replace(/\)/g,'');
    term = term.replace(/\//g,'');
    term = term.replace(/;/g,'');
    term = term.replace(/\./g,'_punkt_');
    term = term.replace(/\:/g,'');
    term = term.replace(/\,/g,'');
    // term=utf8_encode(preg_replace("/[^\w|\-".utf8_decode("äöü")."]/i",'',utf8_decode(term))); // \w matches alphanumeric plus "_"
    term = term.replace(/^\-/g,'');
    term = term.replace(/\-+/g,'-');
    // term = term.replace(/|/g,':');
    term = term.replace(/&/g,' und ');
    term = term.substr(0,150);
    return term.toLowerCase();
}


/**
 * Nachbildung der PHP-Funktion für Javascript
 * @param string term
 * @return string
 */
function sgtr_speaking_url_part_original(term)
{
    if (typeof(term) == 'undefined') return("");

    term = term.replace(/ /g,"-");
	term = term.replace(/__/g,'-');
    // term = term.replace(/ä/g,'ae');
    // term = term.replace(/ö/g,'oe');
    // term = term.replace(/ü/g,'ue');
    // term = term.replace(/ß/g,'ss');
    // term = term.replace(/Ä/g,'Ae');
    // term = term.replace(/Ö/g,'Oe');
    // term = term.replace(/Ü/g,'Ue');
    term = term.replace(/!/g,'');
    term = term.replace(/\?/g,'');
	term = term.replace(/ć/g,'c');
    term = term.replace(/é/g,'e');
    term = term.replace(/è/g,'e');
    term = term.replace(/ê/g,'e');
    term = term.replace(/\(/g,'');
    term = term.replace(/\)/g,'');
    term = term.replace(/\//g,'');
    term = term.replace(/;/g,'');
    term = term.replace(/\./g,'_punkt_');
    term = term.replace(/\:/g,'');
    term = term.replace(/\,/g,'');
    // term=utf8_encode(preg_replace("/[^\w|\-".utf8_decode("äöü")."]/i",'',utf8_decode(term))); // \w matches alphanumeric plus "_"
    term = term.replace(/^\-/g,'');
    term = term.replace(/\-+/g,'-');
    // term = term.replace(/|/g,':');
    term = term.replace(/&/g,' und ');
    term = term.substr(0,150);
    return term;
}




