function visible(section)
{
    var elementSection = document.getElementById(section);
            
    if(elementSection.style.display == 'none')
    {
    elementSection.style.display = '';
     }
     else{
     elementSection.style.display = 'none';
     }
    }

    function isVisible(section)
    {
        var elementSection = document.getElementById(section);
        return (elementSection.style.display == 'none');
    }


// script handles dirty data checking and help text framework

// variables used in this script
var clicks = new Array();
var lastClickIndex = 0;
var onClickHandler = null;
var arrElements = new Array();
var frmToProcessElements;

// 
function OnLinkClick()
{
    if (onClickHandler != null)
    {
        return onClickHandler();
    }

    return true;
}

// When an onclickhandler is set in the current page, attach a click event to all 
//elements in the menu and the main body of the document (wrapper)
function AssignEvents()
{
    if (onClickHandler != null)
    {
        /*AssignControlEvents(document.getElementById('masterTopContentDiv'));*/
        AssignControlEvents(document.getElementById('aspnetForm'));
    }
}
            
// Loops through LINKS and BUTTONS in the page adding an onclick handler where not excluded     
function AssignControlEvents(controlHolder)
{
    var links = controlHolder.getElementsByTagName("A");
    for (i = 0; i < links.length; i++)
    {
        var oldClick = links[i].onclick;
        if (oldClick != null)
        {
              clicks[lastClickIndex] = links[i].onclick;
              links[i].setAttribute("index", lastClickIndex);
              lastClickIndex ++;
        }

        links[i].onclick = function() {
                                            if (this.getAttribute("mark") == null)
                                            {
                                                if (OnLinkClick() == false)
                                                {
                                                    return false;
                                                }
                                            }
                                            if (this.getAttribute("index") != null)
                                            {
                                                if (clicks[this.getAttribute("index")] != null)
                                                {
                                                    return clicks[this.getAttribute("index")]();
                                                }
                                            }
                                            return true;
                                       };
    }
    if(frmToProcessElements == null)
    {
        return;
    }
    
   var clicksSubmit = new Array();
   var lastClickIndexSubmit = 0;
   var buttons = controlHolder.getElementsByTagName("input");
    for (i=0;i<buttons.length;i++)
    {
        if (buttons[i].type == "submit")
        {
            var oldClick = buttons[i].onclick;
            if (oldClick != null)
            {
                  clicksSubmit[lastClickIndexSubmit] = buttons[i].onclick;
                  buttons[i].setAttribute("index", lastClickIndexSubmit);
                  lastClickIndexSubmit ++;
            }
            buttons[i].onclick = function() {
                                           if (this.getAttribute != null)
                                           {
                                          // look for the class name "handlerExclude" and also the deprecated "mark" attribute  
                                                if ((this.getAttribute("mark") == null)
                                                     && (this.className.indexOf("handlerExclude") == -1))
                                                {
                                                    if (OnLinkClick() == false)
                                                    {
                                                        return false;
                                                    }
                                                }
                                                if (this.getAttribute("index") != null)
                                                {
                                                    if (clicksSubmit[this.getAttribute("index")] != null)
                                                    {
                                                       return clicksSubmit[this.getAttribute("index")]();
                                                    }
                                                }
                                            }
                                                return true;
                                           };

        }
    }
}

// APPEARS NOT TO BE USED       
/*function SetButtonEvent(owner) 
 {
        if (owner.getAttribute("mark") == null)
        {
            if (OnLinkClick() == false)
            {
                return false;
            }
        }
        if (owner.getAttribute("index") != null)
        {
            if (clicks[owner.getAttribute("index")] != null)
            {
                return clicks[owner.getAttribute("index")]();
            }
        }
        return true;
   }*/

//Save the form elements on load for comparison later
function LoadElements()
{ 
    // Save all the form elements so that they can be checked for changes at the end
    frmToProcessElements = document.forms[0].elements;
    for (i=0;i<frmToProcessElements.length;i++)
        {
        if ((frmToProcessElements[i].type != "hidden")&&(frmToProcessElements[i].type != "button")&&(frmToProcessElements[i].type != "submit"))
            {
            if ((frmToProcessElements[i].type == "radio")||(frmToProcessElements[i].type == "checkbox"))
                {
                if (frmToProcessElements[i].checked == true)
	                {arrElements[i] = frmToProcessElements[i].value;}
                else
	                {arrElements[i] = "";}
                }
                else
                {
                arrElements[i] = frmToProcessElements[i].value;
                }
            } 
        }
   }
	            
	           
// Method checks to see if any form elements have been changed
function DirtyDataChecker()
{
    for (i=0;i<frmToProcessElements.length;i++)
        {
        if ((frmToProcessElements[i].type != "hidden")&&(frmToProcessElements[i].type != "button")&&(frmToProcessElements[i].type != "submit"))
            {
            if ((frmToProcessElements[i].type == "radio")||(frmToProcessElements[i].type == "checkbox"))
                {
                if (frmToProcessElements[i].checked == true)
	                {
	                if (arrElements[i] != frmToProcessElements[i].value)
		                { return true;}
	                }	
	                else
	                {
	                if (arrElements[i] != "")
		                { return true;}
	                }
                }		
            else
                {
                if (arrElements[i] != frmToProcessElements[i].value)
	                { return true;}
                }
            }	
        }
    return false;	// Data not changed
}


// Method sets up the help text framework.
function addHelp()
{
	var strID, objHelp;
	
	if (document.getElementById && document.appendChild && document.removeChild)
	{

		if(!document.getElementById('aspnetForm')) { return; }		

		var objHelpform = document.getElementById('aspnetForm');
		var objAnchors = objHelpform.getElementsByTagName('a');
		
		
		for (var iCounter=0; iCounter<objAnchors.length; iCounter++)
		{
			if (objAnchors[iCounter].id.indexOf('helplink') > -1) // only work with the helplink links
			{
			
			    //alert(objAnchors[iCounter].id); // debugging - printing the matching anchor ids
				
				strID = getIDFromHref(objAnchors[iCounter].href);
				objHelp = document.getElementById(strID);
				
				objHelp.style.display = 'none';
		        
				objAnchors[iCounter].onclick = function(event){return expandHelp(this, event);}			//add onClick event to anchor
				objAnchors[iCounter].onkeypress = function(event){return expandHelp(this, event);}		//add onKeypress event to anchor
		
				objAnchors[iCounter].parentNode.appendChild(objHelp);				
			}
		}
		
		var objOldnode = document.getElementById('helpTextContainer');
		
		if(objOldnode){
		objOldnode.parentNode.removeChild(objOldnode);
		}
		objHelpform = null;	// Release objects
		objHelp = null;
		objAnchors = null;
	}
}

// helper method to work out the ID of the help text from the href on the link
function getIDFromHref(strHref)
{
	var iOffset = strHref.indexOf('#') + 1;
	var iEnd = strHref.length;

	return strHref.substring(iOffset, iEnd);
}


// Method called when opening a Help text link
function expandHelp(objAnchor, objEvent)
{
	// get the id of the help icon within the link that was clicked
	/*var helpImageContainerName = getIDFromHref(objAnchor.href);  
	helpImageContainerName = helpImageContainerName.replace('text', 'link');  //
	var helpImageContainer = document.getElementById(helpImageContainerName);
	var objHelpImage = helpImageContainer.firstChild;*/
	//
	
	var iKeyCode;

	if (objEvent && objEvent.type == 'keypress')
	{
		if (objEvent.keyCode)
			iKeyCode = objEvent.keyCode;
		else if (objEvent.which)
			iKeyCode = objEvent.which;
		
		if (iKeyCode != 13 && iKeyCode != 32)
			return true;
	}

	strID = getIDFromHref(objAnchor.href);
	objHelp = document.getElementById(strID);

	if (objHelp.style.display == 'none')
		{
		objHelp.style.display = 'block';
		objHelp.setAttribute('class', 'help');
		//objHelpImage.setAttribute('src','images/helpiconcancel.gif');  // if the text is being shown, change to the cancel image
        }
	else
		{
		objHelp.style.display = 'none';
		//objHelpImage.setAttribute('src','images/helpicon.gif');   // if the text is being hidden, change to the default image
        }
	return false;
}


// image swap function to replace all images with filename ending "_nm" with equivalent file ending "_hv" on mouseover
function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) { 
//Do not delete these comments. 
//Non-Obtrusive Image Swap Script V1.1 by Hesido.com 
//Attribution required on all accounts 

    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
                } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}

