// JavaScript Document

function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
	{
	c_start=c_start + c_name.length+1;
	c_end=document.cookie.indexOf(";",c_start);
	if (c_end==-1) c_end=document.cookie.length;
	return unescape(document.cookie.substring(c_start,c_end));
	}
  }
return "";
}
function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function Alert(Visible,CloseTimeInSec,MsgClass,BackgroundImage,AlertMsg) {
	
	$('body').prepend('<div id="MsgOverlay" style="display:none;z-index:200;position:absolute;left:0px;top:0px;height:0px;width:100%;height:'+ $('#ShopMainLayOutTable').height() +'px;background:#000000;'+ Visible +'"></div><div id="Msg" style="display:none;z-index:200;position:absolute;width:100%;height:100%;'+ Visible +'"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="center"><span style="background-image:url('+ BackgroundImage +');background-repeat:no-repeat;width:330px;height:258px;display:block;z-index:100;"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="top" class="AlertMsg '+ MsgClass +'">'+ AlertMsg +'</td></tr></table></span></td></tr></table></div>')
	$('#MsgOverlay').css('opacity', 0.25);

	if (Visible){ShowAlert()}

	setTimeout ("CloseAlert();", CloseTimeInSec*1000);
	$('#MsgOverlay, #Msg').click(function() {
//		CloseAlert();
	});

}
function CloseAlert() {
	$('#Msg').hide();
	$('#MsgOverlay').fadeOut('slow');
}
function ShowAlert() {
	$('#MsgOverlay').fadeIn('slow');
	$('#Msg').show();
}


function BNvidere(){
	CloseAlert();
	if ($('#CookieSave').is(':checked')==true && getCookie('CoockiePopup') == ''){setCookie('CoockiePopup',1,365);}
}

function BNkassen(){
	location.href='/shop/showbasket.html';
	if ($('#CookieSave').is(':checked')==true && getCookie('CoockiePopup') == ''){setCookie('CoockiePopup',1,365);}
}


var BN_videre	= '/images/template/popup-videre.png';
var BN_kurven	= '/images/template/popup-til-kurv.png';
var BN_ok		= '/images/template/popup-ok.png';
var BN_space	= 3;

var BG_error	= '/images/template/popup-background-error.png';
var BG_succes	= '/images/template/popup-background-succes.png';

$(document).ready(function(){
	for(i=0; i<document.forms.length; i++) {
		try {
			document.forms[i].VerticalScrollPos.value=1;
		}
		catch(e){}
	}

})

var isPurchase = false;

old_alert = window.alert;

window.alert = function(txt) {

var BN_spaceTemp = '';
for (iB=1;iB<=BN_space;iB++){BN_spaceTemp=BN_spaceTemp+'&nbsp;';}

	
		if (isPurchase){
			var ShowBox = true;
			
			if (getCookie('CoockiePopup') != ''){
				if (getCookie('CoockiePopup')=="1" || getCookie('CoockiePopup')=="2"){CloseAlert();ShowBox = false;}
			}
			
			if (ShowBox){
			Alert(true,10,'alertclass1',BG_succes,'<div style="margin-top:88px;"><span style="font-size:14px;font-family:Verdana, Geneva, sans-serif;color:#494848;">'+ txt +'</span><br><br><div style="margin-bottom:7px;"><a href="javascript:BNvidere();"><img src="'+ BN_videre +'" border="0" title="Tryk her for at handle videre"></a>'+ BN_spaceTemp +'<a href="javascript:BNkassen();"><img src="'+ BN_kurven +'" border="0" title="Tryk her for at gå til indkøbskurven"></a></div><input type="checkbox" name="CookieSave" id="CookieSave" value="1" style="vertical-align:middle;"> <span style="font-size:10px;font-family:Verdana, Geneva, sans-serif;color:#777676;">Vis ikke denne boks igen</span></div>')
			}
		}else{
			Alert(true,10,'alertclass2',BG_error,'<div style="margin-top:88px;"><span style="font-size:14px;font-family:Verdana, Geneva, sans-serif;color:#494848;">'+ txt +'</span><br><br><br><div style="margin-bottom:7px;"><a href="javascript:CloseAlert();void(0);"><img src="'+ BN_ok +'" border="0" title="Tryk her for at lukke vinduet"></a></div>')
		}

};

function ScrollToSavedVPos(arg){isPurchase=true;};
