function jamp() {

    this.settings = {
        ajaxPath: 'ajax/',
        errorColor: '#DB6400',
        successColor: '#006633',
        defaultColor: '#191919',
        success: function() {

        }
    };

    this.merkzettel = function( exporterID ){
        if( exporterID!='' || exporterID!=undefined ){
            $.ajax({
                url: 'ajax/merkzettel.php',
                data: 'action=add&exporterID='+exporterID,
                type: 'post',
                dataType: 'json',
                success: function( json ){
                    if( json.error!=null ){
                        var elementArray = [];
                        elementArray[0] = { name: 'error',value: json.error };
                        jamp.message( elementArray );
                    } else {
                        $('#listeMerkzettel').html( json.merkzettel );
                    }
                }
            });
        }
    };

    this.deleteMerkzettel = function( exporterID ){
        if( exporterID!='' || exporterID!=undefined ){

            $.ajax({
                url: 'ajax/merkzettel.php',
                data: 'action=delete&exporterID='+exporterID,
                type: 'post',
                dataType: 'json',
                success: function( json ){
                    if( json.error!='' && json.error!=undefined ){
                        var elementArray = [];
                        elementArray[0] = { name: 'error',value: json.error };
                        jamp.message( elementArray );
                    } else {
                        if( json.merkzettel==null ){
                            $('#listeMerkzettel').html( '' );
                        } else {
                            $('#listeMerkzettel').html( json.merkzettel );
                        }
                    }
                }
            });
        }
    };

    this.message = function( elementArray ){
        var self = {
            settings: {
                error: {
                    container: {
                        id: 'popupformcontainer',
                        opacity: 0.8,
                        link:{
                            title: 'ok'
                        },
                        button:{
                            title: 'ok'
                        }
                    }
                },
                overlay:{
                    zIndex: 1000,
                    background: '#ffffff',
                    opacity: 0.8
                }
            }
        }

        var messageArray = new Array();
        messageArray.length = 0;

        if( elementArray.length>0 ){
            for( i in elementArray ){
                if( elementArray[i]!=null ){
                    var element = elementArray[i];

                    messageArray.push( { name: element.name, value: element.value } );
                }

            }
        }

        if( messageArray.length>0 ){
            var overlay = '<div id="page-overlay"></div>';
            var list = '';
            var error = '';

            list = '<ul>'
            for( i in messageArray ) {
                list += '<li>'+messageArray[i].value+'</li>';
            }
            list += '</ul>';

            error += '<div id="'+self.settings.error.container.id+'" class="'+self.settings.error.container.id+'">';
                error += '<div class="popupform">';
                    error += '<div class="list2"></div>';
                    error += '<div align="right"><a class="popupformcontainerlink" onfocus="this.blur();" href="javascript: void(0);" onclick="$(\'#'+self.settings.error.container.id+'\').fadeOut(\'slow\',function() { $(this).remove(); $(\'#page-overlay\').remove(); });" title="'+self.settings.error.container.button.title+'">';

                    error += self.settings.error.container.link.title;
                    
                    error += '</a></div>';
                error += '</div>';
            error += '</div>';

            /* add html to dom */
            $( 'body' ).append( overlay+error );

            /* layout #page-overlay */
            $( '#page-overlay' ).css({
                position: 'absolute',
                top: 0,
                left: 0,
                width: $( document ).width()+'px',
                height: $( document ).height()+'px',
                opacity: self.settings.overlay.opacity,
                background: self.settings.overlay.background,
                zIndex: self.settings.overlay.zIndex
            });

            $( '#'+self.settings.error.container.id+' .popupform .list2' ).append( list );

            $( '#'+self.settings.error.container.id ).css({
                position: 'absolute',
                top: ( ( $( window ).height()/2 )+( $( window ).scrollTop() )-( $( '#'+self.settings.error.container.id ).height()/2 ) ),
                left: ( $( document ).width()/2 )-( $( '#'+self.settings.error.container.id ).width()/2 ),
                opacity: self.settings.error.container.opacity,
                zIndex: self.settings.overlay.zIndex+100
            }).fadeIn('slow');

            $( window ).scroll(function() {
                $( '#'+self.settings.error.container.id ).css({ top : ( ( $( window ).height()/2 )+( $( window ).scrollTop() )-( $( '#'+self.settings.error.container.id ).height()/2 ) ) });
            });
        }
    };

    this.isValidEmail = function( field ){
        var str = $( field ).val();
        var filter = /^.+@.+\..{2,3}$/;

        if( filter.test( str ) ) {
            return true;
        } else {
            return false;
        }
    };

   this.flur = function( j, text ) {
        if($(j).length>0) {
            this.searchText = text;

            $(j).val(text);

            $(j).focus(function() {
                if($(j).val()==text) {
                    $(j).val('');
                }
            });

            $(j).blur(function() {
                if($(j).val()=='') {
                    $(j).val(text);
                }
            });
        }
    };

    this.search = function( j, jInput ) {
        if($(j).length>0) {
            $(j+' input').each(function() {
                if($(this).attr('type')=='button') {
                    $(this).click(function() {
                        if($(jInput).val()!='' && $(jInput).val()!=self.searchText) {
                            $(j).submit();
                        }
                    });
                }
            });
        }
    };

    this.toggleSlide = function( self, idElement ) {
        if( $( self ).css('display')=='none' ){
            $( self ).stop(true, true).slideDown('fast');
        } else {
            $( self).stop(true, true).slideUp('fast');
        }

        if( $( idElement ).css('display')=='none' ){
            $( idElement ).stop(true, true).slideDown('fast');
        } else {
            $( idElement ).stop(true, true).slideUp('fast');
        }
    };

    /*
     *  Formartiert einen Preis, in dem . durch , ersetzt wird.
     *  Ebenso wird der Preis anhand von precision aufgerundet.
     *  Ist precision nicht angegeben, wird er automatisch auf 2 gesetzt.
     */
    this.formatPrice = function(wert,precision) {
        var x,x1,x2;

        if(precision==undefined) {
            precision = 2;
        }

        wert = (wert.toFixed) ? wert.toFixed(precision) : Math.floor(wert)+"."+(100+Math.round((wert-Math.floor(wert))*100)+"").substr(1,2);

        nStr = wert;

        nStr += '';
        x = nStr.split('.');
        x1 = x[0];
        x2 = x.length >= 1 ? ',' + x[1] : '';

        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
            x1 = x1.replace(rgx, '$1' + '.' + '$2');
        }

        return x1 + x2;

    };

    /* returns actual page size as an array [width|height] */
    this.getPageSize = function() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
        var windowWidth, windowHeight;
        if (self.innerHeight) {	// all except Explorer
            if(document.documentElement.clientWidth){
                windowWidth = document.documentElement.clientWidth;
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        // for small pages with total height less then height of the viewport
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }
        // for small pages with total width less then width of the viewport
        if(xScroll < windowWidth){
            pageWidth = xScroll;
        } else {
            pageWidth = windowWidth;
        }
        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
        return arrayPageSize;
    };
}

var jamp = new jamp();

