function mtPopUp(address, width, height) {
	if(typeof width  == 'undefined') width  = 560;
	if(typeof height == 'undefined') height = 300;
	var winPopUp;
	winPopUp = window.open(address, '', 'toolbar=0,statusbar=0,scrollbars=yes,location=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left = 100,top = 100');
} 
function changeImg(img_src, img_name, openedBox, img_src_up) {
	document.getElementById(img_name).src= img_src;
	if(openedBox != 'null'){
		if(document.getElementById(openedBox).style.display == "block"){
			document.getElementById(img_name).src= img_src_up;
		}
	}
		
}

function expandcontent(objname, resultBox, border, backgroundColor, baseBorder, baseBackgroundColor){
	if(document.getElementById(objname).style.display != "none"){
		document.getElementById(objname).style.display = "none";
		if(resultBox != undefined){
			document.getElementById(resultBox).style.background = baseBackgroundColor;
			document.getElementById(resultBox).style.border= baseBorder;
			return;
		}
	}
	if(document.getElementById(objname).style.display == "none"){
		document.getElementById(objname).style.display = "block";
		if(resultBox != undefined){
			document.getElementById(resultBox).style.background = backgroundColor;
			document.getElementById(resultBox).style.border= border;
			return;
		}
	}
}
function showMan(objname, openedBox){
	if(document.getElementById(objname).style.visibility != "hidden"){
		if(openedBox != 'null'){
			if(document.getElementById(openedBox).style.display == "block"){
				return;
			}
		}
		document.getElementById(objname).style.visibility = "hidden";
		return;
		}
	if(document.getElementById(objname).style.visibility == "hidden"){
		document.getElementById(objname).style.visibility = "visible";
	}
}

function EMAddress(address, provider) {
    var At = "@";
    document.write('<a hr' + 'ef="ma' + 'il' + 'to:' + address + At + provider + '" >' + address + At + provider + '</a>')
}

//-----------------------------------------------------------------
// Initialization
//-----------------------------------------------------------------

// values for the ReadyState of XMLHttpRequest object
var READYSTATE_UNINITIALIZED = 0;
var READYSTATE_LOADING = 1;
var READYSTATE_LOADED = 2;
var READYSTATE_INTERACTIVE = 3;
var READYSTATE_COMPLETE = 4;

// values for HTTP status codes
var HTTPSTATUS_OK = 200;

//Possible prefixes ActiveX strings for DOM DOcument
var ARR_ACTIVEX = [
	"MSXML4.DOMDocument",
	"MSXML3.DOMDocument",
	"MSXML2.DOMDocument",
	"MSXML.DOMDocument",
	"Microsoft.XmlDom"];

//When the proper prefix is found, store it here
var STR_ACTIVEX = "";

//browser detection
var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
var isGecko = document.implementation && document.implementation.createDocument;

// ie initialization
if (isIE)
{
	//define found flag
	var bFound = false;
    
    //iterate through strings to determine which one to use (NCZ, 1/30/02)
    for (var i=0; i < ARR_ACTIVEX.length && !bFound; i++)
	{
		try
		{
			//try to create the object, it will cause an error if it doesn't work
			var objXML = new ActiveXObject(ARR_ACTIVEX[i]);

			//if it gets to this point, the string worked, so save it and return
			//the DOM Document
			STR_ACTIVEX = ARR_ACTIVEX[i];
			bFound = true                
        
        }
		catch (objException) {}
	} // end: for
}

// gecko browsers initialization
if (isGecko)
{    
    //add the loadXML() method to the Document class
    Document.prototype.loadXML = function(strXML) {

		//create a DOMParser
        var objDOMParser = new DOMParser();

        //create new document from string
        var objDoc = objDOMParser.parseFromString(strXML, "text/xml");

        //make sure to remove all nodes from the document
		while (this.hasChildNodes())
			this.removeChild(this.lastChild);

        //add the nodes from the new document
        for (var i=0; i < objDoc.childNodes.length; i++)
		{
            //import the node
            var objImportedNode = this.importNode(objDoc.childNodes[i], true);
   
            //append the child to the current document
            this.appendChild(objImportedNode);
        }
    }
}

//-----------------------------------------------------------------
// Cross-browser functions
//-----------------------------------------------------------------

// cross browser capable xml http object reference retriever
function createXmlHttpRequestObject()
{
	if (window.XMLHttpRequest)
	{
		xmlHttpObj = new XMLHttpRequest();
	}
	else
	{
		try
		{
			xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	return xmlHttpObj;
}

// cross browser capable xml object reference retriever
function createXmlObject()
{
	//variable for the created DOM Document
	var xmlObj = null;

	//determine if this is a standards-compliant browser like Mozilla
	if (isGecko)
		//create the DOM Document the standards way
		xmlObj = document.implementation.createDocument('', '', null);
	else if (isIE)
		//create the DOM Document the IE way
		xmlObj = new ActiveXObject(STR_ACTIVEX);

	return xmlObj;
}

// cross browser capable xml serialization
function getXMLSerialization(xmlNode)
{
	var text = false;

	try {
		// Gecko-based browsers, Safari, Opera
		var serializer = new XMLSerializer();
		text = serializer.serializeToString(xmlNode);
  	}
	catch (e)
	{
		try
		{
			// Internet Explorer
			text = xmlNode.xml;
		}
		catch (e) {}
	}

	return text;
}

// cross browser object reference retriever
function getObj(name, isArray)
{
	if ((arguments.length <= 1 || !isArray) && document.getElementById)
		return document.getElementById(name);
	else if (document.all)
		return document.all[name];
	else if (document.layers)
		return getObjNN4(document,name);
	else
		return null;
}

// netscape 4
function getObjNN4(obj,name)
{

	var x = obj.layers;
	var foundLayer;
	
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
			foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
	
		if (tmp)
			foundLayer = tmp;
	}

	return foundLayer;
}

//-----------------------------------------------------------------
// forms functions
//-----------------------------------------------------------------

// disable all form elements based on type
function disableFormElemets(form, type)
{
	for(var i = 0;i < form.elements.length;i++)
	{
		var element = form.elements[i];

		if(element.type == type)
			element.disabled = !element.disabled;
	}
}

// enable all form elements based on type
function enableFormElemets(form, type)
{
	for(var i = 0;i < form.elements.length;i++)
	{
		var element = form.elements[i];

		if(element.type == type)
			element.disabled = false;
	}
}

//
// Add a new option to theSel
//
function addOption(theSel, theText, theValue)
{
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

//
// Delete an option at a custom index
//
function deleteOption(theSel, theIndex)
{ 
	var selLength = theSel.length;

	if(selLength>0)
		theSel.options[theIndex] = null;
}

//
// Delete Options
//
function deleteOptions(theSel)
{
	var selLength = theSel.length;

	for(i=selLength-1; i>=0; i--)
	{
		if(theSel.options[i].selected)
			deleteOption(theSel, i);
	
	}
}

//
// Copy options from one select to another
//
function copyOptions(theSelFrom, theSelTo)
{
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;

	var i;

	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			selectedCount++;
		}
	}

	for(i=selectedCount-1; i>=0; i--)
	{
		var present = false;
				
		for(j=0; j <= theSelTo.length - 1; j++)
		{
			if(selectedValues[i] == theSelTo.options[j].value)
				present = true;
		}	
		
		if(!present)
			addOption(theSelTo, selectedText[i], selectedValues[i]);
	}
	
}

//
// Move selected between two Select list boxes
//
function moveOptions(theSelFrom, theSelTo)
{
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;

	var i;

	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			deleteOption(theSelFrom, i);
			selectedCount++;
		}
	}

	for(i=selectedCount-1; i>=0; i--)
		addOption(theSelTo, selectedText[i], selectedValues[i]);  
}

function moveOptionsBackup(theSelFrom, theSelTo)
{
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;

	var i;

	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			deleteOption(theSelFrom, i);
			selectedCount++;
		}
	}

	for(i=selectedCount-1; i>=0; i--)
		addOption(theSelTo, selectedText[i], selectedValues[i]);  
}

function escapeXml(string)
{
	return string.replace(/&/g, "&amp;")
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;")
		.replace(/"/g, "&quot;")
		.replace(/'/g, "&apos;");
}

//-----------------------------------------------------------------
// remove box content
//-----------------------------------------------------------------

function removeContent(box)
{
	if(box)
	{
		var kids = box.childNodes;
		
		for(i = kids.length - 1; i >= 0; i--)
			box.removeChild(kids[i]);
	}
}

// Remove leading spaces and carriage returns
function trim(s) {
	
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{
		s = s.substring(1, s.length);
	}

	return s;
}

function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}

	return sString;
}

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}

	return sString;
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	
	return sString;
}
