function makeRequest( url, targetElementId )
{
    var http_request = false;

    if ( window.XMLHttpRequest )
    { // Mozilla, Safari, ...
        http_request = new XMLHttpRequest( );
        if ( http_request.overrideMimeType )
        {
            // http_request.ocompleted_dateverrideMimeType( 'text/xml' );
            http_request.overrideMimeType( 'text/html' );
        }
    }
    else if ( window.ActiveXObject )
    { // IE
        try
        {
            http_request = new ActiveXObject( "Msxml2.XMLHTTP" );
        }
        catch ( e )
        {
            try
            {
                http_request = new ActiveXObject( "Microsoft.XMLHTTP" );
            }
            catch ( e ) {}
        }
    }

    if ( !http_request )
    {
        alert( "Cannot create an XMLHTTP instance" );
        return false;
    }

    return http_request;
}

function hide_element( id )
{
    if (document.getElementById) { // DOM3 = IE5, NS6
            document.getElementById(id).style.display = 'none';
    }
    else {
            if (document.layers) { // Netscape 4
                    document.id.display = 'none';
            }
            else { // IE 4
                    document.all.id.style.display = 'none';
            }
    }
}

function show_element( id )
{
    if (document.getElementById) { // DOM3 = IE5, NS6
            document.getElementById(id).style.display = '';
    }
    else {
            if (document.layers) { // Netscape 4
                    document.id.display = '';
            }
            else { // IE 4
                    document.all.id.style.display = '';
            }
    }
}

function toggle_element( id )
{
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(id).style.display == '')
        {
            hide_element(id);
        }
        else
        {
            show_element(id);
        }
    }
    else {
        if (document.layers) { // Netscape 4
            if (document.id.display == '')
            {
                hide_element(id);
            }
            else
            {
                show_element(id);
            }
        }
        else { // IE 4
            if (document.all.id.style.display == '')
            {
                hide_element(id);
            }
            else
            {
                show_element(id);
            }
        }
    }
}

function number2money(n_value) {
    //
    // Original version from: http://www.softcomplex.com/forum/viewthread_2775/
    //

    // validate input
    if ( isNaN( Number(n_value) ) )
    {
        return 'ERROR';
    }

    // save the sign
    var b_negative = Boolean(n_value < 0);
    n_value = Math.abs(n_value);

    // round to 1/100 precision, add ending zeroes if needed
    var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);

    // separate all orders
    var b_first = true;
    var s_subresult;
    while ( n_value > 1 )
    {
        s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
        s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
        b_first = false;
        n_value = n_value/1e3;
    }

    // add at least one integer digit
    if ( b_first )
    {
        s_result = '0.' + s_result;
    }

    // apply formatting and return
    return b_negative ? -s_result : s_result;
}

String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
        return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
        return this.replace(/\s+$/,"");
}

function date_is_valid( date ) // accepted date format: YYYY-MM-DD
{
    if ( date.trim() == "" )
    {
        return false;
    }

    var D = date.split( "-" );

    var month_days = new Array();
    month_days[1] = 31;
    month_days[2] = D[0] % 4 == 0 ? 29 : 28;
    month_days[3] = 31;
    month_days[4] = 30;
    month_days[5] = 31;
    month_days[6] = 30;
    month_days[7] = 31;
    month_days[8] = 31;
    month_days[9] = 30;
    month_days[10] = 31;
    month_days[11] = 30;
    month_days[12] = 31;

    // Check the month
    D[1] = Number( D[1] );
    if ( D[1] < 1 || D[1] > 12 )
    {
        return false;
    }

    // Check the day of month
    D[2] = Number( D[2] );
    if ( D[2] < 1 || D[2] > month_days[ D[1] ] )
    {
        return false;
    }

    return true;
}

function parse_xml( xml_text )
{
    if ( window.ActiveXObject ) // code for IE
    {
        var doc = new ActiveXObject( "Microsoft.XMLDOM" );
        doc.async = "false";
        doc.loadXML( xml_text );
    }
    else // code for Mozilla, Firefox, Opera, etc.
    {
        var parser = new DOMParser();
        var doc = parser.parseFromString( xml_text,"text/xml" );
    }

    return doc;
}

function parse_date_str( date_str )
{
    var D = date_str.split( "-" );
    return new Date( D[0], D[1] - 1, D[2] );

}

function number_only_field( event )
{
    var key_code;
    var key_char;

    if ( window.event )
    {
        key_code = window.event.keyCode;
    }
    else if ( event )
    {
        key_code = event.which;
    }
    else
    {
        return false; // return true; ??
    }

    key_char = String.fromCharCode( key_code );

    //
    // Handle the control keys
    //
    if ( key_code == null ||
            key_code == 0 ||
            key_code == 8 ||
            key_code == 9 ||
            key_code == 13 ||
            key_code == 27 )
    {
        return true;
    }

    //
    // Now check if an allowed char has been entered
    //
    if ( "0123456789.".indexOf( key_char ) > -1 )
    {
        return true;
    }

    //
    // Any other entered char is considered as invalid.
    //
    return false;
}

 function killIt(item){  
            $(function(){  
                $('#'+item).fadeOut(1000);  
            });  
        }           
