var PageIsSizing=false;
var SequenceStarted=false;

var TotalStock=0;


var BskRTV, BskStockID, BskBtnTitle, BskSellString;




var __isIE =  navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox && 
   (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;

function __parseBorderWidth(width) {
    var res = 0;
    if (typeof(width) == "string" && width != null 
                && width != "" ) {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
             //do not know how to calculate other 
             //values (such as 0.5em or 0.1cm) correctly now
             //so just set the width to 1 pixel
            res = 1; 
        }
    }
    return res;
}

//returns border width for some element
function __getBorderWidth(element) {
    var res = new Object();
    res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
    if (window.getComputedStyle) {
        //for Firefox
        var elStyle = window.getComputedStyle(element, null);
        res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));  
        res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));  
        res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));  
        res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));  
    }
    else {
        //for other browsers
        res.left = __parseBorderWidth(element.style.borderLeftWidth);
        res.top = __parseBorderWidth(element.style.borderTopWidth);
        res.right = __parseBorderWidth(element.style.borderRightWidth);
        res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
    }
   
    return res;
}

//returns absolute position of some element within document
function getElementAbsolutePos(element) {
    var res = new Object();
    res.x = 0; res.y = 0;
    if (element !== null) {
        res.x = element.offsetLeft;
        res.y = element.offsetTop;
        
        var offsetParent = element.offsetParent;
        var parentNode = element.parentNode;
        var borderWidth = null;

        while (offsetParent != null) {
            res.x += offsetParent.offsetLeft;
            res.y += offsetParent.offsetTop;
            
            var parentTagName = offsetParent.tagName.toLowerCase();    

            if ((__isIE && parentTagName != "table") || 
                (__isFireFoxNew && parentTagName == "td")) {            
                borderWidth = __getBorderWidth(offsetParent);
                res.x += borderWidth.left;
                res.y += borderWidth.top;
            }
            
            if (offsetParent != document.body && 
                offsetParent != document.documentElement) {
                res.x -= offsetParent.scrollLeft;
                res.y -= offsetParent.scrollTop;
            }

            //next lines are necessary to support FireFox problem with offsetParent
               if (!__isIE) {
                while (offsetParent != parentNode && parentNode !== null) {
                    res.x -= parentNode.scrollLeft;
                    res.y -= parentNode.scrollTop;
                    
                    if (__isFireFoxOld) {
                        borderWidth = __getBorderWidth(parentNode);
                        res.x += borderWidth.left;
                        res.y += borderWidth.top;
                    }
                    parentNode = parentNode.parentNode;
                }    
            }

            parentNode = offsetParent.parentNode;
            offsetParent = offsetParent.offsetParent;
        }
    }
    return res;
}
function ShowTips(ID)
{
   if(document.getElementById("Pop"+ID).abbr != "")
   {
   var Location;
   
   Location = getElementAbsolutePos(document.getElementById("Pop"+ID));
   document.getElementById("ToolInfo").innerHTML = document.getElementById("Pop"+ID).abbr;
   document.getElementById("ToolInfo").style.left = Location.x+80;
   document.getElementById("ToolInfo").style.top = Location.y-30;
   document.getElementById("ToolInfo").style.visibility = "visible";
   document.getElementById("ToolInfo").style.zIndex = "100";

   Location = getElementAbsolutePos(document.getElementById("ToolInfo"));
   }
}
function HideTips()
{
   document.getElementById("ToolInfo").style.visibility = "hidden";
}


//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com


var message="You are unable to right click on this site!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")



// window.onresize=StartResize;

function CheckValidEmail(ID)
{
    var testresults;
    var str=document.getElementById(ID).value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(str))
       testresults=true;
    else{
	   alert("You have entered an INVALID Email Address, Please try again");
       testresults=false;
    }
    return testresults;
}

function SubmitAERego(RTV)
{
   var Name, Email, Path;
   
   Name = document.getElementById("Name");
   if(Name.value == "")
   {
      alert("You have not entered your name, please try again");
	  return;
   }
   Email = document.getElementById("Email");
   if(!CheckValidEmail("Email"))
      return;
   
   Path = "freenews.asp?rtv="+RTV+"&ab=1&N="+Name.value+"&E="+Email.value;
   // alert(Path);
   window.location=Path;
}
function EmptyBasket(CustID)
{
   if(confirm("EMPTY BASKET\n\nPlease Confirm that you want to empty your shopping basket"))
   {
      window.location = "chkbsk.asp?rtv="+CustID+"&bka=99b";
   }
}
function RemoveFromBasket(ItemID, CustID)
{
   var Objtxt;
   
   Objtxt = document.getElementById("cell"+ItemID); 
   if(confirm("Please confirm that you want to remove the following from your basket\n\n"+Objtxt.title))
   {
      // window.location = "chkbsk.asp?rtv="+CustID+"&bka=99a"+"&I="+Objtxt.alt;
      window.location = "amswh.asp?AEV=LSB&rtv="+CustID+"&bka=99a"+"&I="+Objtxt.alt;
   }
}
function SetStyle(LineID)
{
   var ObjItem;
   
   ObjItem = document.getElementById("item"+LineID);
   if(ObjItem == null)
   {
      alert("Error getting input object");
	  return;
   }
   if(ObjItem.value != "" && parseInt(ObjItem.value) > 0)
   {
      ObjItem.style.background = "#0000a0";
	  ObjItem.style.color = "#ffff00";
	  ObjItem.style.fontWeight = "bold";
   }
   else
   {
      ObjItem.value = "";
      ObjItem.style.background = "#ffffff";
	  ObjItem.style.color = "#000000";
	  ObjItem.style.fontWeight = "normal";
   }
}
function PurchaseGoods(RTV, CID, RSC, StockID, BtnTitle, SellString, SID)
{
    var Temp, Item, s,e, length, ObjName, ObjID;
	var basketpath, TotalItems;
	
	BskRTV = RTV;
	BskStockID = StockID;
	BskBtnTitle = BtnTitle;
	BskSellString = SellString;
	
	//if(SID == "Pass")
	   basketpath="amsstock.asp?rtv="+RTV+"&CID="+CID+"&rsc="+RSC+"&S="+StockID+"&ba=sa";
	//else
	//{
	   // basketpath="amssl.asp?rtv="+RTV+"&CID="+CID+"&rsc="+RSC+"&SID="+SID+"&ba=sa";
	   //basketpath="amssl.asp?rtv="+RTV+"&CID="+CID+"&rsc="+RSC+"&SID="+SID+"&ba=sa";
	//}   
	Temp = SellString;
	length = Temp.length;
	s = 0;
	e = 0;
	Item="Customer ID: "+RTV+"\n\n";
	TotalItems=0;
	while(e < length)
	{
	   s = Temp.indexOf("[",s);
	   if(s == -1) break;
	   e = Temp.indexOf("]",s);
	   if(e == -1) break;
	   ObjName = Temp.substring(s+1,e); 
	   ObjID = document.getElementById(ObjName);
	   if(ObjID.value != "" && ObjID.value > 0)
	   {
	      Item += "ID:"+StockID+":"+ObjID.name+" - "+ObjID.value+" x "+BtnTitle+" @ $"+ObjID.alt+" = $"+ObjID.value*parseFloat(ObjID.alt)+"\n";
		  basketpath+="&L"+TotalItems+"="+ObjID.name+"&Q"+TotalItems+"="+ObjID.value;
		  TotalItems++;
	   }
	   s = e;
	}
	if(TotalItems > 0)
	{
	   basketpath+= "&TI="+TotalItems;
	   window.location = basketpath;
       //alert(basketpath);
	}
}
function SwapImage(ctrlID, Image)
{
   ctrlID.src = "pics/menu/"+Image+".gif";
}
function CellOver(ctrlID, Image)
{
   if(ctrlID != 0)
      SwapImage(ctrlID, Image+"On");
   return 'navCellOn';
}
function CellOut(ctrlID, Image)
{
   if(ctrlID != 0)
      SwapImage(ctrlID, Image+"Off");
   return 'navCellOff';
}
function LoadStockPage(CustID, CatType, CatID, RSC)
{
   if(CatType == "Home") // Home Page
   {
	  window.location="default.asp?rtv="+CustID;
   }
   if(CatType == "GiftCert") // Gift Certificate
   {
	  window.location="giftcert.asp?rtv="+CustID;
   }
   if(CatType == "Specials") // Gift Certificate
   {
	  window.location="specials.asp?rtv="+CustID;
   }
   if(CatType == "Sub") // Load Sub Menu
   {
	  window.location="amsbw.asp?rtv="+CustID+"&CID="+CatID+"&rsc="+CatID;
   }
   if(CatType == "Page") // Load Stock Page
   {
	  window.location="amsstock.asp?rtv="+CustID+"&CID="+CatID+"&rsc="+RSC;
   }
   if(CatID == 15) // Newsletters
   {
	  window.location="newsletter.asp?rtv="+CustID;
   }
   if(CatID == 88) // Check Basket
   {
	  window.location="chkbsk.asp?rtv="+CustID;
   }
   if(CatID == 89) // Order
   { 
	  window.location="order.asp?rtv="+CustID;
   }
   if(CatID == 90) // Free Newsletter
   {
	  window.location="freenews.asp?rtv="+CustID;
   }
   if(CatID == 91) // Contact
   {
	  window.location="contact.asp?rtv="+CustID;
   }
   if(CatID == 95) // Register
   {
	  window.location="register.asp?rtv="+CustID;
   }
   if(CatID == 96) // Signin
   {
	  window.location="signin.asp?rtv="+CustID;
   }
   if(CatID == 154) // Signout
   {
	  window.location="default.asp";
   }
   if(CatID == 155) // Account Details
   {
	  window.location="amsad.asp?rtv="+CustID;
   }
}
function GetTotalStock()
{
   return TotalStock;
}
function SetTotalStock(Total)
{
   TotalStock = Total;
}
function IsResizing()
{
   if(PageIsSizing == true)
   {
      PageIsSizing=false;
      setTimeout("IsResizing()",0);
   }
   //alert("Sizing has stopped");
   PageIsSizing=false;
   SequenceStarted=false;
   //SetContainerSizes();
}
function StartResize()
{
   if(PageIsSizing == false)
   {
      PageIsSizing=true;
      if(SequenceStarted == false)
	  {
	     SequenceStarted=true;
		 IsResizing();
	  }
   }
}
function GetBrowserHeight()
{
  if (document.all)
    return document.body.clientHeight;
  else
    return window.innerHeight;
}
function GetBrowserWidth()
{
  if (document.all)
    return document.body.clientWidth;
  else
    return window.innerWidth;
}
function ShowDimensions()
{
   alert("Width: "+GetBrowserWidth()+"\nHeight: "+GetBrowserHeight());
}
function SetContainerSizes()
{
   var width, height;
   var ObjDiv;

   SetInfoProd();
   
   width = GetBrowserWidth();
   height = GetBrowserHeight();

   ObjDiv = document.getElementById("AMSBody");
   if(width <= 800)
      width=800;
   ObjDiv.style.width = width-7;

   width = width-353-157-40;

   ObjDiv = document.getElementById("AMSTMPanel");
   ObjDiv.style.width = width;
   
   ObjDiv = document.getElementById("AMSMainForm");
   
   if (parseInt(navigator.appVersion)>3)
   {
      if (navigator.appName=="Netscape")
	  {
        //width = window.innerWidth;
		height = ObjDiv.innerHeight;
      }
      if (navigator.appName.indexOf("Microsoft")!=-1) {
	     height = ObjDiv.offsetHeight+54;
      }
   }
   height = ObjDiv.offsetHeight+54;
   
   document.getElementById("AMSMenu").style.height = height;
}
function SetInfoProd()
{
   var loop, ObjInfo, ObjProd, ObjTitle, InfoY, ProdY;
   
   for(loop=0;loop<GetTotalStock();loop++)
   {
      ObjInfo = document.getElementById("Info"+loop);
	  ObjProd = document.getElementById("Prod"+loop);
	  ObjTitle = document.getElementById("Title"+loop);
	  
	  if(ObjInfo == null) return;
	  
      if(parseInt(navigator.appVersion) > 3)
      {
         if(navigator.appName.indexOf("Microsoft")!=-1)
	     {
		    InfoY = ObjInfo.offsetHeight+ObjTitle.offsetHeight;
			ProdY = ObjProd.offsetHeight;
	        if(InfoY > ProdY)
		       ObjProd.style.height = InfoY;
         }
         else
	     { 
	        if(ObjInfo.style.pixelHeight > ObjProd.style.pixelHeight)
		      ObjProd.style.height = ObjInfo.style.pixelHeight+document.getElementById("Title"+loop).style.pixelHeight;
		    else 
		       ObjInfo.style.height = ObjProd.style.pixelHeight-document.getElementById("Title"+loop).style.pixelHeight;
         }
      } 
   }
}

