/*****************************************
    Basket functions
    
    Scriptlets: /TradePointGeneralElements/ShoppingCart
    Included in Scriptlet: /TradePoint/Headers & Footers
    
********************************************/
    
    
    var urlChangeVATSession = "/TradePoint/VAT_Process";
    var urlOrderProcess     = "/TradePoint/Order_Process";
    var urlViewBasket       = "/TradePoint/Check%20Out/View_Basket";

    if(!window.process) 
    {
        document.write('<iframe src="/websys/Blank" style="display:none;" name="process" id="process" frameborder="0" height="0" width="0"></iframe>');
    }
    
    function changePriceType( el )
    {
        // Change Session
        process.location.href= urlChangeVATSession+ "?actionType="+ ((el.checked ) ? 'yes' : 'no');	
    }

    function BasketAdd( id, data )
    {
        var basketItems = document.getElementById( id );
        
        //Clear basket -- tveksam kod
        basketItems.innerHTML = '';
        
        //Add items
        var items = data.split('\n');
        for(var i=0; i<items.length; i++)
        {
            if(items[i] != "") 
            {
                var op = document.createElement("option");
                op.value =i;
                op.text = items[i];
                basketItems.options.add( op, basketItems.length );
            }
        }
        
        basketItems.options[ basketItems.length-1 ].selected = true;
    }
   
    //updates all Basket with new html
    function updateBaskets( html )
    {
        var baskets = document.getElementsByName('selectBasket');
        var len = baskets.length;
        for(var bi = 0; bi < len; bi++ )
        {
             BasketAdd( baskets.item(bi).id, html);
        }
    }
        
    function checkout()
    {
        if(top.main)
        {
            parent.document.location = urlViewBasket;
        }
        else
        {
            document.location = urlViewBasket;
        }
    }
     
    function hideConfirm()
    {
        var el = document.getElementById("confirmDiv");
        el.style.display = "none";   
    }
    
	function f_clientWidth() 
	{
		return f_filterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	function f_clientHeight() 
	{
		return f_filterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	}
	function f_scrollLeft() 
	{
		return f_filterResults (
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
		);
	}
	function f_scrollTop() 
	{
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	function f_filterResults(n_win, n_docel, n_body) 
	{
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}

	
    function showConfirm()
    {
        var tempWidth= 630,tempHeight= 460;
		tempWidth	= f_clientWidth();
		tempHeight 	= f_clientHeight();
		
		
        var el = document.getElementById("confirmDiv");
        
        var elWidth = el.clientHeight;
        var elHeight = el.clientHeight;
        
        var scrollWidthOffset = 0;
        var scrollHeightOffset = 0;
        try
        {
            scrollWidthOffset = document.body.parentElement.scrollLeft;
            scrollHeightOffset = document.body.parentElement.scrollTop;
        }
        catch( e )
        {
        }
        
        if( scrollWidthOffset == 0 && scrollHeightOffset == 0 )
        {
            scrollWidthOffset = document.body.scrollLeft;
            scrollHeightOffset = document.body.scrollTop;
        }
        
        if( scrollWidthOffset == 0 && scrollHeightOffset == 0 )
        {
            //firefox
            try
            {
                scrollWidthOffset = window.scrollX;
                scrollHeightOffset = window.scrollY;
            }
            catch( e )
            {
            }
        
        }
        
        if( !scrollWidthOffset )
            scrollWidthOffset = 0;
        
        if( !scrollHeightOffset )
            scrollHeightOffset = 0;
        
        tempWidth = tempWidth/2;
        tempHeight = tempHeight/3;
        
		if( elWidth==0 )
			elWidth = 300;
		if( elHeight==0 )
			elHeight = 200;
		
		var numWidth = Number( Math.round( elWidth ) )/2;
        var numHeight = Number( Math.round( elHeight ) )/2;
        var x = ( tempWidth- numWidth ) + scrollWidthOffset;
        var y = ( tempHeight- numHeight ) + scrollHeightOffset;
        
        x = Math.round( x );
        y = Math.round( y );
       
        el.style.left   = x+"px";
        el.style.top    = y+"px";
        el.style.display = "inline";
        setTimeout('hideConfirm()',2000);
    }
