function show_loading()
{
        var l_div = document.getElementById( 'loading_div' );
        l_div.style.left = 10 + 'px';
        l_div.style.top  = 10 + 'px';
        l_div.style.display = '';
}
function hide_loading()
{
        var l_div = document.getElementById( 'loading_div' );
        l_div.style.display = 'none';
}

function ajax_delete_keyword( keyword_id )
{
        sajax_do_call('ajax_keyword_delete',[keyword_id,ajax_delete_callback]);
        document.getElementById('keyword_row_' + keyword_id).className='deleted_row';
        return false;
}

function ajax_delete_callback( res )
{
        //Do nothing
}


function ajax_add_keyword( url_id, keyword_value )
{
        sajax_do_call('ajax_keyword_add',[url_id,document.getElementById(keyword_value).value,ajax_add_callback]);
        return false;
}

function ajax_list_inlinks( account_id, entire )
{
        show_loading();
        sajax_do_call('ajax_list_inlinks',[account_id,entire,inlinks_callback]);
        return false;
}

function inlinks_callback( res )
{
        hide_loading();

        //var cont = document.createElement( 'div' );
        var cont   = document.getElementById( 'res_cont' );
        cont.style.display  = '';
        cont.style.position = 'absolute';
        cont.style.left     = '20px';
        cont.style.top      = '20px';

        var box     = document.getElementById( 'res_box' );
        var _title   = document.getElementById( 'lightbox_title' );
        if( res[2] )
        {
                _title.innerHTML = 'Yahoo In-links to account URL';
        }
        else
        {
                _title.innerHTML = 'Yahoo In-links to selected result page';
        }
        box.innerHTML = '';
        //cont.className = 'lightbox';

        for( i in res[1] )
        {
                box.innerHTML += res[1][i][0] + '<br />';
        }
}

function ajax_list_insite( account_id, keyword_id )
{
        show_loading();
        sajax_do_call('ajax_list_insite',[account_id,keyword_id,insite_callback]);
        return false;
}

function insite_callback( res )
{
        hide_loading();

        //var cont = document.createElement( 'div' );
        var cont   = document.getElementById( 'res_cont' );
        cont.style.display  = '';
        cont.style.position = 'absolute';
        cont.style.left     = '20px';
        cont.style.top      = '20px';

        var box   = document.getElementById( 'res_box' );
        var _title   = document.getElementById( 'lightbox_title' );
        _title.innerHTML = 'Search results for keyword on this site';

        box.innerHTML = '';
        //cont.className = 'lightbox';

        for( i in res )
        {
                box.innerHTML += res[i][0] + '<br />';
        }
}

function ajax_list_keyword_search( keyword_id )
{
        show_loading();
        sajax_do_call('ajax_list_keyword_search',[keyword_id,keyword_search_callback]);
        return false;
}

function keyword_search_callback( res )
{
        hide_loading();

        //var cont = document.createElement( 'div' );
        var cont   = document.getElementById( 'res_cont' );
        cont.style.display  = '';
        cont.style.position = 'absolute';
        cont.style.left     = '20px';
        cont.style.top      = '20px';

        var box   = document.getElementById( 'res_box' );
        _title.innerHTML = 'Search results for keyword across the web';

        box.innerHTML = '';
        //cont.className = 'lightbox';

        for( i in res )
        {
                box.innerHTML += res[i][0] + '<br />';
        }
}

function ajax_add_callback( res )
{
        hide_loading();

        if( res != 0 )
        {
                var tbl = document.getElementById( 'keyword_overview_table' );
                var row = document.createElement('tr');
                row.className = 'new_keyword';

                    var c1ol = document.createElement('td');
                    var c2ol = document.createElement('td');
                    var c3ol = document.createElement('td');
                        c3ol.colSpan = 8;

                    var a_link = document.createElement('a');
                        a_link.href  = '?act=detailed_keyword&keyword=' + res;
                        a_link.value = res;
                    var textel = document.createTextNode( res );

                a_link.appendChild( textel );

                c2ol.appendChild( a_link );
                row.appendChild( c1ol );
                row.appendChild( c2ol );
                row.appendChild( c3ol );
                tbl.appendChild( row );
                //alert( res );
        }
        else
        {
                alert( 'Keyword could not be added.' );
        }

}


function toggle( elem )
{
        el_id = document.getElementById( elem );
        if( el_id.style.display == 'none' )
        {
                el_id.style.display = '';
        }
        else
        {
                el_id.style.display = 'none';
        }
}

/*

function mouseX(evt) { // Returns the X position of the mouse on the entire document
if (!evt){ var evt = window.event; }
if (evt.clientX){
        alert( '1' );
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
   }
else if(evt.pageX){ alert('2'); return evt.pageX; }
else{ alert('3'); return null; }
}
function mouseY(evt) { // Returns the Y position of the mouse on the entire document
if (!evt) var evt = window.event;
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}
function mouseXview(evt) { // Returns the X position of the mouse on the viewport
if (evt.pageX) return evt.pageX - (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else if (evt.clientX)
   return evt.clientX;
else return null;
}
function mouseYview(evt) { // Returns the Y position of the mouse on the viewport
if (evt.pageY) return evt.pageY - (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else if (evt.clientY)
   return evt.clientY;
else return null;
}

function show_at_mouse( elem_id, new_class )
{
        elem = document.getElementById( elem_id );
        elem.style.display = '';
        elem.className = new_class;
        elem.style.left = mouseX();
        elem.style.top = mouseY();
}

*/

function show_center( elem_id, new_class )
{
        elem = document.getElementById( elem_id );
        elem.style.display = '';
        elem.className = new_class;
        elem.style.left = (window.innerHeight/2) + 'px';
        elem.style.top = '150px';
}


