HW.onload(function(){
	_$('body').addClass('hasJS');
	
	new HW.AutoReload('SearchPanel1_ddwCategory','SearchPanel1$ddwCategory');
	new HW.AutoReload('SearchPanel1_ddwPeriod','SearchPanel1$ddwPeriod');
	
	_$$('span.closePage').each(function(o) { o.createNode('a', 'Close Window', { href: '#' }).bind('click', function() { self.close(); }, false) });
	_$$('li.printLink').each(function(o) { o.createNode('a', 'Print Page', { href: '#' }).bind('click', function() { window.print(); }, false) });
	_$$('div.printLink').each(function(o) { o.createNode('a', '<img class="printIcon" alt="Print" src="images/icon_print.gif"/>', { href: '#' }).bind('click', function() { window.print(); }, false) });
	
	_$$('.go input.goButton').each(function(but){but.remove();});
	_$$('a.dynamicJS').each(function(a){
		a.bind('click',function(){_$(a.hash).focus();},false);
	});
	
	Tabs.init(); 
	var name = window.name;
	if(!name){name = 0;}
	Tabs.activate(name);
	
	if(_$('img.printIcon')){
		var img = _$('img.printIcon')
					.bind('mouseover',function(){
						img.setAttribute('src',img.src.replace('.gif', '_hover.gif'));
					})
					.bind('mouseout',function(){
						img.setAttribute('src',img.src.replace('_hover.gif', '.gif'));
					});
	}
});

HW.AutoReload = function(id,param) {
	var obj = this;
	var elm = _$('#'+id);
	this.defaultState = elm.selectedIndex;
	elm.bind('blur',function(){
		HW.log(obj.defaultState);
		if(elm.selectedIndex != obj.defaultState) {
			__doPostBack(param,'');
		}
	});
}



var counter = 0;

var Tabs = {
	
	tabs: null,
	
	init: function(){
		var obj = this;
		this.tabs = _$$('#divLinkButtons ul li a');
		
		//attach event handlers to each tab
		for(var i = 0; i < this.tabs.length; i++){
			var tabs = this.tabs;
			(function(){
				var index = i;
				HW.attachEvent(tabs[index], 'click', function(){								  
															  
									setTimeout(function(){
											if(!_$('#divLinkButtons').orig){
												//divLinkButtons gets striped out and reinserted by .net
												//We can tell this has happened if this property is absent
												_$('#divLinkButtons').orig = true;
												obj.init(); //we need to reset everything including reattach handlers
												obj.activate(index); //carry out class changes as normal
											}
											else{
												//element not replaced yet - keep looping
												var func = arguments.callee;
												setTimeout(function(){func()}, 10);
											}
										}, 10)
					    }, true);
			})()
		}
		
	},
	
	activate: function(index){
		if(index < this.tabs.length && index >= 0){ 
			//set correct tab to current
			//deactivate all other tabs
			for(var i = 0; i < this.tabs.length; i++){
				if(i == index){
					HW.addClass(this.tabs[i].parentNode, 'current');
					window.name=i;
					
				}else{
					HW.removeClass(this.tabs[i].parentNode, 'current');
				}
			}
		}
	}

}	   




function showstuff(divid) {
    document.getElementById(divid).style.display = "";
}

function hidestuff(divid,divid2) {
    document.getElementById(divid).style.display = "none";
    document.getElementById(divid2).style.display = "none";
}

