
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;
}


var isClicked = null;
var locked = false;


function swapImage(imgName, state)
{
	if(isLoaded){
		//alert(document[imgName].src)
		document[imgName].src = eval(imgName + "_" + state + ".src");
	}
}


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
	{
	}
}