function kH(e)
{
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
function AllowEnter(evt, tb,focusButton) {
    var charCode = evt.charCode || evt.keyCode;
    if (charCode == 13) {
        var fb = document.getElementById(focusButton).focus();
        window.forms[0].submit();
        return true;
    }
}
function OpenDetail(which)
{
var detail=document.getElementById("Detail"+which);
var summary=document.getElementById("Summary"+which);
var button=document.getElementById("more"+which);
button.style.display='none';
detail.className="fsShow";
summary.className="fsSumOpen";
}
function CloseDetail(which)
{
var detail=document.getElementById("Detail"+which);
var summary=document.getElementById("Summary"+which);
var button=document.getElementById("more"+which);
button.style.display='inline';
detail.className="fsHide";
summary.className="fsSumClosed";
}

function SetTab()
{
var tabId = document.getElementById("lTab").value;
var tab=document.getElementById("Tab"+tabId);
if(tab!=null) tab.src="images/Tab"+tabId+"_H.jpg";
}

function Over(which)
{
var tabID = "Tab"+which;
var tab=document.getElementById(tabID);
tab.src="images/"+tabID+"_O.jpg";
}

function Leave(which)
{
var tabID = "Tab"+which;
var tab=document.getElementById(tabID);
var tabSel = document.getElementById("lTab").value;
if(tabSel==which)
tab.src="images/"+tabID+"_H.jpg";
else
tab.src="images/"+tabID+".jpg";
}
function OpenGDA()
{
var GDAdiv = document.getElementById("pGDAGraphic");
GDAdiv.style.display="inline";
}
function CloseGDA()
{
var GDAdiv = document.getElementById("pGDAGraphic");
GDAdiv.style.display="none";
}

function HW(ddl)
{
	var type = ddl.selectedIndex;
	var hwSpan = document.getElementById("hw");
	var hw = hwSpan.getElementsByTagName("img")[0];
	var ind = hw.src.indexOf("Type=");
	var sub = hw.src.substring(0,ind+5);
	hw.src = sub+type;
}

function isNumberKey(evt,tb)
{
    
    var charCode = evt.charCode || evt.keyCode;
    //ie 103
    if ((charCode == 84 || charCode == 116) && tb.id.indexOf("NM")>=0) {
        tb.value = "Tr";
        //alert("changing value to tr returning false");
        return false;
    }
    else {
        if (charCode > 31 && (charCode < 45|| charCode > 57 || charCode == 47)) {
            //alert("{MAIN} hit an alpha so returning false");
            return false;
        }
        else if (charCode == 46) {
            var substrings = tb.value.split(".");
            x = substrings.length - 1;
            if (x > 0) {
                //    alert("hit another decimal so returning false");
                return false;
            }
        }
        else if (charCode == 45) {
            if (tb.value.indexOf("-") == 0) {
                tb.value = tb.value.substring(1);
                return false;
            }
            else {
                tb.value = "-" + tb.value;
                return false;
            }
        }
        //alert("returning true");
        return true;
    }
    //alert("not returning anything");
}
function isIntKey(evt,tb)
{
	var charCode = evt.charCode || evt.keyCode;
	if(charCode>31 && (charCode <48 || charCode >57) && charCode!=45)
	{
	return false;
	}
	return true;
}
function resize(tb)
{
    
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
		try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if(xmlHttp==null)
	{
		alert("No Ajax Support, sorry");
		return;
	}
	else return xmlHttp;

}
function GetAnotherXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	// Internet Explorer
		try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if(xmlHttp==null)
	{
		alert("No Ajax Support, sorry");
		return;
	}
	else return xmlHttp;

}

function HandleAjaxError(response)
{   
    //alert(response);
}



function OpenLogin(ib)
{
	var panel = document.getElementById("pLogin");
	panel.className="shrink";
	ib.className="hidden";
}
function OpenHelp(im)
{
	var helpMain = document.getElementById("HelpPanel");

	if(im.src.indexOf("morea")>0)
	{
		helpMain.rows[1].className="";
		helpMain.rows[2].className="";
		im.src="../images/lessa.jpg";
		//check we don't go off the page
		var nextButton = document.getElementById("fsNext");
		var leftSide = GetElementLeft(nextButton)+124;
		var topSide = GetElementTop(nextButton)+50;
		SetDimensions();
		//get saved height
		var helpDY = document.getElementById("HelpPanelTBdY").value;
		if(helpDY=="") helpMain.rows[1].cells[0].height=200;
		else
		{
			helpMain.rows[1].cells[0].removeAttribute("height");
			helpMain.style.height=helpDY;
		}
		if(leftSide>winW)
		{
		var newLeft = helpMain.style.left.substring(0,helpMain.style.left.indexOf("px"))*1+winW-leftSide;
		helpMain.style.left= newLeft;
		}
		if(topSide>winH)
		{
		var newTop = helpMain.style.top.substring(0,helpMain.style.top.indexOf("px"))*1+winH-topSide;
		helpMain.style.top = newTop;
		}
	}
	else
	{
		helpMain.rows[1].className="hidden";
		helpMain.rows[2].className="hidden";
		im.src="../images/morea.jpg";
		var helpPanel=document.getElementById("HelpPanel");
		helpMain.style.height=0;
		helpMain.style.width=120;
	}
//dd.recalc();
}

function OpenPanel(id)
{
	var PanelID = id;
	if(id.length>1) PanelID=id.substring(0,1);
	document.getElementById("tbCurrentPanel").value=PanelID;
	var panel = document.getElementById("Panel"+id);
	var im = document.getElementById("i"+id);
	var cb = document.getElementById("cb"+id);
	if(panel.className=="hidden")
	{
	 panel.className="";
	 im.src = "../images/lessa.jpg";
	 cb.checked=true;
	}
	else
	{
	 panel.className="hidden";
	 im.src = "../images/morea.jpg";
	 cb.checked=false;
	 }
	 
	 SetScroll(PanelID);
	 //dd.recalc();
}

function CheckPanels()
{
	for(i=1;i<7;i++)
	{
		var im = document.getElementById("i"+i);
		var pan = document.getElementById("Panel"+i);
		var cb = document.getElementById("cb"+i);
		if(pan!=null)
		{
		if(cb.checked)
		{
			pan.className="";
			im.src = "../images/lessa.jpg";
		}
		else
		{
			pan.className="hidden";
			im.src="../images/morea.jpg";
		}
		}
	}
	//subpanels
	var cb1 = document.getElementById("cb3a");
	var pan1 = document.getElementById("Panel3a");
	var im1 = document.getElementById("i3a");
	if(cb1.checked)
	{
		pan1.className="";
		im1.src = "../images/lessa.jpg";
	}
	else
	{
		pan1.className="hidden";
		im1.src="../images/morea.jpg";
	}
	//set scroll
	var current = document.getElementById("tbCurrentPanel").value;
	if(current!="") SetScroll(current);
	
}

function GetElementLeft(eElement)
{
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}

function GetElementTop(eElement)
{
    var nTopPos = eElement.offsetTop;            // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nTopPos += eParElement.offsetTop;        // appending top offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nTopPos;                              // return the number calculated
}

function SetScroll(id)
{
	var imRight = document.getElementById("right"+id);
	if(!imRight) imRight = document.getElementById(id);
	if(imRight)
	{
	var bRight = GetElementLeft(imRight);
	var bBottom = GetElementTop(imRight);
	if(bRight>winW || bBottom>winH)
	{
		if(bRight<winW)
		{
		scrollLeft=0;
		}
		else {scrollLeft = bRight;}
		if(bBottom<winH) {scrollTop=0;}
		else {scrollTop = bBottom;}
		window.scrollTo(scrollLeft,scrollTop);
	}
	}
}
var winW = 0;
var winH = 0;
function SetDimensions()
{
	if (parseInt(navigator.appVersion)>3)
	{
		if (navigator.appName=="Netscape")
		{
			winW = window.innerWidth-16;
			winH = window.innerHeight-16;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1)
		{
		winW = document.body.offsetWidth-20;
		winH = document.body.offsetHeight-20;
		}
	}
}
function HideWaiting()
{
	var cover = document.getElementById("dWaiting");
	cover.className="hidden";
}
function PreWarning()
{
	var cb = parent.document.getElementById("CheckBox1");
	if(cb.checked)
	{
		document.forms[0].submit();
		window.open("http://www.foodspecifications.com","_parent");
	}
	else
	{
		alert("Please confirm you have read and accepted the Terms and Conditions");
	}
}
function PromDiv() {
    var covDiv = document.createElement("div");
    covDiv.id = "covDiv";
    covDiv.className = "covDiv";
    var promDiv = document.createElement("div");
    promDiv.id = "promDiv";
    promDiv.className = "promDiv";
    document.body.appendChild(promDiv);
    document.body.appendChild(covDiv);
    return promDiv;
}
function FullScreenPrompt(promptText,opts,inps)
{
    var covDiv = document.createElement("div");
    covDiv.id = "covDiv";
    covDiv.className = "covDiv";
    var promDiv = document.createElement("div");
    promDiv.id = "promDiv";
    promDiv.className = "promDiv";
    document.body.appendChild(promDiv);
    document.body.appendChild(covDiv);
    
    var para2 = document.createElement("div");
    para2.setAttribute("align","center");
    para2.innerHTML = promptText+"<br/><br/>";
    promDiv.appendChild(para2);
    
    
    var para1 = document.createElement("P");
    para1.setAttribute("align","center");
    var ft = document.createElement("TABLE");
    ft.id = "prompttable";
    ft.className = "prompttable";
    para1.appendChild(ft);
    for (var inpsx = 0;inpsx<inps.length;inpsx++)
    {
        var inper = inps[inpsx];
        var ftr = ft.insertRow(-1);
        var ftc1 = ftr.insertCell(0);
        ftc1.className = "promptcell";
        if (inper.type == "input") {
            var inpsy = document.createElement("INPUT");
            inpsy.type = "text";
            inpsy.id = "promDiv_" + inpsx;
            inpsy.value = inper.defaultText;
            ftc1.appendChild(inpsy);
            var ftc2 = ftr.insertCell(1);
            ftc2.className = "promptcell";
            ftc2.innerHTML = inper.description;
            if (inper.width != null) inpsy.style.width = inper.width + "px";
            if (inper.readOnly) inpsy.setAttribute("readonly", true);
            if (inper.fbox) {
                if (inper.fbox == 'dec') inpsy.setAttribute("onkeypress", "return isNumberKey(event,this)");
                if (inper.fbox == 'int') inpsy.setAttribute("onkeypress", "return isIntKey(event,this)");
            }
        }
        /*
        else if (inper.type == "span") {
        var inpsy = document.createElement("span");
        inpsy.value = inper.defaultText;
        ftc1.appendChild(inpsy);
        var ftc2 = ftr.insertCell(1);
        ftc2.innerHTML = inper.description;
        }*/
        else if (inper.type == "cb") {
            var inpsy = document.createElement("input");
            inpsy.id = "checkbox_" + inpsx;
            inpsy.type = "checkbox";
            if (inper.itemid != 0) {
                inpsy.onclick = function() { SetVisibility(inper.itemid, inper.item, inpsy); };
            }
            ftc1.appendChild(inpsy);
            ftc1.className = "promptcell";
            var vis = inper.readOnly;
            if (inper.readOnly) {
                inpsy.setAttribute("defaultChecked", "true"); //cos ie6 sucks
            }
            inpsy.checked = vis;
            var ftc2 = ftr.insertCell(1);
            ftc2.className = "promptcell";
            ftc2.innerHTML = inper.description;

        }
    }
    promDiv.appendChild(para1);
    var addBody = document.createElement("div");
    addBody.id = "addBody";
    addBody.className = "hidden";
    promDiv.appendChild(addBody);
    
    var para = document.createElement("P");
    para.setAttribute("align","center");
    for(var ix=0;ix<opts.length;ix++)
    {
        var but = FSButton(opts[ix]);
        para.appendChild(but);
    }
    promDiv.appendChild(para);

    var scr = getScrollXY();
    if (!covDiv) {
        covDiv = document.getElementById("covDiv");
    }
    if(covDiv) covDiv.style.top = scr[1]+"px";
    
    promDiv.style.top = (150+scr[1])+"px";
}
function PromptAction(but,covDiv)
{
    alert(but.value+" "+document.getElementById("tbPrompt").value);
    document.body.removeChild(promDiv);
    document.body.removeChild(covDiv);
}
function FSButton(opts)
{
    var lnk = document.createElement("a");
    lnk.className = "anav";
    lnk.onclick = opts[1];
    lnk.innerHTML = opts[0];
    /*
    iml.setAttribute("onmouseup","MouseOut(this)");
    iml.setAttribute("onmousedown","MouseImage(this)");
    iml.setAttribute("onmouseout","MouseOut(this)");
    iml.setAttribute("onmouseover","MouseOver(this)");
    iml.setAttribute("border","0");
    lnk.appendChild(iml);*/
    return lnk;
}
function Inputter(Description,ReadOnly,Default,Width,Type)
{
    this.description = Description;
    this.readOnly = ReadOnly;
    this.defaultText = Default;
    this.width = Width;
    this.type = Type;
    this.itemid = 0;
    this.item = false;
}

//region xy & scroll
//#region
function GlobalScreen()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var wh = [myWidth,myHeight];
 return wh;
}

function getScrollXY()
{
	var scrOfX = 0;scrOfY = 0;
	if(typeof(window.pageYOffset)=='number') {
	var px = 0;
	var py = 0;
	if (parent.window) {
	    //py = parent.window.pageYOffset;
	    //px = parent.window.pageXOffset;
	    scrOfY = window.pageYOffset + py;
	scrOfX = window.pageXOffset + px;
	}
	
	}
	else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
	{
	scrOfY = document.body.scrollTop;
	scrOfX   = document.body.scrollLeft;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
	scrOfY = document.documentElement.scrollTop;
	scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX,scrOfY];
}
function getXY(oElement)
{
    var iCoOrds = [0, 0, 0, 0];
    if (oElement) {
        iCoOrds = [0, 0, oElement.offsetWidth, oElement.offsetHeight];
        if (oElement.offsetParent) {
            do {
                iCoOrds[0] += oElement.offsetLeft;
                iCoOrds[1] += oElement.offsetTop;
            }
            while (oElement = oElement.offsetParent);

        } 
    }
    return iCoOrds;
}
function getControlXY(oElement)
{
    var iCoOrds = [0,0,oElement.offsetWidth,oElement.offsetHeight];
    
	if (oElement.offsetParent)
	{
        do
        {
	        var xy = [oElement.offsetLeft,oElement.offsetTop];
	        iCoOrds[0] += oElement.offsetLeft;
	        iCoOrds[1] += oElement.offsetTop;
        }
        while (oElement = oElement.offsetParent);
        
    }
    return iCoOrds;
}
function MouseXY(e)
{
    var sXY = [0,0];
    if(e==null)
	{
		sXY[0]=window.event.clientX;
		sXY[1]=window.event.clientY;
	}
	else
	{
		sXY[0] = e.clientX;
		sXY[1] = e.clientY;
	}
	return sXY;
}
function StoreVisit(page)
{
    xmlHttp = GetXmlHttpObject();
	var url = "../AjaxFunctions/StoreVisit.aspx?page="+page;
	xmlHttp.open("GET",url+"&sid="+Math.random(),true);
	xmlHttp.send(null);
}
function ChangeHWIm(ddl,imid)
{
    var pref ="";
    var prefInd = ddl.id.lastIndexOf("_");
    if(prefInd>=0) pref=ddl.id.substring(0,prefInd); 
    var type = ddl.options[ddl.selectedIndex].value;
    var hwim = document.getElementById(pref+"_"+imid);
    var imurl = hwim.src;
    var fid = imurl.substring(imurl.indexOf("&fid="));
    imurl = imurl.substring(0,imurl.indexOf("Type=")+5);
    hwim.src = imurl+type+fid+"&sid="+new Date().getMilliseconds();
    hwim.onload = function(){WaitTillLoaded(hwim);};
    
}
function WaitTillLoaded(hwim)
{
    hwim.style.height="auto";
    hwim.style.width="auto";
    ieminmax();
}
function ieminmax()
{
    var ims = document.getElementsByTagName("img");
    for(var x = 0;x<ims.length;x++)
    {
        var cont = ims[x].parentNode;
        var wheel = ims[x].id.indexOf("Wheel");
        var imhe = ims[x].clientHeight; //proper use of max-height will be nicely ignored
        var imwe = ims[x].clientWidth;
        
        
        if(wheel>=0)
        {
            cont = cont.parentNode.parentNode.parentNode.parentNode.parentNode;
        }
        var divhe = parseInt(cont.style.height);
        var divwe = parseInt(cont.style.width);
        
        
        var multi = 1;
        if(divhe<imhe || divwe<imwe)
        {
            if(imhe/divhe>imwe/divwe) multi = divhe/imhe;
            else multi=divwe/imwe;
        }
        ims[x].style.height = (imhe*multi);
        ims[x].style.width = (imwe*multi);
        
        if(divhe>0 && divhe<imhe)
        {
            if(ims[x].src.indexOf("Type=3")>0)
            {
            ims[x].src = ims[x].src.substring(0,ims[x].src.indexOf("Type="))+"Type=4";
            }
            ims[x].style.height=divhe+"px";
        }
        else if(divwe>0 && divwe<imwe)
        {
            if(ims[x].src.indexOf("Type=3")>0)
            {
                ims[x].src = ims[x].src.substring(0,ims[x].src.indexOf("Type="))+"Type=4";
            }
            ims[x].style.width = divwe+"px";
        }
        else 
        if(ims[x].id.indexOf("imLogo")>=0)
        {
            if(imhe>95) ims[x].style.height="95px";
        }
        //valign
        //var halfpad = (parseInt(cont.style.height) - imhe) / 2;
        //ims[x].style.paddingTop = halfpad + "px";
    }
}
function KillWarning() {
    document.body.removeChild(document.getElementById("divWarning"));
}
function PleaseWait(element) {
    var xy = getXY(element);
    var coverDiv = document.createElement("div");
    coverDiv.id = "tempCover";
    coverDiv.className = "coverDiv";
    document.body.appendChild(coverDiv);
    var im = document.createElement("img");
    im.title = "Please Wait";
    im.src = "~/images/waiting.gif";
    im.className = "waiting";
    im.style.top = xy[1] + "px";
    im.style.left = xy[0] + "px";
    im.id = "tempWaiting";
    document.body.appendChild(im);
}
function KillWaiting() {
    var covdiv = document.getElementById("tempCover");
    covdiv.parentNode.removeChild(covdiv);
    var imwa = document.getElementById("tempWaiting");
    imwa.parentNode.removeChild(imwa);
}
function openIC() {
    var icCell = document.getElementById("icCell");
    var icHead = document.getElementById("icHead");
    var icFoot = document.getElementById("icFoot");
    if (icCell.className == "icTableOpen") {
        icCell.className = "icTableClosed";
        icHead.className = "icTableClosed";
        icFoot.className = "icTableClosed";
        var selects = document.getElementsByTagName("input");
        for (var i = 0; i < selects.length; i++) {
            if (selects[i].type == "select") selects[i].className = "";
        }
    }
    else {
        icCell.className = "icTableOpen";
        icHead.className = "header";
        icFoot.className = "header";
        var selects = document.getElementsByTagName("select");
        for (var i = 0; i < selects.length; i++) {
            if (selects[i].type == "select") selects[i].className = "hidden";
        }

    }
}

//#endregion
function statusmsg(element, position, message, maxWidth, msgtype,fadeduration) {
    var old = document.getElementById("smgspan");
    if (old) old.parentNode.removeChild(old);
    
    var xy = getXY(element);
    var msgspan = document.createElement("div");
    var aspan = document.createElement("span");
    aspan.innerHTML = message;
    msgspan.className = "statmsg " + "statmsg" + msgtype;
    msgspan.style.maxWidth = maxWidth + "px";
    msgspan.id = "msgspan";
    document.body.appendChild(msgspan);
    var arr = document.createElement("img");
    arr.title = "Click Here";
    arr.src = "/images/a" + position + ".png";
    arr.id = "statarr";
    arr.className = "statarr";
    msgspan.appendChild(arr);
    msgspan.appendChild(aspan);
    var ndx = msgspan.offsetWidth;
    var ndy = msgspan.offsetHeight;
    var edx = element.offsetWidth;
    var edy = element.offsetHeight;
    var nx = [0, 0];
    var ix = [0, 0];
    switch (position) {
        case 3:
            nx[0] = xy[0] + (edx * 1.1);
            nx[1] = xy[1] - ndy / 2 + edy / 2;
            ix[1] = xy[1] - (edy / 2)-nx[1];
            ix[0] = -18;
            break;
        case 5: 
            nx[0] = xy[0] + edx / 2 - ndx / 2;
            nx[1] = xy[1] + edy;
            ix[1]=-16;
            ix[0]=ndx/2;
            break;
    }
    msgspan.style.top = nx[1] + "px";
    msgspan.style.left = nx[0] + "px";
    arr.style.top = ix[1] + "px";
    arr.style.left = ix[0] + "px";
    if (!fadeduration) fadeduration = 1000;
    setTimeout("fade('msgspan')", fadeduration);
}
var TimeToFade = 1000.0;
function fade(eid) {
    var element = document.getElementById(eid);
    if (element == null)
        return;

    if (element.FadeState == null) {
        if (element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1') {
            element.FadeState = 2;
        }
        else {
            element.FadeState = -2;
        }
    }

    if (element.FadeState == 1 || element.FadeState == -1) {
        element.FadeState = element.FadeState == 1 ? -1 : 1;
        element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    }
    else {
        element.FadeState = element.FadeState == 2 ? -1 : 1;
        element.FadeTimeLeft = TimeToFade;
        setTimeout("animateFade(" + new Date().getTime() + ",'" + element.id + "')", 33);
    }
}
function animateFade(lastTick, eid) {
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var element = document.getElementById(eid);

    if (element.FadeTimeLeft && element.FadeTimeLeft <= elapsedTicks) {
        element.style.opacity = element.FadeState == 1 ? '1' : '0';
        element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
        element.FadeState = element.FadeState == 1 ? 2 : -2;
        document.body.removeChild(element);
        return;
    }

    element.FadeTimeLeft -= elapsedTicks;
    var newOpVal = element.FadeTimeLeft / TimeToFade;
    if (element.FadeState == 1)
        newOpVal = 1 - newOpVal;

    element.style.opacity = newOpVal;
    element.style.filter = 'alpha(opacity = ' + (newOpVal * 100) + ')';
    setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
