var st = 0;

var ie = (document.all);
var dom = (document.getElementById);
var ver = parseInt(navigator.appVersion);
var IE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;
var NS = (navigator.appName == "Netscape") ? 1 : 0;
var TopCoord  = 0;
var LeftCoord = 0;
//var nMenu = 8;
var z = 0;

// run by links and update
function update_links() {
        var z = 0;
        $("a[@title='play video']").each(
            function (){
               $(this).attr("name", z);
                $(this).click (function(){ toggle_webinar_video( this.name ); return false; });
                $('#add'). append('<div id="webinar-stream' + z +'" style="width: 640px; height: 495px; position: absolute; border: solid #0C83BF 10px; left: 70px; top: 220px; z-index: 1000000; background: #0C83BF; display: none;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="640" height="480" id="movie'+ z +'">  <param name="movie" value="/third_party/flash/container.swf?playerOpts=targetClip*'+ this.href +'*s||pauseAtFirstFrame*false*b">  <param name=quality value=high>   <embed src="/third_party/flash/container.swf?playerOpts=targetClip*'+ this.href +'*s||pauseAtFirstFrame*false*b" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="640" height="480"  id="movie'+ z +'">  </embed></object><a href="javascript:toggle_webinar_video('+ z +')" style="float: right; color: #fff;">Close window</a></div>');
                z++;
            }
        );
        
}

function debugObj(obj)
{
    var count = 0;
    var str = "";

    for(prop in obj)
    {
        count++;
        str += prop + "," + obj[prop] + "\n";

        if(count>19)
        {
            alert(str);
            count = 0;
            str = "";
        }
    }
    alert(str);
}
/**
 * Ajax calls
 * @todo Clean up js at the top before // ---- NON AJAX
 */
var orig_rating = new Object();

function get_el(el_id)
{
    return document.getElementById(el_id);
}

// ------------------ NON AJAX -------------------
/**
 * toggles the input size for a tiny mce editor
 * @param {int} width
 * @param {int} height
 */
function toggle_input_size(width,height)
{
    editor = document.getElementById("mce_editor_0");
    if (editor) 
    {
        editor.style.width = width+'px';
        editor.style.height = height+'px';
    }
}


/**
 * Add multiple onload event functions
 */
function add_load_event(function_name) 
{
    var current_onload = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = function_name;
    }
    else 
    {
        if (typeof function_name != 'function'){
            alert("Is not a function: " + function_name);
            return;
        }
        window.onload = function() 
        {
            current_onload();
            function_name();
        }
    }
}


/**
 * Show/hide divs
 * @param {string} ids - a string of , seperated element ids
 */
function show_hide(ids)
{
    var list_of_ids = new Array;
    
    // check for , in id
    if( ids.indexOf(',') )
    {
        list_of_ids = ids.split(',');
    }
    
    // do show/hide based on css display = none
    // it will assume that the element is showing if no css is found
    if( list_of_ids.length > 0 )
    {
        for(i=0; i < list_of_ids.length; i++)
        {
            // show hide ele
            show_hide_ele(list_of_ids[i]);
        }
    }
    else // one id
    {
        // show hide ele
        show_hide_ele(ids);
    }
}

/**
 * Subset of show_hide
 * @param {id} element id
 * @todo add swap attribute etc
 */
function show_hide_ele(id)
{
        var ele = document.getElementById(id);
        
        if(ele.style.display != 'none')
        {
            ele.style.display = 'none';
        } 
        else
        {
            ele.style.display = 'block';
        }
        
        return ele.style.display;
}

function force_show_hide(id, action)
{   
    var ele = document.getElementById(id);
    
    if (!ele) return ;
    
    if(ele.style.display != 'none' && action == 'hide')
    {
        ele.style.display = 'none';
    } 
    else if(ele.style.display != 'block' && action == 'show')
    {
        ele.style.display = 'block';
    }
}

function force_timed_show_hide(id, action)
{
    setTimeout("force_show_hide('"+id+"', '"+action+"')", 80 );
}

/**
 * show_timed_ele - shows an element for a amount of time 
 * @param {Object} ele_id
 * @param {Object} time
 */
function show_timed_ele(ele_id, time)
{
    var ele = document.getElementById(ele_id);
    
    if( ele.style.display != 'block')
    {
        ele.style.display = 'block';
        setTimeout("force_show_hide('"+ele_id+"','hide')", time);
    }
}

/**
 * Swaps innerHTML by id
 * @param {id} element id
 */
function swap_html(id,content_1,content_2)
{
    var ele = document.getElementById(id);
    if(ele.innerHTML ==  content_1)
    {
        ele.innerHTML = content_2;
    }
    else
    {
        ele.innerHTML = content_1;
    }
    
}

/**
 * Woyano_pop_up
 * @param {string} window_target = path to file
 * @param {string} window_name
 * @param {int} int window_width
 * @param {int} int window_height
 */
var pop_win; 
function pop_up_window(window_target, window_width, window_height)
{
    
    // check for ? to make sure the url is correct
    var op = '?';
    if( window_target.indexOf('?') != -1 )
    {
        op = '&';
    }

    if ( pop_win )
    {
        pop_win.focus();    
    }

    //open window
    pop_win = window.open(window_target+op+'pop_up=true', 'pop_win', 'width='+window_width+',height='+window_height+'no,menubar=no,status=no,resizable=yes,scrollbars=yes');

}

/**
 * To be called from pop_ups to fill in a element on the 'window.opener' window
 * to make life easy
 * @param {string} id the element id to be filled
 * @param {string} html the content filler
 */
function update_ele_content(id,html)
{
    // alert(window.opener.document.getElementById(id) + ' '+id); // <-- for Checking if an element exists 
    window.opener.document.getElementById(id).innerHTML = html;
}

// ------------------ AJAX -------------------

/**
 * Flag as adult
 * @param {Object} content_id
 */
function flag_as_adult(content_id)
{
    do_ajax('flag_as_adult',content_id);
}

/**
 * Flag as bad
 * @param {Object} content_id
 */
function flag_as_bad(content_id)
{
    do_ajax('flag_as_bad',content_id);
}

// ------

// Mark as featured
function f(content_id,nudge)
{
    do_ajax('feature_this',content_id+','+nudge);
}

// Mark as Unfeatured
function uf(content_id)
{
    do_ajax('unfeature_this',content_id);
}

// COMMENTS related functions:

/**
 * Clears the add comments details
 * @deprecated
 */
function clear_add_comments()
{
    c = get_el('add_comment');
    c.innerHTML = '';
    
    pid = get_el('parent_comment_id');
    pid.value = '';
    
    return true;
}

/**
 * 
 * @param {integer} comment_id
 */
function comment_up(comment_id)
{
    //do ajax
    do_ajax('comment_increase_rating', comment_id);
}

/**
 * 
 * @param {integer} comment_id
 */
function comment_down(comment_id)
{
    //do ajax
    do_ajax('comment_decrease_rating', comment_id);
}

/**
 * Subits the asset form to upload photos!
 */
function submit_asset_content()
{
    
    // get all forms elements
    var form_ele = get_el('asset_form');
    var form_elements = '';
    var error = '';
    var ele = '';
    
    for (var i=0; i<form_ele.length; i++)
    {
        ele = form_ele.elements[i];
        
        if( ele.getAttribute("name") == 'subject'&& ele.value.length == 0 )
        {
            error += "Title cannot be empty!\n";
        }
        if( ele.getAttribute("name") == 'upload'&& ele.value.length == 0 )
        {
            error += "File location is empty! Please choose an asset to upload.\n";
        }
        if( ele.getAttribute("name") == 'body'&& ele.value.length == 0 )
        {
            error += "Description cannot be empty! \n";
        }
        
        
        form_elements += ele.value+',';
    }
    
    if( error.length > 0 )
    {
        alert(error);
        return;
    }
    /*
    do_ajax('upload_asset_photo', form_elements);
    */
    form_ele.submit();
}

// Globals for comment editing
var ORIG_C = "";
var REPLY_ID = "";

function edit_comment(comment_id)
{
    var comment_input = cancel_comment_action();
    add_title(0);
    reply_title(0);
    
    var comment = get_el('comment_'+comment_id);
    ORIG_C = trim( comment.innerHTML.replace(/<br( *?)\/?>/gi, "") );
    comment.innerHTML = comment_input.innerHTML;
    comment_input.innerHTML = '';

    make_edit_form(comment_id, ORIG_C);
}

function reply_comment(username, comment_id)
{
    var comment_input = cancel_comment_action();

    add_title(0);
    reply_title(1, username);
    
    REPLY_ID = comment_id;
    reply_box(0, REPLY_ID);
    
    var reply_input = get_el('reply_input_'+comment_id);
    reply_input.innerHTML = comment_input.innerHTML;
    comment_input.innerHTML = '';
    
    make_reply_form(reply_input, comment_id);
}

function add_title(x)
{
    var add_title = get_el('add_comment_title');
    if (x==1)
    {
        add_title.style.display = 'block';
    }
    else
    {
        add_title.style.display = 'none';
    }
}

function reply_title(x, username)
{
    var username = (username == null) ? "" : username;
    
    var reply_title = get_el('replying_to_title');
    var un = get_el('replying_to_username');
    un.innerHTML = username;
    
    if (x==1)
    {
        reply_title.style.display = 'block';
    }
    else
    {
        reply_title.style.display = 'none';
    }
}

function reply_box(x, comment_id)
{
    var comment_id = (comment_id == null) ? "" : comment_id;
    var reply_box = get_el('reply_'+comment_id);
    
    if (x==1)
    {
        reply_box.style.display = 'block';
    }
    else
    {
        reply_box.style.display = 'none';
    }
}

function cancel_comment_action()
{
    var comment_input = get_el('comment_input');
    if ( comment_input.innerHTML == '' )
    {
        var comment_form = get_el('add_comment_form');
        var comment_div = comment_form.parentNode;
        reset_form(comment_input, comment_form);
        
        if ( ORIG_C != '' )
        {
            comment_div.innerHTML = ORIG_C.replace(/\n/g, "<br>\n");
            ORIG_C = '';
        }
        
        if ( REPLY_ID != '' )
        {
            reply_box(1, REPLY_ID);
            REPLY_ID = '';
        }
    }
    return comment_input;
}

function reset_form(comment_input, comment_form)
{
    comment_input.innerHTML = comment_form.parentNode.innerHTML;
    comment_form.parentNode.innerHTML = '';
    add_title(1);
    reply_title(0);
    make_add_form(comment_input);
}


function make_add_form(comment_input)
{
    var comment_form = get_el('comment_form');
    
    // if comment_id node exists remove it
    var c_id_input = get_el('comment_id');
    if ( c_id_input != null )
    {
        c_id_input.parentNode.removeChild(c_id_input);
    }
    
    // if parent_comment_id node doesn't exist then append it and clear its value
    var p_c_id_input = get_el('parent_comment_id');
    if ( p_c_id_input == null )
    {
        p_c_id_input = document.createElement('input');
        p_c_id_input.setAttribute('id', 'parent_comment_id');
        p_c_id_input.setAttribute('name', 'parent_comment_id');
        p_c_id_input.setAttribute('type', 'hidden');
        comment_form.appendChild(p_c_id_input);
    }
    p_c_id_input.setAttribute('value', '');
    
    var sub_but = get_el('add_comment_submit');
    sub_but.value = 'Add Comment';
    
    var text_area = get_el('add_comment');
    text_area.innerHTML = '';
    
    var cancel = get_el('cancel_edit');
    cancel.innerHTML = '';

    var action = get_el('do_add_comment');
    if ( action == null )
    {
        action = document.createElement('input');
        action.setAttribute('id', 'do_add_comment');
        action.setAttribute('name', 'do_add_comment');
        action.setAttribute('type', 'hidden');
        action.setAttribute('value', 'true');
        comment_form.appendChild(action);
    }
    
    action = get_el('do_edit_comment');
    if ( action != null )
    {
        comment_form.removeChild(action);
    }
}


function make_edit_form(comment_id, orig_c)
{
    var comment_form = get_el('comment_form');
    
    // if comment_id node doesn't exist then append it and set it
    var c_id_input = get_el('comment_id');

    var add_node_comment_id = false;
    if ( navigator.appName == 'Microsoft Internet Explorer' )
    {
        if ( c_id_input == null || c_id_input.getAttribute('id') == null || c_id_input.getAttribute('id') == "" )
        {
            add_node_comment_id = true;
        }
    }
    else
    {
        if ( c_id_input == null )
        {
            add_node_comment_id = true;
        }
    }
    
    if (add_node_comment_id)
    {
        c_id_input = document.createElement('input');
        c_id_input.setAttribute('id', 'comment_id');
        c_id_input.setAttribute('name', 'comment_id');
        c_id_input.setAttribute('type', 'hidden');
        comment_form.appendChild(c_id_input);
    }
    
    c_id_input.setAttribute('value', comment_id);

    // if parent_comment_id node exists then remove
    var p_c_id_input = get_el('parent_comment_id');

    if ( p_c_id_input != null )
    {
        p_c_id_input.parentNode.removeChild(p_c_id_input);
    }
    
    var sub_but = get_el('add_comment_submit');
    sub_but.value = 'Submit Comment';
    
    var text_area = get_el('add_comment');
    text_area.innerHTML = orig_c;
    text_area.focus();
    
    var cancel = get_el('cancel_edit');
    cancel.innerHTML = '<input type="button" onclick="cancel_comment_action()" value="Cancel" />';

    var action = get_el('do_add_comment');
    if ( action != null )
    {
        action.parentNode.removeChild(action);
    }
    
    action = get_el('do_edit_comment');
    if ( action == null )
    {
        action = document.createElement('input');
        action.setAttribute('id', 'do_edit_comment');
        action.setAttribute('name', 'do_edit_comment');
        action.setAttribute('type', 'hidden');
        action.setAttribute('value', 'true');
        comment_form.appendChild(action);
    }
    
    
}


function make_reply_form(reply_input, comment_id)
{
    var comment_form = get_el('comment_form');
    
    // if comment_id node exists then remove
    var c_id_input = get_el('comment_id');
    if ( c_id_input != null )
    {
        c_id_input.parentNode.removeChild(c_id_input);
    }
    
    // if parent_comment_id node doesn't exist then append it and set it
    var p_c_id_input = get_el('parent_comment_id');
    if ( p_c_id_input == null )
    {
        p_c_id_input = document.createElement('input');
        p_c_id_input.setAttribute('id', 'parent_comment_id');
        p_c_id_input.setAttribute('name', 'parent_comment_id');
        p_c_id_input.setAttribute('type', 'hidden');
        comment_form.appendChild(p_c_id_input);
    }
    p_c_id_input.setAttribute('value', comment_id);
    
    var sub_but = get_el('add_comment_submit');
    sub_but.value = 'Reply to Comment';
    
    var text_area = get_el('add_comment');
    text_area.innerHTML = '';
    text_area.focus();
    
    var cancel = get_el('cancel_edit');
    cancel.innerHTML = '<input type="button" onclick="cancel_comment_action()" value="Cancel" />';

    var action = get_el('do_add_comment');
    if ( action == null )
    {
        action = document.createElement('input');
        action.setAttribute('id', 'do_add_comment');
        action.setAttribute('name', 'do_add_comment');
        action.setAttribute('type', 'hidden');
        action.setAttribute('value', 'true');
        comment_form.appendChild(action);
    }
    
    action = get_el('do_edit_comment');
    if ( action != null )
    {
        comment_form.removeChild(action);
    }
}


/**
 * 
 * @param {integer} comment_id
 * @param {integer} time
 */
function edit_comment_countdown(comment_id, time)
{
    var el = get_el('time_left_'+comment_id);
    
    if (time > 0)
    {
        el.innerHTML = time;
        time--;
        setTimeout("edit_comment_countdown("+comment_id+", "+time+")", 1000);
    }
    else
    {
        var el = get_el('edit_'+comment_id);
        el.className = 'edit';
        
        var comment = get_el('comment_id')
        if ( comment != null )
        {
            cancel_comment_action();            
        }
    }
}


/* 
 * Javascript Trim, LTrim and RTrim Functions (http://www.somacon.com/p355.php)
 */
function ltrim(str)
{ 
 for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
 return str.substring(k, str.length);
}
function rtrim(str)
{
    for (var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
    return str.substring(0,j+1);
}
function trim(str)
{
 return ltrim(rtrim(str));
}

function isWhitespace(charToCheck)
{
 var whitespaceChars = " \t\n\r\f";
 return (whitespaceChars.indexOf(charToCheck) != -1);
}
/* End of Javascript Trim, LTrim and RTrim Functions */

/**
 * 
 * @param {string} name
 */
function jump_to_anchor(name)
{
    window.location.hash = name;
}

/**
 * Load a content template in the editor
 * @param {string} template_id
 */
var have_set_thumb = false;
function insert_asset(id,type,cat,title)
{
    if (typeof title == 'undefined') 
    {
        title = '';
    }
    setTimeout("do_ajax('insert_asset','"+id+","+type+","+cat+","+title+"')",1);
    
    if ( (cat != 'pdf' || cat != 'template') && ! have_set_thumb )
    {
        //set_as_thumb(id,true);
    }
    
    if ( cat == 'image' )
    {
        toggle_input_size(725,400); 
    }
}

function map_thump_path(id)
{
    var els = id.split('');
    var dirs = '';
    for ( i=0; i<3; i++ )
    {
        dirs += els[i] + '/';
    }
    return '/sites/knexus/data/thumbnails/'+dirs+id+'-thumb.png';
}

function set_as_thumb(id,no_alert)
{
    get_el('internal_thumb').value = id;
    get_el('thumb_preview').innerHTML = '<img src="'+map_thump_path(id)+'" width="70" height="70" class="std_image">';
    if ( ! no_alert )
    {
        //alert('Set image as thumbnail! Save content to see changes.');
        close_popup();
    }
}

function close_popup()
{
    $('#'+lastPopup).TransferTo(
        {
            to:lastPopup+'-opener',
            className:'transferer2', 
            duration: 200
        }
    ).hide();
    toggle_selects('show');
}

function update_tinymce(html_str)
{
    tinyMCE.setContent(tinyMCE.getContent()+html_str+'<br /><br />');
    tinyMCE.execCommand('mceFocus',true,'mce_editor_0');
    
    close_popup();

    // One day we would like this to work :(
    //tinyMCE.execInstanceCommand('mce_editor_0','mceInsertContent', false, html_str+'<br />');
}

/* ~~~~ BLOGROLL EDITING ~~~~~ */

/**
 * 
 * @param {string} link_id
 */
function edit_blog_link(link_id)
{
    // change link to input text
    var edit_title_box = get_el('edit_title_box_'+link_id);
    var edit_title_input_box = get_el('edit_title_input_box_'+link_id);
    
    edit_title_box.style.display = 'none';
    edit_title_input_box.style.display = 'block';   

    // change title to input text
    var edit_link_box = get_el('edit_link_box_'+link_id);
    var edit_link_input_box = get_el('edit_link_input_box_'+link_id);
    
    edit_link_box.style.display = 'none';
    edit_link_input_box.style.display = 'block';
    
    // change edit button to save edit form
    var edit_button_box = get_el('edit_button_box_'+link_id);
    var save_edit_box = get_el('save_edit_box_'+link_id);
    
    edit_button_box.style.display = 'none';
    save_edit_box.style.display = 'block';
    
    // change delete button to cancel button
    var del_button_box = get_el('del_button_box_'+link_id);
    var cancel_edit_box = get_el('cancel_edit_box_'+link_id);
    
    del_button_box.style.display = 'none';
    cancel_edit_box.style.display = 'block';
}

/**
 * 
 * @param {string} link_id
 */
function cancel_edit_link(link_id)
{
    var edit_title_box = get_el('edit_title_box_'+link_id);
    var edit_title_input_box = get_el('edit_title_input_box_'+link_id);
    
    edit_title_box.style.display = 'block';
    edit_title_input_box.style.display = 'none';    
    
    // change title to input text
    var edit_link_box = get_el('edit_link_box_'+link_id);
    var edit_link_input_box = get_el('edit_link_input_box_'+link_id);
    
    edit_link_box.style.display = 'block';
    edit_link_input_box.style.display = 'none';
    
    // change edit button to save edit form
    var edit_button_box = get_el('edit_button_box_'+link_id);
    var save_edit_box = get_el('save_edit_box_'+link_id);
    
    edit_button_box.style.display = 'block';
    save_edit_box.style.display = 'none';
    
    // change delete button to cancel button
    var del_button_box = get_el('del_button_box_'+link_id);
    var cancel_edit_box = get_el('cancel_edit_box_'+link_id);
    
    del_button_box.style.display = 'block';
    cancel_edit_box.style.display = 'none';
}


/* ~~~~ AUTO LOOK UPS ~~~~~ */

/**
 * SEARCH autocomplete_lookup
 * @param {Object} search_input
 */
function search_autocomplete_lookup(search_input)
{
    //vars
    if( search_input.length >= 1)
    {
        // slight lag on showing auto complete
        setTimeout("do_ajax('search_autocomplete', '"+search_input+"');", 500);
    }
    else
    {
        force_show_hide('search_autocomplete','hide');
    }
}


/**
 * USERNAME autocomplete_lookup
 * @param {Object} search_input
 */
function username_autocomplete_lookup(search_input)
{
    var submit_value = '';

    if( search_input.length >= 1)
    {
            // split by , and just submit the last value
            if( search_input.indexOf(",") > 0)
            {
                submit_value = search_input.split(",");
                submit_value = submit_value[(submit_value.length-1)];
            }
            else
            {
                submit_value = search_input;
            }

        if( submit_value.length > 0 && submit_value != ' ') // just check you don't search for nothing
        {
            // slight lag on showing auto complete
            setTimeout("do_ajax('username_autocomplete', '"+submit_value+"');", 500);
        }
    }
    else
    {
        force_show_hide('username_autocomplete','hide');
    }
}

/**
 * TAGS autocomplete_lookup
 * @param {Object} search_input
 */
function tags_autocomplete_lookup(search_input)
{
    var submit_value = '';

    //vars
    if( search_input.length >= 1)
    {
            // split by , and just submit the last value
            if( search_input.indexOf(",") > 0)
            {
                
                submit_value = search_input.split(",");
                submit_value = submit_value[(submit_value.length-1)];
            }
            else
            {
                submit_value = search_input;
            }

        if( submit_value.length > 0 && submit_value != ' ') // just check you don't search for nothing
        {
            // slight lag on showing auto complete
            setTimeout("do_ajax('tags_autocomplete', '"+submit_value+"');", 500);
        }
    }
    else
    {
        force_show_hide('tags_autocomplete','hide');
    }
}

/**
 * GEO TAGS autocomplete_lookup
 * @param {Object} search_input
 */
function geo_tags_autocomplete_lookup(search_input)
{

    var submit_value = '';

    //vars
    if( search_input.length >= 1)
    {
            // split by , and just submit the last value
            if( search_input.indexOf(",") > 0)
            {
                
                submit_value = search_input.split(",");
                submit_value = submit_value[(submit_value.length-1)];
            }
            else
            {
                submit_value = search_input;
            }

        if( submit_value.length > 0 && submit_value != ' ') // just check you don't search for nothing
        {
            // slight lag on showing auto complete
            setTimeout("do_ajax('geo_tags_autocomplete', '"+submit_value+"');", 500);
        }
    }
    else
    {
        force_show_hide('geo_tags_autocomplete','hide');
    }
}


/**
 * Fills a element with content from the auto complete drop down menu 
 * used by all dropdown "menus"
 * @param {Object} ele
 * @param {Object} hide_ele
 * @param {Object} content
 * @param {bool} prepend
 */
function fill_form_from_ac(ele, hide_ele, content, prepend)
{
    fill_ele(ele, content, prepend);
    
    force_show_hide(hide_ele,'hide');
    document.getElementById(ele).focus();
}

/**
 * Fills an element with content
 * @param {string} ele - name of element
 * @param {string} content
 */
function fill_ele(ele, content, prepend)
{
    // get var
    var ele = get_el(ele);
    var prepend_value = '';
    var comma = '';
    
    // fill element by type
    if( ele.tag == 'textarea' )
    {
        if( prepend == 'true')
        {
            prepend_value = ele.innerHTML;
        }
        
        if(prepend_value.length > 0)
        {
            comma = ',';
        }
        
        ele.innerHTML = prepend_value+' '+content+comma;
    }
    else
    {
        if( prepend == 'true' && ele.value.length > 1)
        {
            prepend_value = ele.value;
        }
        
        if(prepend_value.length > 0)
        {
            comma = ',';
        }
        
        // do check for 1st char in a search and strip it before adding the seach results on
        if( prepend_value.indexOf(",") > 0 )
        {
            last_search = prepend_value.split(",");
            //if( last_search[(last_search.length-1)].length <= 3 ) // dump last value
            //{
                last_search.pop(); // drop last entry
            //}
            
            // rejoin this way because .join ain't doing what i want it to X(
            prepend_value = '';
            for(i=0; i<last_search.length; i++ )
            {
                    prepend_value += last_search[i]+',';        
            }
        }
        else
        {
            prepend_value = '';
        }

        // fill the element
        ele.value = prepend_value+content+comma;
    }
}

function login_alert()
{
    alert('You need to login to do that.'); 
}

/**
 * MAIL TO!
 * populates the "to" field when your messaging
 * @param {string} name
 */
function pop_from_address_book(name)
{
    fill_ele('to_field', name, true);
}

/**
 * Get version of IE user is using
 */
function getIEVersionNumber()
{
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    if (MSIEOffset == -1)
    {
        return 0;
    }
    else
    {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));   
    }
}

function clear_search_box(search_box)
{
    if ( search_box.value == 'search knexus' || search_box.value == 'search my site' || search_box.value == 'your email' )
    {
        search_box.value = '';
        search_box.style.color = '#000000';
    }
}

function mt(content_id,my_taste,training,no_session)
{   
    if ( no_session )
    {
        alert('Please login to use MyTaste');
        return; 
    }
    
    if ( training )
    {
        var my_text = 'Training';
    }
    else
    {
        var my_text = 'Loading';
    }
    
    get_el('my_taste_'+content_id).innerHTML = my_text + ' <img src="/sites/knexus/template/uk/gfx/ajax-loader.gif" class="va_c">';
    do_ajax('my_taste',content_id+','+my_taste+','+training);

}

function load_iframe(iframe_id,url)
{
    $('#'+iframe_id).attr('src',url);
    $('#'+iframe_id).attr('width',560);
    $('#'+iframe_id).attr('height',260);
}

function toggle_selects(hide_show)
{
    var collection = document.getElementsByTagName('select');
    for ( var i=0; i< collection.length; i++ )
    {
        collection[i].style.display = (hide_show == 'hide' ? 'none' : 'inline');
    }
}

// Fixes bug that was affecting add content screen
function go_hash(my_hash)
{
    setTimeout("window.location.hash = '" + my_hash + "'; ",100);
}

/* ADSENSE FUNCTIONS */
var adsense_default = 'null';
function adsense_set_default(id)
{
    adsense_default = id;
}

function adsense_save_default()
{
    if (adsense_default != 'null')
    {
        do_ajax('adsense_save_default', adsense_default);
        adsense_default = 'null';
    }
}

/* Alex: some form field validation functions */
function isEmailAddr(elem, msg)
{
    var str = elem.value;
    return isEmailStr(str, msg);
}

function isEmailStr(str, msg)
{
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re))
    {
        if (msg) {
            alert(msg);
        }
        return false;
    }
    else
    {
        return true;
    }
}

function isNotEmpty(elem, msg)
{
    var str = elem.value;
    var re = /.+/;
    if (!str.match(re))
    {
        alert(msg);
        return false;
    }else{
        return true;
    }
}

function oneIsNotEmpty(elem1, elem2, msg)
{
    var str1 = elem1.value;
    var str2 = elem2.value;
    var re = /.+/;
    if (!str1.match(re) && !str2.match(re))
    {
        alert(msg);
        return false;
    }else{
        return true;
    }
}

function isLength(elem, len, msg)
{
    var str = elem.value;
    if (str.length != len)
    {
        alert(msg);
        return false;   
    }
    return true;
}

function isChecked(elem, msg)
{
    checked = elem.checked;
    if (!elem.checked)
    {
        alert(msg);
        return false;
    }else{
        return true;
    }
}

function confirm_action(question,url)
{
    if (confirm(question))
    {
        go(url);
    }
}

function confirm_attach_del(question, action, args, id)
{
    if (confirm(question))
    {
        do_ajax_loader(action, args, id);
    }
}

function go(url)
{
    location.href = url;
}

function confirm_form_action(question)
{
    if (confirm(question))
    {
        return true;
    }
    return false;
}

function do_ajax_loader(action, args, id)
{
    get_el(id).innerHTML = '<img src="/sites/knexus/template/uk/gfx/ajax-loader.gif\"/>';
    do_ajax(action, args);
}

function delete_attachment(content_id, content_id, file_id)
{
    //do ajax
    do_ajax('delete_attachment', content_id+','+file_id);
}

var webinar_video_html = '';

// start video with add stat
function start_webinar_video(content_id)
{
//    do_ajax( 'access_stat', content_id);
    toggle_webinar_video(content_id);
}

function toggle_webinar_video(content_id)
{ 
    id = (arguments.length > 0) ? arguments[0] : '';
        
//  jump_to_anchor('table-top');

    var el_stat = show_hide_ele('webinar-stream'+id);
    // for stoping the playing
    if ( el_stat == 'none' )
    {
        webinar_video_html = get_el('webinar-stream'+id).innerHTML;
        get_el('webinar-stream'+id).innerHTML = '';
        get_el('webinar-stream'+id).innerHTML = webinar_video_html;
    }
//  else// if ( webinar_video_html[id] != '' )
//  {
//      get_el('webinar-stream'+id).innerHTML = webinar_video_html[id];
//  }

}

function switch_popup(id, on, left, top) {
    obj = $('#'+id)[0];
    if (obj && obj.style) {
        obj.style.display = (on ? 'inline' : 'none');
    }
}

function show(n) {
    clearTimeout(st);
    hide();

    var argv = show.arguments;
    var argc = show.arguments.length;
    var obj = getobj('menu'+n);
    var img = (argc > 1) ? document.images['m'+argv[1]] : getobj('d'+n);
    var top = (argc > 2) ? argv[2] : null;
    TopCoord  = ObjTop(img, 1);
    LeftCoord = ObjLeft(img, 1);

    if (!document.all) {
        document.getElementById('menu'+n).style.visibility='visible';
    }
    else {
        document.all['menu'+n].style.visibility='visible';
    }
}

function hide() {
        for (n=1; n<=nMenu; n++) {
            var obj = getobj('menu'+n);
            if (!document.all) {
                document.getElementById('menu'+n).style.visibility='hidden';
                document.getElementById('menu'+n).top  = -1000;
                document.getElementById('menu'+n).left = -1000;
            }
            else {
                document.all['menu'+n].top  = -1000;
                document.all['menu'+n].left = -1000;
                document.all['menu'+n].style.visibility='hidden';
            }
        }
}

function getobj(s) {
//alert(s);
if (s =='') return;
if (ie)
return (document.all[s].style);
else if (dom)
return (document.getElementById(s).style);
else
return (document.layers[s]);
}

function ObjLeft(elem, offset) {
if ((NS) && (ver==4)) {
return elem.x + offset;
}
else {
var X = 0;
do { X += elem.offsetLeft } while ((elem = elem.offsetParent) != null);
return X + offset;
}

}

function ObjTop(elem, offset) {
if ((NS) && (ver==4)) {
return elem.y + elem.height + offset;
}
else {
if (IE) {
var H = elem.height;
}
else {
var H = elem.height;
}
var Y = 0;
do { Y += elem.offsetTop } while ((elem = elem.offsetParent) != null);
return Y + H + offset;
}
}

// For movie start from javascript
function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  } else {
    return document[movieName]
  }
}



function copy_from_select(sel_departure, sel_destination, remove) {

    return !$('#'+sel_departure+' option:selected').remove().appendTo('#'+sel_destination);
    
}

// adding new option into select
function add2select(sel, val, title) {
    sel = get_el(sel);
    var newOpt = new Option(title, val);
    newOpt.innerHTML = title;   
    sel.appendChild(newOpt);
}

function switch_plus( num ) {
    plus =  'http://' + location.host + '/sites/knexus/template/uk/gfx/icons/plus.gif';
    minus = 'http://' +  location.host + '/sites/knexus/template/uk/gfx/icons/minus.gif';
    if (el = get_el("plus"+num)){
         el.src = (el.src == minus) ? plus : minus;
    }else{
        alert(get_el("plus"+num));
    }
}

/* Added by Shesternin for "Select all" in /my-knexus/interests */
function select_all_checkbox(checked, xpath) {
    if (!xpath) {
        xpath = '.checkbox_modules';
    }
    checkboxes = $(xpath); 
    for (i=0; i<checkboxes.length; i++) {
        checkboxes[i].checked = checked;
    }
}

/* Access stat */
allTrExpanded    = new Array;
allTblExpanded   = new Array;
allLeafExpanded  = new Array;
allLinksExpanded = new Array;

function parse_table_id(tblName) {
    return '&table=' + tblName;

    params = new Object();
    params[1] = '&g_id=';
    params[2] = '&u_id=';
    params[3] = 'users';
    params[4] = 'activities';

    res = '';
    arr = tblName.split('_');
    for (i=1; i<arr.length-1; i++) {
        res += (params[i] + arr[i]);
    }
    res += ('&t=' + params[arr.length]);

    return res;
}

function change_status(currItem, tblName) {
    var currTR           = currItem.parentNode.parentNode;
    var currTbl          = document.getElementById(tblName);
    var lenTrExpanded    = allTrExpanded.length;
    var lenTblExpanded   = allTblExpanded.length;
    var lenLeafExpanded  = allLeafExpanded.length;

    if (currTR.className == "collapsed") {
        currTR.className = "expanded";
        currTbl.className =  "display";

        arr = tblName.split('_');
        if (arr.length == 3) {
            $('#' + tblName).load(window.location.href + parse_table_id(tblName) );
        }

        allLinksExpanded.push(currTbl);

        allTblExpanded.push(currTbl);
        allTrExpanded.push(currTR);
    }
    else {
        currTR.className = "collapsed";
        currTbl.className = "dont_display";

        for ( var i in allLinksExpanded ) {
            if (allLinksExpanded[i] == currTbl) {
                allLinksExpanded[i] = '';
            }
        }
        
        var currTrChange = currTbl.getElementsByTagName("tr");
        for (i=0; i<currTrChange.length; i++) {
            if (currTrChange[i].className == "expanded") {
                currTrChange[i].className = "collapsed";
            }
        }
        for (i=0; i<lenLeafExpanded; i++) {
            if (allLeafExpanded[i]) {
                allLeafExpanded[i].className = "dont_display";
            }
        }
        if (lenTrExpanded != 0) {
            allTrExpanded[lenTrExpanded - 1].className = "collapsed";
        }
        if (lenTblExpanded != 0) {
            allTblExpanded[lenTblExpanded - 1].className = "dont_display";
        }
        
        
        allTblExpanded.pop();
        allTrExpanded.pop();
    } 
}

function change_status_leaf(currItem, tblName1, tblName2, aName1, aName2) {
    var currTR   = currItem.parentNode.parentNode;
    var currTbl1 = document.getElementById(tblName1);
    var currTbl2 = document.getElementById(tblName2);
    var currA1   = document.getElementById(aName1);
    var currA2   = document.getElementById(aName2);

    if (currTR.className == "collapsed") {
        if (currTR) {
            currTR.className = "expanded";
        }
        if (currTbl1) {
            currTbl1.className =  "display";
        }
        if (currA1) {
            currA1.className =  "dont_display";
        }
        allLeafExpanded.push(currTbl1);
        allLeafExpanded.push(currTbl2);

    } else {
        if (currTR) {
            currTR.className = "collapsed";
        }
        if (currTbl1) {
            currTbl1.className = "dont_display";
        }
        if (currTbl2) {
            currTbl2.className = "dont_display";
        }
        if (currA1) {
            currA1.className =  "display";
        }
        if (currA2) {
            currA2.className =  "display";
        }
        allTblExpanded.pop();
        allTblExpanded.pop();

    }
}

function change_status_link(currA, becomeActiveA, tblNameShow, tblNameHide) {
    var currTR = currA.parentNode.parentNode;
    var currTblShow = document.getElementById(tblNameShow);
    var currTblHide = document.getElementById(tblNameHide);
    
    var currBecomeActiveA = document.getElementById(becomeActiveA);
    
    if (currTblShow) {
        currTblShow.className = "display";
        allLinksExpanded.push(currTblShow);
    }
    if (currTblHide) {
        currTblHide.className = "dont_display";
        for ( var i in allLinksExpanded ) {
            if (allLinksExpanded[i] == currTblHide) {
                allLinksExpanded[i] = '';
            }
        }
        
//        allLinksExpanded.pop(currTblHide);
    }
    
    if (currTR) {
        currTR.className = "expanded";
    }

    if (currA) {
        currA.className = "dont_display";
    }

    if (currBecomeActiveA) {
        currBecomeActiveA.className = "display";
    }
}

/* Added for new design by DS */
function roll(n) {
    var e = document.getElementById(n);
    if (e.style.display == 'block') {
        e.style.display = 'none'
    }
    else {
        e.style.display = 'block'
    }
}

function dE(n, s, type) {
    if (!type)  {
        type = 'block';
    }
    var e = document.getElementById(n);
    if (!s) {
        s = (e.style.display == '') ? -1 : 1;
    }
    e.style.display = (s == 1) ? type : 'none';
}
function subnav (current,all) {
    for (var i = 1; i <= all; i++){
        n = 'subnav' + i;
        var t = document.getElementById(n);
        if (t) {     
            if( i!=current ) {        
                t.style.display = 'none';
            }
            else {
                t.style.display = 'block';
            }
        }
    }
}

function middlenav (current,all) {
    for (var i = 1; i <= all; i++){
        n = 'middlenav' + i;
        b = 'btn_middlenav' + i;
        var item = document.getElementById(n);      
        var btn = document.getElementById(b);       
        if(i!=current) {        
        item.style.display = 'none';
        btn.className = '';
        }
        else {
        item.style.display = 'block';
        btn.className = 'active';
        }
    }
}


function open_video(file_video, width, height)
{
//    file_video = '/sites/knexus/template/uk/gfx/promo_02.flv';
    $('#player_box')[0].innerHTML = '' +
        '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" id=\'movie\'>' +
        '<param name=movie value="/third_party/flash/container.swf?playerOpts=targetClip*' + file_video + '*s||pauseAtFirstFrame*true*b">' +
        '<param name="wmode" value="transparent">' +
        '<param name=quality value=high>' +
        '<embed src="/third_party/flash/container.swf?playerOpts=targetClip*' + file_video + '*s||pauseAtFirstFrame*true*b" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent" width="' + width + '" height="' + height + '" swLiveConnect="true" name=\'movie\'>' +
        '</embed></object>';
}

function close_video()
{
    $('#player_box')[0].innerHTML = '';
}


function get_ids_opened_tabs() {
    var res = '';
   
    for ( var i in allLinksExpanded ) {
        if (typeof(allLinksExpanded[i].id) != 'undefined') {
            res += '&' + allLinksExpanded[i].id;
        }
    }
  
/*
    for (var i in allTrExpanded) {
        if ( !confirm (i) ) {
            break;
        }
    }
    var tabs = $('.display');
    for(i=0; i<tabs.length; i++) {
        if (typeof(tabs[i].id) != 'undefined' && tabs[i].id.substr(0,1) != 'a' ) {
            res += '&' + tabs[i].id;     
        }
    }*/
    return res;
}

function view_report_in_pdf (url, pars, pop_up)
{

    url = 'http://' + window.location.hostname + url + 'pdf?' + pars + get_ids_opened_tabs();
    if (pop_up) {
        pop_up_window(url, 1024, 600);
    }
    else {
        window.location.href = url;
    }    
}

function view_report_print (url, pars, pop_up)
{

    url = 'http://' + window.location.hostname + url + '?print&' + pars + get_ids_opened_tabs();
    if (pop_up) {
        pop_up_window(url, 1024, 600);
    }
    else {
        window.location.href = url;
    }    
}

// Do rating
function r(rating,content_id)
{
    if ( !window.rated ) {
        //get_el('rating_'+content_id).innerHTML = 'Loading...';
        window.rated = 1;
        do_ajax('rate_content',rating+','+content_id);
    }

}

function new_r(id, rating) {
//    alert(orig_rating[id]);
    if (id && rating) {
        orig_rating[id] = rating;
    }
}

// Rating result
function r_result(id,str)
{
    $(id).text(str);
}

// Rating highlight
function r_h(content_id,star, half_stars)
{
    // This caches the original rating before rollover change
    if ( typeof orig_rating[content_id] == 'undefined' )
    {
        orig_rating[content_id] = get_el('rating_'+content_id).innerHTML;
    }

    //var desc = new Array ('rubbish','not great','ok','good','excellent');
    //get_el('rating_txt_'+content_id).innerHTML = "It's "+desc[star-1]+':';
    if (half_stars) {
        if ( typeof(window.rated) == 'undefined' ) {
            for ( var j=1; j <= 10 ; j++ ) {
                i = j/2;
                part = j%2 == 1 ? '_l' : '_r';
                get_el('img_'+content_id+'_'+i).src = template_root+'/i/icons/star_'+(i<=star?'red':'grey') + part + '.gif';
            }
        }
    }
    else {
        for ( var i=1; i <= 5 ; i ++ ) {
            get_el('img_'+content_id+'_'+i).src = template_root+'/gfx/star_'+(i<=star?'red':'grey')+'.gif';
        }
    }
}

// Rating reset
function r_r(content_id)
{
    //get_el('rating_txt_'+content_id).innerHTML = 'Rating:';
//    get_el('rating_'+content_id).innerHTML = orig_rating[content_id];
}

function roll_variant(current, all) {
    for (var i = 1; i <= all; i++){
        n = 'content_variant_' + i;
        b = 'button_variant_' + i;
        var item = document.getElementById(n);      
        var btn = document.getElementById(b);       
        if( i!=current ) {        
            item.style.display = 'none';
            btn.className = 'hover';
        }
        else {
            item.style.display = 'block';
            btn.className = 'active';
        }
    }
}

function show_message(message, type) {
    if (message) {
        type = type == 'error' ? type : 'notify';

        if ($('#error_holder #'+type).length == 0) {
            $('#head').append($('<div id="error_holder"><div id="' + type + '">' + message + '</div><div id="' + type + '_bg">&nbsp;</div>&nbsp;</div>'));
        }

        $('#' + type + '_bg').fadeOut(3000,function(){});

        setTimeout('$("#error_holder").slideUp(300, function(){$("#error_holder").remove();})',2100);
    }
}


function add_to_shopping_cart(data)
{
    $.post('/shopping_cart/add', data,
        function( response ){
            response = process_response( response );
            get_quantity_of_shoping_cart()
            if ( confirm(response) ) {
                window.location = '/shopping_cart';
            }
        }
    );
}


function delete_from_shopping_cart( items )
{
    $.post('/shopping_cart/delete', { 'del[]' : items },
        function( response ){
            process_response( response );
            get_quantity_of_shoping_cart()
        }
    );
}


function get_quantity_of_shoping_cart()
{
    $.post('/shopping_cart/quantity', {}, function (response) {
        $('#shopping_cart').eq(0).html('<a href="/shopping_cart">View Cart('+response+')</a><span class="nbsp"></span>');
//        show_message('Items in shoping cart: ' + response);
    } );
}


function process_response(response)
{
    if (response.substring(0, 6) == 'Error:') {
//        show_message(response.substring(6), 'error');
        return response.substring(6);
    }
    if (response.substring(0, 7) == 'Notify:') {
        show_message(response.substring(7), 'notify');
        return response.substring(7);
    }
    return false;
}


function number_format(val, decimal) {
   decimal   = Math.abs(decimal || 0);
   var decim = Math.pow(10, decimal);
   val = (Math.round(val * decim) + 0.1) / decim;
   val = '' + (Math.round(val * decim * 10)) / (decim * 10);
   val = val.substring(0, val.length - (decimal == 0 ? 2 : 1));

   decimal += (decimal != 0);
   var length  = Math.floor((val.length - 1 - decimal) / 3);
   var l1 = val.length - decimal;
   for (i = 0; i < length; i++) {
       val = val.substr(0, (l1+i)-3*(i+1)-i)+','+val.substr((l1+i)-3*(i+1)-i, 100);
   }
   return val;
}

// Home page pluses
function switch_block(main_block, block)
{
    div         = $(main_block + ' ' + block + 'Header div');
    div_content = $(main_block + ' ' + block + 'Content');
    div_jumper  = $(main_block + ' .jumper');

    if ( div.hasClass("opened") ) {
        div.removeClass("opened");
        div.addClass("closed");
        div_content.slideUp(500);
        div_jumper.slideDown(350);
    }
    else {
        div.removeClass("closed");
        div.addClass("opened");
        div_content.slideDown(500);
        div_jumper.slideUp(350);
    }
}


function favourite_item(link, item_id, type)
{

    link = $(link);
    if ( link.hasClass("noFavourite") ) {
        $.get( '/my_favourites/add',
                { 'type' : type,
                  'item_id' : item_id
                },
                function( response ){
                    process_response( response );
                }
         );
        link.removeClass("noFavourite");
        link.addClass("isFavourite");
    }
    else {
        window.location.href = '/my_favourites';
    }
}


function browseByCategory(control)
{
    var value = control.options[control.selectedIndex].value;
    if (value == 'ask') {
        $('#browseByCategory').html(askList);
    } else if (value == 'opinions') {
        $('#browseByCategory').html(opinionsList);
    }    
}


/* switch option */
function open_checker(name_1, name_2){
    $('#' + name_1 + 'Page').hide();
    $('#' + name_2 + 'Page').show(1000);
}

/* select all checkBoxes */
function select_all(self){
    $('input.checkin').attr({checked: ($(self).attr('checked') ? 'checked' : '')});
}


var waiting_for_server = 0;
/* load html and showing with slide */
function ajax_links(links_area, target_area) {
    $(links_area + ' a').click( function () {
        return load_to_area(this.href, target_area);
    });
}


function load_to_area(href, target_area) {
    if (waiting_for_server) {
        return false;
    }
    waiting_for_server = 1;
    $.get( href, { 'ajax_html' : 'true', 'rnd' : Math.random() },
        function(responseText, textStatus) {
            waiting_for_server = 0;
            if (textStatus == 'success') {
                if ( $.browser.msie && ($.browser.version == '6.0' || $.browser.version == '7.0') ) {
                    $(target_area).children().eq(0).replaceWith(responseText);
                }
                else {
                    $(target_area).eq(0).hide(100, 
                        function() { 
                            $(this).children().eq(0).replaceWith(responseText);
                            $(this).show(700);
                        }
                    );
                }
            }
            else {
                alert('Undefined error!');
            }
        }
    );
    return false;
}


function clearShareWebcastWnd()
{
    $('.error').html('');
    $('dd > input.text').val('');
    $('dd > textarea').val('');
}


function addToPeopleList( html, additionalFunction ) {
    additionalFunction = additionalFunction ? additionalFunction : 'check_input(\'invited_persons\');';
    if ( html ) {
        html = '<div class="invitedPeopleBlock">' + html + '<span class="cross" onClick="$(this.parentNode).remove();' + additionalFunction +'">&nbsp;</span></div>';
        $("#invitedPeople").eq(0).append( html );
        return true;
    }
    return false;
}


function getHiddenInput( value, id, input_name ) {
    input_name = input_name ? input_name : 'user_ids';
    if (value) {
        value = 'value="' + value + '"';
    }
    if (id) {
        id = 'id="' + id + '"';
    }
    return '<input type="hidden" name="' + input_name + '[]" ' + id + ' ' + value + '>';
}


function delete_participant( user_id, connection_id ) {
    $.get( '/connections/delete_participant', { 'user_id' : user_id, 'connection_id' : connection_id } );
    return true;
}


/* navigation menu */
function navi_block(outward_block){
    list = $(outward_block);
    sub_menu = $(outward_block + ' ul');

    if ( 
        list.hasClass("closedPoint") ) {
        list.removeClass("closedPoint");
        list.addClass("openedPoint");
        sub_menu.slideDown(400);
    }
    else {
        list.removeClass("openedPoint");
        list.addClass("closedPoint");
        sub_menu.slideUp(400);
    }
}


/* marketing pages appearing */
function market_appear(number){
    if ($('#marketShow'+ number)[0].style.display == 'none') { 
        $(".marketingMenu li").removeClass("current");
        $(".appearList .appearListDiv").fadeOut(200);
        $('#marketingLink_'+ number).parent().addClass("current");
        $('#marketShow'+ number).fadeIn(400);
    }
}

function ucfirst( str ) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}

//-->
