/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function ntokens(value, token) {

    var count = 0;

    var i = value.indexOf(token,0);
	while (i!=-1) {
        count++;
        i = value.indexOf(token,i+1);
    }

    return count;
	
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function parse(value,token,element) {
	var n = ntokens(value,token);
    var j = 0;
    var result = "";
    var w = false;
    
    if ((n != 0) && (element <= n) && (element > 0)) {
    	for (i=0;i < value.length;i++) {
        	if (value.charAt(i) == token) {
            	j++;
            }
            
            if (j == element) {

                if (value.charAt(i) != token) {
                	result = result + value.charAt(i);
                }
            }
            
            if (j > element) { break; }
        }
    }
    return result;
} 

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE: 			to perform menu panel show transformation using an IFRAME shimming technique(as described by Joe King on 
					http://dotnetjunkies.com to circumvent the way MSIE handles the position of certain elements over certain form elements.  
                    NOTE: this technique, while theoretically able to work with any element type, using a table style
                     of menu structure will circumvent any mouse event bubbling.  See menu.html for a sample structure in this folder.
                     
                    
                    !NOTE! an iframe object must exist at the body level to enable the shim to travel the active browser window.
                    !NOTE! all style requirements for the panel and the shim (iframe) must be inline with the element.  
                    For some odd reason, external descriptors will not works with this iframe shim technique.    
                    
                    Since padding in inclusive of the dimension of the element, the padding of the parents must be taken into
                    account when determine where to place the panel.  Also, if the panel's parent is within the boundaries
                    of a container element (div), then the position of the container must also be taken into account when positioning
                    the panel and it's iframe shim.
                    
                    !FUTURE! - To enable the panel to appear in any of the 4 directions (top, bottom, left, right) of the object, a new
                    parameter value of direction (stringType) could be implemented.  The current design allows the child object
                    to appear below the parent object.  
                    
                    
                    
                    
panelID:			the element ID of the panel to display.  
panelParentID:      the element ID of the "parent" element that causes the panel to launch.
containerID:	    top level container of the panelParentID
panelShimID:		the iframe element ID.  Will always exist
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH 
modified: JMCGRATH - added directional reference. 5 possible values, default, top, left, bottom, right (default=bottom)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function panelShow(panelID, panelParentID, containerID,  panelShimID, location) {
	    
        // fine-tune adjusters. verticle and horizontal adjusters.
    	var vAdj = 0;
        var hAdj = 0;
    
    	var panel = document.getElementById(panelID);
        var shim = document.getElementById(panelShimID);
        var parent = document.getElementById(panelParentID);
        var container = document.getElementById(containerID);
        
        /* when obtaining padding style information from any document element, if the value has not been set then
           it will, as a default, return a zls (zero length string).  If they are set then a string, including the
           units used will be returned.  Note!  This method will only work with direct (px) or relational (em).  Ems are
           converted to px and then rounded down, using the parseInt function (1em = 16px).  As the relation of em changes 
           dependant on browser, it, in theory, should automatically resize. 
           
           Since offsets are not style related, a cardinal value starting @ 0 will always be returned, but must have px 
           appended to the final value. */
           
        var parentlpad = parent.style.paddingLeft; 
        var parentrpad = parent.style.paddingRight;
        var parenttpad = parent.style.paddingTop;
        var parentbpad = parent.style.paddingBottom;
        
        var containerlpad = container.style.paddingLeft;  
        var containerrpad = container.style.paddingRight;
        var containertpad = container.style.paddingTop;
        var containerbpad = container.style.paddingBottom;
        
        var parentw = parent.offsetWidth;
        var parenth = parent.offsetHeight;
        var parentt = parent.offsetTop;
        var parentl = parent.offsetLeft;
        
        var containerw = container.offsetWidth; 
        var containerh = container.offsetHeight;
        var containert = container.offsetTop;
        var containerl = container.offsetLeft;
        
		if (parentlpad == "") { parentlpad = "0px"; }
        if (parentrpad == "") { parentrpad = "0px"; }
        if (parenttpad == "") { parenttpad = "0px"; }
        if (parentbpad == "") { parentbpad = "0px"; }
        
        if (containerlpad == "") {containerlpad = "0px";}
        if (containerrpad == "") {containerrpad = "0px";}
        if (containertpad == "") {containertpad = "0px";}
        if (containerbpad == "") {containerbpad = "0px";}
        
		if (parentlpad.indexOf("em") == -1) { parentlpad = parseInt(parentlpad); } else { parentlpad = parseInt(parentlpad) * 16; } 
        if (parentrpad.indexOf("em") == -1) { parentrpad = parseInt(parentrpad); } else { parentrpad = parseInt(parentrpad) * 16; }
        if (parenttpad.indexOf("em") == -1) { parenttpad = parseInt(parenttpad); } else { parenttpad = parseInt(parenttpad) * 16; }
        if (parentbpad.indexOf("em") == -1) { parentbpad = parseInt(parentbpad); } else { parentbpad = parseInt(parentbpad) * 16; }
        
       	if (containerlpad.indexOf("em") == -1) { containerlpad = parseInt(containerlpad); } else { containerlpad = parseInt(containerlpad) * 16; } 
        if (containerrpad.indexOf("em") == -1) { containerrpad = parseInt(containerrpad); } else { containerrpad = parseInt(containerrpad) * 16; }
        if (containertpad.indexOf("em") == -1) { containertpad = parseInt(containertpad); } else { containertpad = parseInt(containertpad) * 16; }
        if (containerbpad.indexOf("em") == -1) { containerbpad = parseInt(containerbpad); } else { containerbpad = parseInt(containerbpad) * 16; }

        if (location == "default" || location == "bottom") {
        	panel.style.top = parentt + parenth + containert - parentbpad - parenttpad - vAdj + "px";
        	panel.style.left = parentl + parentlpad + containerlpad + "px";
        } else if (location == "left") {
       		panel.style.left = containerl + parentl + parentw + "px"; 
            panel.style.top = parentt + parenth + containert + "px";
            /* removed containert */
        }
        
        panel.style.visibility = "visible";
        
        shim.style.top = panel.style.top;
        shim.style.left = panel.style.left;
        shim.style.height = panel.offsetHeight + "px";
        shim.style.width = panel.offsetWidth + "px";
        shim.style.zIndex = panel.style.zIndex - 1;
       	shim.style.display = "block";         
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function panelHide(panelID, panelShimID) {

	var panel = document.getElementById(panelID);
	var shim = document.getElementById(panelShimID);
                
	panel.style.visibility = "hidden";	
	shim.style.display = "none";
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:      		to swap an image.
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function swimg(elementID, imagePath) {
	document.getElementById(elementID).src = imagePath;
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function swcol(elementID, color) {
	document.getElementById(elementID).style.backgroundColor = color;
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:   			to process action requests for server/database/client interactivity.  This is what I would consider the
					achillies heel of the application as it requires javascript to be enabled on the browser... a definite requirement.
                    Actually, so are cookies because session data is stored client side as opposed to server sidee.
                    
                    The basic requirements of for this script to work are as follows:
                    An input field contained within the referenced form called METHOD
                    An input field contained within the referenced form called PARAMETERS
 					
                    METHOD can be set to the following values:
                    launch_ScheduleEditor;
                    launch_ScheduleLoader;
                    load_Schedule;
                    launch_EventEditor;
                    (note, there is not launch_EventLoader because the EventLoader is a components of the ScheduleEditor)
                    save_Schedule;
                    save_Event;
                    delete_Schedule;
                    delete_Event;
                    duplicate_Schedule;
                    duplicate_Event;
                    
                    
                    
                     
PARAMETER:          
RETURNS/SET:  		

MODIFICATION HISTORY:
started: #date# - JMCGRATH

THIS METHOD OF FORM HANDLING BEEN DEPRECATED IN FAVOR OF STANDARD FORM HANDLING METHODS....
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
function methodHandler(formID, method, parameters) {
    
    if (formID != "") {
    	var form = document.getElementById(formID);
    }
    
    var e_method = document.getElementById("METHOD"); 
    var e_parameters = document.getElementById("PARAMETERS");

    e_method.value = method;
    e_parameters.value = parameters;
    
    if (formID != "") {
    	form.submit();
    }
}          


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function smenu(event, element) {
	var div = document.getElementById(element);
	var shim = document.getElementById("shim");
	
	div.style.display = "block";
	shim.style.top = div.style.top;
	shim.style.left = div.style.left;	  
	shim.style.height = div.style.height;
	shim.style.width =	div.style.width;
	shim.style.zIndex = div.style.zIndex - 1;
	shim.style.display = "block";
	
}

function position(event,launcher,element) {
	
	var div = document.getElementById(element);
	var parent = document.getElementById(launcher);
	var shim = document.getElementById("shim");
	
	var x = event.clientX;
	var y = event.clientY;
	var hide = false;
	
	var yrange = parseInt(parent.offsetTop) + parseInt(parent.offsetHeight) + parseInt(div.offsetHeight); 
	
	if (y >= parseInt(parent.offsetTop) && y < (parseInt(parent.offsetTop) + parseInt(parent.offsetHeight))) {	
		if (x <= parseInt(parent.offsetLeft) || x >= (parseInt(parent.offsetLeft) + parseInt(parent.offsetWidth))) {
			hide = true;
		}
	} else if (y < parseInt(parent.offsetTop)) {
		hide = true;
	} 
	

	
	if (y > parseInt(div.offsetTop) && y < (parseInt(div.offsetTop) + parseInt(div.offsetHeight))) {  
		if (x <= parseInt(div.offsetLeft) || x >= (parseInt(div.offsetLeft) + parseInt(div.offsetWidth))) {
			hide = true;
		}
	} else if (y >= (parseInt(div.offsetTop) + parseInt(div.offsetHeight))) {	 
		hide = true;
	}
	
	
	
	if (hide == true) {
		div.style.display = "none";
		shim.style.display = "none";
	}
	
}


function panelVis(action, elementID) {
	var elm = document.getElementById(elementID);
	
	if (action=="show") {
		elm.style.zIndex = 2;
		elm.style.display = "block";	
	} else {
		elm.style.display = "none";	
	}
}		 

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
function highlightTableRow(tableName, rowIndex, optionSwitch) {
				
	var onColor="#235BC3";
	var offColor="#151616";
	var row = document.getElementById(tableName).rows[rowIndex];
	var cell;
			
	for (cell in row.cells) {
		var xID=row.cells[cell].id;
		if (xID != undefined && xID != "") { 
			if (optionSwitch=="on") {
				document.getElementById(xID).style.backgroundColor=onColor;
			} else {
				document.getElementById(xID).style.backgroundColor=offColor;
			} 
		}
	} 
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - JMCGRATH
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
function swapImage(id, newSrc) {
	var current = document.getElementById(id);
	current.src = newSrc;
}

function swapReelImage(id, newSrc, avail) {
        if (avail=="unrestricted") {
                swapImage(id,newSrc);
                swapImage("availability","images/blankavail.jpg");
        } else if (avail=="restricted") {
                swapImage(id,newSrc);
                swapImage("availability","images/limitedavail.jpg");
        }
}


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE: switches divs on and off when the associated title is clicked
PARAMETER:
RETURNS/SET:

MODIFICATION HISTORY:
started: #date# - GWATSON
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function showDiv(id) {
	if (document.getElementById(id)) {
	    var obj=document.getElementById(id);
	    obj.style.display=(obj.style.display=="none")? "block" : "none";
	}
}


function show(id) {
	if (document.getElementById(id)) {
	    var obj=document.getElementById(id);
	    obj.style.display="block";
	}
}

function hide(id) {
	if (document.getElementById(id)) {
	    var obj=document.getElementById(id);
	    obj.style.display="none";
	}
}


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE: switches all divs of class = divClass to open or closed
PARAMETER:divClass = the class name of the desired div target group.
RETURNS/SET:
if display: none - sets display: block and vice versa


MODIFICATION HISTORY:
started: #date# - GWATSON
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

function show_hideAll(divClass) {
	var faqList = new Array();
	faqList=document.getElementsByTagName('div');
	var objArray = new Array();
	var k = 0;
		
	for (i=0;i<faqList.length;i++) {
		if (faqList[i].className == divClass) {
			objArray[k] = faqList[i];
			k++;
		}
	}
	
	if (objArray[0].style.display == "none") {
		for (j=0;j<objArray.length;j++){
			objArray[j].style.display = "block";
		}	
	} else {
		for (j=0;j<objArray.length;j++){
			objArray[j].style.display = "none";
		}
	}
}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
PURPOSE:		pops a new window fullscreen, for given url and moves focus to the new window. Any other calls to popit() change the popit window, rather than opening a new window alltogether
PARAMETER:		var url -> the url for the new window's page 
RETURNS/SET:	

MODIFICATION HISTORY:
started: # OCT 26/06 # - GWatson
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
		
function popit(url) {
	if (!fullScreen.closed && fullScreen.location) { 
		fullScreen.location.href = url;				 
	} 
	else {
		fullScreen=window.open(url,'galleryPopup','width=600, height=500, resizable=yes, status=yes, top=50, left=50');
		
	}
	if (window.focus) {fullScreen.focus;}
	return false;
}
