/// ok - first some stuff to make IE behave like a decent browser


if( !Array.indexOf )
{
    Array.prototype.indexOf= function( needle )
        {
            for( var itr= 0; itr < this.length; itr++ )
                if( this[ itr ] == needle )
                    return itr;
            
            return -1;
        }
}




// aaaaaaaaaaand a very important piece of code ;)
// it checks if the Firefox console object is defined
// and if not, it defines it with empty methods, in order to avoid bugs

if( !window.console )
{
    function Console()
    {
        this.log= function(){};
        this.debug= function(){};
        this.info= function(){};
        this.warn= function(){};
        this.error= function(){};
        this.assert= function(){};
        this.dir= function(){};
        this.dirxml= function(){};
        this.trace= function(){};
        this.group= function(){};
        this.groupEnd= function(){};
        this.time= function(){};
        this.timeEnd= function(){};
        this.profile= function(){};
        this.count= function(){};
        return this;
    }
    var console= new Console();
}




// now standard functions


function appendElementAfter( parent_node, preceeding_element, inserted_node )
{
    if( preceeding_element.nextSibling )
    {
        parent_node.insertBefore( inserted_node, preceeding_element.nextSibling )
        
    }
    else
        parent_node.appendChild( inserted_node );
    
}


function setOpacity( element, opacity )
    {
    element.style.opacity= opacity;
    element.style.filter= 'alpha(opacity='+( opacity*100 )+')';
    
    }
    
    
function getElementAbsolutePosition( obj )
    {
    var curleft= 0;
    var curtop = 0;
    
    if( obj.offsetParent )
        {
        do
            {
            curleft+= obj.offsetLeft;
            curtop+= obj.offsetTop;
            }
        while( obj = obj.offsetParent );
        }
    return [ curleft, curtop ];
    }


function getScreenDimensions()
    {
    var window_width;
    var window_height;
    
    if( window.innerHeight )
        {
        window_width= window.innerWidth;
        window_height= window.innerHeight;
        }
    else
        {
        if( document.documentElement.clientHeight && 
            ( document.documentElement.clientHeight > 0 ) )
            {
            window_height= document.documentElement.clientHeight;
            window_width= document.documentElement.clientWidth;
            }
        else
            {
            window_height= document.body.clientHeight; 
            window_width= document.body.clientWidth;
            }
        }
    return [ window_width, window_height ];
    }
    
    
function getScrollValues()
    {
    var window_scroll_x;
    var window_scroll_y;
    
    if( window.pageYOffset )
        {
        window_scroll_x= window.pageXOffset;
        window_scroll_y= window.pageYOffset;
        }
    else if( document.body.scrollTop )
        {
        window_scroll_y= document.body.scrollTop;
        window_scroll_x= document.body.scrollLeft;
        }
    else if( document.documentElement.scrollTop )
        {
        window_scroll_x= document.documentElement.scrollLeft; 
        window_scroll_y= document.documentElement.scrollTop;
        }
    else
        {
        window_scroll_x= 0;
        window_scroll_y= 0;
        }
    
    return [ window_scroll_x, window_scroll_y ];
    }


function getEventTarget( event )
    {
    if( !event )
        var event = window.event;
    
    var event_target;
    
    if( event.target)
        event_target = event.target;
    else if( event.srcElement )
        event_target= event.srcElement;
    
    if( event_target.nodeType && ( event_target.nodeType == 3 ) )
        event_target = event_target.parentNode;
    return event_target;
    }
    
    
function getPressedKey( event )
    {
    var key;
    
    if( window.event )
        key= window.event.keyCode;
    else if( event.which )
        key= event.which;
    return String.fromCharCode( key );
    }
    
    
function runOnScroll( element, function_to_run )
    {

    if( element.addEventListener )
        {           
        element.addEventListener( 'DOMMouseScroll', function_to_run, false ); 
        element.addEventListener( 'mousewheel', function_to_run, false ); 
        }
    else if( element.attachEvent )
        element.attachEvent( 'onmousewheel', function_to_run );

    }
    
    
function runOnLoad( function_to_run )
    {
    if( document.addEventListener )
        {
        document.addEventListener( "DOMContentLoaded", function_to_run, false);
        document.addEventListener( "load", function_to_run, false );
        }
    else if( window.addEventListener )
        {
        window.addEventListener( "load", function_to_run, false );
        }
    else if( window.attachEvent )
        {
        window.attachEvent( "onload", function_to_run );
        }
    }
    
    
function addPortableEventListener( element, event, listener, capture )
    {
    var capture= ( capture == null )?false:capture;
    
    if( ( element ) && ( element.addEventListener ) )
        {
        element.addEventListener( event, listener, capture );
        }
    else
        {
        element.attachEvent( 'on'+event, listener );
        }
    }
    
    
function removePortableEventListener( element, event, listener, capture )
    {
    var capture= ( capture == null )?false:capture;
    
    if( ( element ) && ( element.removeEventListener ) )
        {
        element.removeEventListener( event, listener, capture );
        }
    else
        {
        element.detachEvent( 'on'+event, listener );
        }
    }
    
    
    
function setCookieValue( cookie_name, cookie_value, minutes )
{
    var expiration_date;
    
    var minutes= ( minutes == null )?0:minutes;
    
    
    if( minutes != 0 )
    {
        var date= new Date();
        date.setTime( date.getTime()+( minutes*60*1000 ) );
        expiration_date= "; expires="+date.toGMTString();
    }
    else 
        expiration_date= "";
    
    document.cookie= cookie_name+"="+cookie_value+expiration_date+"; path=/";
}
    
    
    
function getCookieValue( cookie_name )
{
    cookie_array= document.cookie.split( '; ' );
    cookie_count= cookie_array.length;
    
    for( var itr=0; itr < cookie_count; itr++ )
    {
    if( cookie_array[ itr ].indexOf( cookie_name+"=" ) == 0 )
        return cookie_array[ itr ].substring( cookie_name.length+1 );
    }
    return null;
}



function unsetCookie( cookie_name ) 
{
    setCookieValue( cookie_name, "", -1 )
}


function stopEventPropagation( event )
{
    if( !event )
        var event = window.event;
    
    try
    {
        event.stopPropagation();
    }
    catch( exploder )
    {
        event.cancelBubble="true";
    }
}




function cancelEvent( event )
{
    if( !event )
        var event = window.event;
    
    
    try
    {
        event.preventDefault();
    }
    catch( exploder )
    {
//         alert( "test" );
//         event.returnValue="false";
    }
}




function removeAllChildNodes( node )
{
    if( node.hasChildNodes() )
        for( itr= node.childNodes.length-1; itr >=0; itr-- )
            node.removeChild( node.childNodes[ itr ] );
}


function showToolTip( id )
{
	document.getElementById( id ).style.display = 'block';
}

function hideToolTip( id )
{
	document.getElementById( id ).style.display = 'none';
}





