

// Opens a popup window at the specified url with the passed dimensions
function openWindow(url, width, height) {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax = 480;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;

    window.open(url, '',
		'width=' + width + ', height= ' + height + ',screenX='+xOffset
		+',screenY=' + yOffset
		+',top=' + yOffset
		+',left='+ xOffset);
}

// Convenience function which parses the given HTML text filled with option tags 
// and repopulates given drop-down element with them.
function ReplaceModelsOptions(element, optionsHTML)
{
	// Remove any existing options 
	while (element.options.length > 0)
        element.options[0] = null;

	// Create an array of each item for the dropdown
	var options = optionsHTML.split(",");
    var selectIndex = 0;
//    var quote = (optionsHTML.indexOf("\"") > 0 ? "\"" : "'");

	// Fill 'er up
	for (var i = 0; i < options.length; i++)
	{
	    aValueText = options[i].split("|");

	    option = new Option;
	    option.text = aValueText[0];
	    option.value = aValueText[1];
	    
	    // Check if it's selected
//	    if (aValueText[0].indexOf('selected') > 0)
//	        selectIndex = i;

	    element.options[element.options.length] = option;
	}

	element.options[selectIndex].selected = true;
}

//------------------------------------------- Start Class StringBuilder -----------------------
// This class is far more efficient in string concatenation than using "+" operator.
function StringBuilder() {
    this.__strings__ = new Array();
}
StringBuilder.prototype.append = function(str){
    this.__strings__.push(str);
}
StringBuilder.prototype.toString = function(){
    return this.__strings__.join("");
}
StringBuilder.prototype.clear = function(){
    return this.__strings__.splice(0, (this.__strings__.length - 1));
}
//------------------------------------------- End Class StringBuilder -----------------------
