// Simple Confirm ...
function SA_ConfirmCancel()
{
	return(confirm('Click OK to Cancel.'));
}
// Set Element Visible=true
function SA_VisualizeElement(ElementID)
	{
	SA_VisualizeObject(document.getElementById(ElementID));
	}
// Set object Visible=true
function SA_VisualizeObject(objItem)
	{
	objItem.style.visibility='visible';
	}
// Set Element Visible=false
function SA_DeVisualizeElement(ElementID)
	{
	SA_DeVisualizeObject(document.getElementById(ElementID));
	}
// Set object Visible=false
function SA_DeVisualizeObject(objItem)
	{
	objItem.style.visibility='hidden';
	}
// Show Element
function SA_ShowElement(ElementID)
	{
	SA_ShowObject(document.getElementById(ElementID));
	}
// Show Object
function SA_ShowObject(objItem)
	{
	objItem.style.display='inline';
	}
// Hide Element...
function SA_HideElement(ElementID)
	{
	SA_HideObject(document.getElementById(ElementID));
	}

// Hide Object...
function SA_HideObject(objItem)
	{
	objItem.style.display='none';
	}
// Show Object Array
function SA_ShowObjectArray(arrObjItems)
	{
	var intIndex;
	for (intIndex=0; intIndex < arrObjItems.length; intIndex++)
		{
		SA_ShowObject(arrObjItems[intIndex]);
		}
	}
// Show Object At Index
function SA_ShowObjectAtIndex(arrObjItems, intIndex)
	{
		SA_ShowObject(arrObjItems[intIndex]);
	}
// Hide Object Array
function SA_HideObjectArray(arrObjItems)
	{
	var intIndex;
	for (intIndex=0; intIndex < arrObjItems.length; intIndex++)
		{
		SA_HideObject(arrObjItems[intIndex]);
		}
	}
// Hide Object At Index
function SA_HideObjectAtIndex(arrObjItems, intIndex)
	{
		SA_HideObject(arrObjItems[intIndex]);
	}
// Set Text...
function SA_SetElementText(ElementID, newText)
	{
	//alert('ElementID: '+ElementID+' New Text: ' + newText);
	document.getElementById(ElementID).innerText=newText;
	//alert('Done with ElementID: '+ElementID+' New Text: ' + newText);
	}

// Toggle Element
function SA_ToggleElementVisible(ElementID)
	{
	if (document.getElementById(ElementID).style.display=='none')
		{
			SA_ShowElement(ElementID);
		}
		else
		{	
			SA_HideElement(ElementID);
		}
	}		

// Hide one Division, Show Another, and Flash a 3rd.
function SA_HideShowFlash(HideElementID, ShowElementID, FlashElementID, FlashSpeed)
	{
		if (FlashSpeed == 0) FlashSpeed = 450;
		if (HideElementID != '') SA_HideElement(HideElementID);		// Hide this Element.
		if (ShowElementID != '') SA_ShowElement(ShowElementID);		// Show this Element
		if (FlashElementID != '')									// If Flash Sub Element Exists, Flash it.
			{
			SA_ShowElement(FlashElementID);
			window.setTimeout('SA_OnHideShowFlash(\'' + FlashElementID + '\',' + FlashSpeed + ');' , FlashSpeed);
			}
	}
	
// Timer Event For HideshowFlash(...)
function SA_OnHideShowFlash(ElementID, FlashSpeed)
	{
	
		SA_ToggleElementVisible(ElementID);
		window.setTimeout('SA_OnHideShowFlash(\'' + ElementID + '\',' + FlashSpeed + ');' , FlashSpeed);
	}	

// Add the class name to the list of classnames for the given element.
function SA_AddObjClassName(objElement,ClassName1)
    {
    var theNames;
    var intIndex;	
	    theNames = objElement.className.split(' ');
	    for (intIndex=0; intIndex < theNames.length; intIndex++)
	        {
	        if (theNames[intIndex].toUpperCase() == ClassName1.toUpperCase())
	            {
	            return;
	            } 
	        }
	    // The ClassName1 was not found w/in the string, so add it.
	    objElement.className = objElement.className + ' ' + ClassName1;
    }	
function SA_AddClassName(ElementID, ClassName1)
    {
    SA_AddObjClassName(document.getElementById(ElementID),ClassName1);
    }	
// Remove the class name from the list of classnames for the given element.
function SA_RemoveObjClassName(objElement, ClassName1)
    {
    var theNames;
    var intIndex;
    var newNames;
	    theNames = objElement.className.split(' ');
	    newNames='';
	    for (intIndex=0; intIndex < theNames.length; intIndex++)
	        {
	        if (theNames[intIndex].toUpperCase() != ClassName1.toUpperCase())
	            {
	            newNames = newNames + ' ' + theNames[intIndex];
	            } 
	        }
	    objElement.className = newNames;
    }
function SA_RemoveClassName(ElementID, ClassName1)
    {
	    SA_RemoveObjClassName( document.getElementById(ElementID),ClassName1);
    }
// Add/Remove the classname from the list of classnames based on a boolean value.
function SA_AddRemoveObjClassNameTF(objElement, TrueOrFalse,ClassName1)
    {
        if (TrueOrFalse == true)
            {SA_AddObjClassName(objElement,ClassName1);}
        else
            {SA_RemoveObjClassName(objElement,ClassName1);}
    }
function SA_AddRemoveClassNameTF(ElementID, TrueOrFalse,ClassName1)
    {
    SA_AddRemoveObjClassNameTF(document.getElementById(ElementID),TrueOrFalse,ClassName1);
    }
// Toggle Element className
function SA_ToggleObjClassName(objElement, ClassName1, ClassName2)
	{
	
	if (objElement.className.toUpperCase() == ClassName1)
		{
			objElement.className = ClassName2;
		}
		else
		{
			objElement.className = ClassName1;
		}
	}	
function SA_ToggleClassName(ElementID, ClassName1, ClassName2)
	{
	SA_ToggleObjClassName(document.getElementById(ElementID),ClassName1,ClassName2);
	}	
	
// Set Element className With Boolean
function SA_SetObjClassNameTF(objElement, TrueOrFalse, ClassNameTrue, ClassNameFalse)
	{
	if (TrueOrFalse == true)
		{
			objElement.className = ClassNameTrue;
		}
		else
		{
			objElement.className = ClassNameFalse;
		}
	}	
function SA_SetClassNameTF(ElementID, TrueOrFalse, ClassNameTrue, ClassNameFalse)
	{
	SA_SetObjClassNameTF(document.getElementById(ElementID),TrueOrFalse,ClassNameTrue,ClassNameFalse);
	}	

// Set className 
function SA_SetObjClassName(objElement,ClassName)
    {
	objElement.className = ClassName;
    }
function SA_SetClassName(ElementID, ClassName)
	{
	SA_SetObjClassName(document.getElementById(ElementID))
	}	

// Exist Current Frame and Open Window on Top...
function SA_OpenTopWindow(TheURL)
	{
	window.open(TheURL,'_top');
	}	
	
function SA_ShowWindow(TheWindow)
	{
	alert(TheWindow.name);
	}
// Set Focus To Element
function SA_SetFocus(ElementID)
	{
	var theElement;
	try {
		theElement = document.getElementById(ElementID);
		theElement.focus();
		}
	catch(er) {/* Do Nothing */}
	}

// Ensure The Current Window Is the Top Frame...
// and Show the ElementID if it is.
// else set the parent location to current location.
function SA_EnsureTopWindow(ElementID)
	{
	if (window.opener != null)
		{
		window.setTimeout('self.close();', 500);
		
		try
		{
			window.opener.location = window.location;
		}
		catch (ex)
		{
			//do nothing..
		}
		
		} 
	else 
		{
		if (window.top != window)
			{
			window.top.location = window.location;
			} 
		else 
			{
			SA_ShowElement(ElementID);
			self.focus();
			}
		}
	}
// Set Element Left Position by an Offset of the Current Scroll Top
function SA_SetElementLeftOffset(ElementID, PixLeft)
	{
	SA_SetElementLeft(ElementID,document.body.scrollLeft+parseInt(PixLeft));
	}
// Set Element Left Position in Pixels
function SA_SetElementLeft(ElementID,PixLeft)
	{
	try {
		document.getElementById(ElementID).style.left=parseInt(PixLeft)+'px';
		innerhtml
		} 
	catch(er) { /* Ignore Errors */}
	}

// Set Element Top Position by an Offset of the Current Scroll Top
function SA_SetElementTopOffset(ElementID, PixTop)
	{
	SA_SetElementTop(ElementID,document.body.scrollTop+parseInt(PixTop));
	}
// Set Element Top Position
function SA_SetElementTop(ElementID,PixTop)
	{
	try {
		document.getElementById(ElementID).style.top=parseInt(PixTop)+'px';
		} 
	catch(er) { /* Ignore Errors */}
	}

// Set Element Top/Left Position
function SA_SetElementTopLeft(ElementID,PixTop,PixLeft)
	{
	SA_SetElementTop(ElementID, PixTop);
	SA_SetElementLeft(ElementID, PixLeft);
	}

// Get Element Top Position
function SA_GetElementTop(ElementID)
	{
	try {
		return parseInt(document.getElementById(ElementID).style.top);
		} 
	catch(er) { /* Ignore Errors */}
	}

// Get Element Width
function SA_GetElementWidth(ElementID)
	{
	try {
		return parseInt(document.getElementById(ElementID).width);
		} 
	catch(er) { /* Ignore Errors */}
	}

// Get Element Left Position
function SA_GetElementLeft(ElementID)
	{
	try {
		return parseInt(document.getElementById(ElementID).style.left);
		} 
	catch(er) { /* Ignore Errors */}
	}

// Begin Progress Rotate Left..
function SA_ProgBar_RotateLeft(csvElements,RotateSpeed)
{
//	csvElements:	Comman Seperated List of Element ID's To Rotate Position
//	RotateSpeded:	# of Miliseconds between rotations. Zero uses Default Speed
var arrElement = csvElements.split(',');
var intIndex;
var intLastLeft;

	if (RotateSpeed == 0) RotateSpeed = 120;

	intLastLeft = SA_GetElementLeft(arrElement[arrElement.length-1]);
	for (intIndex=arrElement.length-1; intIndex > 0; intIndex--)
		{
		SA_SetElementLeft(arrElement[intIndex],SA_GetElementLeft(arrElement[intIndex-1]));
		}
	SA_SetElementLeft(arrElement[0],intLastLeft);
	window.setTimeout('SA_ProgBar_RotateLeft(\'' + arrElement.join(',') + '\',' + RotateSpeed + ');' , RotateSpeed);
}


// Begin Progress Rotate Right..
function SA_ProgBar_RotateRight(csvElements,RotateSpeed)
{
//	csvElements:	Comman Seperated List of Element ID's To Rotate Position
//	RotateSpeded:	# of Miliseconds between rotations. Zero uses Default Speed
var arrElement = csvElements.split(',');
var intIndex;
var int1stLeft;

	if (RotateSpeed == 0) RotateSpeed = 120;
	int1stLeft = SA_GetElementLeft(arrElement[0]);
	for (intIndex=0; intIndex < arrElement.length-1 ; intIndex++)
		{
		SA_SetElementLeft(arrElement[intIndex], SA_GetElementLeft(arrElement[intIndex+1]));
		}
	SA_SetElementLeft(arrElement[arrElement.length-1],int1stLeft);
	window.setTimeout('SA_ProgBar_RotateRight(\'' + arrElement.join(',') + '\',' + RotateSpeed + ');' , RotateSpeed);
}


// Disable A Text Box
function SA_EnableElement(ElementID, Enabled)
	{
	SA_EnableItem(document.getElementById(ElementID),Enabled);
	}

// Disable A Text Box
function SA_EnableItem(Item, Enabled)
	{
	var blnDisabled;
	var ClassName;
	
	try {
		if (Enabled==true)
			{
			blnDisabled=false;
			ClassName='TXT_INPUT';
			}
		else
			{
			blnDisabled=true;
			ClassName='TXT_INPUT_READONLY';
			}
		Item.disabled = blnDisabled;
		Item.className=ClassName;
		}
	catch(er) {/* Do Nothing */}
	}
// Form OnEnterKey	
function SA_ClickButtonOnEnterPressed(objEvent,ElementID)
    {
    try {
        // process only the Enter key
        if (objEvent.keyCode == 13)
        {
            // cancel the default submit
            objEvent.returnValue=false;
            objEvent.cancel = true;
            // submit the form by programmatically clicking the specified button
            document.getElementById(ElementID).click();
        }
        } catch(er) {/* Do Nothing */}
    }
// If the 1st Element in a ddl Is the Value Passed, remove it.
// Usefull for calling on the change event of a ddl to remove the (Select One) option.
function SA_RemoveNullEntry(ElementID, strItem0Value)
	{
	var objList;
	objList = document.getElementById(ElementID);
	if (objList.options.length>0)
		{
		if (objList.options[0].value == strItem0Value && objList.selectedIndex != 0)
			{
			objList.options.remove(0);
			}
		}
	}
// SetVisible Based on True/False

function SA_ShowElementTrue(ElementID, TrueFalse)
	{
	// If True, Show It.
	if (TrueFalse)
		{
		SA_ShowElement(ElementID);
		}
	else
		{
		SA_HideElement(ElementID);
		}
	return TrueFalse
	}
function SA_ShowElementFalse(ElementID, TrueFalse)
	{
	// If True, Hide It.
	if (TrueFalse)
		{
		SA_HideElement(ElementID);
		}
	else
		{
		SA_ShowElement(ElementID);
		}
	return TrueFalse
	}	

// Programataly set controls spacing...
function SA_ProgBar_Align(csvElements,intLeft)
{
//	csvElements:	Comman Seperated List of Element ID's of <Img> Tags to To align
//					Each <Img Tag just have a width=x statement in order to property
//					possition the elements.
//	intLeft:		# Initial Left Value
var arrElement = csvElements.split(',');
var intIndex;
var intWidth;

	for (intIndex=0; intIndex < arrElement.length ; intIndex++)
		{
		SA_SetElementLeft(arrElement[intIndex],intLeft);
		intWidth = SA_GetElementWidth(arrElement[intIndex]);
		intLeft = intLeft + intWidth;
		}
}

