	
	if (! blocks) {
		alert("Set Blocks Please");
	} 

	if (! selection_states){
		alert("Set States Please");
	}
	
	//var normal_block_style = "asset";
	//var selected_block_style = "asset_selected";
	//var last_selected_block_style = "asset_last_selected";

	function open_frame(the_frame, the_url){
                parent.frames[the_frame].location.href = the_url;
        }

	var doit = true;
	function doityes(){
		doit = true;
	}

	function was_clicked(a_block, e){
		//alert("TEST");

		if (doit != true){
			return;
		}
		doit = false;
		setTimeout("doityes()", 5);

		if (parent.frames['viewbuttons']){
			parent.frames['viewbuttons'].active_frame = self;
		}

		the_block = document.getElementById(a_block);

		if (is_unselected(the_block)){
			//Wasn't clicked, therefore show details
			var tmp = a_block;
			tmp = tmp.replace("asset_","");
			var link = "/ui/detail/detail.mhtml?asset=" + tmp;
	                if (parent.frames['detail']){
				parent.frames['detail'].location.href = link;
			}else{
	                        link = "/ui/browser/sit/info.mhtml?id=" + tmp;
				parent.frames['loader'].location.href = link;
			}
		}

		if ( is_shift(e) ){
			if (last_selected){
				var select_from = index_of(last_selected);
				var select_to = index_of(the_block);
				if (select_from > select_to){
					var temp_select = select_from;
					select_from = select_to;
					select_to = temp_select;
				}

				for(var x=select_from; x <= select_to; x++){
					set_selected(document.getElementById(blocks[x]));
				}

			}else{
				select_toggle(the_block);
			}
			//set_selected(last_selected);
			last_selected = the_block;
			//set_last_selected(the_block);
		}else{
			if (is_ctrl(e) == false){
				reset_all();
			}

			
			if (last_selected && (is_selected(last_selected))){
				set_selected(last_selected);
			}
	                last_selected = the_block;
			select_toggle(the_block);
			//if (is_selected(the_block)){
		        //        set_last_selected(the_block);
			//}
		}
		// CSS bug, make sure IE doesn't fsck up the layout.
		//select_toggle( document.getElementById(blocks[0]) );
		//select_toggle( document.getElementById(blocks[0]) );
	}


	function select_toggle(a_block){
		if (is_unselected(a_block)) {
			set_selected(a_block);
		}else{
			set_normal(a_block);
		}
	}

	function is_shift(e){
		return e.shiftKey;
	}
	function is_ctrl(e){
		if (e.metaKey == undefined){
			return e.ctrlKey;
		}else{
			return e.ctrlKey || e.metaKey;
		}
	}

	function is_selected(a_block){
		return (a_block.className == selected_block_style) || (a_block.className == last_selected_block_style);
	}

	function is_unselected(a_block){
		return !(is_selected(a_block));
	}

	function index_of(a_block){
		for(var x=0;x<blocks.length;x++){
			if (blocks[x] == a_block.id){
				return x;
			}
		}
	}

	function set_selected(a_block){
		a_block.className = selected_block_style;
		selection_states[index_of(a_block)] = true;
	}

	function set_last_selected(a_block){
		if (reset_frame){
			reset_frame.reset_last_selected();
		}
                a_block.className = last_selected_block_style;
        }

	function reset_all(){
		for(var x=0;x<blocks.length;x++){
				set_normal( document.getElementById(blocks[x]) );
		}
		last_selected = null;

	}
        function set_all(){
                for(var x=0;x<blocks.length;x++){
                                set_selected( document.getElementById(blocks[x]) );
                }
                last_selected = null;

        }


	function set_normal(a_block){
		if (a_block == last_selected){
			last_selected = null;
		}
		a_block.className = normal_block_style;
		selection_states[index_of(a_block)] = false;

	}

	function dump_values(){

		var output = "Button Values:\n";

		for(var x=0;x<blocks.length;x++){
				output += blocks[x] + ":\t" + selection_states[x] + "\n";
		}

		return output;
	}

	function selected_querystring(a){
		var output = '?';
		if (a == 'noquestion'){
			output = '';
		}
		if(a == 'noargs'){
			output = '?1=1';
		}

                for(var x=0;x<blocks.length;x++){
			if (selection_states[x] == true){
				var tmp = blocks[x]
				tmp = tmp.replace("asset_","")
				output += '&asset_' + x + '=' +  tmp 
			}
                }
		return output;
        }
	
	function selected_id_array(){
		var output = new Array();
		for(var x=0;x<blocks.length;x++){
                        if (selection_states[x] == true){
                                var tmp = blocks[x]
                                tmp = tmp.replace("asset_","")
                                output.push( tmp );
                        }
                }
                return output;
	}

	

	function link_selected(link,frame){
		var arg = '';
		if (link.indexOf('?') == -1){
			arg = 'noargs';
		}
		link = link + selected_querystring(arg);
		if (frame){
			open_frame(frame, link);
		}else{
			document.location = link;
		}
	}

	function link_last_selected(link,frame){
		if (last_selected)
                link = link + '?' + last_selected.id + '=1';
                if (frame){
                        open_frame(frame, link);
                }else{
                        document.location = link;
                }
        }
	
	function reset_last_selected(){
		if (last_selected){
			if (is_selected(last_selected)){
				set_selected(last_selected);
			}else{
				set_normal(last_selected);
			}
			last_selected = null;
		}
	}
