// JavaScript Document

//obligatorisk kod
var xmlHttp;
function ajaxSetup(){
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
    }
	catch (e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
}
//slut obligatorisk kod

var ajax_busy=false;
ajaxSetup();

function ajaxAddToChart(string){
	xmlHttp.abort();
	if(ajax_busy){
		setTimeout('ajaxAddToChart(\''+string+'\')',1000);
		return
	}
	ajax_busy=true;
	//document.getElementById('currenttimes').innerHTML='Hämtar dagens tider';
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			
			document.getElementById('chartdiv').innerHTML=xmlHttp.responseText;
			ajax_busy=false;
		}
	}
	queryurl="/artiklar/butik/index_ajax.cfm?addArtNr="+encodeURIComponent(string)+"&randnr="+Math.floor(Math.random()*1000);
	
	xmlHttp.open("GET",queryurl,true);
	xmlHttp.send(null);
}

function deleteItem(string){
	xmlHttp.abort();
	if(ajax_busy){
		setTimeout('ajaxAddToChart(\''+string+'\')',1000);
		return
	}
	ajax_busy=true;
	//document.getElementById('currenttimes').innerHTML='Hämtar dagens tider';
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById('chartdiv').innerHTML=xmlHttp.responseText;
			ajax_busy=false;
		}
	}
	queryurl="/artiklar/butik/index_ajax.cfm?delArtNr="+encodeURIComponent(string)+"&randnr="+Math.floor(Math.random()*1000);

	xmlHttp.open("GET",queryurl,true);
	xmlHttp.send(null);
}




var popupWin
function openWindow(url, name, w_width, w_height,extraFeatures) {
	if(extraFeatures!='')extraFeatures=extraFeatures+',';
	if (!popupWin || popupWin.closed) {
		center_of_screen_X=Math.floor(screen.availWidth/2)-Math.floor(w_width/2);
		center_of_screen_Y=Math.floor(screen.availHeight/2)-Math.floor(w_height/2);
  		popupWin = window.open(url, name, extraFeatures + 'width='+w_width+',height='+w_height+',left='+center_of_screen_X+',top='+center_of_screen_Y);
		if (!popupWin.opener) popupWin.opener = window
	} else {
		// window is already open; bring window to front
		popupWin.focus()
	}
}
