var IS_FIREFOX=false, IS_MOZ=false, IS_MOZ16=false, IS_IE=false;
var IS_IE5=false, IS_IE6=false;
var MIN_MOZ_VERSION = 20040113;
var OLD_DISPLAY_ATTR = "oldDisplayStyle";
var ROW_HIGHLIGHT_COLOR = "#FcE4E0";

if ( navigator.appName=="Netscape" && parseInt(navigator.appVersion) >= 5 )
{
	IS_MOZ = true;
	IS_MOZ16 = ( parseInt( navigator.productSub ) >= MIN_MOZ_VERSION );
	IS_FIREFOX = ( navigator.userAgent.indexOf("Firefox") != -1 );
	if ( !IS_MOZ16 ) alert("This version of Mozilla is out-of-date. Please update your browser at www.mozilla.org");
}
else
{
	IS_IE = true;
	IS_IE5 = ( navigator.appVersion.indexOf("MSIE 5") != -1 );
	IS_IE6 = ( navigator.appVersion.indexOf("MSIE 6") != -1 );
}


function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if ( typeof element == "string" )
			element = document.getElementById(element);
		if ( arguments.length == 1 )
			return element;
		elements.push( element );
	}
	return elements;
}


function appendEvent(pToObject, szEventType, pFunctionHandler)
{
	if ( IS_IE )
	{
		var szNewEventType="on"+szEventType;
		var bSuccess=pToObject.attachEvent(szNewEventType, pFunctionHandler);
	}
	else if ( IS_MOZ )
	{
		var bSuccess=pToObject.addEventListener(szEventType, pFunctionHandler, false);
	}
	else alert("error: function appendEvent called by unrecognized/obsolete browser.");
}

function checkEnterSubmit( szFormId )
{
	if ( event.keyCode == 13 ) document.forms[ szFormId ].submit();
}

function doNothing(){/*for making null links*/}

function debugObject(objectToDebug,isString)
{
	var tempObj=(isString!=null)?(isString)?eval(''+objectToDebug):objectToDebug:objectToDebug;
	var counter=1;
	var modulusCheck=( IS_MOZ )?16:50;
	var alertString='';
	for (x in tempObj)
	{
		var newObjectEntry='Object '+counter+' inside the object '+objectToDebug+' is: '+x+' - value : '+tempObj[x]+'\n';
		alertString+=(newObjectEntry.length<=150)?newObjectEntry:'Object '+counter+' inside the object '+objectToDebug+' is: '+x+' - value : VERY LONG ENTRY\n';
		counter++;
		if (counter%modulusCheck==0)
		{
			alert(alertString);
			alertString='';
		}
	}
	alert(alertString);
}


function flipDisplay( pElemToFlip, szElemIdToFlip )
{
	if ( pElemToFlip != null )
	{
		if ( getCurrStyle( pElemToFlip ).display != "none" )
		{
			pElemToFlip.setAttribute( OLD_DISPLAY_ATTR, getCurrStyle( pElemToFlip ).display );
			pElemToFlip.style.display = "none";
		}
		else
		{
			var szOld = ( pElemToFlip.getAttribute( OLD_DISPLAY_ATTR ) != null ) ? pElemToFlip.getAttribute( OLD_DISPLAY_ATTR ) : "block";
			pElemToFlip.setAttribute( OLD_DISPLAY_ATTR, getCurrStyle( pElemToFlip ).display );
			pElemToFlip.style.display = szOld;
		}
	}
	else
	{
    	try
    	{
    	    var pElem = document.getElementById( szElemIdToFlip );
    	    if ( getCurrStyle( pElem ).display != "none" )
    	    {

    	        pElem.setAttribute( OLD_DISPLAY_ATTR, getCurrStyle( pElem ).display );
    	        pElem.style.display = "none";
			}
			else
			{
				var szAttrVal = pElem.getAttribute( OLD_DISPLAY_ATTR );
				if ( szAttrVal != null )
				{
					pElem.style.display = szAttrVal;
				}
				else pElem.style.display = "block";
			}
		}
		catch(e)
		{
			alert( "standard_lib flipDisplay error:\n" + e.message );
		}
	}
}

function getCurrStyle( pElem )
{
	return ( IS_MOZ ) ? pElem.style : pElem.currentStyle;
}

function getRealLeft( elementName, pElement )
{
	var elemPoint = ( elementName != null ) ? document.getElementById(elementName) : pElement;
	var xPos = elemPoint.offsetLeft;
	tempEl = elemPoint.offsetParent;
	while (tempEl != null)
	{
		xPos += tempEl.offsetLeft - (( tempEl.tagName.toLowerCase() == "body" ) ? 0 : tempEl.scrollLeft );
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getRealTop( elementName, pElement )
{
	var elemPoint = ( elementName != null ) ? document.getElementById(elementName) : pElement;
	var yPos = elemPoint.offsetTop;
	tempEl = elemPoint.offsetParent;
	while (tempEl != null)
	{
		yPos += tempEl.offsetTop - (( tempEl.tagName.toLowerCase() == "body" ) ? 0 : tempEl.scrollTop);
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function getSrcElement( pEvent )
{
	return ( IS_MOZ ) ? pEvent.target : pEvent.srcElement;
}

function hideAllSelects( isHide )
{
	if (!window.hideAllSelectsColl)
	{
		window.hideAllSelectsColl = window.document.getElementsByTagName("select");
	}
	for ( x = 0; x < window.hideAllSelectsColl.length; x++ )
	{
		if ( window.hideAllSelectsColl[x].getAttribute("noHide") != "noHide" )
		{
			window.hideAllSelectsColl[x].style.visibility = ( isHide == true ) ? "hidden":"visible" ;
		}
	}
}

function highlightRow( event, pRowElem, isHighlight )
{
	pRow = pRowElem;//getSrcElement(event);
	if ( isHighlight == 1 )
	{
		var szColorValue = getCurrStyle( pRow ).backgroundColor;
		if ( szColorValue != null )
		{
			pRow.setAttribute( "oldRowColor", szColorValue );
		}
		pRow.style.backgroundColor = ROW_HIGHLIGHT_COLOR;
	}
	else
	{
		var szOldColorValue = pRow.getAttribute("oldRowColor");
		pRow.style.backgroundColor = ( szOldColorValue != null ) ? szOldColorValue : "transparent" ;
	}
}

function setAction( szFormName, szActionValue )
{
	try
	{
		document.forms[szFormName].action.value = szActionValue;
	}
	catch (e) { alert("Document does not contain either form '"+szFormName+"' or an 'action' input element."); }
}

