// Detect Client Browser type - code moved to the top of the file
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE6=false;
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
if(isIE)
{
    isIE6 = (navigator.appVersion.indexOf("MSIE 6") != -1) ? true : false;
}
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

eraseSaveCookie();
//*******************************************************
window.document.onkeyup=function()
{
  createSaveCookie();
}
window.document.onclick=function()
{
    doHideSubMenu();
    createSaveCookie();
}
//********************************************************
function openTips(file)
{
    if(file!="")
    {
        var helpfile = "/help/" + file + "help.htm";
	    open(helpfile,"_new","height=500,width=650,location=0,menubar=0,status=0,toolbar=0,scrollbars=1");
	}
	else
	    open("live/tips.htm","_new","height=500,width=650,location=0,menubar=0,status=0,toolbar=0");
}
//*************************************************
function setFocus()
{
	var elem = document.getElementById("userid");
	if(elem!=null)
	{
	    elem.focus();
	}
}
//*************************************************
function editOptions()
{
    var href = "options.aspx";
    if(window.showModalDialog) 
        size = "dialogHeight:640px;dialogWidth:1010px;center:yes;resizeable:no; scroll: no; status:no; dialogLeft: 10px; dialogTop: 10px;"
    else
        size = "height=640px,width=1010px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog) 
   {
        if(window.showModalDialog(href,window,size))
            document.location.href = document.location.href;//forms[0].submit();
   }
   else
        window.open(href,"Options",size);
}
//************************************************
function editAppointmentOptions(p)
{
    var href = "/appointmentoptions.aspx?p=" + p;
    if(window.showModalDialog) 
        size = "dialogHeight:450px;dialogWidth:580px;center:yes;resizeable:no;status:no;"
    else
        size = "height=450px,width=580px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog) 
   {
        if(window.showModalDialog(href,window,size))
            document.location.href = document.location.href;//forms[0].submit();
   }
   else
        window.open(href,"Appointment Options",size);
}

//************************************************
function preview(style, prac, name)
{
    var iframe = document.getElementById("preview");
    if(iframe!=null)
    {
        iframe.src = "index.aspx?p=" + prac + "&style=" + style;
    }
    var previewName = document.getElementById("previewName");
    if(previewName!=null)
    {
        previewName.innerHTML = name + " Preview";
    }
}
var previewWindow = null;
function preview_old()
{
    var list = document.getElementById("listStyles2");
    var style = list.options[list.selectedIndex].value;
    if(style=="" && previewWindow)
    {
        previewWindow.close();
        previewWindow=null;
        return;
    }
    var pracid = "";
    var pracLabel = document.getElementById("pracid");
    pracid = pracLabel.innerText;
    
    var href = document.location.href;
    var index = href.indexOf("options.aspx");
    var size = "";
    if(index>0)
    {
        href = href.substring(0,index) + "index.aspx";
        href = href + "?p=" + pracid + "&style=" + style;
        size = "height=550px,width=650px,top=10px,left=550px,status=no,toolbar=no,menubar=no,location=no,resizable";
        previewWindow = window.open(href,"Preview",size);
        if(previewWindow)
            previewWindow.focus();
    }
}
//*********************************************
function closePreview()
{
    if(previewWindow!=null)
    {
        previewWindow.close();
        previewWindow=null;
    }
    else
    {
        preview();
        if(previewWindow!=null)
        {
            previewWindow.close();
            previewWindow=null;
        }
    }   
}

//***********************************************
function openForPrinting()
{
	var href = document.location.href;
	if(href.indexOf("?")>0)
		href += "&print=1";
	else
		href += "?print=1";
	window.open(href,"_blank");
}
//***********************************************
function checkForSave()
{
    if(readSaveCookie()==1)
    {
        var ret = confirm("Discard your changes?");
        if(ret)
            eraseSaveCookie();
        return ret; 
    }
    else
    {
        return true;
    }        
}
//*************************************************
function createSaveCookie()
{
    var enc = document.URL;
    if(enc.indexOf('_form')>0)
    {
	    var date = new Date();
	    date.setTime(date.getTime()+(30*60*1000));
	    document.cookie = "msw_save=1; expires=" + date.toGMTString() + "; path=/";
	}
}
//************************************************
function readSaveCookie() 
{
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') 
		    c = c.substring(1,c.length);
		if (c.indexOf("msw_save=") == 0) 
		    return c.substring(9,c.length);
	}
	return 0;
}
//************************************************
function eraseSaveCookie()
{
	var date = new Date();
	date.setTime(date.getTime()-(30*60*1000));
	document.cookie = "msw_save=0; expires=" + date.toGMTString() + "; path=/";
}
//************************************************
function doFalse()
{
    return false;
}
//**********************************************
function autoRefresh(href,nTime)
{
    setTimeout('jumpTo("' + href + '")', nTime);
}
//**********************************************
function jumpTo(href)
{
    document.location.href=href;
}
//*********************************************
function fadeDetails(elemId1,elemId2)
{
	//Get the element
	var elem1 = document.getElementById(elemId1);
	var elem2 = document.getElementById(elemId2);
	if( (elem1!=null) && (elem2!=null) && (elem1.filters) && (elem2.filters))
	{
		elem1.style.filter="blendTrans(duration=2)";
		elem2.style.filter="blendTrans(duration=2)";
	    elem1.filters[0].Apply();
	    elem2.filters[0].Apply();
	    elem1.style.visibility="visible";
	    elem2.style.visibility="hidden";
	    elem1.filters[0].Play();
	    elem2.filters[0].Play();
	}
	else
	{
	    elem1.style.visibility="visible";
	    elem2.style.visibility="hidden";
	}
}
//***********************************************
function openRepeat(id)
{
    var href = "repeat.aspx?pid=" + id
    if(window.showModalDialog) 
        size = "dialogHeight:580px;dialogWidth:600px;center:yes;resizeable:no;status:no"
    else
        size = "height=580px,width=600px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
        document.location.href=document.location.href;
   }
   else
        window.open(href,"Repeat",size);
}
//***********************************************
function openRepeat1(id)
{
    var href = "repeat1.aspx?pid=" + id
    if(window.showModalDialog) 
        size = "dialogHeight:500px;dialogWidth:600px;center:yes;resizeable:no;status:no"
    else
        size = "height=500px,width=600px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
   }
   else
        window.open(href,"Repeat",size);
}
//***********************************************
function openTest(id)
{
    var href = "test.aspx?tid=" + id
    if(window.showModalDialog) 
        size = "dialogHeight:500px;dialogWidth:600px;center:yes;resizeable:no;status:no";
    else
        size = "height=500px,width=600px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
        document.location.href=document.location.href;
   }
   else
        window.open(href,"Test Result",size);
}
//***********************************************
function openAppointment(id)
{
    var href = "appointment.aspx?pid=" + id
    if(window.showModalDialog) 
        size = "dialogHeight:540px;dialogWidth:600px;center:yes;resizeable:no;status:no"
    else
        size = "height=540px,width=600px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        if(window.showModalDialog(href,window,size))
            document.location.href=document.location.href;
   }
   else
        window.open(href,"Appointment",size);
}

//***********************************************
function openBmi(w,h)
{
    var href = "bmi.aspx?w=" + w + "&h=" + h;
    if(window.showModalDialog) 
        size = "dialogHeight:580px;dialogWidth:570px;center:yes;resizeable:no;status:no";
    else
        size = "height=580px,width=570px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
   }
   else
        window.open(href,"Body Mass Index",size);
}
//*********************************************
function addToFavourites(thepage,thetitle)
{
    if(window.external)
    {
        window.external.Addfavorite(thepage,thetitle);
    }
    else
    {
        alert("You are using a browser that does not support adding to Favourites by script. Please add this page manually");
    }
}
/**********************************************/
function resetCounter()
{
    if(window.confirm("Are you sure you want to reset the counter?\r\nThis action cannot be undone."))
    {
        document.location.href = document.location.href + "&re=1";
    }
}
    /**********************************************/
function deleteInfoContent()
{
    var elem = document.getElementById("title1");
    elem.value="";
    FTB_API["field1"].DeleteContents();
    alert("Press Save Changes to complete the deletion of this page");
}
//*********************************************
function prescriptionHelp()
{
    var href = "/help/prescriptions_help.htm";
    if(window.showModalDialog) 
        size = "dialogHeight:500px;dialogWidth:500px;center:yes;resizeable:no;status:no"
    else
        size = "height=500px,width=500px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
   }
   else
        window.open(href,"Prescriptions Help",size);
}
//***********************************************
function prescriptionHelpLogon()
{
    var href = "/help/prescriptions_help_logon.htm";
    if(window.showModalDialog) 
        size = "dialogHeight:600px;dialogWidth:500px;center:yes;resizeable:no;status:no"
    else
        size = "height=600px,width=500px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
   }
   else
        window.open(href,"Prescriptions Help",size);
}
//***********************************************
function appointmentsHelp()
{
    var href = "/help/appointments_help.htm";
    if(window.showModalDialog) 
        size = "dialogHeight:290px;dialogWidth:400px;center:yes;resizeable:no;status:no"
    else
        size = "height=290px,width=400px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
        document.location.href=document.location.href;
   }
   else
        window.open(href,"Prescriptions Help",size);
}
//***********************************************
function disable(field1)
{
    var elem = document.getElementById(field1);
	if(elem!=null)
	{
	    elem.disabled=true;
	}
}
//***********************************************
function enable(field1)
{
    var elem = document.getElementById(field1);
	if(elem!=null)
	{
	    elem.disabled=false;
	}
}
//**********************************************
function checkLength(checkField,outputField,vLength){
    var b = document.getElementById(checkField); 
    var v = document.getElementById(outputField);
    if(b.value.length>vLength)
        v.innerHTML = "<p>Comments are limited to " + vLength + " characters. You have typed " + b.value.length + ". If you continue, your comment will be truncated</p>";
    else
        v.innerHTML = "<p>&nbsp;</p>";
    return true;
}
//*********************************************
function addLink(fieldId)
{
    if(window.showModalDialog) 
    {
       var href = "uploader.aspx?di=1";
       var size = "dialogHeight:340px;dialogWidth:580px;center:yes;resizeable:no;help:no;status:no";
       var ret = window.showModalDialog(href,window,size);
       if(typeof(ret)!='undefined' && ret != "")
       {
           var index = ret.indexOf("|");
           var link="";
           var title="";
           var align="none";
           if(index>0)
           {
               link = ret.substring(0,index);
               ret = ret.substring(index+1);
               index = ret.indexOf("|");
               if(index>=0)
               {
                    title = ret.substring(0,index);
                    if(index>=0)
                    {
                        align = ret.substring(index+1);
                    }
               }
               if(link!="")
               {
                    //paste into the rich text field
                    var FreeTextBox = document.getElementById(fieldId);
                    if (FreeTextBox!=null) {
                        if(link.length>4 && 
                        ((link.substring(link.length-4).toLowerCase()==".jpg")||
                         (link.substring(link.length-4).toLowerCase()==".gif")||
                         (link.substring(link.length-4).toLowerCase()==".png")))
                            FTB_API[FreeTextBox.id].InsertHtml("<img style=\"float: " + align + ";\" src=\"" + link + "\" alt=\"" + title + "\" /> ");
                        else
                            FTB_API[FreeTextBox.id].InsertHtml("<a style=\"float: " + align + ";\" target=\"_blank\" href=\"" + link + 
                            "\" title=\"" + title + "\">" + title + "</a> ");
                    }
                    else
                        alert("Cannot find text editor!");
                }
            }
        }
     }
     else
        alert("Your browser does not support this functionality");
}
//*********************************************
function EmptyFTB(fieldId)
{
    var FreeTextBox = document.getElementById(fieldId);
    if (FreeTextBox!=null)
    {
        FreeTextBox.value="";
        FTB_API[FreeTextBox.id].value="";
    }
}
//*********************************************
function addStaffPicture()
{
    if(window.showModalDialog) 
    {
       var href = "uploader.aspx?di=2";
       var size = "dialogHeight:260px;dialogWidth:580px;center:yes;resizeable:no;help:no;status:no";
       window.showModalDialog(href,window,size);
       document.forms[0].submit();//document.location.href = document.location.href;
     }
     else
        alert("Your browser does not support this functionality");
}

//***********************************************
function openActivationPage(id)
{
    if(window.showModalDialog)
    {
        var href = "activate.aspx?p=" + id
        if(window.showModalDialog) 
            size = "dialogHeight:240px;dialogWidth:600px;center:yes;resizeable:no;status:no"
        else
            size = "height=240px,width=600px,status=no,toolbar=no,menubar=no,location=no";
       window.showModalDialog(href,window,size);
    }
     else
        alert("Your browser does not support this functionality");
}
//**************************************************
//News
//**************************************************
var maxh = 0;
var pause=0;
var stop=0;
var dataobj;
var nTimeId=0;
function NewsScrollStart(current)
{
    clearTimeout(nTimeId);
    dataobj=document.getElementById("newfeed" + current)
    if(dataobj!=null)
    {
        maxh = dataobj.scrollHeight;
        maxh = dataobj.scrollHeight;
        maxh -= dataobj.offsetHeight;
        if(maxh>0)
        {
            NewsScrollGo();
        }
    }
}
//***************************************************
function PrescriptionScrollStart()
{
    clearTimeout(nTimeId);
    dataobj=document.getElementById("prescriptionsAnnouncementsItem")
    if(dataobj!=null)
    {
        maxh = dataobj.scrollHeight;
        maxh = dataobj.scrollHeight;
        maxh -= dataobj.offsetHeight;
        if(maxh>0)
        {
            NewsScrollGo();
        }
    }
}
//***************************************************
function NewsScrollGo()
{
    dataobj.scrollTop=0;
    nTimeId = setTimeout("NewsScrollNewsDiv()",1000 );
}

//***************************************************
function NewsScrollReset()
{
    if(stop==0 && pause==0)
    {
        dataobj.scrollTop=dataobj.scrollTop-10;
        if(dataobj.scrollTop>0)
        {
            nTimeId=setTimeout("NewsScrollReset()",10)
        }
        else
        {
            nTimeId=setTimeout("NewsScrollNewsDiv()",1000)
        }
    }
    else
        nTimeId=setTimeout("NewsScrollReset()",1000)
  
}
//***************************************************
function NewsScrollNewsDiv()
{
    if(stop==0 && pause==0)
    {
        dataobj.scrollTop=dataobj.scrollTop+1;
        if(dataobj.scrollTop>=maxh)
        {
            nTimeId=setTimeout("NewsScrollReset()",2000)
        }
        else
        {
            nTimeId=setTimeout("NewsScrollNewsDiv()",50)
        }
    }
    else
        nTimeId=setTimeout("NewsScrollNewsDiv()",1000)
}
//***************************************************
//***************************************************
//***************************************************
function shownewfeed()
{
    //read the current value
    var el = document.getElementById("newfeedslist");
    if(el!=null)
    {
        var v = el.value;
        var current="0";
   	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') 
		        c = c.substring(1,c.length);
		    if ((c.indexOf("newfeed=") == 0) && (c.length>8))
		        current = c.substring(8,c.length);
	    }
        //save the value in the cookie
        var date = new Date();
        date.setTime(date.getTime()+(30*60*1000));
        document.cookie = "newfeed=" + v + "; expires=" + date.toGMTString() + "; path=/";
        var a = document.getElementById("newfeed" + current);
        if(a!=null)
        {
            a.style.visibility="hidden";
            a = document.getElementById("newfeed" + v);
            if(a!=null)
            {
                a.style.visibility="visible";
                a.setAttribute("top","-200px");
                NewsScrollStart(v);
            }
        }  
    } 
}
/****************************************/
function clearText(tb)
{
    if(tb)
        tb.value="";
}
function resetText(tb,dt)
{
    if(tb && tb.value=="")
        tb.value=dt;
}
/***************************************/
function closeWindow() 
{
    if(!isIE)
    {
        alert("Your browser is preventing this window from being closed.\r\nPlease close it using the menu in the normal way.");
    }
    else
    {
        window.close();
    }
}
//***********************************************
function openComment(pvar)
{
    var href = "https://www.mysurgerywebsite.co.uk/secure/contact_dlg.aspx?p=" + pvar;
    if(window.showModalDialog) 
        size = "dialogHeight:550px;dialogWidth:570px;center:yes;resizeable:no;status:no"
    else
        size = "height=550px,width=570px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
   { 
        window.showModalDialog(href,window,size);
   }
   else
        window.open(href,"Comment",size);
}
//***********************************************
var min=100;
var max=105;
var tags = ["div","p","td","h1","h2","h3"];
function increaseFontSize()
{
    function doIncrease()
    {
        doToggle("0");
    }
    doIncrease();
    setTimeout(doIncrease,1000);
}
//************************************
function toggleFontSize() 
{
   var cook = readfontCookie();
    if(cook=="0")
   {
        createfontCookie();
   }
   else
   {
        erasefontCookie();
   }
   doToggle(cook);
}
//***********************************
function doToggle(cook)
{
   for(t=0;t<tags.length;t++)
   {
       var p = document.getElementsByTagName(tags[t]);
       for(i=0;i<p.length;i++) 
       {
        if((p[i].className!="pracName")&&(p[i].className!="pracByline"))
        {
              if(p[i].style.fontSize && (p[i].style.fontSize.indexOf("px")>0)) 
              {
                 var s = parseInt(p[i].style.fontSize.replace("px",""));
                 if(cook=="0")
                 {
                    s += 2;
                 }
                 else 
                 {
                    if(s>12)
                        s -= 2;
                 }
                 p[i].style.fontSize = s+"px"
              } 
              else 
              {
                if(cook=="0")
                {
                    p[i].style.fontSize = "103%"
                }
                else
                {
                    p[i].style.fontSize = ""
                }
              }
           }
       }
   }
}
//*************************************************
function createfontCookie()
{
    var date = new Date();
    date.setTime(date.getTime()+(30*60*1000));
    document.cookie = "msw_font=1; expires=" + date.toGMTString() + "; path=/";
    var el = document.getElementById("toggleFont");
    if(el)
        el.innerHTML="<div id=\"toggleFont\"><a href=\"javascript:toggleFontSize();\"><img style=\" border:none;\" src=\"/images/text_standard.gif\" alt=\"Decrease the text size\" /></a></div>";
}
//************************************************
function readfontCookie() 
{
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') 
		    c = c.substring(1,c.length);
		if (c.indexOf("msw_font=") == 0) 
		    return c.substring(9,c.length);
	}
	return "0";
}
//************************************************
function erasefontCookie()
{
	var date = new Date();
	date.setTime(date.getTime()-(30*60*1000));
	document.cookie = "msw_font=0; expires=" + date.toGMTString() + "; path=/";
	var el = document.getElementById("toggleFont");
	if(el)
        el.innerHTML="<div id=\"toggleFont\"><a href=\"javascript:toggleFontSize();\"><img style=\" border:none;\" src=\"/images/text_larger.gif\" alt=\"Increase the text size\" /></a></div>";

}
//************************************************
// FLASH Version Handling
// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type - code moved to the top of the file
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
function checkFlashVersion()
{
    // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
    if(!DetectFlashVer(9, 0, 124))//major version 9, minor version 0, revision 124
    {
        alert('This content requires the Adobe Flash Player version 9 or later.\r\n' + 
   	            'To download Flash visit www.adobe.com/go/getflash');
    }
}
//********************************************
function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
//**************************************************************
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			} else if (versionRevision[0] == "b") {
				versionRevision = versionRevision.substring(1);
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}
	return flashVer;
}
//**************************************************************
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
// END FLASH Version Handling
//********************************************************
function showMenu(id)
{
	var elem = document.getElementById("subMenu" + id);
	if(elem!=null)
	{
	    elem.style.visibility="visible";
	}
}
function showMenu(id)
{
	var elem = document.getElementById("subMenu" + id);
	if(elem!=null)
	{
	    elem.style.visibility="hidden";
	}
}
function toggleTranslate()
{
    var v = document.getElementById('google_translate_element');
    if(v.style['visibility']=="visible")
        v.style['visibility']="hidden";
    else
        v.style['visibility']="visible";    
}
function googleTranslateElementInit() 
{
    new google.translate.TranslateElement({ pageLanguage: 'en'}, 'google_translate_element');
    document.getElementById('google_translate_element').style['visibility']="hidden";
}
    
//**********************************
//Alcohol calculator
//********************************************************
function openAlcoholCalc()
{
    var href = "/alcohol.aspx"
    if(window.showModalDialog) 
        size = "dialogHeight:400px;dialogWidth:650px;center:yes;resizeable:no;status:no"
    else
        size = "height=400px,width=650px,status=no,toolbar=no,menubar=no,location=no";
   if(window.showModalDialog)
        window.showModalDialog(href,window,size);
   else
        window.open(href,"Alcohol Units Calculator",size);
}
//*******************************
var subMenu_elem=null;
//*******************************
// called by onmouseout on the submenu item
function hideSubMenu(e)
{
    try{
        if (!e) var e = window.event;
        //check the target to make sure it is the submenu item
	    var tg = (window.event) ? e.srcElement : e.target;
	    if ((tg.nodeName != 'UL') && (tg.nodeName != 'LI')&&((tg.nodeName != 'DIV'))) 
	    {
	        return;
	    }
        //ensure it is not moving onto an element within itself
	    var reltg = (e.relatedTarget ? e.relatedTarget : e.toElement);
        while (reltg != tg && reltg.nodeName && reltg.nodeName != 'FORM')
        {
            reltg = reltg.parentNode
        }
        if (reltg == tg) 
        {
            return;
        }
        doHideSubMenu();	
    }
    catch(e){
    }
}
//*******************************
function doHideSubMenu()
{
    if(subMenu_elem && (subMenu_elem.style.visibility!="hidden"))
    {
        subMenu_elem.style.visibility="hidden";
        if(isIE6)//deal with the news dropdown
        {
            var n = document.getElementById("newfeedslist");
            if(n)
               n.style.visibility="visible";
        }
    }
}
//*******************************
//Called by a menu item with children
function showSubMenu(s,e)
{
    if(s!='')
    {
        //check the target to make sure it is a menu item    
        if (!e) var e = window.event;
	        var a = (window.event) ? e.srcElement : e.target;
        var p = a.parentNode;        	        
        if(a.nodeName!='A' && p.nodeName != 'LI')//got to be from the menu item link
        {
            return;
        }
        var gp = p.parentNode;
        //if another one is already lit switch it off
        if((subMenu_elem)&&(subMenu_elem.id != s)&&(subMenu_elem.style.visibility!="hidden"))
        {
            subMenu_elem.style.visibility="hidden";
        }
        //Get the sub menu to show        
        subMenu_elem = document.getElementById(s);
        if(subMenu_elem)
        {
            if(subMenu_elem.style.visibility!="visible")
            {
                var location = Sys.UI.DomElement.getLocation(p);
                //for absolute menus do not offset the floating menu
                var newy=location.y;
                var newx=0;
                if((getStyle(gp.parentNode,"position")=="absolute"))
                {
                    newx = p.offsetWidth-10;//absolute menu would never be a horizontal menu
                    newy -= Sys.UI.DomElement.getLocation(gp).y;
                }
                else if(getStyle(document.getElementById("container"),"position")=="relative")//check container style
                {
                    newx = p.offsetWidth-10;//absolute menu would never be a horizontal menu
                }                
                else
                {
                    newy = location.y;
                    if(gp.offsetWidth < 300)
                    {
                        newx = location.x + p.offsetWidth - 10;
                     }
                     else
                        newx = location.x;//wide menus are horizontal menus and should not be pushed across to the right
                 }
                subMenu_elem.style.top = newy + 'px';
                subMenu_elem.style.left = newx + 'px';
                if(isIE6)//deal with the news dropdown
                {
                    var n = document.getElementById("newfeedslist");
                    if(n)
                    {
                        var l = Sys.UI.DomElement.getLocation(n);
                        var r = newx + subMenu_elem.offsetWidth;
                        var b = newy + subMenu_elem.offsetHeight;
                        if((r >= l.x) && (newx <= (l.x + n.offsetWidth)) &&
                           (b >= l.y) && (newy <= (l.y + n.offsetHeight)))
                            n.style.visibility="hidden";
                    }
                }
                subMenu_elem.style.visibility="visible";
            }
        }
    }
}
//**********************************************
// Gets the style of the element - not just the inline style
function getStyle(el,styleProp)
{
	if (el.currentStyle)
		var y = el.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	return y;
}
//*********************************************
function printRequests()
{
    var cbId = 1;
    var cb = document.getElementById("ucheck" + cbId);
    var idOut="";
    while(cb != null)
    {
        if(cb.checked)
            idOut = idOut + "~" + cb.value;
        cbId++;
        cb = document.getElementById("ucheck" + cbId);
    }
    
    cbId = 1;
    cb = document.getElementById("pcheck" + cbId);
    
    while(cb != null)
    {
        if(cb.checked)
            idOut = idOut + "~" + cb.value;
        cbId++;
        cb = document.getElementById("pcheck" + cbId);
    }
    
    if(idOut!="")
        window.open("repeatsprint.aspx?docs=" + idOut);
    else
        alert("First select the repeat requests that you wish to print.");
}
//********************************
var uToggle=false;
var pToggle=false;
function checkAll(b)
{
    var bCheck=true;
    if(b=='u')
    {
        if(uToggle)
        {
            bCheck=false;
        }
        uToggle=!uToggle;
    }
    else
    {
        if(pToggle)
        {
            bCheck=false;
        }    
        pToggle=!pToggle;
    }
        
    var cbId = 1;
    var cb = document.getElementById(b + "check" + cbId);
    while(cb != null)
    {
        cb.checked=bCheck;
        cbId++;
        cb = document.getElementById(b + "check" + cbId);
    }
}