
css('.hide', 'display:none');

function hideFlash() {
	Element.addClassName($('flashMessage'), "hide");
	return false;
}


function initFlash() {
	if ($('flashMessage')) {
		var close = document.createElement("a");
		close.id = "close_flash";
		close.setAttribute('href', '');
		close.innerHTML = 'Stäng';
		close.onclick = hideFlash;
		$('flashMessage').appendChild(close);
		setTimeout('hideFlash()', 3000);
	}
}

function initDispatchButton() {
	if ($('dispatch_button')) {
		$('dispatch_button').onclick = function() {
			$('confirm_order_form').submit();
			//this.disabled = true;
			return true;
		}
	}
}

function initBrowseProducts() {
	if ($('product_select_brand')) {
		$('product_select_brand').onchange = function() {
			var s = this.value.replace(/\s/g,"+");
			location.href = '/brand/' + encodeURI(s);
		}
	}
	if ($('product_select_category')) {
		$('product_select_category').onchange = function() {
			var s = this.value.replace(/\s/g,"+");
			location.href = '/category/' + encodeURI(s);
		}
	}
}

function modifyLinks() { 
 	if (!document.getElementsByTagName) return; 
	var alinks=document.getElementsByTagName("a");
 	for (var i=0; i<alinks.length; i++) {
		//NEW WINDOW - a little bit ugly
   		if (alinks[i].getAttribute("href") && alinks[i].getAttribute("rel") == "external")  {
			alinks[i].target = "_blank";
		
		//DELETE	
		} else 	if (alinks[i].getAttribute("href") && alinks[i].getAttribute("rel") == "delete")  {
			alinks[i].onclick = function() {
				if (confirm(this.getAttribute("title"))) {
					location.href = this.getAttribute("href");
				} 
				return false;
			}
		}
	} 
}

function initStats() {
	var bodies = document.getElementsByTagName('body');
	if (bodies[0].id == 'home') {
		var pic1= new Image(1,1); 
		pic1.src = "http://m1.webstats.motigo.com/n?id=ACwqQwckhJ6PhI7hTz2nZMWlWYOQ"; 
	}
}

function initApp() {
	initBrowseProducts();
	initFlash();
	initDispatchButton();
	modifyLinks() ;
	initStats();
}

//motigo_webstats("ACwqQwckhJ6PhI7hTz2nZMWlWYOQ", 0);
addEvent(window, 'load', initApp);
