﻿window.onresize=resizing;
window.onload=load;
var loaded = false;;

function ShowImg(img)
{   
    imgShow  = document.getElementById("imgShow");
    imgShow.src=img.src.replace("width","xx");
    dlgShowImage.Show();
    var ScrollTop = document.body.scrollTop;
    if (ScrollTop == 0)
    {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
     dlg = document.getElementById("ctl00_dlgShowImage");
     ScrollTop=ScrollTop+150;
    dlg.style.top = ScrollTop + "px";  
}

function load()
    {
       prod = document.getElementById("products");
       if(prod.offsetHeight<2)
       resizing();
        if(maxScroll>0)
        {
            document.getElementById("RigthScrollButton").style.visibility="visible";
           document.getElementById("LeftScrollButton").style.visibility="visible";
            
        }
        loaded =true;
       
        
        
    }
		
		function printPage()
		{
		var printArea = document.getElementById("PrintArea");
			if(printArea) 
	            {
		            var sStart = "<html><head><link href=\"/ComponentArt/Navigation/GridStyle.css\" type=\"text/css\" rel=\"stylesheet\" /> <link rel='stylesheet' type='text/css' href='/styles/anteV3.css'/></head><body onload=\"javascript:window.print();\">";
            						
		            sStop = "</body></html>";
		            var w = window.open('','printWin','width=650,height=440,scrollbars=yes');
		            wdoc = w.document;
		            wdoc.open();
		            wdoc.write( sStart + printArea.innerHTML ) ;
		            wdoc.writeln( sStop );
		            wdoc.close();
	            }
		}
		
		function OpenPage(id)
		{
		      window.location.href= "/framework/page.aspx?id=" + id;
		}
		
		function resizing()
			{
			myHeight = 0;
             if( typeof( window.innerWidth ) == 'number' ) 
             {
                //Non-IE
           //    msg = document.getElementById("msg");	      
               PageTop = document.getElementById("PageTop");
               products = document.getElementById("ctl00_ContentPlaceHolder1_products1_Grid1_dom");
               if(products==null) products = document.getElementById("products");
               bottom = document.getElementById("bottom");
               cart = document.getElementById("cart");
               Content = document.getElementById("Content");
                myHeight = window.innerHeight;
                
             } 
             else if( document.documentElement && 
                        ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
            {
                //IE 6+ in 'standards compliant mode'
               //myHeight =  window.screen.availHeight;
                myHeight = document.documentElement.clientHeight;
                
            }
            else if( document.body && 
                      ( document.body.clientWidth || document.body.clientHeight ) )
            {
              //IE 4 compatible
              myHeight = document.body.clientHeight;
            }
              //myHeight=myHeight-PageTop.offsetHeight + bottom.offsetHeight + cart.offsetHeight;
               myHeight=  myHeight - PageTop.offsetHeight;
	    //      msg.innerHTML=PageTop.offsetHeight + "h" + myHeight + ","  + bottom.offsetHeight +"," +  cart.offsetHeight + "," + Content.offsetHeight +"p:" +  products.offsetHeight;
               
              if(myHeight>products.offsetHeight)
              {
                myHeight=myHeight + bottom.offsetHeight + cart.offsetHeight;
              }
              else
              {
                myHeight=products.offsetHeight + bottom.offsetHeight + cart.offsetHeight;
              }
              
              if (myHeight>Content.offsetHeight)
			{
              Content.style.height=myHeight+"px";
            //  Content.offsetHeight = myHeight;
//			if (myHeight>400)
//				{
//				myHeight 
//	
//				Content.style.height=document.body.scrollTop + myHeight -250;
				//bottom.style.top=document.body.scrollTop+myHeight-bottom.offsetHeight;
			//	window.alert(bottom.style.top);
//				var midHeight;
//				midHeight = document.body.scrollTop + myHeight - bottom.offsetHeight - topSection.offsetHeight;
//				//window.alert("top:" + document.body.scrollTop + "\nclient:" +  document.documentElement.clientHeight + "\nbootom:" +  bottom.offsetHeight + "\ntop:" + topSection.offsetHeight);
//				midsection.style.height = midHeight;
				}
			//	window.alert("h" + myHeight);
			
			}
			var t;
			 
//			var l2Menu = document.getElementById('pnlL2Menu');
//			var maxScroll = l2Menu.scrollWidth - l2Menu.clientWidth;
			function ScrollRigth()
			{
			   

			 //  msg.innerHTML=l2Menu.scrollLeft;
			    if(l2Menu.scrollLeft<maxScroll)
			    {
    			        l2Menu.scrollLeft = l2Menu.scrollLeft +3;
    			        t = setTimeout('ScrollRigth()', 10);
			    }
			   else  if(t!=undefined)  clearTimeout(t);
			   
			
			}
			
			function ScrollLeft()
			{
			//window.alert(by);
			
			    if(l2Menu.scrollLeft>0)
			    {			
			        l2Menu.scrollLeft = l2Menu.scrollLeft - 3;
			        t = setTimeout('ScrollLeft()', 10);
    			
			    }
			    else if(t!=undefined) clearTimeout(t);
			}
			
			
			function ScrollLeftTo(pos)
			{
		//	 msg.innerHTML="lefts" + pos +":" +   l2Menu.scrollLeft;
			    if(l2Menu.scrollLeft>pos)
			    {			
			        l2Menu.scrollLeft = l2Menu.scrollLeft - 4;
			        t = setTimeout('ScrollLeftTo(' + pos + ')', 2);
    			
			    }
			    else if(t!=undefined) clearTimeout(t);
			}
			
		    function ScrollRigthTo(pos)
			{
	//		 msg.innerHTML="rscroll" + pos +":" +   l2Menu.scrollLeft;
			    if(l2Menu.scrollLeft<pos)
			    {			
			        l2Menu.scrollLeft = l2Menu.scrollLeft + 4;
			        t = setTimeout('ScrollRigthTo(' + pos + ')',2);
    			
			    }
			    else if(t!=undefined) clearTimeout(t);
			}
			
			function mnu2PanelHover(number)
			{
			
			if(!loaded) return;
			 if(t!=undefined) clearTimeout(t);
			 var x = ((number - 3) * 100);
			 if(x>maxScroll) x=maxScroll;
			 if(x<0)x=0;
			 if(x>l2Menu.scrollLeft)
			 {
			   ScrollRigthTo(x);
			 }
			 else
			 {
			  ScrollLeftTo(x);
			  }
			  
			  var now = new Date();
  

	//		 msg.innerHTML="hovhov" + x +":" +   l2Menu.scrollLeft + now.getMilliseconds();
			}
			
			function scrollL2menu(pos)
			{
			    l2Menu.scrollLeft = pos;
			}
			
			//ShoppingCart
			function checkout()
{
cbCheckOut.Callback("1");
dlgCheckout.Show();
//window.alert("start");

}
function ShowCart()
{
dlgCheckout.Show();
//window.alert("¨xx");
//dlgCheckout.Show();
}
function ClearCart()
{
cbClear.Callback();
    
}
function ToggleCart(mode)
{
// window.alert(mode);
    cbBuy.Callback("0","0");
    if(mode=="False")
    document.getElementById("Cart").style.height="120px";
    else
    document.getElementById("Cart").style.height="20px";
    resizing();
   // window.alert(mode);
}

function UpdateNextButton(chk)
{
   // window.alert(chk.checked);
 //  Cart.style.width
//    CheckOutButtons = document.getElementById("CheckOutButtons");
    if(chk.checked)
    {
    chk.parentNode.style.width= '200px';
    }
    else
    {
    chk.parentNode.style.width= '400px';
    //CheckOutButtons.style.visibility='visible';
    }
    
    
}


//Products

  function saveCell(itemId, columnField, newValue)
    {
        var row = Grid1.GetRowFromClientId(itemId);
        // Check if value was changed
        var oldValue = row.GetMember(columnField).Value;
        if (oldValue != newValue)
        {
        // Get column index for SetValue
            var col = 0;
            for (var i=0;i<Grid1.Table.Columns.length;i++)
            {
                if (Grid1.Table.Columns[i].DataField == columnField)
                {
                    col = i;
                    break;
                }
            }
            row.SetValue(col, newValue, false);
        }
        return true;
    }



function editGridItem(id)
{
   // msg.innerHTML = "open " + id;
   //openUser(id);
    
}

function BuyGridItem(ProductID)
{

    ant = document.getElementById("antall" + ProductID);
//    msg.innerHTML = "Buy " + ProductID + "antall" + ant.value;
    cbBuy.Callback(ProductID,ant.value);
    
}

