window.addEvents({

    'domready' : function() {

        body_ = $$('body')[0];
        base_ = body_.getProperty('class').split('#');
        base_url = base_[0];
        base_style = ( base_[1] > 0 ? base_url + 'static/styles/'+base_[1]+'/' : base_url + 'static/styles/2/' );

	



	/* -- load external scripts -- */
        
        var js_load = null;
        js_load = new Asset.javascript(base_url+'static/javascript/jscript_classes.js'); 
        js_load = new Asset.javascript(base_url+'static/javascript/libs/history.class.js',{ onload: function(){ 
            base_h = new HistoryManager(); 
            if( $('map') || $$('.map_coords').length > 0 )                                  { js_load = new Asset.javascript(base_url+'static/javascript/jscript_maps.js'); }    
        } });
        if( $$('.rating').length > 0 )                                                      { js_load = new Asset.javascript(base_url+'static/javascript/libs/ratings.class.js'); }
        if( $('forum_topics') )                                                             { js_load = new Asset.javascript(base_url+'static/javascript/jscript_forum.js'); }

	/* -- hook elements -- */

		var smsc = new SmoothScroll();
        $$('a[rel=external]').setProperty( 'target' , '_blank' );                               // open link in new window (gets around validator disallowing target=_blank)
        body_.addEvent( 'click' , function() { if( $('note') ) { $('note').destroy(); } });     // note remover
        
	/* -- blackout and canvas -- */
        
        $('blackout').addEvent( 'click' , function() {
            this.addClass('hide');
            $$('.form_overlay').addClass('hide');
        });
        
	/* -- floating box search results -- */
        if($('floatdiv')){
        $('floating_boxx').addEvent( 'click' , function() {
			$('floatdiv').addClass('hide');
//            this.addClass('hide');
//            $$('.form_overlay').addClass('hide');
        });
		}
        
		
		
        
	/* -- get country code visitor via IP address -- */
/*
        if($('sqscollx')){
	
//------------------------------------------------------------------------------------------------ WELK LAND WOONT VISITOR?

<!-- <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css" type="text/css"> -->
			function getCountryCode(){
			 
			//  var info = document.getElementById('info');
			  var lat = geoip_latitude();
			  var lon = geoip_longitude();
			//  var city = geoip_city();
			  var country = geoip_country_code();
			//  info.innerHTML = country;
			  var url = 'http://maps.google.com/maps/api/staticmap?center='+
						lat+','+lon+'&sensor=false&size=300x300&maptype=roadmap&key='+
						'ABQIAAAAijZqBZcz-rowoXZC1tt9iRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQQBCa'+
						'F1R_k1GBJV5uDLhAKaTePyQ&markers=color:blue|label:I|'+lat+
						','+lon+'6&visible='+lat+','+lon+'|'+(+lat+1)+','+(+lon+1);
			  
//			alert("countryCode: "+country+"\nbase_url"+base_url);
              
                

			new Request.JSON({url:base_url+'dynamic/55_home.php?act=home&cc='+country , onComplete:function(response) {
//			alert("response: "+response);
				
			
			}.bind(this)}).post({ 'cc' : country , 'value' : country }); 


            };

			var sendCC = getCountryCode();

//------------------------------------------------------------------------------------------------ END WELK LAND WOONT VISITOR?

		}
*/
		



    /* -- hide and show rows on click (seen on pretty much every manage xxx page) -- */
    
        parentchild = function() {
            $$('.show_child').addClass( 'hide' );
            $$('.show_parent').addEvent( 'click' , function(e) {
                e.stop();
                $$('*[rel='+this.getProperty('name')+']').toggleClass('hide');
            });
        };
        
        parentchild();
 
    /* -- adverts -- */

        if( $$('.advert').length > 0 ) {
        
            var call_ads = function() {
    
                new Request.JSON({ url:base_url+'imps/adverts?c='+new Date().getTime() , onComplete:function(adverts) {
                
                    var adhash = new Hash(adverts);
                
                    $$('.advert').each( function( el , i ) {
                    
                        adhash.each(function(value, key){
                            value.each( function( ad ) { if( el.getProperty('rel') == key.replace( /ad/ , '' ) ) {
                                if( el.get('html') != ad ) { el.set('html', ad ); }
                                value.erase(ad);
                            }});
                        }); 
                        
                    });
                
                }}).get({ 'keywords' : $('keywords').getProperty('content') , 'sizes' : $$('.advert').getProperty('rel') , 'locate' : $('map') ? ( ( $('map').getProperty('rel') ? $('map').getProperty('rel') : null ) ) : null }); 
            
            };
            
            call_ads();
            call_ads.periodical(15000); // change adverts every 30 seconds
    
        }
        
    /* -- drop down navigation menus -- */
        
        var subnav_on = $$('.subnav_on');
        var subnav_a = [];
        var subnav_ul = [];
        var subnav_head = null;
            
        $$('.subnav').addEvents({
        
            'mouseenter' : function() {          
                
                subnav_head = this.getChildren('a[class^=subnav_head]')[0];
                subnav_a = this.getChildren('a[class~=subnav_head]');
                
                subnav_ul = this.getChildren('ul');
                subnav_ul.removeClass('hide');
                
                if( subnav_head ) {
                
                    if( Browser.Engine.version == 4 && Browser.Engine.trident ) {
                        subnav_ul.setStyles({ 'left': subnav_head.getCoordinates().left , 'top' : $('strip_alpha').getCoordinates().bottom , 'z-index' : 3000  });
                    } else {
                        subnav_ul.setStyles({ 'left': subnav_head.getCoordinates().left , 'top' : $('strip_alpha').getCoordinates().bottom , 'min-width' : subnav_head.getSize().x , 'z-index' : 3000  });
                    }
                }                
            },
            'mouseleave' : function() { subnav_ul.addClass('hide'); }   
            
        });

    /* -- form elements -- */

        // -- bots be gone : creates submit buttons -- //

        $$('span[class=submit]').each( function( el ) { 
            new Element( 'input' , { 'type' : 'submit' , 'name' : el.getProperty('name') , 'value' : el.get('html') } ).replaces(el);
        });
        
        // -- input[type=checkbox] -- //
        
        $$('input[type=checkbox]').each( function( el  ) {
            if( el.getParent().get('tag') == "label" ) {
                label = el.getParent();
                label.addClass( 'input_checkbox' ).cloneEvents(el);
                if( el.getProperty('checked') == true ) { label.addClass( 'checked' ); }
                label.getParent().adopt( el.addClass('hide') );
            }
        });

        $$('.input_checkbox').addEvent( 'click' , function() {
            this.toggleClass('checked');
            input = $$('input[type=checkbox]')[$$('.input_checkbox').indexOf(this)];
            trig = (input.getProperty('checked') == true ? input.setProperty('checked',false) : input.setProperty('checked',true) );
        });
        
        // -- input[type=radio] -- //

        $$('input[type=radio]').each( function( el  ) {
            if( el.getParent().get('tag') == "label" ) {
                label = el.getParent();
                label.addClass( 'input_radio' ).cloneEvents(el).setProperty('rel',el.getProperty('name'));
                if( el.getProperty('checked') == true ) { label.addClass( 'selected' ); }
                label.getParent().adopt( el.addClass('hide') );
            }
        });

        $$('.input_radio').addEvent( 'click' , function() {
            $$('.input_radio[rel='+this.getProperty('rel')+']').removeClass('selected').setProperty('checked',false);
            this.addClass('selected');
            input = $$('input[name='+this.getProperty('rel')+']')[$$('.input_radio[rel='+this.getProperty('rel')+']').indexOf(this)];
            input.setProperty('checked',true)
        });

        // -- input[type=file] delete image function -- //
        
        ssp = [];
        inp = [];
        $$('input[type=file]').each( function(el,i) {
            if( el.getProperty('rel') && el.getProperty('rel') != '' && el.getProperty('rel') != 'x' ) {
                new Element( 'a' , {'href':base_url+'imps/'+el.getProperty('class') , 'name': 'delete_file' , 'rel':el.getProperty('name')+' '+el.getProperty('rel') , 'class':'delete' , 'html':" <img src='"+base_style+"images/delete.png' style='background:#A1CAB3 ; padding:2px' title='Delete' align='absmiddle' /> " + el.getProperty('rel').replace(/x/,'') } ).inject( el , 'after' );
            }
        });
        
        // -- selectngo -- //

        $$('.selectngo').addEvent( 'change' , function() {
            location.href = this.getProperty('rel') + this.getProperty('value');
            return;           
        });

        // -- select populators -- //

        if( $('select_ch') ) {
            update_select_ch = function() {
                $$('.select_ch').addClass('hide');
                $$('div[rel=sel_'+$('select_ch').getProperty('value')+']').removeClass('hide');
            };
            $('select_ch').addEvent( 'change' , update_select_ch );
            update_select_ch();
        }
        
        // -- code editing textarea -- //

        $$('.code').addEvent( 'keydown' , function(e) {
            if( e.key == 'tab' ) {
                e.stop();
                this.insertAtCursor("    ");
                this.setCaretPosition(this.getCaretPosition()+4);
            }
        });
  
    /* -- ie6, you shall go to the ball -- */
    
        if( Browser.Engine.version == 4 && Browser.Engine.trident ) {
        
            // -- pngfix done the long way because otherwise IE cries like a girl. IDEK. -- //
            
            [$$('div[class!=left sa_center]'),$$('form'),$$('#content_alpha ul li.on'),$$('*[src$=png]'),$$('input[type=submit]'),$$('input[type=text]')].each( function( el ) { el.addClass('iefix'); } );
            DD_belatedPNG.fix('.iefix');

            // -- working around the css selectors. or lack thereof, as the case may be. -- //

            [$$('#content_beta input[type=text]'),$$('#content_beta input[type=file]'),$$('#content_beta input[type=password]'),$$('#content_delta input[type=text]'),$$('#content_delta input[type=file]'),$$('#content_delta input[type=password]')].each( function( el ) { el.addClass('text'); });
            [$$('#content_beta input[type=submit]'),$$('#content_delta input[type=submit]'),$$('#content_beta input[type=button]'),$$('#content_delta input[type=button]')].each( function( el ) { el.addClass('submit'); } );
            
        } 

	    var ot = null;
        $$('.overtext').each( function( el ) { ot = new OverText(el,{wrap:true}); } );
        
    /* -- images & videos -- */    
    
        // -- img thumbs -- //
        
        $$('.img_thumb p').addEvent( 'click' , function() {
        
            this.toggleClass('on');
            
            if( $('img_delete') ) {
            
                delete_img = [];
                $$('.img_thumb p.on').each( function( el , i ) { delete_img[i] = el.getProperty( 'alt' ); });
                
                $('img_delete').setProperty( 'value' , delete_img.join('|') );
            
            }
            
        });
        
        // -- image display -- //
        
        if( $$('.imagedisplaysm img').length > 0 ) {
            idl = $$('.imagedisplaylg img')[0];
            $$('.imagedisplaysm img').addEvent( 'click' , function() { idl.setProperty('src',this.getProperty('src').replace(/small/,'large') ); });
        }
			
        
		// deze heb ik erbij gezet zodat op detailed page de thumbs niet over de large image heen komen te staan
        if( $$('.imagedisplaysmprop img').length > 0 ) {
            idl = $$('.imagedisplaylg img')[0];
            $$('.imagedisplaysmprop img').addEvent( 'click' , function() { idl.setProperty('src',this.getProperty('src').replace(/small/,'medium') ); });
        }
        
        
        // -- video loader -- //

        if( $$('.video_player').length > 0 ) {
            var players = [];
            var player_info = [];
            $$('.video_player').each( function( el , i ) {
                player_info = el.getProperty('name').split('_');
                players[i] = new Swiff( base_url+'static/flash/player.swf' , {
                    width: 480,
                    height: 270,
                    params: {
                        wmode: 'opaque',
                        bgcolor: '#FFFFFF',
                        allowfullscreen: 'true',
                        allowscriptaccess: 'always',
                        allownetworking: 'all'
                    },
                    vars : {
                        file : isNaN( player_info[0] ) ? player_info[0] : base_url + 'static/videos/' + player_info[0] + '.flv',
                        image: player_info[1] != '' ? base_url + 'static/images/videos/stills/large/' + player_info[1] : base_url + 'static/images/videos/stills/large/blank.jpg',
                        'logo.file' : base_style + 'images/mcp_bug.png',
                        'logo.link' : base_url,
                        'logo.hide' : false,
                        'logo.position' : 'bottom-left',
                        autostart: false,
                        controlbar: 'over',
                        plugins: 'viral-2',
                        'viral.onpause' : true,
                        'viral.oncomplete' : true,
                        'viral.email_footer' : 'My Club Promotion'
                    }
                }).inject(el);
            });
            
        }
        
    /* -- load overlay form -- */
    
        $$('.load_form').addEvent( 'click' , function(e) { 
            e.stop();
            doc_size = $(document.body).getSize();
            doc_scroll_size = $(document.body).getScrollSize();
            doc_scroll = $(document.body).getScroll();
            if( this.getProperty('id') ) {
                if( $('passthru') ) { $('passthru').destroy(); }
                info = this.getProperty('id').split('_'); // type - id - name //
                if( $(info[0]) && info[2] ) $(info[0]).set( 'html' , $(info[0]).getProperty('rel') + info[2] );
                $(this.getProperty('rel')).adopt( new Element( 'input' , { 'id' : 'passthru' , 'type' : 'hidden' , 'name' : 'passthru' , 'value' : info[0]+'_'+info[1] } ) );
            }
            loading = ( this.getProperty('rel') ? $(this.getProperty('rel')) : $('global_contact_form') );
            $$('.form_overlay_close').addEvent( 'click' , function(e) {
                loading.addClass('hide');
                $('blackout').addClass('hide');
            });
            loading.setStyles({
                'top': 110 , 
                'left':(doc_size.x-413)/2 + 10
            }).removeClass('hide');
            new Fx.Scroll(window).toTop();
            $('blackout').set('opacity',0.4).setStyles({'height':doc_scroll_size.y, 'width':doc_size.x}).removeClass('hide');
        });

    /* -- table sort by headers -- */
        
        var sort_ = $$('table.sort');
              
        if( sort_.length > 0 ) {
        
            sort_.each( function( el , i ) {

                var parse = [];
                el.getChildren('thead')[0].getChildren('tr')[0].getChildren('th').each( function(elb,ib) {  // get the header parsing types
                    if( elb.get('text') != '' ) { parse[ib] = ( elb.getProperty('rel') ? elb.getProperty('rel') : 'string' );  }
                });
         
                var sort_table = new HtmlTable( el , {
                    parsers : parse,
                    classNoSort : 'nosort',
                    classZebra : (el.hasClass('zebra') ? 'light' : ''),
                    classHeadSort : 'sortasc' ,
                    classHeadSortRev: 'sortdesc' , 
                    zebra : (el.hasClass('zebra') ? true : false),
                    sortable : true,
                    sortIndex: null,
                    onSort: function() { tbl_alternate(); }
                });

            });
        
        }

    /* -- search -- */
            
        search_delay = null;
        
        // -- keyword search, found a lot in the admin areas -- //
        
        $$('.search').addEvents({

            'keyup': function() {
				var bizz;
                
                search_disp_ = ( $('search_display') ?  $('search_display') : $("search_" + this.getProperty('name').split('=')[1]) );
                
                $clear( search_delay );
                
                search_delay = ( function() {
//					alert('value :'+ this.getProperty('value') );   
                    
                    new Request.JSON({url: base_url+"imps/"+this.getProperty('name'), onComplete: function(response){ if( response ) {

/*                    
//-------------------------------------------------------------------																														 
					// (voor business-member-linking: haal de waarde business id op, gefilterd uit de http://) - stuur meer met POST() hier onderaan
                    cat = location.href.split(/[\s/]+/);																									 
					catL = cat.length;																									 
					alert('cat :'+ location.href.split(/[\s/]+/)[location.href.split(/[\s/]+/).length-1] );   
                    bizz = cat[catL-1];
//-------------------------------------------------------------------		
*/
                        if( response.display ) {
                            search_disp_.set( 'html' , response.display ) ; 
                            $$('.delete').addEvent( 'click' , delete_item );
							//HIER KOMT DE ANDERE CODE VOOR LINKING BUSINESS - MEMBER ??
                            $$('.connect_link').addEvent( 'click' , connectBusinessMemberPlus );
                            tbl_alternate();
                        } else { search_disp_.set( 'html' , 'No results found! Please try again.' ); }
//                    }}}).post({ 'act' : 'search' , 'value' : this.getProperty('value') , 'ref' : location.href , 'cat' : location.href.split(/[\s/]+/)[location.href.split(/[\s/]+/).length-1] });
                    }}}).post({ 'act' : 'search' , 'value' : this.getProperty('value') , 'ref' : location.href , 'bizz' : $$('.search').getProperty('rel')[0] });
                        
                }.bind(this)).delay( 1000 );

            },
                
            'keydown': function() { $clear( search_delay ); }
            
        });
            
        // -- keyword suggestions, found on the full searchbox -- //     
            
        onlist = 0;
            
        dropsearch = function() { $$('.dropsearch').addEvents({
            'keyup': function() {
                
                if( onlist === 0 ) {
                
                    coords = this.getCoordinates();
                    size = this.getSize();
                    search_delay = $clear( search_delay );
                    
                    if( this.getProperty('value').trim().length > 1 ) {
   
                        search_delay = ( function() {
                            
                            new Request.JSON({url: base_url+"imps/85_search?fetch="+this.getProperty('rel'), onComplete: function(response){ if( response ) {
                            
                                if( response.search ) {
                                    $('searchsuggest').setStyles({'top':coords.bottom + 5, 'left':coords.left , 'width':size.x + 100 });
                                    $('searchsuggest').empty().removeClass('hide');
                                    response.search.each( function( el ) { $('searchsuggest').adopt( new Element( 'a' , {'href':'#'} ).set( 'html' , el.s ) );  });
                                    searchlist = $$('#searchsuggest a');
                                    searchtarg = this;
                                    searchlist.addEvents({
                                        'click' : function(e) { 
										//alert('CLICK: '+this.get('html'));
                                            e.stop();
                                          //  searchtarg.setProperty( 'value' , this.get('html').replace( /<b class="highlight">/ , '' ).replace(/<\/b>/ , '' ).replace( /&amp;/ ,'&' ) );
                                            searchtarg.setProperty( 'value' , this.get('html').replace( /<b class="highlight">/ , '' ).replace(/<\/b>/ , '' ).replace( /<B class=highlight>/ , '' ).replace(/<\/B>/ , '' ).replace( /&amp;/ ,'&' ) ); // '<B... = fix voor IE
                                            $('searchsuggest').empty();
                                            $('searchsuggest').addClass('hide');
                                            onlist = 0;
                                        },
                                        'focus' : function() { 
										//alert('FOCUS: '+this.get('html'));
                                         //   searchtarg.setProperty('value' , this.get('html').replace( /<b class="highlight">/ , '' ).replace(/<\/b>/ , '' ).replace( /&amp;/ ,'&' ) );
                                            searchtarg.setProperty('value' , this.get('html').replace( /<b class="highlight">/ , '' ).replace(/<\/b>/ , '' ).replace( /<B class=highlight>/ , '' ).replace(/<\/B>/ , '' ).replace( /&amp;/ ,'&' ) ); // '<B... = fix voor IE
                                            onlist = 0;
                                        }
										
                                    });
                                } else {
                                    $('searchsuggest').empty();
                                    $('searchsuggest').addClass('hide');
                                    onlist = 0;
                                }
                                
                            }}.bind(this)}).get({ 'value' : this.getProperty('value') });
                        
                        }.bind(this)).delay( 500 );
                    }
                }
            },
            
            'keydown': function(e) { 
                search_delay = $clear( search_delay ); 
                if( !$('searchsuggest') ) { body_.adopt( new Element( 'div' , { 'id' : 'searchsuggest' } ) ); }
                if( !$('searchsuggest').hasClass('hide') && e.key == "down" ) {   
                    searchlist[0].addClass('on');
                    searchlist[0].focus();
                    onlist = 1;  
                    currlist = 1;
                    searchlist.addEvent( 'keydown' , function(e) {
                        if( e.key == "down" || e.key == "up" ) {
                            e.stop();
                            if( !searchlist[currlist] ) currlist = ( e.key == "down" ? 0 : searchlist.length-1 );
                            searchlist.removeClass('on');
                            searchlist[currlist].addClass('on');
                            searchlist[currlist].focus();
                            currlist = ( e.key == "down" ? currlist + 1 : currlist - 1 );
                        }
                    });
                }   
            }
        });
//-----------------------------------------------------------------------------------------------------------------------------------------        
//-----------------------------------------------------------------------------------------------------------------------------------------        
        };
        
        dropsearch();
        
    /* -- news panel -- */
    
        makeScrollbar = function(content,scrollbar,handle,horizontal,ignoreMouse){
	        var steps = ( horizontal ? ( content.getScrollSize().x - content.getSize().x ) : (content.getScrollSize().y - content.getSize().y ) );
	        var slider = new Slider(scrollbar, handle, {	
		        steps: steps,
		        mode: (horizontal?'horizontal':'vertical'),
		        onChange: function(step){
			        var x = (horizontal?step:0);
			        var y = (horizontal?0:step);
			        content.scrollTo(x,y);
		        }
	        }).set(0);
	        if( !(ignoreMouse) ){
		        $$(content, scrollbar).addEvent('mousewheel', function(e){	
			        e = new Event(e).stop();
			        var step = slider.step - e.wheel * 30;	
			        slider.set(step);					
		        });
	        }
            $(document.body).addEvent('mouseleave',function(){slider.drag.stop();});
        };
        
        if( $$('.newscontent').length > 0 ) { 
            nc = null;
            scrollbar = $$('.newscrollbar');
            scrollhandle = $$('.newshandle');
            $$('.newscontent').each( function( el , i ) { nc = makeScrollbar( el , scrollbar[i] , scrollhandle[i] ); });
        }
        
		
		/* voor de icon-box bij travel search - deze heb ik er zelf bij gezet: is nog in experimentele fase en werkt nog niet helemaal
        if( $$('.iBox').length > 0 ) { 
            nc = null;
            scrollbar = $$('.newscrollbar');
            scrollhandle = $$('.newshandle');
            $$('.iBox').each( function( el , i ) { nc = makeScrollbar( el , scrollbar[i] , scrollhandle[i] ); });
        }
*/





    /* -- wysiwyg -- */
    
        if( $$('.wysiwyg').length > 0 ) { js_load = new Asset.javascript(base_url+'static/javascript/libs/ckeditor/ckeditor.js' , { onload : function() {
            
            wysiwyg_ = [];
        
            $$('.wysiwyg').each( function( el , i ) {
                if( el.getProperty('rel') == "advanced" ) {
                    wysiwyg_[i] = CKEDITOR.replace( el , { 
                        uiColor : '#AAAAAA',
                        toolbar : [
                            ['Source','Templates','Maximize','-','Undo','Redo'],
                            ['ShowBlocks'],
                            ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
                            ['Link','Unlink','Anchor'],
                            ['TextColor','BGColor'],
                            '/',
                            ['Bold','Italic','Underline','Strike'],
                            ['NumberedList','BulletedList'],
                            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
                            ['Format','Font','FontSize']
                        ]
                    });     
                } else { wysiwyg_[i] = CKEDITOR.replace( el , { uiColor : '#AAAAAA' , toolbar : [ [ 'Bold', 'Italic', 'Strike' , 'Underline', '-', 'TextColor' , 'FontSize', 'Font']] }); }               

                CKEDITOR.config.forcePasteAsPlainText = true;
                CKEDITOR.config.height = el.getStyle('height');
                CKEDITOR.config.resize_enabled = 0;
                CKEDITOR.config.removePlugins = 'elementspath,save';
                CKEDITOR.config.pasteFromWordRemoveStyle = true; 
                CKEDITOR.config.disableNativeSpellChecker = false;
        //      CKEDITOR.config.entities = false;
                CKEDITOR.config.forceSimpleAmpersand = true;

                CKEDITOR.on( 'instanceReady' , function(e) { e.editor.dataProcessor.writer.lineBreakChars = ''; });

            });  
            
        }} ); }
        
    /* -- load the rest of the external scripts -- */
        
        if( $('covers') ) { js_load = new Asset.javascript(base_url+'static/javascript/jscript_cover.js');  }
        js_load = new Asset.javascript('http://tcr.tynt.com/javascripts/Tracer.js?user=cDJYogv4Cr37szadbiUt4I&amp;s=102'); 
            
    },
    
    'load': function() {

    /* -- delete -- */
        
        delete_item = function(e) {

            e.stop();
            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;
            
            add_note( x , y , "<p><a href='#' id='delete_confirm'><b><font color='red'><u>YES</u>, I definitely want to delete this</font></b></a></p><p><a href='#' id='delete_remove'><u>NO</u> I've changed my mind!</a></p>" );

            cell_curr = this;
//alert("cell_curr: "+cell_curr);
                
            $('delete_confirm').addEvent( 'click' , function(e) {
//            add_note( x , y , "<p><b><font color='red'>deleting..</font></b></p>" );
            
                e.stop();
				

/*
alert("HREF: "+cell_curr.getProperty('name')+ " = "+cell_curr.getProperty('rel')+ " \n\n "+cell_curr.getProperty('href'));

if(cell_curr.getProperty('name') == "delete_property"){ 
				var myRequest = new Request({url: cell_curr});
				myRequest.post('act='+cell_curr.getProperty('name')+ '&id='+cell_curr.getProperty('rel'));
				
				myRequest.onComplete = alert("response-1: "+myRequest.response);
				
				var myFx = new Fx.Tween($('delete_confirm'));

				myFx.start('background-color', '#0f0', '#f00'); 
//				$('note').destroy();
                

// = 
//}else{
}
*/				
                                                                // de href = vaak php-file waar gedelete wordt - zie 'act' etc. beneden de POST
                new Request.JSON({url: cell_curr.getProperty('href'), onComplete: function(response){ 
//				alert("response: "+response );/**/ 
				
				
				if( response ) { 

                    $('note').destroy();

                    if( response.forward ) {
                
                        location.href = response.forward;
                        
                    } else if( response.success == 1 ) {
                    
                        c = 0;
                        while( !cell_curr.hasClass('deletewrap') && c < 20 ) {
                            cell_curr = cell_curr.getParent();
                            c++;
                        }
                        
                        if( c == 20 && !cell_curr.hasClass('deletewrap') ) {
                            location.href = location.href;
                            return;
                        }
                        
                        if( cell_curr.hasClass( 'show_parent' ) ) $$('rel=['+cell_curr.getProperty('name')+']').destroy();
                        
                        cell_height = cell_curr.getSize().y;
                        cell_curr.setStyle( 'height' , cell_height );

                        fade = new Fx.Morph( cell_curr , {duration: 'short', transition: Fx.Transitions.Sine.easeOut} );
                        fade.start({ opacity:[1,0] }).chain( function() {
                            cell_curr.empty();
                            fade.start({height:[cell_height,0]}).chain(function() {
                                cell_curr.destroy();
                                if( $$('.deletewrap').length == 0 ) location.href = location.href;
                                else tbl_alternate();
                            }); 
                        });
                        
                        
                        
                    } else if( response.success == 2 ) {

                        cell_curr.destroy();
                        
                    } else add_note( x , y , response.error );
                                
                }}}).post({ 'act' : cell_curr.getProperty( 'name' ) , 'id' : cell_curr.getProperty( 'rel' ) });


            });
            
            $('delete_remove').addEvent( 'click' , function(e) {
                e.stop();
                $('note').destroy();
            });
            
        }
        
        $$('.delete').addEvent( 'click' , delete_item );




    /* -- email validate -- */
        
        email_valid_sent = null;
        email_valid = function(e) {

            e.stop();
            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;
            
            if( email_valid_sent === null ) {

                email_valid_sent = new Request.JSON({url: base_url + 'imps/36_members' , onComplete: function(response){ if( response ) {
                
                    if( response.note ) { add_note( x , y , response.note ); }    

                }}}).post({ 'act' : 'email_valid' , 'id' : this.getProperty( 'rel' ) });
            
            } else { add_note( x , y , "An e-mail has already been sent!" ); }

        };
        
        $$('.email_valid').addEvent( 'click' , email_valid );



    /* -- connect Business to Member Plus -- */
        
        conn_sent = null;
        connectBusinessMemberPlus = function(e) {

            e.stop();
            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;
			
 
//            cell_curr = this;
			
            add_note( x , y , "<p><a href='#' id='conn_confirm'><b>Yes, I definitely want to connect this</b></a></p><p><a href='#' id='connect_remove'>I've changed my mind!</a></p>" );
 
                
            $('conn_confirm').addEvent( 'click' , function(e) {
            
            if( conn_sent === null ) {

                conn_sent = new Request.JSON({url: base_url + 'imps/95_business?act=member_linked' , onComplete: function(response){ if( response ) {
//			alert("LINK: "+ base_url);
                
                    if( response.note ) { add_note( x , y , response.note ); }    

                }}}).post({ 'act' : 'member_linked' , 'mid' : this.getProperty( 'mid' ) , 'bid' : this.getProperty( 'bid' ) });
            
            } else { add_note( x , y , "Member has already been linked to Business!" ); }

            });
 
 
 
            $('connect_remove').addEvent( 'click' , function(e) {
                e.stop();
                $('note').destroy();
            });

        };
        
        $$('.connect_link').addEvent( 'click' , connectBusinessMemberPlus );





    /* -- report -- */
        
        report_item = function(e) {

            e.stop();
            x = e.client.x - 90;
            y = e.client.y - 193 + getScroll().y;
            
            add_note( x , y , "<p><a href='#' id='report_confirm'><b>Yes, I definitely want to report this</b></a></p><p><a href='#' id='report_remove'>I've changed my mind!</a></p>" );

            $('report_confirm').addEvent( 'click' , function(e) {
            
                e.stop();
                $('note').destroy();

                new Request.JSON({url: this.getProperty('href') , onComplete: function(response){ if( response ) {
                    if( response == 1 )         { new Element('span',{'html':"The report has been made"}).replaces(this); }  
                    else if( response == 2 )    { new Element('span',{'html':"The report could not be made!"}).replaces(this); }  
                    else                        { new Element('span',{'html':"Please wait 30 seconds between reports!"}).replaces(this); } 
                }}.bind(this)}).post({ 'act' : this.getProperty( 'name' ) , 'id' : this.getProperty( 'rel' ) });

            }.bind(this));
            
            $('report_remove').addEvent( 'click' , function(e) {
                e.stop();
                $('note').destroy();
            });
            
        };
        
        $$('.report').addEvent( 'click' , report_item );

    /* -- subscribe -- */
        
        subscribe_item = function(e) {

            e.stop();

            new Request.JSON({url: this.getProperty('href') , onComplete: function(response){ if( response ) {
                if( response == 1 )         { new Element('span',{'html':"Subscribed!"}).replaces(this); }  
                else if( response == 2 )    { new Element('span',{'html':"Unsubscribed!"}).replaces(this); }  
                else                        { new Element('span',{'html':"Already subscribed!"}).replaces(this); } 
            }}.bind(this)}).get({ 'act' : this.getProperty( 'name' ) , 'id' : this.getProperty( 'rel' ) });
            
        };

        $$('.subscribe').addEvent( 'click' , subscribe_item );
        
    /* -- notes -- */
        
        add_note = function( x , y , txt ) {
        
            if( $('note') ) { $('note').destroy(); }
            
            if( x + 300 > window.getWidth() )   { x = window.getWidth() - 300; }
            if( y < 0 )                         { y = 0; }

            body_.adopt( new Element( 'div' , { 'id':'note' } ).setStyles({'top':y , 'left':x } ) );
            $('note').adopt( new Element( 'div' , { 'id':'note_inner' , 'html':txt } ) );
            
            $$('body')[0].addEvent( 'click' , function() { if( $('note') ) { $('note').destroy(); }});
            
        };
 
    /* -- reviews (handy stuff area, v.short so just put it in here) -- */

        if( $('form_reviews') ) {
        
            review_fetch_go = null;
            
            review_fetch = function() {
                new Request.JSON({url: base_url+"imps/1_myclubgolf", onComplete: function(response){ if( response ) {
                    if( response ) { location.href = response; }
                }}}).post({ 'act' : 'review_fetch' , 'value' : $('form_reviews').toQueryString() });
            };
        
            $$('#form_reviews select[name=review_orderby]').addEvent( 'change' , function() { 
                $clear(review_fetch_go);
                review_fetch();
            });
            
            $$('#form_reviews .input_checkbox').addEvent( 'click' , function() {
                $clear(review_fetch_go);
                review_fetch_go = review_fetch.delay(1000);
            });
            
            $$('#form_reviews .filterrating').addEvent( 'click' , function() { 
                $('rating').setProperty( 'value',this.getProperty('rel') );
                $clear(review_fetch_go);
                review_fetch();
            });
        }

    /* -- blank block maker -- */
    
        if( $('block_blank') && $('block_title') && $('block_text') ) {
        
            block_fetch_go = null;
        
            block_fetch = function() {
                new Request.JSON({url: base_url+"imps/1_myclubgolf", onComplete: function(response){ if( response ) {
                    if( response.src ) { $('block_blank').setProperty('src',response.src + '?c=' + new Date().getTime() ); }
                }}}).post({ 'act' : 'block_maker' , 'value' : $('block_form').toQueryString() });
            };
            
            $('block_title').addEvent( 'keyup' , function() {
                $clear(block_fetch_go);
                block_fetch_go = block_fetch.delay(1000);
            });
            $('block_text').addEvent( 'keyup' , function() {
                $clear(block_fetch_go);
                block_fetch_go = block_fetch.delay(1000);
            });
        
        }
        
    /* -- print -- */
    
        $$('.printpage').addEvent( 'click' , function() {  window.print(); });
    
    
    /* -- analytics -- */
    
         var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-17034582-1']);
        _gaq.push(['_trackPageview']);
    
        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();

    }
    
});
