function updateJSON( request, json )
{
    var nbElementsInResponse = json.length;
    for (var i = 0; i < nbElementsInResponse; i++) {
        Element.update( json[i][0], json[i][1] );
    }
} // updateJSON

function updateValuesJSON( json )
{	
	Object.keys( json ).each( function ( key ) {		
		if ( $( key ) ) {
			$( key ).value = json[key];		
		}	
	} );
} // updateValuesJSON


function autoFillPrice( field, count_with_vat, vat_src )
{
    var vat_value = parseFloat( $( vat_src ).value );
    vat_value = isNaN( vat_value ) ? 0 : vat_value;
    var src_suffix = count_with_vat ? 'netto' : 'brutto';
    var target_suffix = count_with_vat ? 'brutto' : 'netto';
    var src_field = $( field + '_' + src_suffix );
    var price_value = parseFloat( src_field.value );
    price_value = isNaN( price_value ) ? 0 : price_value;

    if ( count_with_vat ) {
        var result = Math.round( ( price_value * ( ( vat_value + 100 ) / 100 ) ) * 100 ) / 100;
    } else {
        var result = Math.round( (price_value / ( ( vat_value + 100 ) / 100 ) ) * 100 ) / 100;
    } // endif

    var target_field = $( field + '_' + target_suffix );
    target_field.value = result;
} // autoFillPrice


function autoFillPriceValue( field, count_with_vat, f_value )
{
	var f_value = parseFloat( f_value );
    f_value = isNaN( f_value ) ? 0 : f_value;
    var src_suffix = count_with_vat ? 'netto' : 'brutto';
    var target_suffix = count_with_vat ? 'brutto' : 'netto';
    var src_field = $( field + '_' + src_suffix );
    var price_value = parseFloat( src_field.value );
    price_value = isNaN( price_value ) ? 0 : price_value;

    if ( count_with_vat ) {
        var result = Math.round( ( price_value * ( ( f_value + 100 ) / 100 ) ) * 100 ) / 100;
    } else {
        var result = Math.round( (price_value / ( ( f_value + 100 ) / 100 ) ) * 100 ) / 100;
    } // endif

    var target_field = $( field + '_' + target_suffix );
    target_field.value = result;
} // autoFillPriceValue


function autoFillPricesAfterVatChange()
{
    autoFillPrice( "standard_price", true, "product_vat" );
    autoFillPrice( "discount_price", true, "product_vat" );
} // autoFillPricesAfterVatChange


function colorTableRows( table_id )
{
    var arrRows = $$( '#'+table_id+' tr' );
        var intJ = 0;
        for ( var intI = 0; intI < arrRows.length; intI++ ) {
            if ( arrRows[ intI ].visible() ) {
                arrRows[ intI ].className = ( intJ % 2 == 0 ) ? 'odd' : 'even';
                intJ++;
            }
        }
} // colorTableRows

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}



