
var layer  = null;
var ns = false;
var ie = false;
var moz = false;
var curr_num = null;
var isLoaded = false;
var div,x,y;
var fx,fy;
var timeoutID = null;




function preLoadImages()
{
	// required line, calls exhibeo init function to
	// initialise editing/saving constructs	
	// comment out when developing new templates when required.
	// "init" is a reserved exhibeo function name, do not use. 

	if (pageAction != "publish")
	{
	    init();
	    convertBookmarks();
    }

	if (document.layers)
	    ns = true;

	if (document.getElementById && !document.all)
	    moz = true;

	if(document.all)
	    ie = true;

	isLoaded = true;
	
	try
	{
	    addHoverStateToList(document.getElementById("menu"));
	}
	catch(e)
	{
	}
}


var isClicked = null;
var locked = false;


function swapImage(imgName, state)
{
	if(isLoaded){
		//alert(document[imgName].src)
		document[imgName].src = eval(imgName + "_" + state + ".src");
	}
}

function getMeThere(in_url, in_intAlert)
{
    var blnOpenPage;
    blnOpenPage = true;
    
    if (in_intAlert == 1)
    {
        blnOpenPage = window.confirm("Thank you for visiting the CSL website.\n\nYou are now leaving our site and accessing other websites.\n\nPlease note:\n\n1.   The information provided on external sites may not comply with current Australian Regulations, Australian readers should refer to the relevant Consumer Medical Information (CMI).\n\n2.   The material provided by other websites is for information and not intended as advice.\n\n3.   Information provided by other websites should be discussed with your health care professional and does not replace their advice.");
    } else if (in_intAlert == 2)
    {
        blnOpenPage = window.confirm("Thank you for visiting the CSL website.\n\nThe information you are about to be referred to may not be approved by the Therapeutic Goods Administration.  Further information relevant to the Australian environment is available from CSL Bioplasma or via the Approved Product Information");
    }
    
    if (blnOpenPage)
    {
        Open(in_url, 800, 600, true, true, true, true);
    }
}

function navTo(in_url, in_blnCheck, in_intDisclaimerType)
{
    var intDisclaimerType, undefined;
    
    if (in_intDisclaimerType == undefined)
    {
        intDisclaimerType = 1
    }
    else
    {
        intDisclaimerType = in_intDisclaimerType
    }
    
    getMeThere(in_url, intDisclaimerType);

}


function Open(url, w, h, isResizeable, hasToolbars, hasAddressbars, hasStatusbars)
{
    var resizeable = isResizeable == true ? 1 : 0;
    var toolbar = hasToolbars == true ? 1 : 0;
    var location = hasAddressbars == true ? 1 : 0;
    var status = hasStatusbars == true ? 1 : 0;
    var x = Number(screen.availWidth / 4);
    var y = Number(screen.availHeight / 4) - 100;
    var win = parent.window.open(url,"","height=" + h + ",width=" + w + ",resizable=" + resizeable + ",location=" + location + ",menubar=" + toolbar + ",status=" + status + ",toolbar=" + toolbar + ",scrollbars=1");

    win.focus();
}


function openPopUp(url,w,h)
{
	var x = screen.availWidth - screen.availWidth;
	var y = screen.availHeight - screen.availHeight;
	var win = parent.window.open(url,"win","width=" + w + ",height=" + h + ",resizable=1,location=1,menubar=0,status=1,toolbar=0,scrollbars=1");
	win.focus();
}


function openPlainPopUp(url,w,h)
{   
    var x = Number(screen.availWidth / 4);
    var y = Number(screen.availHeight / 4) - 100;
    
	var win = window.open(url,"win","width=" + w + ",height=" + h + ",resizable=0,location=0,menubar=0,status=0,toolbar=0,scrollbars=1");
	
	win.focus();
}


function openMgrWin(val)
{
    var loc = "list-all.asp?id=" + val;

    mgrwin = window.open(loc,"mgrwin","height=400,width=400,resizable=0,location=0,menubar=0,status=0,toolbar=0");
    mgrwin.focus();
    mgrwin.moveTo(10,10);
}


function convertBookmarks()
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   convertBookmarks.

    @description    :   this function is a workaround to
                        enable the clicking/display of
                        bookmarks while in exhibeo's preview
                        mode.

                        dynamically changes links that 
                        reference bookmarks directly to reference
                        view.asp, passing in the required parameters
                        to this ASP page to imitate the viewing
                        when using a default parameter (the id).

    @prerequisites  :   see 'description'.

    @argument(s)    :   none.
    @return         :   nothing.
    ----------------------------------------------------
    */

    try
    {
        if ((document.getElementsByTagName == null) || (pageAction == null) || (pageAction.toString().toLowerCase() != "view"))
            return;

        var arrDocumentLinks = document.getElementsByTagName("a");

        var intIndex = 0;
        var intCollectionLength = arrDocumentLinks.length;

        var strLocationToken = "/";
        var strBookmarkToken = "#";

        var strPageLocation = "";
        var strPageBookmarkName = "";

        var strJSToken = "'";
        var strTemp;


        for (; intIndex < intCollectionLength; intIndex++)
        {
            if ((arrDocumentLinks[intIndex].href.indexOf(strBookmarkToken) > 0) && (arrDocumentLinks[intIndex].href.substr(arrDocumentLinks[intIndex].href.indexOf(strBookmarkToken) + strBookmarkToken.length).length > 0))
            {
                strPageLocation = arrDocumentLinks[intIndex].href.substr(arrDocumentLinks[intIndex].href.lastIndexOf(strLocationToken) + strLocationToken.length);
                strPageBookmarkName = strPageLocation.substr(strPageLocation.lastIndexOf(strBookmarkToken) + strBookmarkToken.length);

                strPageLocation = strPageLocation.substr(0, strPageLocation.lastIndexOf(strBookmarkToken));

                if (arrDocumentLinks[intIndex].href.indexOf("javascript:") != -1)
                {
                    strTemp = strPageLocation.substr(strPageLocation.indexOf(strJSToken) + strJSToken.length);
                    arrDocumentLinks[intIndex].href = strPageLocation.substr(0, strPageLocation.indexOf(strJSToken)) + strJSToken + document.location.protocol + "//" + document.location.host + document.location.pathname + "?action=view&pagename=" + strTemp + "#" + strPageBookmarkName;
                }
                else
                    arrDocumentLinks[intIndex].href = document.location.protocol + "//" + document.location.host + document.location.pathname + "?action=view&pagename=" + strPageLocation + "#" + strPageBookmarkName;
            }
        }


        // Free variables.
        strJSToken = null;
        strTemp = null;

        strLocationToken = null;
        strBookmarkToken = null;

        strPageLocation = null;
        strPageBookmarkName = null;

        intCollectionLength = null;
        intIndex = null;
        arrDocumentLinks = null;
    }

	catch (e)
	{
	    alert("Error code:\t" + e.number + "\nError description\t" + e.description + "\nError Location:\t" + "convertBookmarks()");
	}

	finally
	{
	}
}


// add hover state to all list items in IE
function addHoverStateToList(in_nav)
{
	in_nav = in_nav.childNodes[0].childNodes[0];
    if (document.all)
    {
        for (var i = 0; i < in_nav.childNodes.length; i++)
        {
            if (in_nav.childNodes[i].nodeName == "TR")
            {
                var list = in_nav.childNodes[i];
                for (var j = 0; j < list.childNodes.length; j++)
                {
                    if (list.childNodes[j].nodeName == "TD")
                    {
                        if (list.childNodes[j].className == "")
                        {
                            list.childNodes[j].onmouseover = function(){this.className += "over";};
                            list.childNodes[j].onmouseout = function(){this.className = this.className.replace("over", "");};
                        }
                    }
                }
            }
        }
    }
}

