function openFullWindow(url, name, behind, center, menuBar) 
{
    return openWindow(url, name, behind, screen.availWidth, screen.availHeight, center, menuBar);
}

function openWindow(url, name, behind, width, height, center, menuBar) 
{
	var now = new Date();
	var append = "tpa=" + now.getSeconds() + now.getMilliseconds();
	if (url != null)
	{
		if (url.indexOf("?") >= 0) { url = url + "&" + append; }
		else { url = url + "?" + append; }
	} 
	else { url = ''; }
	
	// Initialize Menubar
	if (menuBar == true)
	{
		var opts = 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,';
	}
	else
	{
		var opts = 'toolbar=no,location=no,directories=no,status=false,menubar=no,scrollbars=yes,resizable=yes,';
	}
	
	if (width == null) { width = 800; }
	opts += 'width=' + width + ',';
		
	if (height == null) { height = 600; }
	opts += 'height=' + height + ',';
	
	if (center == true)
	{
		var screenWidth = 480;
		var screenHeight = 340;
		if (document.all || document.layers) 
		{
			screenWidth = screen.availWidth;
			screenHeight = screen.availHeight;
		}
		var left = (screenWidth - width) / 2;
		var top = (screenHeight - height) / 2;
	}
	else 
	{
		var left = 100;
		var top = 40;
	}
	opts += 'left='+left+',top='+top;
	
	// Open window
	win = window.open(url,name,opts);
	if (win == null) { return; }
	
	// Focus
	if (behind == false) { win.focus(); }
	else { parent.focus(); }
	
	return win;
}

function redirect(URL,win) 
{
	// Local Variables
	var sURL = "";
	var sQueryString = ""; 
	var oParams = "";
	var sWinHTML = "";
		
	// Initialize
	if (URL.indexOf("?") >= 0) { sURL = URL.substr(0,URL.indexOf("?")); } else { sURL = URL; }
	if (URL.indexOf("?") >= 0) { sQueryString = URL.substr(URL.indexOf("?") + 1); }
	oParams = sQueryString.split("&");  
	if (win == null) { win = window; }
	
	// Check if dirty validation
	with (win.document) 
	{
		open("text/html", "replace");
		sWinHTML = sWinHTML + "<html><head></head><body onload=\"document.forms[0].submit();\"><form action=\"" + sURL + "\" method=\"post\">\n";
		for (i=0; i<oParams.length; i++) 
		{
			var sName = String(oParams[i].substr(0,oParams[i].indexOf("=")));
			var sVal = String(oParams[i].substr(oParams[i].indexOf("=")+1));
			var rExp = /"/gi;
			var sRep = String('&quot;');
			sName = sName.replace(rExp, sRep);
			sVal = sVal.replace(rExp, sRep);
			sWinHTML = sWinHTML + "<input type=\"hidden\" name=\"" + sName + "\" value=\"" + sVal + "\">\n";
		}	
		sWinHTML = sWinHTML + "</form></body></html>";
		write(sWinHTML);
		
		close();
		
		if (closed == true) { focus(); }
	}
}

function onImageDisplayFullsize(oImage)
{
	// Local Variables
	var oForm = document.frmProcess;						// Form Object
		
	// Display full image
	openWindow(oImage.src.replace("_thumb", ""), "imageDisplayFullSize", false, null, null, true, false);
}
		
function onWindowCancel(oWindow)
{
    // Validation
    if (oWindow == null) { return; }
    
    // Cancel
    oWindow.location.reload(true);
}

function onWindowClose(oWindow)
{
    // Validation
    if (oWindow == null) { return; }
    
    // Close the window
    oWindow.close();
}

  /*
    * This function will not return until (at least)
    * the specified number of milliseconds have passed.
    * It does a busy-wait loop.
    */
function JSPause(iNumberMS) 
{
    // Local Variables
    var dtNow = new Date();                                                         // Current date/time
    var dtExitTime = dtNow.getTime() + iNumberMS;                                   // Date/time to exit
    
    // Pause    
    while (true) 
    {
        dtNow = new Date();
        if (dtNow.getTime() > dtExitTime) { return; }
    }
}

function controlFocus(sControlClientID, bScrollIntoView)
{
    // Local Variables
    var ctlFocus = document.getElementById(sControlClientID);                       // Control to focus
    
    // Validation
    if (IsNullOrEmpty(sControlClientID) == true) { return false; }
    if (ctlFocus == null) { return false; }
    
    try 
    { 
        // Focus
        ctlFocus.focus(); 
        
        // Scroll Into View
        if (bScrollIntoView == true) { ctlFocus.scrollIntoView(true); }
    }
    catch(exError) { return false; } 
    
    // Return
    return true;
}

function showControlById(sControlID, bShow)
{
    // Validation
    if (IsNullOrEmpty(sControlID) == true) { return; }

    // Show/Hide Control
    showControl(document.getElementById(sControlID), bShow);
}

function showControl(oControl, bShow)
{
    // Validation
    if (oControl == null) { return; }

    // Show/Hide Control
    if (bShow == true)
    {
        oControl.style.display = "";
    }
    else
    {
        oControl.style.display = "none";
    }
}

function enableControl(oControl, bShow)
{
    // Validation
    if (oControl == null) { return; }

    // Enable/Disable Control
    oControl.enabled = bShow;
}

function onGetElements(oForm, sType, sName)
{
	// Local Variables
	var sReturn = "";													// Return string
	var iElementCounter = 0;											// Element Counter
	
	// Validation
	if (!oForm || oForm == null) { return; }
	if (IsNullOrEmpty(sType) == true) { return; }
	if (IsNullOrEmpty(sName) == true) { return; }
	
	// Get fields
	for(var iCounter = 0; iCounter <= (oForm.elements.length - 1); iCounter++)
 	{
		if (oForm.elements[iCounter].type == sType &&
			oForm.elements[iCounter].name.indexOf(sName) >= 0)
		{
			switch(sType)
			{
				case "checkbox":
					if (oForm.elements[iCounter].checked == true)
					{
						if (iElementCounter != 0) { sReturn += ","; }
						sReturn += oForm.elements[iCounter].value;
						iElementCounter++;
					}
					break;
				default:
					if (iElementCounter != 0) { sReturn += ","; }
					sReturn += oForm.elements[iCounter].value;
					iElementCounter++;
					break;
			}
			
		}
	}
	return sReturn;	
}

function AttachEvent(elementObj, eventName, eventHandlerFunctionName)
{  
    if (elementObj.addEventListener)   
    { // Non-IE browsers    
        elementObj.addEventListener(eventName, eventHandlerFunctionName, false);                             
    }   
    else if (elementObj.attachEvent)   
    { // IE 6+    
        elementObj.attachEvent('on' + eventName, eventHandlerFunctionName);  
    }   
    else   
    { // Older browsers     
        var currentEventHandler = elementObj['on' + eventName];    
        if (currentEventHandler == null)     
        {   
            elementObj['on' + eventName] = eventHandlerFunctionName;    
        }     
        else
        {
            elementObj['on' + eventName] = function(e) { currentEventHandler(e); eventHandlerFunctionName(e); }    
        }  
    }
}

/*
 *  Detach an event
*/
function DetachEvent(oElement, sEventName, oEventHandlerFunctionRef)
{              
    // Validation
    if (oElement == null || IsNullOrEmpty(sEventName) == true || oEventHandlerFunctionRef == null) { return; }
    
    // Remove event
    oElement.detachEvent("on" + sEventName, oEventHandlerFunctionRef);  
}
