
// COMMON.JS - www.pricesmart.com

/* GLOBAL VARIABLES */

// Has the current page finished loading?
var g_bLoaded = false;

/* GLOBAL FUNCTIONS */

// Called when the page finishes loading
function CommonPageLoaded() {
	g_bLoaded = true;
}

// Retrieve an object from the DOM
function DocumentObject( strObjectID, bWithStyle )
{
	if (bWithStyle)
	{
		if (document.getElementById) return (document.getElementById(strObjectID).style); 
		else if (document.all) return (document.all[strObjectID].style); 
		else if ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) == 4)) return (document.layers[strObjectID]); 
	}
	else
	{
		if (document.getElementById) return (document.getElementById(strObjectID)) ; 
		else if (document.all) return (document.all[strObjectID]); 
		else if ((navigator.appName.indexOf('Netscape') != -1) && (parseInt(navigator.appVersion) == 4)) return (document.layers[strObjectID]); 
	}
}

// Get the position of the element on the page
function DocumentObjectPosition( obj ) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// Stub function
function Foo() {
	alert( 'This feature is not yet implemented.' );
}

// Remove whitespace from a string
String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

// Change the label of a form field to red if there is an error
function HighlightErrorField( strID, bError ) {
	DocumentObject( strID, true ).color = ( bError ? '#db0c41' : '#000000' );
}