function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


function doPopup(f)
{
  newwin = null;
  newwin = window.open('', 'Betalning','scrollbars,status,width=550,height=600');
  newwin.focus();
  if(!self.name) { self.name = 'shopwin'; }
  if (!newwin.opener) { newwin.opener = self; }
  f.opener.value = self.name;
  return true;
}

var win= null;
function openPopup(url,w,h)
{
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=yes,';
	settings +='resizable=no';
	win=window.open(url,'window',settings);
	
	if(parseInt(navigator.appVersion) >= 4) {win.window.focus();}
}

function Toggle(item)
{
   obj=document.getElementById(item);
   visible=(obj.style.display!="none");
   key=document.getElementById("x" + item);
   
   if(visible)
   {
     obj.style.display="none";
   }
   else
   {
      obj.style.display="block";
   }
   
   /*if(Get_Cookie('menu_id') == item)
   {
   	Set_Cookie('menu_id', '', '', '/', '', '');
   }
   else
   {   
   	Set_Cookie('menu_id', item, '', '/', '', '');
   }*/
}

function updatePaymentLayer(text, image)
{
	id = 'paymentLayer';
	imageId = 'paymentImageLayer';
	imageHtml = '<img border="0" src="images/paymentproviders/'+image+'" alt="" style="margin-right: 10px">';
	
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
		
		x2 = document.getElementById(imageId);
		x2.innerHTML = '';
		x2.innerHTML = imageHtml;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
		
		x2 = document.all[imageId];
		x2.innerHTML = imageHtml;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		x.document.open();
		x.document.write(text);
		x.document.close();
		
		x2 = document.layers[imageId];
		x2.document.open();
		x2.document.write(imageHtml);
		x2.document.close();
	}
}

function countdown_clock(year, month, day, hour, minute, format)
{
	//I chose a div as the container for the timer, but
	//it can be an input tag inside a form, or anything
	//who's displayed content can be changed through
	//client-side scripting.
	html_code = '<div id="countdown"></div>';
	
	document.write(html_code);
	
	countdown(year, month, day, hour, minute, format);
}
         
function countdown(year, month, day, hour, minute, format)
{
	Today = new Date();
	Todays_Year = Today.getFullYear() - 2000;
	Todays_Month = Today.getMonth() + 1;                  
	
	//Convert both today's date and the target date into miliseconds.                           
	Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
	                     Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
	Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
	
	//Find their difference, and convert that into seconds.                  
	Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
	
	if(Time_Left < 0)
	Time_Left = 0;
	
	element = document.getElementById('countdown');
	
	switch(format)
	{
		case 0:
		    //The simplest way to display the time left.
		    element.innerHTML = Time_Left + ' sek';
		    break;
		case 1:
		    //More datailed.
		    days = Math.floor(Time_Left / (60 * 60 * 24));
		    Time_Left %= (60 * 60 * 24);
		    hours = Math.floor(Time_Left / (60 * 60));
		    Time_Left %= (60 * 60);
		    minutes = Math.floor(Time_Left / 60);
		    Time_Left %= 60;
		    seconds = Time_Left;
		    
		    dps = 'ar'; hps = ''; mps = ''; sps = '';
		    //ps is short for plural suffix.
		    if(days == 1) dps ='';
		    if(hours == 1) hps ='';
		    if(minutes == 1) mps ='';
		    if(seconds == 1) sps ='';
		    
		    element.innerHTML = days + ' dag' + dps + '<br>';
		    element.innerHTML += hours + ' h' + hps + ' ';
		    element.innerHTML += minutes + ' min' + mps + ' ';
		    element.innerHTML += seconds + ' sek' + sps;
		    break;
		default: 
		    countdown.innerHTML = Time_Left + ' sek';
	}
	   
	//Recursive call, keeps the clock ticking.
	setTimeout('countdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ',' + format + ');', 1000);
}

function showWait()
{
	h = 200;
	w = 400;
	
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	document.getElementById("parentDiv").style.display = 'inline';
	document.getElementById("waitIndicatorDiv").style.top = wint+'px';
	document.getElementById("waitIndicatorDiv").style.left = winl+'px';
	document.getElementById("waitIndicatorDiv").style.display = 'inline';
	setTimeout('document.images["indicatorimage"].src = "'+window.IMAGEPATH+'indicator_medium.gif"', 200);	// IE animation fix
}